:root {
  --bg: #ffffff; --fg: #1b1b1f; --muted: #6b6f76; --line: #e6e7ea; --panel: #f4f5f7; --accent: #2f6fed; --accent-fg: #fff;
  --mine: #e9eef9; --hl: #fff2b8; --danger: #c62828; --ok: #2e9b57; --warn: #d9962b;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  font: 17px/1.45 -apple-system, system-ui, 'SF Pro Text', Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #000; --fg: #ececf0; --muted: #8e9199; --line: #26272b; --panel: #17181b; --accent: #4c8dff; --mine: #1d2a44; --hl: #4a4220; --danger: #ff6b6b; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* 🧑 "Your thread switching UI on the web can be scrolled left and right. It should not be able to scroll horizontally." */
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); overscroll-behavior: none; overflow-x: hidden; }
body { position: fixed; inset: 0; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .35; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; }
.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: block; }

#app { height: 100dvh; display: flex; flex-direction: column; position: relative; }

#bar { position: absolute; z-index: 5; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 4px; padding: calc(var(--safe-t) + 6px) 8px 6px 12px;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); transition: transform .25s; }
#bar.away { transform: translateY(-110%); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 7px 12px; border-radius: 20px; background: var(--panel); font-weight: 600; max-width: 60vw; position: relative; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .i { width: 16px; height: 16px; flex: none; }
.chip.quiet { background: none; font-weight: 400; color: var(--muted); font-size: 13px; padding: 7px 8px; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
#agent-unread { background: var(--accent); color: var(--accent-fg); border-radius: 10px; font-size: 12px; padding: 0 6px; min-width: 18px; text-align: center; }
#conn-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); display: inline-block; margin-right: 5px; }
#conn[data-state="retrying"] #conn-dot, #conn[data-state="connecting"] #conn-dot { background: var(--warn); }
#conn[data-state="offline"] #conn-dot { background: var(--danger); }
#conn[data-state="live"] #conn-text { display: none; }
.icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; flex: none; }
.icon.sm { width: 32px; height: 32px; font-size: 22px; line-height: 1; }
.icon.big { width: 52px; height: 52px; background: var(--fg); color: var(--bg); position: relative; }
.icon.round { width: 40px; height: 40px; background: var(--panel); }
.icon.accent { background: var(--accent); color: var(--accent-fg); }
.icon.accent:disabled { background: var(--panel); color: var(--muted); opacity: 1; }

