:root {
    --bg: #f0f4f8;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #eff6ff;
    --success: #10b981;
    --success-light: #ecfdf5;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --purple: #8b5cf6;
    --purple-light: #f5f3ff;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --radius: 12px;
    --radius-sm: 8px;
    --nav-height: 60px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

code {
    background: var(--primary-light);
    color: #1d4ed8;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.88em;
    font-family: "Cascadia Code", Consolas, monospace;
    letter-spacing: 0.02em;
}

/* ── Topbar ── */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    height: var(--nav-height);
    display: flex;
    align-items: center;
    gap: 32px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
    white-space: nowrap;
}

.brand-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    border-radius: 9px;
    color: #fff;
    flex-shrink: 0;
}

.brand-icon svg { display: block; }

.topnav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.topnav a {
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: background 0.15s, color 0.15s;
}

.topnav a:hover {
    background: var(--border-light);
    color: var(--text);
    text-decoration: none;
}

.topnav a.active {
    background: var(--primary-light);
    color: var(--primary);
}

.user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: var(--text-secondary);
}

.user-name {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
}

.user a {
    padding: 6px 12px;
    border-radius: 7px;
    font-size: 13px;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    transition: background 0.15s, border-color 0.15s;
}

.user a:hover {
    background: var(--border-light);
    border-color: #cbd5e1;
    text-decoration: none;
    color: var(--text);
}

/* ── Main layout ── */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px 56px;
}

.page-header {
    margin-bottom: 28px;
}

.page-header h1 {
    margin: 0 0 4px;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}

.page-header .subtitle {
    margin: 0;
    font-size: 14px;
    color: var(--text-secondary);
}

h1 { margin: 0 0 16px; font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; }
h2 {
    margin: 0 0 16px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.section-title h2 { margin: 0; }

.footer {
    text-align: center;
    color: var(--text-muted);
    padding: 24px;
    font-size: 13px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
}

.muted { color: var(--text-secondary); }

/* ── Stats ── */
.stats {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    display: flex;
    align-items: flex-start;
    gap: 14px;
    transition: box-shadow 0.2s, transform 0.2s;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon svg { display: block; }

.stat-icon-blue { background: var(--primary-light); color: var(--primary); }
.stat-icon-green { background: var(--success-light); color: var(--success); }
.stat-icon-amber { background: var(--warning-light); color: var(--warning); }
.stat-icon-purple { background: var(--purple-light); color: var(--purple); }
.stat-icon-slate { background: #f1f5f9; color: #64748b; }

.stat-body { min-width: 0; }

.stat-card .num {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.03em;
    color: var(--text);
}

.stat-card .label {
    color: var(--text-secondary);
    font-size: 13px;
    margin-top: 2px;
}

/* ── Panels & tables ── */
.panel {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
}

.panel-header {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
}

.panel-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.table-wrap {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    overflow: hidden;
}

.table {
    width: 100%;
    border-collapse: collapse;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
}

.table th, .table td {
    padding: 13px 18px;
    border-bottom: 1px solid var(--border-light);
    text-align: left;
    font-size: 14px;
}

.table th {
    background: #f8fafc;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
}

.table tbody tr:last-child td { border-bottom: none; }

.table tbody tr {
    transition: background 0.12s;
}

.table tbody tr:hover {
    background: #f8fafc;
}

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    background: #e2e8f0;
    color: #475569;
}

.badge-unused { background: var(--primary-light); color: #1d4ed8; }
.badge-active { background: var(--success-light); color: #047857; }
.badge-expired { background: var(--danger-light); color: #b91c1c; }
.badge-disabled { background: #f1f5f9; color: #64748b; }

/* ── Alerts ── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 14px;
    border: 1px solid transparent;
}

.alert-error { background: var(--danger-light); color: #991b1b; border-color: #fecaca; }
.alert-ok { background: var(--success-light); color: #166534; border-color: #a7f3d0; }

/* ── Auth pages ── */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #eff6ff 0%, #f0f4f8 40%, #e0e7ff 100%);
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border-radius: 16px;
    padding: 36px 32px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-light);
}

.auth-card .brand-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    margin: 0 auto 16px;
}

.auth-card h1 {
    text-align: center;
    margin-bottom: 6px;
    font-size: 1.4rem;
}

.auth-card .muted {
    text-align: center;
    margin-bottom: 24px;
    font-size: 14px;
}

/* ── Forms ── */
.stack-form {
    max-width: 560px;
}

.checkbox-line {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    font-size: 14px;
    color: var(--text-secondary);
}

.checkbox-line input {
    width: auto;
    margin: 0;
}

label {
    display: block;
    margin: 12px 0 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

input, select, textarea, button { font: inherit; }

input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

button {
    margin-top: 16px;
    padding: 10px 18px;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: #fff;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
}

button:hover {
    background: var(--primary-hover);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.btn-sm {
    margin-top: 0;
    padding: 5px 12px;
    font-size: 12px;
    border-radius: 6px;
}

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #dc2626; box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3); }

.inline-form {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.inline-form input, .inline-form select {
    width: auto;
    min-width: 140px;
}

.grid-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.filters { margin-bottom: 16px; }

.code-block {
    width: 100%;
    background: #0f172a;
    color: #e2e8f0;
    border: 0;
    border-radius: var(--radius-sm);
    padding: 16px;
    font-family: "Cascadia Code", Consolas, monospace;
    font-size: 13px;
    line-height: 1.6;
    overflow: auto;
}

pre.code-block { white-space: pre-wrap; }

.actions form { margin-right: 4px; }

.device-ids .device-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.device-ids .device-row:last-child { margin-bottom: 0; }

/* ── Responsive ── */
@media (max-width: 900px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
    .topbar-inner { gap: 16px; padding: 0 16px; }
    .topnav a { padding: 6px 10px; font-size: 13px; }
}

@media (max-width: 600px) {
    .stats { grid-template-columns: 1fr; }
    .brand-text { display: none; }
    .topnav { gap: 2px; }
    .container { padding: 20px 16px 40px; }
    .table th, .table td { padding: 10px 12px; font-size: 13px; }
}
