:root,
:root[data-theme="dark"] {
    --bg-body: #090b10;
    --bg-canvas-glow: radial-gradient(ellipse 80% 45% at 65% -5%, rgba(88, 101, 242, 0.14), transparent 70%);
    --bg-card: #10131c;
    --bg-sidebar: #0c0e15;
    --bg-item: rgba(255, 255, 255, 0.025);
    --bg-item-hover: rgba(255, 255, 255, 0.06);
    --bg-active: rgba(88, 101, 242, 0.15);
    --bg-input: #0b0d14;
    --border-card: rgba(255, 255, 255, 0.08);
    --border-row: rgba(255, 255, 255, 0.06);
    --border-input: rgba(255, 255, 255, 0.13);
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #8b95a9;
    --text-label: #748096;
    --accent: #5865F2;
    --accent-hover: #4752c4;
    --accent-soft: #818cf8;
    --accent-glow: rgba(88, 101, 242, 0.25);
    --shadow-card: 0 10px 30px -12px rgba(0, 0, 0, 0.55);
    --shadow-btn: 0 4px 14px -2px rgba(88, 101, 242, 0.42);
    --success-text: #4ade80;
    --success-bg: rgba(34, 197, 94, 0.12);
    --success-border: rgba(74, 222, 128, 0.28);
    --error-text: #f87171;
    --error-bg: rgba(239, 68, 68, 0.12);
    --error-border: rgba(248, 113, 113, 0.3);
}

:root[data-theme="light"] {
    --bg-body: #f4f6fa;
    --bg-canvas-glow: radial-gradient(ellipse 80% 45% at 65% -5%, rgba(88, 101, 242, 0.09), transparent 70%);
    --bg-card: #ffffff;
    --bg-sidebar: #fafbfe;
    --bg-item: #f8fafc;
    --bg-item-hover: #f1f5f9;
    --bg-active: rgba(88, 101, 242, 0.1);
    --bg-input: #ffffff;
    --border-card: rgba(15, 23, 42, 0.08);
    --border-row: rgba(15, 23, 42, 0.06);
    --border-input: rgba(15, 23, 42, 0.15);
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --text-label: #64748b;
    --accent: #5865F2;
    --accent-hover: #4752c4;
    --accent-soft: #4f46e5;
    --accent-glow: rgba(88, 101, 242, 0.18);
    --shadow-card: 0 8px 24px -10px rgba(15, 23, 42, 0.08);
    --shadow-btn: 0 4px 12px -2px rgba(88, 101, 242, 0.3);
    --success-text: #15803d;
    --success-bg: rgba(34, 197, 94, 0.1);
    --success-border: rgba(21, 128, 61, 0.24);
    --error-text: #b91c1c;
    --error-bg: rgba(239, 68, 68, 0.1);
    --error-border: rgba(185, 28, 28, 0.24);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

[hidden] {
    display: none !important;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-body);
    background-image: var(--bg-canvas-glow);
    min-height: 100vh;
    min-height: 100dvh;
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.2s ease, color 0.2s ease;
}

body.auth-body {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px 16px;
}

body.drawer-open {
    overflow: hidden;
}

/* ── Loading state ── */
.loading-screen {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px;
}

#loading-message {
    color: var(--text-muted);
    font-size: 0.92rem;
    font-weight: 500;
    letter-spacing: -0.01em;
}

/* ── Full-screen dashboard layout ── */
.dashboard-layout {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    grid-template-columns: 264px minmax(0, 1fr);
}

.dashboard-layout.is-sidebar-collapsed {
    grid-template-columns: 76px minmax(0, 1fr);
}

/* ── Sidebar ── */
.dashboard-sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-card);
    padding: 18px 14px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 100vh;
    min-height: 100dvh;
    position: sticky;
    top: 0;
    transition: width 0.2s ease, padding 0.2s ease;
}

.sidebar-top-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 4px;
}

.sidebar-toggle-btn,
.mobile-open-btn {
    min-height: 36px;
    min-width: 36px;
    padding: 7px 10px;
    background: var(--bg-item);
    border: 1px solid var(--border-row);
    border-radius: 9px;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.sidebar-toggle-btn:hover,
.mobile-open-btn:hover {
    background: var(--bg-item-hover);
    border-color: var(--border-input);
    color: var(--text-primary);
}

.hamburger-lines {
    width: 15px;
    height: 2px;
    background: currentColor;
    border-radius: 999px;
    position: relative;
    display: inline-block;
    flex-shrink: 0;
}

.hamburger-lines::before,
.hamburger-lines::after {
    content: "";
    position: absolute;
    left: 0;
    width: 15px;
    height: 2px;
    background: currentColor;
    border-radius: 999px;
}

.hamburger-lines::before { top: -5px; }
.hamburger-lines::after { top: 5px; }

.sidebar-brand-label {
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-label);
    white-space: nowrap;
}

.sidebar-collapsible {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--border-row);
}

.dashboard-layout.is-sidebar-collapsed .sidebar-brand-label,
.dashboard-layout.is-sidebar-collapsed .user-meta,
.dashboard-layout.is-sidebar-collapsed .nav-btn,
.dashboard-layout.is-sidebar-collapsed .sidebar-footer {
    display: none;
}

