/* Gharysh admin console — design tokens + components (contract M4 §4).
   Dark-first, transcribed from the approved "Gharysh Console" design cards
   (foundations/tokens, components/core, the five screens). Every style lives
   here: the CSP (default-src 'none'; style-src 'self') forbids inline style
   blocks and inline style attributes, so pages carry only classes and the JS
   sets the one genuinely dynamic property — a meter's fill width — through the
   CSSOM (el.style.width), which CSP does not restrict. */

:root {
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222220;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --hairline: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-soft: #86b6ef;
  --accent-deep: #184f95;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
}

* { margin: 0; box-sizing: border-box; }

.hidden { display: none !important; }

body {
  background: var(--page);
  color: var(--ink);
  font: 400 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--accent); }

/* ---- app shell: sidebar + main ------------------------------------------ */

.app { display: flex; min-height: 100vh; }

.side {
  width: 212px; flex: none; border-right: 1px solid var(--hairline);
  padding: 20px 12px; display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 0 8px 18px; }
.brand .name { font-size: 16px; font-weight: 650; }
.nav a {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  border-radius: 8px; color: var(--ink-2); text-decoration: none;
  font-size: 13.5px; margin-bottom: 2px;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: rgba(57, 135, 229, 0.13); color: var(--ink); font-weight: 600; }
.nav svg { flex: none; opacity: 0.85; }
.side .bottom { margin-top: auto; }
.side .bottom a {
  display: flex; align-items: center; gap: 9px; padding: 7px 10px;
  color: var(--muted); text-decoration: none; font-size: 12.5px;
}
.side .bottom a:hover { color: var(--ink-2); }
.side .bottom .version {
  padding: 7px 10px; color: var(--muted); font-size: 11px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.top {
  height: 56px; flex: none; border-bottom: 1px solid var(--hairline);
  display: flex; align-items: center; padding: 0 24px; gap: 12px;
}
.top h1 { font-size: 16px; font-weight: 650; margin-right: auto; }
.top .bc { font-size: 14px; color: var(--muted); margin-right: auto; }
.top .bc b { color: var(--ink); font-weight: 650; }
.top .bc .sep { margin: 0 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--hairline);
  border-radius: 999px; padding: 4px 11px; font-size: 12px; color: var(--ink-2);
}
.chip code { font-family: var(--mono); font-size: 11px; }
.chip .dot { width: 6px; height: 6px; border-radius: 3px; background: var(--good); }
.signout { color: var(--muted); font-size: 12.5px; text-decoration: none; cursor: pointer; background: none; border: 0; }
.signout:hover { color: var(--ink-2); }
.content { padding: 24px; display: grid; gap: 18px; }
.stack { display: grid; gap: 14px; }

/* ---- type ---------------------------------------------------------------- */

.mono { font-family: var(--mono); }

