/* Claude Bot — calm, plain, fast. Warm off-white / near-black, one clay accent. */

:root {
  color-scheme: light dark;
  --bg: #F8F6F1;
  --bg-side: #F1EEE7;
  --surface: #FFFFFF;
  --surface-2: #F3F0E9;
  --line: #E6E1D7;
  --line-strong: #D5CFC2;
  --text: #22201C;
  --muted: #6B665C;
  --faint: #8D877B;
  --accent: #D97757;
  --accent-strong: #B04E2B;
  --accent-ink: #2B160C;
  --accent-soft: #F7E6DC;
  --user-bg: #F1DFD3;
  --user-ink: #2A1B14;
  --info: #5B8DB8;
  --danger: #B3402F;
  --danger-soft: #FBEAE6;
  --wait: #D9A21B;
  --wait-ink: #8A5A00;
  --warn-bg: #FFF0B8;
  --warn-ink: #47350A;
  --warn-line: #E6C24E;
  --screen-bg: #12110F;
  --shadow: 0 1px 2px rgb(50 35 20 / .06), 0 6px 18px rgb(50 35 20 / .08);
  --shadow-lg: 0 24px 64px rgb(40 25 10 / .28), 0 2px 8px rgb(40 25 10 / .12);
  --side-w: 296px;
  --screen-w: 448px;
  --tab-h: 58px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412;
    --bg-side: #1B1A17;
    --surface: #211F1C;
    --surface-2: #2A2723;
    --line: #322F2A;
    --line-strong: #453F38;
    --text: #ECE8E0;
    --muted: #A8A196;
    --faint: #857F74;
    --accent-strong: #EE9873;
    --accent-soft: #3A2A22;
    --user-bg: #402D22;
    --user-ink: #F6E8DD;
    --info: #7FAAD0;
    --danger: #EA7A66;
    --danger-soft: #3A2320;
    --wait: #E6B031;
    --wait-ink: #F0C453;
    --warn-bg: #4A3D11;
    --warn-ink: #FBE9A6;
    --warn-line: #7C6821;
    --screen-bg: #0C0B0A;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 6px 18px rgb(0 0 0 / .3);
    --shadow-lg: 0 24px 64px rgb(0 0 0 / .6), 0 2px 8px rgb(0 0 0 / .4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
a { color: var(--accent-strong); }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; border-radius: 6px; }
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }

/* ---------- small parts ---------- */
.boot { position: fixed; inset: 0; display: grid; place-items: center; color: var(--muted); }

.wordmark { display: inline-flex; align-items: center; gap: 9px; font-weight: 650; font-size: 16px; letter-spacing: -.01em; }
.wordmark .mark { width: 24px; height: 24px; border-radius: 7px; background: url(/app/favicon.svg) center / cover no-repeat; flex: none; }
.wordmark-lg { font-size: 22px; }
.wordmark-lg .mark { width: 32px; height: 32px; border-radius: 9px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; min-height: 38px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-weight: 550; white-space: nowrap; text-decoration: none; line-height: 1.2;
  transition: background .12s, border-color .12s, filter .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-sm { padding: 5px 11px; min-height: 32px; font-size: 13px; border-radius: 9px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.06); }
.btn-quiet { background: transparent; border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }
.btn-danger-text { color: var(--danger); }
.btn-stop { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line-strong)); }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none;
  border: 0; border-radius: 10px; background: transparent; color: var(--muted);
}
.icon-btn:hover { background: color-mix(in srgb, var(--text) 7%, transparent); color: var(--text); }
.icon-btn[aria-pressed="true"], .icon-btn.is-on { color: var(--accent-strong); }
.link-btn { border: 0; background: none; padding: 2px 0; color: var(--accent-strong); font-size: 13px; font-weight: 550; text-align: left; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.grow { flex: 1; }
.field-label { font-size: 12.5px; font-weight: 550; color: var(--muted); }
input[type="text"], input[type="password"], textarea, select {
  width: 100%; padding: 9px 11px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--surface); min-height: 40px;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 70%, transparent); outline-offset: 0; border-color: var(--accent); }
.form-error { color: var(--danger); font-size: 13px; }

.spinner { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; flex: none; opacity: .8; }
@keyframes spin { to { transform: rotate(360deg); } }

