/* AI Usage Hub dashboard. Brand red is for the wordmark and primary actions only;
   the categorical slots are for computers; status colors always come with an icon and label. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --surface-3: #ebeae5;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --border-strong: rgba(11, 11, 11, 0.18);
  --brand: #e3241b;
  --brand-hover: #c81d15;
  --brand-ink: #ffffff;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --s0: #2a78d6;
  --s1: #eb6834;
  --s2: #1baf7a;
  --s3: #eda100;
  --s4: #e87ba4;
  --s5: #008300;
  --s6: #6250d6;
  --other: #898781;
  --mix-0: #3d3c39;
  --mix-1: #6f6e69;
  --mix-2: #a3a29b;
  --mix-3: #d3d2cb;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 10px 30px rgba(11, 11, 11, 0.05);
  --shadow-lg: 0 24px 80px rgba(11, 11, 11, 0.22);
  --radius: 16px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --surface-3: #2c2c2a;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.2);
    --s0: #3987e5;
    --s1: #d95926;
    --s2: #199e70;
    --s3: #c98500;
    --s4: #d55181;
    --s5: #008300;
    --s6: #9085e9;
    --mix-0: #e4e3de;
    --mix-1: #a9a8a0;
    --mix-2: #6c6b66;
    --mix-3: #45443f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 24px 80px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --surface-3: #2c2c2a;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.2);
  --s0: #3987e5;
  --s1: #d95926;
  --s2: #199e70;
  --s3: #c98500;
  --s4: #d55181;
  --s5: #008300;
  --s6: #9085e9;
  --mix-0: #e4e3de;
  --mix-1: #a9a8a0;
  --mix-2: #6c6b66;
  --mix-3: #45443f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 24px 80px rgba(0, 0, 0, 0.6);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 15px;
}

p {
  margin: 0;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

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

.sprite {
  display: none;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* ---------- top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--page) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px 8px;
  border-radius: 9px;
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 900;
  font-size: 17px;
  letter-spacing: -0.03em;
  text-decoration: none;
  white-space: nowrap;
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.live[data-state='live'] .live-dot {
  background: var(--good);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent);
  animation: pulse 2s infinite;
}

.live[data-state='offline'] .live-dot {
  background: var(--critical);
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 55%, transparent);
  }
  70% {
    box-shadow: 0 0 0 7px transparent;
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

:root:not([data-theme='dark']) .theme-dark,
:root[data-theme='dark'] .theme-light {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-dark {
    display: block;
  }
  :root:not([data-theme]) .theme-light {
    display: none;
  }
}

/* ---------- buttons and controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

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

.btn:active {
  transform: translateY(1px);
}

.btn[disabled] {
  opacity: 0.55;
  cursor: default;
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
}

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

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

.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 13px;
  border-radius: 8px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
}

.icon-btn:hover,
.icon-btn[aria-pressed='true'] {
  background: var(--surface-2);
  color: var(--ink);
}

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

.segmented button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--ink-2);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.segmented button:hover {
  color: var(--ink);
}

.segmented button[aria-checked='true'] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 0 0 1px var(--border);
}

.segmented-sm button {
  padding: 4px 10px;
  font-size: 12px;
}

.segmented .short {
  display: none;
}

.select select {
  appearance: none;
  height: 38px;
  padding: 0 34px 0 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23898781' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E")
    no-repeat right 10px center / 16px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}

.input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
}

.input:focus {
  outline: 2px solid var(--brand);
  outline-offset: 0;
  border-color: transparent;
}

.input-money {
  position: relative;
}

.input-money .input {
  padding-left: 24px;
}

.input-money::before {
  content: '$';
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-weight: 600;
}

.switch {
  position: relative;
  width: 44px;
  height: 26px;
  flex: none;
  border-radius: 999px;
  border: 0;
  background: var(--surface-3);
  cursor: pointer;
  transition: background 0.2s;
}

.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}

.switch[aria-checked='true'] {
  background: var(--ink);
}

.switch[aria-checked='true']::after {
  transform: translateX(18px);
  background: var(--surface);
}

/* ---------- layout */
.page {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 24px 40px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.updated {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

body.is-refreshing #dashboard {
  opacity: 0.55;
  transition: opacity 0.2s;
}

#dashboard {
  transition: opacity 0.2s;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-sub,
.section-sub {
  color: var(--ink-2);
  font-size: 12.5px;
}

.card-head .card-sub {
  margin-top: 2px;
}

.card-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.row {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.row-main {
  grid-template-columns: minmax(0, 2.3fr) minmax(300px, 1fr);
}

.row-bottom {
  grid-template-columns: minmax(0, 1.75fr) minmax(320px, 1fr);
}

.stack {
  display: grid;
  gap: 16px;
  align-content: start;
}

.section {
  margin-top: 28px;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
}

.section-head h2 {
  font-size: 17px;
}

/* ---------- KPIs */
.kpis {
  display: grid;
  grid-template-columns: minmax(0, 2fr) repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.kpi {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kpi-label {
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
}

.kpi-value {
  font-size: 30px;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.kpi-hero .kpi-value {
  font-size: 56px;
  letter-spacing: -0.035em;
  line-height: 1;
}

.kpi-foot {
  color: var(--ink-2);
  font-size: 12.5px;
  margin-top: auto;
}

.delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--ink-2);
  font-size: 12.5px;
}

.mix {
  display: flex;
  gap: 2px;
  height: 10px;
  margin: 12px 0 10px;
}

.mix span {
  min-width: 2px;
  border-radius: 2px;
}

.mix span:first-child {
  border-radius: 4px 2px 2px 4px;
}

.mix span:last-child {
  border-radius: 2px 4px 4px 2px;
}

.mix-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 12.5px;
  color: var(--ink-2);
}

.mix-legend b {
  color: var(--ink);
  font-weight: 600;
}

.key {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: -1px;
}

/* ---------- usage chart */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: -4px 0 12px;
  font-size: 12.5px;
  color: var(--ink-2);
}

.legend b {
  color: var(--ink);
  font-weight: 600;
  margin-left: 4px;
}

.chart-card {
  display: flex;
  flex-direction: column;
}

/* The plot fills whatever height the row gives the card; the SVG is absolutely
   placed so it never feeds back into that height. */
.chart {
  position: relative;
  flex: 1 1 auto;
  min-height: 268px;
}

.chart > svg {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.chart svg:focus-visible {
  outline-offset: 4px;
  border-radius: 6px;
}

.chart .grid line {
  stroke: var(--grid);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.chart .baseline {
  stroke: var(--axis);
  shape-rendering: crispEdges;
}

.chart .tick {
  fill: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart .col {
  transition: opacity 0.12s;
}

.chart.has-active .col:not(.is-active) {
  opacity: 0.38;
}

.chart .hover-band {
  fill: var(--surface-2);
  opacity: 0;
}

.chart .col.is-active .hover-band {
  opacity: 1;
}

.chart-empty {
  display: grid;
  place-items: center;
  min-height: 268px;
  color: var(--ink-2);
  text-align: center;
  gap: 4px;
}

.chart-empty b {
  color: var(--ink);
}

/* ---------- bar lists (models, tools) */
.bars {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  align-items: baseline;
}

.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.bar-label small {
  color: var(--ink-2);
  font-weight: 400;
  margin-left: 6px;
}

.bar-value {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 600;
}

.bar-track {
  grid-column: 1 / -1;
  height: 8px;
}

.bar-fill {
  height: 100%;
  min-width: 3px;
  border-radius: 0 4px 4px 0;
  background: var(--mix-1);
}

.muted-note {
  color: var(--ink-2);
  font-size: 13px;
  padding: 6px 0;
}

/* ---------- computers */
.devices {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}

.device {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.device:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.device.is-dim {
  opacity: 0.5;
}

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

@keyframes flash {
  0% {
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--good) 70%, transparent), var(--shadow);
  }
  100% {
    box-shadow: 0 0 0 2px transparent, var(--shadow);
  }
}

.device-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  flex: none;
  margin-top: 4px;
}

.device-name {
  font-size: 15px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.device-meta {
  color: var(--ink-2);
  font-size: 12.5px;
  margin-top: 1px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  white-space: nowrap;
}

.status .icon {
  width: 14px;
  height: 14px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
}

.status-active .status-dot {
  animation: pulse 2s infinite;
}

.status-active {
  color: var(--ink);
}

.status-paused .icon {
  color: var(--warning);
}

.status-limit .icon {
  color: var(--critical);
}

.status-waiting .icon,
.status-idle .icon {
  color: var(--muted);
}

.device-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.stat-label {
  color: var(--ink-2);
  font-size: 12px;
}

.stat-value {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.spark {
  display: block;
  width: 100%;
  height: 40px;
  overflow: visible;
}

.device-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--ink-2);
  font-size: 12.5px;
}

.meter {
  display: grid;
  gap: 5px;
}

.meter-head {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--ink-2);
}

.meter-head b {
  color: var(--ink);
  font-weight: 600;
}

.meter-track {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--ink-2);
}

