/* ============================================================================
   theme.css — Chat Bot Operator Dashboard design system.
   Dark palette + cyan accent. Matches the Api Snap sister dashboards:
   dense data tables, count-first KPIs, clean & fast, no flashy animations.

   Public reusable classes (View agents may use freely):
     Layout : .app-shell .sidebar .main-col .topbar .view-mount
     Cards  : .card .card-head .card-body  | .kpi .kpi-grid .kpi-value .kpi-label .kpi-sub
     Tables : .table-wrap .table  (+ td.ta-right/.ta-center, tr.row-clickable, td.table-empty)
     Forms  : .input .btn (.btn-primary .btn-ghost .btn-danger) .form-row .form-error .field
     Bits   : .badge (.badge-ok .badge-warn .badge-bad .badge-neutral)
              .toast-host .toast  | .modal-backdrop .modal .modal-head/-body/-foot
              .skeleton .skeleton-line .skeleton-row .skeleton-block
     Utils  : .muted .small .mono .ta-right .stack .row .gap .grid-2 .pill
   ============================================================================ */

:root {
  /* ── Palette ───────────────────────────────────────────────────────────────
     Our touch: deep blue-black canvas with a faint indigo undertone (not flat
     grey), a brighter electric-cyan accent paired with an indigo secondary for
     accents/charts, and warmer status hues. Tuned for long-session legibility. */
  --bg-0: #080b11;        /* app background (deepest) */
  --bg-1: #0d1219;        /* sidebar / topbar */
  --bg-2: #121a24;        /* cards */
  --bg-3: #19232f;        /* inputs / hover */
  --bg-4: #243341;        /* borders-as-fill / active */
  --line: #223040;        /* hairline borders */
  --line-soft: #18222e;

  --txt-0: #eef3f8;       /* primary text */
  --txt-1: #b2c0cf;       /* secondary */
  --txt-2: #74879b;       /* muted */

  --accent: #2dd9f0;          /* electric cyan */
  --accent-strong: #5ee7fb;   /* hover / highlight cyan */
  --accent-dim: #0d7d96;      /* deep cyan (bar fills, focus) */
  --accent-soft: rgba(45, 217, 240, 0.12);
  --accent-ink: #042530;      /* text on a solid-accent surface */

  --accent-2: #8b7bf0;        /* indigo secondary (charts, accents) */
  --accent-2-soft: rgba(139, 123, 240, 0.14);

  --ok: #36d6a0;
  --ok-soft: rgba(54, 214, 160, 0.14);
  --warn: #f5c451;
  --warn-soft: rgba(245, 196, 81, 0.14);
  --bad: #f87a7a;
  --bad-soft: rgba(248, 122, 122, 0.14);

  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 224px;
  --topbar-h: 58px;
  /* Layered shadow + a hair of inset rim-light for depth on cards. */
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.35);
  --rim: inset 0 1px 0 rgba(255, 255, 255, 0.025);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  /* Subtle radial wash from the top-left so the canvas isn't dead-flat. */
  background:
    radial-gradient(1100px 620px at 12% -8%, rgba(45, 217, 240, 0.05), transparent 60%),
    radial-gradient(900px 540px at 100% 0%, rgba(139, 123, 240, 0.045), transparent 55%),
    var(--bg-0);
  background-attachment: fixed;
  color: var(--txt-0);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); }
code, .mono { font-family: var(--mono); font-size: 0.92em; letter-spacing: -0.01em; }
h1 { font-size: 21px; font-weight: 680; margin: 0 0 16px; letter-spacing: -0.02em; }
h2 { font-size: 16px; font-weight: 620; margin: 0 0 12px; letter-spacing: -0.01em; }
p { margin: 0 0 10px; }

::selection { background: var(--accent-soft); color: var(--accent-strong); }

/* Slim, themed scrollbars (WebKit) so overflow areas match the palette. */
* { scrollbar-width: thin; scrollbar-color: var(--bg-4) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--bg-4);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: #2f4254; background-clip: padding-box; }
*::-webkit-scrollbar-track { background: transparent; }

