/* ============================================================
   Awall surface stylesheet: dashboard.css
   Split from styles.css (F1, issue #186) — NO rule changes.
   Owns: dashboard two-column layout, bar chart, guardrail ranking, status lists, system status, recent-log compact (S2)
   Concatenating every surfaces/*.css in base.html <link> order
   reproduces the original styles.css byte-for-byte.
   ============================================================ */
.dashboard-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-6);
  align-items: stretch;
}

/* Modern row modifiers (replace 4-col + dashboard-col span pattern) */
.dashboard-row--2-1 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.dashboard-row--2-1 > :first-child {
  grid-column: span 2;
}

.dashboard-row--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* Stacked dashboard rows: replace per-row inline margins with a sibling
   gap rule so spacing stays in CSS. */
.dashboard-row + .dashboard-row {
  margin-top: var(--space-6);
}

.dashboard-col {
  min-width: 0;
  grid-column: span 1;
}

.dashboard-col--wide {
  grid-column: span 3;
}

@media (max-width: 1100px) {
  .dashboard-row,
  .dashboard-row--2-1,
  .dashboard-row--3 {
    grid-template-columns: 1fr;
  }
  .dashboard-col,
  .dashboard-col--wide {
    grid-column: span 1;
  }
}

/* ---------------------------------------------------------
   Async refresh states (S2 #193)
   The dashboard body is re-fetched and innerHTML-swapped on range
   change / auto-refresh (dashboard.js). The region wraps the swap
   target so the refresh indicator and error banner survive the swap.

   "Updating" is a *busy* treatment, not a blank skeleton: the body
   already holds real (stale) data on a refresh, so it stays visible,
   dimmed, while a spinner pill marks it as refreshing — never wiped
   to grey placeholders. On failure the stale data is kept and an
   error banner offers a retry. The spinner reuses the sanctioned
   .btn--saving idiom (720ms); the global reduced-motion guard
   (core.css, F4 §8) freezes it, leaving the dim + pill legible. */
.dashboard-data-region {
  position: relative;
}

.dashboard-data-region:has(#dashboard-data-root[aria-busy="true"]) [data-dashboard-body] {
  opacity: 0.5;
  pointer-events: none;
  transition: opacity var(--transition-base);
}

.dashboard-refresh-indicator {
  position: absolute;
  top: var(--space-4);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-sticky);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--color-elevated);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-lift);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-body);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}

.dashboard-data-region:has(#dashboard-data-root[aria-busy="true"]) .dashboard-refresh-indicator {
  opacity: 1;
}

.dashboard-refresh-spinner {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  animation: dashboard-refresh-spin 720ms linear infinite;
}

@keyframes dashboard-refresh-spin {
  to { transform: rotate(360deg); }
}

/* Fetch-error banner: reuses .alert.alert-warning (feedback.css) for the
   colour treatment. The shared .alert:has(.alert-icon) rule (components.css)
   sets display:flex, which outranks the UA [hidden] { display:none } — so the
   banner would show even when not failing. Re-assert [hidden] at a higher
   specificity to restore the hidden-until-failure contract. */
.dashboard-data-region .dashboard-fetch-error[hidden] {
  display: none;
}

/* Pin the Retry button to the trailing edge of the shared flex alert layout. */
.dashboard-fetch-error__retry {
  margin-left: auto;
  flex-shrink: 0;
}

/* Secondary card-header used after a .card-divider inside the same
   card. The divider already has space above, this only adds the
   matching space below before the next title. */
.card-header.card-header--inner {
  margin-top: var(--space-4);
}

/* Recent requests table: widths in `ch` (character units) so each
   column scales with the table's font size and reliably fits both the
   uppercase header label and its typical cell content. With
   `table-layout: fixed` a column narrower than its header gets clipped,
   so each value below covers `max(headerWidth, typicalContentWidth)`
   plus the cell padding (~5ch).
     time     "HH:MM:SS"      mono 8ch   + "TIME"    header 4ch
     api-key  user-labelled name, ellipsizes when longer than 18ch
     model    name varies, ellipsizes when longer than 20ch
     latency  "3433ms"             6ch  + "LATENCY" header 8ch
   The Trigger / prompt column takes the remainder via `width: auto`. */
.data-table.data-table--recent-requests .col-time    { width: 14ch; }
.data-table.data-table--recent-requests .col-api-key { width: 18ch; }
.data-table.data-table--recent-requests .col-model   { width: 20ch; }
.data-table.data-table--recent-requests .col-latency { width: 14ch; text-align: right; }
.data-table.data-table--recent-requests td { vertical-align: top; overflow: hidden; }
.data-table.data-table--recent-requests td.log-latency {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}
.data-table.data-table--recent-requests td.log-api-key {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Recent Blocks card scroll. The query still returns 8 rows, but the
   card caps its vertical footprint so it stops dominating the row it
   shares with system-status. The thead sticks so the column meaning
   stays readable while scrolling. Focus-visible ring keeps keyboard
   users oriented when the container itself takes focus. */
.recent-blocks-scroll {
  max-height: 360px;
  overflow-y: auto;
  border-radius: var(--radius-input);
}
.recent-blocks-scroll:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
.recent-blocks-scroll .data-table--recent-requests thead th {
  position: sticky;
  top: 0;
  background: var(--color-elevated);
  z-index: 1;
}

/* ---------------------------------------------------------
   27. Bar chart (7-day)
   --------------------------------------------------------- */
.chart-legend {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
}

/* Soft-Semantic Rule (DESIGN.md §2): the 7-day chart legend reads sage /
   terracotta, not the saturated status green/red. palettes.css re-asserts the
   same tokens last; aligning here keeps this owned file self-consistent. */
.legend-dot--allowed { background: var(--bar-allowed); }
.legend-dot--blocked { background: var(--bar-blocked); }

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: var(--space-3);
  height: 140px;
  padding-bottom: 28px; /* space for labels */
  position: relative;
}

