/*
  The component kit (spec 0012 §3): one class family per component, behaviour and sizes as in HyperLiquid's app, colours from tokens.css.
  Every page shows them; /kit shows each one in every state in both themes.
*/
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scrollbar-color: var(--border-strong) var(--canvas); }
body {
  margin: 0; background: var(--canvas); color: var(--text);
  font: var(--fs)/1.45 var(--font); font-variant-ligatures: no-contextual;
}
[data-theme] { color: var(--text); }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.num, td, th, .stat-value, input { font-variant-numeric: tabular-nums lining-nums; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.pos { color: var(--green); }
.neg { color: var(--red); }
.eyebrow { font-size: var(--fs-xs); letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; position: relative; overflow: hidden;
  height: var(--h); padding: 0 16px; border: 1px solid transparent; border-radius: var(--radius-sm);
  font: inherit; font-size: var(--fs-sm); line-height: 1; white-space: nowrap; cursor: pointer;
  background: var(--surface-raised); color: var(--text);
  transition: background-color var(--dur) ease-in-out, border-color var(--dur) ease-in-out, color var(--dur) ease-in-out;
}
.btn-sm { height: var(--h-sm); padding: 0 12px; }
.btn-lg { height: var(--h-lg); padding: 0 20px; font-size: var(--fs); }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-outline { background: transparent; border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-long { background: var(--green); color: var(--on-green); }
.btn-short { background: var(--red); color: var(--on-red); }
@media (hover: hover) {
  .btn:hover { background: var(--surface-hover); }
  .btn-primary:hover { background: var(--accent-hover); }
  .btn-outline:hover { background: var(--accent-soft); }
  .btn-ghost:hover { background: transparent; color: var(--text); }
  .btn-long:hover, .btn-short:hover { filter: brightness(1.08); }
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .4; cursor: default; pointer-events: none; }
.btn[aria-busy="true"] { cursor: progress; }
.btn[aria-busy="true"]::after {
  content: ""; position: absolute; left: 0; bottom: 0; height: 2px; width: 30%; background: currentColor; opacity: .6;
  animation: sweep 1s linear infinite;
}
.icon-btn {
  display: inline-grid; place-items: center; width: var(--h-sm); height: var(--h-sm); padding: 0; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-muted); cursor: pointer; font: inherit;
}
.icon-btn:hover { color: var(--text); background: var(--surface-hover); }
.icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Segmented control and chips: a group of buttons, the pressed one filled */
.seg { display: inline-flex; align-self: flex-start; padding: 2px; gap: 2px; border-radius: var(--radius-sm); background: var(--surface-raised); }
.seg > button { white-space: nowrap;
  height: calc(var(--h) - 4px); padding: 0 14px; border: 0; border-radius: calc(var(--radius-sm) - 2px); flex: 1 1 0;
  background: transparent; color: var(--text-muted); font: inherit; font-size: var(--fs-sm); cursor: pointer;
  transition: background-color var(--dur), color var(--dur);
}
.seg > button:hover { color: var(--text); }
.seg > button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.seg-sides > button[aria-pressed="true"]:first-child { background: var(--green-soft); color: var(--green); }
.seg-sides > button[aria-pressed="true"]:last-child { background: var(--red-soft); color: var(--red); }
.seg-block { display: flex; align-self: stretch; width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: var(--h-sm); padding: 0 12px; border: 1px solid var(--border); border-radius: 999px; background: transparent;
  color: var(--text-muted); font: inherit; font-size: var(--fs-sm); cursor: pointer; transition: border-color var(--dur), color var(--dur), background-color var(--dur);
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.chip:disabled { opacity: .4; cursor: default; }

/* Tabs: text tabs with a sliding 1 px accent underline */
.tabs { position: relative; display: flex; gap: 18px; box-shadow: inset 0 -1px 0 var(--divider); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs > [role="tab"] {
  height: var(--h); padding: 0; border: 0; background: none; color: var(--text-muted); font: inherit; font-size: var(--fs-sm);
  cursor: pointer; white-space: nowrap; transition: color var(--dur);
}
.tabs > [role="tab"]:hover, .tabs > [role="tab"][aria-selected="true"] { color: var(--text); }
.tabs-ink { position: absolute; bottom: 0; left: 0; height: 1px; width: 0; background: var(--accent); transition: left .3s, width .3s; pointer-events: none; }
.tabs-compact { gap: 2px; box-shadow: none; }
.tabs-compact > [role="tab"] { height: var(--h-sm); padding: 0 8px; border-radius: var(--radius-sm); }
.tabs-compact > [role="tab"][aria-selected="true"] { background: var(--surface-raised); }
.tabs-compact .tabs-ink { display: none; }

/* Input: bordered box, label inside on the left, unit on the right */
.field {
  display: flex; align-items: center; gap: 6px; height: var(--h); padding: 0 10px; min-width: 0;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: transparent;
  transition: background-color var(--dur), border-color var(--dur);
}
.field:hover, .field:focus-within { background: var(--surface-hover); border-color: var(--text-muted); }
.field:focus-within { border-color: var(--focus); }
.field-label { font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; }
.field input, .field select {
  flex: 1 1 auto; min-width: 0; width: 100%; height: 100%; border: 0; outline: 0; padding: 0; background: transparent;
  color: var(--text); font: inherit; font-size: var(--fs-sm); text-align: right;
}
.field input::placeholder { color: var(--text-faint); }
.field input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.field input::-webkit-outer-spin-button, .field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.field input[type="date"] { color-scheme: dark; }
.field-unit { font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; }
.field.is-invalid { border-color: var(--red); }
.field.is-disabled { opacity: .45; pointer-events: none; }
.field-msg { margin: 4px 0 0; font-size: var(--fs-xs); color: var(--red); }
.field-hint { margin: 4px 0 0; font-size: var(--fs-xs); color: var(--text-faint); }
.textarea {
  width: 100%; min-height: 160px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: transparent; color: var(--text); font: var(--fs-sm)/1.5 var(--mono); resize: vertical;
}
.textarea:focus { outline: 0; border-color: var(--focus); }

/* Dropdown: a button with a chevron, a dark menu; the searchable variant has a filter box and groups */
.dd { position: relative; display: inline-block; min-width: 0; }
.dd-block { display: block; }
.dd-btn {
  display: flex; align-items: center; gap: 8px; width: 100%; height: var(--h); padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: transparent; color: var(--text);
  font: inherit; font-size: var(--fs-sm); text-align: left; cursor: pointer; transition: background-color var(--dur), border-color var(--dur);
}
.dd-btn:hover, .dd[data-open] .dd-btn { background: var(--surface-hover); border-color: var(--text-muted); }
.dd-btn:disabled { opacity: .45; cursor: default; }
.dd.is-invalid .dd-btn { border-color: var(--red); }
.dd-btn .dd-label { color: var(--text-muted); }
.dd-btn .dd-value { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-btn .icon { transition: transform var(--dur); color: var(--text-muted); }
.dd[data-open] .dd-btn .icon { transform: rotate(180deg); }
.dd-plain .dd-btn { border-color: transparent; padding: 0 4px; width: auto; }
.dd-menu, .table-wrap { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.dd-menu {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; min-width: 100%; max-height: 300px; overflow: auto;
  padding: 4px 0; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-raised);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}
.dd-menu[hidden] { display: none; }
.dd-right .dd-menu { left: auto; right: 0; }
.dd-search { padding: 4px 6px 6px; position: sticky; top: -4px; background: var(--surface-raised); }
.dd-search input {
  width: 100%; height: var(--h-sm); padding: 0 8px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: var(--fs-sm); outline: 0;
}
.dd-search input:focus { border-color: var(--focus); }
.dd-group { padding: 6px 10px 2px; font-size: var(--fs-xs); letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); }
[role="option"] {
  display: flex; align-items: baseline; gap: 8px; padding: 0 10px; line-height: var(--row); min-height: var(--row);
  font-size: var(--fs-sm); color: var(--text-muted); cursor: pointer; white-space: nowrap;
}
[role="option"] .opt-sub { margin-left: auto; padding-left: 16px; font-size: var(--fs-xs); color: var(--text-faint); }
[role="option"][data-active], [role="option"]:hover { background: var(--surface-hover); color: var(--text); }
[role="option"][aria-selected="true"] { color: var(--text); }
[role="option"][aria-selected="true"]::after { content: "✓"; margin-left: 8px; color: var(--accent); }
[role="option"][aria-selected="true"] .opt-sub + ::after { margin-left: 0; }
.dd-empty { padding: 6px 10px; font-size: var(--fs-sm); color: var(--text-faint); }

/* Slider: 8 px track, five dots, ringed thumb, value box beside */
.slider { display: flex; align-items: center; gap: 10px; }
.slider-track { position: relative; flex: 1 1 auto; height: var(--h); display: flex; align-items: center; }
.slider-track input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 8px; margin: 0; border-radius: 14px; outline-offset: 6px;
  background: linear-gradient(to right, var(--accent-soft) 0 var(--pct, 0%), var(--surface-raised) var(--pct, 0%) 100%);
  position: relative; z-index: 1; cursor: pointer;
}
.slider-track input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--accent-soft);
  border: 2px solid var(--accent); box-shadow: 0 0 0 0 var(--accent-soft); transition: box-shadow var(--dur);
}
.slider-track input[type="range"]::-moz-range-thumb {
  width: 10px; height: 10px; border-radius: 50%; background: var(--accent-soft); border: 2px solid var(--accent);
}
.slider-track input[type="range"]:hover::-webkit-slider-thumb { box-shadow: 0 0 0 6px var(--accent-soft); }
.slider-track input[type="range"]:active::-webkit-slider-thumb { box-shadow: 0 0 0 9px var(--accent-soft); }
.slider-dots { position: absolute; inset: 0 7px; display: flex; justify-content: space-between; align-items: center; pointer-events: none; z-index: 2; }
.slider-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--border-strong); }
.slider-dots span[data-on] { background: var(--accent); }
.slider .field { width: 78px; flex: none; }

