:root {
  color-scheme: light;
  --bg: #f6f7f5;
  --panel: #ffffff;
  --raised: #ffffff;
  --hover: #eef0ec;
  --text: #171a18;
  --muted: #667069;
  --line: #e3e6e1;
  --accent: #0f8a73;
  --accent-soft: #e2f3ee;
  --on-accent: #ffffff;
  --user-bg: #0f8a73;
  --user-text: #ffffff;
  --danger: #c8372d;
  --danger-soft: #fbe9e7;
  --code-bg: #f1f3ef;
  --shadow: 0 1px 2px rgb(20 30 25 / 0.06), 0 8px 24px rgb(20 30 25 / 0.08);
  --radius: 16px;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", system-ui, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1110;
  --panel: #161917;
  --raised: #1d211f;
  --hover: #1f2421;
  --text: #ecefeb;
  --muted: #98a19a;
  --line: #2a2f2c;
  --accent: #3fcfae;
  --accent-soft: #15332c;
  --on-accent: #06211a;
  --user-bg: #1d4f43;
  --user-text: #f1fbf8;
  --danger: #ff7a6c;
  --danger-soft: #3a1f1c;
  --code-bg: #0b0d0c;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 10px 30px rgb(0 0 0 / 0.45);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1110;
    --panel: #161917;
    --raised: #1d211f;
    --hover: #1f2421;
    --text: #ecefeb;
    --muted: #98a19a;
    --line: #2a2f2c;
    --accent: #3fcfae;
    --accent-soft: #15332c;
    --on-accent: #06211a;
    --user-bg: #1d4f43;
    --user-text: #f1fbf8;
    --danger: #ff7a6c;
    --danger-soft: #3a1f1c;
    --code-bg: #0b0d0c;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 10px 30px rgb(0 0 0 / 0.45);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; width: 100%; overflow: hidden; overscroll-behavior: none; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); position: fixed; top: var(--vvt, 0px); left: 0; width: 100%; height: var(--vvh, 100%); overflow: hidden; overscroll-behavior: none; -webkit-font-smoothing: antialiased; touch-action: manipulation; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { opacity: 0.5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }

.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* buttons */
.primary, .ghost, .danger { border-radius: 12px; padding: 10px 16px; font-weight: 600; transition: transform 0.08s, background 0.15s, opacity 0.15s; }
.primary { background: var(--accent); color: var(--on-accent); }
.primary:hover { filter: brightness(1.06); }
.ghost { border: 1px solid var(--line); color: var(--text); }
.ghost:hover { background: var(--hover); }
.danger { background: var(--danger-soft); color: var(--danger); }
.wide { width: 100%; }
.primary:active, .ghost:active, .danger:active { transform: scale(0.97); }
.icon-btn { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: var(--muted); transition: background 0.15s, color 0.15s; }
.icon-btn:hover { background: var(--hover); color: var(--text); }

input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); transition: border-color 0.15s, box-shadow 0.15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }

/* brand + avatars */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.brand.big { font-size: 26px; justify-content: center; }
.logo { width: 34px; height: 34px; border-radius: 11px; object-fit: cover; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.15); }
.sticker { display: block; height: auto; max-width: 100%; user-select: none; -webkit-user-drag: none; }
.sticker.hero { width: 190px; margin: -6px auto 0; filter: drop-shadow(0 8px 18px rgb(0 0 0 / 0.18)); animation: float 5s ease-in-out infinite; }
.splash { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: var(--bg); transition: opacity 0.25s; }
.splash.gone { opacity: 0; pointer-events: none; }
.splash .sticker { width: 120px; animation: pulse-soft 1.4s ease-in-out infinite; }
.empty .sticker { width: 170px; filter: drop-shadow(0 8px 18px rgb(0 0 0 / 0.18)); animation: float 5s ease-in-out infinite; }
.quiet .sticker { width: 150px; margin: 0 auto 10px; opacity: 0.95; }
.pawprint { display: inline-block; width: 18px; height: 18px; background: url("/assets/paw.svg") center/contain no-repeat; vertical-align: -3px; }
.avatar { width: 38px; height: 38px; border-radius: 12px; flex: none; display: grid; place-items: center; font-weight: 700; font-size: 16px; color: #fff; text-transform: uppercase; background: linear-gradient(145deg, hsl(var(--h, 160) 62% 50%), hsl(calc(var(--h, 160) + 24) 58% 38%)); box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.12); }
.avatar.sm { width: 32px; height: 32px; border-radius: 10px; font-size: 14px; }
.avatar.lg { width: 96px; height: 96px; border-radius: 28px; font-size: 40px; }

/* login */
.login { height: 100%; display: grid; place-items: center; padding: 16px; background: radial-gradient(900px 500px at 50% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent), var(--bg); }
.login-card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow); text-align: center; }
.login-card p { margin: 0; }
.login-card input { text-align: center; }