.bar-chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  position: relative;
  cursor: default;
  border-radius: 4px;
  outline: none;
}

.bar-chart-col:focus-visible {
  box-shadow: 0 0 0 2px var(--color-primary-focus-ring);
}

.bar-chart-bars {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column-reverse;
  align-items: stretch;
  gap: 2px;
  min-height: 0;
  position: relative;
}

.bar-chart-track {
  position: absolute;
  inset: 0;
  background: var(--color-border);
  opacity: 0.35;
  border-radius: 3px 3px 0 0;
  z-index: 0;
  transition: opacity var(--transition-fast);
  pointer-events: none;
}

.bar-chart-col:hover .bar-chart-track,
.bar-chart-col:focus-visible .bar-chart-track {
  opacity: 0.55;
}

.bar {
  width: 100%;
  border-radius: 3px 3px 0 0;
  min-height: 3px;
  transition: opacity var(--transition-fast);
  position: relative;
  z-index: 1;
}

.bar-chart-col:hover .bar { opacity: 0.85; }

/* Soft-Semantic Rule: bar fills are sage / terracotta so a high blocked-volume
   day does not light up the dashboard like an incident (DESIGN.md §2, §5, §6).
   palettes.css overrides these last with identical tokens. */
.bar--allowed {
  background: var(--bar-allowed);
  opacity: 0.95;
}

.bar--blocked {
  background: var(--bar-blocked);
  opacity: 0.95;
}

.bar-chart-tooltip {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
  min-width: 140px;
  padding: 8px 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-btn);
  box-shadow: var(--shadow-card);
  font-size: var(--font-size-xs);
  color: var(--color-text-body);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, calc(-100% - 10px));
  transition: opacity var(--transition-fast);
  white-space: nowrap;
}

.bar-chart-tooltip[data-visible="true"] {
  opacity: 1;
}

.bar-chart-tooltip__label {
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--color-text-heading);
}

.bar-chart-tooltip__rows {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.bar-chart-tooltip__row {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--color-text-muted);
}

.bar-chart-tooltip__row b {
  margin-left: auto;
  font-weight: 600;
  color: var(--color-text-heading);
  font-variant-numeric: tabular-nums;
}

.bar-chart-tooltip__row--total {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--color-border);
}

.bar-chart-tooltip__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.bar-chart-tooltip__dot--allowed { background: var(--bar-allowed); }
.bar-chart-tooltip__dot--blocked { background: var(--bar-blocked); }

.bar-chart-label {
  position: absolute;
  bottom: -24px;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  white-space: nowrap;
}

.bar-chart-total {
  position: absolute;
  bottom: -8px;
  font-size: 10px;
  color: var(--color-text-muted);
  opacity: 0;
}

/* ---------------------------------------------------------
   28. Guardrail ranking (top triggered)
   --------------------------------------------------------- */
.guardrail-ranking {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.guardrail-ranking-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
  font-size: var(--font-size-sm);
}

.guardrail-ranking-item:last-child {
  border-bottom: none;
}

.guardrail-ranking-name {
  color: var(--color-text-body);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
}

.guardrail-ranking-count {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: var(--color-danger-bg);
  color: var(--color-danger-strong);
  padding: 2px 10px;
  border-radius: var(--radius-pill);
}

.guardrail-ranking-count-num {
  font-weight: 700;
  font-size: var(--font-size-sm);
  font-variant-numeric: tabular-nums;
}

.guardrail-ranking-count-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---------------------------------------------------------
   29. Guardrail status list (compact)
   --------------------------------------------------------- */
.guardrail-status-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.guardrail-status-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--font-size-sm);
  color: var(--color-text-body);
}

.guardrail-status-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Status mark on the dashboard guardrail list: pairs the colored
   dot with an uppercase label so state is never carried by colour
   alone (DESIGN.md status-plus-label rule). */
.guardrail-status-mark {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.guardrail-status-mark--active   .guardrail-status-text { color: var(--color-success-strong); }
.guardrail-status-mark--monitor  .guardrail-status-text { color: var(--color-warning-strong); }
.guardrail-status-mark--inactive .guardrail-status-text { color: var(--color-text-muted); }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot--active  { background: var(--color-success); }
.status-dot--monitor { background: var(--color-warning); }
.status-dot--inactive { background: var(--color-border); }
/* Legacy aliases */
.status-dot--on  { background: var(--color-success); }
.status-dot--off { background: var(--color-border); }

/* ---------------------------------------------------------
   30. System status panel
   --------------------------------------------------------- */
.system-status-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.system-status-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--font-size-sm);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

.system-status-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.system-status-label {
  color: var(--color-text-muted);
}

.system-status-value {
  font-weight: 600;
  color: var(--color-text-heading);
}

.status-pill {
  font-size: var(--font-size-xs);
  font-weight: 600;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-pill--ok {
  background: var(--color-success-bg);
  color: var(--color-success-strong);
}

.status-pill--err {
  background: var(--color-danger-bg);
  color: var(--color-danger-strong);
}

/* ---------------------------------------------------------
   31. Recent log table — compact extras
   --------------------------------------------------------- */
.log-time {
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  line-height: 1.3;
}

.log-time .ts-mono,
.log-time .ts-rel {
  display: block;
}

.log-time .ts-rel {
  margin-top: 2px;
}

.log-model {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.log-latency {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  white-space: nowrap;
}

