/* Zakevo AI — calm, readable, bidirectional UI. Logical properties keep the layout correct in RTL and LTR. */
@font-face { font-family: 'Inter'; src: url('/static/fonts/Inter-VF.ttf') format('truetype'); font-weight: 100 900; font-display: swap; }
@font-face { font-family: 'Plex Arabic'; src: url('/static/fonts/IBMPlexSansArabic-Regular.ttf') format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Plex Arabic'; src: url('/static/fonts/IBMPlexSansArabic-Bold.ttf') format('truetype'); font-weight: 600 800; font-display: swap; }

:root {
  --bg: #F6F4EF; --bg2: #EFECE5; --panel: #FFFFFF; --line: #E2DDD3; --line2: #D3CDC0;
  --fg: #1E2A2E; --fg2: #4A575D; --muted: #7A858A;
  --brand: #1F4E46; --brand2: #2F7D6D; --brand-soft: #E1EEEA; --gold: #E9C46A;
  --ins: #DDF3E6; --ins-fg: #145A32; --del: #FBE1E1; --del-fg: #8E1D1D;
  --warn: #FFF4DA; --warn-fg: #7A5300; --err: #FDE8E8; --err-fg: #9B1C1C;
  --shadow: 0 1px 2px rgba(30, 42, 46, .06), 0 8px 24px rgba(30, 42, 46, .07);
  --radius: 14px; --side: 280px; --editor: min(46vw, 760px);
  --font: 'Inter', 'Plex Arabic', system-ui, -apple-system, 'Segoe UI', 'Noto Sans', 'Noto Sans Arabic', 'Noto Sans CJK SC', sans-serif;
  --mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #12171A; --bg2: #171D21; --panel: #1B2226; --line: #2A3439; --line2: #36424A;
  --fg: #E7ECEE; --fg2: #B9C4C9; --muted: #84929A;
  --brand: #7FC8B4; --brand2: #5FB39D; --brand-soft: #1F3530; --gold: #E9C46A;
  --ins: #183A2A; --ins-fg: #9FE3BE; --del: #42201F; --del-fg: #F5B2AE;
  --warn: #3A3018; --warn-fg: #F3D58A; --err: #3D1F1F; --err-fg: #F6B4B4;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 15px/1.6 var(--font); -webkit-font-smoothing: antialiased; }
:lang(ar) body, [dir='rtl'] { font-feature-settings: 'kern'; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--brand2); }
img { max-width: 100%; }
.boot { height: 100vh; display: grid; place-items: center; }
.boot img { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.92); opacity: .7; } }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line2); background: var(--panel);
  border-radius: 10px; padding: 7px 12px; cursor: pointer; font-size: 14px; line-height: 1.3; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { border-color: var(--brand2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
:root[data-theme='dark'] .btn.primary { color: #0E1A17; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--bg2); }
.btn.small { padding: 4px 9px; font-size: 13px; border-radius: 8px; }
.btn.icon { padding: 7px; width: 36px; height: 36px; border-radius: 10px; }
.btn.danger { color: var(--err-fg); }
.btn.on { background: var(--brand-soft); border-color: var(--brand2); color: var(--brand); }
.input, textarea.input, select.input { width: 100%; border: 1px solid var(--line2); background: var(--panel); border-radius: 10px; padding: 9px 12px; outline: none; }
.input:focus { border-color: var(--brand2); box-shadow: 0 0 0 3px var(--brand-soft); }
label.f { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--fg2); font-weight: 600; }
.ico { width: 18px; height: 18px; display: inline-block; flex: none; }
.ico svg { width: 100%; height: 100%; display: block; }

/* ---------- app shell */
.app { display: grid; grid-template-columns: var(--side) 1fr; grid-template-rows: minmax(0, 1fr); height: 100vh; height: 100dvh; overflow: hidden; }
.app > * { min-height: 0; }
.app.noside { grid-template-columns: 0 1fr; }
.app.editing { grid-template-columns: var(--side) 1fr var(--editor); }
.app.noside.editing { grid-template-columns: 0 1fr var(--editor); }
.side { background: var(--bg2); border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.app.noside .side { visibility: hidden; }
.side-top { padding: 14px 12px 8px; display: flex; align-items: center; gap: 8px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; text-decoration: none; color: var(--fg); }
.brand img { width: 30px; height: 30px; }
.brand b { color: var(--brand2); font-weight: 700; }
.side .new { margin: 4px 12px 10px; justify-content: flex-start; }
.side .search { margin: 0 12px 8px; width: calc(100% - 24px); }
.side-scroll { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.side h4 { margin: 14px 8px 6px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: flex; align-items: center; justify-content: space-between; }
.side h4 button { font-size: 12px; }
.item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 9px; cursor: pointer; color: var(--fg2); font-size: 14px; position: relative; }
.item:hover { background: var(--panel); }
.item.active { background: var(--panel); color: var(--fg); box-shadow: var(--shadow); }
.item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .more { opacity: 0; }
.item:hover .more, .item.active .more { opacity: 1; }
.side-foot { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; align-items: center; gap: 8px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; flex: none; }

.main { display: flex; flex-direction: column; min-width: 0; height: 100%; position: relative; }
.topbar { height: 52px; display: flex; align-items: center; gap: 8px; padding: 0 12px; border-bottom: 1px solid transparent; flex: none; }
.topbar .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .crumb { color: var(--muted); font-size: 13px; }
.tabs-mobile { display: none; }

/* ---------- chat */
.scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.thread { max-width: 820px; margin: 0 auto; padding: 18px 20px 28px; }
.msg { margin: 18px 0; display: flex; gap: 12px; }
.msg.user { justify-content: flex-end; }
.msg.user > div { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.msg.user .bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; border-end-end-radius: 6px; padding: 10px 15px; max-width: 100%; white-space: pre-wrap; word-wrap: break-word; }
.msg.bot .avatar-bot { width: 30px; height: 30px; flex: none; margin-top: 2px; }
.msg.bot .body { flex: 1; min-width: 0; }
.att-row { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; }
.fchip { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 5px 9px; font-size: 13px; max-width: 260px; }
.fchip .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fchip .k { font-size: 10.5px; font-weight: 700; border-radius: 5px; padding: 1px 5px; background: var(--bg2); color: var(--fg2); text-transform: uppercase; }
.fchip .k.pdf { background: #FBE3E1; color: #A1261B; } .fchip .k.sheet { background: #DFF1E4; color: #1D6B36; }
.fchip .k.docx { background: #E0EBFB; color: #1F4E9B; } .fchip .k.pptx { background: #FCE8DA; color: #A44A12; }
.fchip .k.image { background: #F1E5FA; color: #6C2E9B; }
.fchip button { border: 0; background: none; cursor: pointer; padding: 0 2px; color: var(--muted); }
.fchip.busy { opacity: .7; }

.md { word-wrap: break-word; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: .55em 0; }
.md h1, .md h2, .md h3 { line-height: 1.3; margin: 1.1em 0 .45em; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.18em; } .md h3 { font-size: 1.05em; }
.md ul, .md ol { padding-inline-start: 1.4em; margin: .45em 0; }
.md li { margin: .2em 0; }
.md blockquote { margin: .6em 0; padding: .2em .9em; border-inline-start: 3px solid var(--brand2); color: var(--fg2); background: var(--bg2); border-radius: 6px; }
.md code { font-family: var(--mono); font-size: .9em; background: var(--bg2); padding: .1em .35em; border-radius: 5px; }
.md pre { background: #172025; color: #E6EDF0; border-radius: 12px; padding: 12px 14px; overflow-x: auto; direction: ltr; text-align: left; position: relative; }
.md pre code { background: none; padding: 0; color: inherit; }
.md pre .copy { position: absolute; top: 6px; inset-inline-end: 6px; font-size: 12px; background: #2A363C; color: #E6EDF0; border: 0; border-radius: 6px; padding: 3px 8px; cursor: pointer; }
.md table { border-collapse: collapse; margin: .7em 0; font-size: 14px; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: start; }
.md th { background: var(--bg2); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.cite { display: inline-flex; align-items: center; gap: 3px; vertical-align: 1px; font-size: 11.5px; line-height: 1; padding: 3px 6px; margin: 0 2px;
  border-radius: 999px; border: 1px solid var(--line2); background: var(--panel); color: var(--brand2); cursor: pointer; font-weight: 600; white-space: nowrap; }
.cite:hover { background: var(--brand-soft); }
.cite.c { color: #8A5A00; border-color: #E9C46A; background: #FFF8E6; }
:root[data-theme='dark'] .cite.c { background: #3A3018; color: var(--gold); }
.cursor::after { content: ''; display: inline-block; width: 8px; height: 1em; background: var(--brand2); vertical-align: -2px; margin-inline-start: 2px; animation: blink 1s steps(2) infinite; border-radius: 2px; }
@keyframes blink { 50% { opacity: 0; } }
.status { display: inline-flex; align-items: center; gap: 8px; color: var(--fg2); font-size: 13.5px; background: var(--bg2); border-radius: 999px; padding: 5px 12px; margin: 6px 0; }
.spin { width: 14px; height: 14px; border: 2px solid var(--line2); border-top-color: var(--brand2); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.actions { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 8px; opacity: .85; }
.actions .btn { color: var(--fg2); }
.msg.bot:hover .actions { opacity: 1; }
.card-art { display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); background: var(--panel); border-radius: 14px; padding: 10px 12px; margin: 10px 0; cursor: pointer; max-width: 460px; box-shadow: var(--shadow); }
.card-art:hover { border-color: var(--brand2); }
.card-art .ic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.card-art .ic.k-deck { background: #FCE8DA; color: #A44A12; } .card-art .ic.k-sheet { background: #DFF1E4; color: #1D6B36; }
.card-art .meta { font-size: 12.5px; color: var(--muted); }
.err { background: var(--err); color: var(--err-fg); border-radius: 12px; padding: 10px 14px; margin: 8px 0; }
.note { background: var(--warn); color: var(--warn-fg); border-radius: 12px; padding: 10px 14px; margin: 8px 0; font-size: 14px; }
.web-list { display: grid; gap: 6px; margin: 10px 0 0; }
.web-list a { display: block; text-decoration: none; color: var(--fg); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; font-size: 13px; background: var(--panel); }
.web-list a small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- composer */
.composer-wrap { padding: 0 16px 14px; flex: none; }
.composer { max-width: 820px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line2); border-radius: 22px; box-shadow: var(--shadow); padding: 8px; }
.composer:focus-within { border-color: var(--brand2); }
.composer textarea { width: 100%; border: 0; outline: none; resize: none; background: transparent; padding: 8px 10px 6px; max-height: 240px; min-height: 26px; line-height: 1.5; }
.composer .bar { display: flex; align-items: center; gap: 4px; }
.composer .att { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 6px 2px; }
.send { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--brand); color: #fff; display: grid; place-items: center; cursor: pointer; }
:root[data-theme='dark'] .send { color: #0E1A17; }
.send:disabled { background: var(--line2); cursor: default; }
.send.stop { background: var(--fg); }
.sel-chip { display: flex; align-items: center; gap: 8px; margin: 2px 6px 4px; padding: 6px 10px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); font-size: 13px; }
.sel-chip .q { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.disclaimer { text-align: center; font-size: 12px; color: var(--muted); margin-top: 7px; }
.listening { animation: pulse 1s ease-in-out infinite; color: #C0392B !important; }

/* ---------- start screen */
.start { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px 10vh; text-align: center; overflow-y: auto; }
.start .logo { width: 68px; height: 68px; margin-bottom: 14px; filter: drop-shadow(0 8px 18px rgba(31, 78, 70, .25)); }
.start h1 { font-size: clamp(24px, 3.6vw, 34px); margin: 0 0 6px; letter-spacing: -.02em; font-weight: 700; }
.start p.sub { color: var(--fg2); margin: 0 0 22px; }
.start .composer-wrap { width: 100%; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; max-width: 820px; }
.chip { border: 1px solid var(--line2); background: var(--panel); border-radius: 999px; padding: 7px 13px; cursor: pointer; font-size: 13.5px; color: var(--fg2); display: inline-flex; gap: 6px; align-items: center; }
.chip:hover { border-color: var(--brand2); color: var(--fg); }
.chip.ctx { border-color: var(--brand2); background: var(--brand-soft); color: var(--brand); }

/* ---------- editor pane */
.editor { border-inline-start: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-width: 0; height: 100%; overflow: hidden; }
.ed-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); min-height: 52px; }
.ed-head .ttl { flex: 1; min-width: 0; font-weight: 650; border: 1px solid transparent; border-radius: 8px; padding: 4px 8px; background: transparent; outline: none; }
.ed-head .ttl:hover, .ed-head .ttl:focus { border-color: var(--line2); }
.badge { font-size: 11.5px; border-radius: 999px; padding: 2px 8px; background: var(--bg2); color: var(--fg2); white-space: nowrap; }
.ed-body { flex: 1; min-height: 0; overflow-y: auto; position: relative; }
.menu { position: fixed; z-index: 60; background: var(--panel); border: 1px solid var(--line2); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; min-width: 200px; }
.menu button { display: flex; width: 100%; align-items: center; gap: 9px; border: 0; background: none; padding: 8px 10px; border-radius: 8px; cursor: pointer; text-align: start; font-size: 14px; }
.menu button:hover { background: var(--bg2); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* document */
.doc { max-width: 720px; margin: 0 auto; padding: 26px 34px 120px; }
.doc .dtitle { font-size: 26px; font-weight: 700; margin: 0 0 18px; outline: none; letter-spacing: -.01em; }
.blk { position: relative; border-radius: 8px; padding: 2px 8px; margin: 0 -8px; transition: background .12s; }
.blk:hover { background: var(--bg2); }
.blk.sel { background: var(--brand-soft); box-shadow: inset 3px 0 0 var(--brand2); }
[dir='rtl'] .blk.sel { box-shadow: inset -3px 0 0 var(--brand2); }
.blk [contenteditable] { outline: none; }
.blk h1, .blk h2, .blk h3 { margin: .9em 0 .35em; line-height: 1.3; } .blk h1 { font-size: 1.45em; } .blk h2 { font-size: 1.22em; color: var(--brand); } .blk h3 { font-size: 1.07em; }
.blk p { margin: .5em 0; line-height: 1.75; }
.blk ul, .blk ol { margin: .4em 0; padding-inline-start: 1.4em; }
.blk table { border-collapse: collapse; width: 100%; margin: .7em 0; font-size: 14px; }
.blk td, .blk th { border: 1px solid var(--line2); padding: 6px 9px; }
.blk th { background: var(--bg2); }
.blk blockquote { border-inline-start: 3px solid var(--brand2); margin: .6em 0; padding: .2em .9em; color: var(--fg2); }
.blk pre { background: #172025; color: #E6EDF0; border-radius: 10px; padding: 10px 12px; direction: ltr; text-align: left; overflow-x: auto; }
.blk-tools { position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--line); padding: 10px; display: none; }
.blk-tools.on { display: block; }
.blk-tools .qa { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.add-blk { opacity: 0; position: absolute; inset-inline-start: -30px; top: 6px; }
.blk:hover .add-blk { opacity: 1; }
.proposal { border: 1px solid var(--brand2); border-radius: 12px; margin: 10px -8px; overflow: hidden; background: var(--panel); box-shadow: var(--shadow); }
.proposal .ph { display: flex; align-items: center; gap: 8px; padding: 7px 10px; background: var(--brand-soft); color: var(--brand); font-size: 13px; font-weight: 600; }
.proposal .pb { padding: 10px 12px; line-height: 1.8; white-space: pre-wrap; }
del.d { background: var(--del); color: var(--del-fg); text-decoration: line-through; border-radius: 3px; }
ins.i { background: var(--ins); color: var(--ins-fg); text-decoration: none; border-radius: 3px; }

/* deck */
.deckv { display: grid; grid-template-columns: 150px 1fr; height: 100%; min-height: 0; }
.deckv > * { min-height: 0; }
.thumbs { border-inline-end: 1px solid var(--line); overflow-y: auto; padding: 10px; background: var(--bg2); }
.thumb { cursor: pointer; margin-bottom: 10px; position: relative; }
.thumb .n { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.thumb.active .slide { outline: 2px solid var(--brand2); outline-offset: 2px; }
.thumb .dot { position: absolute; top: 18px; inset-inline-end: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 2px var(--panel); }
.stage { overflow-y: auto; padding: 18px; }
.slide { aspect-ratio: 16 / 9; width: 100%; border-radius: 10px; overflow: hidden; position: relative; container-type: inline-size; box-shadow: var(--shadow);
  background: var(--sbg); color: var(--sfg); border: 1px solid var(--line); }
.slide .in { position: absolute; inset: 0; padding: 6cqw 6cqw 5cqw; display: flex; flex-direction: column; }
.slide .bar { position: absolute; top: 0; inset-inline: 0; height: .9cqw; background: var(--sacc); }
.slide h2 { font-size: 4.2cqw; margin: 0 0 2.4cqw; line-height: 1.2; }
.slide ul { margin: 0; padding-inline-start: 3.2cqw; font-size: 2.7cqw; line-height: 1.55; }
.slide ul li::marker { color: var(--sacc); }
.slide.title-l { background: var(--sband); }
.slide.title-l .in { justify-content: center; padding-inline-start: 9cqw; }
.slide.title-l .accent { position: absolute; inset-inline-start: 6cqw; top: 33%; width: 1.4cqw; height: 30%; background: var(--sacc); border-radius: 1cqw; }
.slide.title-l h2 { font-size: 6cqw; }
.slide .subtitle { font-size: 2.8cqw; color: var(--smut); }
.slide .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 2.4cqw; }
.slide .cols > div { background: var(--sband); border-radius: 1.2cqw; padding: 2.4cqw; border-top: .6cqw solid var(--sacc); }
.slide .quote { flex: 1; display: grid; place-items: center; text-align: center; font-size: 3.6cqw; color: var(--sacc); font-style: italic; padding: 0 6cqw; }
.slide .chartbox { display: flex; gap: 3cqw; flex: 1; min-height: 0; }
.slide .chartbox svg { flex: 1.6; min-width: 0; height: 100%; }
.slide table { width: 100%; border-collapse: collapse; font-size: 2.3cqw; }
.slide table td { padding: 1cqw 1.4cqw; border-bottom: 1px solid var(--sband); }
.slide table tr:first-child td { background: var(--sacc); color: #fff; font-weight: 700; }
.slide .opts { display: grid; gap: 1.4cqw; margin-top: 1cqw; }
.slide .opts div { background: var(--sband); border-radius: 1.4cqw; padding: 1.4cqw 2.2cqw; font-size: 2.6cqw; }
.slide .opts div.ok { outline: .35cqw solid var(--sacc); }
.slide .q { font-size: 3cqw; font-weight: 700; }
.slide .act { margin-top: auto; background: var(--sband); color: var(--sacc); font-weight: 700; border-radius: 1.2cqw; padding: 1.4cqw 2.2cqw; font-size: 2.2cqw; }
.slide .num { position: absolute; bottom: 2cqw; inset-inline-end: 3cqw; font-size: 1.4cqw; color: var(--smut); }
.thumbs .slide { box-shadow: none; }
.fields { margin-top: 16px; display: grid; gap: 10px; }
.fields textarea { min-height: 110px; }
.cmp { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.cmp .lab { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }

/* sheet & viewers */
.grid-wrap { overflow: auto; padding: 14px; }
table.grid { border-collapse: collapse; font-size: 13.5px; min-width: 100%; }
table.grid td, table.grid th { border: 1px solid var(--line); padding: 5px 9px; white-space: nowrap; max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
table.grid th { background: var(--bg2); position: sticky; top: 0; font-weight: 650; text-align: start; }
table.grid td[contenteditable]:focus { outline: 2px solid var(--brand2); background: var(--brand-soft); }
table.grid .num { text-align: end; font-variant-numeric: tabular-nums; }
.typ { font-size: 10px; font-weight: 700; color: var(--muted); display: block; text-transform: uppercase; }
.pager { display: flex; align-items: center; gap: 8px; justify-content: center; padding: 8px; border-bottom: 1px solid var(--line); }
.pageimg { display: block; margin: 14px auto; max-width: calc(100% - 28px); box-shadow: var(--shadow); border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.pagetext { white-space: pre-wrap; padding: 6px 18px 30px; font-size: 14px; color: var(--fg2); line-height: 1.8; }
.imgsel { position: relative; display: inline-block; margin: 14px; cursor: crosshair; user-select: none; }
.imgsel img { display: block; max-height: 70vh; border-radius: 8px; }
.imgsel .box { position: absolute; border: 2px solid var(--gold); background: rgba(233, 196, 106, .18); border-radius: 4px; }
.calc { padding: 16px 18px; }
.calc h3 { margin: 0 0 6px; }
.calc ol { padding: 0; list-style-position: inside; color: var(--fg2); }
.calc ol li { margin: 3px 0; }
.calc .formula { font-family: var(--mono); background: var(--bg2); border-radius: 8px; padding: 6px 10px; direction: ltr; text-align: left; margin: 4px 0; font-size: 13px; }
.vlist .v { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); }

/* ---------- dialogs, toasts, auth, admin */
.dlg-back { position: fixed; inset: 0; background: rgba(15, 22, 25, .45); display: grid; place-items: center; z-index: 80; padding: 16px; backdrop-filter: blur(2px); }
.dlg { background: var(--panel); border-radius: 18px; box-shadow: var(--shadow); width: min(560px, 100%); max-height: 90vh; overflow-y: auto; padding: 20px 22px; }
.dlg h3 { margin: 0 0 6px; }
.dlg .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toasts { position: fixed; bottom: 18px; inset-inline-start: 50%; transform: translateX(-50%); z-index: 90; display: grid; gap: 8px; }
[dir='rtl'] .toasts { transform: translateX(50%); }
.toast { background: var(--fg); color: var(--bg); padding: 9px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; animation: up .2s ease-out; }
.toast.bad { background: var(--err-fg); color: #fff; }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background:
  radial-gradient(1200px 500px at 85% -10%, rgba(47, 125, 109, .16), transparent), radial-gradient(900px 400px at -10% 110%, rgba(233, 196, 106, .18), transparent), var(--bg); }
.auth .box { width: min(420px, 100%); background: var(--panel); border-radius: 22px; box-shadow: var(--shadow); padding: 28px; }
.auth .brand { justify-content: center; font-size: 22px; margin-bottom: 4px; }
.auth .brand img { width: 40px; height: 40px; }
.auth .switch { text-align: center; margin-top: 14px; font-size: 14px; }
.page { max-width: 980px; margin: 0 auto; padding: 22px 20px 60px; width: 100%; }
.page h2 { margin-top: 0; }
.tabsx { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabsx button { border: 0; background: none; padding: 9px 14px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--fg2); font-weight: 600; }
.tabsx button.on { border-bottom-color: var(--brand2); color: var(--fg); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.stat b { display: block; font-size: 22px; }
.ok-dot, .bad-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #2EAD6B; margin-inline-end: 6px; }
.bad-dot { background: #D0453B; }
.cardx { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl td, table.tbl th { padding: 8px; border-bottom: 1px solid var(--line); text-align: start; }
.proj-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.list-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }

/* ---------- responsive: phone = tabs between chat and editor, sidebar as drawer */
@media (max-width: 900px) {
  :root { --side: 290px; }
  .app, .app.editing, .app.noside, .app.noside.editing { grid-template-columns: 1fr; }
  .side { position: fixed; inset-block: 0; inset-inline-start: 0; width: var(--side); z-index: 70; transform: translateX(-105%); transition: transform .2s; box-shadow: var(--shadow); }
  [dir='rtl'] .side { transform: translateX(105%); }
  .app.drawer .side { transform: none; visibility: visible; }
  .app.drawer::after { content: ''; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 65; }
  .app.editing .tabs-mobile { display: flex; }
  .app.editing.show-editor .main { display: none; }
  .app.editing:not(.show-editor) .editor { display: none; }
  .editor { border: 0; }
  .tabs-mobile { gap: 4px; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--panel); }
  .tabs-mobile button { flex: 1; }
  .deckv { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .thumbs { display: flex; gap: 8px; border: 0; border-bottom: 1px solid var(--line); overflow-x: auto; padding: 8px; }
  .thumb { width: 110px; flex: none; margin: 0; }
  .doc { padding: 18px 18px 120px; }
  .thread { padding: 12px 12px 20px; }
  .cmp { grid-template-columns: 1fr; }
  .actions .lbl { display: none; }
  .actions .btn { padding: 6px 8px; }
}
@media print { .side, .composer-wrap, .topbar, .editor { display: none !important; } }

/* code editor */
.codewrap { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.codeed { flex: 1; min-height: 0; display: grid; grid-template-columns: auto 1fr; font: 13px/1.6 var(--mono); background: var(--panel); direction: ltr; }
.codeed .gutter { margin: 0; padding: 10px 8px 10px 12px; text-align: right; color: var(--muted); background: var(--bg2); overflow: hidden; user-select: none; font: inherit; }
.code-ta { border: 0; outline: none; resize: none; padding: 10px 12px; white-space: pre; overflow: auto; tab-size: 4; background: transparent; font: inherit; color: var(--fg); }
.ldiff { font: 12.5px/1.6 var(--mono); padding: 6px 0; overflow-x: auto; text-align: left; }
.ldiff div { white-space: pre; padding: 0 12px; min-height: 1.6em; }
.ldiff .p { background: var(--ins); color: var(--ins-fg); } .ldiff .m { background: var(--del); color: var(--del-fg); } .ldiff .gap { color: var(--muted); text-align: center; }
.card-art .ic.k-code { background: #E6E3F7; color: #4B3BA0; }
.tbl tr.hl td { background: var(--brand-soft); }

/* ---------- sign-in showcase */
.auth.split { grid-template-columns: minmax(0, 1.15fr) minmax(340px, 440px); gap: clamp(24px, 5vw, 72px); align-items: center; justify-content: center; padding: clamp(20px, 5vw, 64px); }
.showcase { max-width: 620px; justify-self: end; }
.showcase .brand { font-size: 20px; margin-bottom: 22px; }
.showcase .brand img { width: 36px; height: 36px; }
.showcase h1 { font-size: clamp(28px, 3.4vw, 44px); line-height: 1.15; letter-spacing: -.02em; margin: 0 0 14px; font-weight: 750; }
:root[dir=rtl] .showcase h1 { letter-spacing: 0; line-height: 1.35; }
.showcase .lead { font-size: 16.5px; color: var(--muted); margin: 0 0 26px; max-width: 54ch; }
.showcase .demo { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); padding: 18px 18px 14px; margin-bottom: 26px; }
.showcase .dq { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; align-items: center; }
.showcase .dq .bubble { flex-basis: 100%; width: fit-content; margin-inline-start: auto; max-width: 80%; background: var(--bg2); border-radius: 16px; border-end-end-radius: 6px; padding: 8px 13px; font-size: 14.5px; }
.showcase .da { display: flex; gap: 10px; margin-top: 12px; font-size: 14.5px; }
.showcase .da img { width: 26px; height: 26px; flex: none; }
.showcase .da p { margin: 2px 0 10px; line-height: 1.75; }
.showcase .dcards { display: flex; gap: 8px; flex-wrap: wrap; }
.showcase .dcard { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 5px 10px; font-size: 13px; background: var(--bg); }
.showcase .feats { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 22px; }
.showcase .lf { display: flex; gap: 11px; font-size: 13.5px; color: var(--muted); line-height: 1.55; }
.showcase .lf b { display: block; color: var(--fg); font-size: 14.5px; margin-bottom: 2px; }
.showcase .lfi { flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.auth.split .box { justify-self: start; }
@media (max-width: 900px) {
  .auth.split { grid-template-columns: 1fr; }
  .showcase, .auth.split .box { justify-self: center; }
  .showcase .demo, .showcase .feats { display: none; }
  .showcase { text-align: center; }
  .showcase .brand { justify-content: center; }
  .showcase .lead { margin-inline: auto; }
}
.auth .box-h { margin: 0 0 8px; font-size: 21px; font-weight: 700; }
.showcase .brand { justify-content: flex-start; }
@media (max-width: 900px) { .auth.split { align-content: center; gap: 22px; } .showcase .brand { justify-content: center; } }
.btn.pill { border-radius: 999px; padding: 5px 11px; gap: 6px; font-size: 13.5px; color: var(--muted); }
.btn.pill.on { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.think-tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--brand2); background: var(--brand-soft); border-radius: 999px; padding: 2px 10px; margin-bottom: 6px; }
@media (max-width: 560px) { .btn.pill > span:not(.ico) { display: none; } .btn.pill { padding: 5px 8px; } }
.gen-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin: 10px 0; }
.gen { margin: 0; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--panel); }
.gen img { display: block; width: 100%; max-height: 420px; object-fit: contain; cursor: zoom-in; background: #fff; }
.gen figcaption { display: flex; align-items: center; gap: 6px; padding: 6px 8px 6px 12px; font-size: 12.5px; color: var(--muted); }
.gen figcaption span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details.run { border: 1px solid var(--line); border-radius: 12px; margin: 6px 0 10px; background: var(--panel); font-size: 13.5px; }
details.run summary { cursor: pointer; padding: 7px 12px; display: flex; align-items: center; gap: 7px; list-style: none; color: var(--brand2); }
details.run.bad summary { color: var(--err-fg); }
details.run pre { margin: 0 12px 10px; max-height: 320px; overflow: auto; font-size: 12.5px; background: var(--bg2); border-radius: 8px; padding: 10px; white-space: pre-wrap; }
details.run pre.out { background: var(--bg); border: 1px dashed var(--line); }
details.run pre.err-out { color: var(--err-fg); }
details.run .att-row { padding: 0 12px 10px; }
.runout { border-top: 1px solid var(--line); padding: 10px 12px; font-size: 13px; max-height: 45%; overflow: auto; background: var(--bg); }
.runout .rh { display: flex; align-items: center; gap: 6px; font-weight: 650; margin-bottom: 6px; color: var(--brand2); }
.runout pre { margin: 0 0 8px; white-space: pre-wrap; font-size: 12.5px; background: var(--bg2); border-radius: 8px; padding: 8px 10px; }
.runout .err-out { color: var(--err-fg); }
.runimg { max-width: 100%; border: 1px solid var(--line); border-radius: 8px; margin: 6px 0; background: #fff; }
.btn.busy { opacity: .55; pointer-events: none; }

/* ---------- live preview of HTML / SVG / Mermaid code */
.codewrap.pv { display: flex; flex-direction: column; height: 100%; }
.codebar { padding: 6px 10px; border-bottom: 1px solid var(--line); gap: 6px; }
.seg { display: inline-flex; background: var(--bg2); border-radius: 10px; padding: 2px; gap: 2px; }
.seg .btn { border: 0; background: transparent; border-radius: 8px; }
.seg .btn.on { background: var(--panel); box-shadow: 0 1px 2px rgba(0,0,0,.08); color: var(--fg); }
iframe.preview { flex: 1; width: 100%; min-height: 420px; border: 0; background: #fff; }

/* ================= v1.3: memory, deep research, voice call, assistants, share links ================= */
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; margin-inline-end: 14px; }
.chk input { accent-color: var(--brand2); width: 16px; height: 16px; }
.think-tag.research { color: var(--brand); }

/* memory */
.mem-list { display: flex; flex-direction: column; gap: 6px; max-height: 46vh; overflow: auto; }
.mem-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 14px; }
.mem-item a { color: inherit; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mem-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.mem-chip { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; border: 1px dashed var(--brand2); color: var(--brand2); background: transparent; border-radius: 999px; padding: 3px 10px; font: inherit; font-size: 12.5px; cursor: pointer; }
.mem-chip .q { color: var(--fg2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 340px; }
.mem-chip.off { border-color: var(--line2); color: var(--muted); }

/* deep research progress */
.rcard { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 14px 16px; margin: 4px 0 12px; box-shadow: var(--shadow); max-width: 640px; }
.rhead { display: flex; align-items: center; gap: 8px; color: var(--brand); }
.rtime { font-variant-numeric: tabular-nums; font-size: 13px; }
.rbar { height: 5px; background: var(--bg2); border-radius: 99px; overflow: hidden; margin: 10px 0 12px; }
.rbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand2), var(--gold)); border-radius: 99px; transition: width .6s ease; }
.rsteps { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13.5px; }
.rsteps li { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.rsteps li.done { color: var(--fg2); } .rsteps li.done .ico { color: var(--brand2); }
.rsteps li.now { color: var(--fg); font-weight: 600; }
.rsteps .dot { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--line2); margin: 0 3px; }
.rsteps .spin { width: 13px; height: 13px; }
.rnow { font-size: 12.5px; margin-top: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rqs { margin-top: 8px; font-size: 13px; } .rqs summary { cursor: pointer; } .rqs ul { margin: 6px 0 0; padding-inline-start: 18px; }

/* live voice call */
.vc { position: fixed; inset: 0; z-index: 200; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px;
  background: radial-gradient(ellipse at 50% 35%, #24584F 0%, #12302B 55%, #0B1D1A 100%); color: #EEF5F2; animation: vcIn .25s ease; }
@keyframes vcIn { from { opacity: 0; transform: scale(.98); } }
.vc-top { position: absolute; top: 18px; inset-inline: 0; text-align: center; font-size: 14px; letter-spacing: .04em; opacity: .75; }
.vc-orb { --lv: 0; width: 168px; height: 168px; border-radius: 50%; display: grid; place-items: center; position: relative;
  background: radial-gradient(circle at 40% 35%, #F3E2B0, #E9C46A 45%, #2F7D6D 100%);
  box-shadow: 0 0 calc(30px + var(--lv) * 90px) rgba(233, 196, 106, calc(.25 + var(--lv) * .5)); transform: scale(calc(1 + var(--lv) * .12)); transition: transform .08s linear, box-shadow .08s linear; }
.vc-orb img { width: 70px; height: 70px; border-radius: 18px; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.vc[data-state='thinking'] .vc-orb { animation: vcPulse 1.4s ease-in-out infinite; }
.vc[data-state='speaking'] .vc-orb::after { content: ''; position: absolute; inset: -14px; border-radius: 50%; border: 2px solid rgba(233, 196, 106, .55); animation: vcRing 1.6s ease-out infinite; }
.vc[data-state='idle'] .vc-orb { filter: grayscale(.7); opacity: .7; }
@keyframes vcPulse { 50% { transform: scale(.93); filter: brightness(.9); } }
@keyframes vcRing { from { transform: scale(.92); opacity: 1; } to { transform: scale(1.25); opacity: 0; } }
.vc-status { font-size: 18px; font-weight: 600; }
.vc-text { width: min(680px, 100%); text-align: center; min-height: 90px; }
.vc-you { font-size: 15px; opacity: .7; margin-bottom: 8px; }
.vc-said { font-size: 17px; line-height: 1.6; max-height: 30vh; overflow: auto; }
.vc-hint { font-size: 12.5px; opacity: .55; }
.vc-bar { display: flex; gap: 22px; margin-top: 8px; }
.vc-btn { width: 62px; height: 62px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer; color: #fff; background: rgba(255, 255, 255, .14); transition: background .15s; }
.vc-btn:hover { background: rgba(255, 255, 255, .22); }
.vc-btn.on { background: #fff; color: #12302B; }
.vc-btn.end { background: #D64545; } .vc-btn.end:hover { background: #E25555; }
@media (prefers-reduced-motion: reduce) { .vc-orb, .vc[data-state] .vc-orb, .vc-orb::after { animation: none !important; transition: none; } }

/* custom assistants */
.asst-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.asst-card { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.asst-ic { flex: none; width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 24px; background: var(--brand-soft); }
.asst-ic.big { width: 72px; height: 72px; font-size: 38px; border-radius: 20px; margin: 0 auto; }
.asst-name { font-weight: 700; font-size: 15px; }
.asst-desc { font-size: 13px; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.asst-stats { font-size: 12px; color: var(--brand2); margin-top: 6px; }
.asst-link { font-size: 12px; margin-top: 6px; color: var(--muted); gap: 4px; } .asst-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asst-acts { display: flex; flex-direction: column; gap: 6px; }
.asst-mini { flex: none; width: 18px; text-align: center; font-size: 14px; line-height: 1; }
.side .item.sub { padding-inline-start: 22px; font-size: 13.5px; }
.icon-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.icon-pick .ip { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 19px; cursor: pointer; }
.icon-pick .ip.on { border-color: var(--brand2); background: var(--brand-soft); box-shadow: 0 0 0 2px var(--brand-soft); }
.asst-form textarea { resize: vertical; }
.asst-head { text-align: center; padding: 26px 10px 10px; }
.asst-head h2 { margin: 10px 0 4px; } .asst-head p { margin: 0 auto 10px; max-width: 520px; }
.join { min-height: 100%; display: grid; place-items: center; padding: 30px 16px; background: var(--bg); }
.join-card { width: min(520px, 100%); text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 34px 26px; box-shadow: var(--shadow); }
.join-card h1 { font-size: 24px; margin: 14px 0 6px; }

/* share links */
.share-title { display: flex; align-items: center; gap: 8px; font-weight: 600; padding: 10px 12px; background: var(--bg); border-radius: 10px; }
.share-out { margin-top: 12px; } .share-out .row { gap: 8px; } .share-out .input { flex: 1; }
.public { min-height: 100vh; background: var(--bg); }
.pub-head { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 10px 18px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.pub-head .brand { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; font-size: 17px; } .pub-head .brand img { width: 28px; }
.pub-body { max-width: 860px; margin: 0 auto; padding: 26px 18px 60px; }
.pub-title { font-size: 28px; margin: 0 0 4px; } .pub-by { font-size: 13px; margin-bottom: 22px; }
.pub-foot { text-align: center; margin-top: 40px; font-size: 13px; } .pub-foot a { color: inherit; }
.thread.ro { padding: 0; max-width: none; }
.doc.ro { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 34px 38px; }
.doc.ro .dtitle { margin-top: 0; }
.deck-ro { display: grid; gap: 18px; } .deck-ro .slide-wrap { max-width: 820px; }
.sheet-ro h3 { margin: 18px 0 6px; }
.code-ro iframe.preview { width: 100%; height: 520px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.code-ro details { margin-top: 10px; } .code-ro summary { cursor: pointer; font-weight: 600; }
.code-ro pre { background: var(--bg2); padding: 14px; border-radius: 10px; overflow: auto; max-height: 460px; }
.ro-art { margin-top: 10px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; background: var(--panel); }
.ro-art > summary { cursor: pointer; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.ro-art[open] > summary { margin-bottom: 12px; }
.ro-art .doc.ro { border: 0; padding: 6px 4px; }
@media (max-width: 700px) { .doc.ro { padding: 20px 16px; } .pub-title { font-size: 22px; } .asst-grid { grid-template-columns: 1fr; } .asst-card { flex-wrap: wrap; } .asst-acts { flex-direction: row; width: 100%; } }
