:root {
  --bg: #f6f7f8;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --panel-3: #f3f4f6;
  --text: #111827;
  --text-2: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-2: #d1d5db;
  --soft-brand: #fff7ed;
  --brand: #d97706;
  --brand-2: #b45309;
  --brand-hover: #92400e;
  --accent: #fbbf24;
  --sidebar: #1c2a20;
  --sidebar-text: #9db8a7;
  --sidebar-muted: #6b8a76;
  --danger: #b91c1c;
  --warn: #92400e;
  --ok: #15803d;
  --blue: #1d4ed8;
  --shadow: 0 1px 2px rgba(17, 24, 39, .06), 0 8px 24px rgba(17, 24, 39, .045);
  --shadow-strong: 0 18px 44px rgba(17, 24, 39, .14), 0 4px 12px rgba(17, 24, 39, .08);
  --radius: 8px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2128;
  --panel-3: #21262d;
  --text: #f0f6fc;
  --text-2: #c9d1d9;
  --muted: #8b949e;
  --line: #30363d;
  --line-2: #444c56;
  --soft-brand: #241a0b;
  --brand: #f59e0b;
  --brand-2: #fbbf24;
  --brand-hover: #d97706;
  --accent: #f4d35e;
  --danger: #ff8a80;
  --warn: #ffd166;
  --ok: #8ce7b8;
  --sidebar: #0d1117;
  --sidebar-text: #9db8a7;
  --sidebar-muted: #6b8a76;
  --blue: #8ab4f8;
  --shadow: 0 1px 2px rgba(0, 0, 0, .26), 0 8px 24px rgba(0, 0, 0, .18);
  --shadow-strong: 0 18px 44px rgba(0, 0, 0, .36);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 30% -10%, color-mix(in srgb, var(--soft-brand) 62%, transparent) 0, transparent 340px),
    linear-gradient(180deg, color-mix(in srgb, var(--bg) 92%, var(--soft-brand)) 0, var(--bg) 300px);
  color: var(--text);
  font-family: "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}
