/* CB Admin — dark dashboard styled after the 9Router console.
   Layout responds to viewport width AND to an explicit data-mode attribute, so
   the Desktop/Mobile toggle works on any screen (that was an explicit ask, not
   just media queries). */

:root {
  --bg: #0a0e13;
  --bg-soft: #0f151d;
  --panel: #121a24;
  --panel-2: #16202c;
  --line: #1f2b3a;
  --line-soft: #18222f;
  --txt: #e6edf6;
  --txt-dim: #9dafc4;
  /* Raised from #5f7288: helper text was failing comfortable contrast on the
     dark panels, which the first visual review flagged. */
  --txt-mute: #8296ad;
  --accent: #3b82f6;
  --accent-2: #22d3ee;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

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

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(59,130,246,.14), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 26px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}

.login-brand { display: flex; align-items: center; gap: 10px; }
.login-brand h1 { font-size: 19px; margin: 0; letter-spacing: -.01em; }
.login-sub { color: var(--txt-dim); font-size: 13px; margin: 6px 0 22px; }

.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 12px rgba(59,130,246,.7);
  flex: 0 0 auto;
}

.login-card label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--txt-mute);
  margin: 14px 0 6px;
}

.login-card input {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--txt);
  font-size: 15px;
  outline: none;
}
.login-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,.18);
}

.btn-primary {
  width: 100%;
  margin-top: 20px;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--accent), #2563eb);
  color: #fff;
  border: 0;
  border-radius: 9px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; filter: none; }

.alert {
  background: rgba(248,113,113,.12);
  border: 1px solid rgba(248,113,113,.35);
  color: #fecaca;
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 13px;
  margin-bottom: 4px;
}

.login-foot {
  margin: 20px 0 0;
  font-size: 11.5px;
  color: var(--txt-mute);
  text-align: center;
}

/* ---------- topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: rgba(10,14,19,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}
.topbar-left strong { font-size: 15px; letter-spacing: -.01em; }

.badge-provider {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent-2);
  background: rgba(34,211,238,.1);
  border: 1px solid rgba(34,211,238,.25);
  padding: 2px 7px;
  border-radius: 6px;
}

.seg {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}

.seg-btn {
  background: transparent;
  border: 0;
  color: var(--txt-dim);
  font-size: 12.5px;
  padding: 5px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
}
.seg-btn:hover { color: var(--txt); }
.seg-btn.is-on { background: var(--panel-2); color: var(--txt); box-shadow: inset 0 0 0 1px var(--line); }

.btn-ghost {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--txt-dim);
  padding: 6px 12px;
  border-radius: 9px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
/* Icon-only buttons were 37px wide on a phone — under the comfortable minimum. */
.btn-icon {
  min-width: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 0;
}
.btn-ghost:hover:not(:disabled) { color: var(--txt); border-color: #2a3a4d; }
.btn-ghost:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- layout ---------- */

.wrap {
  max-width: 1320px;
  min-width: 0;
  margin: 0 auto;
  padding: 18px;
  display: grid;
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-width: 0;
  padding: 16px 18px;
}

.panel-head, .add-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  min-width: 0;
}
.panel-head > *, .add-head > * { min-width: 0; }

.panel-head-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.panel-head h2, .add-head h2 {
  font-size: 14px;
  margin: 0;
  font-weight: 600;
  letter-spacing: .01em;
}

.muted { color: var(--txt-mute); font-size: 12px; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- persistent error banner ---------- */

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(248,113,113,.12);
  border: 1px solid rgba(248,113,113,.4);
  color: #fecaca;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
}
/* A class that sets `display` beats the UA stylesheet's [hidden] rule, so the
   banner stayed a 44px empty bar on every page load until this was added.
   Guard every element that combines `hidden` with a display rule. */
