@import url("https://fonts.googleapis.com/css2?family=Figtree:ital,wght@0,300..900;1,300..900&family=Fraunces:ital,opsz,wght,SOFT@0,9..144,300..700,50;1,9..144,300..700,50&display=swap");

:root {
  color-scheme: dark;
  --font-sans: "Figtree", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Fraunces", ui-serif, Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, monospace;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-display: 550;
  --text-title-size: 1.625rem;
  --text-heading-size: 1.25rem;
  --text-body-size: 0.9375rem;
  --text-label-size: 0.8125rem;
  --text-caption-size: 0.75rem;
  --text-eyebrow-size: 0.6875rem;
  --text-eyebrow-tracking: 0.08em;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --radius-control: 12px;
  --radius-card: 18px;
  --radius-pill: 999px;
  --basil-200: #bcdfb3;
  --basil-300: #92c885;
  --basil-400: #68ac5a;
  --basil-950: #0e1f0d;
  --leaf-200: #a5e4c0;
  --leaf-300: #6dcf9c;
  --leaf-400: #3cb578;
  --leaf-950: #062516;
  --apricot-200: #f8d09b;
  --apricot-300: #f3b163;
  --apricot-400: #ed933a;
  --apricot-950: #3a1607;
  --chili-200: #f6b8ae;
  --chili-300: #ee8b7c;
  --chili-400: #e15f4c;
  --chili-950: #300e09;
  --oat-400: #b0a696;
  --oat-950: #1b1815;
  --surface-app: var(--oat-950);
  --surface-card: #302b27;
  --surface-raised: #3c3630;
  --surface-sunken: #16130f;
  --surface-scrim: rgb(8 6 5 / 0.7);
  --text-strong: #ece5db;
  --text-body: #ded7cc;
  --text-muted: #bdb4a6;
  --text-subtle: var(--oat-400);
  --border-subtle: #423b33;
  --border-default: #554c42;
  --border-strong: #6f665a;
  --focus-ring: rgb(146 200 133 / 0.4);
  --shadow-card-edge: inset 0 1px 0 rgb(255 255 255 / 0.07);
  --primary: var(--basil-400);
  --primary-hover: var(--basil-300);
  --primary-active: var(--basil-200);
  --primary-contrast: var(--basil-950);
  --primary-soft: #2f4a28;
  --primary-border: #4a7040;
  --success: var(--leaf-400);
  --success-text: var(--leaf-300);
  --success-soft: #1d4a34;
  --success-border: #2c7050;
  --warning: var(--apricot-400);
  --warning-text: var(--apricot-300);
  --warning-soft: #6a4413;
  --warning-border: #8f5c1a;
  --danger: var(--chili-400);
  --danger-text: var(--chili-300);
  --danger-soft: #6e3325;
  --danger-border: #94452f;
}

* { box-sizing: border-box; }
html, body {
  min-width: 0;
  margin: 0;
  overflow-x: hidden;
  background: var(--surface-app);
  color: var(--text-body);
  font-family: var(--font-sans);
  font-size: var(--text-body-size);
  font-weight: var(--weight-regular);
  line-height: 1.5;
}
button, input { font: inherit; }

.page-title,
.login-card h1,
.status-header h1 {
  margin: 0;
  color: var(--text-strong);
  font-family: var(--font-display);
  font-size: var(--text-title-size);
  font-weight: var(--weight-display);
  font-variation-settings: "SOFT" 50;
  line-height: 1.15;
  letter-spacing: -0.015em;
}

.eyebrow {
  margin: 0 0 .25rem;
  color: var(--basil-300);
  font-size: var(--text-eyebrow-size);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--text-eyebrow-tracking);
  text-transform: uppercase;
}

.muted { color: var(--text-muted); overflow-wrap: anywhere; }
.tnum, td, .metric-value { font-variant-numeric: tabular-nums; }

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid var(--primary);
  border-radius: var(--radius-control);
  padding: .55rem 1rem;
  background: var(--primary);
  color: var(--primary-contrast);
  cursor: pointer;
  font-size: var(--text-label-size);
  font-weight: var(--weight-semibold);
  line-height: 1.3;
  text-decoration: none;
}
button:hover, .button:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button:active, .button:active { background: var(--primary-active); border-color: var(--primary-active); }
button.secondary, .button.secondary {
  border-color: var(--border-strong);
  background: transparent;
  color: var(--text-strong);
}
button.secondary:hover, .button.secondary:hover {
  background: var(--primary-soft);
  border-color: var(--primary-border);
  color: var(--text-strong);
}
button.danger, .button.danger {
  border-color: var(--danger-border);
  background: transparent;
  color: var(--danger-text);
}
button.danger:hover, .button.danger:hover {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger-text);
}
button:disabled {
  border-color: var(--border-default);
  background: var(--surface-sunken);
  color: var(--text-subtle);
  cursor: not-allowed;
}
button.row-select {
  flex: 1 1 12rem;
  justify-content: flex-start;
  min-width: 0;
  border: 0;
  padding: .4rem .5rem;
  background: transparent;
  color: var(--text-body);
  font-weight: var(--weight-medium);
  text-align: left;
}
button.row-select:hover { background: var(--primary-soft); color: var(--text-strong); }