.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(92vw, 460px); pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px; box-shadow: var(--shadow); font-size: 13.5px; opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: auto; }
.toast.in { opacity: 1; transform: none; }
.toast-error { background: var(--danger); color: #fff; }

.offline { position: fixed; top: 0; left: 0; right: 0; height: 28px; z-index: 90; display: flex; align-items: center; justify-content: center; background: var(--warn-bg); color: var(--warn-ink); border-bottom: 1px solid var(--warn-line); font-size: 13px; font-weight: 600; }
#app.is-offline { padding-top: 28px; }

/* avatars + status dots */
.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; flex: none; line-height: 1; user-select: none; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .08); }
.avatar-emoji { font-family: var(--emoji); }
.avatar-wrap { position: relative; display: inline-block; flex: none; }
.dot { position: absolute; right: -2px; bottom: -2px; width: 13px; height: 13px; border-radius: 50%; border: 2.5px solid var(--ring, var(--bg-side)); background: var(--faint); opacity: 1; }
.dot-idle { background: color-mix(in srgb, var(--faint) 70%, var(--bg-side)); }
.dot-working { background: var(--accent); animation: pulse 1.5s ease-out infinite; }
.dot-waiting { background: var(--wait); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); } 100% { box-shadow: 0 0 0 8px transparent; } }
.dot-inline { position: static; display: inline-block; width: 8px; height: 8px; border: 0; flex: none; animation: none; }
.head-status.st-idle .dot-inline { background: var(--faint); opacity: .6; }
.head-status.st-working .dot-inline { background: var(--accent); animation: pulse 1.5s ease-out infinite; }
.head-status.st-waiting .dot-inline { background: var(--wait); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--accent-soft); color: var(--accent-strong); white-space: nowrap; flex: none; }

/* ---------- app shell ---------- */
#app { height: 100vh; height: 100dvh; display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr) var(--screen-w); }
#app[data-view="computer"], #app[data-view="routines"] { grid-template-columns: var(--side-w) minmax(0, 1fr); }
#app[data-view="computer"] #screen-panel, #app[data-view="routines"] #screen-panel { display: none; }
#main { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg); position: relative; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
#tabbar { display: none; }

