:root {
    color-scheme: dark;
    --bg: #080b10;
    --surface: #0e131b;
    --surface-2: #141b25;
    --line: #222d3b;
    --line-strong: #334154;
    --text: #edf3fb;
    --muted: #8491a3;
    --accent: #e94b58;
    --accent-soft: rgba(233, 75, 88, .13);
    --green: #4fd19a;
    --yellow: #e9b95d;
    --blue: #70a9ff;
    --radius: 12px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="light"] {
    color-scheme: light;
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --line: #dfe5ec;
    --line-strong: #cbd4df;
    --text: #17202c;
    --muted: #687587;
    --accent-soft: rgba(214, 48, 64, .09);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 13px; line-height: 1.5; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 18px 14px; background: var(--surface); border-right: 1px solid var(--line); z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 7px 22px; }
.brand > span:last-child { display: grid; }
.brand strong { letter-spacing: .08em; font-size: 14px; }
.brand small { color: var(--muted); font-size: 9px; letter-spacing: .12em; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; flex: 0 0 auto; border: 1px solid rgba(233, 75, 88, .42); border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 12px; }
.brand-mark.large { width: 50px; height: 50px; border-radius: 14px; font-size: 16px; }
.nav-label, .eyebrow { color: var(--muted); font-weight: 700; font-size: 9px; letter-spacing: .15em; }
.sidebar nav { display: grid; gap: 4px; }
.sidebar nav .nav-label { padding: 8px 10px 5px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 0 10px; border: 1px solid transparent; border-radius: 9px; color: var(--muted); font-weight: 600; transition: .18s ease; }
.sidebar nav a i { width: 18px; color: inherit; font-style: normal; font-size: 16px; text-align: center; }
.sidebar nav a:hover { color: var(--text); background: var(--surface-2); }
.sidebar nav a.active { color: var(--text); border-color: rgba(233, 75, 88, .24); background: var(--accent-soft); }
.sidebar nav a.active i { color: var(--accent); }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; gap: 9px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.sidebar-footer div { display: grid; }
.sidebar-footer strong { font-size: 11px; }
.sidebar-footer small { color: var(--muted); font-size: 10px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(79, 209, 154, .1); }

.content { min-width: 0; }
.topbar { height: 58px; position: sticky; top: 0; display: flex; align-items: center; gap: 10px; padding: 0 22px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); z-index: 15; }
.topbar-spacer { flex: 1; }
.icon-button { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: var(--surface); cursor: pointer; }
.icon-button:hover { color: var(--text); border-color: var(--line-strong); }
.mobile-menu { display: none; }
.admin-chip { display: flex; align-items: center; gap: 8px; padding: 0 8px; }
.admin-chip > span { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-weight: 800; }
.admin-chip > div { display: grid; }
.admin-chip strong { font-size: 11px; }
.admin-chip small { color: var(--muted); font-size: 9px; }
.page-content { width: min(1460px, 100%); margin: 0 auto; padding: 24px; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 18px; }
.page-heading.compact { margin-bottom: 14px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 3px; font-size: clamp(23px, 3vw, 30px); letter-spacing: -.04em; }
h2 { margin-bottom: 2px; font-size: 17px; letter-spacing: -.02em; }
.page-heading p, .muted { margin-bottom: 0; color: var(--muted); }

.button { min-height: 36px; display: inline-flex; align-items: center; justify-content: center; padding: 0 13px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--text); font-weight: 700; cursor: pointer; transition: .18s ease; }
.button:hover { transform: translateY(-1px); border-color: var(--line-strong); }
.button.primary { border-color: var(--accent); background: var(--accent); color: #fff; box-shadow: 0 8px 24px rgba(233, 75, 88, .16); }
.button.subtle { background: var(--surface-2); }
.button.full { width: 100%; }

.stats-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat-card { position: relative; min-height: 92px; display: flex; flex-direction: column; justify-content: space-between; padding: 14px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.stat-card span { color: var(--muted); font-size: 11px; font-weight: 700; }
.stat-card strong { font-size: 25px; letter-spacing: -.04em; }
.stat-card i { position: absolute; right: -17px; bottom: -21px; width: 55px; height: 55px; border-radius: 50%; background: var(--line); opacity: .5; }
.stat-card.active i { background: var(--green); }
.stat-card.unused i { background: var(--blue); }
.stat-card.expired i, .stat-card.disabled i { background: var(--accent); }

.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 16px 40px rgba(0, 0, 0, .08); }
.section-heading, .panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.section-heading h2, .panel-heading h2 { margin: 1px 0 0; }
.text-link { color: var(--accent); font-weight: 700; font-size: 11px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 9px 12px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 9px; letter-spacing: .08em; text-align: left; text-transform: uppercase; white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 65%, transparent); }
.align-right { text-align: right; }
code { font: 11px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; color: var(--text); }
code.device { color: var(--muted); }
.key-cell { max-width: 430px; display: flex; align-items: center; gap: 7px; padding: 0; border: 0; background: transparent; cursor: pointer; }
.key-cell code { display: block; overflow: hidden; text-overflow: ellipsis; }
.key-cell span { color: var(--muted); }
.key-cell.copied span { color: var(--green); }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 10px; font-weight: 700; }
.badge i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.active { color: var(--green); }
.badge.unused { color: var(--blue); }
.badge.expired, .badge.disabled { color: var(--accent); }
.row-actions { display: inline-flex; justify-content: end; gap: 5px; }
.mini-button { min-height: 27px; padding: 0 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2); color: var(--muted); font-size: 10px; font-weight: 700; cursor: pointer; }
.mini-button:hover { color: var(--text); border-color: var(--line-strong); }
.mini-button.positive { color: var(--green); }
.mini-button.danger { color: var(--accent); }
.mini-button:disabled { opacity: .35; cursor: not-allowed; }
.empty-table { min-height: 170px; display: grid; place-content: center; gap: 4px; text-align: center; }
.empty-table span { color: var(--muted); }

