:root {
  --bg: #f7f6f3; --surface: #ffffff; --surface-2: #f0eee9; --surface-3: #e8e5de; --text: #1f1e1d; --text-2: #5f5b55; --muted: #8a857d;
  --line: #e3e0d8; --line-strong: #d3cfc5; --accent: #c96442; --accent-2: #b0563a; --accent-soft: #f6e7e0; --on-accent: #fff;
  --ok: #2f7d4f; --ok-soft: #e3f2e8; --warn: #9a6200; --warn-soft: #fff3d6; --err: #b3261e; --err-soft: #fdecea; --info: #1d5fb8; --info-soft: #e3edfb;
  --user: #ebe6dc; --code-bg: #f3f1ec; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06); --shadow-lg: 0 12px 40px rgba(0,0,0,.18);
  --radius: 14px; --side-w: 280px; --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1c1b; --surface: #262524; --surface-2: #2e2d2b; --surface-3: #383633; --text: #ecebe8; --text-2: #c2beb6; --muted: #948f86;
    --line: #363431; --line-strong: #45423e; --accent-soft: #3d2a22; --ok: #6cc08b; --ok-soft: #1f3327; --warn: #e2ac4a; --warn-soft: #3a2f17;
    --err: #f0857b; --err-soft: #40211e; --info: #8ab4f8; --info-soft: #1d2a40; --user: #34312d; --code-bg: #2b2a28;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1d1c1b; --surface: #262524; --surface-2: #2e2d2b; --surface-3: #383633; --text: #ecebe8; --text-2: #c2beb6; --muted: #948f86;
  --line: #363431; --line-strong: #45423e; --accent-soft: #3d2a22; --ok: #6cc08b; --ok-soft: #1f3327; --warn: #e2ac4a; --warn-soft: #3a2f17;
  --err: #f0857b; --err-soft: #40211e; --info: #8ab4f8; --info-soft: #1d2a40; --user: #34312d; --code-bg: #2b2a28;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 16px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", "Segoe UI", sans-serif; overflow: hidden; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--err); min-height: 1.4em; margin: 0; font-size: 14px; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
svg.ic { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: block; }
[data-icon] { display: inline-flex; align-items: center; justify-content: center; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 15px; background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ok { background: var(--ok); color: #fff; border-color: transparent; }
.btn.danger { background: var(--err); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; border-color: var(--line-strong); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; color: var(--text-2); flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.sm { width: 34px; height: 34px; }
.brand-mark { width: 24px; height: 24px; border-radius: 7px; background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 8l4 4-4 4M13 16h4'/%3E%3C/svg%3E") center/70% no-repeat; flex: none; }
.brand-mark.big { width: 48px; height: 48px; border-radius: 14px; }

/* ---------- login ---------- */
.login { height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); padding: 28px 24px; border-radius: 20px; border: 1px solid var(--line); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 4px 0 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--text-2); }
.login-card input { padding: 12px; }

/* ---------- layout ---------- */
.app { height: 100dvh; display: flex; }
.sidebar { width: var(--side-w); flex: none; background: var(--surface-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; height: 100dvh; padding-top: env(safe-area-inset-top); }
.side-mask { display: none; }
.only-mobile { display: none; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100dvh; position: relative; }
@media (max-width: 860px) {
  .only-mobile { display: inline-flex; }
  .sidebar { position: fixed; z-index: 30; left: 0; top: 0; bottom: 0; width: min(86vw, 320px); transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow-lg); }
  .app.side-open .sidebar { transform: none; }
  .app.side-open .side-mask { display: block; position: fixed; inset: 0; z-index: 29; background: rgba(0,0,0,.35); }
}

.side-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 6px 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.new-chat { margin: 6px 12px; display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); font-weight: 600; box-shadow: 0 1px 1px rgba(0,0,0,.03); }
.new-chat:hover { border-color: var(--line-strong); }
.search { margin: 6px 12px 4px; display: flex; align-items: center; gap: 6px; padding: 0 10px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.search input { border: 0; background: transparent; padding: 8px 0; flex: 1; min-width: 0; box-shadow: none; font-size: 15px; }
.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; overscroll-behavior: contain; }
.group-label { font-size: 12px; color: var(--muted); padding: 12px 8px 4px; font-weight: 600; }
.conv-item { display: flex; align-items: center; gap: 8px; padding: 8px 8px; border-radius: 10px; cursor: pointer; position: relative; }
.conv-item:hover { background: var(--surface-3); }
.conv-item.active { background: var(--surface); box-shadow: 0 0 0 1px var(--line); }
.conv-item .ci-main { flex: 1; min-width: 0; }
.conv-item .ci-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14.5px; }
.conv-item .ci-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 6px; align-items: center; }
.ci-more { width: 30px; height: 30px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); flex: none; opacity: 0; }
.conv-item:hover .ci-more, .conv-item.active .ci-more { opacity: 1; }
@media (pointer: coarse) { .ci-more { opacity: 1; } }
.ci-more:hover { background: var(--surface-2); color: var(--text); }
.ci-sub svg { width: 13px; height: 13px; }
.modal-foot { flex-wrap: wrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: transparent; }
.dot.running, .dot.queued, .dot.stopping { background: var(--info); animation: pulse 1.2s infinite; }
.dot.awaiting_approval { background: var(--warn); animation: pulse 1s infinite; }
.dot.failed { background: var(--err); }
@keyframes pulse { 50% { opacity: .35; } }
.conv-empty { padding: 20px 12px; color: var(--muted); font-size: 14px; text-align: center; }
.side-foot { border-top: 1px solid var(--line); padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; }
.usage-card { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-2); }
.usage-card:hover { border-color: var(--line-strong); }
.u-row { display: flex; justify-content: space-between; gap: 8px; }
.bar { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--ok); }
.bar.mid > i { background: var(--warn); }
.bar.high > i { background: var(--err); }
.side-actions { display: flex; gap: 4px; }
.side-link { display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 10px; font-size: 14px; color: var(--text-2); }
.side-link:hover { background: var(--surface-3); color: var(--text); }

