:root {
  --ink: #0B0F13;
  --panel: #151B21;
  --mist: #C9D2D8;
  --steel: #7BA8B6;
  --brass: #C4A574;
  --raise: #1C242C;
  --mute: #8A969E;
  --line: rgba(201, 210, 216, 0.1);
  --fault: #D16A5E;
  --ok: #8FB3A0;
  --reason: #6D818C;
  --rail: 14.5rem;
  --radius: 12px;
  --gap: 1.25rem;
  --page: 68rem;
  --control: 2.25rem;
  --sans: "Bricolage Grotesque", sans-serif;
  --mono: "Red Hat Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { color-scheme: dark; }
body {
  background: var(--ink);
  color: var(--mist);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--steel); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--mist); }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
:focus-visible {
  outline: 2px solid var(--steel);
  outline-offset: 2px;
}
::selection {
  background: color-mix(in srgb, var(--brass) 38%, transparent);
  color: var(--mist);
}

.fuse-wire {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--brass);
  z-index: 50;
  pointer-events: none;
}

.skip {
  position: absolute;
  left: 0.75rem;
  top: -3rem;
  z-index: 60;
  padding: 0.4rem 0.7rem;
  background: var(--panel);
  color: var(--mist);
  border-radius: 8px;
}
.skip:focus { top: 0.75rem; }

/* —— App shell —— */
body.is-app {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  min-height: 100vh;
}
.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 1.5rem 0.85rem 1.15rem;
  border-right: 1px solid var(--line);
  background: var(--ink);
  z-index: 10;
}
.mark {
  display: block;
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.03em;
  color: var(--mist);
  text-decoration: none;
  padding: 0.15rem 0.75rem 0.35rem;
}
.mark:hover { color: var(--brass); }
.rail nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 1.35rem;
}
.rail nav a {
  display: flex;
  align-items: center;
  height: var(--control);
  padding: 0 0.75rem;
  border-radius: 8px;
  color: var(--mute);
  text-decoration: none;
  font-size: 0.95rem;
}
.rail nav a:hover {
  color: var(--mist);
  background: var(--raise);
}
.rail nav a.on {
  color: var(--mist);
  background: var(--raise);
  box-shadow: inset 2px 0 0 var(--brass);
}
.rail-rule {
  display: block;
  height: 1px;
  margin: 0.55rem 0.75rem;
  background: var(--line);
}
.who {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1rem 0.75rem 0.25rem;
  border-top: 1px solid var(--line);
}
.who span {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--mute);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.who .btn { width: 100%; }

.stage { min-width: 0; }
.stage-inner {
  max-width: var(--page);
  margin: 0 auto;
  padding: 0 2rem 4rem;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  min-height: 5.25rem;
  padding: 2rem 0 1.35rem;
}
.page-copy { min-width: 0; flex: 1; }
.page-copy h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--mist);
}
.page-copy p {
  margin: 0.4rem 0 0;
  max-width: 54ch;
  color: var(--mute);
  font-size: 0.95rem;
  overflow-wrap: normal;
}
.page-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-shrink: 0;
  min-height: var(--control);
  gap: 0.5rem;
}
.page-actions form { margin: 0; display: flex; }

main { min-width: 0; }

