/* Harness: mobile-first app shell. Colors follow the Wiggins Lab palette and
   switch with the system light/dark setting. */

:root {
  --bg: #f3f5f6;
  --surface: #ffffff;
  --surface-2: #e9eef0;
  --ink: #142028;
  --muted: #586771;
  --line: #d6dee2;
  --accent: #0b6f6b;
  --accent-ink: #ffffff;
  --accent-soft: #dfefed;
  --bad: #a3322b;
  --bad-soft: #f9e3e1;
  --warn-soft: #fbefd8;
  --shadow: 0 1px 2px rgba(20, 32, 40, .06), 0 8px 28px rgba(20, 32, 40, .12);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --sidebar-w: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1417; --surface: #162026; --surface-2: #1d2a31; --ink: #e4ebee; --muted: #93a3ab; --line: #2a3840;
    --accent: #47bdb6; --accent-ink: #062523; --accent-soft: #143430; --bad: #f08a82; --bad-soft: #3e1f1c; --warn-soft: #3a2b12;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2 { margin: 0; line-height: 1.2; text-wrap: balance; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.note { color: var(--muted); font-size: .87rem; }
.label { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

/* Shell and sidebar */

.shell { display: flex; height: 100dvh; padding-top: env(safe-area-inset-top); }
.main { flex: 1; min-width: 0; height: 100%; overflow-y: auto; outline: none; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 30; width: min(84vw, var(--sidebar-w));
  background: var(--surface); border-right: 1px solid var(--line); padding: calc(16px + env(safe-area-inset-top)) 12px 16px;
  display: flex; flex-direction: column; gap: 16px; transform: translateX(-100%); transition: transform .22s ease;
  overflow-y: auto;
}
.sidebar.open { transform: none; box-shadow: var(--shadow); }
.scrim { position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, .4); }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.brand strong { display: block; font-size: 1.05rem; }
.brand span { display: block; color: var(--muted); font-size: .8rem; }
.nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav a, .nav button {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 0; background: none; text-decoration: none; color: var(--ink); text-align: left; cursor: pointer; min-height: 44px;
}
.nav a:hover, .nav button:hover:not([disabled]) { background: var(--surface-2); }
.nav [aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav button[disabled] { color: var(--muted); cursor: default; }
.nav-text { display: flex; flex-direction: column; line-height: 1.25; }
.soon { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; opacity: .85; }
.nav-sep { height: 1px; background: var(--line); margin: 8px 4px; }
.sidebar-foot { margin-top: auto; color: var(--muted); font-size: .78rem; padding: 0 8px; }
.sidebar-foot p { margin: 0 0 8px; }
.sidebar-foot a { color: inherit; text-decoration: underline; text-underline-offset: 2px; display: inline-block; padding: 6px 0; }

@media (min-width: 900px) {
  .sidebar { position: static; transform: none; width: var(--sidebar-w); flex: none; }
  .scrim { display: none; }
  .menu-btn, .home-bar { display: none !important; }
}

/* Buttons and inputs */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 14px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--ink);
  font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn-danger:hover { background: var(--bad); filter: brightness(1.08); }
.btn-lg { min-height: 48px; padding: 10px 18px; }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: .87rem; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; border: 0; background: none;
  cursor: pointer; color: var(--ink); flex: none;
}
.icon-btn:hover { background: var(--surface-2); }
select, input[type="text"] {
  min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); width: 100%;
}
.select-lg { min-height: 52px; font-size: 1.05rem; }

/* Pages */

