:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #181817;
  --muted: #70706b;
  --line: #e4e4df;
  --soft: #efefeb;
  --accent: #23835f;
  --accent-strong: #176a4b;
  --danger: #b73939;
  --sidebar: #efefeb;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); overflow: hidden; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.app-shell { height: 100%; min-height: 0; display: grid; grid-template-columns: 288px minmax(0, 1fr); overflow: hidden; }
.sidebar { height: 100%; min-height: 0; background: var(--sidebar); border-right: 1px solid var(--line); padding: 18px 14px 14px; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.brand-row { display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 10px; padding: 0 4px 18px; }
.brand-mark, .empty-mark { background: #111; color: white; display: grid; place-items: center; font-weight: 750; }
.brand-mark { width: 38px; height: 38px; border-radius: 8px; }
.brand-name { font-size: 15px; font-weight: 700; }
.connection-line { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; margin-top: 2px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #999; flex: 0 0 auto; }
.status-dot.online { background: #2f9b69; box-shadow: 0 0 0 3px rgba(47, 155, 105, .13); }
.icon-button { border: 0; background: transparent; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 6px; color: var(--muted); font-size: 21px; }
.icon-button:hover { background: rgba(0,0,0,.06); color: var(--text); }
.sidebar-close { display: none; }
.new-task-button { border: 1px solid #d8d8d2; background: var(--panel); color: var(--text); border-radius: 7px; height: 42px; font-weight: 650; text-align: left; padding: 0 14px; box-shadow: 0 1px 1px rgba(0,0,0,.03); }
.new-task-button span { font-size: 20px; margin-right: 7px; vertical-align: -1px; }
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; font-weight: 700; padding: 22px 4px 8px 9px; }
.thread-list { overflow: auto; flex: 1; min-height: 0; }
.thread-item { width: 100%; border: 0; background: transparent; border-radius: 6px; padding: 10px 11px; text-align: left; margin: 1px 0; color: var(--text); }
.thread-item:hover, .thread-item.active { background: rgba(0,0,0,.065); }
.thread-name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; font-weight: 620; }
.thread-meta { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 11px; margin-top: 4px; }
.settings-button { border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--muted); padding: 14px 8px 3px; text-align: left; }
.settings-button span { margin-right: 9px; }

.workspace { min-width: 0; min-height: 0; height: 100%; overflow: hidden; display: grid; grid-template-rows: 62px minmax(0, 1fr) auto; background: var(--bg); }
.topbar { border-bottom: 1px solid var(--line); background: rgba(247,247,245,.95); display: flex; align-items: center; gap: 10px; padding: 0 22px; }
.menu-button { display: none; }
.task-title-wrap { min-width: 0; flex: 1; }
.task-title { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-path { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.stop-button { width: 36px; height: 36px; border: 1px solid #e0caca; background: #fff8f8; color: var(--danger); border-radius: 7px; }
.timeline { overflow-y: auto; padding: 28px max(24px, calc((100% - 820px) / 2)) 130px; scroll-behavior: smooth; }
.empty-state { min-height: 58vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--muted); }
.empty-mark { width: 52px; height: 52px; border-radius: 10px; font-size: 22px; margin-bottom: 18px; }
.empty-state h1 { color: var(--text); font-size: 20px; margin: 0 0 8px; letter-spacing: 0; }
.empty-state p { margin: 0; font-size: 14px; }
.android-pair-button { margin-top: 18px; border: 0; background: #111; color: #fff; text-decoration: none; border-radius: 7px; padding: 11px 15px; font-size: 13px; font-weight: 700; }
.message { margin: 0 0 22px; }
.message-role { color: var(--muted); font-size: 11px; font-weight: 750; margin-bottom: 7px; }
.message-body { font-size: 14px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user { margin-left: auto; max-width: 86%; }
.message.user .message-role { text-align: right; }
.message.user .message-body { background: var(--soft); border: 1px solid var(--line); border-radius: 8px; padding: 11px 13px; }
.event-card { border-left: 3px solid #aaa; padding: 8px 12px; margin: 12px 0 20px; color: var(--muted); background: rgba(255,255,255,.52); font-size: 12px; }
.event-card strong { color: var(--text); display: block; margin-bottom: 5px; }
.event-card pre { margin: 6px 0 0; overflow: auto; white-space: pre-wrap; font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.event-card.running { border-color: #d59a31; }
.event-card.completed { border-color: var(--accent); }

.composer { width: min(820px, calc(100% - 48px)); margin: 0 auto max(18px, env(safe-area-inset-bottom)); border: 1px solid #d6d6d0; background: var(--panel); border-radius: 8px; box-shadow: 0 10px 35px rgba(0,0,0,.08); padding: 9px 9px 9px 14px; display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { resize: none; max-height: 160px; min-height: 34px; flex: 1; border: 0; outline: 0; background: transparent; color: var(--text); line-height: 1.5; padding: 6px 0; }
.send-button { flex: 0 0 auto; width: 36px; height: 36px; border: 0; border-radius: 7px; background: #111; color: #fff; font-size: 21px; }
.send-button:disabled { background: #aaa; cursor: default; }

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.36); z-index: 9; }
dialog { border: 0; padding: 0; border-radius: 8px; width: min(92vw, 500px); color: var(--text); box-shadow: 0 24px 80px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.42); }
.dialog-panel { padding: 22px; background: var(--panel); }
.dialog-header { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 20px; }
.dialog-header h2, .approval-panel h2 { font-size: 18px; margin: 0 0 5px; letter-spacing: 0; }
.dialog-header p, .approval-panel p { color: var(--muted); margin: 0; font-size: 13px; line-height: 1.5; }
.dialog-panel label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin: 15px 0; }
.dialog-panel input, .dialog-panel select { width: 100%; margin-top: 7px; border: 1px solid var(--line); border-radius: 6px; padding: 11px 12px; outline: 0; color: var(--text); background: #fff; }
.dialog-panel input:focus, .dialog-panel select:focus { border-color: #777; box-shadow: 0 0 0 3px rgba(0,0,0,.06); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; }
.primary-button, .secondary-button, .danger-button { border-radius: 6px; padding: 10px 15px; font-weight: 700; border: 1px solid transparent; }
.primary-button { background: #111; color: #fff; }
.secondary-button { background: #fff; border-color: var(--line); color: var(--text); }
.danger-button { background: #fff; border-color: #e2bebe; color: var(--danger); }
.approval-label { color: #9c6508; font-size: 11px; font-weight: 800; margin-bottom: 8px; }
.approval-panel pre { max-height: 42vh; overflow: auto; background: #f3f3f0; padding: 12px; border-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.approval-questions { display: grid; gap: 14px; margin-top: 16px; }
.approval-question { border: 0; padding: 0; margin: 0; }
.approval-question legend { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.approval-option { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; margin: 7px 0; color: var(--text); }
.approval-option input { width: auto; margin: 2px 0 0; }
.approval-question > input { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 10px; background: var(--panel); color: var(--text); }
.toast { position: fixed; left: 50%; bottom: 95px; transform: translateX(-50%); z-index: 30; background: #1c1c1b; color: white; border-radius: 6px; padding: 10px 14px; max-width: min(86vw, 460px); font-size: 13px; box-shadow: 0 8px 30px rgba(0,0,0,.23); }

.auth-view { min-height: 100%; overflow-y: auto; padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom)); background: #f1f2ef; }
.auth-brand { width: min(100%, 420px); margin: 2vh auto 26px; display: flex; align-items: center; gap: 11px; }
.auth-brand > div:last-child { display: grid; gap: 3px; }
.auth-brand strong { font-size: 15px; }
.auth-brand span { color: var(--muted); font-size: 11px; }
.auth-update-button { margin-left: auto; min-height: 34px; padding: 0 11px; border: 1px solid #b9d5c6; border-radius: 6px; background: #edf7f1; color: var(--accent-strong); font-size: 12px; font-weight: 750; }
.auth-panel { width: min(100%, 420px); margin: 0 auto; padding: 28px; border: 1px solid #dcddd8; border-radius: 8px; background: #fff; box-shadow: 0 12px 40px rgba(28, 30, 28, .07); }
.auth-panel h1 { margin: 0 0 22px; font-size: 23px; letter-spacing: 0; }
.segmented-control { height: 38px; padding: 3px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; border-radius: 7px; background: #efefeb; }
.segmented-control button { border: 0; border-radius: 5px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 700; }
.segmented-control button.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.auth-panel form { margin-top: 22px; }
.auth-panel label { display: block; margin-top: 15px; color: var(--muted); font-size: 12px; font-weight: 700; }
.auth-panel input { width: 100%; min-height: 44px; margin-top: 7px; padding: 0 12px; border: 1px solid #d5d6d1; border-radius: 6px; outline: 0; color: var(--text); background: #fff; }
.auth-panel input:focus { border-color: #6e746f; box-shadow: 0 0 0 3px rgba(35, 131, 95, .1); }
.auth-submit { width: 100%; min-height: 44px; margin-top: 22px; border: 0; border-radius: 6px; background: #171918; color: #fff; font-weight: 750; }
.auth-submit:disabled { cursor: wait; opacity: .55; }
.form-error { margin: 12px 0 0; color: var(--danger); font-size: 12px; line-height: 1.5; }
.download-row { margin-top: 22px; padding-top: 17px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.download-row a { color: var(--accent-strong); font-weight: 700; text-decoration: none; }
.device-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: -3px 0 20px; }
.device-actions button { flex: 1 1 150px; }
.device-actions button:disabled, .dialog-actions button:disabled { cursor: default; opacity: .45; }
.settings-actions { flex-wrap: wrap; }
.action-spacer { flex: 1; }
.pair-code-input { text-align: center; font: 700 28px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: 3px; }
.update-button { min-width: 92px; height: 34px; padding: 0 10px; border: 1px solid #b9d5c6; border-radius: 6px; background: #edf7f1; color: var(--accent-strong); font-size: 12px; font-weight: 750; white-space: nowrap; }
.update-notes { margin: 4px 0 0; padding: 15px 18px 15px 34px; border-radius: 6px; background: var(--soft); color: var(--text); font-size: 13px; line-height: 1.7; }
.update-notes:empty { display: none; }
[hidden] { display: none !important; }

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(86vw, 330px); z-index: 10; transform: translateX(-102%); transition: transform .2s ease; padding-top: max(18px, env(safe-area-inset-top)); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close, .menu-button { display: grid; }
  .workspace { grid-template-rows: calc(58px + env(safe-area-inset-top)) minmax(0, 1fr) auto; }
  .topbar { padding: env(safe-area-inset-top) 10px 0; }
  .timeline { padding: 20px 16px 125px; }
  .composer { width: calc(100% - 20px); margin-bottom: max(10px, env(safe-area-inset-bottom)); }
  .empty-state h1 { font-size: 18px; }
  .approval-actions { flex-direction: column-reverse; }
  .approval-actions button { width: 100%; }
  .auth-view { padding-right: 16px; padding-left: 16px; }
  .auth-brand { margin-top: 0; }
  .auth-panel { padding: 24px 20px; }
  .settings-actions .action-spacer { display: none; }
  .settings-actions button { flex: 1 1 calc(50% - 9px); }
  .update-button { min-width: 36px; width: 36px; padding: 0; font-size: 17px; }
  .update-button span { display: none; }
}

@media (prefers-color-scheme: dark) {
  :root { color-scheme: dark; --bg: #1d1d1b; --panel: #292927; --text: #f4f4f0; --muted: #aaa9a2; --line: #3d3d39; --soft: #343431; --sidebar: #242422; }
  .brand-mark, .empty-mark, .send-button, .primary-button { background: #f1f1ed; color: #181817; }
  .android-pair-button { background: #f1f1ed; color: #181817; }
  .new-task-button, .dialog-panel input, .dialog-panel select { background: #2c2c29; }
  .event-card { background: rgba(255,255,255,.035); }
  .topbar { background: rgba(29,29,27,.95); }
  .auth-view { background: #1d1d1b; }
  .auth-panel { border-color: var(--line); background: var(--panel); box-shadow: none; }
  .segmented-control { background: #1f1f1d; }
  .segmented-control button.active { background: #3b3b38; color: var(--text); }
  .auth-panel input { border-color: var(--line); background: #2c2c29; }
  .auth-submit { background: #f1f1ed; color: #181817; }
  .auth-update-button, .update-button { border-color: #365d4c; background: #233a30; color: #8ed0b0; }
}
