:root {
  --brand: #0b8a72; --brand-2: #0b6f86; --brand-ink: #ffffff;
  --bg: #f0f2f5; --panel: #ffffff; --panel-2: #f6f7f9; --hover: #f2f5f8; --line: #e6e8eb; --line-2: #eef0f2;
  --text: #1c2730; --text-2: #3b4752; --muted: #7a8691;
  --accent: #1677ff; --accent-soft: #e6f0ff; --accent-ink: #ffffff; --select: #d9ebff; --unread: #d3e3fd;
  --chat-bg: #e9e5df; --bubble-in: #ffffff; --bubble-out: #dcf6c8; --bubble-out-ink: #1c2730;
  --danger: #d93025; --ok: #1a9b4b; --warn: #c27c0e; --shadow: 0 1px 2px rgba(16,24,32,.08); --shadow-lg: 0 8px 28px rgba(16,24,32,.18);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #0d6e5d; --brand-2: #0b5568;
    --bg: #0f1418; --panel: #172026; --panel-2: #1c262d; --hover: #1f2b33; --line: #26323a; --line-2: #212c33;
    --text: #e6ecef; --text-2: #c3cdd3; --muted: #8b98a2;
    --accent: #4c95ff; --accent-soft: #1b2c45; --select: #1d3550; --unread: #23406a;
    --chat-bg: #11181d; --bubble-in: #1f2a31; --bubble-out: #20402b; --bubble-out-ink: #e6ecef;
    --danger: #ff6b61; --ok: #43c47a; --warn: #f0a83a; --shadow: none; --shadow-lg: 0 8px 28px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  --brand: #0d6e5d; --brand-2: #0b5568;
  --bg: #0f1418; --panel: #172026; --panel-2: #1c262d; --hover: #1f2b33; --line: #26323a; --line-2: #212c33;
  --text: #e6ecef; --text-2: #c3cdd3; --muted: #8b98a2;
  --accent: #4c95ff; --accent-soft: #1b2c45; --select: #1d3550; --unread: #23406a;
  --chat-bg: #11181d; --bubble-in: #1f2a31; --bubble-out: #20402b; --bubble-out-ink: #e6ecef;
  --danger: #ff6b61; --ok: #43c47a; --warn: #f0a83a; --shadow: none; --shadow-lg: 0 8px 28px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 "Segoe UI", Roboto, system-ui, -apple-system, sans-serif; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }
.grow { flex: 1; }
button, input, select, textarea { font: inherit; color: inherit; }
svg.i { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico svg.i { width: 18px; height: 18px; }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; justify-content: center; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 3px 9px; font-size: 12px; border-radius: 6px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent; color: var(--text-2); display: inline-grid; place-items: center; cursor: pointer; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.on { color: var(--accent); background: var(--accent-soft); }
.icon-btn.on-dark { color: var(--brand-ink); }
.icon-btn.on-dark:hover { background: rgba(255,255,255,.14); color: var(--brand-ink); }
input[type=text], input[type=password], input[type=search], select, textarea {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 10px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.logo-mark { width: 30px; height: 30px; border-radius: 7px; background: #fff; color: var(--brand); display: inline-grid; place-items: center; flex: none; }
.logo-mark svg { width: 100%; height: 100%; display: block; }

/* ---------- login ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.login-card { width: min(360px, 100%); background: var(--panel); border-radius: 16px; padding: 28px 24px; display: grid; gap: 12px; box-shadow: var(--shadow-lg); }
.login-logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; }
.login-logo .logo-mark { width: 40px; height: 40px; border-radius: 9px; background: linear-gradient(90deg, var(--brand), var(--brand-2)); color: #fff; }
.login-card p { margin: 0; }

/* ---------- shell ---------- */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.topbar { height: 56px; flex: none; display: flex; align-items: center; gap: 18px; padding: 0 14px; color: var(--brand-ink); background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 18px; }
.topnav { display: flex; gap: 4px; }
.nav-item { border: 0; background: transparent; color: rgba(255,255,255,.9); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.nav-item .short { display: none; }
.nav-item:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav-item.active { background: rgba(0,0,0,.22); color: #fff; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.page-picker { display: flex; align-items: center; gap: 4px; max-width: 46vw; overflow-x: auto; padding: 4px 2px; scrollbar-width: none; }
.page-picker::-webkit-scrollbar { display: none; }
.pp-all { flex: none; height: 30px; padding: 0 11px; border-radius: 999px; border: 1px solid rgba(255,255,255,.3); background: rgba(255,255,255,.12); color: #fff; font-size: 12px; cursor: pointer; }
.pp-all:hover { background: rgba(255,255,255,.22); }
.pp-all.on { background: #fff; color: var(--brand); border-color: #fff; font-weight: 600; }
.pp-page { flex: none; width: 30px; height: 30px; padding: 0; border-radius: 50%; border: 2px solid transparent; background: rgba(255,255,255,.22); cursor: pointer; overflow: hidden; display: grid; place-items: center; opacity: .45; transition: opacity .15s; }
.pp-page:hover { opacity: .85; }
.pp-page.all, .pp-page.on { opacity: 1; }
.pp-page.on { border-color: #fff; box-shadow: 0 0 0 2px rgba(124,240,166,.95); }
.pp-page img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pp-fallback { font-size: 11px; font-weight: 700; color: #fff; }
.pp-sep { flex: none; width: 1px; height: 18px; background: rgba(255,255,255,.3); margin: 0 3px; }
.sync-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.12); color: #fff; border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; white-space: nowrap; font-variant-numeric: tabular-nums; }
.sync-chip:hover { background: rgba(255,255,255,.2); }
.sync-chip i { width: 8px; height: 8px; border-radius: 50%; background: #7cf0a6; }
.sync-chip.warn i { background: #ffd166; }
.sync-chip.bad i { background: #ff8a7a; }
.sync-chip.paused i { background: rgba(255,255,255,.55); }
.sync-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.sync-controls label { display: grid; gap: 3px; }
.sync-controls select { width: auto; min-width: 110px; }
.sync-live { display: grid; gap: 14px; }
.bridge-box { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 8px; }
.mode-box { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 8px; }
.ctl-sep { width: 1px; align-self: stretch; background: var(--line); }
.older-loading { text-align: center; padding: 8px; }
.table tr.sel td { background: var(--select); }
.frames { display: grid; gap: 4px; }
.frame { border: 1px solid var(--line); border-radius: 8px; }
.frame-head { display: flex; gap: 8px; align-items: center; padding: 5px 8px; cursor: pointer; min-width: 0; }
.frame-head:hover { background: var(--hover); }
.frame-json { margin: 0; padding: 8px; max-height: 360px; overflow: auto; font-size: 12px; background: var(--panel-2); border-top: 1px solid var(--line); white-space: pre-wrap; word-break: break-word; }
.bridge-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.bridge-head .grow { flex: 1; }
.sync-sum { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.stats.four { grid-template-columns: repeat(4, 1fr); }
.stat.click { cursor: pointer; } .stat.click:hover { background: var(--hover); }
.st-accent { color: var(--accent); }
.ov-head { display: flex; justify-content: space-between; margin-bottom: 6px; }
.table.compact th, .table.compact td { padding: 4px 6px; text-align: center; } .table.compact td:first-child { text-align: left; }
.ov-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; font-size: 13px; }
.ov-group .gname { font-weight: 600; min-width: 70px; }
.mode-chip { font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.mode-chip.suggest { color: var(--accent); border-color: currentColor; }
.mode-chip.auto { color: #fff; background: var(--ok); border-color: var(--ok); }
.feed { display: grid; gap: 2px; }
.feed-item { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 8px; padding: 7px 6px; border-radius: 8px; cursor: pointer; }
.feed-item:hover { background: var(--hover); }
.feed-item.current { background: var(--select); }
.feed-item.fresh { animation: fresh 2.4s ease-out; }
@keyframes fresh { from { background: var(--accent-soft); } to { background: transparent; } }
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.feed-main { min-width: 0; display: grid; gap: 2px; }
.feed-top { display: flex; justify-content: space-between; gap: 6px; }
.feed-top .fname { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-meta { display: flex; align-items: center; gap: 6px; min-width: 0; }
.feed-meta > :not(.ell) { flex: none; white-space: nowrap; }
.ell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.sync-sum > div { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.sync-sum b { display: block; font-size: 15px; }
.st-ok { color: var(--ok); } .st-warn { color: var(--warn); } .st-bad { color: var(--danger); }

.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: 418px minmax(0, 1fr) 340px; grid-template-rows: minmax(0, 1fr); }
.workspace > * { min-height: 0; }

/* ---------- conversation list ---------- */
.list-pane { display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); }
.list-toolbar { display: flex; gap: 6px; padding: 10px 10px 6px; }
.search { flex: 1; display: flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; color: var(--muted); }
.search input { border: 0; background: transparent; padding: 7px 0; box-shadow: none !important; }
.seg { display: flex; gap: 4px; padding: 0 10px 8px; border-bottom: 1px solid var(--line); }
.seg-item { border: 1px solid var(--line); background: var(--panel); color: var(--text-2); border-radius: 999px; padding: 3px 12px; font-size: 13px; cursor: pointer; }
.seg-item.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.search-toggle { display: none; }
.conv-list { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 6px 0; }
.conv { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 8px; padding: 8px 10px; margin: 0 6px 6px; cursor: pointer; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px; position: relative; }
.conv.unread { background: var(--unread); }
.conv:hover { background: var(--line); }
.conv.active { background: var(--select); border-color: var(--accent); }
.conv.ai-processing { isolation: isolate; }
.conv.ai-processing::before {
  content: ""; position: absolute; inset: 1px; border-radius: 10px; pointer-events: none; z-index: -1;
  --ai-a: color-mix(in srgb, var(--brand) 8%, transparent); --ai-b: color-mix(in srgb, var(--brand) 30%, transparent); --ai-c: color-mix(in srgb, var(--brand-2) 36%, transparent);
  background: linear-gradient(90deg, var(--ai-a) 0%, var(--ai-a) 15%, var(--ai-b) 38%, var(--ai-c) 50%, var(--ai-b) 62%, var(--ai-a) 85%, var(--ai-a) 100%) repeat-x;
  background-size: 200% 100%; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 35%, transparent);
  animation: ai-card-shimmer 2.4s linear infinite, ai-card-glow 2s ease-in-out infinite;
  animation-delay: var(--ai-shimmer-delay, 0ms), var(--ai-glow-delay, 0ms); /* set from the wall clock in app.js */
}
.conv.ai-processing .avatar { outline: 2px solid var(--brand); outline-offset: 2px; }
.conv.ai-processing .foot .pill.ai { opacity: 1; color: var(--brand-ink); font-weight: 600; background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
@keyframes ai-card-shimmer { from { background-position: 200% 0; } to { background-position: 0% 0; } } /* highlight moves left → right */
@keyframes ai-card-glow { 0%, 100% { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 35%, transparent); } 50% { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 70%, transparent), 0 0 8px 0 color-mix(in srgb, var(--brand) 25%, transparent); } }
@media (prefers-reduced-motion: reduce) { .conv.ai-processing::before { animation: none; } }
.conv .avatar { width: 40px; height: 40px; }
.conv .top { display: flex; align-items: center; gap: 6px; }
.conv .system-tags { display: flex; gap: 3px; min-width: 0; max-width: 50%; overflow: hidden; }
.conv .system-tags:empty { display: none; }
.conv .system-tags .pill { flex: 0 1 auto; min-width: 0; height: 16px; padding: 0 5px; font-size: 10px; }
.conv .flag, .conv .time { flex: none; }
.conv .cname { flex: 0 1 auto; min-width: 0; font-size: 14px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .time { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.conv .preview { display: flex; align-items: center; gap: 4px; color: var(--text-2); font-size: 13px; }
.conv .preview span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .preview svg.i { width: 14px; height: 14px; color: var(--muted); }
.conv.unread .cname { font-weight: 700; }
.conv.unread .preview { color: var(--text); font-weight: 600; }
.conv .tag-row { display: flex; align-items: center; gap: 6px; margin-top: 3px; min-height: 18px; }
.conv .meta { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; flex-wrap: nowrap; overflow: hidden; }
.conv .meta > * { flex: none; }
.conv .meta .pill, .conv .foot .pill { height: 16px; padding: 0 6px; font-size: 10px; font-weight: 500; opacity: .7; }
.conv .foot { display: flex; align-items: center; gap: 4px; margin-top: 3px; min-height: 18px; overflow: hidden; }
.conv .foot > * { flex: none; }
.conv .foot > .grow { flex: 1; }
.conv .foot:not(:has(> :not(.grow))) { display: none; }
svg.i path.solid { fill: currentColor; stroke: none; }
.pill.more { background: var(--line); color: var(--muted); }
.conv .group-name { font-size: 11px; color: var(--text-2); font-weight: 600; white-space: nowrap; }
.conv .group-name:empty { display: none; }
.conv .group-name:not(:empty) + .page-name::before { content: "· "; }
.conv .foot > .page-name { flex: 0 1 auto; min-width: 0; font-size: 11px; color: var(--muted); margin-right: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .flag { color: var(--ok); display: inline-grid; }
.conv .flag svg.i { width: 17px; height: 17px; }
.list-more { padding: 12px; text-align: center; }
.list-empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--panel-2); flex: none; }
.avatar.fallback { display: inline-grid; place-items: center; color: #fff; font-weight: 700; font-size: 16px; }

.pill { display: inline-flex; align-items: center; height: 18px; padding: 0 7px; border-radius: 999px; font-size: 11px; font-weight: 600; color: #fff; background: var(--pill, #8a96a3); white-space: nowrap; max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.pill.sys { background: transparent; color: var(--warn); border: 1px solid currentColor; }
.pill.sys[style] { background: color-mix(in srgb, var(--pill) 10%, var(--panel)); color: var(--pill); }
.pill.ai { background: var(--accent-soft); color: var(--accent); }
.pill.ai.err { background: transparent; color: var(--danger); border: 1px solid currentColor; }
.pill.ai.sent { background: transparent; color: var(--ok); border: 1px solid currentColor; }

/* ---------- chat ---------- */
.chat-pane { display: flex; flex-direction: column; min-width: 0; background: var(--chat-bg); }
.chat-empty { margin: auto; text-align: center; color: var(--muted); }
.empty-art { width: 120px; height: 90px; margin: 0 auto 10px; border-radius: 18px; background: linear-gradient(135deg, var(--panel), var(--panel-2)); box-shadow: var(--shadow); position: relative; }
.empty-art::before, .empty-art::after { content: ""; position: absolute; left: 18px; right: 30px; height: 10px; border-radius: 6px; background: var(--line); top: 26px; }
.empty-art::after { top: 48px; right: 50px; }
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-head { display: flex; gap: 10px; align-items: center; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); min-height: 60px; }
.chat-head .who { flex: 1; min-width: 0; }
.chat-head .name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .name-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-head .name-line .name { min-width: 0; }
.win-chip { flex: none; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; cursor: help; }
.win-chip.ok { color: var(--ok); }
.win-chip.warn { color: var(--warn); }
.win-chip.over { color: #fff; background: var(--danger); border-color: var(--danger); }
.chat-head .presence { display: flex; gap: 10px; font-size: 11px; color: var(--muted); overflow: hidden; white-space: nowrap; }
.chat-head .presence > * { overflow: hidden; text-overflow: ellipsis; }
/* someone has the conversation open in Pancake: slowly blinking eye */
.viewing-eye { flex: none; display: inline-grid; place-items: center; color: var(--warn); cursor: help; animation: eye-blink 2.4s ease-in-out infinite; }
.viewing-eye svg.i { width: 15px; height: 15px; }
.composer-bar .viewing-eye { width: 34px; height: 34px; }
.composer-bar .viewing-eye svg.i { width: 18px; height: 18px; }
@keyframes eye-blink { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .viewing-eye { animation: none; } }
.conv .preview .sender { flex: none; color: var(--muted); font-weight: 600; }
.head-actions { display: flex; gap: 2px; }
.back { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 12px 16px 8px; display: flex; flex-direction: column; gap: 2px; overscroll-behavior: contain; }
.day-sep { align-self: center; margin: 12px 0 8px; font-size: 12px; color: var(--text-2); background: var(--panel); padding: 2px 12px; border-radius: 999px; box-shadow: var(--shadow); }
.row { display: flex; align-items: flex-end; gap: 8px; max-width: 78%; }
.row.out { align-self: flex-end; flex-direction: row-reverse; }
.row .avatar { width: 30px; height: 30px; font-size: 12px; }
.row .avatar.spacer { visibility: hidden; }
.row.gap { margin-top: 8px; }
.bubble { padding: 7px 11px; border-radius: 16px; background: var(--bubble-in); box-shadow: var(--shadow); white-space: pre-wrap; word-break: break-word; min-width: 40px; }
.row.out .bubble { background: var(--bubble-out); color: var(--bubble-out-ink); }
.row.in.first .bubble { border-top-left-radius: 6px; }
.row.out.first .bubble { border-top-right-radius: 6px; }
.bubble img { display: block; max-width: 240px; max-height: 260px; border-radius: 10px; margin: 2px 0; cursor: zoom-in; }
.bubble video.media { display: block; max-width: 240px; max-height: 320px; border-radius: 10px; margin: 2px 0; background: #000; }
.bubble audio.media { display: block; width: 240px; max-width: 100%; margin: 2px 0; }
.bubble .file-chip { display: inline-block; max-width: 240px; padding: 6px 10px; border-radius: 8px; background: rgba(0,0,0,.06); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bubble .media-only { padding: 0; background: transparent; box-shadow: none; }
.bubble .btns { display: grid; gap: 4px; margin-top: 6px; }
.bubble .btns span { border: 1px solid rgba(0,0,0,.1); background: rgba(255,255,255,.55); border-radius: 8px; padding: 4px 8px; font-size: 13px; text-align: center; }
.bubble a { color: var(--accent); }
.mt { font-size: 11px; color: var(--muted); margin: 2px 4px 0; }
.row.out .mt { text-align: right; }
.msg-col { display: flex; flex-direction: column; min-width: 0; }
.row.out .msg-col { align-items: flex-end; }
.sys-note { align-self: center; font-size: 12px; color: var(--muted); margin: 4px 0; }

.suggest-bar { margin: 0 12px 6px; background: var(--panel); border: 1px solid var(--accent); border-radius: 12px; padding: 8px 10px; display: grid; gap: 6px; box-shadow: var(--shadow); }
.suggest-bar .sb-head { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--accent); font-weight: 600; }
.suggest-bar .sb-head .grow { flex: 1; }
.suggest-bar ol { margin: 0; padding-left: 18px; font-size: 13px; display: grid; gap: 2px; }
.suggest-bar .sb-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.chat-head, .suggest-bar, .tag-box, .composer { flex: none; }
.messages { min-height: 0; }
.suggest-bar ol { max-height: 30vh; overflow-y: auto; }
.tag-box { display: flex; align-items: flex-start; background: var(--panel); border-top: 1px solid var(--line); }
.tag-grid { flex: 1; min-width: 0; position: relative; display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); grid-auto-rows: 22px; gap: 3px; padding: 6px 8px 0; margin-bottom: 6px; max-height: 53px; overflow: hidden; } /* 2 rows: 6 + 22 + 3 + 22; the bottom space is a margin so row 3 can't show through padding */
.tag-box.expanded .tag-grid { max-height: 40vh; overflow-y: auto; }
.tag-more { flex: none; margin: 6px 8px 0 0; height: 22px; padding: 0 8px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel-2); color: var(--accent); font-size: 11px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.tag-more:hover { background: var(--accent-soft); }
.tag-grid button { position: relative; border: 0; border-radius: 4px; padding: 3px 4px; font-size: 11px; cursor: pointer; color: var(--text); background: color-mix(in srgb, var(--tc, #8a96a3) 22%, var(--panel)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-grid button.on { background: var(--tc, #8a96a3); color: #fff; font-weight: 700; box-shadow: inset 0 0 0 2px rgba(255,255,255,.35); }
.tag-grid button .tag-mark { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.42); color: #fff; border-radius: inherit; }
.tag-grid button .tag-mark svg.i { width: 14px; height: 14px; }
.tag-grid button.sending { cursor: progress; }
.tag-grid button.sending .tag-mark svg.i { animation: send-pulse 1s ease-in-out infinite; }

/* this tab's own sends: a small status mark beside the bubble */
.send-mark { flex: none; align-self: flex-end; display: inline-grid; place-items: center; width: 16px; height: 16px; margin: 0 0 4px -4px; color: var(--muted); }
.send-mark svg.i { width: 14px; height: 14px; }
.send-mark.sent { color: var(--accent); }
.send-mark.failed { color: var(--danger); }
.send-mark.sending svg.i { animation: send-pulse 1s ease-in-out infinite; }
.row.pending .bubble { opacity: .72; }
.row.pending.failed { cursor: pointer; }
.row.pending.failed .bubble { opacity: 1; box-shadow: inset 0 0 0 1.5px var(--danger); }
.row.pending.failed .mt { color: var(--danger); }
.bubble.flow svg.i { width: 14px; height: 14px; vertical-align: -2px; }
@keyframes send-pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .send-mark.sending svg.i, .tag-grid button.sending .tag-mark svg.i { animation: none; } }

.composer { position: relative; background: var(--panel); border-top: 1px solid var(--line); padding: 8px 10px 6px; display: grid; gap: 4px; }
.qr-menu { position: absolute; left: 8px; right: 8px; bottom: 100%; margin-bottom: 4px; max-height: 320px; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-lg); z-index: 20; padding: 4px; }
.qr-item { padding: 6px 8px; border-radius: 6px; cursor: pointer; display: grid; gap: 2px; }
.qr-item.active, .qr-item:hover { background: var(--accent-soft); }
.qr-head { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.qr-head .pill { height: 16px; padding: 0 6px; font-size: 10px; }
.qr-text { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qr-empty { padding: 8px; font-size: 12px; color: var(--muted); }
.composer textarea { border: 0; resize: none; padding: 6px 4px; min-height: 34px; max-height: 160px; overflow-y: hidden; box-shadow: none !important; background: transparent; }
.composer-bar { display: flex; align-items: center; gap: 2px; }
.send-btn { width: 38px; height: 34px; border: 0; border-radius: 8px; background: transparent; color: var(--accent); cursor: pointer; display: inline-grid; place-items: center; }
.send-btn:hover { background: var(--accent-soft); }
.send-btn svg.i { width: 22px; height: 22px; }

/* ---------- side panel ---------- */
.side-pane { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.side-tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.side-tab { flex: 1; border: 0; background: transparent; padding: 14px 4px 12px; cursor: pointer; color: var(--text-2); border-bottom: 2px solid transparent; font-weight: 500; font-size: 13px; white-space: nowrap; }
.side-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.side-close { display: none; align-self: center; margin-right: 6px; }
.count { display: inline-grid; place-items: center; min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px; font-size: 11px; background: var(--danger); color: #fff; }
.side-body { flex: 1; overflow-y: auto; padding: 14px; }
.section { margin-bottom: 18px; }
.section h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.order-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.order-heading h4 { margin: 0; }
.order-notice { margin-bottom: 8px; }
.order-card { margin-bottom: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.order-card summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px; cursor: pointer; font-weight: 600; }
.order-content { display: grid; gap: 5px; padding: 0 9px 9px; overflow-wrap: anywhere; }
.order-history { display: grid; gap: 4px; border-top: 1px solid var(--line); padding-top: 7px; }
.profile { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.profile .avatar { width: 52px; height: 52px; }
.profile .pname { font-weight: 700; font-size: 15px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stat { background: var(--panel-2); border-radius: 10px; padding: 8px; text-align: center; }
.stat b { display: block; font-size: 17px; }
.stat span { font-size: 11px; color: var(--muted); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; font-size: 13px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }

.ai-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.run { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; display: grid; gap: 6px; }
.run.suggested { border-color: var(--accent); }
.run .head { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; align-items: center; }
.run .code { font-weight: 700; font-size: 13px; }
.run textarea { font-size: 13px; }
.run .replies { font-size: 13px; display: grid; gap: 3px; }
.run .replies div { background: var(--panel-2); border-radius: 8px; padding: 4px 8px; }
.run .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.status { flex: none; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--panel-2); color: var(--text-2); }
.status.suggested { background: var(--accent-soft); color: var(--accent); }
.status.sent { color: var(--ok); }
.status.error, .status.aborted { color: var(--danger); }

/* ---------- modal / misc ---------- */
.modal { width: min(1000px, calc(100vw - 24px)); max-width: none; max-height: calc(100dvh - 24px); border: 0; border-radius: 14px; padding: 0; background: var(--panel); color: var(--text); box-shadow: var(--shadow-lg); }
.modal::backdrop { background: rgba(10,16,22,.45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px 10px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px; overflow: auto; max-height: calc(100dvh - 90px); display: grid; gap: 14px; }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 10px; }
.card h3 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.field { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.field > input, .field > select, .field > textarea { color: var(--text); font-size: 14px; }
.check { display: flex; gap: 6px; align-items: center; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { border-bottom: 1px solid var(--line); padding: 6px; text-align: left; vertical-align: top; }
.table tr.click { cursor: pointer; }
.table tr.click:hover td { background: var(--hover); }
.stack { display: grid; gap: 10px; }
.kb-row { display: grid; gap: 6px; border: 1px dashed var(--line); border-radius: 8px; padding: 8px; }
.table-wrap { overflow-x: auto; }
/* settings */
.set-tabs { display: flex; gap: 6px; flex-wrap: wrap; position: sticky; top: -16px; z-index: 2; margin: -16px -16px 0; padding: 12px 16px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.set-body { display: grid; gap: 14px; }
.seg-ctl { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex: none; }
.seg-ctl button { border: 0; background: var(--panel); color: var(--text-2); padding: 5px 12px; font-size: 13px; cursor: pointer; }
.seg-ctl button + button { border-left: 1px solid var(--line); }
.seg-ctl button.on { background: var(--accent); color: var(--accent-ink); }
.group-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.group-head .gname { flex: 1; min-width: min(200px, 100%); font-size: 16px; font-weight: 600; }
.group-head select { width: auto; }
.group-pages { display: inline-flex; gap: 3px; align-items: center; }
.phase-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 8px 16px; }
.phase-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; }
.pp-mini { width: 24px; height: 24px; border-radius: 50%; overflow: hidden; display: inline-grid; place-items: center; background: var(--line); flex: none; }
.pp-mini img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pp-mini .pp-fallback { color: var(--text-2); font-size: 9px; }
details.set-more > summary { cursor: pointer; font-size: 13px; color: var(--text-2); font-weight: 600; }
details.set-more[open] > summary { margin-bottom: 10px; }
.kb-toolbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.kb-groups { display: flex; gap: 6px; flex-wrap: wrap; }
.kb-products { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); gap: 12px; }
.kb-prod { border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: grid; gap: 8px; background: var(--panel-2); }
.kb-prod-head { display: flex; gap: 6px; align-items: center; }
.kb-prod-head input { flex: 1; font-weight: 600; }
.page-cell { display: flex; gap: 8px; align-items: center; }
.flow-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-bottom: 1px solid var(--line-2); }
.bc-page { display: grid; gap: 6px; padding: 8px; border: 1px dashed var(--line); border-radius: 8px; }
.prompt-pre { margin: 0; max-height: 60vh; overflow: auto; white-space: pre-wrap; word-break: break-word; font: 12px/1.5 ui-monospace, Consolas, monospace; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.prompt-note { padding: 8px 10px; border-radius: 8px; background: var(--accent-soft); color: var(--text); font-size: 13px; }
.sticky-actions { position: sticky; bottom: -16px; margin: 0 -16px -16px; padding: 10px 16px; background: var(--panel); border-top: 1px solid var(--line); }
.table.kb { min-width: 980px; }
.table.kb td { min-width: 90px; }
.table.kb td:nth-child(4), .table.kb td:nth-child(5) { min-width: 240px; }
.table textarea, .table input[type=text] { font-size: 13px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1f2a33; color: #fff; padding: 9px 16px; border-radius: 10px; z-index: 60; max-width: calc(100vw - 32px); box-shadow: var(--shadow-lg); font-size: 13px; }
.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.85); display: grid; place-items: center; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 92vh; border-radius: 8px; }

/* ---------- responsive ---------- */
@media (max-width: 1280px) {
  .workspace { grid-template-columns: 374px minmax(0, 1fr); }
  .side-pane { position: fixed; right: 0; top: 56px; bottom: 0; width: min(380px, 100vw); z-index: 30; box-shadow: var(--shadow-lg); transform: translateX(105%); transition: transform .18s ease; }
  .side-pane:not(.open) { visibility: hidden; transition: transform .18s ease, visibility 0s .18s; }
  .side-pane.open { transform: none; box-shadow: 0 0 0 100vmax rgba(10,16,22,.35); }
  .side-close { display: inline-grid; }
}
@media (max-width: 820px) {
  /* header: row 1 = logo · tabs · sync · logout, row 2 = full-width page strip */
  .topbar { height: auto; flex-wrap: wrap; row-gap: 4px; gap: 6px; padding: 6px 8px 4px; padding-top: max(6px, env(safe-area-inset-top)); }
  .top-right { display: contents; }
  .brand-name { display: none; }
  .logo-mark { width: 28px; height: 28px; }
  .topnav .nav-item { padding: 7px 10px; font-size: 14px; }
  .nav-item .long { display: none; }
  .nav-item .short { display: inline; }
  /* connection status: just the coloured dot (details stay in its tooltip / the sync-history modal) */
  .sync-chip { margin-left: auto; width: 26px; height: 26px; padding: 0; justify-content: center; }
  .sync-chip .sync-text { display: none; }
  .page-picker { order: 10; flex: 1 0 100%; max-width: none; padding: 2px 0 4px; }
  .app.in-chat .page-picker { display: none; }
  .pp-page { width: 32px; height: 32px; }
  .pp-all { height: 32px; }
  /* list head: filters · search button · refresh on one row; the search box opens above them */
  .list-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
  .list-toolbar, .seg { display: contents; }
  .seg-item { flex: none; }
  .list-head .search { display: none; order: -1; flex: 1 0 100%; margin-bottom: 2px; }
  .list-head.searching .search { display: flex; }
  .search-toggle { display: inline-grid; order: 1; margin-left: auto; }
  #btn-refresh { order: 2; }
  /* scrolling the list down tucks away the filters and page strip (see the #conv-list scroll handler) */
  .list-head, .page-picker { max-height: 120px; transition: max-height .2s ease, padding .2s ease, margin .2s ease, opacity .15s ease; }
  .app.list-scrolled:not(.in-chat) .list-head, .app.list-scrolled:not(.in-chat) .page-picker { max-height: 0; padding-top: 0; padding-bottom: 0; opacity: 0; overflow: hidden; pointer-events: none; }
  .app.list-scrolled:not(.in-chat) .list-head { border-bottom-width: 0; }
  .app.list-scrolled:not(.in-chat) .page-picker { margin-top: -4px; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .chat-pane { display: none; }
  .app.in-chat .list-pane { display: none; }
  .app.in-chat .chat-pane { display: flex; }
  .back { display: inline-grid; }
  .icon-btn { width: 38px; height: 38px; }
  .chat-head { padding: 6px 8px; gap: 6px; min-height: 56px; }
  .messages { padding: 10px 10px 6px; }
  .row { max-width: 88%; }
  .bubble { font-size: 15px; }
  .bubble img, .bubble video.media, .bubble audio.media, .bubble .file-chip { max-width: min(240px, 62vw); }
  .suggest-bar { margin: 0 8px 6px; }
  .suggest-bar ol { max-height: 22vh; }
  .suggest-bar .sb-head { flex-wrap: wrap; }
  .suggest-bar .btn.small, .run .btn.small, .ai-actions .btn.small { padding: 6px 12px; font-size: 13px; }
  .composer { padding: 6px 8px; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .grid2 { grid-template-columns: 1fr; }
  .side-pane { top: 0; width: 100vw; }
  .side-tab { padding: 12px 2px 10px; }
  .side-body { padding: 12px; }
  .kv { grid-template-columns: 100px minmax(0, 1fr); }
  /* modals become full-screen sheets so the title + close button can never be pushed off-screen */
  .modal { width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  .modal[open] { display: flex; flex-direction: column; }
  .modal-head { flex: none; padding: 6px 6px 6px 14px; padding-top: max(6px, env(safe-area-inset-top)); }
  .modal-body { flex: 1; max-height: none; min-height: 0; padding: 12px; align-content: start; grid-auto-rows: max-content; }
  .table.pages thead { display: none; }
  .table.pages tr { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 6px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .table.pages td { display: block; border: 0; padding: 0; }
  .table.pages td:first-child { grid-column: 1 / -1; }
  .set-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; top: -12px; margin: -12px -12px 0; padding: 10px 12px 8px; }
  .set-tabs .seg-item { flex: none; }
  .sticky-actions { bottom: -12px; margin: 0 -12px -12px; padding: 10px 12px; }
  .card { padding: 10px; }
  .sync-controls select { min-width: 0; }
  /* 16px inputs: iOS Safari zooms the page when focusing anything smaller */
  input[type=text], input[type=password], input[type=search], select, textarea,
  .field > input, .field > select, .field > textarea, .table textarea, .table input[type=text], .run textarea { font-size: 16px; }
}
@media (max-width: 380px) {
  .topnav .nav-item { padding: 7px 7px; font-size: 13px; }
}

/* settings: readable headings/labels, inputs sized to their content instead of the full modal width */
.set-body .card h3 { font-size: 15px; font-weight: 600; text-transform: none; letter-spacing: 0; color: var(--text); }
.set-body .card > p.muted { margin: -4px 0 0; }
.set-body .field > span:first-child { font-size: 13px; font-weight: 600; color: var(--text-2); }
.set-body details.set-more > summary { font-size: 14px; color: var(--text); }
.set-body select { width: auto; min-width: 200px; max-width: 100%; justify-self: start; }
.set-body input[type=number] { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 10px; width: 100%; outline: none; }
.set-body .grid2 { align-items: start; }
.set-sub { margin: 6px 0 -2px; font-size: 13px; font-weight: 700; color: var(--text); padding-bottom: 4px; border-bottom: 1px solid var(--line-2); }
.form-row { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: start; }
.field.f-sm { width: min(220px, 100%); }
.field.f-md { width: min(300px, 100%); }
.field.f-lg { width: min(460px, 100%); }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 10px; align-items: end; }
.row-actions.end { justify-content: flex-end; align-items: center; }
.sticky-actions { justify-content: flex-end; align-items: center; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.chip-label { font-size: 13px; color: var(--muted); align-self: center; margin-right: 2px; }
.ai-mode-row { display: flex; align-items: center; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; padding: 12px 14px; border-radius: 12px; background: var(--panel-2); }
.ai-mode-row b { font-size: 15px; }
.tok-box { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 44px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); cursor: text; }
.tok-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tok { display: inline-flex; align-items: center; gap: 2px; max-width: 100%; padding: 3px 4px 3px 10px; border-radius: 999px; background: var(--panel-2); color: var(--text); font-size: 13px; line-height: 1.3; }
.tok.ai { background: var(--accent-soft); color: var(--accent); }
.tok-x { border: 0; background: transparent; color: inherit; opacity: .55; width: 20px; height: 20px; border-radius: 50%; font-size: 15px; line-height: 1; cursor: pointer; padding: 0; }
.tok-x:hover { opacity: 1; background: rgba(0,0,0,.08); }
.tok-box input.tok-input { flex: 1 0 140px; width: auto; min-width: 0; border: 0 !important; background: transparent !important; box-shadow: none !important; padding: 4px; }
.ai-mix { display: grid; gap: 4px; padding: 8px 10px; border-radius: 8px; background: var(--panel-2); font-size: 13px; }
.ai-mix .warn { color: var(--warn); }
.kb-prod-head { justify-content: space-between; }
.kb-prod-head input { flex: 0 1 460px; }
.group-head .gname { flex: 0 1 360px; }
/* desktop: settings get a wider fixed-height window with the tabs as a left menu; only the content scrolls */
@media (min-width: 1100px) {
  .modal:has(.set-tabs) { width: min(1240px, calc(100vw - 48px)); }
  .modal-body:has(> .set-tabs) { padding: 0; gap: 0; overflow: hidden; height: min(900px, calc(100dvh - 80px)); grid-template-columns: 210px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .set-tabs { position: static; flex-direction: column; flex-wrap: nowrap; gap: 2px; margin: 0; padding: 14px 10px; overflow-y: auto; border-bottom: 0; border-right: 1px solid var(--line); background: var(--panel-2); }
  .set-tabs .seg-item { border: 0; background: transparent; border-radius: 8px; text-align: left; padding: 9px 12px; font-size: 14px; color: var(--text-2); }
  .set-tabs .seg-item:hover { background: var(--hover); }
  .set-tabs .seg-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .set-body { overflow-y: auto; padding: 20px 24px; align-content: start; gap: 16px; }
  .set-body .card { padding: 16px 18px; gap: 12px; }
  .set-body .sticky-actions { bottom: -20px; margin: 0 -24px -20px; padding: 12px 24px; }
}

/* every sheet (activity, sync history, socket log, settings) is an iOS sheet: grouped cards on the grey background */
.modal.ios :is(.modal-body, .sync-live) > h3 { margin: 10px 4px -6px; font-size: 12px; font-weight: 400; text-transform: uppercase; letter-spacing: .03em; color: var(--ios-label-2); }
.modal.ios .modal-body > p, .modal.ios .sync-live > p { margin: -4px 4px 0; }
.modal.ios :is(.sync-controls, .mode-box, .bridge-box, .sync-sum > div) { background: var(--ios-card); border: 0; border-radius: 12px; }
.modal.ios .sync-controls { padding: 12px 16px; gap: 12px 16px; }
.modal.ios .sync-controls select { min-width: 150px; }
.modal.ios .mode-box { padding: 14px 16px; gap: 10px; }
.modal.ios .sync-sum > div { display: grid; gap: 2px; padding: 12px 16px; }
.modal.ios .sync-sum b { font-size: 17px; font-weight: 600; letter-spacing: -.02em; }
.modal.ios .ctl-sep { background: var(--ios-sep); }
.modal.ios .kv dt { color: var(--ios-label-2); }
.modal.ios .table { background: var(--ios-card); border-radius: 12px; border-collapse: separate; border-spacing: 0; overflow: hidden; }
.modal.ios .table :is(th, td) { padding: 8px 10px; }
.modal.ios .table :is(th, td):first-child { padding-left: 16px; }
.modal.ios .table :is(th, td):last-child { padding-right: 16px; }
.modal.ios .table tr:last-child td { border-bottom: 0; }
.modal.ios .table th { font-size: 12px; font-weight: 600; }
.modal.ios .card .table { background: transparent; border-radius: 0; }
.modal.ios .card .table :is(th, td):first-child { padding-left: 6px; }
.modal.ios .table-wrap { border-radius: 12px; }
.modal.ios .frame { background: var(--ios-card); border: 0; border-radius: 10px; }
.modal.ios .frame-json { background: var(--ios-nest); border-top: .5px solid var(--ios-sep); }
.modal.ios .status { background: var(--ios-fill); }
/* tables in sheets: headers and statuses never wrap; only the last column (content / errors with long URLs) breaks anywhere */
.modal.ios .table th, .modal.ios .status { white-space: nowrap; }
.modal.ios .table td:last-child { overflow-wrap: anywhere; }
.modal.ios .sync-live .table td:first-child { min-width: 150px; }

/* ---------- settings in iOS 17 style (the modal gets .ios only while Cài đặt is open) ---------- */
.modal.ios {
  --ios-bg: #f2f2f7; --ios-card: #ffffff; --ios-nest: #f2f2f7; --ios-fill: rgba(118,118,128,.12); --ios-fill-2: rgba(118,118,128,.08);
  --ios-switch: #e9e9eb; --ios-sep: rgba(60,60,67,.18); --ios-label: #000000; --ios-label-2: rgba(60,60,67,.62); --ios-label-3: rgba(60,60,67,.32);
  --ios-blue: #007aff; --ios-blue-soft: rgba(0,122,255,.1); --ios-green: #34c759; --ios-red: #ff3b30; --ios-orange: #ff9500; --ios-seg-on: #ffffff; --ios-bar: rgba(249,249,249,.86);
  background: var(--ios-bg); color: var(--ios-label); border-radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .modal.ios {
    --ios-bg: #000000; --ios-card: #1c1c1e; --ios-nest: #2c2c2e; --ios-fill: rgba(118,118,128,.24); --ios-fill-2: rgba(118,118,128,.18);
    --ios-switch: #39393d; --ios-sep: rgba(84,84,88,.65); --ios-label: #ffffff; --ios-label-2: rgba(235,235,245,.6); --ios-label-3: rgba(235,235,245,.3);
    --ios-blue: #0a84ff; --ios-blue-soft: rgba(10,132,255,.18); --ios-green: #30d158; --ios-red: #ff453a; --ios-orange: #ff9f0a; --ios-seg-on: #636366; --ios-bar: rgba(22,22,24,.86);
  }
}
:root[data-theme="dark"] .modal.ios {
  --ios-bg: #000000; --ios-card: #1c1c1e; --ios-nest: #2c2c2e; --ios-fill: rgba(118,118,128,.24); --ios-fill-2: rgba(118,118,128,.18);
  --ios-switch: #39393d; --ios-sep: rgba(84,84,88,.65); --ios-label: #ffffff; --ios-label-2: rgba(235,235,245,.6); --ios-label-3: rgba(235,235,245,.3);
  --ios-blue: #0a84ff; --ios-blue-soft: rgba(10,132,255,.18); --ios-green: #30d158; --ios-red: #ff453a; --ios-orange: #ff9f0a; --ios-seg-on: #636366; --ios-bar: rgba(22,22,24,.86);
}
/* sheet header: translucent bar, centred title, round grey close button */
.modal.ios .modal-head { position: relative; justify-content: center; min-height: 52px; background: var(--ios-bar); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-bottom: .5px solid var(--ios-sep); }
.modal.ios .modal-head h2 { font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.modal.ios #modal-close { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; border-radius: 50%; background: var(--ios-fill); color: var(--ios-label-2); }
.modal.ios #modal-close svg.i { width: 15px; height: 15px; stroke-width: 2.6; }
.modal.ios .modal-body { background: var(--ios-bg); }
.modal.ios .muted { color: var(--ios-label-2); }
.modal.ios .small, .modal.ios .muted.small { font-size: 13px; }
.modal.ios .error { color: var(--ios-red); }

/* tab menu: icon tiles like the Settings app */
.modal.ios .set-ico { width: 29px; height: 29px; border-radius: 7px; display: inline-grid; place-items: center; color: #fff; flex: none; }
.modal.ios .set-ico svg.i { width: 18px; height: 18px; stroke-width: 2; }
.modal.ios .set-tabs-sep { display: none; }
.modal.ios .set-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; background: var(--ios-bar); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-bottom: .5px solid var(--ios-sep); }
.modal.ios .set-tabs .seg-item { flex: none; white-space: nowrap; }
.modal.ios .table.pages td { vertical-align: middle; }
.modal.ios .set-tabs .seg-item { display: inline-flex; align-items: center; gap: 8px; border: 0; background: var(--ios-card); color: var(--ios-label); border-radius: 10px; padding: 5px 12px 5px 5px; font-size: 14px; }
.modal.ios .set-tabs .seg-item .set-ico { width: 24px; height: 24px; border-radius: 6px; }
.modal.ios .set-tabs .seg-item .set-ico svg.i { width: 15px; height: 15px; }
.modal.ios .set-tabs .seg-item.active { background: var(--ios-blue); color: #fff; font-weight: 600; }
@media (min-width: 1100px) {
  .modal.ios .modal-body:has(> .set-tabs) { grid-template-columns: 240px minmax(0, 1fr); }
  .modal.ios .set-tabs { overflow-x: hidden; background: var(--ios-bg); backdrop-filter: none; -webkit-backdrop-filter: none; border-bottom: 0; border-right: .5px solid var(--ios-sep); padding: 16px 14px; gap: 0; }
  .modal.ios .set-tabs-sep { display: block; padding: 22px 16px 7px; font-size: 13px; color: var(--ios-label-2); text-transform: uppercase; letter-spacing: .02em; }
  .modal.ios .set-tabs .seg-item { position: relative; display: flex; width: 100%; gap: 12px; min-height: 44px; padding: 7px 12px; font-size: 15px; border-radius: 0; }
  .modal.ios .set-tabs .seg-item .set-ico { width: 29px; height: 29px; border-radius: 7px; }
  .modal.ios .set-tabs .seg-item .set-ico svg.i { width: 18px; height: 18px; }
  .modal.ios .set-tabs .seg-item + .seg-item::before { content: ""; position: absolute; top: 0; left: 53px; right: 0; height: .5px; background: var(--ios-sep); }
  .modal.ios .set-tabs .seg-item:first-child, .modal.ios .set-tabs-sep + .seg-item { border-radius: 12px 12px 0 0; }
  .modal.ios .set-tabs .seg-item:last-child, .modal.ios .set-tabs .seg-item:has(+ .set-tabs-sep) { border-radius: 0 0 12px 12px; }
  .modal.ios .set-tabs .seg-item:hover:not(.active) { background: color-mix(in srgb, var(--ios-card) 92%, var(--ios-label)); }
  .modal.ios .set-tabs .seg-item.active { border-radius: 10px; font-weight: 600; }
  .modal.ios .set-tabs .seg-item.active::before, .modal.ios .set-tabs .seg-item.active + .seg-item::before { display: none; }
  .modal.ios .set-body { padding: 22px 28px; gap: 18px; }
}

/* inset grouped cards */
.modal.ios .card { background: var(--ios-card); border: 0; border-radius: 12px; padding: 16px 18px; gap: 12px; }
.modal.ios .set-body .card h3 { font-size: 17px; font-weight: 600; letter-spacing: -.01em; color: var(--ios-label); }
.modal.ios .set-sub { margin: 10px 0 -4px; padding: 0; border: 0; font-size: 13px; font-weight: 400; color: var(--ios-label-2); text-transform: uppercase; letter-spacing: .02em; }
.modal.ios .set-body .field { color: var(--ios-label-2); }
.modal.ios .set-body .field > span:first-child { font-size: 13px; font-weight: 500; color: var(--ios-label-2); }
.modal.ios .tok-box { border: 0; background: var(--ios-card); border-radius: 10px; }
.modal.ios .tok-box:focus-within { box-shadow: 0 0 0 3px var(--ios-blue-soft), 0 0 0 1px var(--ios-blue); }
.modal.ios .tok { background: var(--ios-fill); color: var(--ios-label); }
.modal.ios .tok.ai { background: var(--ios-blue-soft); color: var(--ios-blue); }
.modal.ios .ai-mode-row { background: var(--ios-nest); }
.modal.ios .kb-prod, .modal.ios .bc-page, .modal.ios .ai-mix, .modal.ios .kb-row { background: var(--ios-nest); border: 0; border-radius: 12px; }
.modal.ios .bc-page { padding: 14px; gap: 10px; }
.modal.ios .kb-prod { padding: 14px; }

/* text fields: filled, borderless */
.modal.ios input[type=text], .modal.ios input[type=password], .modal.ios input[type=number], .modal.ios input[type=search], .modal.ios select, .modal.ios textarea {
  background: var(--ios-fill-2); border: 0; border-radius: 10px; padding: 10px 12px; font-size: 15px; color: var(--ios-label); box-shadow: none; transition: background .15s, box-shadow .15s;
}
.modal.ios textarea { resize: vertical; line-height: 1.45; }
.modal.ios :is(.kb-prod, .v2-stage, .bc-page, .ai-mix) :is(input[type=text], input[type=password], input[type=number], select, textarea) { background: var(--ios-card); }
.modal.ios :is(input, select, textarea):focus { background: var(--ios-card); box-shadow: 0 0 0 3px var(--ios-blue-soft), 0 0 0 1px var(--ios-blue); }
.modal.ios ::placeholder { color: var(--ios-label-3); }
.modal.ios select { appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='16' fill='none' stroke='%238e8e93' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 6 6 2.5 9.5 6M2.5 10 6 13.5 9.5 10'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.modal.ios .mono { font-size: 13px; }

/* segmented control */
.modal.ios .seg-ctl { background: var(--ios-fill); border: 0; border-radius: 9px; padding: 2px; gap: 0; }
.modal.ios .seg-ctl button { background: transparent; border: 0; border-radius: 7px; color: var(--ios-label); padding: 5px 16px; font-size: 13px; font-weight: 500; transition: background .2s, box-shadow .2s; }
.modal.ios .seg-ctl button + button { border-left: 0; }
.modal.ios .seg-ctl button.on { background: var(--ios-seg-on); color: var(--ios-label); font-weight: 600; box-shadow: 0 3px 8px rgba(0,0,0,.12), 0 3px 1px rgba(0,0,0,.04); }

/* buttons: filled blue for the main action, grey-tinted otherwise */
.modal.ios .btn { border: 0; background: var(--ios-fill); color: var(--ios-blue); border-radius: 10px; padding: 8px 14px; font-size: 15px; font-weight: 500; }
.modal.ios .btn:hover { background: color-mix(in srgb, var(--ios-fill) 100%, var(--ios-label) 6%); }
.modal.ios .btn.primary { background: var(--ios-blue); color: #fff; font-weight: 600; padding: 9px 20px; border-radius: 12px; }
.modal.ios .btn.primary:hover { background: color-mix(in srgb, var(--ios-blue) 88%, #000); }
.modal.ios .btn.small { padding: 6px 12px; font-size: 14px; }
.modal.ios .btn.danger { color: var(--ios-red); }
.modal.ios .btn:disabled { opacity: .4; cursor: default; }
.modal.ios .icon-btn:not(#modal-close) { color: var(--ios-label-2); border-radius: 50%; }

/* checkboxes become switches */
.modal.ios .check { gap: 10px; font-size: 15px; color: var(--ios-label); cursor: pointer; }
.modal.ios .check input[type=checkbox] { appearance: none; -webkit-appearance: none; position: relative; flex: none; width: 51px; height: 31px; margin: 0; border-radius: 16px; background: var(--ios-switch); cursor: pointer; transition: background .2s; }
.modal.ios .check input[type=checkbox]::before { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 3px 8px rgba(0,0,0,.15), 0 3px 1px rgba(0,0,0,.06); transition: transform .2s; }
.modal.ios .check input[type=checkbox]:checked { background: var(--ios-green); }
.modal.ios .check input[type=checkbox]:checked::before { transform: translateX(20px); }
.modal.ios .check input[type=checkbox]:focus-visible { box-shadow: 0 0 0 3px var(--ios-blue-soft); }

/* disclosure rows */
.modal.ios details.set-more > summary { list-style: none; display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; color: var(--ios-label); }
.modal.ios details.set-more > summary::-webkit-details-marker { display: none; }
.modal.ios details.set-more > summary::before { content: ""; width: 7px; height: 7px; flex: none; border-right: 2px solid var(--ios-label-3); border-bottom: 2px solid var(--ios-label-3); transform: rotate(-45deg); transition: transform .2s; margin: 0 2px; }
.modal.ios details.set-more[open] > summary::before { transform: rotate(45deg); }

/* group chips, tables, notes, save bar */
.modal.ios .set-body .kb-groups .seg-item { border: 0; background: var(--ios-card); color: var(--ios-label); border-radius: 999px; padding: 6px 14px; font-size: 14px; }
.modal.ios .set-body .kb-groups .seg-item.active { background: var(--ios-blue); color: #fff; font-weight: 600; }
.modal.ios .chip-label { color: var(--ios-label-2); font-size: 13px; }
.modal.ios .table th { font-size: 13px; font-weight: 500; color: var(--ios-label-2); }
.modal.ios .table th, .modal.ios .table td { border-bottom: .5px solid var(--ios-sep); }
.modal.ios .prompt-note { background: var(--ios-blue-soft); color: var(--ios-label); border-radius: 10px; }
.modal.ios .prompt-pre { background: var(--ios-nest); border: 0; border-radius: 10px; }
.modal.ios .ai-mix .warn { color: var(--ios-orange); }
.modal.ios .sticky-actions { background: var(--ios-bar); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-top: .5px solid var(--ios-sep); }
.modal.ios .group-head .gname { font-size: 17px; font-weight: 600; }
@media (max-width: 820px) {
  .modal.ios { border-radius: 0; }
  .modal.ios :is(input[type=text], input[type=password], input[type=number], select, textarea) { font-size: 16px; }
}