/* —— Auth —— */
body.is-auth .stage,
body.is-auth .stage-inner {
  max-width: none;
  margin: 0;
  padding: 0;
}
.auth-main {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
}
.auth-brand {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 12vh 10vw 4rem;
}
.auth-brand h1 {
  font-size: clamp(2.2rem, 4.6vw, 3.6rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.03em;
  margin: 0.45rem 0 1rem;
}
.auth-pane {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12vh 8vw 4rem;
  background: color-mix(in srgb, var(--panel) 55%, var(--ink));
  border-left: 1px solid var(--line);
}
.auth-card {
  width: min(22.5rem, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.75rem 1.75rem 1.5rem;
}
.auth-card h2 {
  margin: 0 0 1.1rem;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}

/* —— Type helpers —— */
.eyebrow {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass);
  margin: 0;
}
.lede { max-width: 36ch; color: var(--mute); margin: 0; }
.aside { font-size: 0.9rem; color: var(--mute); margin: 1rem 0 0; }
.err, .callout.fault { color: var(--fault); }
.ok, .callout.ok { color: var(--ok); }
.callout {
  margin: 0 0 0.85rem;
  font-size: 0.9rem;
}
.empty { color: var(--mute); margin: 0; font-size: 0.9rem; }
.mono { font-family: var(--mono); font-size: 0.8125rem; }
.wrap { overflow-wrap: anywhere; word-break: break-all; }
.nows { white-space: nowrap; }

/* —— Controls —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--control);
  padding: 0 0.95rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--brass);
  color: var(--ink);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); color: var(--ink); }
.btn.ghost {
  background: transparent;
  color: var(--mist);
  border-color: var(--line);
  font-weight: 500;
  filter: none;
}
.btn.ghost:hover {
  background: var(--raise);
  border-color: color-mix(in srgb, var(--mist) 22%, transparent);
  color: var(--mist);
  filter: none;
}
.btn.danger {
  background: transparent;
  color: var(--fault);
  border-color: color-mix(in srgb, var(--fault) 38%, transparent);
  font-weight: 500;
}
.btn.danger:hover {
  background: color-mix(in srgb, var(--fault) 12%, transparent);
  color: var(--fault);
  filter: none;
}
.btn.sm {
  height: 1.9rem;
  padding: 0 0.7rem;
  font-size: 0.8rem;
}

label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; color: var(--mute); }
label.check {
  flex-direction: row;
  align-items: center;
  gap: 0.55rem;
  color: var(--mist);
}
label.check input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--brass);
  flex-shrink: 0;
}
form.stack, .auth-card form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
form.stack .btn { align-self: flex-start; }
.auth-card form .btn { width: 100%; }
input, select, textarea {
  background: var(--raise);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  color: var(--mist);
  width: 100%;
}
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--mute) 88%, var(--mist)); }
input:focus, select:focus, textarea:focus {
  border-color: var(--steel);
  outline: none;
}
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--mute) 50%),
    linear-gradient(135deg, var(--mute) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 1.8rem;
}
textarea { min-height: 8rem; resize: vertical; }

.badge {
  display: inline-flex;
  align-items: center;
  height: 1.35rem;
  padding: 0 0.5rem;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--raise);
  color: var(--mute);
  border: 1px solid var(--line);
}
.badge.on {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 35%, transparent);
  background: color-mix(in srgb, var(--ok) 12%, transparent);
}
.badge.off {
  color: var(--mute);
}
.badge.admin {
  color: var(--brass);
  border-color: color-mix(in srgb, var(--brass) 35%, transparent);
  background: color-mix(in srgb, var(--brass) 12%, transparent);
}
.badge.held {
  color: var(--fault);
  border-color: color-mix(in srgb, var(--fault) 35%, transparent);
  background: color-mix(in srgb, var(--fault) 12%, transparent);
}
.badge.cool {
  color: var(--brass);
  border-color: color-mix(in srgb, var(--brass) 35%, transparent);
  background: color-mix(in srgb, var(--brass) 12%, transparent);
}
.account.held {
  box-shadow: inset 2px 0 0 var(--fault);
}

/* —— Surfaces —— */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.2rem 1.35rem 1.3rem;
}
.panel h2 {
  margin: 0 0 0.9rem;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}
.grid-2 > .panel { min-width: 0; }
.stack-y { display: flex; flex-direction: column; gap: var(--gap); }
.key-meta { margin: 0.75rem 0 0; color: var(--mute); }
.panel-foot { margin-top: 0.9rem; }
.panel .callout { margin: 0.85rem 0; }
.panel .code-chip + .code-chip { margin-top: 0.75rem; }

.copy { cursor: pointer; }
.copy:hover { color: var(--steel); }
.copy.ok { color: var(--ok); }
.key { font-size: 0.8rem; }