/* Checkbox and toggle */
.check { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--text); cursor: pointer; }
.check input {
  -webkit-appearance: none; appearance: none; width: 14px; height: 14px; margin: 0; border: 1px solid var(--border-strong);
  border-radius: 3px; background: transparent; display: grid; place-items: center; cursor: pointer; flex: none;
}
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after {
  content: ""; width: 7px; height: 4px; border: solid var(--on-accent); border-width: 0 0 1.5px 1.5px; transform: translateY(-1px) rotate(-45deg);
}
.check input[type="checkbox"][role="switch"] { width: 28px; height: 16px; border-radius: 999px; background: var(--surface-raised); position: relative; place-items: unset; }
.check input[role="switch"]::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 10px; height: 10px; border-radius: 50%; background: var(--text-muted);
  border: 0; transform: none; transition: left var(--dur), background-color var(--dur);
}
.check input[role="switch"]:checked { background: var(--accent-soft); border-color: var(--accent); }
.check input[role="switch"]:checked::after { left: 14px; background: var(--accent); width: 10px; height: 10px; }
.check:has(input:disabled) { opacity: .45; cursor: default; }

/* Pill badge */
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 20px; padding: 0 8px; border-radius: 999px;
  font-size: 10px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap;
  border: 1px solid var(--border); color: var(--text-muted);
}
.pill-accent { border-color: transparent; background: var(--accent-soft); color: var(--accent); }
.pill-green { border-color: transparent; background: var(--green-soft); color: var(--green); }
.pill-red { border-color: transparent; background: var(--red-soft); color: var(--red); }
.pill-warn { border-color: transparent; background: var(--warn-soft); color: var(--warn); }
.pill-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-live::before { animation: pulse 1s ease-in-out infinite alternate; }

