:root {
  --bg: #f6f6f6;
  --surface: #ffffff;
  --surface-subtle: #fafafa;
  --ink: #111111;
  --muted: #666666;
  --line: #dedede;
  --line-strong: #aaaaaa;
  --danger: #7f1d1d;
  --danger-soft: #fef2f2;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  --sidebar: 220px;
  --footer: 38px;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; overflow-x: hidden; background: var(--bg); }
body { min-width: 0; min-height: 100vh; margin: 0; overflow-x: hidden; color: var(--ink); background: var(--bg); }
.app-shell img, .app-shell video, .app-shell svg, .app-shell canvas { max-width: 100%; height: auto; }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
[hidden] { display: none !important; }

button, .button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0.48rem 0.8rem;
  color: var(--ink);
  background: var(--surface);
  font-weight: 650;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
}
button:hover, .button:hover { border-color: #555; background: #f3f3f3; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid #111;
  outline-offset: 2px;
}
button:disabled { cursor: not-allowed; opacity: 0.42; }
button.primary, .button.primary { border-color: #111; color: #fff; background: #111; }
button.primary:hover, .button.primary:hover { background: #2a2a2a; }
button.danger { border-color: var(--danger); color: var(--danger); background: #fff; }
button.quiet { border-color: transparent; background: transparent; }

input, textarea, select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0.58rem 0.68rem;
  color: var(--ink);
  background: #fff;
}
textarea { min-height: 112px; resize: vertical; }
label { display: block; margin: 0.75rem 0 0.3rem; font-size: 0.82rem; font-weight: 700; }
fieldset { min-width: 0; margin: 0 0 0.8rem; border: 1px solid var(--line); border-radius: 7px; padding: 0.8rem; }
legend { padding: 0 0.35rem; font-weight: 700; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0.3rem; font-size: clamp(1.75rem, 3vw, 2.35rem); letter-spacing: -0.045em; }
h2 { margin-bottom: 0.25rem; font-size: 1.05rem; letter-spacing: -0.02em; }
h3 { margin-bottom: 0.2rem; font-size: 0.95rem; }
p { line-height: 1.45; }
code, pre, .mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
code, .mono { overflow-wrap: anywhere; }
pre { max-width: 100%; margin: 0; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }
.eyebrow { margin-bottom: 0.3rem; color: var(--muted); font-size: 0.66rem; font-weight: 800; letter-spacing: 0.14em; }
.form-error { min-height: 1.1rem; margin: 0.35rem 0; color: var(--danger); font-size: 0.82rem; font-weight: 650; }
.field-note { margin: 0.28rem 0 0; color: var(--muted); font-size: 0.77rem; }
.empty-state { padding: 1.4rem; color: var(--muted); text-align: center; }

.auth-screen { display: grid; min-height: 100vh; place-items: center; padding: 1rem; }
.auth-card { width: min(410px, 100%); border: 1px solid var(--line); border-radius: 8px; padding: 2rem; background: var(--surface); box-shadow: var(--shadow); }
.auth-card button { width: 100%; margin-top: 0.6rem; }

.app-shell { min-width: 0; min-height: 100vh; padding: 58px 0 var(--footer) var(--sidebar); }
.sidebar { position: fixed; z-index: 30; inset: 0 auto var(--footer) 0; width: var(--sidebar); border-right: 1px solid var(--line); color: var(--ink); background: #fff; }
.brand { display: flex; height: 58px; align-items: center; gap: 0.65rem; padding: 0 1rem; border-bottom: 1px solid var(--line); font-weight: 750; text-decoration: none; }
.brand-mark { display: grid; width: 30px; height: 30px; border: 1px solid #111; border-radius: 50%; place-items: center; font-size: 0.7rem; }
#primary-nav { padding: 0.75rem 0.65rem; }
.nav-link { display: block; margin: 0.12rem 0; border-radius: 6px; padding: 0.62rem 0.7rem; color: #444; text-decoration: none; font-size: 0.88rem; font-weight: 600; }
.nav-link:hover { background: #f5f5f5; }
.nav-link.active { box-shadow: inset 3px 0 0 #111; color: #111; background: #ededed; }
.owner-label { position: absolute; right: 1rem; bottom: 0.9rem; left: 1rem; margin: 0; overflow: hidden; color: var(--muted); font-size: 0.76rem; text-overflow: ellipsis; white-space: nowrap; }

.topbar { position: fixed; z-index: 20; inset: 0 0 auto var(--sidebar); display: flex; height: 58px; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 0 1.25rem; background: rgba(255, 255, 255, 0.97); }
.topbar .eyebrow { margin: 0; font-size: 0.58rem; }
.mobile-nav-button { display: none; }
main { width: min(1280px, 100%); min-width: 0; margin: 0 auto; padding: 1.5rem; }
.page { min-width: 0; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1.15rem; }
.page-heading p:last-child { margin-bottom: 0; color: var(--muted); }

.panel, .metric-card, .runner-card, .status-card { min-width: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.panel { margin-bottom: 1rem; padding: 1rem; }
.panel-heading { display: flex; min-width: 0; align-items: start; justify-content: space-between; gap: 1rem; margin-bottom: 0.75rem; }
.panel-heading > * { min-width: 0; }
.panel-heading p { margin-bottom: 0; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.metric-card { min-height: 116px; padding: 0.9rem; }
.metric-card p, .metric-label { display: block; margin: 0 0 0.6rem; color: var(--muted); font-size: 0.7rem; font-weight: 750; letter-spacing: 0.06em; text-transform: uppercase; }
.metric-card strong, .metric-value { display: block; margin-bottom: 0.3rem; font-size: 1.25rem; font-weight: 750; overflow-wrap: anywhere; }
.metric-card span, .metric-detail { color: var(--muted); font-size: 0.76rem; overflow-wrap: anywhere; }
.metric-card.unavailable { background: var(--surface-subtle); }
.card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.runner-card { padding: 1rem; }
.runner-card.selected { border-color: #111; box-shadow: inset 0 0 0 1px #111; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 0.65rem; }
.summary-grid > div, .summary-item { min-width: 0; border-left: 2px solid #999; padding: 0.25rem 0.55rem; }
.summary-grid span, .summary-item span { display: block; color: var(--muted); font-size: 0.69rem; font-weight: 700; text-transform: uppercase; }
.summary-grid strong, .summary-item strong { display: block; margin-top: 0.18rem; overflow-wrap: anywhere; }
.quick-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }

.badge { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 0.32rem; border: 1px solid #cfcfcf; border-radius: 999px; padding: 0.18rem 0.47rem; color: #333; background: #f3f3f3; font-size: 0.7rem; font-weight: 700; white-space: nowrap; }
.badge::before { content: ""; width: 0.36rem; height: 0.36rem; border-radius: 50%; background: currentColor; }
.badge.solid { border-color: #111; color: #fff; background: #111; }
.badge.danger { border-color: #d7a5a5; color: var(--danger); background: var(--danger-soft); }
.badge.outline { border-color: #777; color: #111; background: #fff; }

.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.75rem; }
.detail-card { min-width: 0; border: 1px solid var(--line); border-radius: 7px; padding: 0.8rem; background: var(--surface-subtle); }
.detail-card > strong, #selected-model-id { display: block; margin-bottom: 0.22rem; }
.detail-card dl, .readable-list { margin: 0; }
.readable-list { display: grid; gap: 0; }
.readable-row, .detail-card dl > div { display: grid; grid-template-columns: minmax(100px, 0.7fr) minmax(0, 1fr); gap: 0.7rem; border-bottom: 1px solid var(--line); padding: 0.5rem 0; }
.readable-row:last-child, .detail-card dl > div:last-child { border-bottom: 0; }
.readable-row span, .detail-card dt { color: var(--muted); font-size: 0.78rem; }
.readable-row strong, .detail-card dd { min-width: 0; margin: 0; font-size: 0.82rem; overflow-wrap: anywhere; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 0.8rem; }
.form-grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; margin-top: 0.85rem; }
.input-action { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.45rem; }
.radio-row, .check-row { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.radio-row label, .check-row label, fieldset > label, .confirm-check { display: flex; align-items: flex-start; gap: 0.4rem; margin: 0.45rem 0; }
.radio-row input, .check-row input, fieldset input, .confirm-check input { width: auto; margin-top: 0.15rem; }

.table-wrap { width: 100%; max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 7px; }
table { width: 100%; border-collapse: collapse; font-size: 0.81rem; }
th, td { border-bottom: 1px solid var(--line); padding: 0.62rem 0.55rem; text-align: left; vertical-align: top; }
th { color: var(--muted); background: var(--surface-subtle); font-size: 0.68rem; letter-spacing: 0.05em; text-transform: uppercase; }
td code { overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.actions button, .actions .button { min-height: 32px; padding: 0.32rem 0.55rem; font-size: 0.74rem; }
.env-value { min-width: 210px; }


.restart-banner { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.65rem; margin: 0 0 0.8rem; border: 1px solid #cfa648; border-left: 4px solid #9a6b00; border-radius: 7px; padding: 0.8rem; background: #fff7df; }
.restart-banner strong { display: block; margin-bottom: 0.25rem; color: #5b4200; }
.restart-banner p { margin: 0.25rem 0; }
.restart-banner pre { margin: 0; white-space: pre-wrap; }
.restart-banner .muted { color: var(--muted); font-size: 0.75rem; }
.tab-list { display: grid; gap: 0.7rem; margin-top: 0.8rem; }
.tab-card { min-width: 0; border: 1px solid var(--line); border-left: 3px solid #aaa; border-radius: 7px; padding: 0.85rem; }
.tab-card.working { border-left-color: #111; }
.tab-url { display: block; margin: 0.35rem 0; color: var(--muted); font-size: 0.76rem; overflow-wrap: anywhere; }
.tab-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.4rem; margin: 0.65rem 0; }
.tab-meta div { min-width: 0; font-size: 0.74rem; overflow-wrap: anywhere; }
.tab-meta span { display: block; color: var(--muted); }

.catalog-toolbar { display: grid; grid-template-columns: minmax(180px, 1fr) auto; gap: 0.6rem; margin-bottom: 0.7rem; }
.segmented { display: flex; min-width: 0; }
.segmented button { min-width: 88px; border-radius: 0; }
.segmented button:first-child { border-radius: 6px 0 0 6px; }
.segmented button:last-child { border-radius: 0 6px 6px 0; }
.segmented button + button { margin-left: -1px; }
.segmented button.active { z-index: 1; border-color: #111; color: #fff; background: #111; }
.model-list { display: grid; gap: 0.55rem; max-height: 620px; overflow: auto; }
.model-row { display: grid; min-width: 0; grid-template-columns: minmax(0, 1fr) auto; gap: 0.75rem; align-items: center; border: 1px solid var(--line); border-radius: 7px; padding: 0.75rem; }
.model-row.selected { border-color: #111; box-shadow: inset 0 0 0 1px #111; }
.model-row h3 { margin-bottom: 0.2rem; }
.model-row code { display: block; color: var(--muted); font-size: 0.73rem; }
.model-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.4rem; color: var(--muted); font-size: 0.73rem; }
.model-reason { margin: 0.38rem 0 0; color: var(--muted); font-size: 0.76rem; }
.usage-summary { margin-bottom: 0.8rem; }
.model-usage-list { display: grid; gap: 0.65rem; }
.model-usage-row { display: grid; min-width: 0; grid-template-columns: minmax(180px, 0.8fr) minmax(0, 1.5fr); gap: 1rem; border: 1px solid var(--line); border-radius: 7px; padding: 0.8rem; background: var(--surface-subtle); }
.model-usage-row > div:first-child { min-width: 0; }
.model-usage-row > div:first-child strong { display: block; overflow-wrap: anywhere; font-size: 0.82rem; }
.model-usage-row > div:first-child span { display: block; margin-top: 0.3rem; color: var(--muted); font-size: 0.73rem; }
.result-box { border: 1px solid var(--line); border-radius: 7px; padding: 0.8rem; background: var(--surface-subtle); }
.debug-drawer { margin-top: 0.7rem; border-top: 1px solid var(--line); padding-top: 0.65rem; }
.debug-drawer summary { cursor: pointer; color: var(--muted); font-size: 0.78rem; font-weight: 650; }
.debug-drawer pre { margin-top: 0.65rem; font-size: 0.75rem; }

.studio-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 1rem; }
.studio-index { align-self: start; }
.key-list { display: grid; gap: 0.25rem; margin-top: 0.7rem; }
.key-list button { width: 100%; border-color: transparent; text-align: left; font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.74rem; }
.key-list button.selected { border-color: #111; background: #ededed; }
.json-editor { min-height: 410px; font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.76rem; }
.status-sections { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.status-card { padding: 0.9rem; }
.status-card.wide { grid-column: 1 / -1; }

.toast { position: fixed; z-index: 70; top: 68px; right: 1rem; max-width: min(430px, calc(100vw - 2rem)); border: 1px solid var(--danger); border-radius: 7px; padding: 0.7rem 0.9rem; color: var(--danger); background: var(--danger-soft); box-shadow: var(--shadow); font-weight: 650; }
.status-bar { position: fixed; z-index: 35; inset: auto 0 0 0; display: flex; min-width: 0; min-height: var(--footer); align-items: center; overflow-x: auto; border-top: 1px solid #333; color: #dedede; background: #111; white-space: nowrap; }
.status-bar a, .status-bar span { padding: 0.38rem 0.65rem; border-right: 1px solid #3d3d3d; color: inherit; font-size: 0.68rem; text-decoration: none; }
.status-bar strong { color: #fff; }

dialog { width: min(560px, calc(100% - 2rem)); max-height: calc(100vh - 2rem); border: 1px solid var(--line-strong); border-radius: 8px; padding: 1rem; color: var(--ink); background: #fff; box-shadow: 0 18px 70px rgba(0, 0, 0, 0.24); }
dialog::backdrop { background: rgba(0, 0, 0, 0.52); }
.directory-list { display: grid; max-height: 360px; gap: 0.3rem; margin-top: 0.7rem; overflow: auto; }
.directory-list button { display: flex; width: 100%; align-items: center; justify-content: space-between; text-align: left; }

@media (max-width: 980px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  :root { --sidebar: 0px; --footer: 0px; }
  .app-shell { min-height: calc(100dvh - 58px); padding-left: 0; padding-bottom: 0; }
  .sidebar { inset: 58px auto 0 0; width: min(280px, 86vw); transform: translateX(-101%); box-shadow: 4px 0 18px rgba(0, 0, 0, 0.12); }
  .sidebar.open { transform: translateX(0); }
  .brand { display: none; }
  .topbar { left: 0; padding: 0 0.8rem; }
  .mobile-nav-button { display: inline-flex; }
  main { padding: 0.85rem; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .page-heading > button { width: 100%; }
  .metric-grid, .card-grid, .form-grid, .studio-layout, .status-sections { grid-template-columns: minmax(0, 1fr); }
  .status-card.wide { grid-column: auto; }
  .panel { padding: 0.8rem; }
  .panel-heading { align-items: flex-start; flex-direction: column; }
  .catalog-toolbar { grid-template-columns: minmax(0, 1fr); }
  .segmented { width: 100%; }
  .segmented button { min-width: 0; flex: 1; }
  .model-row { align-items: stretch; grid-template-columns: minmax(0, 1fr); }
  .model-usage-row { grid-template-columns: minmax(0, 1fr); }
  .model-row > button { width: 100%; }
  .input-action { grid-template-columns: minmax(0, 1fr); }
  .input-action > button { width: 100%; }
  .readable-row, .detail-card dl > div { grid-template-columns: minmax(0, 1fr); gap: 0.15rem; }
  .status-bar { position: relative; inset: auto; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; padding-bottom: env(safe-area-inset-bottom); white-space: normal; }
  .status-bar a, .status-bar span { min-width: 0; padding: 0.5rem; overflow-wrap: anywhere; font-size: 0.68rem; }
  .env-value { min-width: 160px; }
}

@media (max-width: 420px) {
  .metric-grid { grid-template-columns: minmax(0, 1fr); }
  .auth-card { padding: 1.25rem; }
  .status-bar { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: no-preference) {
  .sidebar { transition: transform 140ms ease-out; }
}
.root-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 0.45rem;
  margin: 0.45rem 0;
  align-items: center;
}
@media (max-width: 700px) {
  .root-row { grid-template-columns: minmax(0, 1fr); }
  .root-row button { width: 100%; }
}


button[data-action-state="pending"] { cursor: progress; opacity: 0.78; }
.browser-install-progress { width: 100%; margin: 0.75rem 0; }
.form-error.action-pending { color: var(--muted); }
.form-error.action-success { color: #166534; }
.form-error.action-error { color: var(--danger); }
.inline-retry {
  display: inline-flex;
  min-height: 26px;
  margin-left: 0.45rem;
  padding: 0.18rem 0.45rem;
  font-size: 0.75rem;
}
.runner-delete-blocked {
  border-left: 3px solid var(--danger);
  padding-left: 0.65rem;
}

.runner-identity-readiness .readable-row strong { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
.runner-select-note { align-self: center; max-width: 360px; }

.button.disabled,
span.button[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.55;
  pointer-events: none;
}
.control-state-note {
  margin-top: 0.45rem;
  color: var(--muted);
}
[data-disabled-reason] {
  position: relative;
}

.page-load-error {
  border-color: #d7a5a5;
  background: var(--danger-soft);
}
.operation-feedback {
  min-width: min(360px, 100%);
  margin-top: 0.45rem;
}

.debug-reference {
  margin-top: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.55rem;
  color: var(--ink);
  background: var(--surface-subtle);
}
.debug-reference summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
}
.debug-reference pre {
  margin: 0.55rem 0;
  color: var(--ink);
  font-size: 0.73rem;
  font-weight: 500;
}
.copy-debug-status {
  align-self: center;
  color: var(--muted);
  font-size: 0.73rem;
}

.cli-diagnostics-panel .readable-list { margin-bottom: 0.75rem; }
.cli-command-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
  margin-top: 0.75rem;
}
.cli-command-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.7rem;
  background: var(--surface-subtle);
}
.cli-command-card h3 { margin: 0; font-size: 0.92rem; }
.cli-command-card pre {
  overflow-x: auto;
  margin: 0.55rem 0 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.copy-command-status {
  align-self: center;
  color: var(--muted);
  font-size: 0.73rem;
}
@media (max-width: 900px) {
  .cli-command-grid { grid-template-columns: minmax(0, 1fr); }
}
