/* Same design system as ../chat/style.css — same tokens, same .app/.sidebar/.main shell —
   so moving between chat and dashboard reads as one app, not two. Dashboard-specific
   components (tables, meters, chips) are new here since chat has no equivalent, but they're
   built from the same palette/type system rather than invented fresh. Status colors keep
   their soft/solid split from chat: soft backgrounds for read-only badges and chips, solid
   fills for buttons that actually do something (approve/reject), matching the composer's
   solid-accent Send button. */

:root {
  color-scheme: light;
  --bg: #f5f2ea;
  --surface: #ffffff;
  --surface-sunken: #ece6d7;
  --text: #2c2820;
  --muted: #85806f;
  --border: #e3ddcc;
  --accent: #c2683f;
  --accent-hover: #a8552f;
  --accent-soft: #f4e3d3;
  --accent-ink: #ffffff;

  --status-good: #4b7a3e;
  --status-good-soft: #e6efdf;
  --status-warning: #b8791f;
  --status-warning-soft: #f6e9d4;
  --status-critical: #a83b2e;
  --status-critical-soft: #f5e0dc;

  --font-display: "Source Serif 4", Georgia, "Iowan Old Style", serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;

  --shadow-sm: 0 1px 2px rgba(44, 40, 32, 0.05);
  --shadow-md: 0 6px 20px -8px rgba(44, 40, 32, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

button, input, select {
  font-family: inherit;
}

/* ---------- layout: identical shell to chat/style.css's .app/.sidebar/.main ---------- */

.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px 18px;
  background: var(--surface-sunken);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.main {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.dashboard-main {
  overflow-y: auto;
  padding: 32px 32px 48px;
}

/* ---------- sidebar ---------- */

.sidebar__brand h1 {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.sidebar__tagline {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.sidebar__link {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  padding: 2px 2px;
}

.sidebar__link:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ---------- sidebar tab nav ---------- */

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.sidebar__nav-item {
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar__nav-item:hover {
  color: var(--text);
  background: var(--surface);
}

.sidebar__nav-item.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.sidebar__nav-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sidebar__spacer {
  flex: 1;
}

.sidebar__note {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.sidebar__auth {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.auth-action {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.auth-action:hover {
  background: var(--accent-soft);
}

.auth-action:focus-visible,
.sidebar__link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- access denied ---------- */

.access-denied {
  background: var(--status-critical-soft);
  border: 1px solid var(--status-critical);
  border-radius: 8px;
  padding: 48px 32px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 520px;
  margin: 10vh auto 0;
}

.access-denied[hidden] {
  display: none;
}

.access-denied h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--status-critical);
}

.access-denied p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text);
}

/* ---------- dashboard content ---------- */

#dashboard-content {
  max-width: 1220px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

#dashboard-content[hidden] {
  display: none;
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.tab-panel[hidden] {
  display: none;
}

/* Plain-language explanation panel — 2-3 short lines, no data encoding, so it just uses
   body text rather than the panel/chip/badge visual language reserved for live data. */
.explainer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 1px 2px rgba(43, 38, 32, 0.05);
}

.explainer p {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
}

.explainer strong {
  color: var(--text);
}

.column {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 22px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 1px 2px rgba(43, 38, 32, 0.05);
  min-width: 0;
}

.column__header {
  padding: 0 22px;
}

.column__header h2 {
  margin: 0 0 2px;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.column__subtitle {
  font-size: 12px;
  color: var(--muted);
}

.column--gateway {
  border-left: 3px solid var(--accent);
}

.column--gateway .column__header h2 {
  font-size: 18px;
}

.column--litellm {
  padding: 22px;
  gap: 22px;
}

.column--litellm .column__header h2 {
  font-family: var(--font-display);
  font-size: 18px;
}

.column--litellm .panel--log {
  padding: 22px 0 0;
}

/* ---------- stat panels ---------- */

.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.panel__header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel__header-row h2 {
  margin: 0;
}

/* Meter: fill color carries severity (accent -> warning -> critical, set in JS by
   threshold); track is a fixed neutral so state reads from the fill alone. */
.meter__track {
  height: 12px;
  border-radius: 6px;
  background: var(--surface-sunken);
  overflow: hidden;
}

.meter__fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 6px;
  transition: width 0.4s ease, background-color 0.4s ease;
}

.meter__value {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* Hero figure: the number a judge watches. Stays in primary ink — severity is
   communicated by the status chip beside the label, not by coloring the figure itself. */
.hero {
  font-family: var(--font-mono);
  font-size: 44px;
  font-weight: 600;
  line-height: 1;
  color: var(--text);
}

.hero__label {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.stat-line {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

/* Status chips: icon + label together, never color alone. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.chip--good {
  background: var(--status-good-soft);
  color: var(--status-good);
}

.chip--warning {
  background: var(--status-warning-soft);
  color: var(--status-warning);
}

.chip--critical {
  background: var(--status-critical-soft);
  color: var(--status-critical);
}

.panel--log {
  padding: 22px 0 0;
}

.panel--log h2 {
  padding: 0 22px;
}

/* ---------- tables ---------- */

.table-wrap {
  max-height: 420px;
  overflow: auto;
  border-top: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

thead th.num,
td.num {
  text-align: right;
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

td.num {
  font-family: var(--font-mono);
}

tbody td.query-cell {
  white-space: normal;
  font-variant-numeric: normal;
  max-width: 320px;
}

tbody tr:hover {
  background: var(--surface-sunken);
}

td.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 12px;
  font-variant-numeric: normal;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.badge--ok {
  background: var(--status-good-soft);
  color: var(--status-good);
}

.badge--fallback {
  background: var(--status-warning-soft);
  color: var(--status-warning);
}

.badge--error {
  background: var(--status-critical-soft);
  color: var(--status-critical);
}

.badge--muted {
  background: var(--surface-sunken);
  color: var(--muted);
}

.query-cell code {
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--muted);
}

/* table-layout: auto lets a column with long, freely-wrappable content (the drafted-action
   JSON) shrink toward zero width, since word-break makes wrapping "free" for the browser —
   every word ends up on its own line instead of the column widening to fit. Fixed layout +
   explicit widths keeps this table's proportions sane regardless of content length. */
.column--gateway table {
  table-layout: fixed;
}

.column--gateway th:nth-child(1),
.column--gateway td:nth-child(1) {
  width: 11%;
}

.column--gateway th:nth-child(2),
.column--gateway td:nth-child(2) {
  width: 13%;
}

.column--gateway th:nth-child(3),
.column--gateway td:nth-child(3) {
  width: 14%;
}

.column--gateway th:nth-child(4),
.column--gateway td:nth-child(4) {
  width: 38%;
}

.column--gateway th:nth-child(5),
.column--gateway td:nth-child(5) {
  width: 12%;
}

.column--gateway th:nth-child(6),
.column--gateway td:nth-child(6) {
  width: 12%;
}

.column--gateway td {
  vertical-align: top;
  /* Overrides the general tbody td { white-space: nowrap } rule above — this table's
     columns are deliberately narrow (fixed layout), so short cells (time, requested-by,
     ticket type) need to wrap onto a second line instead of overflowing into their
     neighbor, which is what nowrap did here. */
  white-space: normal;
}

/* The full drafted-action JSON can run long — cap its own height and let it scroll
   independently, rather than stretching the whole row (and crowding the short cells beside
   it) to fit the entire payload. */
.column--gateway .query-cell code {
  max-height: 110px;
  overflow-y: auto;
}

.actions-cell {
  white-space: nowrap;
}

/* ---------- buttons: solid fills (they DO something), unlike badges/chips (soft, read-only) —
   same language as the composer's solid-accent Send button in chat/style.css ---------- */

.btn {
  border: none;
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  margin-right: 4px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-note {
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
}

.btn--approve {
  background: var(--status-good);
  color: #fff;
}

.btn--approve:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn--reject {
  background: var(--status-critical);
  color: #fff;
}

.btn--reject:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn--neutral {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn--neutral:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--accent);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.limit-line {
  display: block;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--muted);
  /* Was nowrap — fine while this only ever held a short "$5 / unlimited" limit value, but the
     "used, X left" remaining figure appended alongside daily/monthly limits can run longer
     than the column, and nowrap on a block element doesn't scroll, it just overflows past the
     cell/table edge. Wrap instead, and let the nested .cell-muted detail break onto its own
     line rather than spilling out. */
  white-space: normal;
  overflow-wrap: break-word;
}

.limit-line .cell-muted {
  display: inline-block;
}

.cell-muted {
  color: var(--muted);
  font-size: 12px;
}

.meter--compact .meter__track {
  height: 6px;
  margin-bottom: 4px;
}

/* ---------- create-user / edit-limits forms ----------
   Styled as their own elevated card (sunken fill + border + shadow) rather than a plain
   dashed-divider block — the panel around it is already --surface (white), so a distinct
   card is what makes "you're now editing" read as a state change, not just more table rows. */

.create-user-form {
  margin-top: 18px;
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.create-user-form[hidden] {
  display: none;
}

.create-user-form .form-row:first-child {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.create-user-form .form-row:first-child strong {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}

.form-row label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.form-row label.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-weight: 400;
  color: var(--text);
}

.form-row input[type="text"],
.form-row input[type="number"],
.form-row select {
  padding: 9px 11px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-row input:focus,
.form-row select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.create-user-form .form-row:last-child {
  padding-top: 2px;
}

.create-user-form .btn {
  padding: 9px 18px;
  font-size: 12.5px;
  border-radius: 7px;
}

.create-user-error {
  font-size: 12px;
  color: var(--status-critical);
}

.form-hint {
  margin: 0;
  font-size: 12px;
  font-style: italic;
  color: var(--muted);
}

/* ---------- responsive ---------- */

@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: 100vh;
  }

  .sidebar {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    gap: 10px;
  }

  .sidebar__brand h1 {
    font-size: 17px;
  }

  .sidebar__tagline,
  .sidebar__note {
    display: none;
  }

  .sidebar__nav {
    flex-direction: row;
    border-top: none;
    padding-top: 0;
    gap: 6px;
  }

  .sidebar__spacer {
    flex: 1 0 auto;
    min-width: 0;
  }

  .sidebar__auth {
    border-top: none;
    padding-top: 0;
  }

  .dashboard-main {
    padding: 20px 16px 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