:focus-visible {
  outline: 2px solid var(--basil-300);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--focus-ring);
}

.login-shell { display: grid; min-height: 100dvh; place-items: center; padding: 1rem; }
.login-card, .dialog-card {
  width: min(100%, 30rem);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-card);
  padding: 1.5rem;
  background: var(--surface-card);
  box-shadow: var(--shadow-card-edge);
}
.login-card .muted { font-size: var(--text-label-size); color: var(--text-muted); }
.login-card label {
  display: block;
  margin: 1.2rem 0 .35rem;
  color: var(--text-strong);
  font-size: var(--text-label-size);
  font-weight: var(--weight-semibold);
}
.login-card input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-control);
  padding: .65rem;
  background: var(--surface-sunken);
  color: var(--text-strong);
}
.login-card button { width: 100%; margin-top: 1rem; }
.error { min-height: 1.5rem; color: var(--danger-text); }

.status-header {
  position: sticky;
  z-index: 2;
  top: 0;
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-default);
  padding: 1rem clamp(1rem, 3vw, 2rem);
  background: #171411;
}
.header-brand { min-width: 0; }
.header-status { min-width: 0; }
.header-status .badge-hero { margin-bottom: .35rem; }
.header-meta, .dialog-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .65rem; }
.header-meta { justify-content: flex-end; }
.snapshot-time { color: var(--text-muted); font-size: var(--text-caption-size); }

.badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  padding: .15rem .6rem;
  color: var(--text-strong);
  font-size: var(--text-caption-size);
  font-weight: var(--weight-medium);
  white-space: nowrap;
}
.badge-hero {
  min-height: 44px;
  padding: .35rem .95rem;
  font-size: var(--text-heading-size);
  font-weight: var(--weight-semibold);
}
.badge[data-tone="healthy"], .badge[data-tone="working"] {
  border-color: var(--success-border);
  background: var(--success-soft);
  color: var(--success-text);
}
.badge[data-tone="warning"], .badge[data-tone="waiting"] {
  border-color: var(--warning-border);
  background: var(--warning-soft);
  color: var(--warning-text);
}
.badge[data-tone="critical"], .badge[data-tone="paused"], .badge[data-tone="unknown"] {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger-text);
}

.view-tabs {
  display: flex;
  gap: .25rem;
  overflow-x: auto;
  border-bottom: 1px solid var(--border-default);
  padding: .5rem clamp(1rem, 3vw, 2rem);
}
.view-tabs a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-control);
  padding: .5rem .8rem;
  color: var(--text-muted);
  font-size: var(--text-label-size);
  font-weight: var(--weight-medium);
  text-decoration: none;
  white-space: nowrap;
}
.view-tabs a[aria-current="page"] {
  background: var(--surface-raised);
  box-shadow: var(--shadow-card-edge), inset 0 -2px 0 var(--basil-300);
  color: var(--text-strong);
}
.view-tabs a:focus-visible,
.view-tabs a[aria-current="page"]:focus-visible {
  outline: 2px solid var(--basil-300);
  outline-offset: 2px;
  box-shadow: var(--shadow-card-edge), inset 0 -2px 0 var(--basil-300), 0 0 0 5px var(--focus-ring);
}

.view-container { width: min(100%, 96rem); margin: auto; padding: 1rem clamp(.75rem, 3vw, 2rem) 3rem; }
.overview-grid, .eval-layout, .admin-grid, .metric-grid, .cluster-grid { display: grid; gap: 1rem; }
.overview-grid { grid-template-columns: minmax(0, 1.4fr) minmax(18rem, .8fr); }
.eval-layout { grid-template-columns: minmax(18rem, .7fr) minmax(0, 1.3fr); }
.admin-grid { grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); align-content: start; }
.cluster-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack, .control-group { display: grid; gap: .75rem; align-content: start; min-width: 0; }
.control-group.compact, .dialog-actions { display: flex; flex-wrap: wrap; gap: .65rem; }
.admin-grid .card { align-content: start; }

.card {
  min-width: 0;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-card);
  padding: 1rem;
  background: var(--surface-card);
  box-shadow: var(--shadow-card-edge);
}
.card h2, .dialog-card h2 {
  margin: 0 0 .8rem;
  color: var(--text-strong);
  font-family: var(--font-sans);
  font-size: var(--text-heading-size);
  font-weight: var(--weight-semibold);
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.list { display: grid; gap: .5rem; margin: 0; padding: 0; list-style: none; }
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem .75rem;
  min-width: 0;
  border: 0;
  border-radius: var(--radius-control);
  padding: .65rem .75rem;
  background: var(--surface-sunken);
}
.row[data-rank="0"] { background: var(--danger-soft); }
.row.is-selected, .row[aria-current="true"] {
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 1px var(--primary-border);
}
.row p { margin: 0; }
.row-copy { flex: 1 1 12rem; min-width: 0; }
.row-title { display: block; color: var(--text-strong); font-weight: var(--weight-semibold); overflow-wrap: anywhere; }
.row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .55rem; margin-top: .3rem; }
.row-id { color: var(--text-strong); font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; }
.row .button, .row button { margin-top: 0; }