/* ---------- topbar ---------- */
.topbar { display: flex; align-items: center; gap: 6px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); z-index: 5; }
.top-title { flex: 1; min-width: 0; padding: 0 4px; }
.conv-title { font-weight: 650; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; text-align: left; font-size: 15.5px; }
.top-sub { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); min-width: 0; }
.top-sub > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pill { flex: none; padding: 0 8px; border-radius: 99px; font-size: 11.5px; line-height: 19px; font-weight: 600; }
.pill:empty { display: none; }
.pill.running, .pill.queued, .pill.stopping { background: var(--info-soft); color: var(--info); }
.pill.awaiting_approval { background: var(--warn-soft); color: var(--warn); }
.pill.completed { background: var(--ok-soft); color: var(--ok); }
.pill.failed, .pill.auth, .pill.quota, .pill.session, .pill.error { background: var(--err-soft); color: var(--err); }
.pill.interrupted, .pill.stopped { background: var(--surface-3); color: var(--text-2); }

/* ---------- messages ---------- */
.scroller { flex: 1; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.messages, .welcome { max-width: 800px; margin: 0 auto; padding: 16px 16px 24px; }
.welcome { display: flex; flex-direction: column; align-items: center; text-align: center; padding-top: 10vh; gap: 10px; }
.welcome h2 { margin: 6px 0 14px; font-size: 24px; font-weight: 650; }
.field-label { font-size: 13px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 99px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 14px; max-width: 100%; }
.chip span.t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chip.dashed { border-style: dashed; color: var(--text-2); }
.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; width: 100%; margin-top: 18px; }
.suggestion { text-align: left; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; color: var(--text-2); }
.suggestion:hover { border-color: var(--line-strong); color: var(--text); }

