/* Anselm Gateway admin — design tokens + hand-written styles.
   Bright, airy, light. All colors / spacing / radii / shadows go through CSS
   variables (no inline hardcoded color values anywhere in JS). */

:root {
  /* surfaces */
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #fbfcfd;
  --surface-hover: #f3f5f8;
  --overlay: rgba(17, 24, 39, 0.38);

  /* lines */
  --border: #e7eaef;
  --border-strong: #d6dbe3;

  /* text */
  --text: #1a2230;
  --text-soft: #5a6577;
  --text-faint: #8a93a3;

  /* accent (indigo) */
  --accent: #4f5bd5;
  --accent-strong: #3f49bf;
  --accent-soft: #eceefb;
  --accent-ring: rgba(79, 91, 213, 0.28);

  /* semantic */
  --ok: #1f9d63;
  --ok-soft: #e6f6ee;
  --warn: #c8870f;
  --warn-soft: #fcf3e0;
  --danger: #d6443a;
  --danger-soft: #fbe9e7;
  --info: #2a7de1;
  --info-soft: #e8f1fd;

  /* spacing scale */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  /* radii */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;

  /* shadows — soft, low */
  --shadow-sm: 0 1px 2px rgba(20, 28, 46, 0.05);
  --shadow-md: 0 4px 16px rgba(20, 28, 46, 0.07);
  --shadow-lg: 0 12px 40px rgba(20, 28, 46, 0.12);

  --row-h: 32px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app { min-height: 100%; }

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

/* ---------- login ---------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--s5);
  background:
    radial-gradient(900px 500px at 50% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--s6);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin-bottom: var(--s5);
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: var(--shadow-sm);
  flex: 0 0 auto;
}

.brand-name { font-weight: 650; font-size: 15px; letter-spacing: -0.01em; }
.brand-sub { color: var(--text-faint); font-size: 12px; }

.field { margin-bottom: var(--s4); }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 550;
  color: var(--text-soft);
  margin-bottom: var(--s2);
}

input[type="text"], input[type="password"], input.inp, textarea.inp, select.inp {
  width: 100%;
  height: 38px;
  padding: 0 var(--s3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
textarea.inp { height: auto; padding: var(--s2) var(--s3); resize: vertical; line-height: 1.5; }

input:focus, textarea.inp:focus, select.inp:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

input:disabled, textarea.inp:disabled {
  background: var(--surface-2);
  color: var(--text-faint);
  cursor: not-allowed;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  height: 36px;
  padding: 0 var(--s4);
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: background .12s, border-color .12s, box-shadow .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-hover); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:focus-visible { box-shadow: 0 0 0 3px var(--accent-ring); outline: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }

.btn-danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.btn-danger:hover { background: #f7ddd9; }

.btn-sm { height: 28px; padding: 0 var(--s3); font-size: 12px; }
.btn-full { width: 100%; height: 40px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-hover); }

/* ---------- shell ---------- */

.shell {
  display: grid;
  grid-template-columns: 224px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "side top" "side main";
  min-height: 100vh;
}

.topbar {
  grid-area: top;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--s5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar .page-title { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }

.topbar-right { display: flex; align-items: center; gap: var(--s3); }
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  font-size: 13px;
  color: var(--text-soft);
}
.user-dot {
  width: 8px; height: 8px; border-radius: var(--r-pill);
  background: var(--ok);
}

.sidebar {
  grid-area: side;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--s4) var(--s3);
  display: flex;
  flex-direction: column;
  gap: var(--s1);
}

.side-brand {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s3) var(--s5);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  height: 38px;
  padding: 0 var(--s3);
  border-radius: var(--r-sm);
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  user-select: none;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-strong); }
.nav-icon { width: 16px; text-align: center; opacity: .9; }

.main {
  grid-area: main;
  padding: var(--s5);
  overflow: auto;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s4);
  gap: var(--s3);
}
.section-head h2 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.section-sub { color: var(--text-faint); font-size: 12px; }

/* ---------- cards / metrics ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--s4);
  margin-bottom: var(--s5);
}

.metric {
  padding: var(--s4) var(--s5);
}
.metric .label {
  font-size: 12px;
  color: var(--text-faint);
  font-weight: 550;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.metric .value {
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin-top: var(--s2);
  font-variant-numeric: tabular-nums;
  /* A dual-value budget (e.g. "12,345,678 / 50,000,000") can overrun a narrow
     metric column — wrap rather than clip, and let very long values shrink a step
     so they stay on a sensible line instead of overflowing the card. */
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.2;
}
.metric .value.long { font-size: 19px; }
.metric .meta { font-size: 12px; color: var(--text-soft); margin-top: var(--s1); }

.progress {
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--surface-hover);
  overflow: hidden;
  margin-top: var(--s3);
}
.progress > span {
  display: block;
  /* Width is the ONE truly dynamic value (the live budget percentage). It is set
     via the CSSOM (el.style.width) in JS, which is exempt from the strict CSP's
     style-src — never as an HTML inline style attribute. */
  width: 0;
  height: 100%;
  background: var(--accent);
  border-radius: var(--r-pill);
  transition: width .4s ease;
}
.progress.warn > span { background: var(--warn); }
.progress.danger > span { background: var(--danger); }

/* ---------- badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 10px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}
.badge .dot { width: 7px; height: 7px; border-radius: var(--r-pill); background: currentColor; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: var(--surface-hover); color: var(--text-soft); }

/* ---------- alerts list ---------- */

