:root {
  --font-heading: 'Orbitron', monospace;
  --font-body: 'Inter', sans-serif;
  --bg: #ffffff;
  --bg2: #f8f9fb;
  --bg3: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --accent: #06b6d4;
  --accent-dark: #0891b2;
  --accent-dim: rgba(6, 182, 212, 0.10);
  --text: #0a0f1e;
  --text-2: #374151;
  --muted: #6b7280;
  --success: #10b981;
  --success-dim: rgba(16, 185, 129, 0.10);
  --danger: #ef4444;
  --danger-dim: rgba(239, 68, 68, 0.10);
  --warning: #f59e0b;
  --warning-dim: rgba(245, 158, 11, 0.10);
  --sidebar-bg: #0a1628;
  --sidebar-text: #6b849e;
  --sidebar-active-bg: rgba(6, 182, 212, 0.12);
  --sidebar-active-text: #06b6d4;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 6px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.06);
  --transition: 0.14s ease;
  --max-width: 1200px;
}

html[data-theme='light'] {
  --bg: #ffffff;
  --bg2: #f8f9fb;
  --bg3: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0a0f1e;
  --text-2: #374151;
  --muted: #6b7280;
  --sidebar-bg: #0a1628;
  --sidebar-text: #6b849e;
  --sidebar-active-bg: rgba(6, 182, 212, 0.12);
  --sidebar-active-text: #06b6d4;
}

html[data-theme='dark'] {
  --bg: #05050a;
  --bg2: #0d0d18;
  --bg3: #131325;
  --card: #0f0f1e;
  --border: rgba(255,255,255,0.08);
  --text: #f0f4f8;
  --text-2: #cbd5e1;
  --muted: #64748b;
  --sidebar-bg: #070711;
  --sidebar-text: rgba(107,132,158,0.6);
  --sidebar-active-bg: rgba(6,182,212,0.12);
  --sidebar-active-text: #06b6d4;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow: 0 4px 6px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg2);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

h1,h2,h3,h4,h5,h6 {
  font-family: var(--font-heading);
  margin: 0;
  color: var(--text);
}
h1 { font-size: 2rem; font-weight: 700; line-height: 1.25; }
h2 { font-size: 1.5rem; font-weight: 600; line-height: 1.3; }
h3 { font-size: 1.25rem; font-weight: 600; line-height: 1.35; }
p { margin: 0; }

img, svg { max-width: 100%; }

.container {
  width: min(100%, var(--max-width));
  margin: 0 auto;
  padding: 0 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  margin: 0 0 24px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: var(--transition);
  min-height: 44px;
  min-width: 44px;
  text-decoration: none;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); text-decoration: none; }
.btn-outline { background: transparent; border-color: var(--accent); color: var(--accent-dark); }
.btn-outline:hover { background: var(--accent-dim); text-decoration: none; }
.btn-secondary { background: var(--bg2); border-color: var(--border); color: var(--text-2); }
.btn-secondary:hover { background: var(--bg3); text-decoration: none; }
.btn-danger { background: transparent; border-color: rgba(239,68,68,0.3); color: var(--danger); }
.btn-danger:hover { background: var(--danger-dim); text-decoration: none; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 34px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-success { background: var(--success-dim); color: var(--success); }
.badge-warning { background: var(--warning-dim); color: var(--warning); }
.badge-danger  { background: var(--danger-dim);  color: var(--danger);  }
.badge-accent  { background: var(--accent-dim);  color: var(--accent-dark); }
.badge-muted   { background: var(--bg3); color: var(--muted); }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px;
  font-family: var(--font-body);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}
.form-group { margin-bottom: 16px; }
.form-row { display: grid; gap: 16px; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 580px; }
th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
}
tr:hover td { background: var(--bg2); }
tr:last-child td { border-bottom: none; }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}
.empty-state svg { margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 14px; margin: 0 0 16px; }

/* KPI cards */
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; }
.kpi-card { position: relative; border-top: 3px solid var(--accent); }
.kpi-label { font: 600 11px/1.3 var(--font-heading); color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.kpi-value { margin-top: 8px; font: 700 1.75rem/1.2 var(--font-heading); color: var(--text); font-variant-numeric: tabular-nums; }
.kpi-value.loading { color: var(--muted); animation: pulse 1.2s infinite; }
.kpi-sub { margin-top: 4px; font-size: 14px; color: var(--muted); }

/* Live dot */
.live-dot {
  display: inline-block;
  width: 7px; height: 7px;
  background: var(--success);
  border-radius: 50%;
  animation: livePulse 2s infinite;
  flex-shrink: 0;
}

/* Layout helpers */
.stack { display: grid; gap: 16px; }
.flex { display: flex; align-items: center; gap: 8px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.text-sm { font-size: 13px; }
.notice {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 14px;
  color: var(--text-2);
  background: var(--bg2);
}

/* Sidebar shared */
.app-shell { display: flex; min-height: 100vh; background: var(--bg); }
.sidebar {
  width: 118px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  padding: max(12px,env(safe-area-inset-top)) 12px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid rgba(255,255,255,0.06);
  z-index: 120;
}
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.topbar {
  height: 58px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: max(0px,env(safe-area-inset-top)) 16px 0;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 110;
}
.topbar-inner {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.page-content { flex: 1; padding: 24px 16px max(24px,env(safe-area-inset-bottom)); }

.logo { font-family: var(--font-heading); font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 12px; text-align: center; }
.logo .accent { color: var(--accent); }

.sidebar-nav { margin-top: 20px; display: flex; flex-direction: column; gap: 4px; }
.sidebar-link {
  color: var(--sidebar-text);
  border-radius: var(--radius);
  padding: 11px 10px;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}
.sidebar-link:hover { background: rgba(255,255,255,0.06); text-decoration: none; }
.sidebar-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); }
.sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer { margin-top: auto; padding-top: 10px; }

.mobile-menu-btn, .theme-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-2);
  width: 44px; height: 44px;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.mobile-menu-btn { display: none; }

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 119;
}
.overlay.visible { display: block; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 24px 0 0;
}
.page-subtitle { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* Skeleton / animation */
.skeleton {
  background: linear-gradient(90deg, var(--bg2) 25%, var(--bg3) 50%, var(--bg2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}
.fade-in { animation: fadeIn 0.22s ease; }
.hidden { display: none !important; }

@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes livePulse { 0%,100% { opacity: 1; box-shadow: 0 0 0 0 rgba(16,185,129,0.4); } 50% { box-shadow: 0 0 0 4px rgba(16,185,129,0); } }

/* Action buttons */
.action-btn {
  background: none; border: none; cursor: pointer;
  padding: 5px; border-radius: var(--radius);
  color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  transition: color var(--transition), background var(--transition);
}
.action-btn:hover { color: var(--text); background: var(--bg2); }
.action-btn.danger:hover { color: var(--danger); background: var(--danger-dim); }

/* Responsive */
@media (max-width: 1024px) { .kpi-grid { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 767px) {
  h1 { font-size: 1.65rem; }
  .mobile-menu-btn { display: inline-flex; }
  .sidebar { position: fixed; left: -168px; top: 0; bottom: 0; transition: left 0.25s ease; }
  .sidebar.open { left: 0; }
  .page-content { padding: 16px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 479px) { .kpi-grid { grid-template-columns: 1fr; } }
@media (min-width: 768px) { .container { padding: 0 24px; } .topbar { padding-left: 24px; padding-right: 24px; } .page-content { padding: 24px; } h1 { font-size: 2rem; } }
