:root {
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
  font-synthesis: none;
  color-scheme: dark;
  --bg: #101915;
  --surface: #19261e;
  --surface-raised: #223229;
  --ink: #f0f4eb;
  --muted: #afc0ad;
  --soft: #829782;
  --line: #34483a;
  --accent: #bbdf86;
  --accent-ink: #172315;
  --danger: #f4a7a0;
  --success: #b7dc9a;
  --warning: #f0c883;
  --focus: #eacb85;
  --shadow: 0 14px 48px rgb(0 0 0 / .18);
}

body[data-theme="light"] {
  color-scheme: light;
  --bg: #edf2e9;
  --surface: #fbfdf9;
  --surface-raised: #e5eee3;
  --ink: #17251a;
  --muted: #4d6251;
  --soft: #657969;
  --line: #c4d3c4;
  --accent: #315f3d;
  --accent-ink: #f7fbf4;
  --danger: #a12e2e;
  --success: #286140;
  --warning: #805018;
  --focus: #9b5f10;
  --shadow: 0 16px 44px rgb(26 52 32 / .09);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.52; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
input, select, textarea { max-width: 100%; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
::selection { background: var(--accent); color: var(--accent-ink); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; z-index: 20; top: -100px; left: 16px; padding: 12px 18px; color: var(--accent-ink); background: var(--accent); }
.skip-link:focus { top: 12px; }

.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; font-size: 20px; font-weight: 800; letter-spacing: -.045em; white-space: nowrap; }
.brand img { flex: none; border-radius: 8px; }
.kicker { margin: 0 0 9px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .13em; }
body[data-theme="light"] .kicker { color: var(--accent); }

.button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 10px; padding: 10px 17px; border: 1px solid transparent; border-radius: 8px; font-weight: 750; line-height: 1.1; text-decoration: none; transition: background-color .16s ease, border-color .16s ease, color .16s ease, transform .16s ease; }
.button:active:not(:disabled) { transform: translateY(1px); }
.button-primary { background: var(--accent); color: var(--accent-ink); }
.button-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 84%, var(--surface)); }
.button-outline { background: transparent; color: var(--ink); border-color: var(--line); }
.button-outline:hover:not(:disabled) { background: var(--surface-raised); border-color: var(--soft); }
.button-quiet { background: transparent; color: var(--muted); }
.button-quiet:hover:not(:disabled) { color: var(--ink); background: var(--surface-raised); }
.button:disabled { opacity: .55; }

