/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
img { max-width: 100%; display: block; }

/* ── Theme tokens ── */
:root {
    --bg: #ffffff;
    --bg2: #f7f7f8;
    --bg3: #efefef;
    --border: #e4e4e7;
    --text: #18181b;
    --text2: #52525b;
    --text3: #a1a1aa;
    --accent: #18181b;
    --accent-fg: #ffffff;
    --link: #2563eb;
    --danger: #dc2626;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,.08);
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --bg: #0f0f10;
    --bg2: #18181b;
    --bg3: #27272a;
    --border: #3f3f46;
    --text: #fafafa;
    --text2: #a1a1aa;
    --text3: #71717a;
    --accent: #fafafa;
    --accent-fg: #0f0f10;
    --link: #60a5fa;
    --danger: #f87171;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,.4);
}

/* ── Base ── */
html { font-size: 15px; scroll-behavior: smooth; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background var(--transition), color var(--transition);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main { flex: 1; }

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ── */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: 56px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(8px);
    transition: background var(--transition), border-color var(--transition);
}

.nav-brand {
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: -0.01em;
    color: var(--text);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
}

.nav-user {
    color: var(--text2);
    font-size: 0.85rem;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Theme toggle ── */
.theme-toggle {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: background var(--transition);
    flex-shrink: 0;
}
.theme-toggle:hover { background: var(--border); }
[data-theme="dark"] .icon-sun { display: inline; }
[data-theme="dark"] .icon-moon { display: none; }
.icon-sun { display: none; }
.icon-moon { display: inline; }

/* ── Buttons ── */
.btn-primary {
    background: var(--accent);
    color: var(--accent-fg);
    border: none;
    padding: 0.45rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    transition: opacity var(--transition);
    white-space: nowrap;
}
.btn-primary:hover { opacity: 0.85; text-decoration: none; }
.btn-full { width: 100%; justify-content: center; padding: 0.65rem; }

.btn-secondary {
    background: var(--bg3);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.45rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    display: inline-block;
    transition: background var(--transition);
}
.btn-secondary:hover { background: var(--border); text-decoration: none; }

.btn-link {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text2);
    padding: 0;
}
.btn-link:hover { color: var(--text); text-decoration: underline; }

.btn-small {
    background: var(--accent);
    color: var(--accent-fg);
    border: none;
    padding: 0.3rem 0.65rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
}
.btn-danger { background: var(--danger); color: #fff; }

/* ── Auth pages ── */
.auth-page {
    background: var(--bg2);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.auth-wrapper { width: 100%; max-width: 420px; }

.auth-header { text-align: center; margin-bottom: 2rem; }
.auth-header h1 {
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 0.35rem;
    color: var(--text);
}
.auth-header p { color: var(--text2); font-size: 0.875rem; line-height: 1.5; }

.auth-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow-md);
}
.auth-box h2 { font-size: 1.2rem; font-weight: 700; margin-bottom: 0.3rem; }
.auth-subtitle { color: var(--text2); font-size: 0.875rem; margin-bottom: 1.5rem; }

.auth-form { display: flex; flex-direction: column; gap: 0.75rem; }
.auth-form label { font-size: 0.85rem; font-weight: 500; color: var(--text2); }
.auth-form input {
    padding: 0.65rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    background: var(--bg2);
    color: var(--text);
    outline: none;
    transition: border-color var(--transition);
    width: 100%;
}
.auth-form input:focus { border-color: var(--text); }

.auth-footer { margin-top: 1rem; text-align: center; font-size: 0.85rem; color: var(--text2); }
.auth-footer a { color: var(--link); }

.alert.error {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    color: #b91c1c;
    padding: 0.65rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
}
[data-theme="dark"] .alert.error {
    background: #2d0a0a;
    border-color: #7f1d1d;
    color: #fca5a5;
}

