/* Component library. See docs/DESIGN.md "Components" and design/stitch/13-components. Every
   page (Login/Overview/Tokens/Token detail from T26; Alerts/Stats/Health/Logs/Settings/error
   pages from T27) shares this one class vocabulary (`.card`, `.btn`, `.table`, `.badge-*`,
   `.toast`, `.tabs`, `.live-dot`, `.cost-banner-*`, …). */

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 36px;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: var(--text-body-sm-size);
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-raised);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--surface-raised);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-danger:hover {
  background: #f2555a33;
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 640px) {
  .btn {
    height: 44px;
  }
}

/* Fields, inputs, selects */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.field label {
  font-size: var(--text-label-caps-size);
  font-weight: var(--text-label-caps-weight);
  letter-spacing: var(--text-label-caps-tracking);
  text-transform: uppercase;
  color: var(--text-muted);
}

.field input,
.field select,
.field textarea,
.input,
.filter-bar input[type="text"],
.filter-bar select,
.table input[type="text"],
.table select {
  background: var(--surface-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  height: 36px;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-body-sm-size);
}

.field textarea {
  height: auto;
  font-family: var(--font-mono);
  resize: vertical;
}

.field input::placeholder,
.filter-bar input[type="text"]::placeholder {
  color: var(--text-subtle);
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.filter-bar input[type="text"]:focus,
.filter-bar select:focus,
.table input[type="text"]:focus,
.table select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.field input.has-error,
.input.has-error {
  border-color: var(--danger);
}

.field-error {
  display: block;
  font-size: var(--text-caption-size);
  color: var(--danger);
  margin-top: 2px;
}

.field-password {
  position: relative;
}

.field-password input {
  width: 100%;
  padding-right: var(--space-8);
}

.field-password-toggle {
  position: absolute;
  right: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  padding: var(--space-1);
  display: flex;
}

.field-password-toggle:hover {
  color: var(--text);
}

.alert-inline {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-4);
  font-size: var(--text-caption-size);
}

.alert-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid transparent;
}

/* Toggle switch */

.toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

/* The switch's own hit box (this <button>) and its visible pill (`.toggle-track-visual`, the
   child span) are deliberately separate elements: DESIGN.md specs the pill itself at a fixed
   36x20 ("Toggle switch: 36x20 pill") but also floors every mobile tap target at 44px ("Density"),
   and a real switch this small can't be both at once. Keeping the drawn pill exactly 36x20 while
   growing the button's own (invisible) box to 44x44 on mobile (see the mobile media query below)
   satisfies both. */
.toggle-track {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-track-visual {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: var(--radius-full);
  background: var(--surface-input);
  border: 1px solid var(--border-strong);
  transition: background-color 0.15s;
}

.toggle-track-visual::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.15s, background-color 0.15s;
}

.toggle-track[aria-pressed="true"] .toggle-track-visual {
  background: var(--primary);
  border-color: var(--primary);
}

.toggle-track[aria-pressed="true"] .toggle-track-visual::after {
  background: var(--canvas);
  transform: translateX(16px);
}

/* Segmented control */

.segmented {
  display: inline-flex;
  background: var(--surface-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 2px;
  gap: 2px;
}

.segmented-option {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: var(--text-caption-size);
  font-weight: 500;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.segmented-option.is-active {
  background: var(--primary-soft);
  color: var(--primary);
}

.segmented-option:not(.is-active):hover {
  color: var(--text);
}

/* Pills, badges, stage pills */

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  height: 20px;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-label-caps-size);
  font-weight: var(--text-label-caps-weight);
  letter-spacing: var(--text-label-caps-tracking);
  text-transform: uppercase;
  background: var(--surface-raised);
  color: var(--text-muted);
  white-space: nowrap;
}

#logs-new-pill {
  margin-bottom: var(--space-3);
  background: var(--primary-soft);
  color: var(--primary);
}

/* `.pill`'s own `display: inline-flex` (an author rule) otherwise beats the `[hidden]` UA rule
   in the cascade even without `!important` — both are equal specificity, and author styles
   always win over user-agent ones — so a `hidden` `.pill` still rendered as an empty dot. */
