* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --bg: #0f1216;
    --bg2: #171c22;
    --bg3: #1e252d;
    --border: #2a333d;
    --text: #e6edf3;
    --muted: #8b98a5;
    --accent: #4f9cf9;
    --accent2: #3b82f6;
    --danger: #ef4444;
    --success: #22c55e;
}
body {
    font-family: -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
    background: var(--bg); color: var(--text); line-height: 1.5;
    min-height: 100vh; display: flex; flex-direction: column;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.container { max-width: 1000px; margin: 0 auto; padding: 0 16px; width: 100%; }
main.container { flex: 1; padding-top: 24px; padding-bottom: 40px; }

.topbar { background: var(--bg2); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; gap: 24px; height: 60px; }
.logo { font-weight: 700; font-size: 18px; color: var(--text); }
.nav { display: flex; gap: 6px; flex: 1; }
.nav a { color: var(--muted); padding: 6px 12px; border-radius: 6px; font-size: 14px; }
.nav a:hover { background: var(--bg3); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--bg3); color: var(--text); }
.userbox { display: flex; align-items: center; gap: 10px; }
.user-link { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }

.avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: 50%;
    color: #fff; font-weight: 600; font-size: 14px; flex-shrink: 0;
}
.avatar.lg { width: 72px; height: 72px; font-size: 28px; }

.btn {
    display: inline-block; padding: 8px 16px; border-radius: 8px;
    background: var(--bg3); color: var(--text); text-decoration: none;
    border: 1px solid var(--border); cursor: pointer; font-size: 14px;
    font-family: inherit; transition: .15s;
}
.btn:hover { background: #2a333d; }
.btn-primary { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.btn-primary:hover { background: #2563eb; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

.card {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 12px; padding: 20px; margin-bottom: 16px;
}
.card h1, .card h2 { margin-bottom: 14px; font-size: 20px; }

.form-group { margin-bottom: 14px; }
label { display: block; margin-bottom: 6px; font-size: 14px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], textarea {
    width: 100%; padding: 10px 12px; border-radius: 8px;
    background: var(--bg); border: 1px solid var(--border);
    color: var(--text); font-size: 14px; font-family: inherit; outline: none;
    transition: border-color .15s;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 100px; }
.error { color: var(--danger); font-size: 14px; margin-bottom: 12px; }

.topic-item {
    display: flex; gap: 14px; padding: 16px;
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 10px; margin-bottom: 10px; color: var(--text);
    transition: .15s;
}
.topic-item:hover { border-color: var(--accent); background: var(--bg3); text-decoration: none; }
.topic-main { flex: 1; min-width: 0; }
.topic-title { font-weight: 600; font-size: 16px; margin-bottom: 4px; word-wrap: break-word; }
.topic-meta { font-size: 13px; color: var(--muted); }
.topic-count {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-width: 60px; color: var(--muted); font-size: 12px; text-align: center;
}
.topic-count b { font-size: 18px; color: var(--text); }

.post {
    display: flex; gap: 14px; padding: 16px;
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 10px; margin-bottom: 12px;
}
.post-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; font-size: 14px; flex-wrap: wrap; }
.post-author { font-weight: 600; color: var(--text); }
.post-time { color: var(--muted); font-size: 12px; }
.post-body { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }

.users-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.user-card {
    display: flex; align-items: center; gap: 12px; padding: 14px;
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 10px; color: var(--text); transition: .15s;
}
.user-card:hover { border-color: var(--accent); text-decoration: none; }
.user-card .name { font-weight: 600; }
.user-card .role { font-size: 12px; color: var(--muted); }

.chat-box {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 12px; display: flex; flex-direction: column;
    height: calc(100vh - 220px); min-height: 400px;
    overflow: hidden;
}
.chat-messages {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 12px;
    scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.chat-messages::-webkit-scrollbar-thumb:hover { background: #3a4450; }

.chat-msg { display: flex; gap: 10px; align-items: flex-start; }
.chat-msg > div { min-width: 0; max-width: 75%; }
.chat-msg .body {
    background: var(--bg3); padding: 8px 12px; border-radius: 10px;
    word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap;
}
.chat-msg .head { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.chat-msg .head b { color: var(--text); font-size: 13px; }

.chat-form { display: flex; gap: 10px; padding: 12px; border-top: 1px solid var(--border); }
.chat-form input { flex: 1; }
.chat-form input:focus { border-color: var(--accent); }

.flash {
    background: rgba(34,197,94,.15); border: 1px solid var(--success);
    color: #86efac; padding: 10px 14px; border-radius: 8px; margin-bottom: 16px;
}
.muted { color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.mt { margin-top: 16px; }
.footer { border-top: 1px solid var(--border); padding: 20px 0; color: var(--muted); font-size: 13px; text-align: center; }
code { background: var(--bg3); padding: 2px 6px; border-radius: 4px; font-size: 13px; font-family: "SF Mono", Consolas, monospace; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
tr:last-child td { border-bottom: none; }

.pagination {
    display: flex; gap: 6px; justify-content: center;
    flex-wrap: wrap; margin: 20px 0;
}
.page-link {
    padding: 6px 12px; border-radius: 6px;
    background: var(--bg2); border: 1px solid var(--border);
    color: var(--text); font-size: 14px; transition: .15s;
}
.page-link:hover { background: var(--bg3); text-decoration: none; }
.page-link.active { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.page-dots {
    display: inline-flex; align-items: center;
    padding: 6px 4px; color: var(--muted); font-size: 14px;
}

#load-more {
    margin: 4px auto 12px;
    font-size: 12px;
    opacity: .75;
    transition: .15s;
}
#load-more:hover:not(:disabled) { opacity: 1; }
#load-more:disabled { opacity: .4; cursor: wait; }

@media (max-width: 640px) {
    .topbar-inner { gap: 12px; height: auto; padding: 10px 0; flex-wrap: wrap; }
    .nav { order: 3; width: 100%; justify-content: flex-start; overflow-x: auto; }
    .nav a { font-size: 13px; padding: 5px 10px; white-space: nowrap; }
    .userbox { margin-left: auto; }
    .user-link span:last-child { display: none; }

    .container { padding: 0 12px; }
    .card { padding: 16px; border-radius: 10px; }
    .topic-item, .post { padding: 12px; gap: 10px; }
    .topic-count { display: none; }
    .avatar.lg { width: 56px; height: 56px; font-size: 22px; }
    .chat-msg > div { max-width: 85%; }
    .chat-box { height: calc(100vh - 260px); }
    h1 { font-size: 20px; }
    .users-grid { grid-template-columns: 1fr; }
    table { font-size: 13px; }
    th, td { padding: 8px 6px; }
}