/* app shell */
.app { display: flex; height: 100%; }
.sidebar { width: var(--sidebar-w, 280px); flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 10px 10px; gap: 6px; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 10px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; font-weight: 600; text-align: left; width: 100%; color: var(--text); }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item .badge { margin-left: auto; }
.badge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--accent); color: var(--on-accent); font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; }
.side-label { padding: 14px 12px 4px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.bot-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; display: grid; gap: 2px; align-content: start; }
.bot-list li { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 12px; cursor: pointer; position: relative; transition: background 0.12s; }
.bot-list li:hover { background: var(--hover); }
.bot-list li.active { background: var(--accent-soft); }
.bot-list .meta { min-width: 0; display: grid; }
.bot-list .meta strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bot-list .meta small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.bot-list .state { margin-left: auto; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.bot-list li.unread .state { background: var(--accent); }
.bot-list li.running .state { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.side-foot { display: flex; gap: 4px; padding-top: 8px; border-top: 1px solid var(--line); }
.foot-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--muted); }
.foot-btn:hover { background: var(--hover); color: var(--text); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; background: var(--bg); }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: color-mix(in srgb, var(--panel) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); min-height: 60px; }
.who { flex: 1; min-width: 0; }
.who-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu { display: none; }

/* model controls */
.controls { display: flex; align-items: center; gap: 8px; padding: 8px 14px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); background: var(--panel); }
.controls::-webkit-scrollbar { display: none; }
.controls select { width: auto; flex: none; padding: 6px 28px 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; background-color: var(--bg); }
.controls .params { display: contents; }
.controls label { display: inline-flex; align-items: center; gap: 6px; flex: none; padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--text); background: var(--bg); cursor: pointer; }
.controls input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); padding: 0; }
.controls .hint { margin-left: 4px; white-space: nowrap; flex: none; max-width: 40ch; overflow: hidden; text-overflow: ellipsis; }