.alert-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border);
}
.alert-row:last-child { border-bottom: none; }
.alert-bar { width: 3px; align-self: stretch; border-radius: var(--r-pill); background: var(--text-faint); }
.alert-bar.sev-critical { background: var(--danger); }
.alert-bar.sev-warning { background: var(--warn); }
.alert-bar.sev-info { background: var(--info); }
.alert-main { flex: 1; min-width: 0; }
.alert-reason { font-weight: 600; font-size: 13px; }
.alert-msg { color: var(--text-soft); font-size: 12px; }
.alert-time { color: var(--text-faint); font-size: 12px; white-space: nowrap; }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }
table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.tbl th {
  text-align: left;
  font-weight: 600;
  color: var(--text-faint);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  position: sticky;
  top: 0;
}
table.tbl td {
  padding: var(--s2) var(--s4);
  /* Compact rows: honor the --row-h (32px) design token rather than a hard-coded
     44px, so the "tight" intent actually lands. min-height keeps a row breathable
     when a cell wraps; padding gives vertical air without forcing tall rows. */
  height: var(--row-h);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tr:hover td { background: var(--surface-2); }

.mono { font-family: var(--mono); font-size: 12px; }
.id-cell { display: inline-flex; align-items: center; gap: var(--s2); }
.copy-btn {
  border: none; background: transparent; cursor: pointer;
  color: var(--text-faint); padding: 2px 4px; border-radius: 6px; font-size: 12px;
}
.copy-btn:hover { background: var(--surface-hover); color: var(--text); }
.row-actions { display: flex; gap: var(--s2); justify-content: flex-end; }

.list-foot {
  display: flex;
  justify-content: center;
  padding: var(--s4);
}

/* ---------- config ---------- */

.cfg-group { margin-bottom: var(--s5); }
.cfg-group-title {
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-faint);
  margin: 0 0 var(--s3);
}
.cfg-item {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: var(--s4);
  align-items: start;
  padding: var(--s4);
  border-bottom: 1px solid var(--border);
}
.cfg-item:last-child { border-bottom: none; }
.cfg-key { font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.cfg-default { color: var(--text-faint); font-size: 12px; margin-top: var(--s1); }
.cfg-range { color: var(--text-faint); font-size: 11px; margin-top: var(--s1); font-variant-numeric: tabular-nums; }
.cfg-note { color: var(--warn); font-size: 12px; margin-top: var(--s2); max-width: 48ch; }
.cfg-err { color: var(--danger); font-size: 12px; margin-top: var(--s2); }
.cfg-control { display: flex; flex-direction: column; gap: var(--s2); }
.masked {
  font-family: var(--mono);
  color: var(--text-faint);
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-sm);
  padding: 8px var(--s3);
  font-size: 13px;
}

/* ---------- audit ---------- */
.audit-action { font-weight: 600; }
.audit-target { font-family: var(--mono); font-size: 12px; color: var(--text-soft); }

/* ---------- modal ---------- */

.modal-host {
  position: fixed; inset: 0;
  background: var(--overlay);
  display: grid; place-items: center;
  padding: var(--s5);
  z-index: 50;
}
.modal {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--s5);
}
.modal h3 { margin: 0 0 var(--s2); font-size: 16px; }
.modal p { margin: 0 0 var(--s4); color: var(--text-soft); font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s4); }

/* ---------- toast ---------- */

#toast-host {
  position: fixed;
  right: var(--s5);
  bottom: var(--s5);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  z-index: 80;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-md);
  padding: var(--s3) var(--s4);
  font-size: 13px;
  max-width: 340px;
  animation: toast-in .18s ease;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- misc ---------- */

.banner-err {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--r-sm);
  padding: var(--s3) var(--s4);
  font-size: 13px;
  margin-bottom: var(--s4);
  font-weight: 550;
}
.empty {
  text-align: center;
  color: var(--text-faint);
  padding: var(--s7) var(--s4);
  font-size: 13px;
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: var(--r-pill);
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { display: grid; place-items: center; padding: var(--s7); }

.muted { color: var(--text-faint); }
.tnum { font-variant-numeric: tabular-nums; }

/* ---------- layout utilities ----------
   Small static layout helpers that replace former HTML inline `style=` attributes.
   The strict CSP (default-src 'self', no unsafe-inline) blocks HTML inline style
   attributes, so every static style lives in a class here; only genuinely dynamic
   values (e.g. progress width) are set through the CSSOM in JS. */

.spacer-8 { height: 8px; }
.row-inline { display: flex; align-items: center; gap: var(--s3); }
.row-gap8 { display: flex; gap: var(--s2); }
.cell-right { text-align: right; }

.badges-card {
  padding: var(--s4);
  display: flex;
  gap: var(--s3);
  flex-wrap: wrap;
  margin-bottom: var(--s5);
}
.gap-card { margin-bottom: var(--s5); }
.section-head-tight { margin-top: var(--s2); }
.subhead { margin: 0; font-size: 14px; }
.cfg-group-pad { padding: var(--s4) var(--s4) var(--s1); }
.export-card { max-width: 560px; }
.export-blurb { margin: var(--s2) 0 var(--s4); font-size: 13px; }

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-areas: "top" "main";
  }
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 224px;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .scrim {
    position: fixed; inset: 0; background: var(--overlay); z-index: 55;
  }
  .menu-btn { display: inline-flex; }
  .cfg-item { grid-template-columns: 1fr; }
}
.menu-btn { display: none; }
