/* Cobra remote: phone-first, Cobra's palette (lib/core/colors.dart). */
:root {
  --bg: #FBFCF9; --surface: #F2F4EF; --surface-high: #E8EBE4; --raised: #FFFFFF;
  --text: #0E1411; --muted: #5F6B63; --faint: #A3ADA5;
  --accent: #078A5C; --on-accent: #FFFFFF; --accent-soft: #DFF3E6;
  --ok: #12925A; --warn: #B86E00; --err: #D63A2F; --err-soft: #FBE4E1;
  --line: rgba(14, 20, 17, .10);
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --top: env(safe-area-inset-top, 0px); --bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0B0F0D; --surface: #131815; --surface-high: #1B221D; --raised: #171D19;
    --text: #ECF1EC; --muted: #8E9A91; --faint: #5A655D;
    --accent: #2BF0A0; --on-accent: #04241A; --accent-soft: #14231A;
    --ok: #5FE08A; --warn: #F5B454; --err: #FF6B5E; --err-soft: #2A1714;
    --line: rgba(236, 241, 236, .09);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; font-size: 16px; color: var(--text); }
a { color: var(--accent); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--err); min-height: 1.2em; }

#app, .screen { height: 100%; }
#main { display: flex; flex-direction: column; height: 100dvh; }

/* Pairing */
#pair { display: flex; align-items: center; justify-content: center; padding: calc(24px + var(--top)) 20px calc(24px + var(--bottom)); min-height: 100dvh; }
.pair-box { width: 100%; max-width: 380px; text-align: center; }
.pair-icon { width: 72px; height: 72px; border-radius: 18px; }
.pair-box h1 { margin: 12px 0 4px; font-size: 26px; }
.steps-help { text-align: left; color: var(--muted); padding-left: 20px; margin: 18px 0; }
.steps-help li { margin: 6px 0; }
#pair-form { display: flex; flex-direction: column; gap: 10px; }
#pair-code {
  text-align: center; font: 600 26px/1 var(--mono); letter-spacing: .12em; padding: 14px;
  border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); text-transform: uppercase;
}

