:root {
  --bg: #f3f6f2;
  --bg-grad-1: #e9efe7;
  --bg-grad-2: #f3f6f2;
  --surface: #ffffff;
  --surface-2: #f2f5f0;
  --ink: #1b2a21;
  --muted: #5d6f63;
  --line: #e1e7df;
  --line-strong: #ccd6cb;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --accent-dark: #25402f;
  --accent-soft: #dbeede;
  --brand-bar: #25402f;
  --brand-mint: #a5d6b9;
  --ok: #2f7d54;
  --ok-soft: #d9f0e1;
  --warn: #8a5a12;
  --warn-soft: #f8ecd3;
  --bad: #b42318;
  --bad-soft: #fde4e1;
  --shadow: 0 1px 2px rgba(20, 40, 30, .05), 0 10px 28px rgba(20, 40, 30, .07);
  --radius: 14px;
  --radius-sm: 9px;
  color-scheme: light;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1712;
    --bg-grad-1: #11201a;
    --bg-grad-2: #0e1712;
    --surface: #15211b;
    --surface-2: #1a2820;
    --ink: #e8eee9;
    --muted: #9aa99f;
    --line: #27352c;
    --line-strong: #34453a;
    --accent: #7cc6a0;
    --accent-ink: #08231a;
    --accent-dark: #a5d6b9;
    --accent-soft: #1a3a2b;
    --brand-bar: #1b2f24;
    --brand-mint: #a5d6b9;
    --ok: #5bd39a;
    --ok-soft: #123524;
    --warn: #fbbf24;
    --warn-soft: #3a2e10;
    --bad: #f87171;
    --bad-soft: #3a1c1a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 32px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 500; }

h1, h2, h3 { margin: 0; letter-spacing: -.01em; line-height: 1.25; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }

/* ---- Controls ---- */
button, input, select, textarea { font: inherit; color: var(--ink); }
button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0 18px;
  font-weight: 650;
  cursor: pointer;
  transition: filter .15s ease, background .15s ease, transform .05s ease;
}
button:hover { filter: brightness(1.05); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: progress; }
button.secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line-strong);
}
button.secondary:hover { background: var(--surface-2); }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  background: var(--surface);
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 96px; resize: vertical; }
label { display: grid; gap: 6px; color: var(--muted); font-weight: 600; font-size: .9rem; }
form { display: grid; gap: 16px; }