.banner[hidden],
[hidden] { display: none !important; }
.banner .btn-mini { border-color: rgba(248,113,113,.4); color: #fecaca; flex: 0 0 auto; }

/* ---------- stat cards ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 15px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.card-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--txt-mute);
}

.card-value {
  font-family: var(--mono);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -.02em;
  color: var(--txt);
  overflow-wrap: anywhere;
}

.card-foot { font-size: 11px; color: var(--txt-mute); }

/* ---------- add-account ---------- */

.add-desc { margin: -4px 0 12px; }
.add-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.add-actions .btn-primary { width: auto; margin-top: 0; }

.login-box {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--bg-soft);
  border: 1px dashed var(--line);
  border-radius: 10px;
}

.login-box a {
  display: block;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent-2);
  word-break: break-all;
  text-decoration: none;
}
.login-box a:hover { text-decoration: underline; }

.poll-state {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--txt-dim);
}
.poll-state.ok { color: var(--ok); }
.poll-state.bad { color: var(--bad); }

/* ---------- chart ---------- */

.chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 150px;
  padding-top: 6px;
  overflow: hidden;
}

.bar-col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  justify-content: flex-end;
  border-radius: 6px;
}
/* Keyboard users get the same per-bar values as hover users. */
.bar-col:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.chart-hint { margin: 10px 0 0; }
.chart-scale { margin: 0 0 4px; }

.poll-retry { margin-top: 8px; }

/* ---------- lock / quota panel ---------- */

.lock-card {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.lock-card:last-child { margin-bottom: 0; }

.lock-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.lock-head strong { font-size: 13.5px; }

.lock-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 5px 14px;
  font-size: 12.5px;
}

.lock-k { color: var(--txt-mute); white-space: nowrap; }
.lock-v { color: var(--txt-dim); font-family: var(--mono); font-size: 12px; }
.lock-v-dim { color: var(--txt-dim); font-size: 12px; font-style: italic; }
.lock-v-strong { color: var(--bad); font-weight: 600; }

/* Several models can be locked at once, each with its own countdown. */
.lock-pills { display: inline-flex; flex-wrap: wrap; gap: 4px; }

.lock-err-label {
  margin: 12px 0 4px;
  font-size: 11px;
  color: var(--txt-mute);
}

.lock-err {
  margin: 0 0 0;
  padding-top: 9px;
  border-top: 1px solid var(--line-soft);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--txt-mute);
  word-break: break-word;
}

.lock-hint { margin: 12px 0 0; line-height: 1.6; }
.lock-hint code {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--bg-soft);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--accent-2);
}

.bar {
  width: 100%;
  max-width: 46px;
  background: linear-gradient(180deg, var(--accent), #1d4ed8);
  border-radius: 4px 4px 0 0;
  min-height: 3px;
  transition: filter .15s;
}
.bar-col:hover .bar { filter: brightness(1.25); }

/* A day with no traffic keeps a visible baseline instead of vanishing. */
.bar-zero {
  background: var(--line);
  min-height: 3px;
  height: 3px !important;
}

.bar-lbl {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--txt-mute);
  white-space: nowrap;
}

/* ---------- table ---------- */

.table-wrap {
  overflow-x: auto;
  min-width: 0;
  max-width: 100%;
}

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.tbl th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--txt-mute);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.tbl td {
  padding: 10px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-family: var(--mono); white-space: nowrap; }
.tbl .acct-name { font-weight: 500; }

.pill {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  font-family: var(--mono);
  white-space: nowrap;
}
.pill-ok   { background: rgba(52,211,153,.13); color: var(--ok);   border: 1px solid rgba(52,211,153,.3); }
.pill-warn { background: rgba(251,191,36,.13); color: var(--warn); border: 1px solid rgba(251,191,36,.3); }
.pill-bad  { background: rgba(248,113,113,.13); color: var(--bad); border: 1px solid rgba(248,113,113,.3); }
.pill-dim  { background: rgba(139,155,176,.1); color: var(--txt-dim); border: 1px solid var(--line); }