/* ── Hero ── */
.hero {
    padding: 2.5rem 1.5rem 2rem;
    border-bottom: 1px solid var(--border);
}
.hero h1 {
    font-size: clamp(1.5rem, 4vw, 2.25rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.15;
    margin-bottom: 0.5rem;
}
.hero h2 {
    font-size: clamp(1rem, 2.5vw, 1.25rem);
    font-weight: 400;
    color: var(--text2);
    line-height: 1.5;
}

/* ── Threads container ── */
.threads-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-bottom: 1px solid var(--border);
}

.threads-panel { padding: 1.5rem; }
.threads-panel:first-child { border-right: 1px solid var(--border); }

.threads-panel h3 {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text3);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.thread-list { list-style: none; }

.thread-list li {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}
.thread-list li:last-child { border-bottom: none; }

.thread-list li::before {
    content: "•";
    color: var(--text3);
    flex-shrink: 0;
    font-size: 0.8rem;
}

.thread-title {
    flex: 1;
    font-size: 0.875rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.thread-title:hover { color: var(--link); text-decoration: none; }

.thread-meta {
    font-size: 0.75rem;
    color: var(--text3);
    white-space: nowrap;
    flex-shrink: 0;
}

.empty { color: var(--text3); font-size: 0.875rem; padding: 0.5rem 0; }

/* ── Sections ── */
.section {
    padding: 1.75rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.section-header .section-title { margin-bottom: 0; }

.section-title {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text3);
    margin-bottom: 1rem;
}

.drive-embed {
    width: 100%;
    height: 360px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* ── Members table ── */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.members-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.members-table th {
    text-align: left;
    padding: 0.6rem 0.75rem;
    border-bottom: 2px solid var(--border);
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--bg);
}
.members-table td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border);
    color: var(--text2);
}
.members-table tr:last-child td { border-bottom: none; }
.members-table tr:hover td { background: var(--bg2); }
.members-table a { color: var(--link); }
.empty-row { text-align: center; color: var(--text3); padding: 2rem !important; }

/* Sort headers */
.col-hidden { display: none; }
.sortable thead th { cursor: pointer; user-select: none; white-space: nowrap; }
.sortable thead th:hover { color: var(--text2); }
.sortable thead th.sorted-asc,
.sortable thead th.sorted-desc { color: var(--text); }
.sort-icon { font-size: 0.65rem; margin-left: 3px; }

/* Editable admin table */
.members-table.editable td input {
    width: 100%;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    background: var(--bg2);
    color: var(--text);
}
.members-table.editable td input:focus { border-color: var(--text); outline: none; }
.actions { display: flex; gap: 0.4rem; align-items: center; white-space: nowrap; }

/* ── Thread page ── */
.thread-page { max-width: 740px; margin: 0 auto; padding: 2rem 1.5rem; }

.back-link {
    font-size: 0.85rem;
    color: var(--text2);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-bottom: 1.5rem;
}
.back-link:hover { color: var(--text); text-decoration: none; }

.thread-header { margin-bottom: 1.5rem; }
.thread-header h1 {
    font-size: clamp(1.25rem, 3vw, 1.6rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
}
.thread-meta { font-size: 0.82rem; color: var(--text3); }

.post-body {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 2rem;
    line-height: 1.75;
    color: var(--text);
}

.replies-section { margin-bottom: 2rem; }
.replies-section h3 { font-size: 0.85rem; font-weight: 600; color: var(--text2); margin-bottom: 1rem; }

.reply-form h3, .form-page h2 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }

textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    resize: vertical;
    font-family: inherit;
    display: block;
    margin-bottom: 0.75rem;
    background: var(--bg2);
    color: var(--text);
    outline: none;
    transition: border-color var(--transition);
}
textarea:focus { border-color: var(--text); }

/* ── Post card ── */
.post-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    background: var(--bg);
    overflow: hidden;
}

.post-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 1rem;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    gap: 0.75rem;
    flex-wrap: wrap;
}