/* ---- Brand ---- */
.brand { display: inline-flex; align-items: center; gap: 11px; }
.brand-mark {
  display: grid; place-items: center;
  width: 38px; height: 38px;
  background: var(--accent); color: var(--accent-ink);
  border-radius: 11px; font-weight: 800; font-size: 1.2rem;
  box-shadow: var(--shadow);
}
.brand-name { display: grid; font-weight: 750; font-size: 1.12rem; line-height: 1.05; }
.brand-name small { font-weight: 600; font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.brand-lg .brand-mark { width: 52px; height: 52px; border-radius: 15px; font-size: 1.7rem; }
.brand-lg .brand-name { font-size: 1.4rem; }
.brand-logo { height: 30px; width: auto; display: block; }
.brand-lg .brand-logo { height: 58px; }

/* ---- Login ---- */
.login-screen {
  min-height: 100%;
  display: grid;
  place-content: center;
  gap: 20px;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--bg-grad-1), transparent),
    linear-gradient(180deg, var(--bg-grad-2), var(--bg));
}
.login-card {
  width: min(92vw, 400px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px 28px;
  display: grid;
  gap: 22px;
}
.login-card .brand { justify-content: center; }
.login-foot { text-align: center; font-size: .85rem; }

/* ---- App shell ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px clamp(14px, 4vw, 28px);
  background: var(--brand-bar);
  color: #eef5ef;
  border-bottom: 1px solid rgba(0, 0, 0, .25);
}
.topbar .muted { color: rgba(238, 245, 239, .66); }
.topbar .brand-name { color: #fff; }
.topbar .brand-name small { color: rgba(238, 245, 239, .7); }
.topbar .brand-mark { background: var(--brand-mint); color: #1d3326; }
.topbar .user-meta strong { color: #fff; }
.topbar .user-meta span { color: rgba(238, 245, 239, .66); }
.topbar .avatar { background: var(--brand-mint); color: #1d3326; }
.topbar button.secondary {
  background: rgba(255, 255, 255, .12);
  color: #fff;
  border-color: rgba(255, 255, 255, .28);
}
.topbar button.secondary:hover { background: rgba(255, 255, 255, .2); }
.user-box { display: flex; align-items: center; gap: 12px; }
.user-meta { display: grid; text-align: right; line-height: 1.2; }
.user-meta strong { font-size: .95rem; }
.user-meta span { font-size: .78rem; }
.avatar {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-dark);
  font-weight: 750;
}

.tabs {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 12px clamp(14px, 4vw, 28px) 0;
  max-width: 1140px; margin: 0 auto; width: 100%;
}
.tabs button {
  min-height: 40px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0 16px;
  font-weight: 600;
}
.tabs button:hover { background: var(--surface-2); color: var(--ink); filter: none; }
.tabs button.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}

.content {
  max-width: 1140px; margin: 0 auto; width: 100%;
  padding: 20px clamp(14px, 4vw, 28px) 48px;
}
.panel { display: none; }
.panel.active { display: grid; gap: 18px; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.panel-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 14px; flex-wrap: wrap;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(16px, 3vw, 24px);
  display: grid; gap: 16px;
}

/* ---- Metrics ---- */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(186px, 1fr));
  gap: 14px;
}
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: grid; gap: 8px; align-content: start;
  min-height: 96px;
}
.metric-label { color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.metric-value { font-size: 1.5rem; font-weight: 720; line-height: 1.15; }
.metric-value.accent { color: var(--accent); }
.metric-value.ok { color: var(--ok); }
.metric-value.warn { color: var(--warn); }
.metric-value.bad { color: var(--bad); }

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 650;
  line-height: 1.5;
  white-space: nowrap;
}
.badge + .badge { margin-left: 4px; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

/* ---- Forms (grid) ---- */
.gridform {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  align-items: end;
}
.gridform button { align-self: end; }
.wide { grid-column: 1 / -1; }
.choices {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  display: flex; flex-wrap: wrap; gap: 16px;
  padding: 12px 14px; margin: 0;
}
.choices label, .confirm { display: flex; align-items: center; gap: 9px; color: var(--ink); font-weight: 600; }
.choices input, .confirm input { width: auto; }
fieldset { border: 0; padding: 0; margin: 0; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: 11px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
thead th {
  position: sticky; top: 0;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--accent-soft) 30%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9rem; }
.row-actions { display: flex; gap: 8px; }
.row-actions button { min-height: 34px; padding: 0 12px; }

/* ---- Alerts ---- */
.alert-list { display: grid; gap: 10px; }
.alert {
  width: 100%; text-align: left;
  border: 1px solid color-mix(in srgb, var(--bad) 30%, var(--line));
  border-left: 5px solid var(--bad);
  border-radius: var(--radius-sm);
  background: var(--bad-soft);
  color: var(--bad);
  padding: 13px 15px;
  font-weight: 600;
}
button.alert { cursor: pointer; font-weight: 700; min-height: 0; }
button.alert:hover { filter: brightness(.99); }
.alert strong, .alert span { display: block; }
.alert span { margin-top: 4px; font-weight: 600; color: color-mix(in srgb, var(--bad) 80%, var(--ink)); }
.alert-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 11px; }
.alert-actions button { min-height: 36px; }

/* ---- Messages ---- */
.message { min-height: 20px; font-size: .9rem; color: var(--muted); font-weight: 600; margin: 0; }
.message.error { color: var(--bad); }
.message.ok { color: var(--ok); }

.admin-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .user-meta { display: none; }
  .tabs { gap: 4px; }
  .tabs button { padding: 0 12px; font-size: .92rem; }
  .panel-head { gap: 8px; }
  .admin-actions { width: 100%; }
  .admin-actions button { flex: 1; }
  th, td { padding: 10px 11px; font-size: .92rem; }
}
