/* Targets Safari 15: no CSS nesting, color-mix(), container queries, @property or :has(). */
:root {
  --bg: #f7f6f2;
  --panel: #ffffff;
  --panel-2: #f0eee8;
  --hover: #ebe8e0;
  --text: #22211e;
  --text-2: #4a4740;
  --muted: #8a867c;
  --border: #e4e0d6;
  --accent: #c2653c;
  --accent-soft: #f6e4da;
  --accent-text: #ffffff;
  --user-bg: #ece7dc;
  --code-bg: #f3f1ec;
  --ok: #3d7f4f;
  --warn: #a8741a;
  --danger: #b5432f;
  --danger-bg: #fbecea;
  --perm-bg: #fdf6ea;
  --shadow: 0 8px 30px rgba(40, 30, 10, 0.12);
  --tk-k: #a2410f;
  --tk-s: #3d7f4f;
  --tk-c: #9a958a;
  --tk-n: #1f6aa5;
  --tk-f: #6b4ab0;
  --app-h: 100vh;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18;
    --panel: #252421;
    --panel-2: #2d2c28;
    --hover: #34322e;
    --text: #eceae4;
    --text-2: #c9c5bb;
    --muted: #9a958a;
    --border: #383631;
    --accent: #db7c52;
    --accent-soft: #3d2b21;
    --accent-text: #1b1a18;
    --user-bg: #34322d;
    --code-bg: #22211e;
    --ok: #7dbb8c;
    --warn: #d9a54d;
    --danger: #e57b6c;
    --danger-bg: #3b2523;
    --perm-bg: #33291b;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    --tk-k: #f0a070;
    --tk-s: #9ccc8a;
    --tk-c: #7d796f;
    --tk-n: #7fb6e8;
    --tk-f: #c8a6f5;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}
/* Pin the body so iOS does not scroll the whole page when the keyboard opens. */
body { position: fixed; top: 0; right: 0; bottom: 0; left: 0; overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button { -webkit-appearance: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }

/* Icons */
.ic { width: 20px; height: 20px; display: inline-block; vertical-align: middle; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-text { display: inline-flex; align-items: center; }
.icon-text .ic { width: 17px; height: 17px; margin-right: 6px; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  color: var(--text);
  line-height: 1.3;
}
.btn:active { background: var(--hover); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.small { padding: 6px 10px; font-size: 14px; border-radius: 9px; }
.btn[disabled] { opacity: 0.45; }
.icon-btn {
  border: 0;
  background: transparent;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  padding: 0;
}
.icon-btn .ic { width: 22px; height: 22px; }
.icon-btn.small { width: 34px; height: 34px; }
.icon-btn.small .ic { width: 19px; height: 19px; }
.icon-btn:active { background: var(--hover); }

/* Login */
.login { position: absolute; top: 0; right: 0; bottom: 0; left: 0; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; align-items: stretch; text-align: center; }
.login-card > * + * { margin-top: 12px; }
.login-logo { width: 64px; height: 64px; border-radius: 16px; align-self: center; }
.login-card h1 { margin-top: 16px; margin-bottom: 0; font-size: 24px; }
.login-card p.muted { margin-top: 2px; margin-bottom: 14px; }
.login-card input { padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); outline: none; }
.login-card input:focus { border-color: var(--accent); }
.login-card .btn { padding: 12px; }

/* Shell */
.app { position: absolute; left: 0; right: 0; top: 0; height: var(--app-h); display: flex; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; position: relative; }
.topbar {
  display: flex;
  align-items: center;
  padding: 6px 8px;
  padding-top: calc(6px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex: none;
  min-height: 52px;
}
.title-wrap { flex: 1; min-width: 0; padding: 0 6px; cursor: pointer; }
.chat-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.3; }
.chat-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.3; }
.chat-sub .live { color: var(--ok); }
.chat-sub .off { color: var(--danger); }
.ctx { position: relative; width: 34px; height: 34px; flex: none; display: flex; align-items: center; justify-content: center; }
.ctx svg { position: absolute; top: 0; left: 0; width: 34px; height: 34px; transform: rotate(-90deg); }
.ctx circle { fill: none; stroke-width: 3; }
.ctx .ctx-bg { stroke: var(--border); }
.ctx .ctx-fg { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: 94.25; stroke-dashoffset: 94.25; transition: stroke-dashoffset 0.4s; }
.ctx.high .ctx-fg { stroke: var(--danger); }
.ctx span { font-size: 9.5px; color: var(--muted); font-weight: 600; }

.banner { padding: 7px 14px; font-size: 13px; background: var(--perm-bg); color: var(--warn); border-bottom: 1px solid var(--border); flex: none; text-align: center; }
.banner.bad { background: var(--danger-bg); color: var(--danger); }

/* Drawer */
.drawer {
  width: 300px;
  flex: none;
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.drawer-head { display: flex; align-items: center; padding: 12px 12px 6px 16px; }
.brand-logo { width: 26px; height: 26px; border-radius: 7px; margin-right: 10px; }
.brand { font-weight: 700; flex: 1; }
.seg { display: flex; margin: 6px 12px 0; background: var(--panel-2); border-radius: 10px; padding: 3px; }
.seg-btn { flex: 1; border: 0; background: transparent; padding: 6px; border-radius: 8px; color: var(--muted); cursor: pointer; font-size: 14px; }
.seg-btn.active { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); }
.tab-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 12px; }
.drawer-tools { display: flex; }
.search { flex: 1; min-width: 0; display: flex; align-items: center; background: var(--panel-2); border-radius: 10px; padding: 0 9px; margin-right: 8px; color: var(--muted); }
.search .ic { width: 16px; height: 16px; }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 8px 6px; outline: none; font-size: 15px; -webkit-appearance: none; }
.drawer-tools .btn { padding: 7px 11px; font-size: 14px; }
.drawer-foot { padding: 6px 10px; border-top: 1px solid var(--border); }
.scrim { display: none; }
@media (max-width: 800px) {
  .drawer {
    position: absolute;
    z-index: 20;
    top: 0;
    bottom: 0;
    left: 0;
    width: 86%;
    max-width: 340px;
    transform: translateX(-102%);
    transition: transform 0.24s ease;
    box-shadow: var(--shadow);
  }
  .app.drawer-open .drawer { transform: none; }
  .app.drawer-open .scrim { display: block; position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 10; background: rgba(0, 0, 0, 0.32); }
}
@media (min-width: 801px) {
  .only-mobile { display: none !important; }
}

