/* site.css: the carbs website's look. Tokens first (light on :root, dark for the system setting and for the header's
 * theme switch), then layout, components and the ANSI colours of the monitor's text. charts.css uses the same tokens.
 * Chart colours c1..c6 are the validated categorical palette (dataviz six checks, light and dark surfaces); text never
 * wears them. Status colours (pos, neg, warn) always come with a sign, an icon or a word. */

:root {
  color-scheme: light;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --bg: #f3f3ef;
  --surface: #fcfcfb;
  --surface-2: #efefea;
  --border: #dcdbd3;
  --field-border: #8a8982; /* form fields: 3:1 against --bg (their fill) and --surface (the card) */
  --text: #17191a;
  --text-dim: #4f5352;
  --muted: #6a6d6a;
  --muted-fill: #b4b3ab;
  --accent: #8a5a00;
  --accent-ink: #ffffff;
  --pos: #0b6b23;
  --neg: #c02f2f;
  --warn: #8a5a00;
  --grid: #e7e6e0;
  --axis: #b9b8af;
  --focus: #2a78d6;
  --c1: #2a78d6;
  --c2: #eb6834;
  --c3: #1baf7a;
  --c4: #eda100;
  --c5: #e87ba4;
  --c6: #008300;
  --shadow: 0 1px 2px rgba(20, 20, 18, 0.06);
  --ansi-bg: #efefea;
  --ansi-text: #3c403e;
  --ansi-black: #3c403e;
  --ansi-red: #c22020;
  --ansi-green: #16761b;
  --ansi-yellow: #7d6400;
  --ansi-blue: #1d5fb5;
  --ansi-magenta: #9a2f9a;
  --ansi-cyan: #00757a;
  --ansi-white: #17191a;
  --ansi-96: #0b7285;
}

/* Dark: a nod to the old site (deep green-black, amber links). Declared for the system setting unless the switch
   chose light, and again for the switch's dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1713;
    --surface: #16201b;
    --surface-2: #1d2923;
    --border: #2b3832;
    --field-border: #66736c;
    --text: #e6ebe8;
    --text-dim: #a7b3ad;
    --muted: #86938c;
    --muted-fill: #4d5a53;
    --accent: #e1a514;
    --accent-ink: #1a1300;
    --pos: #3ec46d;
    --neg: #f07272;
    --warn: #f0b429;
    --grid: #233029;
    --axis: #3d4b44;
    --focus: #6da7ec;
    --c1: #3987e5;
    --c2: #d95926;
    --c3: #199e70;
    --c4: #c98500;
    --c5: #d55181;
    --c6: #008300;
    --shadow: none;
    --ansi-bg: #111a15;
    --ansi-text: #aaaaaa;
    --ansi-black: #7d8a83;
    --ansi-red: #f25a5a;
    --ansi-green: #1ed71e;
    --ansi-yellow: #f2e600;
    --ansi-blue: #3ea0fa;
    --ansi-magenta: #e45fe4;
    --ansi-cyan: #00b3b3;
    --ansi-white: #e6ebe8;
    --ansi-96: #5fd7ff;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1713;
  --surface: #16201b;
  --surface-2: #1d2923;
  --border: #2b3832;
  --field-border: #66736c;
  --text: #e6ebe8;
  --text-dim: #a7b3ad;
  --muted: #86938c;
  --muted-fill: #4d5a53;
  --accent: #e1a514;
  --accent-ink: #1a1300;
  --pos: #3ec46d;
  --neg: #f07272;
  --warn: #f0b429;
  --grid: #233029;
  --axis: #3d4b44;
  --focus: #6da7ec;
  --c1: #3987e5;
  --c2: #d95926;
  --c3: #199e70;
  --c4: #c98500;
  --c5: #d55181;
  --c6: #008300;
  --shadow: none;
  --ansi-bg: #111a15;
  --ansi-text: #aaaaaa;
  --ansi-black: #7d8a83;
  --ansi-red: #f25a5a;
  --ansi-green: #1ed71e;
  --ansi-yellow: #f2e600;
  --ansi-blue: #3ea0fa;
  --ansi-magenta: #e45fe4;
  --ansi-cyan: #00b3b3;
  --ansi-white: #e6ebe8;
  --ansi-96: #5fd7ff;
}

/* -- base ------------------------------------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font-sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3 { line-height: 1.25; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.dim { color: var(--text-dim); font-weight: 400; }
.mono { font-family: var(--font-mono); }
.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;
}
.skip-link { position: absolute; left: -9999px; top: 8px; z-index: 100; }
.skip-link:focus { left: 16px; background: var(--surface); padding: 6px 10px; border-radius: 6px; }
.icon { flex: none; vertical-align: -2px; }

/* -- top bar ---------------------------------------------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px;
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 4px 20px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
  text-decoration: none;
}
.brand-mark { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); transform: rotate(45deg); }
.tabs {
  display: flex;
  align-items: stretch;
  gap: 2px;
  min-width: 0;
  flex: 1 1 auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 15px 10px 13px;
  color: var(--text-dim);
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab:focus-visible { outline-offset: -2px; }
.tab-ext { margin-left: 6px; }
.topbar-end { display: flex; align-items: center; gap: 10px; margin-left: auto; flex: none; }
.user { color: var(--text-dim); max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout { margin: 0; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn[hidden] { display: none; }

@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; padding-top: 6px; }
  .tabs { order: 3; flex-basis: 100%; margin: 0 -8px; }
  .tab { padding: 8px 8px 9px; }
  .user { display: none; }
}

/* -- page frame ------------------------------------------------------------------------------------------------- */