/* messages */
.scroller { flex: 1; overflow-y: auto; scroll-behavior: smooth; overscroll-behavior: contain; }
.messages { max-width: var(--col-w, 820px); margin: 0 auto; padding: 24px 16px 12px; display: flex; flex-direction: column; gap: 22px; min-height: 100%; }
.msg { display: flex; gap: 12px; max-width: 100%; animation: rise 0.22s ease-out both; }
.msg.user { justify-content: flex-end; }
.msg .body { min-width: 0; max-width: min(680px, 100%); }
.msg.user .body { background: var(--user-bg); color: var(--user-text); padding: 10px 15px; border-radius: 20px 20px 6px 20px; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 1px 2px rgb(0 0 0 / 0.1); }
.msg.assistant .body { flex: 1; padding-top: 4px; }
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0.55em 0; }
.md h1, .md h2, .md h3 { margin: 1em 0 0.4em; line-height: 1.25; letter-spacing: -0.01em; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.2em; } .md h3 { font-size: 1.05em; }
.md ul, .md ol { padding-left: 1.4em; margin: 0.5em 0; }
.md li { margin: 0.2em 0; }
.md a { color: var(--accent); text-underline-offset: 3px; }
.md blockquote { margin: 0.7em 0; padding: 2px 14px; border-left: 3px solid var(--line); color: var(--muted); }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; }
.md :not(pre) > code { background: var(--code-bg); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; font-size: 0.88em; }
.codeblock { position: relative; margin: 0.7em 0; border: 1px solid var(--line); border-radius: 14px; background: var(--code-bg); overflow: hidden; }
.codeblock .bar { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 4px 14px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.codeblock pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.codeblock code { font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; font-size: 13px; line-height: 1.55; }
.mini-btn { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 8px; color: var(--muted); font-size: 12px; font-weight: 600; }
.mini-btn:hover { background: var(--hover); color: var(--text); }
.mini-btn .ic { width: 15px; height: 15px; }
.actions { display: flex; gap: 2px; margin-top: 6px; opacity: 0; transition: opacity 0.15s; }
.msg.assistant:hover .actions, .msg.assistant:focus-within .actions, .msg.assistant.last .actions { opacity: 1; }

/* tools, helpers, files */
.chip { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; margin: 3px 6px 3px 0; padding: 5px 11px 5px 9px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.chip .ic { width: 15px; height: 15px; }
.chip.done .ic { color: var(--accent); }
.chip.error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
details.tool { display: inline-block; max-width: 100%; vertical-align: top; }
details.tool > summary { list-style: none; cursor: pointer; display: inline-flex; }
details.tool > summary::-webkit-details-marker { display: none; }
details.tool[open] { display: block; }
details.tool .detail { margin: 4px 0 6px; padding: 10px 12px; border-radius: 12px; background: var(--code-bg); border: 1px solid var(--line); font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-all; color: var(--muted); }
.spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; flex: none; }
.helper { margin: 6px 0; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 12px; background: var(--panel); }
.helper.error { border-left-color: var(--danger); }
.helper > summary { cursor: pointer; padding: 8px 12px; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); list-style: none; }
.helper > summary::-webkit-details-marker { display: none; }
.helper ul { margin: 0; padding: 0 14px 6px 32px; font-size: 12px; color: var(--muted); }
.helper pre { margin: 0; padding: 4px 14px 12px; white-space: pre-wrap; font: inherit; font-size: 13px; }
.file { display: inline-flex; align-items: center; gap: 12px; margin: 6px 0; padding: 10px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); text-decoration: none; transition: border-color 0.15s, transform 0.1s; }
.file:hover { border-color: var(--accent); }
.file:active { transform: scale(0.98); }
.file .ic { color: var(--accent); }
.file span { display: grid; line-height: 1.25; }
.file small { color: var(--muted); }
.file-caption { margin: 6px 0 2px; }
.status { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.err { color: var(--danger); background: var(--danger-soft); padding: 10px 14px; border-radius: 12px; font-size: 14px; margin: 8px 0 0; }
.typing { display: inline-flex; align-items: center; gap: 8px; padding: 6px 2px; color: var(--muted); font-size: 13px; }
.typing img { width: 30px; height: auto; animation: tilt 1.1s ease-in-out infinite; transform-origin: 50% 90%; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); opacity: 0.5; animation: bounce 1.1s infinite ease-in-out; }
.typing i:nth-child(3) { animation-delay: 0.15s; }
.typing i:nth-child(4) { animation-delay: 0.3s; }

/* empty */
.empty { margin: auto; text-align: center; color: var(--muted); display: grid; gap: 10px; justify-items: center; padding: 40px 16px; }
.empty h2 { margin: 6px 0 0; color: var(--text); font-size: 20px; }
.empty p { margin: 0; max-width: 34ch; }