.chat-list, .fs-list { list-style: none; margin: 10px 0 0; padding: 0; }
.chat-list li { padding: 9px 4px 9px 10px; border-radius: 10px; cursor: pointer; display: flex; align-items: center; }
.chat-list li + li { margin-top: 2px; }
.chat-list li:active { background: var(--hover); }
.chat-list li.active { background: var(--panel-2); }
.chat-list .ci-icon { color: var(--muted); margin-right: 10px; display: flex; flex: none; }
.chat-list .ci-icon .ic { width: 17px; height: 17px; }
.chat-list .ci-main { flex: 1; min-width: 0; }
.chat-list .ci-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.chat-list .ci-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list .empty-li { color: var(--muted); font-size: 14px; cursor: default; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin: 0 4px 0 8px; flex: none; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; font-size: 13px; color: var(--muted); }
.crumbs button { border: 0; background: transparent; padding: 3px 4px; border-radius: 6px; color: var(--text-2); cursor: pointer; font-size: 13px; }
.crumbs button:active { background: var(--hover); }
.crumbs .sep { padding: 0 1px; }
.fs-actions { display: flex; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.fs-actions .btn { margin: 0 6px 6px 0; }
.fs-list li { display: flex; align-items: center; padding: 9px 6px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 15px; }
.fs-list li:active { background: var(--hover); }
.fs-list .fs-icon { width: 26px; flex: none; color: var(--muted); display: flex; }
.fs-list .fs-icon.dir { color: var(--accent); }
.fs-list .fs-icon .ic { width: 18px; height: 18px; }
.fs-list .fs-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fs-list .fs-meta { font-size: 12px; color: var(--muted); margin-left: 8px; text-align: right; flex: none; }

/* Messages */
.msg-wrap { flex: 1; min-height: 0; position: relative; }
.messages { position: absolute; top: 0; right: 0; bottom: 0; left: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px 14px 24px; }
.messages > * { max-width: 780px; margin-left: auto; margin-right: auto; }
.messages > * + * { margin-top: 14px; }
.fab {
  position: absolute;
  right: 16px;
  bottom: 12px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.load-more { display: block; text-align: center; }
.load-more .btn { font-size: 13px; }

.welcome { text-align: center; padding-top: 12vh; }
.welcome img { width: 56px; height: 56px; border-radius: 14px; }
.welcome h2 { font-size: 20px; margin: 14px 0 4px; }
.welcome p { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.suggests { display: flex; flex-wrap: wrap; justify-content: center; max-width: 520px; margin: 0 auto; }
.suggests button { border: 1px solid var(--border); background: var(--panel); border-radius: 12px; padding: 9px 12px; margin: 4px; font-size: 14px; cursor: pointer; text-align: left; color: var(--text-2); }
.suggests button:active { background: var(--hover); }

.msg-user { display: flex; flex-direction: column; align-items: flex-end; }
.msg-user .bubble { background: var(--user-bg); border-radius: 18px 18px 5px 18px; padding: 9px 14px; max-width: 86%; white-space: pre-wrap; word-wrap: break-word; }
.msg-user .files { display: flex; flex-wrap: wrap; justify-content: flex-end; max-width: 86%; margin-bottom: 6px; }
.msg-user .files > * { margin: 0 0 4px 6px; }
.msg-actions { display: flex; margin-top: 2px; opacity: 0.75; }
.msg-actions button { border: 0; background: transparent; color: var(--muted); padding: 4px 6px; border-radius: 7px; cursor: pointer; display: inline-flex; align-items: center; font-size: 12px; }
.msg-actions button .ic { width: 15px; height: 15px; margin-right: 3px; }
.msg-actions button:active { background: var(--hover); }
.thumb { width: 88px; height: 88px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); display: block; cursor: zoom-in; }
.file-chip { display: inline-flex; align-items: center; font-size: 13px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); max-width: 220px; }
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .ic { width: 15px; height: 15px; margin-right: 5px; color: var(--muted); }

.msg-ai { word-wrap: break-word; }
.msg-ai.sub { margin-left: 18px; font-size: 14px; color: var(--text-2); }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0.6em 0; }
.md h2, .md h3, .md h4, .md h5, .md h6 { margin: 1em 0 0.4em; line-height: 1.35; }
.md h2 { font-size: 1.22em; }
.md h3 { font-size: 1.1em; }
.md h4, .md h5, .md h6 { font-size: 1em; }
.md ul, .md ol { padding-left: 1.4em; margin: 0.5em 0; }
.md li + li { margin-top: 0.2em; }
.md li p { margin: 0.2em 0; }
.md blockquote { margin: 0.6em 0; padding: 0.1em 0.9em; border-left: 3px solid var(--border); color: var(--muted); }
.md code { font-family: var(--mono); font-size: 0.86em; background: var(--code-bg); padding: 0.12em 0.38em; border-radius: 5px; border: 1px solid var(--border); }
.md a { color: var(--accent); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1em 0; }
.code { margin: 0.7em 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--code-bg); }
.code-bar { display: flex; justify-content: space-between; align-items: center; padding: 3px 6px 3px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); }
.code-bar .copy { border: 0; background: transparent; color: var(--muted); font-size: 12px; padding: 4px 8px; border-radius: 6px; cursor: pointer; }
.code-bar .copy:active { background: var(--hover); }
.code pre { margin: 0; padding: 10px 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.code pre code, pre.plain { background: transparent; border: 0; padding: 0; font-size: 12.5px; line-height: 1.55; font-family: var(--mono); }
.tk-k { color: var(--tk-k); }
.tk-s { color: var(--tk-s); }
.tk-c { color: var(--tk-c); font-style: italic; }
.tk-n { color: var(--tk-n); }
.tk-f { color: var(--tk-f); }
.table-wrap { overflow-x: auto; margin: 0.7em 0; -webkit-overflow-scrolling: touch; }
.md table { border-collapse: collapse; font-size: 14px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: var(--panel-2); }
.streaming > :last-child::after, .streaming:empty::after { content: ""; display: inline-block; width: 8px; height: 1em; margin-left: 2px; vertical-align: -0.15em; background: var(--accent); border-radius: 2px; animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

.thinking { font-size: 14px; color: var(--muted); }
.thinking summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; }
.thinking summary::-webkit-details-marker { display: none; }
.thinking summary .ic { width: 16px; height: 16px; margin-right: 5px; }
.thinking.live summary { animation: pulse 1.6s ease-in-out infinite; }
.thinking .md { margin-top: 6px; padding-left: 12px; border-left: 2px solid var(--border); white-space: pre-wrap; }

/* Tool groups */
.tgroup { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); font-size: 14px; overflow: hidden; }
.tgroup.sub { margin-left: 18px; }
.tg-head { display: flex; align-items: center; padding: 8px 10px; cursor: pointer; min-width: 0; }
.tg-head:active { background: var(--hover); }
.tg-icon { width: 22px; height: 22px; border-radius: 6px; display: flex; align-items: center; justify-content: center; flex: none; background: var(--panel-2); color: var(--text-2); }
.tg-icon .ic { width: 14px; height: 14px; }
.tg-text { flex: 1; min-width: 0; margin-left: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tg-text b { font-weight: 600; }
.tg-text .sum { color: var(--muted); font-family: var(--mono); font-size: 12.5px; margin-left: 6px; }
.tg-state { margin-left: 8px; flex: none; display: flex; align-items: center; font-size: 12px; color: var(--muted); }
.tg-state .ic { width: 16px; height: 16px; }
.tg-state.ok { color: var(--ok); }
.tg-state.err { color: var(--danger); }
.tg-chev { margin-left: 4px; color: var(--muted); display: flex; transition: transform 0.15s; }
.tg-chev .ic { width: 16px; height: 16px; }
.open > .tg-head .tg-chev, .trow.open > .tr-head .tg-chev { transform: rotate(90deg); }
.tg-list { border-top: 1px solid var(--border); display: none; }
.tgroup.open > .tg-list { display: block; }
.trow + .trow { border-top: 1px solid var(--border); }
.trow.sub { padding-left: 16px; }
.tr-head { display: flex; align-items: center; padding: 7px 10px; cursor: pointer; min-width: 0; }
.tr-head:active { background: var(--hover); }
.tr-body { display: none; padding: 2px 10px 10px; }
.trow.open > .tr-body { display: block; }
.t-label { font-size: 12px; color: var(--muted); margin: 8px 0 4px; }
.t-label:first-child { margin-top: 2px; }
pre.plain {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 340px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
}
pre.plain.nowrap { white-space: pre; word-break: normal; }
.diff .del { color: var(--danger); background: var(--danger-bg); }
.diff .add { color: var(--ok); }
.todos { list-style: none; padding: 0; margin: 0; }
.todos li { padding: 3px 0; display: flex; align-items: flex-start; font-size: 14px; }
.todos li .ic { width: 16px; height: 16px; margin: 3px 7px 0 0; color: var(--muted); }
.todos li.done { color: var(--muted); text-decoration: line-through; }
.todos li.active { font-weight: 600; }
.todos li.active .ic { color: var(--accent); }

/* Permission */
.perm { border: 1px solid var(--warn); background: var(--perm-bg); border-radius: var(--radius); padding: 12px; }
.perm-title { font-weight: 600; margin-bottom: 4px; display: flex; align-items: center; }
.perm-title .ic { color: var(--warn); margin-right: 6px; }
.perm-reason { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.perm-actions { display: flex; flex-wrap: wrap; margin-top: 10px; }
.perm-actions .btn { margin: 0 8px 6px 0; }
.perm.done { border-color: var(--border); background: var(--panel); padding: 8px 12px; }
.perm.done .perm-detail, .perm.done .q-block { display: none; }
.perm-state { font-size: 13px; color: var(--muted); }
.q-block { margin-top: 10px; }
.q-head { font-size: 12px; color: var(--muted); }
.q-text { font-weight: 600; margin: 2px 0 6px; }
.q-opt { display: flex; align-items: flex-start; padding: 8px 10px; margin-bottom: 6px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); cursor: pointer; }
.q-opt input { margin: 5px 9px 0 0; flex: none; }
.q-opt small { display: block; color: var(--muted); }
.q-other { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); outline: none; }