/* Header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + var(--top)) 14px 8px; border-bottom: 1px solid var(--line); background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 34px; height: 34px; border-radius: 9px; flex: none; }
.brand-text { min-width: 0; }
.pc { display: flex; align-items: center; gap: 6px; font-weight: 650; font-size: 15px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.dot.wait { background: var(--warn); }
.chip {
  display: inline-block; max-width: 62vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12.5px; color: var(--muted); padding: 1px 0;
}
.chip b { color: var(--text); font-weight: 600; }
.top-actions { display: flex; gap: 4px; flex: none; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 10px; color: var(--muted); flex: none; }
.icon-btn:active { background: var(--surface-high); }
.banner { padding: 8px 14px; font-size: 14px; background: var(--accent-soft); color: var(--text); border-bottom: 1px solid var(--line); }
.banner.bad { background: var(--err-soft); }

/* Views */
#views { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; display: flex; flex-direction: column; }
.view.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 14px 24px; display: block; }
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* Tabs */
.tabs {
  display: flex; border-top: 1px solid var(--line); background: var(--bg);
  padding: 4px 6px calc(4px + var(--bottom));
}
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 0; font-size: 11px; color: var(--muted); border-radius: 10px; }
.tabs button.on { color: var(--accent); }
.tabs button .badge { position: absolute; }
.tabs button { position: relative; }
.tab-badge { position: absolute; top: 2px; left: calc(50% + 8px); min-width: 8px; height: 8px; border-radius: 4px; background: var(--warn); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 14px; border-radius: 12px; background: var(--surface-high); font-weight: 600; font-size: 15px;
}
.btn:disabled { opacity: .45; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.danger { background: var(--err-soft); color: var(--err); }
.btn.ghost { background: none; color: var(--accent); padding: 8px 10px; }
.btn.small { padding: 6px 10px; font-size: 13.5px; border-radius: 10px; }
.btn.wide { width: 100%; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* Composer */
.composer { border-top: 1px solid var(--line); padding: 8px 10px 8px; background: var(--bg); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea {
  flex: 1; resize: none; max-height: 160px; padding: 9px 13px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--surface); outline: none; line-height: 1.35;
}
.composer textarea:focus { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.send { width: 38px; height: 38px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.send svg { width: 19px; height: 19px; fill: currentColor; stroke-width: 1.2; }
.send.stop { background: var(--err); color: #fff; }
.send.stop svg { display: none; }
.send.stop::before { content: ""; width: 13px; height: 13px; border-radius: 3px; background: currentColor; }
.send:disabled { opacity: .4; }
.attach { display: flex; align-items: center; gap: 8px; margin: 0 0 8px 44px; }
.attach img { width: 54px; height: 54px; object-fit: cover; border-radius: 10px; }

/* Chat */
.chat-list { flex: 1; padding: 14px 12px 10px; }
.msg { margin: 0 0 14px; display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.bubble { max-width: 88%; padding: 9px 13px; border-radius: 18px; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.assistant .bubble { background: var(--surface); border-bottom-left-radius: 6px; max-width: 100%; }
.msg .meta { font-size: 11.5px; color: var(--faint); margin: 3px 6px 0; }
.msg .tag { font-size: 12.5px; opacity: .85; margin-bottom: 4px; }
.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty h3 { color: var(--text); margin: 8px 0 4px; font-size: 18px; }
details.think { margin: 0 0 8px; font-size: 13.5px; color: var(--muted); }
details.think summary { cursor: pointer; list-style: none; font-weight: 600; }
details.think summary::-webkit-details-marker { display: none; }
details.think summary::before { content: "▸ "; }
details.think[open] summary::before { content: "▾ "; }
details.think div { white-space: pre-wrap; margin-top: 6px; border-left: 2px solid var(--line); padding-left: 10px; max-height: 40vh; overflow-y: auto; }
.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

/* Markdown */
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .6em; }
.md h1, .md h2, .md h3, .md h4 { margin: .8em 0 .4em; line-height: 1.25; font-size: 1.05em; }
.md h1 { font-size: 1.25em; } .md h2 { font-size: 1.15em; }
.md ul, .md ol { margin: 0 0 .6em; padding-left: 1.3em; }
.md li { margin: .15em 0; }
.md code { font: 13.5px/1.4 var(--mono); background: var(--surface-high); padding: 1px 5px; border-radius: 5px; }
.md pre { position: relative; margin: .5em 0 .7em; background: var(--surface-high); border-radius: 10px; padding: 10px 12px; overflow-x: auto; }
.md pre code { background: none; padding: 0; font-size: 12.5px; white-space: pre; display: block; }
.md pre .lang { position: absolute; top: 4px; right: 8px; font-size: 10.5px; color: var(--faint); font-family: var(--mono); }
.md blockquote { margin: 0 0 .6em; padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }
.md table { border-collapse: collapse; font-size: 13.5px; margin: .4em 0 .7em; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: .8em 0; }

/* Cards and lists */
.card { background: var(--surface); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.card .label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; margin: 0 0 14px; }
.item { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); width: 100%; text-align: left; }
.item:first-child { border-top: 0; }
.item .title { font-weight: 560; overflow-wrap: anywhere; }
.item .sub { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.item.on { background: var(--accent-soft); }
.item.on .title { color: var(--accent); }
button.item:active { background: var(--surface-high); }
.section-title { font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 4px 8px; font-weight: 650; }
.progress { height: 6px; border-radius: 3px; background: var(--surface-high); overflow: hidden; margin: 8px 0 4px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }
.progress.indeterminate > div { width: 35% !important; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }
.seg { display: flex; background: var(--surface); border-radius: 12px; padding: 3px; margin: 0 0 14px; }
.seg button { flex: 1; padding: 8px 0; border-radius: 9px; font-weight: 600; font-size: 14.5px; color: var(--muted); }
.seg button.on { background: var(--raised); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.chips { display: flex; gap: 6px; overflow-x: auto; margin: 0 0 10px; padding-bottom: 2px; }
.chips button { flex: none; padding: 6px 12px; border-radius: 999px; background: var(--surface); font-size: 13.5px; color: var(--muted); }
.chips button.on { background: var(--accent); color: var(--on-accent); }
.field { width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--raised); outline: none; }
textarea.field { resize: vertical; min-height: 96px; line-height: 1.4; }
.pill { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: var(--surface-high); color: var(--muted); margin-left: 4px; vertical-align: 1px; }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.spin { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Agent */
.agent-head { padding: 10px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.agent-head .grow .title { font-weight: 650; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-head .grow .sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-body { flex: 1; padding: 12px 12px 10px; }
.step { margin: 0 0 10px; }
.step.user .bubble { margin-left: auto; background: var(--accent); color: var(--on-accent); border-radius: 18px 18px 6px 18px; white-space: pre-wrap; max-width: 88%; padding: 9px 13px; width: fit-content; }
.step.assistant .text { padding: 2px 4px; overflow-wrap: anywhere; }
.tool { background: var(--surface); border-radius: 12px; overflow: hidden; }
.tool > button { display: flex; align-items: center; gap: 9px; width: 100%; padding: 9px 12px; text-align: left; font-size: 14px; }
.tool .ico { width: 18px; text-align: center; flex: none; font-weight: 700; }
.tool .ico.ok { color: var(--ok); } .tool .ico.error, .tool .ico.denied { color: var(--err); } .tool .ico.approval { color: var(--warn); }
.tool .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool .sum { font-size: 12px; color: var(--muted); flex: none; max-width: 34%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool .out { border-top: 1px solid var(--line); padding: 8px 12px 10px; }
.tool pre { margin: 0; font: 12px/1.45 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 50vh; overflow-y: auto; }
.tool .args { color: var(--muted); margin-bottom: 6px; }
.notice { font-size: 13px; color: var(--muted); padding: 2px 6px; white-space: pre-wrap; }
.finished { border-left: 3px solid var(--ok); background: var(--surface); border-radius: 10px; padding: 10px 12px; }
.failed { border-left: 3px solid var(--err); background: var(--err-soft); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; }
.teacher { border-left: 3px solid var(--warn); background: var(--surface); border-radius: 10px; padding: 9px 12px; font-size: 14px; }
.teacher b { color: var(--warn); }
.todos { background: var(--surface); border-radius: 12px; padding: 8px 12px; margin: 0 0 10px; font-size: 13.5px; }
.todos div { padding: 2px 0; }
.todos .done { color: var(--muted); text-decoration: line-through; }
.wait-card { margin: 0 10px 8px; background: var(--raised); border: 1px solid color-mix(in srgb, var(--warn) 55%, var(--line)); border-radius: var(--radius); padding: 12px; box-shadow: 0 6px 20px rgba(0, 0, 0, .18); }
.wait-card .label { color: var(--warn); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; margin-bottom: 4px; }
.wait-card pre { font: 12px/1.4 var(--mono); background: var(--surface); border-radius: 8px; padding: 8px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 30vh; overflow-y: auto; margin: 8px 0; }
.wait-card .row { margin-top: 8px; }
.start { padding: 16px 14px; }
.start h2 { margin: 6px 0 4px; font-size: 20px; }
.folder-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px; border-radius: 12px; background: var(--surface); text-align: left; margin: 12px 0; }
.folder-btn .sub { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 2px; }
.switch { position: relative; width: 50px; height: 30px; border-radius: 15px; background: var(--surface-high); flex: none; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s; }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(20px); }

/* Sheet */
.sheet-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 86dvh; display: flex; flex-direction: column;
  background: var(--raised); border-radius: 18px 18px 0 0; padding-bottom: var(--bottom); box-shadow: 0 -8px 30px rgba(0, 0, 0, .3);
}
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--faint); margin: 7px auto 0; opacity: .6; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px 6px 16px; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-body { overflow-y: auto; padding: 4px 14px 18px; -webkit-overflow-scrolling: touch; }
.sheet .list { background: var(--surface); }
.crumbs { font-size: 13px; color: var(--muted); margin: 0 0 10px; overflow-wrap: anywhere; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + var(--bottom)); z-index: 30;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.toast.bad { background: var(--err); color: #fff; }

@media (min-width: 720px) {
  #main { max-width: 760px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