.page { width: 100%; max-width: 1400px; margin: 0 auto; padding: 20px 16px 32px; flex: 1 0 auto; }
.page-narrow { max-width: 520px; }
.footer { text-align: center; padding: 20px 16px 28px; color: var(--text-dim); font-size: 0.85rem; border-top: 1px solid var(--border); }
.footer p { margin: 2px 0; }
.motto { font-style: italic; }
.footer-note { color: var(--muted); font-size: 0.78rem; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 24px;
  margin-bottom: 14px;
}
.page-head > p { margin: 0; }
.page-title { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; min-width: 0; flex: 1 1 auto; }
/* the arb lookup of every venue page (GET /<l>/arb?id=): an id, a link to an arb or a monitor line */
.arb-find { display: flex; gap: 6px; flex: 0 1 330px; min-width: 0; margin: 0; }
.arb-find input { flex: 1 1 auto; min-width: 0; width: auto; }
@media (max-width: 600px) { .arb-find { flex-basis: 100%; } }
.page-title h1 { margin: 0; font-size: 1.5rem; font-weight: 650; }
.subnav { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 8px; }
.subnav a {
  padding: 4px 12px;
  border-radius: 6px;
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 500;
}
.subnav a:hover { color: var(--text); }
.subnav a[aria-current] { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border); font-weight: 600; }

.fresh {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}
.fresh-ok { border-color: color-mix(in srgb, var(--pos) 45%, var(--border)); }
.fresh-ok .icon { color: var(--pos); }
.fresh-warn { border-color: var(--warn); }
.fresh-warn .icon { color: var(--warn); }
.fresh-stale { border-color: var(--neg); }
.fresh-stale .icon { color: var(--neg); }