.pill[hidden] {
  display: none;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-caption-size);
  font-weight: 500;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--surface-raised);
}

.badge-good {
  color: var(--primary);
  background: var(--primary-soft);
  border-color: transparent;
}

.badge-warn {
  color: var(--warning);
  background: var(--warning-soft);
  border-color: transparent;
}

.badge-bad {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: transparent;
}

.stage-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-label-caps-size);
  font-weight: 600;
  letter-spacing: var(--text-label-caps-tracking);
  text-transform: uppercase;
  white-space: nowrap;
}

.stage-pill-new {
  background: var(--stage-new-soft);
  color: var(--stage-new);
}

.stage-pill-active {
  background: var(--stage-active-soft);
  color: var(--stage-active);
}

.stage-pill-hot {
  background: var(--stage-hot-soft);
  color: var(--stage-hot);
  box-shadow: var(--glow-hot);
}

.stage-pill-dead {
  background: var(--stage-dead-soft);
  color: var(--stage-dead);
}

/* Cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.card-compact {
  padding: var(--space-4);
}

/* The signature mint-to-purple gradient hairline. One per page at most (DESIGN.md
   "Elevation & Depth"). Wrap the card's normal `.card` element with `.hairline` — a 1px padding
   box painted with the gradient, containing the real card so its own background still reads as
   `--surface`. */
.hairline {
  border-radius: calc(var(--radius-lg) + 1px);
  padding: 1px;
  background: linear-gradient(135deg, #14f195a6 0%, #9945ffa6 100%);
}

.hairline > .card {
  border: none;
}

/* Stat tiles */

.stat-tile {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.stat-tile .stat-value {
  font-family: var(--font-mono);
  font-feature-settings: var(--tabular-nums);
  font-size: var(--text-metric-lg-size);
  font-weight: var(--text-metric-lg-weight);
  line-height: var(--text-metric-lg-line);
  letter-spacing: var(--text-metric-lg-tracking);
  color: var(--text);
}

.stat-tile .stat-label {
  font-size: var(--text-label-caps-size);
  font-weight: var(--text-label-caps-weight);
  letter-spacing: var(--text-label-caps-tracking);
  text-transform: uppercase;
  color: var(--text-subtle);
}

.stat-tile .stat-delta-up {
  color: var(--primary);
}

.stat-tile .stat-delta-down {
  color: var(--danger);
}

/* Tables */

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-body-sm-size);
}

.table th,
.table td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table th {
  color: var(--text-subtle);
  font-weight: var(--text-label-caps-weight);
  font-size: var(--text-label-caps-size);
  text-transform: uppercase;
  letter-spacing: var(--text-label-caps-tracking);
}

.table tbody tr:hover {
  background: var(--surface-raised);
}

.table .num {
  text-align: right;
  font-family: var(--font-mono);
  font-feature-settings: var(--tabular-nums);
}

.table-row-hot {
  box-shadow: var(--glow-hot);
}

.table-mono {
  font-family: var(--font-mono);
  font-size: var(--text-caption-size);
}

/* Tokens list mobile card (T28, matches design/stitch/03-tokens/mobile.png): the desktop <table>
   becomes one bordered "card" per <tr>, laid out with named grid areas instead of table rows/
   cells — identity+score on top, an Mcap/Vol/Holders 3-column strip (matching the mock's own
   `grid grid-cols-3` metrics row), then a detected-time footer. Liquidity has no room on this
   card and is hidden; it's still in the desktop table and the underlying data. */