/* composer */
.composer { padding: 6px 14px calc(12px + env(safe-area-inset-bottom)); }
.composer-box { max-width: var(--col-w, 820px); margin: 0 auto; display: flex; align-items: flex-end; gap: 4px; padding: 6px 6px 6px 8px; border: 1px solid var(--line); border-radius: 22px; background: var(--raised); box-shadow: var(--shadow); transition: border-color 0.15s; }
.composer-box:focus-within { border-color: var(--accent); }
.composer textarea { border: 0; background: none; box-shadow: none; resize: none; max-height: 200px; padding: 9px 6px; line-height: 1.45; }
.composer textarea:focus { box-shadow: none; }
.send { width: 40px; height: 40px; border-radius: 14px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; flex: none; transition: transform 0.08s, filter 0.15s; }
.send:hover { filter: brightness(1.08); }
.send:active { transform: scale(0.92); }
.send.stop { background: var(--danger); color: #fff; }
.to-bottom { position: absolute; right: 18px; bottom: 96px; width: 40px; height: 40px; border-radius: 50%; background: var(--raised); border: 1px solid var(--line); box-shadow: var(--shadow); display: grid; place-items: center; z-index: 5; }

/* today */
.today-body { flex: 1; overflow-y: auto; padding: 20px 16px 40px; display: grid; gap: 26px; align-content: start; max-width: var(--col-w, 820px); width: 100%; margin: 0 auto; }
.today h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card-item { text-align: left; display: flex; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); width: 100%; transition: border-color 0.15s, transform 0.1s, box-shadow 0.15s; }
.card-item:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); box-shadow: var(--shadow); }
.card-item:active { transform: scale(0.99); }
.card-item .col { min-width: 0; display: grid; gap: 3px; flex: 1; }
.card-item .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card-item .top small { color: var(--muted); flex: none; }
.card-item p { margin: 0; color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card-item.running { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.card-item.failed p { color: var(--danger); }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--accent); }
.quiet { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 60px 0; }