.filter-bar { display: grid; grid-template-columns: minmax(240px, 1fr) 170px auto; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.search-box { display: flex; align-items: center; gap: 8px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); }
.search-box span { color: var(--muted); font-size: 17px; }
.search-box input { width: 100%; border: 0; outline: 0; color: var(--text); background: transparent; }
.field { display: grid; gap: 5px; }
.field > span { color: var(--muted); font-size: 10px; font-weight: 700; }
input, select, textarea { width: 100%; min-height: 37px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; outline: 0; background: var(--surface-2); color: var(--text); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[readonly] { color: var(--muted); }
.form-panel, .generated-panel { margin-bottom: 12px; }
.generate-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding: 16px; }
.custom-duration-control { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, .7fr); align-items: end; gap: 12px; padding: 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); }
.toggle-control { position: relative; display: flex; align-items: center; gap: 10px; min-height: 37px; cursor: pointer; }
.toggle-control > input { position: absolute; width: 1px; height: 1px; padding: 0; opacity: 0; pointer-events: none; }
.toggle-track { width: 38px; height: 21px; position: relative; flex: 0 0 auto; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); transition: .18s ease; }
.toggle-track i { position: absolute; top: 3px; left: 3px; width: 13px; height: 13px; border-radius: 50%; background: var(--muted); transition: .18s ease; }
.toggle-control > input:checked + .toggle-track { border-color: var(--accent); background: var(--accent-soft); }
.toggle-control > input:checked + .toggle-track i { transform: translateX(17px); background: var(--accent); }
.toggle-control > input:focus-visible + .toggle-track { box-shadow: 0 0 0 3px var(--accent-soft); }
.toggle-copy { display: grid; }
.toggle-copy strong { font-size: 11px; }
.toggle-copy small { color: var(--muted); font-size: 10px; }
.custom-duration-field[hidden] { display: none; }
input:disabled, select:disabled { opacity: .55; cursor: not-allowed; }
.activation-note { grid-column: 1 / -1; display: flex; align-items: center; gap: 9px; padding: 10px; border: 1px solid rgba(112, 169, 255, .18); border-radius: 9px; background: rgba(112, 169, 255, .06); }
.activation-note > span { color: var(--blue); font-size: 17px; }
.activation-note div { display: grid; }
.activation-note strong { font-size: 11px; }
.activation-note p { margin: 0; color: var(--muted); font-size: 10px; }
.form-actions { grid-column: 1 / -1; display: flex; justify-content: end; gap: 8px; padding-top: 3px; }
.key-output { min-height: 150px; padding: 12px; border: 0; border-radius: 0 0 var(--radius) var(--radius); resize: vertical; font: 11px/1.7 ui-monospace, SFMono-Regular, Consolas, monospace; }
.alert { margin-bottom: 12px; padding: 10px 12px; border: 1px solid rgba(79, 209, 154, .25); border-radius: 9px; background: rgba(79, 209, 154, .08); color: var(--green); font-weight: 600; }
.alert.error { border-color: rgba(233, 75, 88, .25); background: var(--accent-soft); color: var(--accent); }

.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 22px; background: radial-gradient(circle at 15% 15%, var(--accent-soft), transparent 28%), var(--bg); }
.auth-shell { width: min(820px, 100%); display: grid; grid-template-columns: 1fr 360px; align-items: center; gap: 44px; }
.auth-shell.install-shell { width: min(900px, 100%); grid-template-columns: .8fr 1.2fr; }
.auth-intro h1 { margin: 13px 0 7px; font-size: 40px; }
.auth-intro p { max-width: 370px; color: var(--muted); }
.auth-intro .eyebrow { display: block; margin-top: 22px; color: var(--accent); }
.auth-panel { padding-bottom: 16px; }
.auth-panel > h2, .auth-panel > p, .auth-panel > a, .auth-panel > .eyebrow { margin-left: 16px; margin-right: 16px; }
.auth-panel > .eyebrow { display: block; padding-top: 16px; }
.auth-panel > .button { margin-top: 14px; width: calc(100% - 32px); }
.form-stack { display: grid; gap: 11px; padding: 16px; }
.auth-panel .alert { margin: 14px 16px 0; }
.form-grid.two { display: grid; grid-template-columns: 1fr 110px; gap: 10px; }
.divider { height: 1px; margin: 3px 0; background: var(--line); }

@media (max-width: 1050px) {
    .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: 0; transform: translateX(-102%); width: 220px; box-shadow: 18px 0 60px rgba(0, 0, 0, .34); transition: transform .2s ease; }
    .menu-open .sidebar { transform: translateX(0); }
    .mobile-menu { display: grid; }
    .topbar { padding: 0 13px; }
    .admin-chip > div { display: none; }
    .page-content { padding: 17px 13px; }
    .page-heading { align-items: start; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filter-bar { grid-template-columns: 1fr; }
    .generate-grid { grid-template-columns: 1fr; }
    .custom-duration-control { grid-template-columns: 1fr; }
    .auth-shell, .auth-shell.install-shell { grid-template-columns: 1fr; gap: 18px; }
    .auth-intro h1 { font-size: 30px; }
    .auth-intro p { margin-bottom: 0; }
}

@media (max-width: 480px) {
    .page-heading { display: grid; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .auth-body { padding: 12px; }
    .auth-intro { display: none; }
    .form-grid.two { grid-template-columns: 1fr; }
}