.meter-fill.warn {
  background: var(--warning);
}

.meter-fill.over {
  background: var(--critical);
}

/* ---------- sessions table */
.table-wrap {
  overflow-x: auto;
  margin: 0 -20px -20px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  text-align: left;
  font-weight: 600;
  color: var(--ink-2);
  font-size: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.table th:first-child,
.table td:first-child {
  padding-left: 20px;
}

.table th:last-child,
.table td:last-child {
  padding-right: 20px;
}

.table tr:last-child td {
  border-bottom: 0;
}

.table-wrap > .muted-note {
  padding: 0 20px 20px;
}

.chart .table-wrap {
  margin: 0 -20px;
  max-height: 268px;
  overflow: auto;
}

.drawer .table-wrap {
  margin: 0 -24px;
}

.drawer .table-wrap > .muted-note {
  padding: 0 24px;
}

.table .num {
  text-align: right;
}

.table tbody tr.clickable {
  cursor: pointer;
}

.table tbody tr.clickable:hover,
.table tbody tr.clickable:focus-visible {
  background: var(--surface-2);
  outline: none;
}

.who {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 220px;
}

.who span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.who .swatch {
  margin-top: 0;
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
}

.pill-live {
  color: var(--ink);
}

.pill-live::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--good);
  animation: pulse 2s infinite;
}