@media (max-width: 640px) {
  #tokens-table-wrap .table thead {
    display: none;
  }

  #tokens-table-wrap .table,
  #tokens-table-wrap .table tbody {
    display: block;
    width: 100%;
  }

  #tokens-table-wrap .table tr {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-areas:
      "identity identity score"
      "mcap vol holders"
      "footer footer footer";
    column-gap: var(--space-3);
    row-gap: var(--space-2);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-3);
    margin-bottom: var(--space-3);
  }

  #tokens-table-wrap .table td {
    display: block;
    border: none;
    padding: 0;
    white-space: normal;
  }

  #tokens-table-wrap .col-identity {
    grid-area: identity;
  }

  #tokens-table-wrap .col-identity-stage {
    display: block;
    margin-top: 2px;
  }

  #tokens-table-wrap .table td.col-stage {
    display: none;
  }

  #tokens-table-wrap .col-score {
    grid-area: score;
    justify-self: end;
    align-self: center;
  }

  #tokens-table-wrap .table td.col-liquidity {
    display: none;
  }

  #tokens-table-wrap .col-mcap {
    grid-area: mcap;
  }

  #tokens-table-wrap .col-vol {
    grid-area: vol;
  }

  #tokens-table-wrap .col-holders {
    grid-area: holders;
  }

  #tokens-table-wrap .col-mcap,
  #tokens-table-wrap .col-vol,
  #tokens-table-wrap .col-holders {
    display: flex;
    flex-direction: column;
    text-align: left;
  }

  #tokens-table-wrap .table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: var(--text-label-caps-size);
    text-transform: uppercase;
    letter-spacing: var(--text-label-caps-tracking);
    color: var(--text-muted);
    margin-bottom: 2px;
  }

  #tokens-table-wrap .col-detected {
    grid-area: footer;
    color: var(--text-subtle);
    font-size: var(--text-caption-size);
  }
}

/* Alerts mobile card (T28, matches design/stitch/05-alerts/mobile.png): a header line
   (timestamp/status/trigger), an identity+numbers row, then the existing <details> expand block
   unchanged underneath. */
@media (max-width: 640px) {
  #alerts-table-wrap .table thead {
    display: none;
  }

  #alerts-table-wrap .table,
  #alerts-table-wrap .table tbody {
    display: block;
    width: 100%;
  }

  #alerts-table-wrap .table tr {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-3);
    margin-bottom: var(--space-3);
  }

  #alerts-table-wrap .table td {
    display: block;
    border: none;
    padding: 0;
    white-space: normal;
  }

  #alerts-table-wrap .table td.col-time,
  #alerts-table-wrap .table td.col-status,
  #alerts-table-wrap .table td.col-kind {
    display: inline-block;
    margin-right: var(--space-2);
    font-size: var(--text-caption-size);
    color: var(--text-subtle);
  }

  #alerts-table-wrap .table td.col-identity {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--space-2);
  }

  #alerts-table-wrap .table td.col-mcap,
  #alerts-table-wrap .table td.col-score {
    display: inline-block;
    margin-left: var(--space-3);
  }

  #alerts-table-wrap .col-message {
    margin-top: var(--space-2);
  }

  #alerts-table-wrap .col-message summary {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

/* Generic stacked-table pattern (T28): any <table class="table"> not given bespoke treatment
   above (Tokens/Alerts) and not opted out via `.table-wrap-matrix` (the Token-detail per-window
   matrix, Task 6) becomes label:value rows inside a bordered card per <tr> — Logs, Token-detail's
   Base metrics/Alert history tables, and the Settings Links/Windows editable-row tables. */
@media (max-width: 640px) {
  .table-wrap:not(.table-wrap-matrix) .table thead {
    display: none;
  }

  .table-wrap:not(.table-wrap-matrix) .table,
  .table-wrap:not(.table-wrap-matrix) .table tbody,
  .table-wrap:not(.table-wrap-matrix) .table tr {
    display: block;
    width: 100%;
  }

  .table-wrap:not(.table-wrap-matrix) .table tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-3);
    margin-bottom: var(--space-2);
  }

  .table-wrap:not(.table-wrap-matrix) .table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-3);
    border: none;
    padding: var(--space-1) 0;
    min-height: 32px;
    white-space: normal;
  }

  .table-wrap:not(.table-wrap-matrix) .table td[data-label]::before {
    content: attr(data-label);
    font-size: var(--text-label-caps-size);
    text-transform: uppercase;
    letter-spacing: var(--text-label-caps-tracking);
    color: var(--text-muted);
    flex-shrink: 0;
    margin-right: var(--space-2);
  }

  .table-wrap:not(.table-wrap-matrix) .table td:not([data-label]) {
    justify-content: flex-start;
  }

  .table-wrap:not(.table-wrap-matrix) .table td input,
  .table-wrap:not(.table-wrap-matrix) .table td select {
    flex: 1;
    min-width: 0;
  }
}

