/*
 * Manta dashboard (MAN-14).
 *
 * One stylesheet, no build step, no framework — the same reason the rest of
 * `web/` is plain ES modules: these files are served verbatim by Workers Static
 * Assets, and a toolchain between the source and the deployed artifact is a
 * toolchain nobody here can run against a preview URL that does not exist.
 *
 * Light and dark are both defined. The palette is the same hues in both, so a
 * screenshot pasted into an issue reads the same either way.
 */

:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --line: #dfe3e8;
  --ink: #14181f;
  --ink-soft: #5a6472;
  --ink-faint: #8b95a3;
  --accent: #1f6feb;
  --accent-soft: #e7f0ff;
  --ok: #1a7f4b;
  --warn: #9a6400;
  --bad: #c02a2a;
  --info: #4b3fa8;

  --radius: 8px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Menlo", "Consolas", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Helvetica Neue", "Hiragino Sans",
    "Noto Sans JP", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #151b23;
    --surface-2: #1b222c;
    --line: #2a323d;
    --ink: #e6edf3;
    --ink-soft: #9aa7b5;
    --ink-faint: #6e7b8a;
    --accent: #58a6ff;
    --accent-soft: #16273f;
    --ok: #4ac97e;
    --warn: #e3b341;
    --bad: #ff7b72;
    --info: #a68bfa;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0 0 3rem;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
  font-family: var(--mono);
  font-size: 0.92em;
}

/* --- shell --------------------------------------------------------------- */

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: baseline;
}

.brand-name {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--ink);
}

/*
 * The mark is pixel art (MAN-32), so it is sized in whole multiples of its own
 * 64-unit grid rather than to a round CSS length: at 26px each art pixel is a
 * shade over 0.4px, and `crispEdges` in the SVG snaps the run boundaries
 * consistently instead of dropping the one-pixel tail.
 *
 * `flex-shrink` is pinned because `.top` wraps at narrow widths, and a squashed
 * logo is worse than a wrapped one.
 */
.brand-mark {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

.top nav {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}

.nav-link {
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius);
  color: var(--ink-soft);
  font-weight: 500;
}

.nav-link:hover {
  background: var(--surface-2);
  text-decoration: none;
}

.nav-on {
  background: var(--accent-soft);
  color: var(--accent);
}