.range-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; flex-basis: 100%; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg a {
  padding: 5px 14px;
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.seg a + a { border-left: 1px solid var(--border); }
.seg a:hover { background: var(--surface-2); color: var(--text); }
.seg a[aria-current] { background: var(--accent); color: var(--accent-ink); font-weight: 650; }
.seg a:focus-visible { outline-offset: -3px; }
.end-form { display: inline-flex; align-items: center; gap: 8px; margin: 0; flex-wrap: wrap; }
.end-form label { color: var(--text-dim); font-size: 0.875rem; }
.end-form input { width: auto; }

.period { margin: -2px 0 12px; color: var(--text-dim); font-size: 0.85rem; font-variant-numeric: tabular-nums; }

/* -- banners, badges -------------------------------------------------------------------------------------------- */

.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 0 14px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.banner .icon { margin-top: 2px; }
.banner-warn { border-left-color: var(--warn); }
.banner-warn .icon { color: var(--warn); }
.banner-error { border-left-color: var(--neg); }
.banner-error .icon { color: var(--neg); }
.banner-info { border-left-color: var(--accent); }
.error-list { margin: 4px 0 0; padding-left: 18px; }

.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 5px;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  line-height: 1.5;
  border: 1px solid var(--border);
  color: var(--text-dim);
  background: var(--surface-2);
  vertical-align: 1px;
}
.badge-mm {
  color: var(--text);
  background: color-mix(in srgb, var(--c2) 18%, var(--surface));
  border-color: color-mix(in srgb, var(--c2) 55%, var(--surface));
}
.kind-reg { color: var(--text-dim); font-size: 0.8rem; }

.age-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.age-ok .icon, .state-ok .icon { color: var(--pos); }
.age-warn .icon { color: var(--warn); }
.age-stale .icon, .state-down .icon { color: var(--neg); }
.state { display: inline-flex; align-items: center; gap: 5px; }
.state-planned { color: var(--text-dim); }

.amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt.pos { color: var(--pos); }
.amt.neg { color: var(--neg); }
.amt.zero { color: var(--text-dim); }

/* -- buttons and fields ----------------------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover { border-color: var(--axis); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-quiet { background: transparent; }
.btn[hidden] { display: none; }

input, select {
  font: inherit;
  font-size: 0.875rem;
  height: 32px;
  padding: 0 9px;
  width: 100%;
  min-width: 0;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--field-border);
  border-radius: 7px;
}
input::placeholder { color: var(--muted); opacity: 1; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--neg); box-shadow: inset 3px 0 0 var(--neg); }
input:hover, select:hover { border-color: var(--text-dim); }
input:focus-visible, select:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }

/* -- cards and grids -------------------------------------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin: 0 0 16px;
  min-width: 0;
  box-shadow: var(--shadow);
}
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 0 0 10px;
}
.card-head h2 { margin: 0; font-size: 1rem; font-weight: 650; }
.card-head > span, .card-head > a { font-size: 0.82rem; }
.sub-head { font-size: 0.9rem; margin: 16px 0 8px; font-weight: 650; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-bottom: 16px; align-items: start; }
.grid-2 > .card { margin: 0; }
@media (min-width: 980px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* -- KPI tiles -------------------------------------------------------------------------------------------------- */