/* Token detail per-window metrics, mobile only (T28, matches design/stitch/04-token-detail/
   mobile.png's horizontally-scrolling window cards): one card per window, each card peeking at
   80% width so the next one is visibly cut off at the edge — a scroll-snap-only affordance in
   place of the mock's JS dot-page-indicator. */
.window-cards {
  display: flex;
  gap: var(--space-3);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-bottom: var(--space-2);
}

.window-card {
  flex: 0 0 80%;
  scroll-snap-align: start;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.window-card-title {
  font-size: var(--text-label-caps-size);
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: var(--space-3);
}

.window-card-row {
  display: flex;
  justify-content: space-between;
  padding: var(--space-1) 0;
  font-size: var(--text-body-sm-size);
}

/* Token identity cell */

.token-identity {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.token-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-mint-purple);
  color: var(--on-primary);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
}

.token-identity-name {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}

.token-identity-name .name {
  font-size: var(--text-body-sm-size);
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
}

.token-identity-name .ticker {
  font-family: var(--font-mono);
  font-size: var(--text-label-caps-size);
  color: var(--text-subtle);
}

/* Only shown on the Tokens list mobile card (below), where the stage pill moves under the name
   instead of its own table column. */
.col-identity-stage {
  display: none;
}

/* Score ring: an SVG progress circle with the gradient stroke (DESIGN.md "Score ring"). Stroke
   colour is set per-stage via a `.score-ring-{stage}` class on the wrapper; width/offset come
   from SVG attributes, never `style=` (CSP `style-src 'self'`). */

.score-ring {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.score-ring svg {
  transform: rotate(-90deg);
}

.score-ring-track {
  stroke: var(--border);
}

.score-ring-value {
  stroke-linecap: round;
}

.score-ring-new .score-ring-value {
  stroke: var(--stage-new);
}

.score-ring-active .score-ring-value {
  stroke: var(--stage-active);
}

.score-ring-hot .score-ring-value {
  stroke: var(--stage-hot);
}

.score-ring-dead .score-ring-value {
  stroke: var(--stage-dead);
}

.score-ring-label {
  position: absolute;
  font-family: var(--font-mono);
  font-feature-settings: var(--tabular-nums);
  font-weight: 600;
  color: var(--text);
}

.score-ring-sm .score-ring-label {
  font-size: 11px;
}

.score-ring-lg .score-ring-label {
  font-size: 22px;
}

/* Sparkline: a small trend line, no axes (DESIGN.md "Shapes"). Mint for an upward trend, danger
   for downward — pick with `.sparkline-up`/`.sparkline-down` on the wrapping element. */

.sparkline {
  display: block;
  overflow: visible;
}

.sparkline-up {
  color: var(--primary);
}

.sparkline-down {
  color: var(--danger);
}

.sparkline path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Meters / progress bars — `<progress>` per docs/DESIGN.md "Implementation notes" (dynamic
   widths never use `style=`). */

.meter {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border: none;
  border-radius: var(--radius-full);
  overflow: hidden;
  background: var(--surface-raised);
}

.meter::-webkit-progress-bar {
  background: var(--surface-raised);
  border-radius: var(--radius-full);
}

.meter::-webkit-progress-value {
  background: var(--primary);
  border-radius: var(--radius-full);
}

.meter::-moz-progress-bar {
  background: var(--primary);
  border-radius: var(--radius-full);
}

.meter-warn::-webkit-progress-value {
  background: var(--warning);
}

.meter-warn::-moz-progress-bar {
  background: var(--warning);
}

.meter-danger::-webkit-progress-value {
  background: var(--danger);
}

.meter-danger::-moz-progress-bar {
  background: var(--danger);
}

/* Tabs */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-5);
  overflow-x: auto;
}