.factory-state-body { display: flex; flex-wrap: wrap; align-items: center; gap: .65rem; }
.work-identity { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem .75rem; margin-bottom: .5rem; }
.work-title { margin: 0; color: var(--text-strong); font-weight: var(--weight-semibold); }
.work-progress { margin: 0 0 .75rem; }

.metric-grid { grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
.metric { min-width: 0; }
.metric-label {
  display: block;
  color: var(--text-muted);
  font-size: var(--text-label-size);
  font-weight: var(--weight-medium);
}
.metric-value {
  display: block;
  margin-top: .2rem;
  color: var(--text-strong);
  font-size: 1.125rem;
  font-weight: var(--weight-semibold);
  white-space: nowrap;
  overflow: visible;
}
.cluster { min-width: 0; }
.cluster .eyebrow { margin-bottom: .5rem; }
.eval-score { display: grid; gap: .35rem; }
.eval-score + .eval-score { margin-top: .75rem; }

.bar {
  display: block;
  width: 100%;
  height: 8px;
  overflow: hidden;
  margin-top: .4rem;
  border-radius: var(--radius-pill);
  background: var(--surface-sunken);
}
.bar-fill {
  display: block;
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--primary);
}
.bar[data-tone="success"] .bar-fill { background: var(--success); }
.bar[data-tone="warning"] .bar-fill { background: var(--warning); }
.bar[data-tone="danger"] .bar-fill { background: var(--danger-text); }

.route {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem .55rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.route li {
  flex: 1 1 6.25rem;
  min-width: 0;
  border-top: 3px solid var(--border-strong);
  padding-top: .4rem;
  color: var(--text-muted);
  font-size: var(--text-label-size);
}
.route li[data-state="complete"] { border-color: var(--success); color: var(--success-text); }
.route li[data-state="current"] {
  border-color: var(--warning);
  color: var(--warning-text);
  font-weight: var(--weight-semibold);
}

.table-wrap { max-width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; overflow-wrap: anywhere; }
th, td { border-bottom: 1px solid var(--border-subtle); padding: .55rem .6rem; text-align: left; vertical-align: top; }
thead th {
  position: sticky;
  z-index: 1;
  top: 0;
  background: var(--surface-card);
  color: var(--text-muted);
  font-size: var(--text-caption-size);
  font-weight: var(--weight-semibold);
}
tbody tr:nth-child(even) { background: var(--surface-sunken); }
th.num, td.num { text-align: right; white-space: nowrap; }
tr.is-idle { color: var(--text-subtle); }
tr.is-idle .badge { opacity: .75; }
.token-cell { display: grid; gap: .3rem; justify-items: end; }

details { border-top: 1px solid var(--border-subtle); margin-top: .7rem; padding-top: .7rem; }
summary {
  min-height: 44px;
  color: var(--text-strong);
  cursor: pointer;
  font-size: var(--text-label-size);
  font-weight: var(--weight-semibold);
}
pre {
  max-height: 32rem;
  overflow: auto;
  margin: .5rem 0 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-control);
  padding: .75rem;
  background: var(--surface-sunken);
  color: var(--text-body);
  font-family: var(--font-mono);
  font-size: var(--text-caption-size);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

dialog { width: min(calc(100% - 2rem), 34rem); border: 0; padding: 0; background: transparent; color: var(--text-body); }
dialog::backdrop { background: var(--surface-scrim); }
.dialog-card { width: min(100%, 34rem); }
.dialog-actions { justify-content: flex-end; margin-top: 1rem; }

.global-message {
  position: fixed;
  z-index: 3;
  right: 1rem;
  bottom: 1rem;
  max-width: calc(100% - 2rem);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-card);
  padding: .75rem;
  background: var(--surface-raised);
  box-shadow: var(--shadow-card-edge);
}
.global-message:empty { display: none; }

@media (max-width: 52rem) {
  .status-header { position: static; grid-template-columns: minmax(0, 1fr); }
  .header-meta { justify-content: flex-start; }
  .overview-grid, .eval-layout, .cluster-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 30rem) {
  .dialog-actions { display: grid; }
  .card { padding: .8rem; }
  .metric-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: no-preference) {
  button, .button, .view-tabs a {
    transition: background-color 140ms ease-out, border-color 140ms ease-out, color 140ms ease-out, transform 90ms var(--ease-out);
  }
  button:active:not(:disabled), .button:active { transform: scale(0.97); }
}
