/* ============================================================
   Design tokens — "Console" system
   A dark control-room base with a mint/teal signal accent;
   numeric data renders in mono as a "readout" to reinforce the
   console feel. Light mode swaps surfaces, keeps the same signal.
   ============================================================ */

:root {
    --bg: #0a0d14;
    --surface: #12151f;
    --surface-raised: #171b28;
    --border: #232838;
    --border-strong: #2e3448;
    --text: #e9ebf3;
    --text-muted: #8991ab;
    --text-faint: #565d76;

    --accent: #4fd1c5;
    --accent-strong: #38b2ac;
    --accent-soft: rgba(79, 209, 197, 0.12);
    --accent-contrast: #06201d;

    --danger: #ff6b6b;
    --danger-soft: rgba(255, 107, 107, 0.12);
    --warning: #f6ad55;
    --warning-soft: rgba(246, 173, 85, 0.12);

    --shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);

    --font-display: 'Sora', system-ui, -apple-system, sans-serif;
    --font-body: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;

    --sidebar-w: 240px;
    color-scheme: dark;
}

:root[data-theme='light'] {
    --bg: #f4f5fa;
    --surface: #ffffff;
    --surface-raised: #ffffff;
    --border: #e4e6f0;
    --border-strong: #d2d5e6;
    --text: #161925;
    --text-muted: #5b6178;
    --text-faint: #9aa0b8;

    --accent: #0d9488;
    --accent-strong: #0f766e;
    --accent-soft: rgba(13, 148, 136, 0.08);
    --accent-contrast: #ffffff;

    --danger: #dc3545;
    --danger-soft: rgba(220, 53, 69, 0.07);
    --warning: #b45309;
    --warning-soft: rgba(180, 83, 9, 0.08);

    --shadow: 0 12px 32px rgba(30, 34, 60, 0.08);
    --shadow-sm: 0 2px 8px rgba(30, 34, 60, 0.05);
    color-scheme: light;
}

* { box-sizing: border-box; }

html { color-scheme: inherit; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    transition: background 0.2s ease, color 0.2s ease;
}

h1, h2, h3 {
    font-family: var(--font-display);
    letter-spacing: -0.01em;
    color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); }

code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--accent-soft);
    color: var(--accent);
    padding: 2px 6px;
    border-radius: 5px;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.link-muted {
    color: var(--text-muted);
    font-size: 0.9rem;
}
.link-muted:hover { color: var(--text); }

/* ============================================================
   Buttons
   ============================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 9px 18px;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-strong); color: var(--accent-contrast); }

.btn-danger {
    background: transparent;
    color: var(--danger);
    border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger-soft); }

/* ============================================================
   Landing page
   ============================================================ */

.landing {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    position: relative;
}

.landing-theme-toggle { position: absolute; top: 24px; right: 24px; }

.landing-card {
    max-width: 500px;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 56px 40px;
    box-shadow: var(--shadow);
}

.landing-mark {
    width: 52px;
    height: 52px;
    margin: 0 auto 20px;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
}
.landing-mark svg { width: 26px; height: 26px; }

.landing-card h1 { font-size: 1.6rem; margin: 0 0 10px; }

.landing-card p {
    color: var(--text-muted);
    margin: 0 0 28px;
}

/* ============================================================
   Topbar (used on pages without a sidebar: home / guild picker)
   ============================================================ */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-display);
    font-weight: 700;
    color: var(--text);
}
.brand-mark {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: var(--accent-soft);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
}
.brand-mark svg { width: 15px; height: 15px; }

.topbar-user {
    display: flex;
    align-items: center;
    gap: 18px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ============================================================
   Theme toggle switch
   ============================================================ */

.theme-toggle {
    position: relative;
    width: 52px;
    height: 28px;
    border-radius: 999px;
    background: var(--surface-raised);
    border: 1px solid var(--border-strong);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    padding: 2px;
    flex-shrink: 0;
}

.theme-toggle-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-contrast);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
    transform: translateX(0);
}
.theme-toggle-thumb svg { width: 13px; height: 13px; }

.theme-toggle-thumb .icon-sun { display: none; }
:root[data-theme='light'] .theme-toggle-thumb .icon-moon { display: none; }
:root[data-theme='light'] .theme-toggle-thumb .icon-sun { display: block; }

:root[data-theme='light'] .theme-toggle-thumb { transform: translateX(24px); }

/* ============================================================
   App shell: sidebar + main (guild-scoped pages)
   ============================================================ */

.shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-back {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 600;
    padding: 6px 8px 14px;
}
.sidebar-back:hover { color: var(--text); }
.sidebar-back svg { width: 14px; height: 14px; }

.sidebar-guild {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    margin-bottom: 18px;
}

.sidebar-guild-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    overflow: hidden;
    background: var(--accent-soft);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-weight: 700;
    flex-shrink: 0;
}
.sidebar-guild-icon img { width: 100%; height: 100%; object-fit: cover; }

.sidebar-guild-name {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.92rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.88rem;
    font-weight: 600;
    border-left: 2px solid transparent;
    position: relative;
}

.sidebar-link svg { width: 17px; height: 17px; flex-shrink: 0; }

.sidebar-link:hover { color: var(--text); background: var(--surface-raised); text-decoration: none; }

.sidebar-link.active {
    color: var(--accent);
    background: var(--accent-soft);
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.sidebar-user {
    font-size: 0.82rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.main {
    flex: 1;
    min-width: 0;
}

.main-topbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 16px 32px;
    border-bottom: 1px solid var(--border);
}

/* ============================================================
   Page / content
   ============================================================ */

.page {
    max-width: 760px;
    margin: 0 auto;
    padding: 32px 24px 80px;
}

.page-wide { max-width: 920px; }

h1.page-title { margin: 4px 0 4px; font-size: 1.5rem; }

.subtitle, .empty-state {
    color: var(--text-muted);
    margin-bottom: 24px;
}

/* ============================================================
   Guild grid (picker)
   ============================================================ */

.guild-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 14px;
}