.tab-link {
  padding: var(--space-2) 0;
  color: var(--text-muted);
  font-size: var(--text-body-sm-size);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.tab-link:hover {
  color: var(--text);
  text-decoration: none;
}

.tab-link.is-active {
  color: var(--text);
  border-bottom-color: var(--primary);
}

/* Live dot / status pill / connection dots */

.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-subtle);
}

.live-dot.is-connected {
  background: var(--primary);
}

.pulse-dot {
  position: relative;
  display: inline-flex;
  width: 8px;
  height: 8px;
}

.pulse-dot::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--primary);
  opacity: 0.75;
  animation: pulse-ring 2s cubic-bezier(0, 0, 0.2, 1) infinite;
}

.pulse-dot::after {
  content: "";
  position: relative;
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
}

@keyframes pulse-ring {
  0% {
    transform: scale(1);
    opacity: 0.75;
  }
  100% {
    transform: scale(2.4);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pulse-dot::before {
    animation: none;
    opacity: 0;
  }
}

.connection-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-subtle);
  display: inline-block;
}

.connection-dot.is-connected {
  background: var(--primary);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  font-size: var(--text-caption-size);
  font-weight: 500;
  color: var(--text);
}

.dry-run-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  background: var(--warning-soft);
  color: var(--warning);
  font-size: var(--text-label-caps-size);
  font-weight: 600;
  letter-spacing: var(--text-label-caps-tracking);
}

/* Event rows (Overview / Stage history) */

.event-row {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--text-body-sm-size);
}

.event-row:last-child {
  border-bottom: none;
}

.event-row .event-time {
  font-family: var(--font-mono);
  color: var(--text-subtle);
  flex-shrink: 0;
}

/* A stage-history message ("<mint> NEW -> ACTIVE") is one long unbroken string with a full mint
   address in it — same flex min-width:0 fix as .filter-result-row, but wrapped rather than
   ellipsis-truncated since the message is meant to be read, not identified at a glance. */
.event-row .event-message {
  min-width: 0;
  overflow-wrap: anywhere;
}

.event-row .event-level-error {
  color: var(--danger);
}

.event-row .event-level-warning {
  color: var(--warning);
}

.event-row .event-level-info {
  color: var(--text-muted);
}

/* Empty states, skeletons */

.empty-state {
  color: var(--text-subtle);
  font-size: var(--text-body-sm-size);
  padding: var(--space-4) 0;
  text-align: center;
}

.empty-state .icon {
  width: 24px;
  height: 24px;
  color: var(--text-subtle);
  margin-bottom: var(--space-2);
}

.skeleton-topbar-status {
  display: inline-block;
  width: 180px;
  height: 20px;
  vertical-align: middle;
}

.skeleton {
  background: var(--surface-raised);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
  color: transparent;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, #ffffff0d, transparent);
  animation: skeleton-shimmer 1.6s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton::after {
    animation: none;
  }
}

/* Value flash: a brief highlight when a number changes (DESIGN.md "Do's"). Applied/removed by
   JS; harmless if a page never toggles it. */

.value-flash-up {
  animation: value-flash-up 1.2s ease-out;
}

.value-flash-down {
  animation: value-flash-down 1.2s ease-out;
}

@keyframes value-flash-up {
  0% {
    color: var(--primary);
  }
  100% {
    color: inherit;
  }
}

@keyframes value-flash-down {
  0% {
    color: var(--danger);
  }
  100% {
    color: inherit;
  }
}

@media (prefers-reduced-motion: reduce) {
  .value-flash-up,
  .value-flash-down {
    animation: none;
  }
}

/* Toasts */

.toast-region {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(320px, calc(100vw - 2 * var(--space-5)));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-body-sm-size);
  box-shadow: var(--shadow-modal);
}

.toast-success {
  color: var(--primary);
}

.toast-error {
  color: var(--danger);
}

.cost-banner {
  font-size: var(--text-body-sm-size);
  padding: var(--space-2) 0;
}

.cost-banner-amber {
  color: var(--warning);
}

.cost-banner-red {
  color: var(--danger);
}