.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (min-width: 720px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1120px) { .kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.kpi {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 12px 14px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: 0.8rem; font-weight: 600; color: var(--text-dim); }
.kpi-value { font-size: 1.6rem; font-weight: 650; line-height: 1.2; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.kpi-meta { display: flex; flex-wrap: wrap; gap: 0 6px; font-size: 0.78rem; color: var(--text-dim); }
.kpi-note { font-size: 0.78rem; color: var(--text-dim); }
.delta { font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.delta-good { color: var(--pos); }
.delta-bad { color: var(--neg); }
.delta-flat { color: var(--text-dim); }
.kpi .spark { margin-top: auto; padding-top: 6px; }
@media (max-width: 420px) {
  .kpi { padding: 10px 12px 8px; }
  .kpi-value { font-size: 1.3rem; }
}

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

/* position: the visually hidden labels and captions inside stay in the scroll box, never widen the page */
.table-scroll { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-card { padding-bottom: 8px; }
.num-table, .kv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.num-table th, .num-table td {
  padding: 6px 10px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--grid);
}
.num-table th:first-child, .num-table td:first-child { padding-left: 0; }
.num-table th:last-child, .num-table td:last-child { padding-right: 0; }
.num-table thead th { font-size: 0.75rem; font-weight: 600; color: var(--text-dim); border-bottom-color: var(--border); }
.num-table tbody th { font-weight: 500; }
.num-table th:first-child, .num-table td:first-child, .num-table .l { text-align: left; }
.num-table tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.num-table tbody tr:last-child > * { border-bottom: 0; }
.path {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  white-space: normal !important;
  overflow-wrap: break-word; /* the path filter puts a <wbr> after each ">": wrap between coins */
  text-align: left !important;
  min-width: 14ch;
}
.empty { color: var(--text-dim); text-align: left; padding: 12px 0; margin: 0; }
.col-bar { min-width: 170px; }
.inbar {
  display: inline-block;
  width: 64px;
  height: 6px;
  margin-right: 8px;
  vertical-align: 2px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}
.inbar-fill { display: block; height: 100%; border-radius: 3px; background: var(--muted-fill); }
.inbar-fill.pos { background: var(--pos); }
.inbar-fill.neg { background: var(--neg); }
.inbar-fill.acc { background: var(--c1); }
@media (max-width: 600px) {
  .hide-narrow { display: none; }
  .col-bar { min-width: 0; }
  .inbar { width: 40px; }
}
.kv-table th, .kv-table td { padding: 4px 10px 4px 0; border-bottom: 1px solid var(--grid); text-align: left; vertical-align: top; }
.kv-table th { font-family: var(--font-mono); font-weight: 500; color: var(--text-dim); width: 1%; white-space: nowrap; }
.kv-table td { font-family: var(--font-mono); font-size: 0.8rem; overflow-wrap: anywhere; }
.kv-table caption { text-align: left; font-weight: 600; padding: 8px 0 4px; }

/* -- home ------------------------------------------------------------------------------------------------------- */

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.home-grid > .card { margin: 0; display: flex; flex-direction: column; }
.venue-card .card-head h2 { font-size: 1.15rem; }
.venue-card .card-head h2 a { color: var(--text); text-decoration: none; }
.venue-card .card-head h2 a:hover { text-decoration: underline; }
.stats { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 4px 0 8px; }
.stats > div { flex: 1 1 auto; min-width: 0; }
.stats dt { font-size: 0.75rem; color: var(--text-dim); white-space: nowrap; }
.stats dd { margin: 2px 0 0; font-size: 1.2rem; font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.card-note { margin: 0 0 8px; color: var(--text-dim); font-size: 0.82rem; }
.note-warn .icon { color: var(--warn); }
.card-foot { display: flex; gap: 16px; margin-top: auto; padding-top: 10px; border-top: 1px solid var(--grid); font-weight: 500; }
.links-card h2 { margin: 0 0 8px; font-size: 1rem; }
.link-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.link-list a { font-weight: 600; }
.link-list .icon { margin: 0 6px 0 3px; color: var(--accent); }

/* -- arbs list -------------------------------------------------------------------------------------------------- */

.filters { display: grid; gap: 12px; }
/* 6 columns on wide screens: dates, account, outcome, kind, pair; then the amounts and the text search */
.filter-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
@media (min-width: 640px) { .filter-row { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .filter-row { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 0.78rem; font-weight: 600; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field-wide, .field-full { grid-column: 1 / -1; }
@media (min-width: 1100px) { .field-wide { grid-column: span 3; } }
.advanced > summary { cursor: pointer; color: var(--text-dim); font-size: 0.85rem; font-weight: 600; width: max-content; max-width: 100%; }
.advanced[open] > summary { margin-bottom: 10px; }
.filter-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.filter-hint { font-size: 0.8rem; }

.list-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 16px;
  margin: 2px 0 10px;
  font-size: 0.875rem;
}
.list-bar p { margin: 0; }
.list-info { color: var(--text-dim); }
.list-totals { display: flex; flex-wrap: wrap; gap: 4px 14px; font-variant-numeric: tabular-nums; }
.list-bar .btn { margin-left: auto; }
.rows-form { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: 0; }
.rows-form label { margin-left: 6px; }
.rows-form select { width: auto; padding: 2px 6px; font-size: 0.85rem; }
.list-bar .rows-form .btn { margin-left: 0; }

.arbs-card { padding: 4px 0; }
.arbs {
  --arb-cols: 160px 116px minmax(92px, 1fr) 60px minmax(146px, 2fr) 84px 56px 68px 72px 72px 78px 72px 64px 80px;
  min-width: 1356px;
  font-size: 0.84rem;
  font-variant-numeric: tabular-nums;
}
.arb-row {
  display: grid;
  grid-template-columns: var(--arb-cols);
  gap: 0 8px;
  align-items: center;
  padding: 6px 16px;
}
.arb-row > span { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.arb-row > .path { white-space: normal; overflow: visible; font-size: 0.78rem; min-width: 0; }
.arb-row .n { text-align: right; }
.arbs-head { font-size: 0.75rem; font-weight: 600; color: var(--text-dim); border-bottom: 1px solid var(--border); padding-top: 8px; }
details.arb { border-bottom: 1px solid var(--grid); }
details.arb:last-child { border-bottom: 0; }
details.arb > summary { display: block; list-style: none; cursor: pointer; }
details.arb > summary::-webkit-details-marker { display: none; }
details.arb > summary:hover { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
details.arb > summary:focus-visible { outline-offset: -2px; }
details.arb[open] > summary { background: var(--surface-2); }
.caret {
  display: inline-block;
  width: 0;
  height: 0;
  margin: 0 7px 1px 0;
  border-left: 5px solid var(--text-dim);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.12s;
}
details.arb[open] .caret { transform: rotate(90deg); }
details.arb > .desc { padding: 6px 16px 12px; background: var(--surface-2); }
.pager { display: flex; justify-content: flex-end; gap: 8px; margin: 4px 0 8px; }
/* the list at an arb (?at=<id>, the arb page's "In the timeline"): its rows marked by a bar and a tint, the first one
   the target of #arb-<id> (below the sticky header) */
details.arb-hit > summary { box-shadow: inset 4px 0 0 var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
details.arb-hit > summary:hover { background: color-mix(in srgb, var(--accent) 18%, var(--surface)); }
details.arb-hit[open] > summary { background: color-mix(in srgb, var(--accent) 16%, var(--surface-2)); }
details.arb-hit { scroll-margin-top: 120px; }
/* rows of the arb much older than its newest row (a route stored late), listed last: the dashed line marks the jump */
details.arb:not(.arb-far) + details.arb-far { border-top: 2px dashed var(--accent); }
.at-card .card-head h2 { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.at-note { margin: 0; color: var(--text-dim); font-size: 0.875rem; }

/* -- arb detail ------------------------------------------------------------------------------------------------- */

.crumbs { margin: -4px 0 12px; }
.related { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0; font-size: 0.875rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); gap: 10px 18px; margin: 0; }
.facts dt { font-size: 0.75rem; color: var(--text-dim); }
.facts dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.facts .wide { grid-column: 1 / -1; }
.facts-tight { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
@media (max-width: 600px) { .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.arb-summary h2 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.badge-multi { color: var(--text); background: color-mix(in srgb, var(--c1) 16%, var(--surface)); border-color: color-mix(in srgb, var(--c1) 50%, var(--surface)); }
.notice-card h2 { margin: 0 0 6px; font-size: 1rem; }
.notice-card p { margin: 4px 0; }
.desc-card { scroll-margin-top: 110px; }
.desc-card .card-head .btn { height: 26px; padding: 0 9px; font-size: 0.8rem; }

/* the monitor's ANSI block (ansi2html output, escaped) */
.desc pre, pre.ansi2html-content {
  margin: 0;
  padding: 10px 12px;
  overflow-x: auto;
  background: var(--ansi-bg);
  color: var(--ansi-text);
  border-radius: 7px;
  font: 0.8rem/1.5 var(--font-mono);
  white-space: pre;
  tab-size: 4;
}
.desc-card .desc { margin: 0 -4px; }
/* the arb page's competition per leg (comp_rows): the rows of web.competition, in the monitor's colours */
.comp { margin-top: 12px; }
.comp-title { font-size: 0.9rem; font-weight: 600; margin: 0 0 6px; }
.comp-title .dim { font-size: 0.8rem; margin-left: 4px; }
.comp-table .comp-markers { white-space: nowrap; font-size: 0.8rem; }
.comp-table tr.comp-note td { padding-top: 0; font-size: 0.78rem; border-top: 0; }
.comp-legend { font-size: 0.78rem; margin: 6px 0 0; }
.comp-none { margin: 10px 0 0; font-size: 0.85rem; color: var(--text-dim); }
.arb-comp { margin-left: 6px; font-size: 0.72rem; color: var(--text-dim); }
.ansi1 { font-weight: 700; }
.ansi2 { opacity: 0.75; }
.ansi3 { font-style: italic; }
.ansi4 { text-decoration: underline; }
.ansi9 { text-decoration: line-through; }
.ansi30, .ansi90 { color: var(--ansi-black); }
.ansi31, .ansi91 { color: var(--ansi-red); }
.ansi32, .ansi92 { color: var(--ansi-green); }
.ansi33, .ansi93 { color: var(--ansi-yellow); }
.ansi34, .ansi94 { color: var(--ansi-blue); }
.ansi35, .ansi95 { color: var(--ansi-magenta); }
.ansi36 { color: var(--ansi-cyan); }
.ansi96 { color: var(--ansi-96); } /* the monitor's bright cyan (arb_render.rs CYAN): neutral figures */
.ansi37, .ansi97 { color: var(--ansi-white); }

/* -- status ----------------------------------------------------------------------------------------------------- */

.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-item {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) auto;
  gap: 4px 10px;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid var(--grid);
}
.alert-text { overflow-wrap: anywhere; }
.alert-since { font-size: 0.8rem; white-space: nowrap; }
.sev { display: inline-flex; align-items: center; gap: 5px; font-size: 0.75rem; font-weight: 650; text-transform: uppercase; }
.sev-crit .icon, .sev-critical .icon { color: var(--neg); }
.sev-warn .icon, .sev-warning .icon { color: var(--warn); }
.sev-info .icon { color: var(--text-dim); }
@media (max-width: 520px) {
  .alert-item { grid-template-columns: 1fr; }
}

/* -- sortable tables (app.js turns each sortable header into a button) ------------------------------------------ */

.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0;
  margin: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.sort-btn:hover { color: var(--text); }
th[aria-sort] .sort-btn { color: var(--text); }
.sort-mark { display: inline-block; width: 0.8em; font-size: 0.7rem; color: var(--muted); text-align: center; }
.sort-mark::after { content: "↕"; opacity: 0.55; }
th[aria-sort="descending"] .sort-mark::after { content: "▼"; opacity: 1; color: var(--accent); }
th[aria-sort="ascending"] .sort-mark::after { content: "▲"; opacity: 1; color: var(--accent); }
.num-table thead th:not(:first-child) .sort-btn { flex-direction: row-reverse; } /* right-aligned: the mark first */
.arbs-head [data-sort-dir] .sort-btn { color: var(--text); }
.arbs-head [data-sort-dir="descending"] .sort-mark::after { content: "▼"; opacity: 1; color: var(--accent); }
.arbs-head [data-sort-dir="ascending"] .sort-mark::after { content: "▲"; opacity: 1; color: var(--accent); }
.arbs-head .n .sort-btn { flex-direction: row-reverse; } /* right-aligned: the mark first */

/* -- balances (templates/balances.html): the accounts beside (or above) the selected account ---------------------- */

.fresh-row { display: flex; flex-wrap: wrap; gap: 8px; }
.bal-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; margin-bottom: 16px; }
.bal-layout > .card, .bal-detail > .card { margin: 0; }
.bal-detail { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; min-width: 0; }
/* the target of the account links' #account (absolute: not a grid item, no gap of its own): on a narrow screen it is
   the detail's top, which scrolls into view below the sticky header; side by side it is the page's top (.bal-detail
   static), so a click on an account does not move the page */
.bal-anchor { position: absolute; top: 0; left: 0; width: 1px; height: 1px; scroll-margin-top: 110px; }
.coins-card { scroll-margin-top: 110px; }
@media (min-width: 1280px) {
  /* side by side from 1280 px: the coins' 8 columns need up to about 730 px (an account with many tiny prices); the
     accounts take what their table needs (more with an old snapshot's warning icon), at most 460 px */
  .bal-layout { grid-template-columns: fit-content(460px) minmax(0, 1fr); }
  /* the card stays in view; on a short screen only its table scrolls, in its own box, under the sticky head and
     above the pinned ALL ACCOUNTS row (app.js brings the selected row into view in that box) */
  .bal-accounts { position: sticky; top: 68px; max-height: calc(100vh - 84px); display: flex; flex-direction: column; }
  .bal-accounts > * { flex: none; }
  .bal-accounts > .acct-scroll { flex: 0 1 auto; min-height: 0; overflow-y: auto; }
  .acct-table thead th { position: sticky; top: 0; z-index: 2; background: var(--surface); }
  .bal-detail { position: static; }
  .coins-card { scroll-margin-top: 68px; }
}

.acct-table th, .acct-table td { padding: 7px 6px; }
.acct-table th:first-child, .acct-table td:first-child { padding-left: 8px; }
.acct-table th:last-child, .acct-table td:last-child { padding-right: 8px; }
.acct-table tbody tr { position: relative; }
.acct-table tbody tr:hover { cursor: pointer; }
/* the account link covers its whole row (each row is one link) */
.row-link { color: var(--text); font-weight: 600; text-decoration: none; }
.row-link::after { content: ""; position: absolute; inset: 0; }
.row-link:hover { text-decoration: underline; }
.row-link:focus-visible { outline: none; }
.row-link:focus-visible::after { outline: 2px solid var(--focus); outline-offset: -2px; border-radius: 4px; }
.acct-table tr.selected > * { background: color-mix(in srgb, var(--accent) 13%, var(--surface)); }
.acct-table tr.selected > :first-child { box-shadow: inset 3px 0 0 var(--accent); }
.acct-table tr.selected .row-link { color: var(--text); }
.acct-table tfoot th, .acct-table tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 2; /* above the rows' link overlays */
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 0;
}
.all-row > * { font-weight: 650; }
.all-row th { font-size: 0.75rem; letter-spacing: 0.04em; }
@media (max-width: 600px) {
  /* four columns (no Share) fit a phone: tighter cells, and the pinned row's label on two lines */
  .acct-table th, .acct-table td { padding-left: 5px; padding-right: 5px; }
  .all-row th { white-space: normal; line-height: 1.2; }
}
@media (max-width: 400px) { .acct-table, .coin-table { font-size: 0.8rem; } } /* fits 360 px without a side scroll */
.off-count { color: var(--warn); font-weight: 650; }
.snap-old { display: inline-flex; align-items: center; gap: 4px; color: var(--text); }
/* a pill or badge whose age keeps counting (app.js) has both icons: the one of its current state shows */
[data-fresh].fresh-ok > .icon-warn, [data-fresh].fresh-stale > .icon-ok,
[data-fresh].age-ok > .icon-warn, [data-fresh].age-stale > .icon-clock { display: none; }
.snap-old .icon { color: var(--warn); }
.bal-withheld { margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 4px; align-items: baseline; }
.bal-withheld .icon { color: var(--text-dim); }

.acct-card .card-head h2 { font-size: 1.15rem; }
.acct-card .age-badge .icon { color: var(--text-dim); }
.acct-card .age-stale .icon { color: var(--warn); }
.acct-facts { grid-template-columns: repeat(auto-fill, minmax(min(100%, 130px), 1fr)); }
.acct-facts dd { font-size: 1.05rem; }
@media (max-width: 600px) { .acct-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.coins-card .card-head { align-items: center; }
.coins-card .card-head h2 .dim { font-size: 0.82rem; margin-left: 4px; }
.coin-filter { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.coin-filter[hidden] { display: none; }
.coin-filter input { width: 180px; height: 30px; }
.filter-count { font-size: 0.8rem; min-width: 4ch; }
@media (max-width: 600px) {
  .coin-filter { margin-left: 0; flex: 1 1 100%; flex-wrap: wrap; }
  .coin-filter input { flex: 1 1 auto; width: auto; }
}
@media (min-width: 761px) {
  /* a long list (small coins shown) scrolls inside its card: the header and the pinned summary stay in view */
  .coins-scroll { max-height: min(78vh, 1100px); overflow-y: auto; }
  .coins-scroll thead th { position: sticky; top: 0; z-index: 1; background: var(--surface); }
}
.coin-table tbody th { font-weight: 600; }
/* on a phone the Qty and Band ($) columns are hidden; their values show as a second line under the coin and the value */
.cell-sub { display: none; }
@media (max-width: 600px) {
  .coin-table th, .coin-table td { vertical-align: top; }
  .cell-sub { display: block; margin-top: 1px; font-size: 0.72rem; font-weight: 400; color: var(--text-dim); white-space: normal; }
}
.coin-table .band { color: var(--text-dim); white-space: normal; } /* may wrap after its "–" when space is short */
.coin-table tr.is-small > * { color: var(--text-dim); }
.gap { font-weight: 600; }
.gap-ok { color: var(--pos); }
.gap-off { color: var(--warn); }
.gap-off.gap-big { color: var(--neg); }
.gap-sub, .gap-none, .gap-unknown { color: var(--text-dim); font-weight: 400; }
.coin-table tr.is-small .gap-ok { color: var(--pos); }
.coin-table tr.is-small .gap-off { color: var(--warn); }
.coin-table tr.is-small .gap-off.gap-big { color: var(--neg); }
/* the small coins' line, pinned under the coins (below their scroll box) */
.small-line {
  margin: 0;
  padding: 8px 0 2px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}
.small-line a { font-weight: 600; }
.coin-note { margin: 8px 0 4px; font-size: 0.78rem; }
.quiet-link { text-decoration: none; } /* an underline would hide the "_" of BR_1 */
.quiet-link:hover { text-decoration: underline; }
.stat-link { color: inherit; text-decoration-color: var(--border); }
.stat-link:hover { text-decoration-color: currentColor; }

/* -- login (templates/login.html; the header is hidden there, so the card shows the brand) ---------------------- */

.login-wrap { display: flex; justify-content: center; padding: clamp(24px, 9vh, 96px) 0 48px; }
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}
.login-brand { margin: 0; font-size: 1.6rem; font-weight: 650; letter-spacing: 0.02em; color: var(--accent); }
.login-sub { margin: 4px 0 20px; color: var(--text-dim); font-size: 0.95rem; }
.login-msg {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.92rem;
  line-height: 1.4;
  border: 1px solid var(--border);
  border-left-width: 4px;
  background: var(--surface-2);
}
.login-msg strong { font-weight: 650; }
.login-msg-error { border-left-color: var(--neg); }
.login-msg-need { border-left-color: var(--warn); }
.login-msg-info { border-left-color: var(--accent); }
.login-form { display: grid; gap: 14px; margin: 0; }
.login-field { display: grid; gap: 6px; }
.login-field label { font-size: 0.85rem; font-weight: 600; color: var(--text-dim); }
.login-field input { height: auto; font-size: 1rem; padding: 10px 12px; border-radius: 8px; }
.login-remember { display: flex; align-items: center; gap: 8px; font-size: 0.92rem; cursor: pointer; }
.login-remember input { width: 16px; height: 16px; margin: 0; padding: 0; accent-color: var(--accent); }
.login-hint { color: var(--text-dim); }
.login-submit {
  font: inherit;
  font-weight: 650;
  font-size: 1rem;
  cursor: pointer;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}
.login-submit:hover { filter: brightness(1.08); }
.login-foot { margin: 16px 0 0; font-size: 0.8rem; color: var(--text-dim); }

/* -- error page ------------------------------------------------------------------------------------------------- */

.error-page { max-width: 520px; margin: 8vh auto; text-align: center; }
.error-code { font-size: 3rem; font-weight: 700; color: var(--accent); margin: 0; letter-spacing: 0.04em; }
.error-page h1 { margin: 4px 0 8px; }
.error-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.error-actions form { margin: 0; }