.identity {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.bottom {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  max-width: 1500px;
  margin: 2rem auto 0;
  padding: 1rem 1.5rem;
  color: var(--ink-faint);
  font-size: 0.78rem;
}

main {
  max-width: 1500px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* --- filters ------------------------------------------------------------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 2rem;
  margin-bottom: 1.25rem;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.filter-label {
  color: var(--ink-faint);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.filter-sep {
  color: var(--ink-faint);
}

.chip {
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.chip:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.chip-on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

input.date,
input.user-box,
input.token-box {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.85rem;
}

input.user-box {
  min-width: 15rem;
}

.button {
  display: inline-block;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.button:hover {
  text-decoration: none;
  filter: brightness(1.08);
}

.button.subtle {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-soft);
}

/* --- stats --------------------------------------------------------------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat {
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.stat-label {
  color: var(--ink-faint);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  margin-top: 0.15rem;
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  margin-top: 0.15rem;
  color: var(--ink-faint);
  font-size: 0.78rem;
}

.stat-muted .stat-value {
  color: var(--ink-faint);
  font-weight: 500;
}

/* --- detail page head ----------------------------------------------------- */

/* The heading of a page that is about one thing. It replaces a grid of `.stat`
   tiles on the prompt and session screens: those tiles are the overview's
   component, and a detail page built out of them reads as a dashboard whatever
   its scope (MAN-31). */
.page-head {
  margin-bottom: 1.25rem;
}

.page-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 0.75rem;
  margin: 0;
  font-size: 1.35rem;
  font-weight: 620;
  letter-spacing: -0.02em;
}

.page-kind {
  color: var(--ink);
}

/* The full id, not a shortened one: on a detail page the identifier is the
   subject, and it is what somebody copies out to paste into a query. */
.page-id {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--ink-soft);
  word-break: break-all;
}

.page-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.5rem;
  margin: 0.35rem 0 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.page-sep {
  color: var(--ink-faint);
}

/* The six tiles, as one line. Tabular figures so the numbers still line up
   with the tables below them. */
.page-summary {
  margin: 0.4rem 0 0;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

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

.panel {
  margin-bottom: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 620;
}

.panel-actions {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.panel-note {
  margin: 0;
  padding: 0.5rem 1rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.panel-body > * + * {
  border-top: 1px solid var(--line);
}

/* A panel that starts closed. `details summary` already carries the padding and
   the pointer; this is the row layout and the count on the right. */
.panel-fold > details > summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.7rem 1rem;
}

.panel-fold > details[open] > summary {
  border-bottom: 1px solid var(--line);
}

.fold-title {
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 620;
}

.fold-count {
  color: var(--ink-faint);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

/* --- stored content ------------------------------------------------------- */

.content-slot {
  padding: 1rem;
}

.content-slot > * + * {
  margin-top: 0.6rem;
}

.content-none,
.content-have,
.content-refused {
  margin: 0;
  font-size: 0.95rem;
}

.content-none {
  color: var(--ink-soft);
}

.content-refused {
  color: var(--bad);
}

.content-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.content-actions .muted {
  flex: 1 1 18rem;
  font-size: 0.8rem;
}

.reason-box {
  flex: 1 1 16rem;
  max-width: 28rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9rem;
}

.content-record {
  padding: 1rem;
}

.content-head {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
}

.content-value + .content-value {
  margin-top: 0.75rem;
}

.content-key {
  margin: 0 0 0.25rem;
  font-size: 0.78rem;
  color: var(--ink-faint);
}

/* The stored text itself. `pre-wrap` because a prompt is prose with newlines in
   it, not code with meaningful columns, and a horizontal scrollbar on a
   paragraph is how you make it unreadable. */
.content-body {
  margin: 0;
  padding: 0.7rem 0.85rem;
  max-height: 32rem;
  overflow: auto;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

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

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

caption {
  padding: 0.5rem 1rem;
  color: var(--ink-soft);
  text-align: left;
}

th,
td {
  padding: 0.4rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--surface-2);
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.nowrap {
  white-space: nowrap;
}

code.id {
  padding: 0.05rem 0.3rem;
  background: var(--surface-2);
  border-radius: 4px;
}

.tree-indent {
  color: var(--ink-faint);
  font-family: var(--mono);
}

.muted {
  color: var(--ink-faint);
}

.bad {
  color: var(--bad);
}

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

.badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid currentColor;
}

td > .badge:first-child {
  margin-left: 0;
}

.badge-ok {
  color: var(--ok);
}
.badge-bad {
  color: var(--bad);
}
.badge-warn {
  color: var(--warn);
}
.badge-info {
  color: var(--info);
}

/* --- bars ---------------------------------------------------------------- */

/*
 * The date band is reserved out of the track rather than shared with it.
 *
 * `--h` is a percentage of `.bar`'s content box, so whatever the labels take
 * from that box comes off the top of the tallest bar and nowhere else. While
 * the label was an in-flow sibling of the fill, the 100% bar wanted the whole
 * column plus a label, flex-shrink took the difference out of *both* children,
 * and the peak day rendered about a fifth short with its own date wrapped onto
 * two lines — while every other day rendered true to scale, which is the worst
 * way for a chart to be wrong. Bottom padding now holds the band open and the
 * label is positioned into it, out of flow, where it cannot bid for the track.
 */
.bars {
  --bar-track: 7rem;
  --bar-band: 2.85rem;

  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 1rem;
  overflow-x: auto;
}

.bar {
  flex: 1 0 6px;
  min-width: 6px;
  height: calc(var(--bar-track) + var(--bar-band));
  padding-bottom: var(--bar-band);
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
}

.bar-fill {
  width: 100%;
  height: var(--h);
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  min-height: 1px;
}

.bar:hover .bar-fill {
  filter: brightness(1.2);
}

.bar-label {
  position: absolute;
  top: calc(var(--bar-track) + 0.25rem);
  left: 50%;
  transform: translateX(-50%);
  color: var(--ink-faint);
  font-size: 0.62rem;
  font-variant-numeric: tabular-nums;
  writing-mode: vertical-rl;
  max-height: 2.6rem;
}

/* --- messages ------------------------------------------------------------ */

.empty,
.loading {
  margin: 0;
  padding: 1rem;
  color: var(--ink-faint);
}

.caveats {
  margin: 0 0 1.25rem;
  padding: 0.6rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--ink-faint);
  border-radius: var(--radius);
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.panel-body .caveats {
  margin: 0;
  border-radius: 0;
  border-left: none;
  border-right: none;
  border-bottom: none;
}

.caveats ul {
  margin: 0;
  padding-left: 1.1rem;
}

.failure {
  max-width: 42rem;
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--bad);
  border-radius: var(--radius);
}

.failure h2 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

.failure p {
  margin: 0 0 0.5rem;
}

.failure .advice {
  color: var(--ink-soft);
}

/* --- facts --------------------------------------------------------------- */

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 0.5rem 1.5rem;
  margin: 0;
  padding: 1rem;
}

.facts dt {
  color: var(--ink-faint);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.facts dd {
  margin: 0 0 0.4rem;
  word-break: break-word;
}

details summary {
  padding: 0.6rem 1rem;
  cursor: pointer;
  color: var(--ink-soft);
}

.more {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  margin: 0;
}

/* --- credential gate ----------------------------------------------------- */

.gate {
  max-width: 34rem;
  margin: 4rem auto;
  padding: 1.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.gate h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}

.gate p {
  color: var(--ink-soft);
}

.token-box {
  width: 100%;
  margin: 0.5rem 0 0.75rem;
  font-family: var(--mono);
}

.gate-error {
  color: var(--bad);
}

.gate-help {
  margin-top: 1rem;
  font-size: 0.8rem;
  font-family: var(--mono);
  color: var(--ink-faint);
}
