:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #ffffff;
    --accent: #3b5bfd;
    --accent-dark: #2843d1;
    --success: #16a34a;
    --success-bg: #dcfce7;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
    --warn: #d97706;
    --warn-bg: #fef3c7;
    --gray: #64748b;
    --gray-bg: #f1f5f9;
    --radius: 10px;
    --radius-sm: 7px;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 6px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ================= Login Page ================= */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: radial-gradient(circle at 30% 20%, #1e293b 0%, #0f172a 60%, #0b1120 100%);
}
.login-box {
    background: var(--surface);
    padding: 40px 36px;
    border-radius: 16px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.35);
    text-align: center;
}
.login-icon {
    width: 56px; height: 56px;
    display: flex; align-items: center; justify-content: center;
    font-size: 26px;
    background: linear-gradient(135deg, var(--accent), #6d5bff);
    border-radius: 14px;
    margin: 0 auto 18px;
}
.login-box h1 { font-size: 20px; margin: 0 0 4px; }
.login-sub { color: var(--text-muted); font-size: 13px; margin: 0 0 22px; }
.login-box label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--text-muted); text-align: right; }
.login-box input {
    width: 100%; padding: 11px 14px; margin-bottom: 16px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 14px; transition: border-color .15s, box-shadow .15s;
}
.login-box input:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 91, 253, 0.15);
}
.login-box button {
    width: 100%; padding: 12px; background: var(--accent); color: #fff;
    border: none; border-radius: var(--radius-sm); font-size: 15px; font-weight: 600;
    cursor: pointer; transition: background .15s;
}
.login-box button:hover { background: var(--accent-dark); }

/* ================= App Shell ================= */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar .brand {
    display: flex; align-items: center; gap: 10px;
    color: #fff; font-weight: 700; font-size: 15px;
    padding: 0 8px 22px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 18px;
}
.brand-icon { font-size: 18px; }

.side-nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.side-nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 8px;
    text-decoration: none; font-size: 13.5px;
    color: var(--sidebar-text);
    transition: background .15s, color .15s;
}
.side-nav a:hover { background: rgba(255,255,255,0.06); color: #e2e8f0; }
.side-nav a.active { background: var(--accent); color: #fff; }
.nav-icon { font-size: 15px; width: 18px; text-align: center; }

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding-top: 14px;
    margin-top: 14px;
    display: flex; flex-direction: column; gap: 8px;
}
.admin-chip { font-size: 12.5px; color: #cbd5e1; padding: 0 4px; }
.logout-link {
    font-size: 13px; color: #fca5a5; text-decoration: none;
    padding: 8px 10px; border-radius: 8px; transition: background .15s;
}
.logout-link:hover { background: rgba(220, 38, 38, 0.12); }

.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 18px 28px;
    position: sticky; top: 0; z-index: 5;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 700; }

.container { padding: 24px 28px 40px; max-width: 1200px; }

/* ================= Stats ================= */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    border-inline-start: 4px solid var(--gray);
}
.stat-card .stat-num { font-size: 26px; font-weight: 800; line-height: 1; }
.stat-card .stat-label { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; }
.stat-active { border-inline-start-color: var(--success); }
.stat-inactive { border-inline-start-color: var(--gray); }
.stat-expired { border-inline-start-color: var(--warn); }
.stat-suspended { border-inline-start-color: var(--danger); }

/* ================= Panels ================= */
.panel {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 22px;
    box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 16px; font-size: 15.5px; font-weight: 700; }
.panel-narrow { max-width: 460px; }
.panel-head {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 12px; margin-bottom: 4px;
}
.panel-head h2 { margin: 0; }

.inline-form, .filter-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.inline-form input, .filter-form input, .filter-form select {
    padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 13.5px; background: var(--surface);
}
.inline-form input:focus, .filter-form input:focus, .filter-form select:focus,
.stacked-form input:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59, 91, 253, 0.12);
}

.stacked-form label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--text-muted); }
.stacked-form input, .stacked-form select {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 14px; background: var(--surface);
}
.form-actions { margin-top: 22px; display: flex; gap: 10px; }
.field-hint { display: block; margin-top: -10px; margin-bottom: 4px; font-size: 11.5px; color: var(--text-muted); }

/* ================= Buttons ================= */
.btn {
    padding: 9px 16px; border: none; border-radius: var(--radius-sm); cursor: pointer;
    font-size: 13.5px; font-weight: 600; color: #fff; background: var(--accent);
    text-decoration: none; display: inline-block; transition: background .15s, opacity .15s;
}
.btn:hover { opacity: 0.92; }
.btn-primary { background: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-small { padding: 6px 12px; font-size: 12px; }
.btn-ok { background: var(--success); }
.btn-warn { background: var(--warn); }
.btn-danger { background: var(--danger); }
.btn-ghost { background: var(--gray-bg); color: var(--text); }
.btn-ghost:hover { background: #e2e8f0; opacity: 1; }

/* ================= Table ================= */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 12px 14px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: var(--gray-bg); font-weight: 700; font-size: 12.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .02em; }
tbody tr:hover { background: #f8fafc; }
td.empty { text-align: center; color: var(--text-muted); padding: 30px; }
.mono { font-family: 'Consolas', 'Courier New', monospace; font-weight: 600; letter-spacing: .02em; }

.copy-cell { display: flex; align-items: center; gap: 8px; }
.copy-btn { border: none; background: transparent; cursor: pointer; font-size: 13px; opacity: .6; }
.copy-btn:hover { opacity: 1; }

/* ================= Badges ================= */
.badge { padding: 4px 11px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.badge-active { background: var(--success-bg); color: #15803d; }
.badge-inactive { background: var(--gray-bg); color: var(--gray); }
.badge-expired { background: var(--warn-bg); color: #b45309; }
.badge-suspended { background: var(--danger-bg); color: #b91c1c; }

.lock-icon { font-size: 11px; opacity: .7; margin-inline-start: 4px; }
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }
.inline { display: inline; }

/* ================= Flash ================= */
.flash { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 18px; font-size: 13.5px; font-weight: 600; }
.flash.success { background: var(--success-bg); color: #15803d; }
.flash.error { background: var(--danger-bg); color: #b91c1c; }

/* ================= Pagination ================= */
.pagination { display: flex; gap: 6px; margin-top: 18px; flex-wrap: wrap; }
.page-link {
    padding: 7px 13px; border-radius: var(--radius-sm); background: var(--gray-bg); color: var(--text);
    text-decoration: none; font-size: 12.5px; font-weight: 600;
}
.page-link.active { background: var(--accent); color: #fff; }

/* ================= Responsive ================= */
@media (max-width: 820px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 12px 16px; gap: 16px; }
    .sidebar .brand { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
    .side-nav { flex-direction: row; flex: 1; }
    .sidebar-footer { flex-direction: row; align-items: center; border-top: none; margin-top: 0; padding-top: 0; }
    .container { padding: 18px; }
}