.code-chip {
  display: block;
  font-family: var(--mono);
  font-size: 0.8rem;
  background: var(--raise);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  overflow-wrap: anywhere;
  word-break: break-all;
}
.code-block {
  font-family: var(--mono);
  font-size: 0.78rem;
  background: var(--raise);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.85rem 0.9rem;
  overflow-x: auto;
  white-space: pre;
  color: var(--mist);
  margin: 0.85rem 0 0;
  line-height: 1.5;
}
.pills {
  list-style: none;
  margin: 0.85rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.pill {
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  background: var(--raise);
  border: 1px solid var(--line);
  color: var(--mist);
}

/* —— Tables —— */
.table-wrap { overflow-x: auto; margin: 0 -0.15rem; }
.log {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.log th {
  text-align: left;
  font-weight: 500;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--mute);
  padding: 0.2rem 0.75rem 0.65rem 0;
  white-space: nowrap;
}
.log td {
  padding: 0.7rem 0.75rem 0.7rem 0;
  border-top: 1px solid var(--line);
  vertical-align: middle;
  overflow-wrap: anywhere;
}
.log td:last-child, .log th:last-child { padding-right: 0; }
.log .num { text-align: right; font-variant-numeric: tabular-nums; }
.log th.num { text-align: right; }
.log .tight {
  width: 1%;
  min-width: max-content;
  white-space: nowrap;
  overflow-wrap: normal;
  padding-left: 1.1rem;
}
.log tbody tr:hover td {
  background: color-mix(in srgb, var(--mist) 3%, transparent);
}
.row-actions {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
  flex-wrap: nowrap;
  white-space: nowrap;
  width: max-content;
  min-width: 9.25rem;
  margin-left: auto;
}

/* —— Usage —— */
.stat .week { margin: 0.35rem 0 0.35rem; }
.stat .num {
  font-family: var(--mono);
  font-size: 2.35rem;
  font-weight: 500;
  letter-spacing: -0.04em;
  color: var(--mist);
  font-variant-numeric: tabular-nums;
}
.stat .unit {
  font-size: 1rem;
  color: var(--mute);
  margin-left: 0.2rem;
}
.usage-sub {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--mute);
}

.interval {
  display: inline-flex;
  gap: 2px;
  background: var(--raise);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
  flex-shrink: 0;
}
.interval button {
  background: transparent;
  color: var(--mute);
  border: 0;
  height: calc(var(--control) - 8px);
  padding: 0 0.75rem;
  border-radius: 7px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.interval button.on {
  background: var(--panel);
  color: var(--mist);
  box-shadow: 0 0 0 1px var(--line);
}
.interval button:hover:not(.on) { color: var(--mist); }

.chart-panel { padding-bottom: 1.1rem; }
.chart-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.7rem;
}
.chart-panel h2 { margin: 0; }
.chart-legend {
  display: flex;
  gap: 1rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--mute);
  flex-wrap: wrap;
  justify-content: flex-end;
}
.swatch { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--mute); }
.swatch::before {
  content: "";
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 2px;
  background: var(--reason);
}
.swatch.brass::before { background: var(--brass); }
.swatch.steel::before { background: var(--steel); }
.bars-wrap { position: relative; }
.bars { width: 100%; min-height: 220px; }
.chart-empty {
  position: absolute;
  left: 1rem;
  right: 1rem;
  top: 42%;
  text-align: center;
  margin: 0;
}
.bars svg { display: block; width: 100%; height: 220px; }
.chart-tip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: var(--mist);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 0.45rem 0.55rem;
  z-index: 2;
  white-space: nowrap;
}
.chart-tip strong { color: var(--brass); font-weight: 500; }

.fuses:empty, .mix:empty { display: none; }
.mix:empty + .mix-key { margin-top: 0; }
.fuses {
  display: flex;
  gap: 3px;
  background: var(--ink);
  padding: 3px;
  border-radius: 8px;
  overflow: hidden;
}
.fuse {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 76px;
  background: var(--raise);
  overflow: hidden;
  color: var(--mist);
}
.fuse-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--brass);
  animation: fuse-in 0.9s cubic-bezier(.2,.7,.2,1) forwards;
}
@keyframes fuse-in {
  from { width: 0; }
  to { width: var(--fill); }
}
.fuse-name, .fuse-amt {
  position: relative;
  display: block;
  padding: 0.55rem 0.7rem 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  z-index: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fuse-amt { padding-top: 0.15rem; color: color-mix(in srgb, var(--mist) 80%, transparent); }

.mix {
  display: flex;
  height: 76px;
  background: var(--ink);
  padding: 3px;
  gap: 3px;
  border-radius: 8px;
  overflow: hidden;
}
.mix-seg { background: var(--brass); min-width: 0; }
.mix-seg.completion { background: var(--steel); }
.mix-seg.reasoning { background: var(--reason); }
.mix-key {
  list-style: none;
  margin: 0.85rem 0 0;
  padding: 0;
  font-family: var(--mono);
  font-size: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.1rem;
}
.mix-key li { color: var(--mute); }
.mix-key b { color: var(--mist); font-weight: 500; }

.hbars { display: flex; flex-direction: column; gap: 0.65rem; }
.hbar {
  display: grid;
  grid-template-columns: minmax(4.5rem, 28%) 1fr auto;
  gap: 0.7rem;
  align-items: center;
}
.hbar-name, .hbar-amt {
  font-family: var(--mono);
  font-size: 0.72rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hbar-amt { color: var(--mute); font-variant-numeric: tabular-nums; }
.hbar-track { height: 8px; background: var(--raise); border-radius: 99px; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--brass); width: 0; border-radius: 99px; }

.heat-wrap { overflow-x: auto; }
.heat {
  display: grid;
  grid-template-columns: 2.2rem repeat(24, minmax(0.7rem, 1fr));
  gap: 3px;
  min-width: 36rem;
}
.heat span {
  font-family: var(--mono);
  font-size: 0.62rem;
  color: var(--mute);
  line-height: 0.85rem;
}
.heat .hcell {
  aspect-ratio: 1;
  min-height: 0.7rem;
  background: var(--raise);
  border-radius: 2px;
}
.heat .hcell[data-v]:hover { outline: 1px solid var(--brass); }

.account-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.25rem;
}
.account-head h2 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}
.account-head .eyebrow { margin-bottom: 0.35rem; }
.account-head form { margin: 0; }
.head-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.probe-out {
  margin: 0.35rem 0 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}