.dashboard-layout.is-sidebar-collapsed .sidebar-top-bar {
    justify-content: center;
    padding: 0;
}

.dashboard-layout.is-sidebar-collapsed .sidebar-profile-btn {
    justify-content: center;
    padding: 8px;
}

.sidebar-profile-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px;
    background: var(--bg-item);
    border: 1px solid var(--border-row);
    border-radius: 12px;
    color: var(--text-primary);
    text-decoration: none;
    text-align: left;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.sidebar-profile-btn:hover {
    background: var(--bg-item-hover);
    border-color: var(--border-input);
}

.sidebar-profile-btn.is-active {
    background: var(--bg-active);
    border-color: rgba(88, 101, 242, 0.45);
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 2px solid var(--border-input);
    object-fit: cover;
    flex-shrink: 0;
}

.user-avatar-lg {
    width: 68px;
    height: 68px;
    border-width: 3px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.user-meta {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-user-name {
    font-size: 0.88rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.nav-btn {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 40px;
    padding: 9px 12px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 9px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.nav-btn:hover {
    background: var(--bg-item-hover);
    color: var(--text-primary);
}

.nav-btn.is-active {
    background: var(--bg-active);
    border-color: rgba(88, 101, 242, 0.32);
    color: var(--text-primary);
    font-weight: 600;
}

.nav-btn.is-active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 999px 999px 0;
    background: var(--accent);
}

.mobile-header-bar {
    display: none;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(2px);
    z-index: 30;
}

/* ── Main full-screen workspace ── */
.dashboard-main {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 28px 36px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.page-panel {
    width: 100%;
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 16px;
    padding: 28px 32px;
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-row);
}

.page-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.page-header-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
}

.back-btn {
    min-height: 36px;
    padding: 6px 12px;
    background: var(--bg-item);
    border: 1px solid var(--border-input);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.back-btn:hover {
    background: var(--bg-item-hover);
    border-color: var(--border-input);
    color: var(--text-primary);
}

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

.page-header .subtitle {
    white-space: normal;
}

/* ── Login page ── */
.auth-card {
    width: 100%;
    max-width: 390px;
    margin: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 16px;
    padding: 36px 32px;
    box-shadow: var(--shadow-card);
    text-align: center;
}

.brand-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 18px;
    color: var(--accent);
    filter: drop-shadow(0 6px 16px var(--accent-glow));
}

.brand-icon svg { width: 100%; height: 100%; fill: currentColor; }

.auth-card h1 {
    color: var(--text-primary);
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 6px;
}

.auth-card .subtitle { margin-bottom: 24px; }

.error-message {
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    color: var(--error-text);
    font-size: 0.82rem;
    padding: 10px 12px;
    border-radius: 9px;
    margin-bottom: 18px;
}

.discord-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    min-height: 44px;
    padding: 12px 18px;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 10px;
    box-shadow: var(--shadow-btn);
    transition: background 0.18s ease, transform 0.18s ease;
}

.discord-btn:hover { background: var(--accent-hover); transform: translateY(-1px); }

.discord-btn svg { width: 18px; height: 18px; fill: currentColor; }

/* ── Cookie banner & disclaimer ── */
.auth-disclaimer {
    margin-top: 16px;
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.45;
}

.disclaimer-box {
    margin-top: 10px;
    padding: 16px;
    background: var(--bg-item);
    border: 1px solid var(--border-row);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
}

.disclaimer-box h2 {
    font-size: 0.94rem;
    font-weight: 600;
    color: var(--text-primary);
}

.disclaimer-box p {
    font-size: 0.84rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.cookie-banner {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: 16px;
    z-index: 60;
    display: flex;
    justify-content: center;
    pointer-events: none;
}

.cookie-banner-content {
    pointer-events: auto;
    width: 100%;
    max-width: 820px;
    background: var(--bg-card);
    border: 1px solid var(--border-input);
    border-radius: 14px;
    padding: 16px 20px;
    box-shadow: var(--shadow-card);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
}

.cookie-banner-text {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.84rem;
    color: var(--text-secondary);
}

.cookie-banner-text strong {
    font-size: 0.92rem;
    color: var(--text-primary);
}

.cookie-banner-text code {
    font-family: monospace;
    font-size: 0.8rem;
    padding: 1px 5px;
    border-radius: 5px;
    background: var(--bg-item-hover);
    color: var(--text-primary);
}

.cookie-details {
    margin-top: 6px;
    padding-top: 8px;
    border-top: 1px solid var(--border-row);
}

.cookie-details ul {
    padding-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.cookie-banner-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.cookie-btn-primary,
.cookie-btn-secondary {
    min-height: 38px;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.cookie-btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
}

.cookie-btn-primary:hover {
    background: var(--accent-hover);
}

.cookie-btn-secondary {
    background: var(--bg-item);
    color: var(--text-primary);
    border: 1px solid var(--border-input);
}

.cookie-btn-secondary:hover {
    background: var(--bg-item-hover);
}

@media (max-width: 640px) {
    .cookie-banner-content {
        flex-direction: column;
        padding: 14px 16px;
    }

    .cookie-banner-actions {
        width: 100%;
    }

    .cookie-btn-primary,
    .cookie-btn-secondary {
        flex: 1;
    }
}

/* ── Profile page ── */
.account-banner {
    width: 100%;
    height: 140px;
    border-radius: 14px;
    border: 1px solid var(--border-row);
    background-size: cover;
    background-position: center;
}

.account-hero {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 4px 0;
}

.account-hero h2 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.account-details {
    max-width: 640px;
    background: var(--bg-item);
    border: 1px solid var(--border-row);
    border-radius: 12px;
    padding: 4px 18px;
    display: flex;
    flex-direction: column;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 13px 0;
    border-top: 1px solid var(--border-row);
}

.account-details .info-row:first-child {
    border-top: none;
}

.info-label {
    color: var(--text-label);
    font-size: 0.74rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    flex-shrink: 0;
}

.info-value {
    color: var(--text-secondary);
    font-size: 0.86rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 40px;
    padding: 9px 14px;
    background: var(--bg-item);
    border: 1px solid var(--border-input);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 9px;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.logout-btn:hover {
    background: var(--error-bg);
    border-color: var(--error-border);
    color: var(--error-text);
}

/* ── Servers grid ── */
.count-pill {
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-item);
    border: 1px solid var(--border-input);
    padding: 4px 11px;
    border-radius: 999px;
    flex-shrink: 0;
}

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

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

.guild-btn {
    width: 100%;
    min-height: 64px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 15px;
    background: var(--bg-item);
    border: 1px solid var(--border-row);
    border-radius: 12px;
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.guild-btn:hover:not(:disabled) {
    background: var(--bg-item-hover);
    border-color: var(--border-input);
    transform: translateY(-1px);
}

.guild-btn:disabled {
    opacity: 0.52;
    cursor: not-allowed;
}

.guild-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border-row);
    object-fit: cover;
    flex-shrink: 0;
}

.guild-icon-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-active);
    color: var(--accent-soft);
    border-color: rgba(88, 101, 242, 0.25);
    font-size: 0.78rem;
    font-weight: 700;
}