/* Tooltip (positioned by kit/overlay.js) */
.tooltip {
  position: fixed; z-index: 60; max-width: 320px; padding: 6px 10px; border-radius: 5px; pointer-events: none;
  background: var(--surface-raised); border: 1px solid var(--border); color: var(--text); font-size: var(--fs-xs); line-height: 1.4;
  opacity: 0; transition: opacity .2s;
}
.tooltip[data-show] { opacity: 1; }

/* Modal: the native dialog */
dialog.modal {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--border);
  border-radius: var(--radius-lg); background: var(--surface); color: var(--text); overflow: auto;
}
dialog.modal::backdrop { background: var(--overlay); backdrop-filter: blur(2px); }
dialog.modal[open] { animation: fade .1s ease-out; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--divider); }
.modal-head h2 { font-size: var(--fs-lg); }
.modal-body { padding: 16px 20px; font-size: var(--fs); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; }
@media (max-width: 480px) {
  dialog.modal { width: 100vw; max-width: 100vw; max-height: 100vh; height: 100vh; margin: 0; border-radius: 0; }
}

/* Toasts: bottom right, at most three */
.toasts { position: fixed; z-index: 70; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; width: min(340px, calc(100vw - 32px)); }
.toast {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-size: var(--fs-sm); box-shadow: 0 8px 24px rgba(0, 0, 0, .35); animation: rise .2s ease-out;
}
.toast:nth-child(n+4) { display: none; }
.toast::before { content: ""; width: 3px; align-self: stretch; border-radius: 2px; background: var(--text-muted); flex: none; }
.toast-ok::before { background: var(--green); }
.toast-err::before { background: var(--red); }
.toast-info::before { background: var(--accent); }
.toast-text { flex: 1 1 auto; }
.toast .icon-btn { width: 20px; height: 20px; margin: -2px -4px 0 0; }