.muted { color: var(--txt-2); }
.small { font-size: 12px; }
.ta-right { text-align: right; }
.ta-center { text-align: center; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, var(--bg-1), var(--bg-0));
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.brand-logo { width: 28px; height: 28px; border-radius: 8px; flex: 0 0 auto; display: block; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--accent-ink);
  background: linear-gradient(135deg, var(--accent-strong), var(--accent-2));
  box-shadow: 0 0 18px rgba(45, 217, 240, 0.35);
}
.brand-text {
  font-size: 15px;
  background: linear-gradient(90deg, var(--txt-0), var(--accent-strong));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--txt-1);
  font-weight: 500;
  transition: background 0.14s ease, color 0.14s ease;
}
.nav-link:hover { background: var(--bg-2); color: var(--txt-0); }
.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent);
}
/* Active rail — a small cyan bar pinned to the link's left edge. */
.nav-link.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}
.nav-link.active .nav-icon { color: var(--accent); }
.nav-icon { display: inline-flex; color: var(--txt-2); transition: color 0.14s ease; }
.nav-link:hover .nav-icon { color: var(--txt-1); }
.nav-label { font-size: 13.5px; }

.sidebar-foot { padding: 8px; border-top: 1px solid var(--line-soft); }

.main-col { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-h);
  flex: 0 0 var(--topbar-h);
  background: rgba(13, 18, 25, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }

.view-mount {
  flex: 1;
  overflow: auto;
  padding: 22px 24px 40px;
}

/* ── Health pill + token chip ────────────────────────────────────────────── */
.health-pill {
  font-size: 12px;
  font-family: var(--mono);
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  white-space: nowrap;
}
.health-ok { color: var(--ok); border-color: var(--ok-soft); background: var(--ok-soft); }
.health-warn { color: var(--warn); border-color: var(--warn-soft); background: var(--warn-soft); }
.health-bad { color: var(--bad); border-color: var(--bad-soft); background: var(--bad-soft); }

.token-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--txt-1);
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-2);
}
.token-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--txt-2);
}
.is-admin .token-dot { background: var(--accent); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--txt-0);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}
.btn:hover { background: var(--bg-4); }
.btn:active { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 680;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.15) inset, 0 4px 14px rgba(45, 217, 240, 0.18);
}
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg-2); }
.btn-danger {
  background: var(--bad-soft);
  border-color: var(--bad);
  color: var(--bad);
}
.btn-danger:hover { background: var(--bad); color: #2a0c0c; }

/* ── Inputs ──────────────────────────────────────────────────────────────── */
.input, input[type="text"], input[type="search"], input[type="number"],
input[type="url"], select, textarea {
  font: inherit;
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--txt-0);
  padding: 8px 11px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.input:focus, input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
textarea.input { resize: vertical; font-family: var(--mono); font-size: 12.5px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > label { font-size: 12px; color: var(--txt-1); font-weight: 550; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-error { color: var(--bad); font-size: 12.5px; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm), var(--rim);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
}
.card-head h2 { margin: 0; }
.card-body { /* slot */ }
.error-panel { border-color: var(--bad-soft); }
.error-panel h2 { color: var(--bad); }

/* ── KPI tiles (count-first) ─────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.kpi {
  position: relative;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.012), transparent 40%),
    var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  overflow: hidden;
  box-shadow: var(--rim);
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.kpi::before {
  /* Hairline accent rail along the top edge of every KPI tile. */
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  opacity: 0.55;
}
.kpi:hover { border-color: var(--bg-4); transform: translateY(-1px); }
.kpi-value {
  font-size: 31px;
  font-weight: 720;
  letter-spacing: -0.025em;
  line-height: 1.05;
  color: var(--txt-0);
  font-variant-numeric: tabular-nums;
}
.kpi-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--txt-2);
  font-weight: 650;
}
.kpi-sub { font-size: 12px; color: var(--accent); }