/* Settings: sticky save bar (docs/tasks.md T27 Part c). Fixed to the bottom of the viewport,
   shown/hidden and its count kept live by `static/js/app.js`'s dirty-field tracking. */

.save-bar[hidden] {
  display: none;
}

.save-bar {
  position: fixed;
  left: 50%;
  bottom: var(--space-5);
  transform: translateX(-50%);
  z-index: 70;
  width: min(720px, calc(100% - 2 * var(--space-5)));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  background: #171a1fe6; /* --surface-raised at 90% opacity, see .topbar's own note */
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-5);
  box-shadow: var(--shadow-modal);
}

.save-bar-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-body-sm-size);
  font-weight: 500;
  color: var(--text);
}

.save-bar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

@media (max-width: 640px) {
  .save-bar {
    left: var(--space-4);
    right: var(--space-4);
    bottom: calc(var(--space-4) + 56px);
    width: auto;
    transform: none;
  }
}

/* Modals */

dialog.modal {
  background: transparent;
  border: none;
  padding: 0;
  max-width: 560px;
  width: calc(100% - var(--space-8));
  /* The UA stylesheet sets `color: black` directly on <dialog>, which otherwise beats the
     inherited dark-theme text color once the browser promotes it to the top layer. */
  color: var(--text);
}

dialog.modal::backdrop {
  background: rgba(10, 11, 13, 0.7); /* --scrim: ::backdrop can't reliably read custom properties */
  backdrop-filter: blur(8px);
}

dialog.modal .card {
  margin: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
}

.expandable-text {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--canvas);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-top: var(--space-2);
  margin-bottom: 0;
  font-family: var(--font-sans);
  font-size: var(--text-body-sm-size);
  color: var(--text-muted);
}

.expandable-text-mono {
  font-family: var(--font-mono);
  font-size: var(--text-caption-size);
  color: var(--text);
}

.expandable-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: var(--space-2);
}

details summary {
  cursor: pointer;
  color: var(--primary);
}

/* App shell: sidebar + top bar. See docs/DESIGN.md "Layout". */

.app-shell {
  min-height: 100%;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  z-index: 50;
  transition: width 0.15s;
}

.sidebar-brand {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  overflow: hidden;
}

.sidebar-brand-group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.sidebar-brand-mark {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--gradient-mint-purple);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--on-primary);
  flex-shrink: 0;
}

.sidebar-brand-name {
  font-size: var(--text-h3-size);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-2);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: var(--text-body-sm-size);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-link:hover {
  color: var(--text);
  background: var(--surface-raised);
  text-decoration: none;
}

.sidebar-link.is-active {
  color: var(--primary);
  background: var(--primary-soft);
}

.sidebar-link .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-collapse {
  border: none;
  background: transparent;
  color: var(--text-subtle);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.sidebar-collapse:hover {
  color: var(--text);
  background: var(--surface-raised);
}

.sidebar-footer {
  padding: var(--space-2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-1);
}

.sidebar-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-caption-size);
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text);
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: var(--text-body-sm-size);
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-signout {
  border: none;
  background: transparent;
  color: var(--text-subtle);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.sidebar-signout:hover {
  color: var(--text);
  background: var(--surface-raised);
}

/* Collapsed state, toggled by JS (`static/js/app.js`), persisted in `localStorage`. */
.app-shell.is-sidebar-collapsed .sidebar {
  width: var(--sidebar-width-collapsed);
}

.app-shell.is-sidebar-collapsed .sidebar-brand-name,
.app-shell.is-sidebar-collapsed .sidebar-link span:not(.icon),
.app-shell.is-sidebar-collapsed .sidebar-user-name,
.app-shell.is-sidebar-collapsed .sidebar-footer form {
  display: none;
}

.app-shell.is-sidebar-collapsed .topbar,
.app-shell.is-sidebar-collapsed .app-main {
  margin-left: var(--sidebar-width-collapsed);
}

.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-height);
  margin-left: var(--sidebar-width);
  background: #111317e6; /* --surface at 90% opacity: backdrop-filter needs a translucent base */
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 0 var(--space-6);
  z-index: 40;
  transition: margin-left 0.15s;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  font-size: var(--text-caption-size);
  color: var(--text-subtle);
}

