/* Bein Chat: minimal, compact, mobile first. One accent, soft borders, small controls, icon buttons. */
:root {
  --bg: #0d0e11; --surface: #14161a; --surface-2: #1b1e24; --hover: rgba(255,255,255,.06); --border: rgba(255,255,255,.09);
  --fg: #e8e9ed; --muted: #8b92a0; --faint: #5c6270;
  --accent: #8aa4ff; --accent-fg: #0a0d18; --accent-soft: rgba(138,164,255,.14);
  --ok: #4cc38a; --bad: #f2706f; --warn: #e9b949;
  --r-sm: 8px; --r-md: 12px; --r-lg: 18px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --ctl: 32px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #ffffff; --surface: #f7f7f8; --surface-2: #efeff2; --hover: rgba(0,0,0,.05); --border: rgba(0,0,0,.09);
    --fg: #17181c; --muted: #6a7080; --faint: #9aa0ad; --accent: #3b5bdb; --accent-fg: #fff; --accent-soft: rgba(59,91,219,.1);
    --ok: #168a58; --bad: #cc3b3b; --warn: #a56d00; color-scheme: light; }
}
:root[data-theme="dark"] { --bg: #0d0e11; --surface: #14161a; --surface-2: #1b1e24; --hover: rgba(255,255,255,.06); --border: rgba(255,255,255,.09); --fg: #e8e9ed; --muted: #8b92a0; --faint: #5c6270; --accent: #8aa4ff; --accent-fg: #0a0d18; --accent-soft: rgba(138,164,255,.14); --ok: #4cc38a; --bad: #f2706f; --warn: #e9b949; color-scheme: dark; }
:root[data-theme="light"] { --bg: #ffffff; --surface: #f7f7f8; --surface-2: #efeff2; --hover: rgba(0,0,0,.05); --border: rgba(0,0,0,.09); --fg: #17181c; --muted: #6a7080; --faint: #9aa0ad; --accent: #3b5bdb; --accent-fg: #fff; --accent-soft: rgba(59,91,219,.1); --ok: #168a58; --bad: #cc3b3b; --warn: #a56d00; color-scheme: light; }
:root[data-size="small"] { font-size: 14px; } :root[data-size="large"] { font-size: 17px; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 15px; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--fg); font: 1rem/1.55 var(--font); overscroll-behavior: none; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; pointer-events: none; }
svg.i.fill { fill: currentColor; stroke: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- controls ---------- */
button, input, textarea, select { font: inherit; color: inherit; }
button { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--ctl); padding: 0 12px; border: 1px solid var(--border); border-radius: var(--r-sm);
  background: transparent; font-size: .9rem; line-height: 1; cursor: pointer; touch-action: manipulation; transition: background-color .12s, border-color .12s, color .12s, opacity .12s; white-space: nowrap; }
button:hover { background: var(--hover); }
button:active { background: var(--surface-2); }
button:disabled { opacity: .45; cursor: default; }
/* a 44px touch target without a 44px look */
button::after { content: ""; position: absolute; inset: -6px -4px; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: transparent; font-weight: 600; }
button.primary:hover { background: color-mix(in srgb, var(--accent) 88%, #fff); }
button.danger { color: var(--bad); }
button.ghost, .ibtn, .linkbtn, .conv .more { border-color: transparent; }
.ibtn { width: 34px; padding: 0; color: var(--muted); }
.ibtn:hover { color: var(--fg); }
.linkbtn { min-height: 0; height: 22px; padding: 0 6px; font-size: .8rem; color: var(--muted); border-radius: 6px; }
.linkbtn:hover { color: var(--accent); background: var(--accent-soft); }
a.btn { display: inline-flex; align-items: center; justify-content: center; min-height: var(--ctl); padding: 0 12px; border: 1px solid var(--border); border-radius: var(--r-sm); color: var(--fg); text-decoration: none; font-size: .9rem; }
a.btn:hover { background: var(--hover); }
input[type=text], input[type=password], input[type=search], input[type=url], input[type=number], input:not([type]), select, textarea {
  min-height: var(--ctl); padding: 0 10px; border: 1px solid var(--border); border-radius: var(--r-sm); background: transparent; outline: none; transition: border-color .12s, background-color .12s; }
input:focus, select:focus, textarea:focus { border-color: color-mix(in srgb, var(--accent) 70%, transparent); background: var(--surface); }
input::placeholder, textarea::placeholder { color: var(--faint); }
select { appearance: none; padding-right: 26px; cursor: pointer; background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b92a0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 7px center / 14px; }
select option { background: var(--surface); color: var(--fg); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); min-height: 0; }
.err { color: var(--bad); min-height: 1.2em; margin: 0; font-size: .85rem; }
.muted { color: var(--muted); font-size: .85rem; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.pill { font-size: .72rem; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
code { font: .86em var(--mono); background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }
h3 { margin: 18px 0 8px; font-size: .75rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); }

/* ---------- login ---------- */
#login { height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
#loginForm { width: 100%; max-width: 320px; display: grid; gap: 10px; }
#loginForm h1 { margin: 0 0 6px; font-size: 1.4rem; letter-spacing: -.02em; }
#loginForm input { min-height: 38px; }
#loginForm button { min-height: 38px; }

/* ---------- shell ---------- */
#app { display: flex; height: var(--vvh, 100dvh); }
main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
#top { display: flex; align-items: center; gap: 4px; min-height: 48px; padding: 4px 8px; padding-top: max(4px, env(safe-area-inset-top)); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); z-index: 4; }
.titlebox { flex: 1; min-width: 0; display: grid; padding-left: 4px; }
#top h1 { margin: 0; font-size: .95rem; font-weight: 600; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.25; }
.subtitle { justify-self: start; max-width: 100%; min-height: 0; height: 18px; padding: 0; border: 0; border-radius: 4px; color: var(--muted); font-size: .75rem; overflow: hidden; text-overflow: ellipsis; }
.subtitle::after { inset: -6px -8px; }
.subtitle:hover { background: transparent; color: var(--fg); }
#model { height: 28px; min-height: 28px; max-width: 34vw; border-color: transparent; color: var(--muted); font-size: .8rem; padding: 0 22px 0 8px; text-overflow: ellipsis; }
#model:hover { background-color: var(--hover); color: var(--fg); }
#previewBtn { min-height: 28px; height: 28px; padding: 0 10px; border: 0; background: var(--accent-soft); color: var(--accent); font-size: .78rem; font-weight: 600; border-radius: 999px; }
#previewBtn:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }
#filesBtn { height: 28px; min-height: 28px; padding: 0 8px; border-color: transparent; color: var(--muted); font-size: .8rem; }
#filesBtn:hover { color: var(--fg); }
#filesBtn .t { display: none; }
#conn { margin: 0 8px 0 4px; }
#portMenu { position: absolute; right: 8px; top: 46px; z-index: 12; display: grid; min-width: 220px; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: 0 12px 32px rgba(0,0,0,.35); }
#portMenu button { justify-content: flex-start; border: 0; min-height: 34px; }

/* ---------- sidebar (a drawer on phones) ---------- */
#side { position: fixed; z-index: 30; inset: 0 auto 0 0; width: min(290px, 86vw); display: flex; flex-direction: column; gap: 8px; padding: 10px; padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--surface); border-right: 1px solid var(--border); transform: translateX(-100%); visibility: hidden; transition: transform .22s cubic-bezier(.2,.8,.2,1), visibility .22s; }
#side.open { transform: none; visibility: visible; }
#scrim { position: fixed; inset: 0; z-index: 29; background: rgba(0,0,0,.5); }
.side-head { display: flex; flex-direction: column; gap: 4px; }
.brand { padding: 4px 6px 6px; font-size: 1rem; letter-spacing: -.02em; }
#newChat { justify-content: flex-start; width: 100%; height: 34px; border-color: transparent; background: var(--hover); font-weight: 500; }
#newChat:hover { background: color-mix(in srgb, var(--fg) 12%, transparent); }
#search { width: 100%; height: 32px; }
#convList { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; margin-inline: -4px; padding-inline: 4px; }
#convList li { border-radius: var(--r-sm); }
#convList li.active { background: var(--hover); }
.conv { display: flex; align-items: center; min-height: 34px; }
.conv .name { flex: 1; min-width: 0; padding: 6px 8px; cursor: pointer; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-radius: var(--r-sm); }
.conv .more { flex: none; width: 28px; min-height: 28px; padding: 0; color: var(--faint); font-size: 1rem; opacity: 0; }
#convList li:hover .more, #convList li.active .more, .conv .more:focus-visible { opacity: 1; }
@media (pointer: coarse) { .conv .more { opacity: .7; } }
.ptag { margin-left: 8px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .7rem; vertical-align: middle; }
.conv-actions { display: flex; gap: 6px; padding: 2px 6px 8px; }
.conv-actions button { flex: 1; min-height: 28px; font-size: .8rem; }
.none { color: var(--faint); padding: 10px 8px; font-size: .85rem; }
.side-foot { display: grid; gap: 2px; padding-top: 6px; border-top: 1px solid var(--border); }
.side-foot button { justify-content: flex-start; height: 30px; min-height: 30px; border-color: transparent; color: var(--muted); font-size: .85rem; padding: 0 8px; }
.side-foot button:hover { color: var(--fg); }
.side-foot .two { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }

/* ---------- feed ---------- */
#feed { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 14px 8px; }
#msgs, #empty { max-width: 720px; margin: 0 auto; }
#msgs > * { margin-bottom: 14px; }
#empty { padding-top: 14vh; text-align: center; color: var(--muted); }
#empty h2 { color: var(--fg); font-size: 1.5rem; letter-spacing: -.02em; margin: 0 0 6px; font-weight: 600; }
#empty p { margin: 0 auto; max-width: 440px; font-size: .92rem; text-wrap: balance; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 18px; }
.chip { height: auto; min-height: 32px; padding: 6px 12px; border-radius: 999px; color: var(--muted); font-size: .85rem; white-space: normal; text-align: left; line-height: 1.3; }
.chip:hover { color: var(--fg); }
#feed.drop { outline: 2px dashed var(--accent); outline-offset: -8px; }

.umsg { display: grid; justify-items: end; gap: 2px; }
.msg-user { width: fit-content; max-width: 88%; padding: 7px 13px; background: var(--surface-2); border-radius: 18px 18px 5px 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.uedit { opacity: 0; } .umsg:hover .uedit, .uedit:focus-visible { opacity: 1; }
@media (pointer: coarse) { .uedit { opacity: .6; } }
.uatt { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: 88%; }
.uatt img { max-width: 220px; max-height: 160px; border-radius: var(--r-md); border: 1px solid var(--border); display: block; }
.msg-assistant { overflow-wrap: anywhere; line-height: 1.65; }
.msg-assistant.streaming::after { content: ""; display: inline-block; width: 6px; height: 1em; margin-left: 2px; vertical-align: text-bottom; border-radius: 2px; background: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.msg-assistant > :first-child { margin-top: 0; } .msg-assistant > :last-child { margin-bottom: 0; }
.msg-assistant p, .msg-assistant ul, .msg-assistant ol, .msg-assistant blockquote { margin: .6em 0; }
.msg-assistant ul, .msg-assistant ol { padding-left: 1.3em; }
.msg-assistant li + li { margin-top: .2em; }
.msg-assistant h1, .msg-assistant h2, .msg-assistant h3, .msg-assistant h4 { margin: 1.1em 0 .4em; line-height: 1.3; letter-spacing: -.01em; text-transform: none; color: var(--fg); font-size: 1rem; font-weight: 600; }
.msg-assistant h1 { font-size: 1.25rem; } .msg-assistant h2 { font-size: 1.12rem; }
.msg-assistant a { color: var(--accent); text-underline-offset: 2px; }
.msg-assistant blockquote { border-left: 2px solid var(--border); padding-left: 12px; color: var(--muted); }
.msg-assistant hr { border: 0; border-top: 1px solid var(--border); }
.codeblock { margin: .7em 0; border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; background: var(--surface); }
.codebar { display: flex; justify-content: space-between; align-items: center; padding: 0 4px 0 12px; height: 30px; color: var(--faint); font-size: .72rem; border-bottom: 1px solid var(--border); }
.codebar .copy { min-height: 24px; height: 24px; padding: 0 8px; font-size: .72rem; border-color: transparent; color: var(--muted); }
.codeblock pre { margin: 0; padding: 10px 12px; overflow-x: auto; }
.codeblock code { background: none; padding: 0; font: .82rem/1.55 var(--mono); }
.tablewrap { overflow-x: auto; margin: .7em 0; }
table { border-collapse: collapse; font-size: .88rem; } th, td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; } th { background: var(--surface); font-weight: 600; }

/* tool cards, verify, permission */
.tool { border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; }
.tool.nested { margin-left: 16px; }
.tool-head { width: 100%; justify-content: flex-start; gap: 10px; height: 34px; min-height: 34px; padding: 0 10px; border: 0; border-radius: 0; text-align: left; }
.tool-head::after { display: none; }
.tool-head .name { font: 600 .78rem var(--mono); color: var(--accent); flex: none; }
.tool-head .sum { flex: 1; min-width: 0; font: .78rem var(--mono); color: var(--muted); overflow: hidden; text-overflow: ellipsis; text-align: left; }
.tool-head .st { flex: none; font-size: .85rem; }
.tool-head .st.run { width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.st.done { color: var(--ok); } .st.error { color: var(--bad); } .st.interrupted { color: var(--faint); }
.tool-body { border-top: 1px solid var(--border); padding: 8px 10px 10px; background: var(--surface); }
.tool-body pre { margin: 0 0 6px; max-height: 40vh; overflow: auto; font: .76rem/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.lbl { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); margin: 6px 0 2px; }
.perm { border: 1px solid color-mix(in srgb, var(--warn) 55%, transparent); border-radius: var(--r-md); padding: 10px 12px; background: color-mix(in srgb, var(--warn) 6%, transparent); }
.perm .q { font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.perm pre { margin: 0 0 8px; padding: 7px 10px; max-height: 30vh; overflow: auto; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm); font: .78rem/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.perm .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.perm .row + .row { margin-top: 6px; }
.perm .row button { height: 30px; min-height: 30px; font-size: .82rem; }
.perm .row button:not(.primary):not(.deny) { border-color: transparent; color: var(--muted); padding: 0 8px; }
.perm .row button:not(.primary):not(.deny):hover { color: var(--fg); }
.perm .deny { color: var(--bad); }
.perm-done { color: var(--muted); font-size: .82rem; }
.notice, .msg-error { padding: 7px 11px; border-radius: var(--r-sm); font: .78rem/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.notice { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.msg-error { background: color-mix(in srgb, var(--bad) 10%, transparent); color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent); }
.meta { color: var(--faint); font-size: .75rem; }
.turn-meta { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.turn-meta .linkbtn:first-of-type { margin-left: 4px; }
.working { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .85rem; }
.working .spin { width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }

/* diffs */
.diff { border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; background: var(--bg); }
.diff-head { display: flex; align-items: center; gap: 8px; padding: 4px 10px; background: var(--surface-2); font: .75rem var(--mono); }
.diff-path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; }
.diff-head .add, .dl.add { color: var(--ok); } .diff-head .del, .dl.del { color: var(--bad); }
.diff-body { max-height: 44vh; overflow: auto; font: .76rem/1.5 var(--mono); }
.dl { padding: 0 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.dl.add { background: color-mix(in srgb, var(--ok) 12%, transparent); } .dl.del { background: color-mix(in srgb, var(--bad) 12%, transparent); }
.dl.hunk { color: var(--faint); background: var(--surface); }

/* ---------- composer ---------- */
#jump { position: absolute; right: 16px; bottom: 84px; width: 32px; height: 32px; min-height: 0; padding: 0; border-radius: 50%; background: var(--surface); box-shadow: 0 4px 14px rgba(0,0,0,.3); z-index: 5; }
#toast { position: absolute; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 6; max-width: 90%; padding: 7px 14px; border-radius: 999px; background: var(--fg); color: var(--bg); font-size: .85rem; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
#editBar { display: flex; align-items: center; gap: 8px; width: calc(100% - 24px); max-width: 720px; margin: 0 auto 4px; padding: 5px 12px; border-radius: var(--r-sm); background: color-mix(in srgb, var(--warn) 10%, transparent); color: var(--warn); font-size: .8rem; }
#editBar span { flex: 1; }
#attachChips { display: flex; gap: 6px; overflow-x: auto; width: calc(100% - 24px); max-width: 720px; margin: 0 auto 4px; }
.achip { display: flex; align-items: center; gap: 8px; flex: none; max-width: 240px; padding: 3px 4px 3px 5px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); font-size: .8rem; }
.achip.up { opacity: .6; }
.achip img { width: 28px; height: 28px; object-fit: cover; border-radius: 5px; }
.achip .an { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.achip .x { min-height: 22px; width: 22px; padding: 0; border: 0; font-size: 1rem; color: var(--muted); }
.achip.static { padding: 4px 10px; }
#composer { display: flex; align-items: flex-end; gap: 2px; width: calc(100% - 24px); max-width: 720px; margin: 0 auto 10px; margin-bottom: max(10px, env(safe-area-inset-bottom)); padding: 5px; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; box-shadow: 0 1px 2px rgba(0,0,0,.12); transition: border-color .12s, box-shadow .12s; }
#composer:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); box-shadow: 0 0 0 3px var(--accent-soft); }
#input { flex: 1; min-width: 0; min-height: 34px; max-height: 200px; resize: none; padding: 7px 6px; line-height: 1.45; border: 0; border-radius: 0; background: transparent; }
#input:focus { background: transparent; }
#attachBtn { width: 34px; height: 34px; padding: 0; border: 0; border-radius: 50%; color: var(--muted); flex: none; }
#attachBtn:hover { color: var(--fg); }
#sendBtn, #stopBtn { width: 34px; height: 34px; min-height: 34px; padding: 0; border-radius: 50%; flex: none; }
#stopBtn { background: var(--fg); color: var(--bg); border: 0; }
#stopBtn:hover { background: color-mix(in srgb, var(--fg) 85%, transparent); }

/* ---------- sheets: files, projects, settings, preview ---------- */
#files, .sheet { position: fixed; z-index: 40; inset: 0; display: flex; flex-direction: column; background: var(--bg); padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
.files-head { display: flex; align-items: center; gap: 6px; min-height: 46px; padding: 4px 8px; border-bottom: 1px solid var(--border); }
.files-head strong { font-size: .95rem; font-weight: 600; margin-left: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files-head .grow { flex: 1; }
.files-head button { height: 30px; min-height: 30px; font-size: .82rem; }
.files-head .ibtn { width: 34px; }
#files .err, .sheet .err { padding: 0 14px; }
#fListWrap, #fView { flex: 1; min-height: 0; overflow-y: auto; }
#fCrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 0; padding: 8px 10px 4px; color: var(--faint); font-size: .82rem; }
.crumb { min-height: 26px; height: 26px; padding: 0 6px; border: 0; color: var(--muted); font-size: .82rem; }
.crumb:hover { color: var(--accent); }
#fList { list-style: none; margin: 0; padding: 0 6px 12px; }
.frow { display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 0 10px; border-radius: var(--r-sm); cursor: pointer; font-size: .9rem; }
.frow:hover { background: var(--hover); }
.frow.disabled { opacity: .45; cursor: default; }
.frow .ico { flex: none; width: 16px; text-align: center; color: var(--accent); font-weight: 700; }
.frow .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.frow .fmeta { color: var(--faint); font-size: .75rem; flex: none; }
.fview-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px 4px; }
.fview-head button { height: 28px; min-height: 28px; font-size: .8rem; }
.fview-name { display: grid; min-width: 0; } .fview-name strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .95rem; }
.fview-actions { display: flex; gap: 6px; flex-wrap: wrap; padding: 6px 14px 10px; }
.fview-actions > * { flex: 0 0 auto; height: 30px; min-height: 30px; font-size: .82rem; }
#fBody { padding: 0 14px 16px; }
#fBody pre { margin: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); font: .78rem/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
#fBody img { max-width: 100%; border-radius: var(--r-sm); border: 1px solid var(--border); }
.sbody { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 14px 24px; }
.list { list-style: none; margin: 0; padding: 0; }
.prow { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 8px; border-radius: var(--r-sm); }
.prow:hover { background: var(--hover); } .prow.sel { background: var(--accent-soft); }
.pmain { flex: 1; min-width: 0; cursor: pointer; }
.pmain .nm { font-size: .92rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pmain .meta { color: var(--muted); font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow button { height: 28px; min-height: 28px; font-size: .8rem; }
.clist { list-style: none; margin: 0; padding: 0; font: .78rem/1.5 var(--mono); }
.clist li { display: flex; gap: 10px; padding: 2px 0; overflow-wrap: anywhere; }
.clist .st { flex: none; width: 20px; color: var(--accent); }
.clist code { flex: none; background: none; padding: 0; color: var(--muted); }
.clist .muted { margin-left: auto; flex: none; font-size: .72rem; }
.toolbar { display: flex; gap: 6px; align-items: center; margin: 10px 0 6px; flex-wrap: wrap; }
.toolbar input { flex: 1 1 140px; min-width: 0; }
.toolbar > button, .toolbar > select { flex: 0 0 auto; }
form.toolbar { flex-wrap: nowrap; }
.form { display: grid; gap: 8px; margin-top: 8px; }
.form button { justify-self: start; }
.field { display: grid; gap: 4px; margin: 12px 0 8px; font-size: .8rem; color: var(--muted); }
.field input, .field select { max-width: 100%; }

/* settings */
#setTabs { display: flex; gap: 2px; overflow-x: auto; padding: 0 10px; border-bottom: 1px solid var(--border); }
.stab { flex: none; height: 38px; min-height: 38px; padding: 0 10px; border: 0; border-radius: 0; border-bottom: 2px solid transparent; color: var(--muted); }
.stab::after { inset: 0; }
.stab:hover { background: transparent; color: var(--fg); }
.stab.active { color: var(--fg); border-bottom-color: var(--accent); }
.cards3 { display: grid; gap: 8px; grid-template-columns: repeat(3, 1fr); margin-top: 6px; }
.card { display: grid; gap: 2px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r-md); }
.card span { color: var(--muted); font-size: .72rem; }
.card b { font-size: 1.15rem; font-weight: 600; letter-spacing: -.01em; }
.card small { color: var(--faint); font-size: .7rem; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 96px; padding: 6px 0 0; border-bottom: 1px solid var(--border); }
.barcol { flex: 1; height: 100%; display: flex; align-items: flex-end; min-width: 2px; }
.barcol i { display: block; width: 100%; background: var(--accent); border-radius: 2px 2px 0 0; opacity: .8; }
.urow { display: flex; justify-content: space-between; gap: 12px; align-items: center; min-height: 38px; padding: 0 6px; border-radius: var(--r-sm); cursor: pointer; font-size: .9rem; }
.urow:hover { background: var(--hover); }
.urow .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mrow { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; align-items: end; padding: 12px 0; border-bottom: 1px solid var(--border); }
.mname { grid-column: 1 / -1; display: grid; }
.mname b { font-weight: 600; font-size: .92rem; }
.pin { display: grid; gap: 3px; font-size: .72rem; color: var(--muted); }
.pin input { height: 30px; min-height: 30px; }
.dflt { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; font-size: .85rem; }
.dflt input { width: 16px; height: 16px; }
.krow { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: .88rem; }
.krow span:last-child { text-align: right; overflow-wrap: anywhere; }
.sbody > .btn, .sbody > button { margin: 10px 0 0; }
.sbody > .primary { margin-top: 14px; }

/* live preview */
#preview { position: fixed; z-index: 45; inset: 0; display: flex; flex-direction: column; background: var(--bg); padding-top: env(safe-area-inset-top); }
#pvStage { flex: 1; min-height: 0; display: flex; justify-content: center; background: var(--surface-2); }
#pvStage iframe { width: 100%; height: 100%; border: 0; background: #fff; }
#pvStage.phone iframe { width: 390px; max-width: 100%; box-shadow: 0 0 0 1px var(--border); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation-duration: .01ms !important; } }

/* ---------- desktop ---------- */
@media (min-width: 900px) {
  #side { position: static; transform: none; visibility: visible; width: 264px; flex: none; transition: none; }
  #scrim, #menu { display: none !important; }
  #top { padding-left: 14px; }
  #feed { padding: 24px 20px 8px; }
  #filesBtn .t { display: inline; }
  #composer { margin-bottom: 18px; }
  #files { inset: 0 0 0 auto; width: min(460px, 42vw); border-left: 1px solid var(--border); box-shadow: -10px 0 30px rgba(0,0,0,.25); }
  .sheet { inset: 6vh 0 6vh 50%; transform: translateX(-50%); width: min(720px, 92vw); height: 88vh; border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: 0 0 0 100vmax rgba(0,0,0,.5), 0 24px 60px rgba(0,0,0,.4); overflow: hidden; padding-top: 0; }
  #preview { inset: 3vh 3vw; border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; box-shadow: 0 0 0 100vmax rgba(0,0,0,.5); padding-top: 0; }
  #model { max-width: 240px; }
  .mrow { grid-template-columns: 1.4fr 100px 100px 80px; } .mname, .dflt { grid-column: auto; }
  #convList li .more { opacity: 0; }
}

/* polish 2 */
#input:focus-visible { outline: none; }
.sbody .fview-head, .sbody .fview-actions { padding-left: 0; padding-right: 0; }

/* ---------- logo ---------- */
.logo { width: 22px; height: 22px; border-radius: 6px; vertical-align: -5px; margin-right: 8px; flex: none; }
.brand { display: flex; align-items: center; }
.logo.lg { width: 48px; height: 48px; border-radius: 13px; margin: 0 0 6px; }
.logo.xl { width: 56px; height: 56px; border-radius: 15px; margin: 0 auto 14px; display: block; }
#loginForm .logo { margin-right: 0; }

/* ---------- file cards ---------- */
.files-made:empty { display: none; }
.turn { display: grid; gap: 6px; }
.fcards { display: grid; gap: 6px; max-width: 520px; }
.fcard { border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; background: var(--surface); }
.frow2 { display: flex; align-items: center; }
.fhead { flex: 1; min-width: 0; justify-content: flex-start; gap: 12px; height: 54px; min-height: 54px; padding: 0 6px 0 12px; border: 0; border-radius: 0; text-align: left; }
.fhead::after { display: none; }
.fext { flex: none; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; font: 700 .62rem var(--mono); text-transform: uppercase; letter-spacing: .02em;
  background: var(--surface-2); color: var(--muted); }
.fext.k-text, .fext.k-markdown { background: var(--accent-soft); color: var(--accent); }
.fext.k-csv { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.fext.k-html, .fext.k-svg { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.fext.k-image { background: color-mix(in srgb, #c47bff 16%, transparent); color: #c47bff; }
.fext.k-pdf { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.fmain { flex: 1; min-width: 0; display: grid; gap: 1px; }
.fnm { font-size: .9rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fsub { color: var(--muted); font-size: .75rem; }
.chev { flex: none; width: 7px; height: 7px; margin-right: 6px; border-right: 1.75px solid var(--faint); border-bottom: 1.75px solid var(--faint); transform: rotate(-45deg); transition: transform .15s; }
.fhead[aria-expanded="true"] .chev { transform: rotate(45deg); }
.fdl { flex: none; margin-right: 6px; }
.fbody { border-top: 1px solid var(--border); padding: 10px 12px; background: var(--bg); }
.fpre { margin: 0; max-height: 52vh; overflow: auto; font: .78rem/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.fimg { max-width: 100%; max-height: 52vh; border-radius: var(--r-sm); border: 1px solid var(--border); display: block; }
.fframe { width: 100%; height: 340px; border: 1px solid var(--border); border-radius: var(--r-sm); background: #fff; display: block; }
.fmd { max-height: 56vh; overflow: auto; }
.factions { display: flex; gap: 2px; margin-top: 8px; flex-wrap: wrap; }
.factions a.linkbtn { display: inline-flex; align-items: center; text-decoration: none; }
.fmore { justify-self: start; }

/* polish 3 */
.fnm { font-size: .86rem; }
.fhead { height: 50px; min-height: 50px; }
#loginForm { text-align: center; }
#loginForm .logo.lg { display: block; margin: 0 auto 6px; }

/* ---------- shared chat page ---------- */
body.share { height: auto; min-height: 100%; }
.share-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 720px; margin: 0 auto; padding: 12px 16px; }
.share-brand { display: flex; align-items: center; font-weight: 600; letter-spacing: -.01em; color: var(--fg); text-decoration: none; }
.share-main { max-width: 720px; margin: 0 auto; padding: 8px 16px 40px; }
.share-main h1 { font-size: 1.4rem; letter-spacing: -.02em; margin: 8px 0 2px; text-wrap: balance; }
.share-main #msgs { margin-top: 18px; max-width: none; }
.share-foot { text-align: center; padding: 16px; border-top: 1px solid var(--border); font-size: .78rem; }
.tool-head.static { cursor: default; display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px; }
.tool-head.static:hover { background: transparent; }

/* ---------- questions ---------- */
.qcard { border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); border-radius: var(--r-md); padding: 10px 12px; background: var(--accent-soft); }
.qcard.done { border-color: var(--border); background: var(--surface); }
.qq { font-weight: 600; font-size: .92rem; margin-bottom: 8px; }
.qopts { display: flex; flex-wrap: wrap; gap: 6px; }
.qopt { height: 32px; min-height: 32px; padding: 0 14px; border-radius: 999px; background: var(--bg); font-weight: 500; }
.qopt:hover { border-color: var(--accent); color: var(--accent); }
.qother { display: flex; gap: 6px; margin-top: 8px; }
.qother input { flex: 1; min-width: 0; height: 32px; min-height: 32px; background: var(--bg); }
.qother button { height: 32px; min-height: 32px; }
.qans { color: var(--muted); font-size: .85rem; }

/* ---------- search results ---------- */
#results { flex: 1; overflow-y: auto; margin-inline: -4px; padding-inline: 4px; }
#results h3 { margin: 12px 6px 4px; }
.hit { display: grid; gap: 2px; width: 100%; height: auto; min-height: 0; padding: 7px 8px; border: 0; border-radius: var(--r-sm); text-align: left; white-space: normal; justify-items: start; }
.hit .hmeta { display: flex; gap: 8px; align-items: center; font-size: .72rem; color: var(--faint); max-width: 100%; }
.hit .hk { flex: none; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.hit .ht { font-size: .88rem; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.hit .hs { font-size: .8rem; color: var(--muted); line-height: 1.4; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
mark { background: color-mix(in srgb, var(--warn) 35%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.flash { animation: flash 2.2s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px var(--accent-soft); background: var(--accent-soft); } 100% { box-shadow: 0 0 0 4px transparent; background: transparent; } }

/* ---------- voice, message actions, live status ---------- */
#micBtn { width: 34px; height: 34px; padding: 0; border: 0; border-radius: 50%; color: var(--muted); flex: none; }
#micBtn:hover { color: var(--fg); }
#micBtn.live { color: #fff; background: var(--bad); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--bad) 25%, transparent); } }
.mactions { display: flex; gap: 2px; margin-top: 4px; opacity: 0; transition: opacity .12s; }
.msg-assistant:hover .mactions, .mactions:focus-within { opacity: 1; }
@media (pointer: coarse) { .mactions { opacity: .65; } }
.working .wlabel { color: var(--fg); }
.working .welapsed { margin-left: 2px; font-variant-numeric: tabular-nums; }

/* ---------- dialogs, segmented control ---------- */
.dlg { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgba(0,0,0,.5); }
.dlg-card { width: min(420px, 100%); display: grid; gap: 10px; padding: 14px 16px 16px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: 0 24px 60px rgba(0,0,0,.4); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.dlg-card input[readonly] { width: 100%; font-size: .85rem; }
.chk { display: flex; align-items: flex-start; gap: 8px; font-size: .88rem; }
.chk input { margin-top: 3px; width: 16px; height: 16px; }
.dlg-card .primary { justify-self: start; }
.seg { display: inline-flex; padding: 2px; border: 1px solid var(--border); border-radius: 999px; }
.seg button { height: 26px; min-height: 26px; padding: 0 10px; border: 0; border-radius: 999px; font-size: .78rem; color: var(--muted); }
.seg button.on { background: var(--surface-2); color: var(--fg); }

/* ---------- review changes ---------- */
.revsum { margin: 8px 0 10px; font-size: .9rem; }
.add { color: var(--ok); } .del { color: var(--bad); }
.revlist { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; }
.revrow + .revrow { border-top: 1px solid var(--border); }
.revhead { width: 100%; justify-content: flex-start; gap: 10px; height: 38px; min-height: 38px; padding: 0 10px; border: 0; border-radius: 0; text-align: left; }
.revhead::after { display: none; }
.rpath { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; direction: rtl; text-align: left; font: .8rem var(--mono); }
.rnum { flex: none; font: .75rem var(--mono); }
.rst { flex: none; width: 52px; text-align: center; font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; border-radius: 6px; padding: 2px 0; background: var(--surface-2); color: var(--muted); }
.rst.s-A { color: var(--ok); } .rst.s-D { color: var(--bad); } .rst.s-M { color: var(--accent); }
.revdetail { padding: 0 10px 10px; background: var(--surface); }
.revdetail .diff { margin-bottom: 4px; }
.revfoot { display: grid; gap: 8px; margin-top: 14px; justify-items: start; }
.revfoot form { width: 100%; }

/* ---------- GitHub / branches ---------- */
.rline { overflow-wrap: anywhere; margin: 2px 0 6px; }
.prform { padding: 10px 0 0; }
.prform textarea { min-height: 56px; padding: 6px 10px; resize: vertical; }
#ghQ { width: 100%; margin: 6px 0; }
.sbody .pill { margin-left: 6px; }

/* polish 4 */
.hit { justify-content: stretch; grid-template-columns: minmax(0, 1fr); }
.hit:hover { background: var(--hover); }