.status-stack {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  min-width: 0;
  width: min(100%, 240px);
  max-width: 100%;
}
.status-detail {
  color: var(--txt-mute);
  font-size: 10px;
  font-family: var(--mono);
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.25;
  text-align: right;
}

/* Lock pills carry a model name plus a duration, which can exceed the column.
   Wrap instead of clipping, so neither the model nor the countdown is lost. */
.pill-lock {
  white-space: normal;
  line-height: 1.35;
  text-align: left;
  max-width: 190px;
}

.btn-mini {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--txt-dim);
  font-size: 11.5px;
  padding: 4px 9px;
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.btn-mini:hover:not(:disabled) { color: var(--txt); border-color: #2a3a4d; }
.btn-mini:disabled { opacity: .5; cursor: not-allowed; }

.empty {
  padding: 24px;
  text-align: center;
  color: var(--txt-mute);
  font-size: 13px;
}
.lock-empty-warning {
  color: var(--warn);
  border: 1px solid rgba(251,191,36,.22);
  border-radius: 8px;
  background: rgba(251,191,36,.05);
}

.notes {
  margin: 0;
  padding-left: 18px;
  color: var(--txt-dim);
  font-size: 12.5px;
  display: grid;
  gap: 6px;
}
.notes code {
  font-family: var(--mono);
  font-size: 11.5px;
  background: var(--bg-soft);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--accent-2);
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 20px);
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--txt);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: min(92vw, 460px);
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
  z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { border-color: rgba(248,113,113,.45); color: #fecaca; }
.toast.ok  { border-color: rgba(52,211,153,.45); color: #bbf7d0; }

/* =========================================================================
   MOBILE
   Applied when the viewport is narrow OR when the operator forces mobile mode.
   ========================================================================= */

@media (max-width: 980px) {
  html:not([data-mode="desktop"]) .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  html:not([data-mode="desktop"]) .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  html:not([data-mode="desktop"]) .wrap { padding: 12px; gap: 12px; }
  html:not([data-mode="desktop"]) .topbar { padding: 10px 12px; flex-wrap: wrap; }
  html:not([data-mode="desktop"]) .panel-head { align-items: flex-start; flex-direction: column; }
  html:not([data-mode="desktop"]) .panel-head-right { width: 100%; min-width: 0; justify-content: space-between; }
  html:not([data-mode="desktop"]) .panel-head-right > .muted { min-width: 0; overflow-wrap: anywhere; }
  html:not([data-mode="desktop"]) .card-value { font-size: 18px; }
  html:not([data-mode="desktop"]) .chart { height: 120px; }
}

/* A narrow physical viewport must never overflow, even if the operator
   explicitly selected Desktop mode. Keep the mode's visual semantics, but
   let the flex headers wrap instead of imposing a desktop min-content width. */
@media (max-width: 700px) {
  html[data-mode="desktop"] .topbar { padding: 10px 12px; flex-wrap: wrap; }
  html[data-mode="desktop"] .topbar-left,
  html[data-mode="desktop"] .topbar-right { min-width: 0; flex-wrap: wrap; }
  html[data-mode="desktop"] .wrap { padding: 12px; gap: 12px; }
  html[data-mode="desktop"] .panel-head { align-items: flex-start; flex-wrap: wrap; }
  html[data-mode="desktop"] .panel-head-right {
    width: 100%;
    min-width: 0;
    justify-content: space-between;
  }
  html[data-mode="desktop"] .panel-head-right > .muted {
    min-width: 0;
    overflow-wrap: anywhere;
  }
}

/* Forced mobile mode — independent of actual viewport width. */
html[data-mode="mobile"] .wrap { padding: 12px; gap: 12px; max-width: 560px; }
html[data-mode="mobile"] .topbar { padding: 10px 12px; flex-wrap: wrap; }
html[data-mode="mobile"] .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
html[data-mode="mobile"] .panel-head { align-items: flex-start; flex-direction: column; }
html[data-mode="mobile"] .panel-head-right { width: 100%; min-width: 0; justify-content: space-between; }
html[data-mode="mobile"] .panel-head-right > .muted { min-width: 0; overflow-wrap: anywhere; }
html[data-mode="mobile"] .card-value { font-size: 18px; }
html[data-mode="mobile"] .chart { height: 120px; }
html[data-mode="mobile"] .add-actions { flex-direction: column; }
html[data-mode="mobile"] .add-actions .btn-primary,
html[data-mode="mobile"] .add-actions .btn-ghost { width: 100%; }

/* Table becomes stacked cards in mobile mode. */
html[data-mode="mobile"] .table-wrap { overflow: visible; }
html[data-mode="mobile"] .tbl thead { display: none; }
html[data-mode="mobile"] .tbl,
html[data-mode="mobile"] .tbl tbody,
html[data-mode="mobile"] .tbl tr,
html[data-mode="mobile"] .tbl td { display: block; width: 100%; }

html[data-mode="mobile"] .tbl tr {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 10px;
  padding: 10px 12px;
}

html[data-mode="mobile"] .tbl td {
  border: 0;
  padding: 4px 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  text-align: right;
}

html[data-mode="mobile"] .tbl td::before {
  content: attr(data-label);
  color: var(--txt-mute);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  text-align: left;
  flex: 0 0 auto;
}

html[data-mode="mobile"] .tbl td.num { text-align: right; }
html[data-mode="mobile"] .tbl td:last-child { justify-content: flex-end; padding-top: 8px; }
html[data-mode="mobile"] .tbl td:last-child::before { content: ""; }

/* Touch targets: the first visual review measured the Test button and the
   window chips under the 44px comfortable minimum on a phone. */
html[data-mode="mobile"] .seg-btn { min-width: 40px; min-height: 40px; padding: 0 12px; font-size: 13px; }
html[data-mode="mobile"] .btn-ghost { min-height: 40px; }
html[data-mode="mobile"] .btn-mini { min-height: 40px; padding: 0 14px; font-size: 13px; }
html[data-mode="mobile"] .tbl td:last-child { padding-top: 10px; }

@media (max-width: 640px) {
  html:not([data-mode="desktop"]) .seg-btn { min-width: 40px; min-height: 40px; padding: 0 12px; font-size: 13px; }
  html:not([data-mode="desktop"]) .btn-ghost { min-height: 40px; }
  html:not([data-mode="desktop"]) .btn-mini { min-height: 40px; padding: 0 14px; font-size: 13px; }
}

/* Same stacking when the viewport itself is phone-sized. */
@media (max-width: 640px) {
  html:not([data-mode="desktop"]) .table-wrap { overflow: visible; }
  html:not([data-mode="desktop"]) .tbl thead { display: none; }
  html:not([data-mode="desktop"]) .tbl,
  html:not([data-mode="desktop"]) .tbl tbody,
  html:not([data-mode="desktop"]) .tbl tr,
  html:not([data-mode="desktop"]) .tbl td { display: block; width: 100%; }
  html:not([data-mode="desktop"]) .tbl tr {
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 10px;
    padding: 10px 12px;
  }
  html:not([data-mode="desktop"]) .tbl td {
    border: 0; padding: 4px 0;
    display: flex; justify-content: space-between; gap: 12px; text-align: right;
  }
  html:not([data-mode="desktop"]) .tbl td::before {
    content: attr(data-label);
    color: var(--txt-mute); font-size: 11px;
    text-transform: uppercase; letter-spacing: .05em;
    text-align: left; flex: 0 0 auto;
  }
  html:not([data-mode="desktop"]) .tbl td:last-child { justify-content: flex-end; padding-top: 8px; }
  html:not([data-mode="desktop"]) .tbl td:last-child::before { content: ""; }
  html:not([data-mode="desktop"]) .add-actions { flex-direction: column; }
  html:not([data-mode="desktop"]) .add-actions .btn-primary,
  html:not([data-mode="desktop"]) .add-actions .btn-ghost { width: 100%; }
}