.msg-user { display: flex; flex-direction: column; align-items: flex-end; margin: 18px 0 8px; gap: 6px; }
.bubble { background: var(--user); padding: 10px 14px; border-radius: 18px 18px 6px 18px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.att-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: 85%; }
.att-img { width: 92px; height: 92px; border-radius: 12px; object-fit: cover; border: 1px solid var(--line); background: var(--surface-2); cursor: zoom-in; }
.att-file { display: inline-flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; color: var(--text); text-decoration: none; max-width: 240px; }
.att-file .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.turn { margin: 8px 0 20px; display: flex; flex-direction: column; gap: 6px; }
.md { overflow-wrap: anywhere; line-height: 1.7; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: .6em 0; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.35; margin: 1.1em 0 .5em; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.22em; } .md h3 { font-size: 1.1em; }
.md ul, .md ol { padding-left: 1.4em; margin: .5em 0; }
.md li { margin: .2em 0; }
.md blockquote { margin: .6em 0; padding: 2px 12px; border-left: 3px solid var(--line-strong); color: var(--text-2); }
.md a { color: var(--accent); text-underline-offset: 2px; }
.md code { font-family: var(--mono); font-size: .88em; background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.md table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 14px; margin: .6em 0; }
.md th, .md td { border: 1px solid var(--line-strong); padding: 6px 10px; text-align: left; }
.md th { background: var(--surface-2); }
.md img { max-width: 100%; }
.codeblock { margin: .7em 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--code-bg); }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 4px 12px; font-size: 12px; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--line); font-family: var(--mono); }
.copy-btn { display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border-radius: 7px; font-size: 12px; color: var(--text-2); font-family: inherit; }
.copy-btn:hover { background: var(--surface-3); }
.codeblock pre { margin: 0; padding: 12px; overflow-x: auto; font-size: 13px; line-height: 1.55; }
.codeblock pre code, pre code.hljs { background: transparent !important; padding: 0; font-family: var(--mono); font-size: 13px; }

.thinking { border-left: 2px solid var(--line-strong); padding-left: 12px; color: var(--text-2); font-size: 14px; }
.thinking summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; user-select: none; }
.thinking summary::-webkit-details-marker { display: none; }
.thinking .th-body { white-space: pre-wrap; margin-top: 6px; max-height: 320px; overflow-y: auto; overflow-wrap: anywhere; }
.thinking.live summary span.t::after { content: '…'; animation: pulse 1s infinite; }

