:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-raised: #fafafa;
  --surface-hover: #f5f5f5;
  --border: #e8e8e8;
  --border-strong: #dcdcdc;
  --text: #0a0a0a;
  --text-secondary: #6b6b6b;
  --text-muted: #a3a3a3;
  --brand: #ff3131;
  --brand-contrast: #ffffff;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --neutral: #6b7280;
  --neutral-bg: #f3f4f6;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --sidebar-width: 240px;
  --sidebar-width-collapsed: 68px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --surface: #0a0a0a;
    --surface-raised: #111111;
    --surface-hover: #1a1a1a;
    --border: #1f1f1f;
    --border-strong: #2a2a2a;
    --text: #ffffff;
    --text-secondary: #a1a1a1;
    --text-muted: #6b6b6b;
    --success: #22c55e;
    --success-bg: rgba(34,197,94,0.12);
    --danger: #f87171;
    --danger-bg: rgba(248,113,113,0.12);
    --warning: #fbbf24;
    --warning-bg: rgba(251,191,36,0.12);
    --neutral: #9ca3af;
    --neutral-bg: rgba(156,163,175,0.12);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.5);
  }
}

:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #0a0a0a;
  --surface-raised: #111111;
  --surface-hover: #1a1a1a;
  --border: #1f1f1f;
  --border-strong: #2a2a2a;
  --text: #ffffff;
  --text-secondary: #a1a1a1;
  --text-muted: #6b6b6b;
  --success: #22c55e;
  --success-bg: rgba(34,197,94,0.12);
  --danger: #f87171;
  --danger-bg: rgba(248,113,113,0.12);
  --warning: #fbbf24;
  --warning-bg: rgba(251,191,36,0.12);
  --neutral: #9ca3af;
  --neutral-bg: rgba(156,163,175,0.12);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.02em; }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }
p { margin: 0 0 8px; color: var(--text-secondary); }
a { color: inherit; text-decoration: none; }

.numeric { font-variant-numeric: tabular-nums; font-weight: 650; letter-spacing: -0.01em; }

::selection { background: rgba(255,49,49,0.18); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease, transform 150ms ease;
}
.btn:hover { background: var(--surface-hover); }
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.btn-primary:hover { opacity: 0.88; background: var(--text); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(255,49,49,0.12);
}
.field .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.field .error-text { font-size: 12px; color: var(--danger); margin-top: 4px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

/* ---------- Cards / surfaces ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: rgba(220,38,38,0.2); }
.alert-success { background: var(--success-bg); color: var(--success); border-color: rgba(22,163,74,0.2); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral); }

.brand-accent-line { height: 2px; width: 32px; background: var(--brand); border-radius: 2px; }

/* ---------- Auth / install shell ---------- */
.centered-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-box {
  width: 100%;
  max-width: 400px;
}
.wizard-box {
  width: 100%;
  max-width: 480px;
}
.brand-mark {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 28px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-mark::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--brand);
  display: inline-block;
}

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  transition: width 200ms ease;
}
.sidebar.collapsed { width: var(--sidebar-width-collapsed); }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar nav a:hover { background: var(--surface-hover); color: var(--text); }
.sidebar nav a.active { background: var(--surface-hover); color: var(--text); font-weight: 650; position: relative; }
.sidebar nav a.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 2px;
  height: 16px;
  background: var(--brand);
  border-radius: 2px;
}
.sidebar .nav-group-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); padding: 14px 10px 6px; font-weight: 650; }
.main-content { flex: 1; min-width: 0; }
.topbar {
  height: 56px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}
.page-content { padding: 28px 32px; max-width: 1200px; }

.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; }
.stat-card .stat-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; font-weight: 550; }
.stat-card .stat-value { font-size: 24px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 28px; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 650; padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.data-table td { padding: 12px; border-bottom: 1px solid var(--border); }
table.data-table tr:last-child td { border-bottom: none; }

.empty-state { text-align: center; padding: 48px 24px; color: var(--text-secondary); }
.empty-state h3 { margin-bottom: 6px; color: var(--text); }

.mobile-only { display: none; }
.sidebar-backdrop { display: none; }

/* ---------- Slide-over panel ---------- */
.slideover-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 55;
}
.slideover-backdrop.open { display: block; }
.slideover-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 420px;
  max-width: 92vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 56;
  transform: translateX(100%);
  transition: transform 220ms ease;
  overflow-y: auto;
  padding: 24px;
}
.slideover-panel.open { transform: translateX(0); }

@media print {
  .sidebar, .topbar, .no-print, .sidebar-backdrop { display: none !important; }
  .main-content { width: 100%; }
  .page-content { padding: 0; max-width: none; }
  body { background: #fff; color: #000; }
  .card { border: none; padding: 0; }
}

@media (max-width: 900px) {
  .sidebar { position: fixed; z-index: 40; height: 100vh; transform: translateX(-100%); transition: transform 200ms ease; }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar-backdrop.visible { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 35; }
  .page-content { padding: 20px 16px; }
  .field-row { flex-direction: column; gap: 0; }
  .mobile-only { display: inline-flex; }
  .desktop-only { display: none; }
  .stat-grid { grid-template-columns: 1fr; }
  div[style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }
}