.sys { text-align: center; font-size: 12px; color: var(--muted); }
.result { font-size: 12px; color: var(--muted); display: flex; align-items: center; }
.result .ic { width: 14px; height: 14px; margin-right: 4px; color: var(--ok); }
.error-box { border: 1px solid var(--danger); background: var(--danger-bg); color: var(--danger); border-radius: 12px; padding: 10px 12px; white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.working-row { display: flex; align-items: center; font-size: 13px; color: var(--muted); }
.working-row .spinner { margin-right: 8px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; flex: none; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Dock / composer */
.dock { flex: none; position: relative; padding: 0 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
.dock > * { max-width: 780px; margin-left: auto; margin-right: auto; }
.todo-panel { border: 1px solid var(--border); background: var(--panel); border-radius: 12px; margin-bottom: 8px; font-size: 14px; overflow: hidden; }
.todo-head { display: flex; align-items: center; padding: 7px 10px; cursor: pointer; }
.todo-head .tg-text { margin-left: 0; }
.todo-panel .todos { padding: 2px 10px 8px; max-height: 30vh; overflow-y: auto; }
.todo-panel.collapsed .todos { display: none; }
.cmd-menu, .pop-menu {
  position: absolute;
  bottom: 100%;
  left: 10px;
  right: 10px;
  margin-bottom: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow-y: auto;
  max-height: 46vh;
  z-index: 5;
}
.pop-menu { right: auto; min-width: 200px; padding: 4px; }
.pop-menu button { display: flex; width: 100%; border: 0; background: transparent; padding: 10px 12px; border-radius: 9px; cursor: pointer; text-align: left; }
.pop-menu button:active { background: var(--hover); }
.cmd-item { display: block; width: 100%; border: 0; background: transparent; text-align: left; padding: 8px 12px; cursor: pointer; }
.cmd-item + .cmd-item { border-top: 1px solid var(--border); }
.cmd-item:active, .cmd-item.sel { background: var(--hover); }
.cmd-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); font-size: 14px; }
.cmd-item b { font-weight: 600; }
.cmd-hint { color: var(--muted); font-size: 12px; }
.cmd-item small { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.composer { background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 6px 6px 6px 6px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04); }
.composer textarea {
  display: block;
  width: 100%;
  resize: none;
  border: 0;
  background: transparent;
  padding: 6px 10px 4px;
  max-height: 200px;
  line-height: 1.45;
  outline: none;
  font-size: 16px; /* >=16px stops iOS from zooming into the field */
}
.composer-bar { display: flex; align-items: center; }
.spacer { flex: 1; }
.chip {
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12.5px;
  color: var(--text-2);
  margin-left: 4px;
  cursor: pointer;
  white-space: nowrap;
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip.warn { color: var(--danger); border-color: var(--danger); }
.chip:active { background: var(--hover); }
.send-btn { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text); cursor: pointer; flex: none; display: flex; align-items: center; justify-content: center; padding: 0; }
.send-btn .ic { width: 20px; height: 20px; stroke-width: 2.2; }
.send-btn.stop { background: var(--text); color: var(--bg); }
.send-btn[disabled] { opacity: 0.35; }
.attach-list { display: flex; flex-wrap: wrap; padding: 2px 4px 0; }
.attach-list:empty { display: none; }
.attach-list .att { position: relative; margin: 6px 8px 2px 0; }
.attach-list .att .thumb { width: 56px; height: 56px; }
.attach-list .att .x { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--panel); background: var(--text); color: var(--bg); padding: 0; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.attach-list .att .x .ic { width: 12px; height: 12px; stroke-width: 2.6; }
.attach-list .att .prog { position: absolute; left: 3px; right: 3px; bottom: 3px; height: 3px; border-radius: 2px; background: var(--accent); transform-origin: left; }

/* Modal / sheet */
.modal { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 50; background: rgba(0, 0, 0, 0.38); display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 801px) { .modal { align-items: center; } }
.modal-card { background: var(--panel); width: 100%; max-width: 680px; max-height: 90%; border-radius: 18px 18px 0 0; display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
@media (min-width: 801px) { .modal-card { border-radius: 18px; } }
.modal-head { display: flex; align-items: center; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--border); font-weight: 600; flex: none; }
.modal-head > span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-actions { display: flex; flex: none; }
.modal-actions .btn { margin-left: 6px; }
.modal-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 16px 18px; }
.modal-body img.preview { max-width: 100%; border-radius: 10px; display: block; margin: 0 auto; }
.sheet-list { list-style: none; margin: -4px -8px; padding: 0; }
.sheet-list li { display: flex; align-items: center; padding: 12px 10px; border-radius: 10px; cursor: pointer; }
.sheet-list li:active { background: var(--hover); }
.sheet-list li .ic { margin-right: 12px; color: var(--muted); }
.sheet-list li.danger, .sheet-list li.danger .ic { color: var(--danger); }
.sheet-list li .sl-main { flex: 1; min-width: 0; }
.sheet-list li small { display: block; color: var(--muted); font-size: 12.5px; }
.sheet-list li .check { color: var(--accent); margin: 0 0 0 8px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input[type="text"] { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); outline: none; font-size: 16px; }
.field input[type="text"]:focus { border-color: var(--accent); }
.field label.check { display: flex; align-items: flex-start; font-size: 15px; color: var(--text); margin: 0; cursor: pointer; }
.field label.check input { margin: 5px 9px 0 0; flex: none; }
.field label.check small { color: var(--muted); font-size: 12.5px; }
.drawer-foot { display: flex; justify-content: space-between; }
.drawer-foot .btn { padding-left: 6px; padding-right: 6px; }