/* Progress bar: 4 px, determinate or indeterminate */
.progress { height: 4px; border-radius: 2px; background: var(--accent-soft); overflow: hidden; position: relative; }
.progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 2px; transition: width .2s ease-out; }
.progress[data-indeterminate] .progress-fill { width: 20%; position: absolute; animation: sweep 1s linear infinite; }
.progress-label { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: var(--fs-sm); color: var(--text-muted); }

/* Stage list (run phases) */
.stages { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: var(--fs-sm); }
.stages li { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; color: var(--text-faint); }
.stages li::before { content: ""; width: 6px; height: 6px; border-radius: 50%; border: 1px solid currentColor; flex: none; transform: translateY(-1px); }
.stages li[data-state="active"] { color: var(--text); }
.stages li[data-state="active"]::before { background: var(--accent); border-color: var(--accent); animation: pulse 1s ease-in-out infinite alternate; }
.stages li[data-state="done"] { color: var(--text-muted); }
.stages li[data-state="done"]::before { background: var(--green); border-color: var(--green); }
.stages li[data-state="failed"] { color: var(--red); }
.stages li[data-state="failed"]::before { background: var(--red); border-color: var(--red); }
.stages .stage-ms { margin-left: auto; color: var(--text-faint); }

/* Skeleton */
.skeleton {
  display: block; border-radius: 2px; min-height: 12px;
  background: linear-gradient(90deg, transparent 0, rgba(255, 255, 255, .08) 50%, transparent 100%) var(--divider);
  background-size: 200% 100%; animation: shimmer 3s linear infinite;
}

/* Table: sticky header, numbers right-aligned */
.table-wrap { overflow: auto; max-height: 420px; }
.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.tbl th, .tbl td { height: var(--row); padding: 0 8px; text-align: right; white-space: nowrap; }
.tbl th { position: sticky; top: 0; z-index: 1; background: var(--surface); color: var(--text-muted); font-weight: 400; border-bottom: 1px solid var(--divider); }
.tbl td { border-bottom: 1px solid var(--divider); }
.tbl .l { text-align: left; }
.tbl tbody tr:hover td { background: var(--surface-hover); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl-note { padding: 6px 8px; font-size: var(--fs-xs); color: var(--text-faint); }

/* Stat tile */
/* Lines between tiles only: each tile draws its right and bottom line, the outer ones are clipped away. */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); overflow: hidden; }
.stat { padding: 10px 12px; min-width: 0; border-right: 1px solid var(--divider); border-bottom: 1px solid var(--divider); margin: 0 -1px -1px 0; }
.stat-label { font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value { margin-top: 2px; font-size: 18px; line-height: 1.2; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-sub { margin-top: 2px; font-size: var(--fs-xs); color: var(--text-faint); }

/* Panels: BL's terminal style, 1 px border grid between them */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; padding: 0 12px; border-bottom: 1px solid var(--divider); }
.panel-head h2, .panel-head h3 { font-size: var(--fs-sm); font-weight: 500; }
.panel-body { padding: 12px; }
.panel-grid { display: grid; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.panel-grid > .panel { border: 0; border-radius: 0; }

/* Problem box (errors) */
.problem { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--red-soft); border-left: 2px solid var(--red); font-size: var(--fs-sm); }
.problem strong { color: var(--red); font-weight: 600; }
.problem p, .problem ul { margin: 4px 0 0; }
.problem ul { padding-left: 16px; }
.problem code { font-family: var(--mono); font-size: var(--fs-xs); color: var(--text-muted); }
.notice { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--warn-soft); border-left: 2px solid var(--warn); font-size: var(--fs-sm); }

@keyframes sweep { from { left: -30%; transform: translateX(0); } to { left: 100%; } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes pulse { from { opacity: 1; } to { opacity: .35; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; animation-iteration-count: 1 !important; transition-duration: 0s !important; }
  .progress[data-indeterminate] .progress-fill { left: 0; width: 100%; opacity: .5; }
}