.guild-name {
    flex: 1;
    min-width: 0;
    font-size: 0.92rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.guild-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 999px;
    flex-shrink: 0;
}

.badge-active {
    background: var(--success-bg);
    color: var(--success-text);
    border: 1px solid var(--success-border);
}

.badge-inactive {
    background: var(--bg-item);
    color: var(--text-muted);
    border: 1px solid var(--border-row);
}

/* ── Forms & Settings ── */
.settings-form {
    max-width: 520px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.field-label {
    font-size: 0.86rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.text-input,
.select-input {
    width: 100%;
    min-height: 42px;
    padding: 10px 13px;
    font-size: 0.9rem;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 9px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.select-input {
    cursor: pointer;
}

.select-input option {
    background: var(--bg-card);
    color: var(--text-primary);
}

.text-input:focus,
.select-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.toggle-group {
    padding: 12px 15px;
    background: var(--bg-item);
    border: 1px solid var(--border-row);
    border-radius: 10px;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 28px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
}

.toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    padding-top: 4px;
}

.save-btn {
    min-height: 42px;
    padding: 10px 20px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 9px;
    font-size: 0.88rem;
    font-weight: 600;
    box-shadow: var(--shadow-btn);
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
}

.save-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.save-btn:disabled {
    opacity: 0.6;
    box-shadow: none;
    cursor: not-allowed;
}

.status-message {
    font-size: 0.84rem;
    font-weight: 500;
    color: var(--text-muted);
}

.status-success {
    color: var(--success-text);
}

.status-error {
    color: var(--error-text);
}

@media (max-width: 768px) {
    .dashboard-layout,
    .dashboard-layout.is-sidebar-collapsed {
        grid-template-columns: 1fr;
    }

    .dashboard-main {
        padding: 14px;
        padding-bottom: max(18px, env(safe-area-inset-bottom));
        gap: 14px;
    }

    .mobile-header-bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        background: var(--bg-card);
        border: 1px solid var(--border-card);
        border-radius: 12px;
        padding: 10px 14px;
        box-shadow: var(--shadow-card);
    }

    .mobile-view-title {
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--text-primary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .dashboard-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(84vw, 280px);
        z-index: 40;
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
    }

    .dashboard-sidebar.is-mobile-open {
        transform: translateX(0);
    }

    .dashboard-layout.is-sidebar-collapsed .sidebar-brand-label,
    .dashboard-layout.is-sidebar-collapsed .user-meta,
    .dashboard-layout.is-sidebar-collapsed .sidebar-footer {
        display: flex;
    }

    .dashboard-layout.is-sidebar-collapsed .nav-btn {
        display: flex;
    }

    .page-panel {
        padding: 20px 18px;
        border-radius: 14px;
    }

    .page-header {
        flex-direction: column;
        gap: 10px;
    }

    .guild-grid {
        grid-template-columns: 1fr;
    }

    .save-btn {
        width: 100%;
    }
}