.guild-card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    text-align: center;
    color: var(--text);
    transition: border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.guild-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    transform: translateY(-1px);
}

.guild-card-disabled { opacity: 0.7; cursor: default; }
.guild-card-disabled:hover { border-color: var(--border); transform: none; box-shadow: none; }

.btn-invite {
    display: flex;
    justify-content: center;
    margin-top: 12px;
    width: 100%;
    padding: 8px 14px;
    font-size: 0.82rem;
}

.guild-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 12px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--surface-raised);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.2rem;
}
.guild-icon img { width: 100%; height: 100%; object-fit: cover; }

.guild-name {
    font-weight: 600;
    font-size: 0.92rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.guild-badge {
    margin-top: 6px;
    font-size: 0.72rem;
    color: var(--text-faint);
}

/* ============================================================
   Panels
   ============================================================ */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 24px;
    margin-top: 18px;
}

.panel h2 { margin: 0 0 4px; font-size: 1.05rem; }

.panel-desc {
    color: var(--text-muted);
    font-size: 0.87rem;
    margin: 4px 0 18px;
    max-width: 56ch;
}

.panel form {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.panel label {
    width: 100%;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ============================================================
   Inputs
   ============================================================ */

select, input[type='text'], input[type='number'] {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-family: var(--font-body);
    font-size: 0.88rem;
    min-width: 220px;
    transition: border-color 0.15s ease;
}
select:focus, input:focus { border-color: var(--accent); }
select:disabled, input:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================
   Flash messages
   ============================================================ */

.flash {
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    color: var(--text);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    font-size: 0.87rem;
}

.flash-error { background: var(--danger-soft); border-color: var(--danger); }

/* ============================================================
   Status badges & readouts
   ============================================================ */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 3px 9px;
    border-radius: 999px;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.badge-active { background: var(--accent-soft); color: var(--accent); }
.badge-ended { background: var(--surface-raised); color: var(--text-faint); }

.readout {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    color: var(--text);
}

/* ============================================================
   Data tables
   ============================================================ */

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.data-table th {
    text-align: left;
    color: var(--text-faint);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0 10px 10px;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 11px 10px;
    border-bottom: 1px solid var(--border);
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface-raised); }

.rank-cell {
    font-family: var(--font-mono);
    color: var(--text-faint);
    width: 28px;
}

/* ============================================================
   Member picker
   ============================================================ */

.member-picker { position: relative; width: 100%; max-width: 320px; }

.mp-search {
    width: 100%;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-family: var(--font-body);
    font-size: 0.88rem;
}
.mp-search:focus { border-color: var(--accent); }

.mp-results {
    position: absolute;
    z-index: 10;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface-raised);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    margin-top: 4px;
    max-height: 240px;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

.mp-result {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    cursor: pointer;
    font-size: 0.85rem;
}
.mp-result:hover { background: var(--accent-soft); }
.mp-result img { width: 24px; height: 24px; border-radius: 50%; }
.mp-username { color: var(--text-faint); font-size: 0.78rem; font-family: var(--font-mono); }

.mp-empty, .mp-error { padding: 8px 10px; color: var(--text-muted); font-size: 0.85rem; }

.mp-selected {
    margin-top: 6px;
    font-size: 0.78rem;
    font-family: var(--font-mono);
    color: var(--accent);
}

/* ============================================================
   Commands page
   ============================================================ */

.command-search {
    width: 100%;
    max-width: 480px;
    display: block;
    margin: 18px 0 16px;
    min-width: 0;
}

.command-cat-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 4px;
}

.command-cat-tab {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 999px;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.command-cat-tab:hover { color: var(--text); border-color: var(--border-strong); }

.command-cat-tab.active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

.command-cat-tab .count-pill {
    background: var(--surface-raised);
    color: var(--text-faint);
    font-size: 0.72rem;
    padding: 1px 7px;
    border-radius: 999px;
}

.command-cat-tab.active .count-pill { background: var(--accent-contrast); color: var(--accent); }

.command-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.command-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.command-item summary {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 16px;
    cursor: pointer;
    user-select: none;
}

.command-item summary::-webkit-details-marker { display: none; }

.command-name {
    font-family: var(--font-mono);
    color: var(--accent);
    font-weight: 500;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.command-summary-desc {
    color: var(--text-muted);
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.command-chevron {
    width: 16px;
    height: 16px;
    color: var(--text-faint);
    flex-shrink: 0;
    transition: transform 0.15s ease;
}

.command-item[open] .command-chevron { transform: rotate(90deg); }
.command-item[open] summary { border-bottom: 1px solid var(--border); }

.command-detail { padding: 14px 16px 18px; }

.command-full-desc {
    color: var(--text);
    font-size: 0.87rem;
    margin: 0 0 12px;
}

.command-no-options {
    color: var(--text-faint);
    font-size: 0.83rem;
    margin: 0;
}

.command-options-table { font-size: 0.82rem; }
.command-options-table th, .command-options-table td { padding: 8px 10px; }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 760px) {
    .shell { flex-direction: column; }

    .sidebar {
        position: static;
        height: auto;
        width: 100%;
        flex-direction: row;
        align-items: center;
        overflow-x: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 12px 14px;
        gap: 14px;
    }

    .sidebar-back, .sidebar-footer { display: none; }
    .sidebar-guild { margin-bottom: 0; }
    .sidebar-nav { flex-direction: row; }
    .sidebar-link span { display: none; }

    .page { padding: 24px 16px 60px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}