.step { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; font-size: 14px; }
.step > summary { list-style: none; display: flex; align-items: center; gap: 8px; padding: 8px 10px; cursor: pointer; min-width: 0; }
.step > summary::-webkit-details-marker { display: none; }
.step .s-ic { width: 26px; height: 26px; border-radius: 8px; background: var(--surface-2); display: inline-flex; align-items: center; justify-content: center; color: var(--text-2); flex: none; }
.step .s-ic svg { width: 15px; height: 15px; }
.step .s-name { font-weight: 600; flex: none; }
.step .s-arg { color: var(--muted); font-family: var(--mono); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.step .s-state { flex: none; font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.step.err .s-ic { background: var(--err-soft); color: var(--err); }
.step.done .s-ic { background: var(--ok-soft); color: var(--ok); }
.step .s-body { padding: 0 10px 10px; display: flex; flex-direction: column; gap: 6px; }
.badge { display: inline-flex; align-items: center; gap: 3px; padding: 0 7px; border-radius: 99px; font-size: 11px; line-height: 18px; font-weight: 600; white-space: nowrap; }
.badge.auto { background: var(--info-soft); color: var(--info); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.no { background: var(--err-soft); color: var(--err); }
.label-sm { font-size: 12px; color: var(--muted); }
pre.box { margin: 0; background: var(--code-bg); border-radius: 8px; padding: 8px 10px; font-family: var(--mono); font-size: 12.5px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 360px; overflow: auto; }
.diff { font-family: var(--mono); font-size: 12.5px; line-height: 1.5; border-radius: 8px; overflow: auto; max-height: 360px; background: var(--code-bg); }
.diff div { padding: 0 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.diff .del { background: color-mix(in srgb, var(--err) 14%, transparent); }
.diff .add { background: color-mix(in srgb, var(--ok) 16%, transparent); }
.path { font-family: var(--mono); font-size: 12.5px; color: var(--text-2); overflow-wrap: anywhere; }

.approval { border: 1.5px solid var(--warn); background: var(--warn-soft); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.approval .a-head { display: flex; align-items: center; gap: 8px; font-weight: 650; color: var(--warn); }
.approval .a-reason { font-size: 13px; color: var(--text-2); }
.approval .a-actions { display: flex; gap: 10px; }
.approval .a-actions .btn { flex: 1; padding: 11px; }
.approval .a-timer { font-size: 12px; color: var(--muted); }
.approval.done { border-color: var(--line); background: var(--surface); }
.approval.done .a-head { color: var(--text-2); }

.turn-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 12px; color: var(--muted); margin-top: 2px; }
.turn-foot .tf-btn { display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px; border-radius: 6px; }
.turn-foot .tf-btn:hover { background: var(--surface-2); color: var(--text); }
.turn-foot svg { width: 14px; height: 14px; }
.sysline { text-align: center; font-size: 13px; color: var(--muted); margin: 10px 0; }
.alert { border-radius: 12px; padding: 10px 12px; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.alert.error { background: var(--err-soft); color: var(--err); }
.alert.notice { background: var(--warn-soft); color: var(--warn); }
.typing { display: inline-flex; align-items: center; gap: 4px; padding: 6px 0; color: var(--muted); font-size: 14px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }

.to-bottom { position: absolute; right: 50%; transform: translateX(50%); bottom: calc(150px + env(safe-area-inset-bottom)); width: 36px; height: 36px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line-strong); box-shadow: var(--shadow); color: var(--text-2); z-index: 4; }

/* ---------- composer ---------- */
.composer-wrap { padding: 6px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom)); background: linear-gradient(to bottom, transparent, var(--bg) 18px); }
.composer { max-width: 800px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 20px; box-shadow: var(--shadow); padding: 8px 8px 6px 12px; display: flex; flex-direction: column; gap: 4px; transition: border-color .15s; }
.composer.drag { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, var(--line-strong)); }
.composer textarea { border: 0; box-shadow: none !important; background: transparent; resize: none; padding: 6px 2px; max-height: 38dvh; line-height: 1.5; min-height: 26px; }
.composer-bar { display: flex; align-items: center; gap: 4px; margin-left: -6px; }
.spacer { flex: 1; }
.chip-btn { display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 10px; border-radius: 99px; font-size: 12.5px; color: var(--text-2); border: 1px solid var(--line); background: var(--surface); white-space: nowrap; max-width: 42vw; overflow: hidden; text-overflow: ellipsis; }
.chip-btn:hover { border-color: var(--line-strong); color: var(--text); }
.chip-btn svg { width: 14px; height: 14px; }
.chip-btn.mode-acceptEdits { color: var(--info); border-color: color-mix(in srgb, var(--info) 35%, var(--line)); }
.chip-btn.mode-full { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--line)); }
.chip-btn.mode-auto { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }
.send-btn { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.send-btn:disabled { opacity: .4; cursor: default; }
.send-btn.stop { background: var(--text); color: var(--bg); }
.composer-note { text-align: center; font-size: 11.5px; margin-top: 5px; }
.attach-row { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 2px; }
.att-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 4px 4px 8px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12.5px; max-width: 220px; position: relative; overflow: hidden; }
.att-chip img { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; }
.att-chip .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-chip .prog { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--accent); }
.att-chip .x { width: 22px; height: 22px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.att-chip .x:hover { background: var(--surface-3); }
.att-chip.err { border-color: var(--err); color: var(--err); }

/* ---------- modal / sheet ---------- */
.modal-mask { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 560px; max-height: min(86dvh, 860px); display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: pop .18s ease; overflow: hidden; }
.modal.wide { max-width: 760px; }
.modal.narrow { max-width: 420px; }
@keyframes pop { from { transform: translateY(12px); opacity: .6; } }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; flex: 1; }
.modal-body { padding: 14px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
@media (max-width: 860px) {
  .modal-mask { align-items: flex-end; padding: 0; }
  .modal, .modal.wide, .modal.narrow { max-width: none; border-radius: 18px 18px 0 0; max-height: 90dvh; animation: up .22s ease; }
  @keyframes up { from { transform: translateY(40%); } }
}
.tabs { display: flex; gap: 4px; padding: 0 14px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { padding: 10px 10px; font-size: 14px; color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.section-title { font-size: 13px; font-weight: 650; color: var(--text-2); margin: 0 0 -6px; }
.opt-list { display: flex; flex-direction: column; gap: 8px; }
.opt { display: flex; align-items: flex-start; gap: 10px; text-align: left; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); width: 100%; }
.opt:hover { border-color: var(--line-strong); }
.opt.active { border-color: var(--accent); background: var(--accent-soft); }
.opt .o-ic { width: 30px; height: 30px; border-radius: 9px; background: var(--surface-2); display: inline-flex; align-items: center; justify-content: center; flex: none; color: var(--text-2); }
.opt.active .o-ic { background: var(--accent); color: #fff; }
.opt .o-t { font-weight: 600; font-size: 14.5px; }
.opt .o-d { font-size: 12.5px; color: var(--text-2); margin-top: 1px; }
.opt .o-main { flex: 1; min-width: 0; }
.opt .o-check { color: var(--accent); }
.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { flex: 1; padding: 7px 8px; border-radius: 8px; font-size: 13px; color: var(--text-2); white-space: nowrap; }
.seg button.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.form-row { display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: 13px; color: var(--text-2); font-weight: 600; }
.form-row input, .form-row select { padding: 10px 12px; }
.form-hint { font-size: 12.5px; color: var(--muted); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.switch-row .sr-t { font-weight: 600; font-size: 14.5px; }
.switch-row .sr-d { font-size: 12.5px; color: var(--text-2); }
.switch { width: 46px; height: 28px; border-radius: 99px; background: var(--surface-3); position: relative; flex: none; transition: background .15s; }
.switch::after { content: ''; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.switch.on { background: var(--ok); }
.switch.on::after { transform: translateX(18px); }
.proj-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.proj-item .p-main { flex: 1; min-width: 0; }
.proj-item .p-name { font-weight: 600; font-size: 14.5px; }
.proj-item .p-path { font-family: var(--mono); font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.dir-browser { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.dir-cur { padding: 8px 12px; background: var(--surface-2); font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; display: flex; align-items: center; gap: 8px; }
.dir-list { max-height: 280px; overflow-y: auto; }
.dir-item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 9px 12px; border-top: 1px solid var(--line); font-size: 14px; }
.dir-item:hover { background: var(--surface-2); }
.dir-item.sel { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 520px) { .stat-grid { grid-template-columns: 1fr; } }
.stat { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat .st-t { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .st-v { font-size: 20px; font-weight: 700; margin: 2px 0; }
.stat .st-s { font-size: 12px; color: var(--text-2); }
.limit { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.limit .bar { height: 8px; }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 6px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; min-width: 0; }
.chart .col i { width: 100%; max-width: 26px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.chart .col span { font-size: 10px; color: var(--muted); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); }
table.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; }
.img-viewer { max-width: 100%; max-height: 80dvh; border-radius: 8px; display: block; margin: 0 auto; }

/* ---------- toasts ---------- */
.toasts { position: fixed; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: calc(100% - 32px); max-width: 420px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow-lg); animation: pop .18s; pointer-events: auto; }
.toast.err { background: var(--err); color: #fff; }

.u-reset { font-size: 11px; color: var(--muted); margin-top: -2px; }
.files-card { display: flex; flex-direction: column; gap: 6px; }
.file-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); text-decoration: none; }
.file-row:hover { border-color: var(--accent); }
.file-row .f-ext { width: 40px; height: 40px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.file-row .f-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-row .f-name { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.file-row .f-size { font-size: 12px; color: var(--muted); }
.file-row svg { color: var(--accent); }

.whoami { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); padding: 0 2px; }
.whoami .who-name { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