body.login-open { overflow: hidden; }

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 252px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--sidebar) 94%, #fbbf24) 0, var(--sidebar) 280px),
    var(--sidebar);
  color: var(--sidebar-text);
  border-right: 0;
  padding: 0;
  z-index: 20;
  box-shadow: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
}
.brand img { border-radius: var(--radius); background: rgba(255, 255, 255, .08); box-shadow: 0 0 0 1px rgba(251, 191, 36, .2); }
.brand strong { display: block; color: #fff; font-size: 17px; font-weight: 850; }
.brand span { display: block; color: var(--sidebar-muted); font-size: 10.5px; margin-top: 1px; text-transform: uppercase; font-weight: 700; }

.nav { display: grid; gap: 0; padding: 10px 0; }
.nav-item {
  border: 0;
  background: transparent;
  color: var(--sidebar-text);
  text-align: left;
  padding: 10px 16px;
  border-radius: 0;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-right: 3px solid transparent;
  font-size: 13.5px;
  font-weight: 650;
  transition: all .14s ease;
}
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #f3f4f6; }
.nav-item.active {
  background: rgba(251, 191, 36, .1);
  color: var(--accent);
  border-right-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(251, 191, 36, .03);
}
.nav-icon {
  width: 20px;
  height: auto;
  flex-shrink: 0;
  text-align: center;
  font-size: 16px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  margin-left: 252px;
  min-height: 60px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 22px;
  box-shadow: 0 1px 2px rgba(17, 24, 39, .06);
}
.topbar h1 { margin: 0; font-size: 16px; font-weight: 800; line-height: 1.15; letter-spacing: 0; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.top-actions { display: flex; gap: 9px; align-items: center; }

.main {
  margin-left: 252px;
  padding: 24px;
  max-width: 1440px;
}
.view { display: none; }
.view.active { display: block; }

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.section-stack { display: grid; gap: 14px; }

.home-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(260px, .7fr);
  gap: 18px;
  align-items: stretch;
  margin-bottom: 14px;
  padding: 24px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--sidebar) 94%, #fbbf24), var(--sidebar) 68%),
    var(--sidebar);
  color: #f9fafb;
  border: 1px solid rgba(251, 191, 36, .18);
  border-radius: var(--radius);
  box-shadow: var(--shadow-strong);
}
.home-kicker {
  margin: 0 0 8px;
  color: #fbbf24;
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}
.home-hero h2 {
  margin: 0;
  font-size: 27px;
  line-height: 1.12;
  font-weight: 900;
}
.home-hero p { margin: 10px 0 0; color: #b6c7bd; max-width: 640px; }
.home-hero-side {
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .045);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04);
}
.home-hero-side span { color: #9db8a7; font-size: 12px; font-weight: 750; text-transform: uppercase; }
.home-hero-side strong { font-size: 24px; line-height: 1.1; }
.home-hero-side small { color: #c7d6cc; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  padding: 14px 18px 0;
}
.panel-title { margin: 0; font-size: 16px; font-weight: 850; letter-spacing: 0; color: var(--text); }
.panel-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.panel-body { padding: 14px 18px 18px; }

.stat {
  padding: 16px;
  min-height: 116px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.stat::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0) 56%, rgba(217, 119, 6, .07));
  pointer-events: none;
}
.stat span { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.stat strong { display: block; margin-top: 8px; font-size: 28px; font-weight: 900; line-height: 1.05; font-variant-numeric: tabular-nums; }
.stat small { display: block; margin-top: 8px; color: var(--muted); }
.stat.featured {
  background: linear-gradient(180deg, color-mix(in srgb, var(--panel) 92%, var(--soft-brand)), var(--panel));
  border-color: color-mix(in srgb, var(--brand) 28%, var(--line));
}
.stat.featured strong { color: var(--brand-2); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.form-grid .wide { grid-column: span 2; }
.form-grid .full { grid-column: 1 / -1; }

.label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.field {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 9px 10px;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(17, 24, 39, .02);
}
.field:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(217, 119, 6, .2); }
.field.compact { min-width: 155px; }
textarea.field { min-height: 84px; resize: vertical; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius);
  min-height: 42px;
  padding: 9px 13px;
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(17, 24, 39, .04);
  transition: transform .14s ease, background .14s ease, border-color .14s ease, color .14s ease, box-shadow .14s ease;
}
.btn.primary { background: linear-gradient(180deg, #e38a16, var(--brand)); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); color: var(--danger); background: color-mix(in srgb, var(--panel) 92%, #fee2e2); }
.btn:hover, .icon-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(17, 24, 39, .08); }
.icon-btn {
  min-width: 42px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
}
.theme-toggle {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  box-shadow: var(--shadow);
  transition: transform .14s ease, background .14s ease, border-color .14s ease, color .14s ease;
}
.theme-toggle:hover {
  transform: translateY(-1px);
  background: var(--panel-3);
  border-color: var(--line-2);
}
.theme-toggle-icon {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #111827;
  color: #fbbf24;
  font-size: 16px;
  line-height: 1;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08), 0 2px 6px rgba(17, 24, 39, .18);
}
.theme-toggle.is-dark .theme-toggle-icon {
  background: #fef3c7;
  color: #92400e;
}
#menu-btn { display: none; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-weight: 800; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
tbody tr { transition: background .14s ease; }
tbody tr:hover { background: color-mix(in srgb, var(--panel) 88%, var(--panel-2)); }
td.actions { width: 1%; white-space: nowrap; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 750;
  border: 1px solid var(--line);
}
.badge.ok { color: var(--ok); background: color-mix(in srgb, var(--panel) 80%, #dcfce7); border-color: color-mix(in srgb, var(--ok) 24%, var(--line)); }
.badge.warn { color: var(--warn); background: color-mix(in srgb, var(--panel) 80%, #fef3c7); border-color: color-mix(in srgb, var(--warn) 24%, var(--line)); }
.badge.danger { color: var(--danger); background: color-mix(in srgb, var(--panel) 80%, #fee2e2); border-color: color-mix(in srgb, var(--danger) 24%, var(--line)); }
button:disabled {
  cursor: not-allowed;
  opacity: .55;
  transform: none !important;
}

.list { display: grid; gap: 10px; }
.row-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), color-mix(in srgb, var(--panel) 86%, var(--panel-2)));
}
.row-item strong { display: block; }
.row-item span { color: var(--muted); font-size: 13px; }

.bar {
  height: 10px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--line) 60%, transparent);
}
.bar > span {
  display: block;
  height: 100%;
  width: var(--w, 0%);
  background: linear-gradient(90deg, var(--brand), var(--accent));
}

.empty {
  padding: 26px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.empty strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
}

.toast-wrap {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 8px;
  z-index: 50;
}
.toast {
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: color-mix(in srgb, var(--sidebar) 84%, rgba(0, 0, 0, .38));
  backdrop-filter: blur(12px);
}
.login-box {
  width: min(380px, 100%);
  display: grid;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 24px 48px rgba(17, 24, 39, .16);
  padding: 22px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}
.login-brand strong { display: block; font-size: 18px; }
.login-brand span { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.login-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .38);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 60;
}
.modal[hidden] { display: none; }
.modal-box {
  width: min(760px, 100%);
  max-height: 88vh;
  overflow: auto;
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 18px; }
#modal-body { padding: 16px; }

.switch-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}

@media (max-width: 980px) {
  .grid.cols-4, .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .home-hero { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .18s ease;
  }
  body.menu-open .sidebar { transform: translateX(0); }
  .topbar, .main { margin-left: 0; }
  .topbar {
    align-items: flex-start;
    padding: 12px;
    min-height: 74px;
    flex-wrap: wrap;
  }
  #menu-btn { display: inline-block; }
  .top-actions { align-items: stretch; width: 100%; }
  .top-actions .field.compact { flex: 1; min-width: 0; }
  .main { padding: 12px; }
  .home-hero { padding: 18px; }
  .home-hero h2 { font-size: 22px; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2, .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .stat strong { font-size: 23px; }
  table, thead, tbody, tr, th, td { display: block; }
  table { min-width: 0; }
  thead { display: none; }
  tbody { display: grid; gap: 10px; }
  tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 10px;
  }
  td {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 10px;
    border-bottom: 0;
    padding: 7px 0;
  }
  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
  }
  td.actions {
    width: auto;
    white-space: normal;
    grid-template-columns: 1fr;
  }
  td.actions::before { content: ""; display: none; }
  td.actions .btn { margin: 2px 4px 2px 0; }
}