.page { max-width: 760px; margin: 0 auto; padding: 16px 16px 48px; display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; align-items: center; gap: 8px; }
.page-head h1 { font-size: 1.5rem; flex: 1; }
.home-bar { padding: 8px 8px 0; }
.home h1 { font-size: clamp(1.6rem, 6vw, 2.2rem); margin-top: 8px; }
.home-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.home-actions .btn { flex: 1 1 200px; }
.home-section { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.recent-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.recent-item { display: flex; flex-direction: column; padding: 10px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.recent-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-meta { color: var(--muted); font-size: .82rem; }
.wf-cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.wf-card {
  text-align: left; padding: 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
}
.wf-card:hover { border-color: var(--accent); }
.wf-name { font-weight: 600; font-size: 1.05rem; }
.wf-desc { color: var(--muted); font-size: .87rem; }
.wf-steps { margin: 8px 0 0; padding-left: 20px; font-size: .87rem; }
.wf-steps li { margin: 2px 0; }
.wf-steps li span:first-child { margin-right: 6px; }
.wf-model { color: var(--muted); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); display: flex; flex-direction: column; gap: 8px; align-items: center; }
.empty-title { font-weight: 600; color: var(--ink); font-size: 1.05rem; }

/* Chat */

.chat { display: flex; flex-direction: column; height: 100%; }
.chat-head {
  display: flex; align-items: center; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); background: var(--surface); flex: none;
}
.model-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; min-height: 40px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; max-width: 55%; flex: none;
}
.model-btn:hover { border-color: var(--accent); }
.model-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-provider { color: var(--muted); font-size: .78rem; display: none; }
@media (min-width: 520px) { .model-provider { display: inline; } }
.chat-title { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 0 6px; }
.chat-kind { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.chat-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .92rem; }

.stepbar {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px 12px; padding: 10px 12px;
  border-bottom: 1px solid var(--line); background: var(--surface); flex: none;
}
.step-now { font-size: .95rem; }
.step-count { color: var(--muted); }
.step-list {
  grid-column: 1 / -1; grid-row: 2; display: flex; gap: 6px; list-style: none; margin: 0; padding: 0;
  overflow-x: auto; scrollbar-width: none;
}
.step-list li {
  display: flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border-radius: 99px; border: 1px solid var(--line);
  font-size: .8rem; white-space: nowrap; color: var(--muted);
}
.step-num { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--surface-2); font-size: .72rem; font-weight: 600; }
.step-model { opacity: .8; }
.step-model::before { content: "· "; }
.step-list li.done .step-num { background: var(--accent-soft); color: var(--accent); }
.step-list li.current { border-color: var(--accent); color: var(--ink); background: var(--accent-soft); }
.step-list li.current .step-num { background: var(--accent); color: var(--accent-ink); }
.next-btn { white-space: nowrap; gap: 4px; }
.next-name { display: none; margin-left: -4px; }
@media (min-width: 560px) { .next-name { display: inline; } }
.step-last { color: var(--muted); font-size: .87rem; }

.scroller { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.messages { max-width: 780px; margin: 0 auto; padding: 16px 12px 24px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; flex-direction: column; gap: 4px; max-width: 100%; }
.msg.user { align-items: flex-end; }
.msg.user .bubble { background: var(--accent); color: var(--accent-ink); border-radius: 16px 16px 4px 16px; padding: 10px 14px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant .bubble { background: var(--surface); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; padding: 10px 14px; max-width: 100%; overflow-wrap: anywhere; }
.msg.outside { opacity: .45; }
.msg-meta { font-size: .76rem; color: var(--muted); padding: 0 4px; }
.md p, .md ol, .md ul, .md pre, .md h4 { margin: 0 0 .7em; }
.md > :last-child { margin-bottom: 0; }
.md ol, .md ul { padding-left: 1.3em; }
.md h4 { font-size: 1rem; }
.md code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--surface-2); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md.streaming > :last-child::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(.6); opacity: .5; } 40% { transform: none; opacity: 1; } }
.event { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .8rem; text-align: center; }
.event::before, .event::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.event span { max-width: 80%; }
.error-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 10px 14px; border-radius: 12px;
  background: var(--bad-soft); border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); font-size: .9rem;
}
.error-card strong { color: var(--bad); }
.error-note { color: var(--muted); font-size: .8rem; }
.error-card .btn { margin-top: 4px; }

