:root {
  color-scheme: dark;
  --bg: #070b14;
  --sidebar: #0b1120;
  --surface: #111827;
  --surface-raised: #172033;
  --surface-soft: #0d1525;
  --border: #25324a;
  --border-strong: #34435f;
  --text: #f8fafc;
  --text-secondary: #cbd5e1;
  --muted: #8fa0b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --success-soft: #123823;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-soft: #421820;
  --warning: #f59e0b;
  --warning-soft: #402c0c;
  --radius: 14px;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 28px 18px 20px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--primary);
  color: white;
  font-size: 17px;
  font-weight: 800;
}

.brand-copy strong { display: block; font-size: 17px; line-height: 1.2; }
.brand-copy span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; text-transform: uppercase; }

.nav-label {
  margin: 8px 12px 7px;
  color: #687a95;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.nav { display: grid; gap: 5px; }

.nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 44px;
  padding: 0 13px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 600;
}

.nav a:hover { background: #131d30; color: var(--text); }
.nav a.active { background: #1b2b47; color: white; }
.nav-icon { width: 20px; color: #7e93b2; text-align: center; font-size: 15px; }
.nav a.active .nav-icon { color: #60a5fa; }
.sidebar-footer { margin-top: auto; padding-top: 22px; }

.main {
  min-width: 0;
  width: 100%;
  max-width: 1560px;
  padding: 34px 40px 56px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow { margin: 0 0 5px; color: var(--primary); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.page-header h1 { margin: 0; font-size: 28px; line-height: 1.25; }
.page-header p { margin: 7px 0 0; color: var(--muted); }
.admin-chip { display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; }
.admin-avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: #1d4ed8; font-weight: 800; }
.admin-chip strong { display: block; font-size: 13px; }
.admin-chip span { display: block; color: var(--muted); font-size: 11px; }

.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  padding: 13px 15px;
  border: 1px solid #1f6a3e;
  border-radius: 11px;
  background: var(--success-soft);
  color: #bbf7d0;
}

.notice.error { border-color: #803040; background: var(--danger-soft); color: #fecaca; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat-card { padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: #16294a; color: #60a5fa; font-weight: 800; }
.stat-value { display: block; margin-top: 16px; font-size: 30px; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-meta { display: block; margin-top: 8px; color: var(--muted); font-size: 12px; }

.panel { margin-top: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.panel-header h2 { margin: 0; font-size: 17px; }
.panel-header p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.panel-body { padding: 22px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { min-width: 0; }
.field.span-full { grid-column: 1 / -1; }
.field label { display: block; margin-bottom: 7px; color: var(--text-secondary); font-size: 12px; font-weight: 650; }
.field .hint { display: block; margin-top: 6px; color: var(--muted); font-size: 11px; }

.input, .field input, .field select, .field textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  outline: none;
  background: var(--surface-soft);
  color: var(--text);
}

.field textarea { min-height: 90px; resize: vertical; }
.field input::placeholder, .field textarea::placeholder { color: #60718b; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: #60a5fa; box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15); }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; margin-top: 18px; }

.btn, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: var(--primary);
  color: white;
  font-weight: 700;
  cursor: pointer;
}

.btn:hover, button:hover { background: var(--primary-hover); }
.btn:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid rgba(96, 165, 250, 0.45); outline-offset: 2px; }
.btn.secondary, button.secondary { background: #202e45; border-color: #34445f; color: #dce8f8; }
.btn.secondary:hover, button.secondary:hover { background: #2a3a54; }
.btn.danger, button.danger { background: var(--danger-soft); border-color: #72303b; color: #fecaca; }
.btn.danger:hover, button.danger:hover { background: var(--danger-hover); color: white; }
.btn.ghost, button.ghost { background: transparent; border-color: var(--border); color: var(--text-secondary); }
.btn.small, button.small { min-height: 32px; padding: 5px 9px; font-size: 12px; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
.inline-form { display: inline-flex; margin: 0; }
.action-group { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }

.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; min-width: 840px; border-collapse: collapse; }
.data-table th, .data-table td { padding: 14px 16px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.data-table th { background: #0e1728; color: #8fa1bb; font-size: 11px; font-weight: 750; text-transform: uppercase; white-space: nowrap; }
.data-table td { color: var(--text-secondary); font-size: 13px; }
.data-table tbody tr:hover { background: rgba(30, 45, 70, 0.32); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.cell-primary { color: var(--text); font-weight: 700; }
.cell-subtitle { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.numeric { font-variant-numeric: tabular-nums; white-space: nowrap; }
.truncate { display: block; max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge { display: inline-flex; align-items: center; gap: 6px; min-height: 26px; padding: 4px 9px; border-radius: 999px; font-size: 11px; font-weight: 750; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.success { background: var(--success-soft); color: #86efac; }
.badge.danger { background: var(--danger-soft); color: #fca5a5; }
.badge.warning { background: var(--warning-soft); color: #fcd34d; }
.badge.neutral { background: #273247; color: #cbd5e1; }

.users-table { min-width: 880px; }
.checkbox { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 12px; white-space: nowrap; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); }

.user-dialog {
  width: min(560px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}
.user-dialog::backdrop { background: rgba(2, 6, 14, 0.78); }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.dialog-header h2 { margin: 0; font-size: 18px; }
.dialog-header p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.dialog-close { width: 34px; min-height: 34px; padding: 0; border-radius: 8px; background: transparent; border-color: var(--border); color: var(--muted); font-size: 20px; }
.dialog-close:hover { background: #202e45; color: white; }
.dialog-body { padding: 22px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }

.empty-state { padding: 40px 24px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; margin-bottom: 5px; color: var(--text-secondary); font-size: 14px; }

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.login-shell { width: min(430px, 100%); }
.login-brand { justify-content: center; padding-bottom: 22px; }
.login-card { padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0; font-size: 24px; text-align: center; }
.login-card > p { margin: 7px 0 24px; color: var(--muted); text-align: center; }
.login-card .field { margin-bottom: 15px; }
.login-card button { width: 100%; min-height: 44px; margin-top: 4px; }
.login-footer { margin-top: 18px; color: #657792; font-size: 11px; text-align: center; }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding-bottom: 14px; }
  .nav-label, .sidebar-footer { display: none; }
  .nav { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
  .nav a { flex: 0 0 auto; min-height: 38px; padding: 0 11px; }
  .main { padding: 24px 18px 44px; }
  .page-header { align-items: center; }
}

@media (max-width: 620px) {
  .stats-grid, .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .field.span-full { grid-column: auto; }
  .page-header { display: block; }
  .admin-chip { width: fit-content; margin-top: 16px; }
  .panel-header, .panel-body { padding: 17px; }
  .form-actions { justify-content: stretch; }
  .form-actions .btn, .form-actions button { flex: 1; }
}