.probe-out.hidden { margin: 0; padding: 0; border: 0; }
.checks {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-family: var(--mono);
  font-size: 0.75rem;
}
.checks li {
  display: grid;
  grid-template-columns: 3.2rem minmax(0, 1fr);
  gap: 0.65rem;
  align-items: start;
}
.checks .mark { font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.68rem; }
.checks .mark.ok { color: var(--ok); }
.checks .mark.bad { color: var(--fault); }
.checks .mark.skip { color: var(--mute); }
.checks b { color: var(--mist); font-weight: 500; }
.checks span.detail { color: var(--mute); }
.probe-row td { padding-top: 0.35rem; }
.usage-meter {
  height: 8px;
  background: var(--raise);
  border-radius: 99px;
  overflow: hidden;
  margin: 0.55rem 0 0.35rem;
}
.usage-meter > span {
  display: block;
  height: 100%;
  width: var(--pct, 0%);
  background: var(--brass);
  border-radius: 99px;
}
.money-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.15rem;
  margin: 0.55rem 0 0;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--mist);
}
.money-row b { font-weight: 500; color: var(--mute); }
.products { margin-top: 0.55rem; }
.key-model { color: var(--mute); font-size: 0.7rem; }

/* —— Device / Grok —— */
.device .code {
  font-family: var(--mono);
  font-size: 2.1rem;
  letter-spacing: 0.18em;
  margin: 0.5rem 0 0.7rem;
  color: var(--brass);
}
.device p { margin: 0 0 0.65rem; color: var(--mute); }
.device .eyebrow { margin-bottom: 0.15rem; }
.device form { margin-top: 0.35rem; }
.pulse { font-family: var(--mono); font-size: 0.8rem; color: var(--steel); }
.hidden { display: none !important; }

/* —— Responsive —— */
@media (max-width: 960px) {
  .grid-2 { grid-template-columns: 1fr; }
  .chart-top { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
}
@media (max-width: 800px) {
  body.is-app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .rail {
    position: sticky;
    top: 0;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1rem 0.75rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .mark { padding: 0; flex-shrink: 0; }
  .rail nav {
    flex-direction: row;
    margin-top: 0;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    gap: 2px;
  }
  .rail nav a { padding: 0 0.65rem; flex-shrink: 0; }
  .rail nav a.on { box-shadow: inset 0 -2px 0 var(--brass); }
  .rail-rule { display: none; }
  .who {
    margin-top: 0;
    padding: 0;
    border-top: 0;
    flex-direction: row;
    align-items: center;
    gap: 0.65rem;
    flex-shrink: 0;
  }
  .who span { display: none; }
  .who .btn { width: auto; height: 1.9rem; padding: 0 0.7rem; font-size: 0.8rem; }
  form.stack .btn { align-self: stretch; width: 100%; }
  .row-actions { min-width: 0; }
  .stage-inner { padding: 0 1.15rem 3rem; }
  .page-head {
    flex-direction: column;
    align-items: stretch;
    min-height: 0;
    padding: 1.35rem 0 1.1rem;
    gap: 0.85rem;
  }
  .page-actions { justify-content: flex-start; }
  .auth-main { grid-template-columns: 1fr; }
  .auth-brand { padding: 3.5rem 1.5rem 1.25rem; }
  .auth-pane {
    padding: 0 1.5rem 3rem;
    background: transparent;
    border-left: 0;
    align-items: flex-start;
  }
  .auth-card { width: 100%; }
  .lede { max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  .fuse-fill { animation: none; width: var(--fill); }
}
