:root {
  --bg-base: #0A0F1E;
  --bg-surface: #111827;
  --bg-elevated: #1A2236;
  --bg-input: #0E1526;
  --border-subtle: rgba(255,255,255,0.06);
  --border-default: rgba(255,255,255,0.12);
  --border-strong: rgba(255,255,255,0.24);
  --text-primary: #F0F4FA;
  --text-secondary: #94A3B8;
  --text-tertiary: #5B6577;
  --accent: #14B8A6;
  --accent-strong: #0F9E8E;
  --accent-muted: rgba(20,184,166,0.14);
  --ok: #22C55E;   --ok-bg: #0D3B22;
  --warn: #F59E0B; --warn-bg: #3D2A06;
  --bad: #EF4444;  --bad-bg: #431414;
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body: 'DM Sans', 'Segoe UI', sans-serif;
  --radius-md: 8px; --radius-lg: 12px; --radius-xl: 16px;
  --ease-out: cubic-bezier(0,0,0.2,1);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg-base); color: var(--text-primary); font-family: var(--font-body); font-size: 16px; line-height: 1.5; }
body { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
a { color: var(--accent); }
h1, h2 { font-family: var(--font-display); font-weight: 400; line-height: 1.2; margin: 0 0 12px; }
h1 { font-size: 1.75rem; } h2 { font-size: 1.25rem; }
.muted { color: var(--text-secondary); font-size: 0.875rem; }

/* Shell */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top)); background: rgba(10,15,30,0.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle); }
.brand { font-family: var(--font-display); font-size: 1.15rem; flex: 1; white-space: nowrap; }
.brand small { font-family: var(--font-body); color: var(--text-secondary); font-size: 0.75rem; margin-left: 6px; }
main { max-width: 960px; margin: 0 auto; padding: 20px 16px 96px; }

/* Sidebar (Admin) */
.sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: 240px; z-index: 30; display: flex; flex-direction: column;
  background: var(--bg-surface); border-right: 1px solid var(--border-subtle); padding: calc(16px + env(safe-area-inset-top)) 12px 16px;
  transform: translateX(-100%); visibility: hidden; transition: transform 250ms var(--ease-out), visibility 0s linear 250ms; }
.side-brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: 1.2rem; padding: 4px 8px 20px; }
.mark-sm { width: 32px; height: 32px; border-radius: 9px; background: var(--accent-muted); color: var(--accent); display: grid; place-items: center; font-size: 1.05rem; }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-nav a { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: var(--radius-md);
  color: var(--text-secondary); text-decoration: none; font-weight: 500; transition: background 150ms, color 150ms; }
.side-nav a:hover { background: var(--bg-elevated); color: var(--text-primary); }
.side-nav a.active { background: var(--accent-muted); color: var(--accent); }
.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.side-foot { border-top: 1px solid var(--border-subtle); padding: 14px 12px 0; font-size: 0.9rem; }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 25; opacity: 0; pointer-events: none; transition: opacity 250ms; }
body.drawer-open .sidebar { transform: none; visibility: visible; transition: transform 250ms var(--ease-out); }
body.drawer-open .backdrop { opacity: 1; pointer-events: auto; }
.menu-btn, .side-close { font-size: 1.2rem; width: 44px; padding: 0; }
@media (min-width: 1024px) {
  .sidebar { transform: none; visibility: visible; transition: none; }
  .backdrop, .topbar .menu-btn, .side-brand .side-close { display: none; }
  body.has-sidebar .topbar, body.has-sidebar main { margin-left: 240px; }
  body.has-sidebar .brand-name { display: none; }
  body.has-sidebar .brand small { margin-left: 0; font-size: 0.875rem; }
}

/* Cards / forms */
.card { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-xl); padding: 20px; margin-bottom: 16px; animation: fadeUp 250ms var(--ease-out) both; }
.auth { max-width: 400px; margin: 8vh auto 0; }
.auth .mark { width: 44px; height: 44px; border-radius: 12px; background: var(--accent-muted); color: var(--accent);
  display: grid; place-items: center; font-family: var(--font-display); font-size: 1.4rem; margin-bottom: 16px; }
label { display: block; font-size: 0.875rem; color: var(--text-secondary); margin: 14px 0 6px; }
input, select { width: 100%; min-height: 48px; padding: 10px 14px; border-radius: var(--radius-md); border: 1px solid var(--border-default);
  background: var(--bg-input); color: var(--text-primary); font: inherit; font-size: 1rem; }
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input.pin { letter-spacing: 0.4em; font-size: 1.25rem; text-align: center; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px;
  border-radius: var(--radius-md); border: 1px solid transparent; background: var(--accent); color: #04211E; font: inherit;
  font-weight: 600; cursor: pointer; transition: background 150ms var(--ease-out), transform 100ms; }
.btn:hover { background: var(--accent-strong); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: progress; }
.btn.block { width: 100%; margin-top: 20px; }
.btn.ghost { background: transparent; color: var(--text-primary); border-color: var(--border-default); }
.btn.ghost:hover { background: var(--bg-elevated); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 0.875rem; }
.btn.danger { background: transparent; color: var(--bad); border-color: rgba(239,68,68,0.4); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.alert { margin-top: 14px; padding: 10px 14px; border-radius: var(--radius-md); background: var(--bad-bg); color: #FCA5A5; font-size: 0.9rem; }
.notice { margin-top: 14px; padding: 10px 14px; border-radius: var(--radius-md); background: var(--accent-muted); color: var(--accent); font-size: 0.9rem; }

/* Lists */
.list { display: grid; gap: 10px; }
.item { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: 14px 16px; }
.item .title { font-weight: 600; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.75rem; background: var(--bg-elevated); color: var(--text-secondary); margin-right: 4px; }
.badge.admin { background: var(--accent-muted); color: var(--accent); }
.badge.off { background: var(--bad-bg); color: #FCA5A5; }
.badge.warn { background: var(--warn-bg); color: #FCD34D; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border-subtle); vertical-align: top; }
th { color: var(--text-secondary); font-weight: 500; position: sticky; top: 0; background: var(--bg-surface); }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 0.8rem; color: var(--text-secondary); }
.table-wrap { overflow-x: auto; }

/* Dialog */
dialog { border: 1px solid var(--border-default); border-radius: var(--radius-xl); background: var(--bg-elevated); color: var(--text-primary);
  width: min(440px, calc(100vw - 32px)); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,0.6); }

/* Toast */
.toast { position: fixed; left: 16px; right: 16px; margin: 0 auto; width: fit-content; bottom: 24px; background: var(--bg-elevated); border: 1px solid var(--border-default);
  padding: 12px 18px; border-radius: 999px; z-index: 50; animation: fadeUp 250ms var(--ease-out) both; max-width: calc(100vw - 32px); }

@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@media (min-width: 768px) { main { padding-top: 28px; } h1 { font-size: 2rem; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
