:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #14171c;
  --muted: #5d6673;
  --line: #e3e6ea;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --approved: #15803d;
  --declined: #b42318;
  --review: #b45309;
  --pending: #4b5563;
  --expired: #8b8f97;
  --chip: #eef1f4;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --panel: #171b21;
    --ink: #e7eaee;
    --muted: #9aa3ae;
    --line: #2a3038;
    --accent: #2dd4bf;
    --accent-ink: #062a27;
    --approved: #4ade80;
    --declined: #f87171;
    --review: #fbbf24;
    --pending: #9ca3af;
    --expired: #6b7280;
    --chip: #222831;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.error { color: var(--declined); min-height: 1.2em; margin: 8px 0; }

/* buttons and inputs */
button, input, select, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 7px 12px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.approve { border-color: var(--approved); color: var(--approved); font-weight: 600; }
button.decline { border-color: var(--declined); color: var(--declined); font-weight: 600; }
button.link { border: 0; background: none; color: var(--muted); padding: 0; text-align: left; }
button.link:hover { color: var(--ink); }
input, select, textarea {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 10px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; resize: vertical; }
label { display: block; font-weight: 600; margin: 12px 0 4px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow);
}
.login-card input { width: 100%; }
.login-card button { width: 100%; margin-top: 4px; }

/* shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  border-right: 1px solid var(--line); background: var(--panel); padding: 20px 14px;
  display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; margin-bottom: 2px; }
.logo {
  width: 22px; height: 22px; border-radius: 7px;
  background: conic-gradient(from 210deg, var(--accent), #6366f1, var(--accent));
}
.tenant { color: var(--muted); font-size: 12.5px; margin: 0 0 14px 30px; overflow-wrap: anywhere; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
nav a {
  color: var(--ink); text-decoration: none; padding: 7px 10px; border-radius: 8px;
  display: flex; justify-content: space-between; align-items: center;
}
nav a:hover { background: var(--chip); }
nav a.active { background: var(--chip); font-weight: 600; }
.badge {
  background: var(--review); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700;
  padding: 0 7px; line-height: 18px;
}
main { padding: 28px 32px 48px; min-width: 0; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }

/* panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; align-content: start; align-items: start; }
.tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.two { grid-template-columns: 2fr 1fr; }
.tile .num { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.tile .sub { color: var(--muted); font-size: 12.5px; }
.tile.review .num { color: var(--review); }

/* chart */
.chart svg { width: 100%; height: 200px; display: block; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .gridline { stroke: var(--line); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.c-approved { fill: var(--approved); background: var(--approved); }
.c-needs_review { fill: var(--review); background: var(--review); }
.c-declined { fill: var(--declined); background: var(--declined); }
.c-expired { fill: var(--expired); background: var(--expired); }
.c-pending, .c-processing { fill: var(--pending); background: var(--pending); }

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) 36px; gap: 8px; align-items: center; font-size: 12.5px; }
.bar-row .track { grid-column: 1 / -1; height: 6px; background: var(--chip); border-radius: 4px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--accent); }
.bar-row .count { text-align: right; color: var(--muted); }

/* status, chips */
.status {
  display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12.5px; white-space: nowrap;
}
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.s-approved { color: var(--approved); }
.s-declined { color: var(--declined); }
.s-needs_review { color: var(--review); }
.s-pending, .s-processing { color: var(--pending); }
.s-expired { color: var(--expired); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--chip); border-radius: 999px; padding: 1px 9px; font-size: 12px; white-space: nowrap; }
.chip.warn { color: var(--review); }
.chip.bad { color: var(--declined); }

/* tables */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--chip); }
.pager { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.empty { color: var(--muted); padding: 28px 0; text-align: center; }

/* detail */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.sections { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.back { margin-bottom: 12px; }
.review-box textarea { min-height: 70px; margin-bottom: 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.notice { border-left: 3px solid var(--review); padding: 8px 12px; background: var(--chip); border-radius: 6px; margin-bottom: 16px; }
.policy-editor textarea { min-height: 360px; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; }
.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: var(--bg);
  padding: 10px 14px; border-radius: 10px; font-size: 13px; box-shadow: 0 6px 24px rgba(0,0,0,.2);
}

@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 14px 16px; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .tenant { margin: 0 0 8px; }
  main { padding: 20px 16px 40px; }
}
a.panel { color: inherit; text-decoration: none; }
a.panel:hover { border-color: var(--muted); }
.field input, .field select { width: 100%; }
form.panel .actions { margin-top: 14px; }