.post-author { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.author-name { font-size: 0.875rem; font-weight: 600; color: var(--text); }
.post-time { font-size: 0.78rem; color: var(--text3); }

.post-actions { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; }

.action-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.25rem 0.6rem;
    font-size: 0.78rem;
    color: var(--text2);
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    transition: background var(--transition), color var(--transition);
}
.action-btn:hover { background: var(--bg3); color: var(--text); text-decoration: none; }
.action-danger { color: var(--danger); border-color: var(--danger); }
.action-danger:hover { background: var(--danger); color: #fff; }

.post-title {
    font-size: clamp(1.2rem, 3vw, 1.6rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    padding: 1rem 1rem 0.5rem;
}

.post-body {
    padding: 0.75rem 1rem 1rem;
    line-height: 1.75;
    color: var(--text);
    background: none;
    border: none;
    border-radius: 0;
    margin: 0;
}

.reply-card .reply-body {
    padding: 0.75rem 1rem 1rem;
    font-size: 0.9rem;
    line-height: 1.65;
    color: var(--text);
}

/* Quoted reply preview */
.post-body br + br, .reply-body br + br { display: block; content: ''; margin: 0.25rem 0; }

.edit-link {
    font-size: 0.75rem;
    color: var(--text3);
    font-weight: 500;
}
.edit-link:hover { color: var(--link); text-decoration: none; }

.edit-form { margin-bottom: 1rem; }
.edit-title-input {
    width: 100%;
    font-size: 1.35rem;
    font-weight: 700;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg2);
    color: var(--text);
    margin-bottom: 0.75rem;
    outline: none;
}
.edit-title-input:focus { border-color: var(--text); }
.edit-actions { display: flex; gap: 0.6rem; margin-top: 0.5rem; }

.login-prompt {
    padding: 1.25rem;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
    font-size: 0.9rem;
    color: var(--text2);
}
.login-prompt a { color: var(--link); font-weight: 500; }

/* ── New thread / form page ── */
.form-page { max-width: 680px; margin: 0 auto; padding: 2rem 1.5rem; }
.form-page h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: 1.5rem; letter-spacing: -0.01em; }

.post-form { display: flex; flex-direction: column; gap: 0.75rem; }
.post-form label { font-size: 0.85rem; font-weight: 500; color: var(--text2); }
.post-form input {
    padding: 0.65rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    background: var(--bg2);
    color: var(--text);
    outline: none;
    width: 100%;
    transition: border-color var(--transition);
}
.post-form input:focus { border-color: var(--text); }
.form-actions { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }

/* ── Admin page ── */
.admin-page { padding: 2rem 1.5rem; max-width: 1100px; margin: 0 auto; }
.admin-page h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: 1.5rem; }

.add-form {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 2rem;
}
.add-form h3 { font-size: 0.85rem; font-weight: 600; color: var(--text2); margin-bottom: 0.75rem; }

.inline-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.inline-form input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.875rem;
    flex: 1;
    min-width: 120px;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color var(--transition);
}
.inline-form input:focus { border-color: var(--text); }

/* ── Footer ── */
footer {
    padding: 1.5rem;
    font-size: 0.8rem;
    color: var(--text3);
    border-top: 1px solid var(--border);
    text-align: center;
    margin-top: auto;
}

/* ── Mobile ── */
@media (max-width: 640px) {
    .navbar { padding: 0 1rem; }
    .nav-user { display: none; }

    .hero { padding: 1.75rem 1rem 1.5rem; }

    .threads-container { grid-template-columns: 1fr; }
    .threads-panel { padding: 1.25rem 1rem; }
    .threads-panel:first-child { border-right: none; border-bottom: 1px solid var(--border); }

    .section { padding: 1.25rem 1rem; }

    .thread-page,
    .form-page { padding: 1.25rem 1rem; }

    .admin-page { padding: 1.25rem 1rem; }
    .inline-form { flex-direction: column; }
    .inline-form input { width: 100%; min-width: unset; }

    .members-table th,
    .members-table td { padding: 0.5rem; font-size: 0.82rem; }

    .post-body { padding: 1rem; }
    .form-actions { flex-direction: column; align-items: stretch; }
    .form-actions .btn-secondary { text-align: center; }

    .drive-embed { height: 280px; }
}