/* ---------- live feed */
.feed-card {
  display: flex;
  flex-direction: column;
}

/* contain: size keeps a long feed from stretching the row; it scrolls inside
   whatever height the sessions card next to it sets. */
.feed {
  flex: 1 1 auto;
  min-height: 420px;
  contain: size;
  list-style: none;
  margin: 0 -8px;
  padding: 0;
  overflow-y: auto;
}

.table-more {
  display: flex;
  justify-content: center;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
}

.feed li {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  gap: 2px 10px;
  padding: 9px 8px;
  border-radius: 10px;
}

.feed li.new {
  animation: arrive 1.6s ease-out;
}

@keyframes arrive {
  0% {
    background: color-mix(in srgb, var(--good) 16%, transparent);
    transform: translateY(-4px);
  }
  20% {
    transform: none;
  }
  100% {
    background: transparent;
  }
}

.feed-icon {
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--ink-2);
}

.feed-icon .icon {
  width: 15px;
  height: 15px;
}

.feed-icon.bad {
  color: var(--critical);
}

.feed-icon.blocked {
  color: var(--warning);
}

.feed-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.feed-time {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.feed-text {
  grid-column: 2 / -1;
  color: var(--ink-2);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.feed-text .who {
  vertical-align: bottom;
  max-width: 140px;
  margin-right: 6px;
  color: var(--ink);
}

/* ---------- empty state */
.empty {
  display: grid;
  place-items: center;
  padding: 48px 0;
}

.empty-card {
  max-width: 720px;
  text-align: center;
  padding: 40px 36px;
}

.empty-card h1 {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.empty-card > p {
  color: var(--ink-2);
  margin: 10px auto 26px;
  max-width: 540px;
  font-size: 15px;
}

.steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 0 0 28px;
  padding: 0;
  list-style: none;
  text-align: left;
  counter-reset: step;
}

.steps li {
  counter-increment: step;
  padding: 16px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 13px;
}

.steps li::before {
  content: counter(step);
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-bottom: 10px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--page);
  font-weight: 700;
  font-size: 12px;
}

.steps b {
  display: block;
  color: var(--ink);
  margin-bottom: 2px;
}

/* ---------- drawer and modal */
dialog {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0;
}

dialog::backdrop {
  background: rgba(10, 10, 10, 0.45);
  backdrop-filter: blur(2px);
}

.drawer {
  margin: 0 0 0 auto;
  width: min(560px, 100vw);
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  border-width: 0 0 0 1px;
  box-shadow: var(--shadow-lg);
}

.drawer[open] {
  animation: slide-in 0.22s ease-out;
}

@keyframes slide-in {
  from {
    transform: translateX(40px);
    opacity: 0;
  }
}

.drawer-body {
  padding: 22px 24px 32px;
}

.modal {
  width: min(620px, calc(100vw - 32px));
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
}

.modal[open] {
  animation: pop 0.18s ease-out;
}

@keyframes pop {
  from {
    transform: scale(0.97);
    opacity: 0;
  }
}

.modal-body {
  padding: 24px;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}

.dialog-head h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.dialog-head p {
  color: var(--ink-2);
  margin-top: 3px;
}

.dialog-head .icon-btn {
  margin: -6px -8px 0 auto;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 22px;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
}

.field > span {
  font-weight: 600;
}

.field small,
.hint {
  color: var(--ink-2);
  font-size: 12.5px;
}

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-2);
  cursor: pointer;
}

.check input {
  margin-top: 3px;
  accent-color: var(--brand);
}

.check b {
  display: block;
}

.error {
  color: var(--critical);
  font-size: 13px;
  min-height: 18px;
}

.setup-steps {
  display: grid;
  gap: 18px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.setup-steps > li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 4px 12px;
}

.setup-steps > li::before {
  content: counter(step);
  grid-row: span 3;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--page);
  font-weight: 700;
  font-size: 12px;
}

.setup-steps b {
  font-weight: 650;
}