/* ---------- sidebar ---------- */
#sidebar { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg-side); border-right: 1px solid var(--line); --ring: var(--bg-side); }
.brand { height: 60px; padding: 0 12px 0 16px; display: flex; align-items: center; justify-content: space-between; flex: none; }
.brand-actions { display: flex; gap: 2px; }
.side-main { padding: 2px 10px 10px; border-bottom: 1px solid var(--line); flex: none; }
.side-list { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.side-list.is-empty { flex: none; padding: 0; }
.side-empty { display: none; color: var(--muted); font-size: 13px; padding: 14px 20px 6px; flex: 1; }
.side-list.is-empty + .side-empty { display: block; }

.bot-row {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  width: 100%; padding: 9px 10px; border: 0; border-radius: 12px; background: transparent; text-align: left; --ring: var(--bg-side);
}
.bot-row:hover { background: color-mix(in srgb, var(--text) 5.5%, transparent); }
.bot-row.is-selected { background: var(--surface); box-shadow: 0 0 0 1px var(--line), 0 1px 2px rgb(50 35 20 / .05); --ring: var(--surface); }
.bot-row.is-main { padding: 11px 10px; }
.row-text { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.row-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row-name { font-weight: 620; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 12.8px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub.sub-working { color: var(--accent-strong); }
.row-sub.sub-waiting { color: var(--wait-ink); font-weight: 550; }
.count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; }
.count.count-wait { background: var(--wait); color: #3A2A00; }

.new-bot { margin: 6px 10px 8px; padding: 10px 12px; border: 1px dashed var(--line-strong); border-radius: 12px; background: transparent; color: var(--muted); font-weight: 560; display: flex; align-items: center; justify-content: center; gap: 8px; flex: none; }
.new-bot:hover { color: var(--text); border-color: var(--faint); background: color-mix(in srgb, var(--text) 4%, transparent); }
.side-foot { flex: none; padding: 8px 10px 12px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 1px; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 550; text-align: left; width: 100%; }
.nav-item:hover { background: color-mix(in srgb, var(--text) 5.5%, transparent); color: var(--text); }
.nav-item.is-active { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
.nav-label { flex: 1; }
.nav-badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: var(--faint); color: var(--bg); font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; }
.nav-item.has-pending { color: var(--text); }
.nav-item.has-pending .nav-badge { background: var(--wait); color: #3A2A00; }
[data-icon] { display: inline-flex; }
.brand-actions [data-icon], .brand-actions .icon-btn { display: inline-grid; }

/* ---------- chat ---------- */
#view-chat { position: relative; }
.chat-head { height: 60px; flex: none; display: flex; align-items: center; gap: 12px; padding: 0 14px 0 20px; border-bottom: 1px solid var(--line); background: var(--bg); }
.head-avatar { flex: none; display: inline-flex; }
.head-text { flex: 1; min-width: 0; }
.head-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.head-name { font-size: 15.5px; font-weight: 650; letter-spacing: -.005em; white-space: nowrap; }
.head-title { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.head-status { display: flex; align-items: center; gap: 7px; font-size: 12.8px; color: var(--muted); min-width: 0; }
.head-status-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-status.st-waiting { color: var(--wait-ink); font-weight: 550; }
.head-status.st-working { color: var(--accent-strong); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent-strong); font-size: 12.5px; font-weight: 600; white-space: nowrap; flex: none; }
.head-screen { display: none; }

.transcript { position: relative; flex: 1; min-height: 0; }
.scroller { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; overflow-anchor: none; scroll-behavior: auto; }
.stream-wrap { width: 100%; max-width: 800px; margin: 0 auto; padding: 22px 20px 14px; min-height: 100%; display: flex; flex-direction: column; }
.stream { display: flex; flex-direction: column; gap: 10px; }
.top-note { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); font-size: 12.5px; padding: 0 0 12px; }
.empty { flex: 1; display: grid; place-items: center; padding: 40px 0; }
.empty-card { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; max-width: 360px; color: var(--muted); }
.empty-card .avatar { margin-bottom: 6px; }
.empty-title { font-weight: 640; font-size: 16px; color: var(--text); }
.empty-sub { font-size: 13.5px; }
.jump { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 99px; border: 1px solid var(--line-strong); background: var(--surface); box-shadow: var(--shadow); font-weight: 560; font-size: 13px; z-index: 5; }
.jump:hover { background: var(--surface-2); }

.working { display: flex; align-items: center; gap: 10px; margin: 12px 0 0 4px; font-size: 13px; color: var(--muted); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: .35; animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .18s; }
.dots i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-2px); } }

.row { display: flex; flex-direction: column; min-width: 0; }
.row-user { align-items: flex-end; }
.row-bot { align-items: flex-start; }
.bubble { max-width: min(660px, 88%); padding: 9px 14px; border-radius: 18px; overflow-wrap: anywhere; min-width: 0; }
.bubble-user { background: var(--user-bg); color: var(--user-ink); border-bottom-right-radius: 6px; }
.user-text { white-space: pre-wrap; }
.bubble-bot { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.meta { font-size: 11.5px; color: var(--faint); margin: 3px 6px 0; }
.atts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.user-text + .atts { margin-top: 8px; }
.bubble-user > .atts:first-child { margin-top: 0; }
.att-img { display: block; }
.att-img img { display: block; min-width: 96px; min-height: 64px; max-width: 240px; max-height: 180px; object-fit: cover; border-radius: 10px; border: 1px solid rgb(0 0 0 / .08); }
.att-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; background: rgb(255 255 255 / .55); color: inherit; text-decoration: none; font-size: 13px; }
@media (prefers-color-scheme: dark) { .att-chip { background: rgb(255 255 255 / .1); } }

/* markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .65em; }
.md ul, .md ol { margin: 0 0 .65em; padding-left: 1.35em; }
.md li { margin: .15em 0; }
.md li > p { margin: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: .9em 0 .35em; font-size: 1em; font-weight: 680; line-height: 1.3; }
.md h1 { font-size: 1.12em; }
.md code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: .1em .38em; border-radius: 5px; }
.md pre { margin: 0 0 .7em; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; font-size: 12.5px; line-height: 1.5; }
.md blockquote { margin: 0 0 .65em; padding: 0 0 0 12px; border-left: 3px solid var(--line-strong); color: var(--muted); }
.md table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: 0 0 .7em; font-size: .95em; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 9px; text-align: left; }
.md th { background: var(--surface-2); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: .9em 0; }
.md img { max-width: 100%; height: auto; border-radius: 8px; }
.md a { text-underline-offset: 2px; }

/* tool runs */
.tools { align-self: flex-start; max-width: 100%; min-width: 0; font-size: 12.8px; color: var(--muted); }
.tools-toggle { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; padding: 4px 11px 4px 7px; border: 0; border-radius: 99px; background: color-mix(in srgb, var(--text) 5.5%, transparent); color: inherit; text-align: left; }
.tools-toggle:hover { background: color-mix(in srgb, var(--text) 9%, transparent); color: var(--text); }
.tools-chev { transition: transform .15s; flex: none; }
.tools.is-open .tools-chev { transform: rotate(90deg); }
.tools-count { font-weight: 600; white-space: nowrap; }
.tools-what { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tools-err { margin-left: 8px; color: var(--danger); font-weight: 600; white-space: nowrap; }
.tool-list { list-style: none; margin: 6px 0 2px 10px; padding: 0 0 0 4px; border-left: 2px solid var(--line); }
.tool-row { display: flex; gap: 10px; align-items: baseline; padding: 3px 0 3px 10px; min-width: 0; }
.tool-name { flex: none; width: 118px; color: var(--faint); font-size: 12px; }
.tool-summary { font-family: var(--mono); font-size: 12px; color: var(--muted); overflow-wrap: anywhere; min-width: 0; }
.tool-row.is-error .tool-summary, .tool-row.is-error .tool-name { color: var(--danger); }

/* cards */
.card { width: min(660px, 100%); align-self: flex-start; border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 11px 14px 12px; min-width: 0; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.card-title { font-weight: 640; color: var(--text); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-time { font-size: 11.5px; color: var(--faint); margin-left: auto; flex: none; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.card-msg { background: var(--surface-2); border-left-width: 3px; }
.card-msg.is-out { border-left-color: var(--accent); }
.card-msg.is-in { border-left-color: var(--info); }
.card-msg .card-text { font-size: 14px; overflow-wrap: anywhere; }
.card-msg.is-long:not(.is-open) .card-text { max-height: 9.6em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.card-msg .link-btn { margin-top: 4px; }

.card-file { padding: 0; overflow: hidden; }
.file-preview { display: block; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.file-preview img { display: block; width: 100%; max-height: 340px; object-fit: contain; }
.file-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 14px; }
.file-icon { color: var(--muted); display: inline-flex; }
.file-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { font-size: 12.5px; color: var(--muted); }

.card-approval.is-pending { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface)); }
.card-approval .card-head svg { color: var(--accent-strong); }
.card-approval.is-decided { background: var(--surface-2); }
.card-approval.st-denied .card-head svg { color: var(--danger); }
.card-approval.st-allowed .card-head svg, .card-approval.st-always .card-head svg { color: var(--info); }
.approval-action { font-weight: 620; overflow-wrap: anywhere; }
.approval-details { margin-top: 3px; color: var(--muted); font-size: 13.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.approval-rule { margin-top: 6px; color: var(--accent-strong); font-size: 13px; font-weight: 550; overflow-wrap: anywhere; }
.card-handoff.is-pending { border-color: var(--warn-line); background: var(--warn-bg); color: var(--warn-ink); }
.card-handoff.is-pending .card-head, .card-handoff.is-pending .card-title, .card-handoff.is-pending .card-time { color: var(--warn-ink); }
.card-handoff .handoff-text { overflow-wrap: anywhere; }
.card-handoff.is-decided { background: var(--surface-2); }
.card-handoff.is-pending .btn { border-color: var(--warn-line); background: rgb(255 255 255 / .55); color: var(--warn-ink); }
.card-handoff.is-pending .btn-primary { background: var(--warn-ink); border-color: var(--warn-ink); color: var(--warn-bg); }
.card-handoff.is-pending .btn-quiet { background: transparent; border-color: transparent; }
@media (prefers-color-scheme: dark) { .card-handoff.is-pending .btn { background: rgb(255 255 255 / .08); } .card-handoff.is-pending .btn-primary { background: var(--warn-ink); } }

.event { align-self: center; max-width: 90%; text-align: center; font-size: 12.5px; color: var(--faint); padding: 2px 8px; overflow-wrap: anywhere; }
.err-line { align-self: flex-start; display: flex; gap: 8px; align-items: flex-start; max-width: min(660px, 100%); padding: 8px 12px; border-radius: 12px; background: var(--danger-soft); color: var(--danger); font-size: 13.5px; overflow-wrap: anywhere; }
.err-line svg { flex: none; margin-top: 2px; }
.day { align-self: stretch; display: flex; align-items: center; gap: 12px; margin: 10px 0 2px; color: var(--faint); font-size: 12px; font-weight: 550; }
.day::before, .day::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* composer */
.composer { flex: none; width: 100%; max-width: 800px; margin: 0 auto; padding: 4px 20px 18px; }
.composer-box { display: flex; align-items: flex-end; gap: 4px; padding: 6px 6px 6px 6px; border: 1px solid var(--line-strong); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); transition: border-color .12s, box-shadow .12s; }
.composer-box:focus-within { border-color: color-mix(in srgb, var(--accent) 75%, var(--line-strong)); box-shadow: var(--shadow), 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.composer-input { flex: 1; min-width: 0; border: 0; background: transparent; resize: none; padding: 8px 4px; min-height: 36px; max-height: 190px; line-height: 1.45; font-size: 15px; outline: none; }
.composer-input:focus-visible { outline: none; }
.composer-input::placeholder { color: var(--faint); }
.composer-attach { width: 36px; height: 36px; border-radius: 50%; }
.send-btn { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: inline-grid; place-items: center; flex: none; transition: background .12s, opacity .12s; }
.send-btn:hover:not(:disabled) { filter: brightness(1.06); }
.send-btn:disabled { background: var(--line); color: var(--faint); cursor: default; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 6px 8px; }
.chip-file { display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12.8px; max-width: 100%; }
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.chip-x { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; border: 0; background: transparent; color: var(--muted); padding: 0; }
.chip-x:hover { background: color-mix(in srgb, var(--text) 10%, transparent); }

.drop-veil { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(3px); border: 2px dashed var(--accent); border-radius: 14px; margin: 8px; pointer-events: none; }
.drop-card { display: inline-flex; align-items: center; gap: 10px; padding: 12px 20px; border-radius: 99px; background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }

/* ---------- screen panel ---------- */
#screen-panel { min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; background: var(--bg-side); border-left: 1px solid var(--line); }
.scr-head { height: 60px; flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 14px 0 16px; }
.scr-title { display: flex; align-items: center; gap: 9px; min-width: 0; }
.scr-label { font-weight: 640; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scr-head-actions { display: flex; align-items: center; gap: 6px; }
.scr-close { display: none; }
.led { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--faint); opacity: .55; }
.led-on { background: #4FB477; opacity: 1; box-shadow: 0 0 0 3px color-mix(in srgb, #4FB477 25%, transparent); }
.led-wait { background: var(--wait); opacity: 1; box-shadow: 0 0 0 3px color-mix(in srgb, var(--wait) 30%, transparent); }

.scr-stagewrap { position: relative; flex: none; }
.scr-stage { position: relative; aspect-ratio: 16 / 10; margin: 0 16px; background: var(--screen-bg); border-radius: 12px; overflow: hidden; box-shadow: 0 0 0 1px var(--line-strong), 0 6px 20px rgb(30 20 10 / .16); flex: none; }
.scr-stage.is-control { box-shadow: 0 0 0 2px var(--accent), 0 6px 20px rgb(30 20 10 / .16); }
.scr-stage.is-tall { margin: 0 auto; width: min(100%, calc((100dvh - 250px) * 1.6)); }
.scr-host, .scr-live, .scr-snap { position: absolute; inset: 0; width: 100%; height: 100%; }
.scr-snap { object-fit: contain; background: var(--screen-bg); }
.scr-overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 16px 22px; text-align: center; color: #CFC9BC; background: color-mix(in srgb, var(--screen-bg) 94%, transparent); font-size: 13.5px; }
.scr-overlay svg { color: #8E887C; }
.ov-title { font-weight: 640; color: #ECE8E0; font-size: 14.5px; }
.ov-sub { max-width: 30ch; color: #A8A196; font-size: 12.8px; margin-bottom: 4px; }
.scr-note { position: absolute; left: 8px; top: 8px; padding: 3px 10px; border-radius: 99px; background: rgb(0 0 0 / .6); color: #ECE8E0; font-size: 12px; }
.scr-placeholder { position: absolute; inset: 0; display: grid; place-items: center; background: var(--screen-bg); color: #A8A196; font-size: 13px; }

.handoff-banner { position: absolute; left: 24px; right: 24px; bottom: 8px; display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-radius: 11px; background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line); box-shadow: 0 8px 24px rgb(0 0 0 / .35); font-size: 13px; z-index: 3; }
.hb-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.hb-text strong { font-weight: 680; }
.hb-text span { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.hb-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.handoff-banner .btn { border-color: var(--warn-line); background: rgb(255 255 255 / .55); color: var(--warn-ink); min-height: 30px; padding: 4px 10px; font-size: 12.5px; }
.handoff-banner .btn.hb-open { background: var(--warn-ink); border-color: var(--warn-ink); color: var(--warn-bg); }
.handoff-banner .btn-ghost { background: transparent; border-color: transparent; }
@media (prefers-color-scheme: dark) { .handoff-banner .btn { background: rgb(255 255 255 / .09); } .handoff-banner .btn.hb-open { background: var(--warn-ink); } }

.scr-foot { padding: 14px 18px 24px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.scr-status { font-size: 13px; color: var(--muted); }
.scr-status.st-working { color: var(--accent-strong); }
.scr-status.st-waiting { color: var(--wait-ink); font-weight: 550; }
.scr-tools { margin: 4px 0 0; }
.scr-tools .tool-name { width: auto; min-width: 0; max-width: 42%; }
.scr-tools .tool-row { flex-direction: column; gap: 0; padding: 4px 0 4px 10px; }

/* full-screen modal */
.dlg.dlg-screen { width: min(1240px, calc(100vw - 24px), calc((100dvh - 250px) * 1.6 + 34px)); max-width: none; }
.screen-modal { display: flex; flex-direction: column; gap: 12px; padding: 4px 16px 16px; }
.screen-modal .scr-head { padding: 0; }
.screen-modal .scr-stage { margin: 0 auto; }
.screen-modal .scr-stagewrap { margin: 0; }
.modal-note { text-align: center; color: var(--muted); font-size: 13px; }
.modal-actions { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; padding: 10px 14px; border-radius: 12px; background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line); }
.modal-ask { overflow-wrap: anywhere; }
.dlg-screen.is-control .modal-note { color: var(--accent-strong); font-weight: 550; }

/* "Type on screen" bar: shown only while Take control is on */
.type-bar { display: flex; flex-direction: column; gap: 8px; width: min(100%, 720px); margin: 0 auto; }
.tb-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.tb-input { flex: 1; min-width: 0; font-size: 16px; } /* 16px: iOS zooms the page on focus below this */
.tb-input.is-masked { -webkit-text-security: disc; }
.tb-send { min-width: 64px; min-height: 40px; }
.tb-keys { flex-wrap: wrap; }
.tb-key { flex: 1 1 auto; padding-inline: 8px; }

.switch { display: inline-flex; align-items: center; gap: 9px; white-space: nowrap; padding: 4px 6px; border: 0; background: transparent; border-radius: 99px; font-weight: 560; font-size: 13.5px; }
.switch-track { position: relative; width: 38px; height: 22px; border-radius: 99px; background: var(--line-strong); transition: background .15s; flex: none; }
.switch-thumb { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .3); transition: transform .15s; }
.switch[aria-checked="true"] .switch-track { background: var(--accent); }
.switch[aria-checked="true"] .switch-thumb { transform: translateX(16px); }
.switch-plain { padding: 2px; }

/* ---------- other views ---------- */
.view-head { padding: 16px 24px 10px; flex: none; display: flex; align-items: flex-end; justify-content: space-between; min-height: 60px; border-bottom: 1px solid var(--line); }
.view-title { font-size: 19px; font-weight: 660; letter-spacing: -.01em; }
.view-sub { margin-top: 1px; color: var(--muted); font-size: 13px; min-height: 1.2em; }
.view-scroll { flex: 1; min-height: 0; overflow-y: auto; }

.cc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; padding: 20px 24px 28px; }
.cc { min-width: 0; }
.cc-open { display: block; width: 100%; padding: 0; text-align: left; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); overflow: hidden; transition: box-shadow .15s, border-color .15s; }
.cc-open:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.cc.is-wait .cc-open { border-color: var(--warn-line); box-shadow: 0 0 0 2px color-mix(in srgb, var(--warn-line) 60%, transparent); }
.cc-thumb { position: relative; aspect-ratio: 16 / 10; background: var(--screen-bg); }
.cc-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cc-ph { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: #A8A196; font-size: 13px; }
.cc-ph .btn { background: transparent; color: #ECE8E0; border-color: #5A544B; }
.cc-ph .btn:hover { background: rgb(255 255 255 / .08); }
.cc-foot { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.cc-text { display: flex; flex-direction: column; min-width: 0; }
.cc-name { font-weight: 630; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cc-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cc-sub.st-working { color: var(--accent-strong); }
.cc-sub.st-waiting { color: var(--wait-ink); font-weight: 550; }

.rt-list { list-style: none; margin: 0; padding: 18px 24px 28px; max-width: 1000px; }
.rt { display: grid; grid-template-columns: minmax(0, 1fr) 130px 150px auto; gap: 16px; align-items: center; padding: 14px 16px; margin-bottom: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.rt.is-off { background: transparent; }
.rt.is-off .rt-main { opacity: .6; }
.rt-name { font-weight: 640; overflow-wrap: anywhere; }
.rt-when { font-size: 13px; color: var(--accent-strong); }
.rt-prompt { margin-top: 3px; font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.rt-bot { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13.5px; }
.rt-bot span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rt-next { display: flex; flex-direction: column; font-size: 13.5px; }
.rt-next-label { font-size: 11.5px; color: var(--faint); }
.rt-actions { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.rt-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 56px 16px; color: var(--muted); }
.rt-empty .empty-sub { max-width: 36ch; }

.perms { max-width: 1000px; padding: 4px 24px 32px; }
.perm-title { font-size: 15px; font-weight: 650; }
.perm-sub { margin: 2px 0 10px; color: var(--muted); font-size: 13px; }
.perm-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.perm { display: flex; flex-direction: column; gap: 1px; padding: 9px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.perm-rule { font-weight: 560; overflow-wrap: anywhere; }
.perm-meta { font-size: 12px; color: var(--faint); }

/* ---------- dialogs ---------- */
.dlg { border: 0; padding: 0; border-radius: 20px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; }
.dlg::backdrop { background: rgb(24 16 8 / .5); backdrop-filter: blur(2px); }
.dlg[open] { animation: dlg-in .16s ease-out; }
@keyframes dlg-in { from { opacity: 0; transform: translateY(6px) scale(.985); } }
.dlg-body { padding: 20px 22px 22px; display: flex; flex-direction: column; gap: 15px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin: -4px -8px 0 0; }
.dlg-title { font-size: 18px; font-weight: 660; letter-spacing: -.01em; }
.dlg-text { color: var(--muted); }
.dlg-actions { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.dlg-actions .spacer { flex: 1; }
.dlg-confirm { width: min(420px, calc(100vw - 24px)); }
.bd-top { display: flex; align-items: flex-end; gap: 14px; }
.bd-preview { display: inline-flex; padding-bottom: 0; }
.tpl-block { display: flex; flex-direction: column; gap: 8px; }
.tpl-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; min-height: 32px; border-radius: 99px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 13px; font-weight: 520; }
.chip:hover { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 50%, var(--line-strong)); }
.chip span { font-family: var(--emoji); }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 6px; }
.emoji-btn { height: 38px; border-radius: 10px; border: 1px solid transparent; background: var(--surface-2); font-size: 20px; font-family: var(--emoji); line-height: 1; padding: 0; }
.emoji-btn:hover { border-color: var(--line-strong); }
.emoji-btn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
.emoji-custom { height: 38px !important; min-height: 38px !important; padding: 0 !important; text-align: center; font-size: 18px; font-family: var(--emoji), var(--font); border-style: dashed !important; }
.swatches { display: flex; flex-wrap: wrap; gap: 9px; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 0; padding: 0; display: inline-grid; place-items: center; color: #fff; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .1); }
.swatch svg { opacity: 0; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
.swatch[aria-pressed="true"] svg { opacity: 1; }

/* ---------- login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; overflow: auto; position: fixed; inset: 0; background: var(--bg); }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 16px; padding: 32px 30px 30px; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
.login-lede { color: var(--muted); margin-top: -8px; }

/* ---------- narrow desktop: screen becomes a drawer ---------- */
@media (max-width: 1100px) and (min-width: 701px) {
  :root { --side-w: 264px; }
  #app, #app[data-view="computer"], #app[data-view="routines"] { grid-template-columns: var(--side-w) minmax(0, 1fr); }
  #screen-panel { display: flex !important; position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 92vw); z-index: 40; transform: translateX(102%); visibility: hidden; transition: transform .22s ease, visibility 0s .22s; box-shadow: var(--shadow-lg); }
  #app[data-screen="open"] #screen-panel { transform: none; visibility: visible; transition: transform .22s ease; }
  .head-screen { display: inline-flex; }
  .scr-close { display: inline-grid; }
}

/* ---------- phone ---------- */
@media (max-width: 700px) {
  body { font-size: 15px; }
  #app, #app[data-view="computer"], #app[data-view="routines"] { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); }
  #sidebar, #main, #screen-panel, #app[data-view="computer"] #screen-panel, #app[data-view="routines"] #screen-panel { display: none; }
  #app[data-pane="bots"] #sidebar { display: flex; border-right: 0; }
  #app[data-pane="main"] #main { display: flex; }
  #app[data-pane="screen"] #screen-panel { display: flex; border-left: 0; }
  #tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--bg-side); border-top: 1px solid var(--line); }
  .tab { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; background: transparent; color: var(--muted); font-size: 11.5px; font-weight: 580; }
  .tab.is-active { color: var(--accent-strong); }
  .tab-icon { display: inline-flex; }
  .tab-badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }
  .toasts { bottom: calc(var(--tab-h) + 14px + env(safe-area-inset-bottom)); }

  .bot-row { padding: 11px 10px; }
  .chat-head { padding: 0 6px 0 12px; gap: 10px; }
  .head-title, .head-line .badge { display: none; }
  .pill { padding: 6px; }
  .pill-text { display: none; }
  .stream-wrap { padding: 16px 12px 10px; }
  .bubble { max-width: 92%; }
  .composer { padding: 4px 10px 10px; }
  .composer-input { font-size: 16px; }
  .att-img img { max-width: 200px; }
  .tool-name { width: 92px; }
  .view-head { padding: 12px 16px 10px; }
  .cc-grid { padding: 16px 14px 24px; grid-template-columns: 1fr; }
  .rt-list { padding: 14px 14px 12px; }
  .perms { padding: 4px 14px 24px; }
  .rt { grid-template-columns: minmax(0, 1fr) auto; gap: 10px 12px; }
  .rt-main { grid-column: 1 / -1; }
  .rt-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .rt-next { align-items: flex-end; }
  .scr-stage { margin: 0 12px; }
  .handoff-banner { position: static; margin: 10px 12px 0; box-shadow: none; }
  .scr-head { padding: 0 8px 0 14px; }
  .dlg { width: 100vw; max-width: 100vw; max-height: 100dvh; border-radius: 20px 20px 0 0; margin: auto 0 0; }
  .dlg.dlg-screen { width: 100vw; height: 100dvh; border-radius: 0; margin: 0; } /* .dlg.dlg-screen (desktop width) outranks .dlg, so say it again here */
  .dlg-screen .screen-modal { padding: 4px 10px 12px; min-height: 100%; }
  .scr-stage.is-tall { width: 100%; }
  .dlg-screen .scr-title .avatar { display: none; }
  .dlg-body { padding: 18px 16px 20px; }
  .login-card { padding: 26px 22px; }
}

@media (pointer: coarse) {
  .icon-btn { width: 42px; height: 42px; }
  .btn-sm { min-height: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* Table cells must not inherit .bubble's overflow-wrap:anywhere, or columns squeeze words apart ("Le dg er"); .md table scrolls sideways instead. */
.md th, .md td { overflow-wrap: normal; word-break: normal; min-width: 6ch; }