#feed { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: calc(var(--safe-t) + 56px) 14px 12px; scroll-behavior: auto; overscroll-behavior: contain; }
.msg { margin: 0 0 14px; max-width: 100%; position: relative; }
.msg.agent { padding-left: 14px; }
.msg.agent.unread::before { content: ''; position: absolute; left: 0; top: .55em; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.msg.mine { display: flex; flex-direction: column; align-items: flex-end; }
.msg.mine .bubble { background: var(--mine); padding: 8px 14px; border-radius: 20px 20px 6px 20px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.mine.sending .bubble { opacity: .55; }
.msg .state { font-size: 12px; color: var(--muted); margin-top: 2px; }
.msg .state:empty { display: none; }
.msg .state button { color: var(--accent); font-weight: 600; margin-left: 8px; }
.msg.failed .state { color: var(--danger); }
.title { font-size: 12px; color: var(--muted); letter-spacing: .02em; margin-bottom: 2px; }
.body p, .body li, .body h4 { margin: 0 0 .5em; overflow-wrap: anywhere; }
.body h4 { font-size: 1em; }
.body ul { margin: 0 0 .5em; padding-left: 1.2em; }
.body pre { background: var(--panel); border-radius: 10px; padding: 10px 12px; overflow-x: auto; font-size: 13px; margin: 0 0 .6em; -webkit-overflow-scrolling: touch; }
.body code { font: 14px ui-monospace, Menlo, monospace; background: var(--panel); border-radius: 4px; padding: 0 3px; }
.body pre code { background: none; padding: 0; }
.body a { color: var(--accent); }
.s { border-radius: 4px; -webkit-box-decoration-break: clone; box-decoration-break: clone; transition: background .15s; }
.s.now { background: var(--hl); }
.notice { text-align: center; color: var(--muted); font-size: 13px; margin: 8px 0 14px; }
.empty { text-align: center; color: var(--muted); margin-top: 30vh; }

#banner { margin: 0 12px 6px; padding: 9px 14px; border-radius: 14px; background: var(--panel); font-size: 14px; text-align: center; }
#banner.warn { background: color-mix(in srgb, var(--warn) 22%, var(--bg)); }
#banner.err { background: color-mix(in srgb, var(--danger) 20%, var(--bg)); }
#banner.tap { background: var(--accent); color: var(--accent-fg); font-weight: 600; }

#dock { border-top: 1px solid var(--line); background: var(--bg); padding-bottom: var(--safe-b); }
#transport { display: flex; align-items: center; gap: 2px; padding: 4px 8px 0; height: 60px; overflow: hidden; transition: height .2s, opacity .2s, padding .2s; }
#dock.min #transport { height: 0; opacity: 0; padding-top: 0; }
#rate { font-variant-numeric: tabular-nums; font-size: 14px; min-width: 34px; text-align: center; }
#play .pause, #play .spin { display: none; }
#play[data-state="playing"] .play { display: none; }
#play[data-state="playing"] .pause { display: block; }
#play[data-state="loading"] .play, #play[data-state="loading"] .pause { display: none; }
#play[data-state="loading"] .spin { display: block; }
.spin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid color-mix(in srgb, var(--bg) 30%, transparent); border-top-color: var(--bg); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#play[data-state="error"] { background: var(--danger); }
#composer { display: flex; align-items: flex-end; gap: 6px; padding: 6px 10px 8px; }
#field { flex: 1; background: var(--panel); border-radius: 22px; padding: 0 14px; min-height: 40px; display: flex; align-items: center; position: relative; }
#draft { flex: 1; width: 100%; font: inherit; font-size: 17px; color: inherit; background: none; border: 0; outline: 0; resize: none; padding: 8px 0; max-height: 40vh; line-height: 1.35; }
#level { position: absolute; right: 10px; bottom: 8px; width: 60px; height: 12px; opacity: .85; }
#mic .done { display: none; }
#composer.rec #mic { background: var(--danger); color: #fff; }
#composer.rec #mic .mic { display: none; }
#composer.rec #mic .done { display: block; }
#composer.rec #draft { padding-right: 64px; }

#toast { position: absolute; left: 50%; bottom: calc(120px + var(--safe-b)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 9px 16px; border-radius: 18px; font-size: 14px; max-width: 90vw; z-index: 9; }
#toast button { color: var(--accent); margin-left: 12px; font-weight: 600; filter: brightness(1.3); }

dialog { border: 0; padding: 0; background: var(--bg); color: var(--fg); width: min(100vw, 560px); max-width: 100vw; max-height: 86dvh; margin: auto auto 0; border-radius: 20px 20px 0 0; }
dialog.top { top: 0; margin: 0 auto auto; border-radius: 0 0 20px 20px; padding-top: var(--safe-t, env(safe-area-inset-top, 0px)); max-height: 60dvh; }
dialog.top .sheet { max-height: 60dvh; }
dialog::backdrop { background: rgba(0,0,0,.45); }
.sheet { box-sizing: border-box; padding: 12px 16px calc(16px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; max-height: 86dvh; overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.sheet > * { flex-shrink: 0; }
.sheet.full { height: 86dvh; }
.sheet-head { display: flex; align-items: center; gap: 8px; }
.sheet-head h2, #login h2 { margin: 0; font-size: 20px; flex: 1; }
.sheet-head input { flex: 1; font: inherit; border: 0; background: var(--panel); border-radius: 12px; padding: 10px 14px; color: inherit; outline: 0; }
#topics { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex-shrink: 1; min-height: 0; -webkit-overflow-scrolling: touch; }
#topics li { display: flex; flex-direction: column; gap: 1px; padding: 11px 6px; border-bottom: 1px solid var(--line); position: relative; }
#topics li[aria-current="true"] { background: var(--panel); border-radius: 10px; }
#topics .name { font-weight: 600; }
#topics .snip { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#topics .badge { position: absolute; right: 8px; top: 12px; background: var(--accent); color: var(--accent-fg); border-radius: 10px; font-size: 12px; padding: 0 7px; }
section { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; }
.row input[type=range] { flex: 1; max-width: 55%; }
.row input[type=checkbox] { width: 24px; height: 24px; }
button.wide { padding: 13px; border-radius: 12px; background: var(--panel); font-weight: 600; width: 100%; }
button.wide.accent { background: var(--accent); color: var(--accent-fg); }
button.wide.danger { color: var(--danger); }
#login-form textarea { font: 14px ui-monospace, monospace; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: inherit; padding: 10px; }
pre { margin: 0; font: 12px/1.35 ui-monospace, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
#debug-status { background: var(--panel); padding: 10px; border-radius: 10px; max-height: 30dvh; overflow: auto; -webkit-overflow-scrolling: touch; }
#debug-log { flex: 1 1 0; min-height: 120px; overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; user-select: text; -webkit-user-select: text; }
.debug-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.debug-actions button { padding: 9px 14px; border-radius: 10px; background: var(--panel); font-weight: 600; }

/* Long or recording text: the text box full width on top, the buttons on one row below it (thumb reach). */
#composer { flex-wrap: wrap; justify-content: flex-end; align-items: center; }
#composer.tall #field { order: 1; flex: 1 0 100%; }
#composer.tall > button { order: 2; }
#composer.tall #cancel-rec { margin-right: auto; }
#net { margin: 0 12px 6px; padding: 7px 14px; border-radius: 14px; font-size: 13px; text-align: center; background: color-mix(in srgb, var(--warn) 22%, var(--bg)); }
#jump { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(130px + var(--safe-b)); z-index: 6; background: var(--accent); color: var(--accent-fg); padding: 8px 16px; border-radius: 18px; font-weight: 600; box-shadow: 0 2px 10px rgba(0,0,0,.25); }

.atts { margin: 4px 0 8px; display: flex; flex-direction: column; gap: 6px; }
.msg.mine .atts { align-items: flex-end; }
.att .attimg { display: block; max-width: 100%; max-height: 50vh; border-radius: 12px; background: var(--panel); min-height: 60px; }
.att.chip .chipbtn { background: var(--panel); border-radius: 14px; padding: 6px 12px; font-size: 14px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#howto { display: block; text-align: center; padding: 12px; border-radius: 12px; background: var(--accent); color: var(--accent-fg); font-weight: 700; text-decoration: none; }
#listen[data-state='on'] { opacity: .6; }
#listen[data-state='heard'] { opacity: 1; background: var(--accent); }
#listen { position: relative; }
#listen-label { display: none; }
#listen[data-state='listening'] { background: var(--accent); color: var(--accent-fg); }
#listen[data-state='on'] { background: color-mix(in srgb, var(--accent) 35%, var(--panel)); }
#listen[data-state='waiting'] { outline: 2px dashed var(--warn); }
#listen[data-state='heard'], #listen[data-state='dictating'], #listen[data-state='sending'] { background: var(--danger); color: #fff; }
#prev-agent-name { display: none; }
#prev-agent .arrow { font-size: 20px; line-height: 1; }

.footer { margin: 2px 0 8px; font-size: 13px; color: var(--muted); }
.footer-chip { background: var(--panel); border-radius: 12px; padding: 3px 10px; font-size: 12px; }
.footer-text { white-space: pre-wrap; margin-top: 4px; }
@media (max-width: 899px) { .footer:not(.open) .footer-text { display: none; } }
@media (min-width: 900px) { .footer-chip { display: none; } }
#tap-flash { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%) scale(.8); font-size: 44px; opacity: 0; pointer-events: none; z-index: 8; background: color-mix(in srgb, var(--bg) 80%, transparent); border-radius: 50%; width: 90px; height: 90px; display: grid; place-items: center; }
#tap-flash.show { animation: flash .7s ease-out; }
@keyframes flash { 0% { opacity: .95; transform: translate(-50%, -50%) scale(.8); } 100% { opacity: 0; transform: translate(-50%, -50%) scale(1.15); } }
#listen[data-state='command'] { background: var(--warn); color: #000; }
#topics .chan { font-size: 11px; color: var(--muted, #888); border: 1px solid var(--line); border-radius: 8px; padding: 1px 6px; margin-left: 6px; white-space: nowrap; }

.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; padding: 4px 16px 16px; }
.keys dt { font-weight: 700; white-space: nowrap; }
.keys dd { margin: 0; }
html.picker-open, html.picker-open body { position: fixed; inset: 0; width: 100%; overflow: hidden; overscroll-behavior: none; touch-action: none; }
#picker { overscroll-behavior: contain; }
#picker #topics { touch-action: pan-y; overscroll-behavior: contain; }
#picker::backdrop { touch-action: none; }
#composer.warming #mic { background: var(--warn, #d9a400); animation: mic-warm 0.9s ease-in-out infinite; }
#composer.warming #level { visibility: hidden; }
@keyframes mic-warm { 50% { opacity: .45; } }
#next-unread { position: relative; }
#next-unread .arrow { font-size: 20px; line-height: 1; }
#next-unread-count { position: absolute; top: -2px; right: -2px; background: var(--accent); color: var(--accent-fg); border-radius: 9px; font-size: 11px; min-width: 16px; line-height: 16px; text-align: center; }
.msg.agent .mark-read { display: none; margin: 6px 0 0 auto; font-size: 13px; padding: 4px 12px; border-radius: 14px; background: var(--panel); color: var(--muted, inherit); border: 0; }
.msg.agent.unread .mark-read { display: block; }
.body .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 0 .6em; border: 1px solid var(--panel); border-radius: 10px; }
.body table { border-collapse: collapse; font-size: 13px; width: max-content; min-width: 100%; }
.body th, .body td { padding: 6px 10px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--panel); }
.body th { background: var(--panel); font-weight: 600; white-space: nowrap; }
.body tr:last-child td { border-bottom: 0; }
.att .attcap { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: 13px; color: var(--muted, inherit); opacity: .85; }
.att .attname { flex: 1; min-width: 0; overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; }
.att .atthide { background: var(--panel); border: 0; border-radius: 12px; padding: 3px 10px; font-size: 12px; color: inherit; }
#attach .i { stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