/* dialogs */
dialog { border: 0; padding: 0; background: transparent; width: min(480px, 94vw); max-height: 92dvh; margin: auto; color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / 0.5); backdrop-filter: blur(3px); }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 20px; display: grid; gap: 14px; max-height: 92dvh; overflow-y: auto; box-shadow: var(--shadow); }
.sheet h2 { margin: 0; font-size: 19px; }
.sheet-grip { display: none; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: -8px auto 0; }
.row { display: flex; gap: 10px; justify-content: space-between; }
.row > button { flex: 1; }
.danger-zone { padding-top: 12px; border-top: 1px solid var(--line); }
.routines h3 { margin: 4px 0 8px; font-size: 14px; }
.routines ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.routines li { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 4px; font-size: 13px; background: var(--bg); }
.routines li.off { opacity: 0.55; }
.routines li .meta { color: var(--muted); }
.routines li .actions { display: flex; gap: 6px; opacity: 1; margin: 4px 0 0; flex-wrap: wrap; }
.routines li .actions button { padding: 4px 10px; font-size: 12px; border-radius: 8px; }
.routine-new { display: grid; gap: 8px; margin-top: 10px; }
.devices { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.devices li { display: flex; justify-content: space-between; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 13px; }
.devices li small { color: var(--muted); display: block; }
.devices .name { overflow-wrap: anywhere; }

/* toast + backdrop */
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: min(420px, 92vw); padding: 11px 16px; border-radius: 14px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); z-index: 60; font-size: 14px; animation: rise 0.2s ease-out; }
.backdrop { position: fixed; inset: 0; z-index: 19; background: rgb(0 0 0 / 0.5); animation: fade 0.2s; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.35; transform: scale(0.8); } }
@keyframes float { 50% { transform: translateY(-6px); } }
@keyframes pulse-soft { 50% { transform: scale(0.94); opacity: 0.8; } }
@keyframes tilt { 0%, 100% { transform: rotate(-7deg); } 50% { transform: rotate(7deg) translateY(-2px); } }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); } 40% { transform: translateY(-5px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

@media (max-width: 760px) {
  .menu { display: grid; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; width: min(310px, 86vw); transform: translateX(-102%); transition: transform 0.22s ease; box-shadow: var(--shadow); padding-top: calc(14px + env(safe-area-inset-top)); }
  .sidebar.open { transform: none; }
  .messages { padding: 16px 12px 8px; gap: 18px; }
  .controls .hint { display: none; }
  .composer { padding: 4px 10px calc(10px + env(safe-area-inset-bottom)); }
  .to-bottom { bottom: 84px; right: 12px; }
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; }
  .sheet { border-radius: 24px 24px 0 0; border-bottom: 0; padding-bottom: calc(20px + env(safe-area-inset-bottom)); animation: rise 0.25s ease-out; }
  .sheet-grip { display: block; }
  .cards { grid-template-columns: 1fr; }
}

.attachments { max-width: var(--col-w, 820px); margin: 0 auto 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.attachments .chip { margin: 0; color: var(--text); }
.chat.dropping::after { content: "Отпусти, чтобы загрузить файл"; position: absolute; inset: 10px; z-index: 30; display: grid; place-items: center; border: 2px dashed var(--accent); border-radius: 22px; background: color-mix(in srgb, var(--bg) 82%, transparent); color: var(--accent); font-weight: 700; font-size: 18px; }

/* media in the chat */
.attachment { margin: 6px 0; display: grid; gap: 6px; justify-items: start; max-width: 100%; }
.attachment p { margin: 0; }
.media { display: block; max-width: min(100%, 520px); border-radius: 14px; border: 1px solid var(--line); background: var(--code-bg); }
.media.image { max-height: 420px; width: auto; height: auto; cursor: zoom-in; object-fit: contain; }
.media.video { width: min(100%, 520px); max-height: 420px; background: #000; }
.media.audio { width: min(100%, 380px); height: 44px; border: 0; background: none; }
.file.slim { padding: 6px 12px; border-radius: 10px; font-size: 13px; margin: 0; }
.msg.user .body .attachment { margin-top: 8px; }
.msg.user .body .file { color: var(--text); }
.textpreview { width: min(100%, 560px); border: 1px solid var(--line); border-radius: 12px; background: var(--code-bg); }
.textpreview summary { cursor: pointer; padding: 8px 12px; font-size: 13px; color: var(--muted); }
.textpreview pre { margin: 0; padding: 4px 14px 12px; max-height: 320px; overflow: auto; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; color: var(--text); }
.chip .thumb { width: 22px; height: 22px; border-radius: 6px; object-fit: cover; }
.lightbox { position: fixed; inset: 0; z-index: 80; background: rgb(0 0 0 / 0.88); display: grid; place-items: center; padding: 16px 16px 64px; animation: fade 0.15s; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.lightbox-bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; align-items: center; justify-content: center; padding: 12px; color: #fff; background: linear-gradient(transparent, rgb(0 0 0 / 0.6)); }
.lightbox-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.lightbox-bar .mini-btn { color: #fff; background: rgb(255 255 255 / 0.14); padding: 8px 14px; font-size: 14px; }

/* search palette */
kbd { margin-left: auto; font: 600 11px/1 inherit; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; }
dialog.palette { width: min(640px, 94vw); margin-top: 8vh; }
.palette .sheet { padding: 14px; gap: 10px; max-height: 80dvh; }
.search-row { display: flex; align-items: center; gap: 10px; padding: 0 6px; color: var(--muted); }
.search-row input { border: 0; background: none; box-shadow: none; font-size: 17px; padding: 8px 0; color: var(--text); }
.search-row input:focus { box-shadow: none; }
.check { display: flex; align-items: center; gap: 8px; flex-direction: row; font-size: 13px; padding: 0 6px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.results { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; overflow-y: auto; }
.results li { display: flex; gap: 12px; padding: 10px; border-radius: 12px; cursor: pointer; }
.results li:hover, .results li.active { background: var(--hover); }
.results .col { min-width: 0; display: grid; gap: 2px; flex: 1; }
.results .top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.results .top small { color: var(--muted); }
.results .snippet { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.results mark { background: color-mix(in srgb, var(--accent) 28%, transparent); color: var(--text); border-radius: 4px; padding: 0 2px; }
.search-empty { text-align: center; color: var(--muted); padding: 24px 8px; display: grid; gap: 8px; justify-items: center; }
.search-empty .sticker { width: 110px; }
.msg.flash .body { animation: flash 2s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 3px transparent; } }
.older { display: block; margin: 0 auto 8px; }

.integrations { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.integrations h3 { margin: 0; font-size: 14px; }
.integrations .check { padding: 0; }
#f-composio-box { display: grid; gap: 8px; }
.conn { display: flex; flex-wrap: wrap; gap: 6px; }
.conn .chip { margin: 0; color: var(--text); }
.conn .chip button { margin-left: 4px; color: var(--accent); font-weight: 700; font-size: 12px; }
.conn .chip.ok .ic { color: var(--accent); }

/* voice dictation */
.mic.listening { color: #fff; background: var(--danger); animation: ring 1.4s ease-out infinite; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 55%, transparent); } 100% { box-shadow: 0 0 0 12px transparent; } }
.listening-note { max-width: var(--col-w, 820px); margin: 0 auto 6px; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.listening-note img { height: 44px; width: auto; }

/* dogs in the interface */
.typing img { width: auto; height: 38px; animation: none; transform: none; }
.chip-dog { width: 22px; height: 22px; object-fit: contain; margin: -3px 0 -3px -4px; }
.err { display: flex; align-items: center; gap: 12px; }
.err img { height: 44px; width: auto; flex: none; }
.celebrate { position: fixed; right: 18px; bottom: 96px; width: 120px; height: auto; z-index: 70; pointer-events: none; animation: pop 2.6s ease-out forwards; }
@keyframes pop { 0% { transform: translateY(30px) scale(0.6); opacity: 0; } 12% { transform: none; opacity: 1; } 80% { opacity: 1; } 100% { transform: translateY(-10px); opacity: 0; } }
.logo.sticker-logo { object-fit: contain; box-shadow: none; background: none; }
.splash .sticker { width: 150px; animation: none; }
.quiet .sticker { width: 160px; }
.empty .sticker { width: 170px; }
.search-empty .sticker { width: 120px; }

.search-row input::-webkit-search-cancel-button { display: none; }

/* settings */
.settings { gap: 12px; }
.block { display: grid; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--bg); }
.block h3 { margin: 0; font-size: 15px; }
.why { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.switch { display: flex; align-items: flex-start; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); cursor: pointer; color: var(--text); font-size: 14px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { flex: none; width: 38px; height: 22px; margin-top: 2px; border-radius: 11px; background: var(--line); position: relative; transition: background 0.18s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / 0.3); transition: transform 0.18s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .track { opacity: 0.45; }
.switch .text { display: grid; gap: 2px; }
.switch small { color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.services { display: flex; flex-wrap: wrap; gap: 8px; }
.service { display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); font-size: 13px; font-weight: 600; color: var(--text); }
.service.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.service .state { font-weight: 500; font-size: 12px; color: var(--muted); }
.service.on .state { color: var(--accent); }
.service .link { color: var(--accent); font-weight: 700; font-size: 12px; text-decoration: underline; text-underline-offset: 3px; }
.when { display: flex; gap: 8px; flex-wrap: wrap; }
.when select, .when input { width: auto; flex: 1 1 130px; }
.routines li { background: var(--panel); }

.typing { padding: 10px 2px; }
.typing img { display: none; }

/* iPhone: nothing may pan the page sideways, and focus must not zoom */
.app, .main, .scroller, .messages, .today-body { max-width: 100%; }
.main, .today { overflow: hidden; }
.scroller, .today-body { overflow-x: hidden; }
.messages > *, .msg, .msg .body, .md, .attachment { min-width: 0; max-width: 100%; }
.md img, .md video, .md table { max-width: 100%; }
.sidebar:not(.open) { visibility: hidden; }
@media (min-width: 761px) { .sidebar:not(.open) { visibility: visible; } }
@media (max-width: 760px) {
  .sidebar { transition: transform 0.22s ease, visibility 0s linear 0.22s; }
  .sidebar.open { transition: transform 0.22s ease; visibility: visible; }
  dialog { width: 100%; max-width: 100%; }
}
@media (pointer: coarse) {
  input, select, textarea { font-size: 16px; }
  .controls select { font-size: 16px; }
}

/* settings: a full screen of its own on phones, one scroll area, nothing sideways */
dialog { overflow: hidden; }
.sheet > *, .block > * { min-width: 0; }
.sheet { overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.bar { position: sticky; bottom: -20px; background: var(--panel); padding: 10px 0 4px; margin-bottom: -4px; z-index: 2; }
@media (max-width: 760px) {
  dialog#bot-dialog, dialog#devices-dialog { position: fixed; inset: 0; width: 100%; max-width: 100%; height: 100%; max-height: 100%; margin: 0; }
  dialog#bot-dialog .sheet, dialog#devices-dialog .sheet { height: 100%; max-height: 100%; border-radius: 0; border: 0; overflow-y: auto; touch-action: pan-y; padding: calc(16px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); align-content: start; }
  dialog#bot-dialog .sheet-grip, dialog#devices-dialog .sheet-grip { display: none; }
  .bar { bottom: calc(-24px - env(safe-area-inset-bottom)); }
  .block { padding: 12px; }
  textarea, input, select { max-width: 100%; }
}

/* iOS: the keyboard resizes the visual viewport, not the layout one; --vvh/--vvt come from app.js */
.switch { position: relative; }
.switch input { width: 1px; height: 1px; padding: 0; border: 0; left: 0; top: 0; }
.keyboard .composer { padding-bottom: 8px; }
.keyboard .toast { bottom: 24px; }
@media (max-width: 760px) {
  dialog#bot-dialog, dialog#devices-dialog { top: var(--vvt, 0px); height: var(--vvh, 100%); max-height: var(--vvh, 100%); }
  dialog#bot-dialog .sheet, dialog#devices-dialog .sheet { scroll-padding-bottom: 96px; }
  .keyboard dialog#bot-dialog .sheet { padding-bottom: 16px; }
}

/* resizable panels (desktop): drag the edge, double-click to reset */
.resizer { display: none; }
.composer { position: relative; }
.col-grip, .composer-grip { display: none; }
@media (min-width: 761px) and (pointer: fine) {
  .resizer { display: block; position: relative; flex: none; width: 0; z-index: 8; }
  .resizer::before { content: ""; position: absolute; top: 0; bottom: 0; left: -4px; width: 9px; cursor: col-resize; }
  .resizer::after { content: ""; position: absolute; top: 0; bottom: 0; left: -1px; width: 2px; background: transparent; transition: background 0.15s; pointer-events: none; }
  .resizer:hover::after, .resizer.dragging::after { background: var(--accent); }
  .col-grip { display: block; position: absolute; top: 50%; width: 10px; height: 34px; margin-top: -17px; border-radius: 5px; background: var(--line); cursor: ew-resize; opacity: 0; transition: opacity 0.15s, background 0.15s; touch-action: none; }
  .composer:hover .col-grip, .col-grip.dragging { opacity: 1; }
  .col-grip:hover, .col-grip.dragging { background: var(--accent); }
  .composer-grip { display: block; position: absolute; left: 50%; top: -3px; width: 56px; height: 8px; margin-left: -28px; border-radius: 4px; background: var(--line); cursor: ns-resize; opacity: 0; transition: opacity 0.15s, background 0.15s; touch-action: none; z-index: 3; }
  .composer:hover .composer-grip, .composer-grip.dragging { opacity: 1; }
  .composer-grip:hover, .composer-grip.dragging { background: var(--accent); }
  .composer textarea { min-height: var(--composer-min, 0px); max-height: 60vh; }
}
body.resizing { cursor: col-resize; user-select: none; -webkit-user-select: none; }
body.resizing.vertical { cursor: ns-resize; }

/* live status, offline banner, menu, activity log, poses */
.live { display: inline-flex; align-items: center; gap: 10px; padding: 8px 2px; color: var(--muted); font-size: 14px; }
.live .typing { padding: 0; }
.live .elapsed { font-variant-numeric: tabular-nums; opacity: 0.8; }
.offline { position: fixed; left: 50%; top: 10px; transform: translateX(-50%); z-index: 90; display: flex; align-items: center; gap: 10px; max-width: min(520px, 94vw); padding: 10px 14px; border-radius: 14px; background: var(--text); color: var(--bg); font-size: 13.5px; box-shadow: var(--shadow); }
.offline .spin { border-color: color-mix(in srgb, var(--bg) 40%, transparent); border-top-color: var(--bg); }
.menu-pop { position: fixed; z-index: 70; min-width: 230px; padding: 6px; border: 1px solid var(--line); border-radius: 14px; background: var(--raised); box-shadow: var(--shadow); display: grid; }
.menu-pop button { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; font-size: 14.5px; text-align: left; color: var(--text); }
.menu-pop button:hover { background: var(--hover); }
.activity { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; overflow-y: auto; max-height: 60dvh; }
.activity .day { margin: 10px 0 2px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.activity li.row-item { display: grid; gap: 2px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); font-size: 13.5px; }
.activity .top { display: flex; justify-content: space-between; gap: 10px; }
.activity .top small { color: var(--muted); flex: none; }
.activity .detail { color: var(--muted); font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.activity .bad { color: var(--danger); }
.poses { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.pose { display: grid; place-items: center; aspect-ratio: 1; border: 2px solid var(--line); border-radius: 16px; background: var(--panel); padding: 4px; }
.pose img { max-width: 100%; max-height: 100%; object-fit: contain; }
.pose.on { border-color: var(--accent); background: var(--accent-soft); }
.avatar.pose { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--line); padding: 2px; }
.avatar.pose img { width: 100%; height: 100%; object-fit: contain; }
.install-hint { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); font-size: 14px; }
.install-hint button { margin-left: auto; color: var(--muted); }

/* touch: targets of at least 44 px */
@media (pointer: coarse) {
  .icon-btn, .foot-btn { width: 44px; height: 44px; }
  .mini-btn { min-height: 40px; padding: 8px 12px; }
  .nav-item { min-height: 48px; }
  .bot-list li { min-height: 56px; }
  .send { width: 46px; height: 46px; }
  .switch { padding: 12px; }
  .service button, .service .link { min-height: 32px; }
  .menu-pop button { min-height: 48px; }
  .chip button { min-width: 32px; min-height: 32px; }
  .controls select { min-height: 40px; }
  .actions { opacity: 1; }
}

.msg.user { flex-direction: column; align-items: flex-end; gap: 2px; }
.msg.user .actions.mine { margin-top: 0; opacity: 0; }
.msg.user:hover .actions.mine, .msg.user:focus-within .actions.mine { opacity: 1; }
@media (pointer: coarse) { .msg.user .actions.mine { opacity: 1; } }

/* seamless chat switching: one block per chat, the others stay hidden */
.thread { display: flex; flex-direction: column; gap: 22px; }
.thread[hidden] { display: none; }
.messages { gap: 0; }
.skeleton { display: grid; gap: 12px; padding: 8px 0; }
.skeleton span { height: 18px; border-radius: 9px; background: linear-gradient(90deg, var(--line), color-mix(in srgb, var(--line) 40%, transparent), var(--line)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.messages > .thread { flex: 1 1 auto; }

/* the dispatcher on the Today screen */
.today-rest { display: grid; gap: 26px; align-content: start; }
.hub { display: grid; gap: 10px; padding: 16px; border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: 20px; background: linear-gradient(180deg, var(--accent-soft), var(--panel)); box-shadow: var(--shadow); }
.hub-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hub-title { font-weight: 700; font-size: 17px; }
.hub-form { display: flex; gap: 8px; align-items: flex-end; }
.hub-form textarea { flex: 1; border-radius: 14px; background: var(--panel); resize: none; max-height: 40dvh; min-height: 52px; }
.hub-thread { display: grid; gap: 14px; }
.hub-thread:empty { display: none; }
.hub-thread .msg { max-width: 100%; }
.hub-thread .msg.user .body { max-width: 100%; }
.question { display: grid; gap: 10px; margin: 8px 0; padding: 12px 14px; border: 1px solid var(--accent); border-radius: 14px; background: var(--accent-soft); }
.question .q { font-weight: 600; }
.question .by { font-size: 12px; color: var(--muted); }
.question .options { display: flex; flex-wrap: wrap; gap: 8px; }
.question .options button { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--accent); color: var(--accent); font-weight: 600; background: var(--panel); }
.question .answer { display: flex; gap: 8px; }
.question .answer input { flex: 1; }
.question.done { border-color: var(--line); background: var(--bg); }
.question.done .q { color: var(--muted); font-weight: 500; }

.splash { flex-direction: column; gap: 14px; text-align: center; padding: 20px; }
.splash { display: flex; align-items: center; justify-content: center; }
.splash-note { margin: 0; max-width: 34ch; color: var(--muted); font-size: 14px; }

.tunnel-url { display: flex; align-items: center; gap: 8px; }
.tunnel-url a { flex: 1; min-width: 0; overflow-wrap: anywhere; color: var(--accent); font-size: 14px; }