/* Files Claude produced, shown under its reply */
.outputs { display: flex; flex-wrap: wrap; align-items: flex-start; margin-top: 10px; }
.outputs > * { margin: 0 8px 8px 0; }
.outputs .thumb.out { width: 120px; height: 120px; object-fit: contain; background: #fff; }
.out-card { display: flex; align-items: center; border: 1px solid var(--border); background: var(--panel); border-radius: 12px; padding: 8px 12px 8px 8px; cursor: pointer; max-width: 100%; text-align: left; }
.out-card:active { background: var(--hover); }
.out-ext { flex: none; min-width: 42px; height: 42px; padding: 0 4px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; margin-right: 10px; }
.out-meta { display: flex; flex-direction: column; min-width: 0; }
.out-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 56vw; }
.out-size { font-size: 12px; color: var(--muted); }
.media-preview { width: 100%; max-height: 70vh; border-radius: 10px; background: #000; }
audio.media-preview { background: transparent; }
.html-preview { width: 100%; height: 65vh; border: 1px solid var(--border); border-radius: 10px; background: #fff; }

/* Search results */
.search-results { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 8px; }
.sr-head { font-size: 12px; color: var(--muted); padding: 0 4px 6px; }
.sr-item { padding: 8px 6px; border-radius: 10px; cursor: pointer; }
.sr-item:active { background: var(--hover); }
.sr-title { display: flex; align-items: center; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; }
.sr-title .ic { width: 15px; height: 15px; margin-right: 6px; color: var(--muted); }
.sr-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sr-when { margin-left: auto; padding-left: 8px; font-size: 11.5px; font-weight: 400; color: var(--muted); flex: none; }
.sr-snippet { font-size: 13px; color: var(--text-2); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sr-snippet mark { background: var(--accent-soft); color: var(--accent); border-radius: 3px; padding: 0 1px; }
.flash { animation: flash 2.2s ease-out; border-radius: 12px; }
@keyframes flash { 0%, 40% { background: var(--accent-soft); box-shadow: 0 0 0 6px var(--accent-soft); } 100% { background: transparent; box-shadow: 0 0 0 6px transparent; } }

/* Usage */
.u-plan { font-weight: 600; margin-bottom: 12px; }
.u-row { margin-bottom: 16px; }
.u-head { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 5px; }
.u-bar { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.u-fill { height: 100%; background: var(--ok); border-radius: 99px; transition: width 0.4s; }
.u-fill.warn { background: var(--warn); }
.u-fill.bad { background: var(--danger); }
.u-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.banner { cursor: pointer; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 8px; word-break: break-all; }
.row { display: flex; flex-wrap: wrap; }
.row .btn { margin: 0 8px 8px 0; }
.todo-panel.open .tg-chev { transform: rotate(90deg); }
.info-grid { display: grid; grid-template-columns: auto 1fr; font-size: 14px; }
.info-grid div { padding: 5px 0; border-bottom: 1px solid var(--border); }
.info-grid div:nth-child(odd) { color: var(--muted); padding-right: 14px; white-space: nowrap; }
.info-grid div:nth-child(even) { word-break: break-all; }
.code-view { font-family: var(--mono); font-size: 12.5px; line-height: 1.55; background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; overflow: auto; -webkit-overflow-scrolling: touch; padding: 8px 0; }
.code-view .ln { display: flex; white-space: pre; }
.code-view .ln::before { content: attr(data-n); flex: none; width: 3.4em; padding-right: 10px; text-align: right; color: var(--muted); opacity: 0.6; -webkit-user-select: none; user-select: none; }
.code-view .ln span.code-line { padding-right: 12px; }

.lightbox { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 70; background: rgba(0, 0, 0, 0.92); display: flex; align-items: center; justify-content: center; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }

.toast { position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 80; background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 12px; font-size: 14px; max-width: 90%; box-shadow: var(--shadow); }
