:root {
    --bg-base:      #0f1117;
    --bg-surface:   #161b27;
    --bg-elevated:  #1e2535;
    --border:       #2a3347;
    --text-primary: #e8eaf0;
    --text-secondary:#a0aec0;
    --text-muted:   #6b7a99;
    --accent:       #3b82f6;
    --accent-dim:   rgba(59,130,246,.25);
    --accent-bg:    rgba(59,130,246,.08);
    --accent-hover: #2563eb;
    --danger:       #ef4444;
    --danger-bg:    rgba(239,68,68,.08);
    --radius:       10px;
    --radius-sm:    6px;
    --font:         'DM Sans', system-ui, sans-serif;
    --font-mono:    'JetBrains Mono', monospace;
    --sidebar-w:    240px;
}

/* ── Light theme ────────────────────────────────────────────── */
[data-theme="light"] {
    --bg-base:      #f1f5f9;
    --bg-surface:   #ffffff;
    --bg-elevated:  #f8fafc;
    --border:       #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary:#475569;
    --text-muted:   #94a3b8;
    --accent:       #2563eb;
    --accent-dim:   rgba(37,99,235,.2);
    --accent-bg:    rgba(37,99,235,.06);
    --accent-hover: #1d4ed8;
    --danger:       #dc2626;
    --danger-bg:    rgba(220,38,38,.07);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: var(--font); background: var(--bg-base); color: var(--text-primary); font-size: 14px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ────────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
}
.sidebar-header { padding: 20px 16px 16px; border-bottom: 1px solid var(--border); }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1rem; color: var(--text-primary); }
.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.sidebar-footer { border-top: 1px solid var(--border); padding: 8px; }

.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: var(--radius-sm);
    color: var(--text-secondary); font-weight: 500; font-size: .9rem;
    cursor: pointer; transition: background .15s, color .15s;
    text-decoration: none;
}
.nav-item:hover { background: var(--bg-elevated); color: var(--text-primary); text-decoration: none; }
.nav-item.active { background: var(--accent-bg); color: var(--accent); }
.nav-item svg { flex-shrink: 0; }
.nav-logout:hover { background: var(--danger-bg); color: var(--danger); }

.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
.top-bar {
    position: sticky; top: 0; z-index: 50;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: 0 28px;
    height: 60px;
    display: flex; align-items: center; gap: 12px;
}
.page-title { font-size: 1.15rem; font-weight: 700; color: var(--text-primary); flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.topbar-icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: var(--radius-sm);
    color: var(--text-secondary); font-size: .78rem; font-weight: 700;
    transition: background .15s, color .15s; text-decoration: none;
}
.topbar-icon-btn:hover { background: var(--bg-elevated); color: var(--text-primary); text-decoration: none; }
.content-area { padding: 28px; flex: 1; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px;
}
.card-title { font-size: 1rem; font-weight: 700; color: var(--text-primary); }

/* ── Stats bar ──────────────────────────────────────────────── */
.stats-row { display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.stat-card {
    flex: 1; min-width: 140px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--text-primary); line-height: 1; }
.stat-label { font-size: .8rem; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: .04em; }

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
thead { background: var(--bg-elevated); }
th { padding: 12px 16px; text-align: left; font-size: .78rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
td { padding: 13px 16px; border-top: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: var(--bg-elevated); }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: var(--radius-sm);
    font-family: var(--font); font-size: .88rem; font-weight: 600;
    border: none; cursor: pointer; transition: background .15s, opacity .15s;
    text-decoration: none; white-space: nowrap;
}
.btn-primary   { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); text-decoration: none; }
.btn-secondary { background: var(--bg-elevated); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); text-decoration: none; }
.btn-danger    { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.18); text-decoration: none; }
.btn-sm { padding: 5px 11px; font-size: .8rem; }
.btn-group { display: flex; gap: 6px; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 20px; margin-bottom: 20px; }
.form-grid .full-width { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: .83rem; font-weight: 600; color: var(--text-secondary); }
.form-control {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font); font-size: .9rem;
    padding: 8px 12px;
    width: 100%;
    transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--accent); }
.form-control[readonly] { opacity: .65; cursor: default; }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }
.form-hint { font-size: .78rem; color: var(--text-muted); }
.form-actions { display: flex; gap: 10px; align-items: center; padding-top: 4px; }

/* Checkboxes */
.options-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.option-check {
    display: flex; align-items: flex-start; gap: 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
.option-check:has(input:checked) { border-color: var(--accent); background: var(--accent-bg); }
.option-check input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); flex-shrink: 0; margin-top: 2px; cursor: pointer; }
.option-check-label { font-weight: 600; font-size: .88rem; }
.option-check-desc { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }

/* ── Badges & pills ─────────────────────────────────────────── */
.status-badge {
    display: inline-block;
    background: color-mix(in srgb, var(--badge-color) 15%, transparent);
    color: var(--badge-color);
    border: 1px solid color-mix(in srgb, var(--badge-color) 40%, transparent);
    border-radius: 20px;
    padding: 2px 10px;
    font-size: .75rem;
    font-weight: 600;
}
.option-pill {
    display: inline-block;
    background: var(--accent-bg);
    color: var(--accent);
    border: 1px solid var(--accent-dim);
    border-radius: 20px;
    padding: 2px 9px;
    font-size: .73rem;
    font-weight: 600;
    margin: 2px 2px 2px 0;
}

/* ── License key display ────────────────────────────────────── */
.license-key-box {
    display: flex; align-items: center; gap: 8px;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
}
.license-key-value {
    font-family: var(--font-mono);
    font-size: .95rem;
    color: var(--accent);
    letter-spacing: .05em;
    flex: 1;
}

/* ── Flash messages ─────────────────────────────────────────── */
.flash-message {
    padding: 12px 16px; border-radius: var(--radius-sm);
    margin-bottom: 20px; font-weight: 500; font-size: .9rem;
}
.flash-success { background: rgba(16,185,129,.1); color: #10b981; border: 1px solid rgba(16,185,129,.3); }
.flash-error   { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(239,68,68,.3); }
.flash-info    { background: var(--accent-bg); color: var(--accent); border: 1px solid var(--accent-dim); }

/* ── Login page ─────────────────────────────────────────────── */
.login-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg-base); }
.login-card {
    width: 100%; max-width: 380px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 36px 32px;
}
.login-logo {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    font-size: 1.3rem; font-weight: 700;
    margin-bottom: 28px;
}
.login-error {
    background: var(--danger-bg); color: var(--danger);
    border: 1px solid rgba(239,68,68,.3);
    border-radius: var(--radius-sm);
    padding: 10px 14px; margin-bottom: 16px; font-size: .88rem;
}

/* ── Danger zone ─────────────────────────────────────────────── */
.danger-zone {
    border: 1px solid rgba(239,68,68,.25);
    border-radius: var(--radius);
    padding: 20px 24px;
    background: rgba(239,68,68,.04);
}

/* ── Monospace key in table ──────────────────────────────────── */
.key-mono { font-family: var(--font-mono); font-size: .82rem; color: var(--text-secondary); letter-spacing: .03em; }

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state { padding: 48px 24px; text-align: center; color: var(--text-muted); }