.setup-steps p {
  color: var(--ink-2);
  font-size: 13px;
}

.code {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 6px;
  padding: 10px 10px 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12.5px;
}

.code pre {
  margin: 0;
  flex: 1;
  min-width: 0;
  white-space: pre-wrap;
  word-break: break-all;
}

.code pre.scroll {
  max-height: 220px;
  overflow: auto;
  white-space: pre;
  word-break: normal;
}

.code .icon-btn {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 8px;
  background: var(--surface);
  border-color: var(--border);
}

.callout {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  padding: 12px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--warning) 14%, var(--surface));
  font-size: 13px;
}

.callout .icon {
  color: var(--warning);
  margin-top: 1px;
}

details.more {
  margin-top: 16px;
}

details.more summary {
  cursor: pointer;
  color: var(--ink-2);
  font-weight: 600;
  font-size: 13px;
}

.panel {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.panel > h3 {
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-2);
  margin-bottom: 12px;
}

.mini-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px 12px;
}

.kv {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 8px 12px;
  margin: 0;
  font-size: 13px;
}

.kv dt {
  color: var(--ink-2);
}

.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-2);
  margin-bottom: 14px;
}

.control-row b {
  display: block;
}

.control-row small {
  color: var(--ink-2);
}

.limits {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.limits .field {
  margin: 0;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}

.timeline li {
  display: grid;
  grid-template-columns: 52px 28px minmax(0, 1fr);
  gap: 0 10px;
  padding: 7px 0;
  font-size: 13px;
}

.timeline .t {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  padding-top: 5px;
}

.timeline .feed-icon {
  width: 28px;
  height: 28px;
  grid-row: auto;
}

.timeline .what b {
  font-weight: 600;
}

.timeline .what p {
  color: var(--ink-2);
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

.prompt-text {
  margin-top: 4px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  white-space: pre-wrap;
  max-height: 160px;
  overflow: auto;
}

/* ---------- tooltip and toast */
.tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  min-width: 180px;
  max-width: 300px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  font-size: 12.5px;
}

.tooltip-title {
  color: var(--ink-2);
  font-size: 12px;
  margin-bottom: 6px;
}

.tooltip-total {
  font-size: 16px;
  font-weight: 650;
  margin-bottom: 6px;
}

.tooltip-row {
  display: grid;
  grid-template-columns: 14px auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 2px 0;
}

.tooltip-row b {
  font-variant-numeric: tabular-nums;
}

.tooltip-row span:last-child {
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.line-key {
  width: 14px;
  height: 3px;
  border-radius: 2px;
}

/* A manual popover, so it lands in the top layer above any open dialog. */
.toast {
  position: fixed;
  inset: auto auto 24px 50%;
  margin: 0;
  border: 0;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--page);
  font-weight: 600;
  box-shadow: var(--shadow-lg);
}

.drawer .table th:first-child,
.drawer .table td:first-child {
  padding-left: 24px;
}

.drawer .table th:last-child,
.drawer .table td:last-child {
  padding-right: 24px;
}

.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
  margin-top: 36px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12.5px;
}

/* ---------- login */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.login-card {
  width: min(400px, 100%);
  padding: 32px 28px;
}

.login-card h1 {
  font-size: 22px;
  margin: 22px 0 6px;
  letter-spacing: -0.02em;
}

.login-card > p {
  color: var(--ink-2);
  margin-bottom: 20px;
}

.login-card .btn {
  width: 100%;
  height: 42px;
}

.login-foot {
  margin-top: 18px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* ---------- responsive */
@media (max-width: 1180px) {
  .kpis {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .kpi-hero {
    grid-column: 1 / -1;
  }
  .row-main,
  .row-bottom {
    grid-template-columns: minmax(0, 1fr);
  }
  .stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar-inner,
  .page {
    padding-left: 16px;
    padding-right: 16px;
  }
  .topbar-inner {
    gap: 8px;
  }
  .live-label,
  .btn-primary span {
    display: none;
  }
  .btn-primary {
    width: 36px;
    padding: 0;
  }
  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
  .kpi-hero .kpi-value {
    font-size: 48px;
  }
  .kpi-value {
    font-size: 24px;
  }
  .stack,
  .steps,
  .limits {
    grid-template-columns: minmax(0, 1fr);
  }
  .segmented .long {
    display: none;
  }
  .segmented .short {
    display: inline;
  }
  .updated {
    margin-left: 0;
  }
  .card {
    padding: 16px;
  }
  .table-wrap {
    margin: 0 -16px -16px;
  }
  .card-head {
    flex-wrap: wrap;
  }
  .devices {
    grid-template-columns: minmax(0, 1fr);
  }
  .drawer-body,
  .modal-body {
    padding: 18px 16px 28px;
  }
  .mini-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .kv {
    grid-template-columns: 110px minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