/* ---- dashboard tiles ----------------------------------------------------- */

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.tile .lbl { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.tile .val { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; }
.tile .val small { font-size: 15px; font-weight: 600; color: var(--ink-2); margin-left: 2px; }
.tile .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.tile .sub b { color: var(--ink-2); font-weight: 600; }

/* ---- panels -------------------------------------------------------------- */

.cols { display: grid; grid-template-columns: 1fr 320px; gap: 18px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.panel.clip { overflow: hidden; }
.panel .head { display: flex; align-items: baseline; padding: 14px 18px 10px; }
.panel .head.center { align-items: center; }
.panel .head h2 { font-size: 14px; font-weight: 600; margin-right: auto; }
.panel .head a { font-size: 12.5px; color: var(--accent); text-decoration: none; }
.panel .body { padding: 4px 18px 16px; }
.rows { padding: 2px 18px 14px; }

/* buckets-by-usage rows (dashboard) */
.brow {
  display: grid; grid-template-columns: 150px 1fr 240px; gap: 14px;
  align-items: center; padding: 9px 0; border-bottom: 1px solid var(--hairline);
}
.brow:last-child { border-bottom: 0; }
.brow .bname { font-size: 13.5px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.dotv { width: 6px; height: 6px; border-radius: 3px; flex: none; }
.dotv.pub { background: var(--accent); }
.dotv.priv { background: var(--hairline); }
.brow .bval {
  font-size: 12.5px; color: var(--muted); text-align: right;
  font-variant-numeric: tabular-nums; display: flex; justify-content: flex-end;
  align-items: center; gap: 6px;
}
.brow .bval b { color: var(--ink-2); font-weight: 600; }
.brow .bval svg { flex: none; }
.brow a.bname { text-decoration: none; color: var(--ink); }
.brow a.bname:hover { text-decoration: underline; }

/* operations panel (dashboard) */
.oprow {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 18px; border-bottom: 1px solid var(--hairline);
  font-size: 13px; color: var(--ink-2);
}
.oprow:last-of-type { border-bottom: 0; }
.oprow .n { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); }
.oprow .ok { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.panel .foot {
  padding: 10px 18px 14px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--hairline);
}
.panel .foot .mono { font-size: 11px; }

/* ---- meters -------------------------------------------------------------- */
/* Track carries the dimmed hue, fill carries severity; JS sets fill width. */

.meter { height: 6px; border-radius: 3px; overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 3px; width: 0; }
.meter.is-normal { background: rgba(57, 135, 229, 0.22); }
.meter.is-normal > i { background: var(--accent); }
.meter.is-high { background: rgba(250, 178, 25, 0.20); }
.meter.is-high > i { background: var(--warning); }
.meter.is-critical { background: rgba(208, 59, 59, 0.20); }
.meter.is-critical > i { background: var(--critical); }
.meter.is-none { background: rgba(137, 135, 129, 0.18); }
.meter.is-none > i { background: var(--muted); }

.sev-high { color: var(--warning); }
.sev-critical { color: var(--critical); }

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

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--hairline); }
th {
  color: var(--muted); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.06em;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td code { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
td.name { font-weight: 600; }
td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; color: var(--ink-2); white-space: nowrap; }
td.pct { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
td.pct svg { vertical-align: -1px; margin-right: 4px; }
th.r, td.r { text-align: right; }
td.dim { color: var(--ink-2); }
.arrow { color: var(--muted); }
.meter-cell .meter { min-width: 160px; }

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

.badge {
  display: inline-flex; align-items: center; gap: 5px; border-radius: 999px;
  padding: 2.5px 9px; font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 3px; }
.badge-public { background: rgba(57, 135, 229, 0.15); color: #86b6ef; }
.badge-public .dot { background: var(--accent); }
.badge-private { background: rgba(137, 135, 129, 0.15); color: var(--ink-2); }
.badge-private .dot { background: var(--muted); }
.badge-admin { background: rgba(144, 133, 233, 0.15); color: #b3aaf2; }
.badge-user { background: rgba(137, 135, 129, 0.15); color: var(--ink-2); }
.badge-active { background: rgba(12, 163, 12, 0.14); color: #4ec24e; }
.badge-active .dot { background: var(--good); }
.badge-disabled { background: rgba(137, 135, 129, 0.15); color: var(--muted); }
.badge-disabled .dot { background: var(--muted); }
.badge-rw { background: rgba(57, 135, 229, 0.15); color: #86b6ef; }
.badge-r { background: rgba(137, 135, 129, 0.15); color: var(--ink-2); }

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

.btn {
  border: 0; border-radius: 8px; padding: 8px 14px; font: 600 13px/1 system-ui, sans-serif;
  cursor: pointer; display: inline-flex; align-items: center; gap: 7px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #2f78d1; }
.btn-secondary { background: transparent; color: var(--ink-2); border: 1px solid var(--hairline); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--critical); border: 1px solid rgba(208, 59, 59, 0.4); }
.btn-danger:hover { background: rgba(208, 59, 59, 0.12); }
.btn-ghost { background: transparent; color: var(--accent); padding: 8px 8px; border: 0; font: 600 12.5px system-ui, sans-serif; cursor: pointer; }
.btn-ghost:hover { text-decoration: underline; }
.btn-ghost.danger { color: var(--critical); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-xs { padding: 2px 6px; font-size: 12px; }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.btn[disabled]:hover { background: var(--accent); text-decoration: none; }

/* ---- inputs -------------------------------------------------------------- */

label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.input {
  background: var(--page); border: 1px solid var(--hairline); border-radius: 8px;
  padding: 9px 12px; color: var(--ink); font: 400 13.5px system-ui, sans-serif;
}
.input.mono { font-family: var(--mono); font-size: 12.5px; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
select.input { cursor: pointer; }

/* ---- callouts ------------------------------------------------------------ */

.callout { display: flex; gap: 10px; border-radius: 10px; padding: 12px 14px; font-size: 13px; align-items: flex-start; }
.callout.center { align-items: center; }
.callout svg { flex: none; margin-top: 1px; }
.callout-info { background: rgba(57, 135, 229, 0.10); border: 1px solid rgba(57, 135, 229, 0.25); color: var(--ink-2); }
.callout b { color: var(--ink); font-weight: 600; }
.callout code { font-family: var(--mono); font-size: 12px; color: var(--ink); }
.callout a { color: var(--accent); text-decoration: none; font-weight: 600; font-size: 12.5px; }
.callout .spacer { margin-left: auto; }

/* ---- toggles ------------------------------------------------------------- */

.toggle {
  width: 36px; height: 20px; border-radius: 10px; position: relative;
  display: inline-block; flex: none; border: 0; cursor: pointer; padding: 0;
}
.toggle i { position: absolute; top: 2px; width: 16px; height: 16px; border-radius: 8px; background: #fff; }
.toggle.on { background: var(--accent); }
.toggle.on i { right: 2px; }
.toggle.off { background: var(--hairline); }
.toggle.off i { left: 2px; }
.toggle[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---- bucket-detail specifics -------------------------------------------- */

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.usage { display: flex; align-items: baseline; gap: 14px; }
.usage .big { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; }
.usage .big small { font-size: 15px; color: var(--ink-2); font-weight: 600; }
.usage .of { color: var(--muted); font-size: 13px; }
.usage-meter { margin: 12px 0 6px; }
.usage-foot { display: flex; font-size: 12.5px; color: var(--muted); justify-content: space-between; font-variant-numeric: tabular-nums; gap: 12px; }

.setting { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--hairline); }
.setting:last-child { border-bottom: 0; }
.setting .txt { margin-right: auto; }
.setting .txt .t { font-size: 13.5px; font-weight: 600; }
.setting .txt .d { font-size: 12.5px; color: var(--muted); }
.setting .input { width: 130px; }

.tight th, .tight td { padding: 9px 0; }
.tight td code { overflow-wrap: anywhere; }
.row-link { cursor: pointer; }
.events { color: var(--muted); font-size: 11.5px; }
.addrow { display: flex; gap: 8px; margin-top: 12px; }
.addrow .input { flex: 1; min-width: 0; }
.addrow select.input { flex: none; width: 150px; }
.owner-tag { color: var(--muted); font-size: 11.5px; }

/* ---- users specifics ----------------------------------------------------- */

.toolbar { display: flex; gap: 8px; }
.toolbar .input { width: 200px; }
.toolbar select.input { width: 120px; }
.caret { color: var(--muted); margin-right: 8px; display: inline-block; width: 10px; }
tr.userrow td { cursor: pointer; }
tr.userrow.expanded td { background: var(--surface-2); border-bottom: 0; }
tr.keypanel > td { background: var(--surface-2); padding: 0 16px 14px 40px; }
.keys { background: var(--surface); border: 1px solid var(--hairline); border-radius: 10px; overflow: hidden; }
.keys table td, .keys table th { padding: 9px 14px; }
.keys .foot-row { display: flex; align-items: center; padding: 10px 14px; }
.keycount { color: var(--muted); font-size: 12px; }
.keys .foot-row .spacer { flex: 1; min-width: 12px; }

/* ---- empty state --------------------------------------------------------- */

.empty { padding: 40px 18px; text-align: center; color: var(--muted); font-size: 13px; }
.loading { padding: 28px 18px; text-align: center; color: var(--muted); font-size: 13px; }

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

body.login {
  background: radial-gradient(560px 340px at 50% 30%, #14181f 0%, var(--page) 65%);
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
}
.login-wrap { width: 380px; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 11px; margin-bottom: 10px; }
.login-brand .name { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
.login-tag { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 26px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px; }
.login-card label { margin-bottom: 6px; }
.login-card .input { width: 100%; font-family: var(--mono); font-size: 13px; margin-bottom: 16px; }
.login-card .btn-signin { width: 100%; border: 0; border-radius: 8px; padding: 11px; background: var(--accent); color: #fff; font: 600 14px system-ui, sans-serif; cursor: pointer; }
.login-card .btn-signin:hover { background: #2f78d1; }
.login-card .btn-signin[disabled] { opacity: 0.5; cursor: progress; }
.login-hint { font-size: 12.5px; color: var(--muted); margin-top: 16px; line-height: 1.55; }
.login-hint code { font-family: var(--mono); font-size: 11.5px; color: var(--ink-2); }
.login-hint b { color: var(--ink-2); }
.login-error { color: var(--critical); font-size: 12.5px; margin-top: 14px; min-height: 16px; }
.login-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 22px; display: flex; gap: 14px; justify-content: center; align-items: center; }
.login-foot .sep { width: 3px; height: 3px; border-radius: 2px; background: var(--hairline); }

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

.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal {
  width: 460px; max-width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px; box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}
.modal h3 { font-size: 15px; font-weight: 650; margin-bottom: 6px; }
.modal p { font-size: 13px; color: var(--ink-2); margin-bottom: 14px; }
.modal p b { color: var(--ink); }
.modal label { margin-top: 4px; }
.modal .input { width: 100%; margin-bottom: 4px; }
.secretbox {
  display: flex; align-items: center; gap: 10px; background: var(--page);
  border: 1px solid var(--hairline); border-radius: 8px; padding: 10px 12px;
  font-family: var(--mono); font-size: 12.5px; color: var(--ink);
  margin-bottom: 14px; word-break: break-all;
}
.secretbox .val { flex: 1; min-width: 0; }
.secretbox .btn-ghost { margin-left: auto; flex: none; padding: 2px 6px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ---- toasts -------------------------------------------------------------- */

.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: 380px; }
.toast {
  border-radius: 10px; padding: 11px 14px; font-size: 13px; color: var(--ink);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); border: 1px solid var(--border);
  opacity: 1; transition: opacity 0.3s ease;
}
.toast--error { background: #2a1717; border-color: rgba(208, 59, 59, 0.5); }
.toast--info { background: var(--surface-2); }
.toast--success { background: #16241a; border-color: rgba(12, 163, 12, 0.4); }
.toast--out { opacity: 0; }

/* ---- recipes ------------------------------------------------------------- */

.recipe { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.recipe .head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--hairline); }
.recipe .head h2 { font-size: 14px; font-weight: 600; margin-right: auto; }
.recipe pre {
  margin: 0; padding: 16px 18px; overflow-x: auto; font-family: var(--mono);
  font-size: 12.5px; line-height: 1.7; color: var(--ink-2);
}
.recipe pre b { color: var(--ink); font-weight: 600; }