/* ── Tables (dense) ──────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-2);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table thead th {
  text-align: left;
  padding: 11px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.055em;
  color: var(--txt-2);
  font-weight: 650;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
.table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--txt-0);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background 0.1s ease; }
.table tbody tr:hover { background: var(--bg-3); }
.table tr.row-clickable { cursor: pointer; }
/* Cyan edge cue on hover for clickable rows (drill-down affordance). */
.table tr.row-clickable:hover td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.table td.table-empty {
  text-align: center;
  color: var(--txt-2);
  padding: 28px 14px;
}

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-ok { color: var(--ok); background: var(--ok-soft); border-color: var(--ok-soft); }
.badge-warn { color: var(--warn); background: var(--warn-soft); border-color: var(--warn-soft); }
.badge-bad { color: var(--bad); background: var(--bad-soft); border-color: var(--bad-soft); }
.badge-neutral { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-soft); }
.pill { /* alias for a soft neutral chip */
  display: inline-flex; padding: 2px 9px; border-radius: 999px;
  background: var(--bg-3); border: 1px solid var(--line); font-size: 12px;
}

/* ── Toasts ──────────────────────────────────────────────────────────────── */
.toast-host {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 200px;
  max-width: 360px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--txt-0);
  box-shadow: var(--shadow);
  font-size: 13px;
  cursor: pointer;
  opacity: 0;
  transform: translateX(12px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast-in { opacity: 1; transform: translateX(0); }
.toast-success { border-left: 3px solid var(--ok); }
.toast-error { border-left: 3px solid var(--bad); }
.toast-warn { border-left: 3px solid var(--warn); }
.toast-info { border-left: 3px solid var(--accent); }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 10, 0.66);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
  padding: 20px;
}
.modal {
  width: 100%;
  max-width: 520px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow: auto;
}
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 18px 20px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
}
.modal .modal-foot { /* when foot lives inside body, drop the top border duplication */ }

/* ── Skeletons (loading) ─────────────────────────────────────────────────── */
@keyframes sk-pulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 0.85; } }
.skeleton, .skeleton-block {
  background: linear-gradient(90deg, var(--bg-3), var(--bg-4), var(--bg-3));
  border-radius: var(--radius-sm);
  animation: sk-pulse 1.3s ease-in-out infinite;
}
.skeleton-lines, .skeleton-table { display: flex; flex-direction: column; gap: 10px; }
.skeleton-line { height: 14px; width: 100%; }
.skeleton-line:nth-child(2) { width: 80%; }
.skeleton-line:nth-child(3) { width: 60%; }
.skeleton-row { height: 38px; width: 100%; }
.skeleton-block { min-height: 92px; }

/* ── Small utilities ─────────────────────────────────────────────────────── */
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.gap { gap: 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* `hidden` must win over component display rules (e.g. .field is flex). */
[hidden] { display: none !important; }

/* A text-only button (secondary links such as "Operator token" in the sign-in). */
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.link-btn:hover { color: var(--accent-strong); }

/* Hide admin-only controls unless the body is flagged admin (app.js). */
.admin-only { display: none; }
.is-admin .admin-only { display: revert; }

/* ── Responsive-ish ──────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 64px 1fr; }
  .brand-text, .nav-label, .sidebar-foot { display: none; }
  .nav-link { justify-content: center; padding: 11px 0; }
  .grid-2 { grid-template-columns: 1fr; }
}
/* Phone width (R11.05): the health pill shrinks with an ellipsis so the role chip
   and Sign out stay on screen; no page-level horizontal scroll at 375px. */
@media (max-width: 520px) {
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-left { flex: 1 1 auto; min-width: 0; }
  .topbar-right { flex: 0 0 auto; gap: 6px; }
  .health-pill { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .view-mount { padding: 16px 12px 32px; }
}

/* Signed out with the sign-in modal dismissed (app.js showSignedOut). */
.signed-out-card { max-width: 420px; margin: 18vh auto 0; padding: 28px; text-align: center; }
.signed-out-card h2 { margin: 0 0 8px; }
.signed-out-card p { margin: 0 0 20px; }