.link-btn { border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; padding: 0 0 0 4px; white-space: nowrap; text-decoration: underline; text-underline-offset: 2px; margin-left: auto; }
.summary-banner {
  display: flex; gap: 8px; align-items: flex-start; margin: 0 auto; max-width: 780px; width: calc(100% - 24px);
  padding: 8px 12px; border-radius: 10px; background: var(--warn-soft); font-size: .84rem; flex: none;
}

/* Sub-task (delegation) cards */
.delegation {
  display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 10px; background: var(--surface); font-size: .87rem; min-width: 0;
}
.delegation.status-awaiting { background: var(--warn-soft); }
.delegation.status-failed, .delegation.refused { border-left-color: var(--bad); }
.delegation.status-skipped, .delegation.status-stopped { border-left-color: var(--line); }
.deleg-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.deleg-title { font-weight: 600; }
.deleg-status { font-size: .76rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.deleg-status.status-done { background: var(--accent-soft); color: var(--accent); }
.deleg-status.status-failed, .deleg-status.status-refused { background: var(--bad-soft); color: var(--bad); }
.deleg-model { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .8rem; flex-wrap: wrap; }
.deleg-model-name { display: inline-flex; align-items: center; gap: 6px; }
.deleg-task { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 8.5em; overflow: auto; }
.deleg-estimate { margin: 0; font-variant-numeric: tabular-nums; }
.deleg-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.deleg-error { margin: 0; color: var(--bad); }
.deleg-result summary { cursor: pointer; color: var(--muted); font-size: .8rem; }
.deleg-result .md { margin-top: 6px; overflow-wrap: anywhere; }
.deleg-children { display: flex; flex-direction: column; gap: 8px; margin-left: 6px; }
.cost-line .cost-subtask { color: var(--ink); font-weight: 600; }
.setting-group { display: flex; flex-direction: column; gap: 16px; }

.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  max-width: 804px; width: 100%; margin: 0 auto; flex: none;
}
.composer textarea {
  flex: 1; resize: none; min-height: 46px; max-height: 200px; padding: 11px 14px; border-radius: 22px;
  border: 1px solid var(--line); background: var(--surface); line-height: 1.4;
}
.send-btn {
  width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; cursor: pointer; flex: none;
}
.send-btn.stop { background: var(--ink); color: var(--bg); }

/* Context inspector */