.auth-view { display: grid; min-height: 100svh; padding: clamp(24px, 6vw, 70px); place-items: center; }
.auth-panel { width: min(100%, 470px); padding: clamp(28px, 5vw, 50px); border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.auth-brand { margin-bottom: 34px; }
.auth-panel h1 { margin: 0 0 16px; max-width: 11ch; font-size: clamp(38px, 6vw, 51px); line-height: 1.04; letter-spacing: -.065em; text-wrap: balance; }
.auth-lead { margin: 0 0 24px; max-width: 42ch; color: var(--muted); }
.auth-panel form { display: grid; gap: 12px; }
.auth-panel form .button { margin-top: 10px; }
.auth-note { margin: 20px 0 0; color: var(--soft); font-size: 13px; }

.topbar { border-bottom: 1px solid var(--line); background: var(--surface); }
.topbar-inner { max-width: 1640px; min-height: 76px; margin: 0 auto; padding: 0 clamp(18px, 3.5vw, 52px); display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.connection { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 700; padding: 0 15px 0 0; margin-right: 4px; border-right: 1px solid var(--line); white-space: nowrap; }
.connection-dot { width: 7px; height: 7px; background: var(--success); border-radius: 50%; }
.connection.is-offline .connection-dot { background: var(--danger); }

.workspace { max-width: 1640px; margin: 0 auto; padding: clamp(26px, 4vw, 56px) clamp(18px, 3.5vw, 52px) 72px; }
.workspace-heading { display: flex; justify-content: space-between; align-items: end; gap: 30px; margin-bottom: 24px; }
.workspace-heading h1 { margin: 0; font-size: clamp(40px, 4.8vw, 70px); line-height: 1.02; letter-spacing: -.068em; font-weight: 800; text-wrap: balance; }
.workspace-heading p:last-child { margin: 16px 0 0; max-width: 60ch; color: var(--muted); }
.workspace-stats { display: flex; gap: 26px; flex: none; padding-bottom: 5px; }
.workspace-stats > div { display: grid; gap: 1px; min-width: 52px; }
.workspace-stats strong { font-size: 21px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.workspace-stats span { color: var(--soft); font-size: 12px; }
.workspace-stats #modelLabel { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.workspace-stats #browserLabel { font-size: 15px; }
.workspace-tabs { display: flex; gap: 28px; margin-bottom: 27px; border-bottom: 1px solid var(--line); }
.workspace-tabs button { min-height: 46px; margin-bottom: -1px; padding: 7px 1px 10px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-weight: 750; }
.workspace-tabs button:hover { color: var(--ink); }
.workspace-tabs button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--ink); }

.notice { margin: -10px 0 24px; padding: 12px 16px; border: 1px solid var(--danger); border-radius: 8px; color: var(--ink); background: color-mix(in srgb, var(--danger) 11%, var(--surface)); }
.notice.is-success { border-color: var(--success); background: color-mix(in srgb, var(--success) 9%, var(--surface)); }
.workspace-grid { display: grid; grid-template-columns: minmax(320px, 370px) minmax(0, 1fr); align-items: start; gap: 22px; }
.left-column { display: grid; gap: 22px; min-width: 0; }
.panel { min-width: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.composer { padding: clamp(20px, 2vw, 28px); }
.panel-titleline { display: flex; align-items: start; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.panel-titleline h2 { margin: 0; font-size: 23px; line-height: 1.14; letter-spacing: -.045em; }
.panel-index { color: var(--soft); font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }
.field { display: grid; align-content: start; gap: 7px; margin-bottom: 18px; min-width: 0; }
.field-row { display: grid; grid-template-columns: minmax(0, 1fr) 120px; gap: 12px; }
label { color: var(--ink); font-size: 14px; font-weight: 700; }
.optional { color: var(--soft); font-weight: 500; }
input:not([type="file"]), select, textarea { width: 100%; min-height: 44px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: var(--bg); transition: border-color .16s ease, background-color .16s ease; }
input:not([type="file"]):hover, select:hover, textarea:hover { border-color: var(--soft); }
input::placeholder, textarea::placeholder { color: var(--soft); opacity: 1; }
textarea { resize: vertical; min-height: 120px; line-height: 1.5; }
input[type="file"] { width: 100%; padding: 9px 10px; border: 1px dashed var(--line); border-radius: 7px; color: var(--muted); background: var(--bg); font-size: 13px; }
input[type="file"]::file-selector-button { margin-right: 10px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface-raised); color: var(--ink); font: inherit; font-weight: 700; cursor: pointer; }
.field-help { margin: 0; color: var(--soft); font-size: 13px; line-height: 1.45; }
.form-error { margin: 0 0 14px; color: var(--danger); font-size: 14px; }
.advanced { padding: 0 0 4px; margin: 1px 0 16px; border-top: 1px solid var(--line); }
.advanced summary { min-height: 48px; display: flex; align-items: center; cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 700; }
.advanced[open] summary { color: var(--ink); }
.launch-button { width: 100%; justify-content: space-between; }
.launch-button span:last-child { font-size: 18px; font-weight: 500; }

.runs-panel { min-width: 0; padding: 24px 0 8px; }
.runs-heading { align-items: center; margin: 0 22px 14px; }
.runs-heading .button { min-height: 38px; padding: 7px 10px; font-size: 13px; }
.runs-list { display: grid; grid-template-columns: minmax(0, 1fr); }
.run-item { display: grid; width: 100%; min-width: 0; gap: 9px; padding: 17px 22px 19px; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--ink); text-align: left; }
.run-item:hover { background: var(--surface-raised); }
.run-item.is-selected { background: var(--surface-raised); box-shadow: inset 3px 0 var(--accent); }
.run-item-top { display: flex; min-width: 0; align-items: baseline; justify-content: space-between; gap: 12px; }
.run-item strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.run-item time { color: var(--soft); font-size: 12px; white-space: nowrap; }
.run-item-bottom { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 12px; }
.run-item-bottom span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-item-bottom span:last-child { flex: none; }
.run-empty { border-top: 1px solid var(--line); padding: 26px 22px 30px; color: var(--muted); }
.run-empty strong { display: block; color: var(--ink); margin-bottom: 4px; }
.skeleton-run { height: 70px; margin: 0 22px; border-top: 1px solid var(--line); background: var(--surface-raised); opacity: .36; }

.detail-panel { min-height: 680px; padding: clamp(23px, 2.4vw, 38px); }
.detail-empty { min-height: 602px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; max-width: 430px; margin: auto; }
.empty-mark { display: inline-grid; place-items: center; width: 82px; height: 82px; margin-bottom: 46px; border: 1px solid var(--line); border-radius: 12px; color: var(--accent); font-family: Georgia, serif; font-size: 75px; line-height: 1; }
.detail-empty h2 { margin: 0; font-size: clamp(34px, 3.4vw, 50px); line-height: 1.08; letter-spacing: -.06em; text-wrap: balance; }
.detail-empty p:last-child { color: var(--muted); max-width: 37ch; }
.detail-head { display: flex; align-items: start; justify-content: space-between; gap: 24px; padding-bottom: 28px; border-bottom: 1px solid var(--line); }
.detail-head h2 { margin: 0; overflow-wrap: anywhere; font-size: clamp(30px, 3.1vw, 47px); line-height: 1.08; letter-spacing: -.055em; }
.detail-brief { margin: 13px 0 0; color: var(--muted); max-width: 75ch; white-space: pre-wrap; overflow-wrap: anywhere; }
.detail-head-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 9px; flex: none; }
.status-tag { display: inline-flex; align-items: center; min-height: 32px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .02em; text-transform: capitalize; }
.status-tag[data-status="running"] { border-color: var(--success); color: var(--success); }
.status-tag[data-status="solved"] { background: var(--success); border-color: var(--success); color: var(--bg); }
.status-tag[data-status="failed"], .status-tag[data-status="stopped"] { color: var(--danger); border-color: var(--danger); }
.detail-section { padding: 27px 0; border-bottom: 1px solid var(--line); }
.detail-section:last-child { border-bottom: 0; padding-bottom: 0; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.section-heading h3 { margin: 0; font-size: 17px; letter-spacing: -.025em; }
.section-heading span { color: var(--soft); font-size: 12px; font-variant-numeric: tabular-nums; }
.agent-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(205px, 1fr)); gap: 0 20px; }
.budget-line { margin: -4px 0 12px; font-variant-numeric: tabular-nums; }
.agent-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; padding: 13px 0; border-top: 1px solid var(--line); }
.agent-row:first-child { border-top: 1px solid var(--line); }
.agent-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 700; text-transform: capitalize; }
.agent-meta { color: var(--soft); font-family: "SFMono-Regular", Consolas, monospace; font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.agent-state { font-size: 11px; font-weight: 700; text-transform: capitalize; }
.agent-state[data-status="running"] { color: var(--success); }
.agent-state[data-status="failed"] { color: var(--danger); }
.file-list { display: flex; flex-wrap: wrap; gap: 8px; }
.file-chip { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 5px; color: var(--ink); font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; overflow-wrap: anywhere; }
.file-chip small { color: var(--soft); font-family: "Avenir Next", Avenir, sans-serif; }
.section-empty { margin: 0; color: var(--soft); font-size: 14px; }
.upload-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.upload-row[hidden] { display: none; }
.upload-row input { flex: 1; min-width: 0; }
.upload-label { display: none; }
.flag-row { display: flex; gap: 10px; }
.flag-row input { flex: 1; min-width: 0; font-family: "SFMono-Regular", Consolas, monospace; font-size: 13px; }
.verify-section #markSolved { margin-top: 8px; padding-left: 0; }
.verify-section #flagFeedback { margin-top: 11px; }
.event-list { display: grid; max-height: 760px; overflow-y: auto; }
.event-row { display: grid; grid-template-columns: 83px minmax(0, 1fr); gap: 16px; padding: 15px 0; border-top: 1px solid var(--line); }
.event-time { color: var(--soft); font-family: "SFMono-Regular", Consolas, monospace; font-size: 11px; font-variant-numeric: tabular-nums; }
.event-body { min-width: 0; }
.event-label { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .025em; text-transform: capitalize; }
.event-label .event-agent { color: var(--soft); font-weight: 600; text-transform: none; }
.event-text { margin: 6px 0 0; max-height: 240px; overflow: auto; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; line-height: 1.55; }
.footer { display: flex; justify-content: space-between; gap: 20px; max-width: 1640px; padding: 0 clamp(18px, 3.5vw, 52px) 32px; margin: 0 auto; color: var(--soft); font-size: 12px; }

.chat-panel { width: min(100%, 960px); margin: 0 auto; padding: clamp(20px, 3.5vw, 38px); }
.chat-intro { display: flex; justify-content: space-between; align-items: start; gap: 20px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.chat-intro h2 { margin: 0; font-size: clamp(30px, 3vw, 44px); letter-spacing: -.055em; line-height: 1.1; }
.chat-intro p:last-child { margin: 12px 0 0; max-width: 56ch; color: var(--muted); }
.chat-messages { min-height: 320px; max-height: 62vh; overflow-y: auto; }
.chat-empty { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; min-height: 320px; max-width: 430px; margin: auto; }
.chat-empty .empty-mark { width: 54px; height: 54px; margin-bottom: 24px; font-size: 50px; }
.chat-empty h3 { margin: 0; font-size: 25px; letter-spacing: -.04em; }
.chat-empty p { margin: 9px 0 0; color: var(--muted); }
.chat-message { padding: 22px 0; border-bottom: 1px solid var(--line); }
.chat-message:last-child { border-bottom: 0; }
.chat-message-label { margin: 0 0 9px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.chat-message[data-role="user"] .chat-message-label { color: var(--soft); }
.chat-message-content { margin: 0; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.65; }
.chat-message.is-pending .chat-message-content { color: var(--muted); }
.chat-form { display: grid; gap: 10px; padding-top: 24px; border-top: 1px solid var(--line); }
.chat-form textarea { min-height: 108px; }
.chat-form-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.chat-form-footer .button { flex: none; }

@media (max-width: 1120px) {
  .workspace-heading { align-items: start; flex-direction: column; }
  .workspace-grid { grid-template-columns: minmax(300px, 340px) minmax(0, 1fr); }
  .detail-head { flex-direction: column; }
  .detail-head-actions { justify-content: flex-start; }
}

@media (max-width: 850px) {
  .workspace-grid { grid-template-columns: minmax(0, 1fr); }
  .left-column { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .workspace-heading { margin-bottom: 29px; }
  .detail-panel { min-height: 470px; }
  .detail-panel.has-run { order: -1; }
  .detail-empty { min-height: 400px; }
}

@media (max-width: 680px) {
  .topbar-inner { min-height: 66px; }
  .brand { font-size: 17px; gap: 8px; }
  .brand img { width: 29px; height: 29px; }
  .topbar-actions { gap: 1px; }
  .topbar-actions .button { padding: 8px 10px; font-size: 13px; }
  .connection { display: none; }
  .workspace { padding-top: 32px; }
  .workspace-heading h1 { max-width: 10ch; }
  .workspace-stats { width: 100%; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
  .workspace-stats > div { min-width: 0; }
  .left-column { grid-template-columns: minmax(0, 1fr); }
  .detail-head { gap: 18px; }
  .detail-panel { padding: 21px; }
  .event-row { grid-template-columns: 1fr; gap: 2px; }
  .footer { flex-direction: column; gap: 4px; }
  .chat-intro { flex-direction: column; }
  .chat-form-footer { align-items: stretch; flex-direction: column; gap: 12px; }
  .chat-form-footer .button { width: 100%; }
}

@media (max-width: 420px) {
  .topbar-inner { padding-left: 12px; padding-right: 12px; }
  .brand { font-size: 15px; }
  .topbar-actions .button { padding: 7px 7px; font-size: 12px; }
  .field-row { grid-template-columns: minmax(0, 1fr) 112px; }
  .upload-row { align-items: stretch; flex-direction: column; }
  .flag-row { flex-direction: column; }
  .flag-row .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0s !important; animation-duration: 0s !important; }
}