.topbar-title strong {
  color: var(--text-muted);
  font-weight: 500;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar-connections {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar-connection {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-caption-size);
  color: var(--text-muted);
}

.app-main {
  margin-left: var(--sidebar-width);
  padding: var(--space-6) var(--space-8);
  max-width: var(--page-max-width);
  transition: margin-left 0.15s;
}

@media (max-width: 640px) {
  .sidebar {
    display: none;
  }

  .topbar,
  .app-shell.is-sidebar-collapsed .topbar,
  .app-main,
  .app-shell.is-sidebar-collapsed .app-main {
    margin-left: 0;
  }

  .app-main {
    padding: var(--space-4);
    padding-bottom: calc(var(--space-4) + 56px);
  }

  .bottom-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 56px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 50;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .bottom-tabbar-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-subtle);
    font-size: 10px;
    min-height: 44px;
    background: transparent;
    border: none;
    font-family: var(--font-sans);
    cursor: pointer;
  }

  .bottom-tabbar-link.is-active {
    color: var(--primary);
  }

  .bottom-tabbar-link .icon {
    width: 18px;
    height: 18px;
  }

  /* Compact top bar (docs/DESIGN.md "Mobile (< 640px)"): title shrinks, connection dots hide,
     the status pill/DRY RUN badge stay since they're the at-a-glance state that matters most on
     the smallest viewport. */
  .topbar {
    margin-left: 0;
    padding: 0 var(--space-4);
    padding-top: env(safe-area-inset-top);
    height: calc(var(--topbar-height) + env(safe-area-inset-top));
    gap: var(--space-2);
  }

  .topbar-title {
    font-size: var(--text-body-sm-size);
  }

  .topbar-connections {
    display: none;
  }

  /* Toasts move to the top on mobile (docs/DESIGN.md "Toast") so they never sit under the thumb
     or the bottom tab bar. */
  .toast-region {
    top: calc(var(--space-4) + env(safe-area-inset-top));
    right: var(--space-4);
    left: var(--space-4);
    bottom: auto;
    width: auto;
  }

  /* Modals become bottom sheets on mobile (docs/DESIGN.md "Modal / bottom sheet"). showModal()/
     .close() and Escape/backdrop dismissal are unaffected — those are UA <dialog> behaviours,
     independent of position. */
  dialog.modal {
    position: fixed;
    inset: auto 0 0 0;
    margin: 0;
    max-width: none;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
  }

  dialog.modal .card {
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border-bottom: none;
    padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom));
  }

  /* Tab bars scroll horizontally on mobile instead of wrapping (docs/DESIGN.md "Tabs") —
     .tabs already has overflow-x: auto, only flex-wrap: wrap was preventing the scroll. */
  .tabs {
    flex-wrap: nowrap;
  }

  /* Stat tiles go 2 per row on mobile (docs/DESIGN.md "Mobile (< 640px)"). Overview's own stat
     row (`#overview-stats`, Tracked now / Hot / Alerts today / Helius credits) is the one place
     `.stat-tile`s sit inside `.card-grid` instead of `.stat-grid` (they're styled bigger/richer
     there, `.card.card-compact.stat-tile`) — `.card-grid`'s auto-fit already collapses to 1
     column under ~560px, so it needs its own override to hit 2 instead of `.stat-grid`'s rule. */
  .stat-grid,
  #overview-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  /* 16px input text prevents iOS Safari's auto-zoom-on-focus (inputs otherwise render at
     --text-body-sm-size = 13px, below the 16px threshold). 44px height meets the same tap-target
     minimum as .btn (they're 36px otherwise, see the base rule above). Same selector list
     components.css already uses for these elements. */
  .field input,
  .field select,
  .field textarea,
  .input,
  .filter-bar input[type="text"],
  .filter-bar select,
  .table input[type="text"],
  .table select {
    font-size: 16px;
    height: 44px;
  }

  /* Bare checkboxes with no wrapping <label> (Settings Filters/Score "enabled" column, Links "On"
     column) get one added in the template (see settings_{filters,score,links}.html) so there's a
     real 44px tap target instead of the ~13px native checkbox box; this sizes that wrapper. Every
     OTHER checkbox in Settings already has a wrapping <label> with visible text next to it
     (Health/Alerts/Lifecycle notify toggles, in a `.filter-bar`; Windows' "confirm remove", in a
     `<td>`) — :has() sizes those the same way without touching their markup. Deliberately not
     scoped to a specific ancestor class (`.field`/`.filter-bar`/`<td>` all appear) since a <label>
     wrapping a checkbox/radio is this exact toggle-row pattern everywhere it occurs in this repo.
     .toggle-track (the scanner on/off switch) isn't included here: its 44px mobile floor works
     differently (the button's own box grows around an unchanged-size `.toggle-track-visual` pill,
     see components above) since, unlike these, its visible size is fixed by DESIGN.md at 36x20. */
  .checkbox-tap,
  label:has(input[type="checkbox"]),
  label:has(input[type="radio"]) {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .toggle-track {
    min-width: 44px;
    min-height: 44px;
  }

  .checkbox-tap {
    display: inline-flex;
    justify-content: center;
    min-width: 44px;
  }

  /* Bare navigational/filter links with no explicit height — tabs, segmented controls, filter
     pills, pagination, the token identity cell (used outside the Tokens/Alerts bespoke cards too,
     e.g. Overview's live-tokens list), and footer/breadcrumb links. */
  .tab-link,
  .segmented-option,
  .stage-filter-pill,
  .token-identity,
  .pagination a,
  .live-card-footer a,
  .issues-card-footer a,
  .page-header a.text-caption,
  .research-toggle-link,
  .token-analyse-link,
  .table-wrap:not(.table-wrap-matrix) .table td a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* Any <details><summary> expand control (Alerts' message expand, Health's issue traceback). */
  details summary {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* The login page's icon-only show/hide password button (absolutely positioned inside the
     field, so enlarging it doesn't reflow anything else). */
  .field-password-toggle {
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
  }

  /* Logs' search+filter form (the only `.filter-bar` that's also `.filter-autosubmit` — Tokens/
     Alerts use segmented controls and pills instead, not this label+input row shape) goes single
     column so each field gets full width instead of an uneven 2-up wrap. */
  .filter-bar.filter-autosubmit {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar.filter-autosubmit label {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-1);
  }

  .filter-bar.filter-autosubmit input[type="text"],
  .filter-bar.filter-autosubmit select {
    width: 100%;
  }
}

@media (min-width: 641px) {
  .bottom-tabbar {
    display: none;
  }
}

/* "More" bottom sheet (T28): lists Stats/Logs/Settings/Sign out. Its trigger button only exists
   inside .bottom-tabbar, which is display:none above 640px, so the dialog itself needs no media
   guard — it simply never receives a showModal() call on desktop. */
.more-sheet-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.more-sheet-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  min-height: 44px;
  border-radius: var(--radius-md);
  color: var(--text);
}

.more-sheet-link:hover,
.more-sheet-link:active {
  background: var(--surface-raised);
}

/* Error pages (404 / 403 / 500). See design/stitch/13-components "System Status & Error Pages". */

.error-card-wrap {
  width: 100%;
  max-width: 400px;
}

.error-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-3);
}

.error-card .btn {
  margin-top: var(--space-2);
}

.error-code {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: var(--text-body-size);
  font-weight: 700;
}

.error-code-info {
  color: var(--info);
}

.error-code-warn {
  color: var(--warning);
}

.error-code-danger {
  color: var(--danger);
}

/* Login page */

.login-page {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.login-card-wrap {
  width: 100%;
  max-width: 400px;
}

.login-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: var(--space-6);
}

.login-header .sidebar-brand-mark {
  width: 40px;
  height: 40px;
  margin-bottom: var(--space-4);
}

.login-footer {
  margin-top: var(--space-5);
  text-align: center;
}