.inspector {
  margin: 8px auto 0; max-width: 780px; width: calc(100% - 24px); border: 1px dashed var(--accent); border-radius: 10px;
  background: var(--surface); font-size: .84rem; flex: none; max-height: 40vh; overflow-y: auto;
}
.inspector summary {
  display: flex; justify-content: space-between; gap: 8px; padding: 8px 12px; cursor: pointer; position: sticky; top: 0;
  background: var(--surface); font-weight: 600;
}
.insp-stats { font-family: var(--mono); font-weight: 400; color: var(--muted); }
.insp-body { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.insp-notes { margin: 0; padding-left: 18px; color: var(--muted); }
.insp-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.insp-item { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.insp-item.kind-summary { background: var(--warn-soft); }
.insp-item.kind-draft { border-style: dashed; }
.insp-item-head { display: flex; gap: 8px; align-items: center; font-size: .76rem; }
.insp-role { font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.insp-tag { border: 1px solid var(--line); border-radius: 99px; padding: 0 6px; color: var(--muted); }
.insp-tokens { margin-left: auto; font-family: var(--mono); color: var(--muted); }
.insp-text { white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.insp-text.expanded { display: block; }

/* History and folders */

.history-body { display: flex; flex-direction: column; gap: 10px; }
.folder { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); transition: border-color .15s, background .15s; }
.folder.drop-over { border-color: var(--accent); background: var(--accent-soft); }
.folder-head { display: flex; align-items: center; padding: 4px 4px 4px 0; }
.folder-toggle {
  flex: 1; display: flex; align-items: center; gap: 8px; padding: 10px 12px; min-height: 48px; border: 0; background: none;
  cursor: pointer; text-align: left; font-weight: 600;
}
.chev { display: inline-grid; transition: transform .15s; }
.chev.open { transform: rotate(90deg); }
.count { color: var(--muted); font-weight: 400; font-size: .85rem; }
.chat-list { list-style: none; margin: 0; padding: 0 6px 6px; display: flex; flex-direction: column; gap: 2px; }
.chat-row { display: flex; align-items: center; border-radius: 10px; }
.chat-row:hover { background: var(--surface-2); }
.chat-row.dragging { opacity: .4; }
.chat-link { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 8px 10px; text-decoration: none; color: var(--ink); }
.chat-row-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-row-meta { color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-empty { color: var(--muted); font-size: .85rem; padding: 6px 10px 10px; }
@media (pointer: fine) { .chat-row { cursor: grab; } }

/* Settings */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card h2 { font-size: 1.05rem; }
.card.dev { border-style: dashed; border-color: var(--accent); }
.setting { display: flex; flex-direction: column; gap: 6px; }
.setting-label { font-weight: 500; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; min-height: 44px; }
input[role="switch"] {
  appearance: none; width: 46px; height: 28px; border-radius: 99px; background: var(--line); position: relative; cursor: pointer;
  flex: none; transition: background .15s; margin: 0;
}
input[role="switch"]::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff;
  transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}
input[role="switch"]:checked { background: var(--accent); }
input[role="switch"]:checked::after { transform: translateX(18px); }

/* Dialogs, menus, toasts */

.dialog {
  border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
  width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
}
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-inner { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dialog h2 { font-size: 1.2rem; }
.dialog-sub { color: var(--muted); font-size: .9rem; margin-top: -6px; }
.dialog-body { display: flex; flex-direction: column; gap: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.switch-dialog { border-top: 4px solid var(--accent); }
.include-box { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--surface-2); display: flex; flex-direction: column; gap: 6px; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 600; cursor: pointer; min-height: 32px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; }
.choice-list { display: flex; flex-direction: column; gap: 4px; }
.choice { text-align: left; padding: 10px 12px; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.choice:hover { background: var(--surface-2); }
.choice.current { border-color: var(--accent); background: var(--accent-soft); }
.choice-new { color: var(--accent); }

.menu {
  position: fixed; z-index: 50; min-width: 220px; max-width: calc(100vw - 16px); overflow-y: auto; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.menu-heading { padding: 8px 10px 4px; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.menu-item {
  display: flex; flex-direction: column; align-items: flex-start; width: 100%; padding: 8px 10px; min-height: 40px; border: 0;
  border-radius: 8px; background: none; cursor: pointer; text-align: left;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-item.checked { background: var(--accent-soft); }
.menu-item.checked .menu-label::after { content: " ✓"; color: var(--accent); }
.menu-item.danger { color: var(--bad); }
.menu-sub { font-size: .76rem; color: var(--muted); }
.model-menu { min-width: 260px; }
.menu-item[disabled] { cursor: default; color: var(--muted); }
.menu-item[disabled]:hover { background: none; }
.menu-row { display: flex; align-items: center; gap: 4px; }
.menu-row .menu-item { flex: 1; min-width: 0; }
.menu-link {
  flex: none; display: inline-flex; align-items: center; min-height: 40px; padding: 0 10px; border-radius: 8px;
  color: var(--accent); font-size: .84rem; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.menu-link:hover, .menu-link:focus-visible { background: var(--surface-2); outline: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 60; transition: .25s;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Iteration 1: message actions, model labels, starters, cost line, search */

.msg-model { display: flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; color: var(--muted); padding: 0 4px; }
.prov-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.prov-anthropic { background: #c96442; }
.prov-openai { background: #10a37f; }
.prov-google { background: #4285f4; }
.prov-deepseek { background: #4d6bfe; }
.prov-mistral { background: #fa520f; }
.prov-openrouter { background: #6467f2; }
.msg-tag { font-weight: 500; border: 1px solid var(--line); border-radius: 99px; padding: 0 6px; font-size: .72rem; }
.msg-actions { display: flex; gap: 0; margin: -4px -6px 0; }
.msg.user .msg-actions { justify-content: flex-end; }
.act-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center; border: 0; background: none; border-radius: 8px;
  color: var(--muted); cursor: pointer;
}
.act-btn:hover { background: var(--surface-2); color: var(--ink); }
.act-btn[aria-pressed="true"] { color: var(--accent); }
.msg.excluded .bubble { opacity: .5; border-style: dashed; }
.msg.user.excluded .bubble { background: var(--surface-2); color: var(--ink); }
.left-out { display: flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--muted); padding: 0 4px; }
.starters { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 560px; margin: 4px auto 0; }
.messages > .starters { justify-content: flex-start; margin: 0; }
.starter {
  text-align: left; padding: 10px 14px; min-height: 44px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); cursor: pointer; font-size: .9rem; max-width: 100%;
}
.starter:hover { border-color: var(--accent); background: var(--accent-soft); }
.composer-wrap { flex: none; padding-bottom: env(safe-area-inset-bottom); }
.composer-wrap .composer { padding-bottom: 4px; }
.cost-line { max-width: 804px; margin: 0 auto; padding: 0 16px 8px 26px; font-size: .76rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.search-box {
  display: flex; align-items: center; gap: 8px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  color: var(--muted);
}
.search-box:focus-within { border-color: var(--accent); }
.search-input { flex: 1; border: 0; background: none; min-height: 46px; outline: none; color: var(--ink); }
.search-input::-webkit-search-cancel-button { cursor: pointer; }
.chat-list.results { padding: 0; }
.chat-row-snippet { color: var(--ink); opacity: .8; font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin-mark { color: var(--accent); margin-right: 4px; vertical-align: -2px; display: inline-flex; }
.folder-toggle.static { cursor: default; }
.folder.pinned { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.shortcuts { margin: 0; display: grid; gap: 6px; }
.shortcuts div { display: flex; justify-content: space-between; gap: 12px; }
.shortcuts dt, .shortcuts dd { margin: 0; }
kbd { font-family: var(--mono); font-size: .8rem; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 1px 6px; background: var(--surface-2); }

/* Touch screens: every control gets at least a 48px target (Android guidance). */
@media (pointer: coarse) {
  .icon-btn, .send-btn { width: 48px; height: 48px; }
  .act-btn { width: 48px; height: 48px; }
  .msg-actions { margin: -8px -10px -4px; }
  .model-btn, .btn, .next-btn, .nav a, .nav button, .menu-item, .choice, .starter, .chat-link, .folder-toggle, select, input[type="text"], .search-input { min-height: 48px; }
  .composer textarea { min-height: 48px; }
  .switch-row { min-height: 48px; }
  .check { min-height: 48px; }
  .link-btn { min-height: 48px; }
}

/* Iteration 1 polish */
.msg-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 0 8px; }
.msg-foot .msg-actions { margin: -4px 0 -4px -6px; }
.msg.user .msg-actions { display: none; }
.msg.user.show-actions .msg-actions, .msg.user:focus-within .msg-actions { display: flex; }
@media (hover: hover) { .msg.user:hover .msg-actions { display: flex; } }
.msg.user .bubble { cursor: pointer; }
.toast { bottom: calc(110px + env(safe-area-inset-bottom)); }
.model-btn { max-width: 46%; min-width: 0; flex: 0 1 auto; }
@media (pointer: coarse) { .msg-foot .msg-actions { margin: -8px 0 -8px -10px; } }

/* Your stack: home card, import screen, settings */
.stack-card {
  display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none;
}
.stack-card.cta { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); background: var(--accent-soft); }
.stack-card.cta:hover { border-color: var(--accent); }
.stack-card-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.stack-card-title { font-weight: 700; margin-right: auto; }
.stack-card-link { color: var(--accent); font-weight: 600; display: inline-flex; align-items: center; gap: 4px; text-decoration: none; min-height: 32px; }
.stack-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.stack-chips li { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); font-size: .84rem; }
.chip-role { color: var(--muted); font-weight: 600; }
.chip-role::after { content: ":"; }
.lead { font-size: 1.02rem; }
.callout { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--ink); }
.role-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.role-row { padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); display: flex; flex-direction: column; gap: 2px; }
.role-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.role-name { font-weight: 700; }
.role-model { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.role-prov { color: var(--muted); font-weight: 400; font-size: .8rem; }
.role-job, .role-uses { color: var(--muted); font-size: .86rem; }
.role-note { font-size: .84rem; padding: 6px 10px; margin-top: 4px; border-radius: 8px; background: var(--warn-soft); }
.role-inline { font-weight: 400; }
@media (pointer: coarse) { .stack-card-link { min-height: 48px; } }
.role-quiz { display: flex; gap: 6px; align-items: flex-start; font-size: .82rem; color: var(--muted); margin-top: 4px; }
.role-quiz .icon { margin-top: 2px; }
.import .import-actions { position: sticky; bottom: 0; z-index: 2; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 24%); }

/* Configuration */
.trust-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.trust-list li { display: flex; gap: 10px; align-items: flex-start; font-size: .9rem; }
.trust-list .icon { color: var(--accent); margin-top: 2px; }
.config-body { display: flex; flex-direction: column; gap: 16px; }
.provider-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.provider-head h2 { display: flex; align-items: center; gap: 8px; }
.status-chip { font-size: .78rem; font-weight: 600; padding: 3px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.status-chip.ok { background: var(--accent-soft); color: var(--accent); }
.status-chip.bad { background: var(--bad-soft); color: var(--bad); }
.key-form { display: flex; flex-direction: column; gap: 8px; }
.key-row { display: flex; gap: 8px; align-items: center; }
.key-row input { flex: 1; min-width: 0; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-family: var(--mono); }
.btn-danger-ghost { color: var(--bad); }
.model-check { font-size: .86rem; display: flex; flex-direction: column; gap: 4px; padding-top: 4px; border-top: 1px solid var(--line); }
.bad-text { color: var(--bad); }
.error-provider { font-family: var(--mono); font-size: .8rem; overflow-wrap: anywhere; }
@media (pointer: coarse) { .key-row input { min-height: 48px; } }
.key-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Configuration: groups, paste warnings, privacy line and gateway models */
.config-group { margin: 8px 0 -6px; }
.key-warn-box:empty { display: none; }
.key-warnings { margin: 0; padding: 8px 12px 8px 28px; border-radius: 10px; background: var(--warn-soft); font-size: .86rem; }
.privacy-line { margin: 0; }
.gw-models { display: flex; flex-direction: column; gap: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.gw-models h3 { margin: 0; font-size: .95rem; }
.gw-model-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.gw-model-list li { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.gw-model-text { display: flex; flex-direction: column; min-width: 0; }
.gw-model-name { font-weight: 600; }
.gw-model-id { font-family: var(--mono); font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }
.md a { color: var(--accent); text-decoration: underline; overflow-wrap: anywhere; }
@media (pointer: coarse) { .menu-link { min-height: 48px; } }

/* Workflow editor */
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.wf-edit-list { display: flex; flex-direction: column; gap: 16px; }
.wf-edit-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wf-edit-card-head h2 { margin: 0; }
.step-edit-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.step-edit { display: flex; flex-direction: column; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.step-edit-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.step-edit-num { font-weight: 700; }
.step-edit-tools { display: flex; gap: 4px; }
.step-edit-tools .icon-btn[disabled] { opacity: .35; cursor: default; }
.icon-btn.danger { color: var(--bad); }
.step-edit .field, .workflow-editor .field { display: flex; flex-direction: column; gap: 6px; }
.step-edit select, .step-edit input[type="text"], .step-edit textarea, .workflow-editor .field input {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit;
}
.step-edit textarea { min-height: 80px; resize: vertical; }
.step-uses { margin: 0; }
.step-more summary { cursor: pointer; color: var(--accent); font-weight: 600; min-height: 32px; display: flex; align-items: center; }
.step-more[open] { display: flex; flex-direction: column; gap: 10px; }
.editor-actions { position: sticky; bottom: 0; padding: 10px 0; background: var(--bg); }
@media (pointer: coarse) {
  .step-edit select, .step-edit input[type="text"], .workflow-editor .field input { min-height: 48px; }
  .step-edit-tools .icon-btn { min-width: 48px; min-height: 48px; }
  .step-more summary { min-height: 48px; }
}

/* Google Drive backups (Settings) */
#drive-settings h3 { font-size: 1rem; margin-top: 8px; }
.vault-dialog input[type="password"] { min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); width: 100%; }
.pw-kinds { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.pw-choice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.pw-choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.pw-choice input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.pw-choice > span { display: flex; flex-direction: column; gap: 2px; }
.rec-tag { align-self: flex-start; font-size: .75rem; font-weight: 600; color: var(--accent-ink); background: var(--accent); border-radius: 999px; padding: 1px 8px; }
.form-error { color: var(--bad); min-height: 1.2em; margin: 0; }
.form-error:empty { display: none; }
.recovery-code { font-family: var(--mono); font-size: 1.15rem; letter-spacing: .04em; padding: 12px; border: 1px dashed var(--line); border-radius: 10px; background: var(--surface-2); overflow-wrap: anywhere; user-select: all; }
@media (pointer: coarse) { .vault-dialog input[type="password"] { min-height: 48px; } }

/* The chat header's Google Drive button */
.drive-btn { display: inline-flex; align-items: center; justify-content: center; width: auto; min-width: 40px; gap: 6px; padding: 0 10px; color: var(--muted); }
.drive-btn.kept { color: var(--accent); }
.drive-btn.warn { color: var(--bad); }
.drive-btn-text { font-size: .8rem; white-space: nowrap; }
@media (max-width: 700px) { .drive-btn { padding: 0 8px; } .drive-btn-text { display: none; } }

/* Free tier and the full app (quota.js, license.js, views/upgrade.js) */
.plan-note { background: var(--accent-soft); border-radius: 10px; padding: 10px 14px; font-size: .9rem; margin: 12px 0; }
.plan-note.low { background: var(--warn-soft); }
.quota-note.low { color: var(--ink); font-weight: 600; }
.quota-meter { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 4px 0 10px; }
.quota-meter span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.upgrade-list { margin: 6px 0 0; padding-left: 20px; }
.upgrade-list li { margin: 4px 0; }
.wf-card.locked { opacity: .7; }
.wf-card .wf-name .status-chip { margin-left: 8px; vertical-align: middle; }

/* First run on Home (views/home.js) */
.getting-started { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin: 14px 0 18px; display: grid; gap: 8px; }
.getting-started .note { margin: 0; }
.gs-steps { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 10px; }
.gs-steps li { display: grid; grid-template-columns: 28px 1fr; gap: 4px 10px; align-items: start; }
.gs-steps li > .btn { grid-column: 2; justify-self: start; margin-top: 4px; }
.gs-mark { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .8rem; font-weight: 700; border: 1px solid var(--line); color: var(--muted); }
.gs-steps li.next .gs-mark { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.gs-steps li.done .gs-mark { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.gs-steps li.done .gs-label { color: var(--muted); text-decoration: line-through; }
.gs-label { font-weight: 600; display: block; }
.gs-detail { display: block; color: var(--muted); font-size: .87rem; }
.welcome { border: 1px solid var(--accent); }
