:root {
  color-scheme: light;
  --bg: #fbfbfa;
  --panel: #efefec;
  --card: #ffffff;
  --ink: #161614;
  --muted: #73736d;
  --line: #deded8;
  --hover: #e7e7e2;
  --accent: #171716;
  --success: #2f8a52;
  --danger: #b5453d;
  --shadow: 0 18px 50px rgba(25, 25, 22, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; max-width: 100%; overflow-x: hidden; background: var(--bg); color: var(--ink); touch-action: pan-x pan-y; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.mobile-only { display: none; }

.app-shell { min-height: 100dvh; display: grid; grid-template-columns: 268px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100dvh; background: var(--panel); border-right: 1px solid var(--line); padding: 14px 12px; display: flex; flex-direction: column; z-index: 30; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 7px 14px; }
.brand { display: flex; align-items: center; gap: 9px; font-size: 17px; }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 14px; background: var(--card); font-size: 29px; }
.brand-mark.small { width: 30px; height: 30px; border-radius: 9px; font-size: 19px; }
.new-thread { display: flex; align-items: center; gap: 10px; width: 100%; padding: 11px 12px; color: var(--ink); background: transparent; border: 0; border-radius: 9px; text-align: left; font-weight: 600; }
.new-thread:hover { background: var(--hover); }
.section-label { margin: 20px 12px 7px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.project-list { display: grid; gap: 2px; overflow: auto; }
.project-button { border: 0; background: transparent; border-radius: 9px; padding: 10px 12px; display: flex; align-items: center; gap: 10px; color: var(--ink); text-align: left; min-width: 0; }
.project-button:hover, .project-button.active { background: var(--hover); }
.project-icon { width: 24px; height: 24px; border: 1px solid #cfcfc8; border-radius: 7px; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.project-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot { margin-top: auto; padding: 12px; display: grid; gap: 10px; color: var(--muted); font-size: 12px; }
.connection-state { display: flex; align-items: center; gap: 8px; }
.logout-button { justify-self: start; border: 0; padding: 4px 0; background: transparent; color: var(--muted); font-size: 11px; }
.logout-button:hover { color: var(--ink); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #b7b7b0; }
.status-dot.online { background: var(--success); box-shadow: 0 0 0 3px rgba(47,138,82,.12); }

.main { min-width: 0; min-height: 100dvh; }
.topbar { position: sticky; top: 0; z-index: 20; height: 58px; display: flex; align-items: center; gap: 8px; padding: 0 18px; border-bottom: 1px solid rgba(222,222,216,.8); background: rgba(247,247,245,.88); backdrop-filter: blur(18px); }
.topbar-title { min-width: 0; display: flex; flex-direction: column; flex: 1; }
.topbar-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.topbar-title span { color: var(--muted); font-size: 11px; }
.icon-button { width: 36px; height: 36px; display: grid; place-items: center; border: 0; background: transparent; border-radius: 9px; color: var(--ink); font-size: 20px; }
.icon-button:hover { background: var(--hover); }

.screen { width: min(100%, 1040px); margin: 0 auto; padding: 36px 32px 70px; }
.content-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.content-kicker { display: block; margin-bottom: 7px; color: var(--muted); font-size: 9px; font-weight: 760; letter-spacing: .13em; }
.content-head h1 { margin: 0 0 5px; font-size: clamp(25px, 4vw, 34px); letter-spacing: -.035em; }
.content-head p { margin: 0; color: var(--muted); font-size: 13px; }
.new-work-button { display: inline-flex; align-items: center; gap: 7px; }
.primary, .secondary { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; font-weight: 650; }
.primary { border-color: var(--accent); background: var(--accent); color: white; }
.primary:hover { background: #30302e; }
.secondary { background: var(--card); color: var(--ink); }
.wide { width: 100%; }

.thread-list { display: grid; gap: 8px; }
.thread-card { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; border: 1px solid transparent; border-radius: 14px; padding: 17px 18px; background: transparent; color: var(--ink); text-align: left; }
.thread-card:hover { border-color: var(--line); background: rgba(255,255,255,.62); }
.thread-card h2 { margin: 0 0 6px; display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 15px; line-height: 1.35; }
.thread-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-card p { margin: 0; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 7px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.thread-flags { display: flex; align-items: center; gap: 6px; }
.unread-dot { flex: 0 0 auto; width: 7px; height: 7px; border-radius: 50%; background: #2878e3; box-shadow: 0 0 0 3px rgba(40,120,227,.1); }
.unread-pill { border-radius: 999px; padding: 3px 7px; background: #e5efff; color: #236bc7; font-weight: 700; }
.thread-card.unread .thread-title { font-weight: 760; }
.thread-card.active-task { border-color: rgba(47,138,82,.22); background: rgba(47,138,82,.045); }
.status-pill { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 7px; background: var(--card); }
.status-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #aaa; }
.status-pill.running::before { background: var(--success); animation: pulse 1.4s infinite; }
.status-pill.waiting::before { background: #d58a22; animation: pulse 1.4s infinite; }
.status-pill.error::before { background: var(--danger); }
.status-pill.idle::before { background: var(--success); }
.status-pill.paused::before { background: #aaa; }
@keyframes pulse { 50% { opacity: .35; } }
.empty { padding: 90px 20px; text-align: center; color: var(--muted); }
.empty-icon { width: 54px; height: 54px; margin: 0 auto 15px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 16px; background: var(--card); font-size: 28px; }
.empty h2 { margin: 0 0 7px; color: var(--ink); font-size: 17px; }
.empty p { margin: 0; font-size: 13px; }

.chat-screen { width: min(100%, 820px); min-height: calc(100dvh - 58px); padding-top: 24px; padding-bottom: 170px; touch-action: pan-y; }
.messages { display: flex; flex-direction: column; gap: 22px; }
.message { line-height: 1.62; font-size: 15px; }
.message.user { align-self: flex-end; max-width: min(86%, 650px); padding: 12px 15px; background: #e9e9e5; border-radius: 16px 16px 4px 16px; white-space: pre-wrap; }
.message.agent { align-self: stretch; overflow-wrap: anywhere; }
.message-label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; }
.rich-text { color: var(--ink); }
.rich-text p { margin: 0 0 18px; white-space: pre-wrap; }
.rich-text p:last-child { margin-bottom: 0; }
.rich-text h3 { margin: 26px 0 10px; font-size: 17px; }
.rich-text ol, .rich-text ul { margin: 3px 0 20px; padding-left: 30px; }
.rich-text li { margin: 8px 0; padding-left: 3px; }
.rich-text code { padding: 3px 7px; border-radius: 7px; background: #ececea; font: .88em/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
.rich-text a { color: inherit; text-decoration-color: #a6a6a0; text-underline-offset: 3px; }
.code-card { margin: 14px 0 20px; overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
.code-toolbar { min-height: 45px; display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
.code-language { margin-right: auto; color: var(--muted); font-size: 11px; }
.code-action { border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; background: var(--card); color: var(--muted); font-size: 11px; }
.code-toolbar .code-language + .code-action { margin-left: 0; }
.code-toolbar .code-action:first-child { margin-left: 0; }
.copy-button { margin-left: auto; border: 0; background: transparent; color: var(--muted); font-size: 18px; }
.code-card pre { margin: 0; padding: 5px 20px 20px; overflow-x: auto; white-space: pre-wrap; color: var(--ink); font: 14px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; }
.web-preview { margin: 18px 0; display: grid; grid-template-columns: 58px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--ink); text-decoration: none; }
.web-preview-icon { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 12px; background: #f3f3f1; color: #32b5de; font-size: 27px; }
.web-preview-copy { min-width: 0; display: flex; flex-direction: column; }
.web-preview-copy strong { font-size: 14px; }
.web-preview-copy span { margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.web-preview-open { border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; background: var(--bg); font-size: 12px; white-space: nowrap; }
.message-actions { display: flex; align-items: center; gap: 3px; margin-top: 15px; color: var(--muted); }
.message-actions button { width: 31px; height: 31px; border: 0; border-radius: 8px; background: transparent; color: inherit; font-size: 16px; }
.message-actions button:hover { background: var(--hover); }
.tool-card { border: 1px solid var(--line); background: rgba(255,255,255,.55); border-radius: 12px; overflow: hidden; }
.tool-card summary { padding: 11px 13px; cursor: pointer; font-size: 12px; font-weight: 650; }
.tool-card pre { margin: 0; padding: 12px 13px; border-top: 1px solid var(--line); background: #20201e; color: #e8e8e4; font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.composer { position: fixed; left: calc(268px + (100vw - 268px)/2); transform: translateX(-50%); bottom: 0; z-index: 15; width: min(calc(100vw - 308px), 780px); padding: 18px 0 max(20px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 28%); }
.composer-box { border: 1px solid #cecec7; border-radius: 18px; background: var(--card); padding: 12px; box-shadow: 0 8px 30px rgba(30,30,27,.09); }
.composer textarea { display: block; width: 100%; max-height: 170px; resize: none; border: 0; outline: 0; background: transparent; color: var(--ink); line-height: 1.5; }
.composer textarea::placeholder { color: #96968f; }
.composer-actions { margin-top: 7px; display: flex; align-items: center; gap: 7px; }
.run-status { color: var(--muted); font-size: 11px; }
.send-button, .stop-button { width: 32px; height: 32px; border: 0; border-radius: 10px; background: var(--accent); color: white; font-size: 18px; }
.send-button:disabled { opacity: .3; }
.stop-button { font-size: 10px; }
.mic-button { width: 34px; height: 34px; margin-left: auto; display: grid; place-items: center; border: 0; border-radius: 10px; background: transparent; color: var(--muted); }
.mic-button:hover { background: var(--hover); color: var(--ink); }
.mic-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.mic-button.listening { background: #fbe6e4; color: var(--danger); animation: micPulse 1.4s ease-in-out infinite; }
.mic-button:disabled { opacity: .35; }
@keyframes micPulse { 50% { box-shadow: 0 0 0 6px rgba(181,69,61,.1); } }

.dialog { width: min(92vw, 520px); border: 1px solid var(--line); border-radius: 18px; padding: 22px; background: var(--bg); color: var(--ink); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(20,20,18,.34); backdrop-filter: blur(3px); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.dialog h2 { margin: 4px 0 0; font-size: 22px; }
.eyebrow { color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .1em; }
.dialog label { display: block; margin: 15px 0 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
.dialog select, .dialog textarea, .login input { width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 12px; background: var(--card); color: var(--ink); outline: 0; }
.dialog textarea { resize: vertical; margin-bottom: 17px; }
.approval-dialog { text-align: center; }
.approval-icon { width: 42px; height: 42px; margin: 0 auto 13px; display: grid; place-items: center; border: 1px solid #ddc08b; border-radius: 13px; background: #fff4d9; color: #775216; font-weight: 800; }
.approval-dialog p { color: var(--muted); font-size: 13px; }
.approval-dialog pre { max-height: 210px; overflow: auto; border-radius: 11px; padding: 12px; background: #20201e; color: #e8e8e4; text-align: left; white-space: pre-wrap; font: 11px/1.5 ui-monospace, monospace; }
.approval-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.question-list { display: grid; gap: 22px; margin: 4px 0 22px; }
.question-block { border: 0; padding: 0; margin: 0; }
.question-block legend { margin-bottom: 4px; font-size: 15px; font-weight: 700; }
.question-copy { margin: 0 0 11px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.question-options { display: grid; gap: 7px; }
.question-option { display: grid; grid-template-columns: 20px 1fr; gap: 9px; align-items: start; padding: 11px 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--card); cursor: pointer; }
.question-option:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.question-option input { margin-top: 3px; accent-color: var(--ink); }
.question-option strong { display: block; font-size: 13px; }
.question-option small { display: block; margin-top: 2px; color: var(--muted); line-height: 1.4; }
.question-input { width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 12px; background: var(--card); color: var(--ink); outline: 0; }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 360px); text-align: center; }
.login-card .brand-mark { margin: 0 auto 18px; }
.login-card h1 { margin: 0; font-size: 27px; }
.login-card > p { margin: 7px 0 28px; color: var(--muted); }
.login-card label { display: block; margin-bottom: 7px; color: var(--muted); text-align: left; font-size: 12px; }
.login-card input { margin-bottom: 12px; }
.remember-row { margin: 4px 0 20px !important; display: grid !important; grid-template-columns: 20px 1fr; align-items: start; gap: 9px; color: var(--ink) !important; cursor: pointer; }
.remember-row input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--ink); }
.remember-row span { text-align: left; }
.remember-row strong { display: block; font-size: 12px; }
.remember-row small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
.error { min-height: 18px; color: var(--danger); font-size: 12px; }
.toast { position: fixed; left: 50%; bottom: 28px; z-index: 100; transform: translateX(-50%); border-radius: 999px; padding: 10px 15px; background: #20201e; color: white; font-size: 12px; box-shadow: var(--shadow); }
.scrim { display: none; }

@media (prefers-color-scheme: dark) {
  :root { color-scheme: dark; --bg: #1d1d1b; --panel: #171716; --card: #272725; --ink: #f1f1ed; --muted: #a0a09a; --line: #383835; --hover: #2c2c29; --accent: #f0f0ec; --shadow: 0 20px 55px rgba(0,0,0,.35); }
  .primary, .send-button, .stop-button { color: #171716; }
  .primary:hover { background: #d7d7d1; }
  .topbar { background: rgba(29,29,27,.88); }
  .message.user { background: #30302d; }
  .rich-text code { background: #30302d; }
  .web-preview-icon { background: #30302d; }
  .thread-card:hover { background: rgba(255,255,255,.035); }
  .unread-pill { background: #223956; color: #8dbaf4; }
  .thread-card.active-task { background: rgba(47,138,82,.08); }
  .composer { background: linear-gradient(transparent, var(--bg) 28%); }
  .approval-icon { background: #493a20; border-color: #66522c; color: #f1cf88; }
  .mic-button.listening { background: #4a2926; }
}

@media (max-width: 760px) {
  .mobile-only { display: grid; }
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; transform: translateX(-105%); width: min(86vw, 310px); transition: transform .22s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .scrim { position: fixed; inset: 0; z-index: 25; background: rgba(15,15,14,.3); }
  .scrim.open { display: block; }
  .topbar { height: 54px; padding: 0 10px; }
  .screen { padding: 24px 15px 70px; }
  .content-head { margin-bottom: 18px; align-items: center; }
  .content-head h1 { font-size: 28px; }
  #new-thread-inline { display: none; }
  .thread-card { padding: 15px 10px; border-bottom: 1px solid var(--line); border-radius: 0; }
  .thread-card:hover { border-left-color: transparent; border-right-color: transparent; border-top-color: transparent; background: transparent; }
  .chat-screen { min-height: calc(100dvh - 54px); padding: 18px 14px 145px; }
  .messages { gap: 20px; }
  .message { font-size: 14px; }
  .message.agent { font-size: 16px; line-height: 1.72; }
  .message.user { max-width: 92%; }
  .web-preview { grid-template-columns: 48px minmax(0, 1fr) auto; padding: 12px; gap: 10px; }
  .web-preview-icon { width: 42px; height: 42px; }
  .web-preview-open { padding: 8px 9px; }
  .composer { left: 0; transform: none; width: 100%; padding: 16px 12px max(12px, env(safe-area-inset-bottom)); }
  .composer-box { border-radius: 17px; }
  .dialog { width: calc(100vw - 20px); margin-bottom: max(10px, env(safe-area-inset-bottom)); }
  .approval-actions { flex-direction: column-reverse; }
  .approval-actions button { width: 100%; }
}
