/* MEПPO Assistant — design tokens, layout and components.
   Logical properties throughout so Arabic / Hebrew / Persian / Urdu mirror cleanly. */

/* ---------------- Tokens ---------------- */
:root {
  --bg: #0B1220; --bg-2: #0E1728; --surface: #111C2E; --surface-2: #162438; --surface-3: #1C2D45; --stage: #0D1A2C;
  --text: #F4F7FB; --text-2: #A7B4C7; --text-3: #8592A8; --border: #28374B; --border-strong: #3A4C66;
  --accent: #42D6C5; --accent-ink: #04201D; --accent-soft: rgba(66, 214, 197, .13); --accent-line: rgba(66, 214, 197, .45);
  --accent-2: #77B8FF; --accent-2-soft: rgba(119, 184, 255, .14);
  --ok: #36C98F; --ok-soft: rgba(54, 201, 143, .14); --warn: #F0B45C; --warn-soft: rgba(240, 180, 92, .14); --err: #F07178; --err-soft: rgba(240, 113, 120, .14);
  --user-bubble: #17344A; --focus: #8FE8DE;
  --f-sans: "IBM Plex Sans", "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", "Noto Sans", "Noto Sans Arabic", Tahoma, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Menlo, monospace;
  --fs-xs: 12px; --fs-sm: 13.5px; --fs: 15px; --fs-md: 16.5px; --fs-lg: 20px; --fs-xl: clamp(20px, 2.2vw, 26px);
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px;
  --r-sm: 6px; --r: 10px; --r-lg: 14px; --r-pill: 999px;
  --sh-1: 0 1px 2px rgba(0, 0, 0, .25); --sh-2: 0 10px 30px rgba(0, 0, 0, .35); --sh-3: 0 24px 60px rgba(0, 0, 0, .5);
  --t-fast: .14s ease; --t: .22s cubic-bezier(.2, .7, .2, 1);
  --rail-w: 232px; --nav-h: 64px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #F3F6FA; --bg-2: #EAF0F6; --surface: #FFFFFF; --surface-2: #F1F5F9; --surface-3: #E5ECF3; --stage: #0F2034;
  --text: #0E1A2B; --text-2: #46566C; --text-3: #5F6E83; --border: #D3DCE6; --border-strong: #B7C4D3;
  --accent: #0E8C7F; --accent-ink: #FFFFFF; --accent-soft: rgba(14, 140, 127, .1); --accent-line: rgba(14, 140, 127, .4);
  --accent-2: #2D6FC4; --accent-2-soft: rgba(45, 111, 196, .1);
  --ok: #18825A; --ok-soft: rgba(24, 130, 90, .1); --warn: #9A6514; --warn-soft: rgba(154, 101, 20, .1); --err: #B83A42; --err-soft: rgba(184, 58, 66, .09);
  --user-bubble: #DDEFF0; --focus: #0E8C7F;
  --sh-1: 0 1px 2px rgba(15, 32, 52, .08); --sh-2: 0 10px 30px rgba(15, 32, 52, .12); --sh-3: 0 24px 60px rgba(15, 32, 52, .2);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root[data-theme="system"] {
    --bg: #F3F6FA; --bg-2: #EAF0F6; --surface: #FFFFFF; --surface-2: #F1F5F9; --surface-3: #E5ECF3; --stage: #0F2034;
    --text: #0E1A2B; --text-2: #46566C; --text-3: #5F6E83; --border: #D3DCE6; --border-strong: #B7C4D3;
    --accent: #0E8C7F; --accent-ink: #FFFFFF; --accent-soft: rgba(14, 140, 127, .1); --accent-line: rgba(14, 140, 127, .4);
    --accent-2: #2D6FC4; --accent-2-soft: rgba(45, 111, 196, .1);
    --ok: #18825A; --ok-soft: rgba(24, 130, 90, .1); --warn: #9A6514; --warn-soft: rgba(154, 101, 20, .1); --err: #B83A42; --err-soft: rgba(184, 58, 66, .09);
    --user-bubble: #DDEFF0; --focus: #0E8C7F;
    --sh-1: 0 1px 2px rgba(15, 32, 52, .08); --sh-2: 0 10px 30px rgba(15, 32, 52, .12); --sh-3: 0 24px 60px rgba(15, 32, 52, .2);
    color-scheme: light;
  }
}

/* ---------------- Base ---------------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--f-sans); font-size: var(--fs); line-height: 1.55; overflow-x: hidden; }
:lang(ar), :lang(fa), :lang(ur) { line-height: 1.75; }
button, select, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; text-wrap: balance; font-weight: 600; letter-spacing: -.01em; }
:lang(ar) h1, :lang(ar) h2, :lang(ar) h3 { letter-spacing: 0; }
p { margin: 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
[tabindex="-1"]:focus { outline: none; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; inset-inline-start: 12px; top: -60px; z-index: 100; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: var(--r); font-weight: 600; text-decoration: none; transition: top var(--t-fast); }
.skip:focus { top: 12px; }
.ic { width: 20px; height: 20px; flex: 0 0 auto; display: inline-block; vertical-align: middle; }
.ic-sm { width: 16px; height: 16px; } .ic-xs { width: 13px; height: 13px; } .ic-lg { width: 32px; height: 32px; }
[dir="rtl"] .flip { transform: scaleX(-1); }
.muted { color: var(--text-3); font-weight: 400; }
.row-gap { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
code, .lang-code { font-family: var(--f-mono); }

/* ---------------- Buttons and inputs ---------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 0 14px; border-radius: var(--r); border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); font-weight: 500; font-size: var(--fs-sm); text-decoration: none; white-space: nowrap; transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast), color var(--t-fast); }
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--text-3); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: var(--fs-xs); border-radius: var(--r-sm); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, white); border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); border-color: transparent; }
.btn-danger { background: var(--err); border-color: var(--err); color: #1A0507; font-weight: 600; }
:root[data-theme="light"] .btn-danger { color: #fff; }
.btn-danger-ghost { background: transparent; border-color: color-mix(in srgb, var(--err) 45%, transparent); color: var(--err); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--err-soft); border-color: var(--err); }
.btn-ghost-stage { background: transparent; border-color: rgba(255, 255, 255, .25); color: #E9F0F8; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: var(--r); border: 1px solid transparent; background: transparent; color: var(--text-2); transition: background var(--t-fast), color var(--t-fast); }
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-btn-danger:hover:not(:disabled) { background: var(--err-soft); color: var(--err); }
.icon-btn-stage { color: #C9D6E5; border-color: rgba(255, 255, 255, .14); background: rgba(255, 255, 255, .04); width: 34px; height: 34px; }
.icon-btn-stage:hover { background: rgba(255, 255, 255, .1) !important; color: #fff !important; }
.sel { min-height: 40px; border: 1px solid var(--border-strong); background-color: var(--surface-2); border-radius: var(--r); padding-block: 0; padding-inline: 12px 32px; font-size: var(--fs-sm); max-width: 100%;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%238592A8' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; }
[dir="rtl"] .sel { background-position: left 11px center; }
.sel:hover { border-color: var(--text-3); }
.sel-sm { min-height: 34px; font-size: var(--fs-sm); border-radius: var(--r-sm); padding-inline: 10px 28px; }
.sel option { background: var(--surface); color: var(--text); }
.sel-stage { background-color: rgba(255, 255, 255, .05); border-color: rgba(255, 255, 255, .14); color: #DCE6F2; }
input[type="text"], input[type="url"], input[type="search"], input[type="password"], input[type="number"], textarea { border: 1px solid var(--border-strong); background: var(--bg-2); border-radius: var(--r); padding: 9px 12px; color: var(--text); min-width: 0; transition: border-color var(--t-fast), box-shadow var(--t-fast); }
input:focus, textarea:focus, .sel:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: var(--fs-sm); color: var(--text-2); margin-bottom: var(--sp-3); }
.field input, .field textarea { font-size: var(--fs); }
.field textarea { resize: vertical; min-height: 120px; }
.radios { border: 0; padding: 0; margin: 0 0 var(--sp-3); }
.radios legend { margin-bottom: 6px; }
.radios label { display: flex; gap: 8px; align-items: center; color: var(--text); padding: 4px 0; }
.check { display: flex; gap: 8px; align-items: center; font-size: var(--fs-sm); color: var(--text-2); margin: var(--sp-2) 0; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; }
.switch { appearance: none; -webkit-appearance: none; width: 40px !important; height: 22px !important; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border-strong); position: relative; flex: 0 0 auto; cursor: pointer; transition: background var(--t-fast), border-color var(--t-fast); margin: 0; }
.switch::after { content: ""; position: absolute; top: 2px; inset-inline-start: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--text-2); transition: inset-inline-start var(--t-fast), background var(--t-fast); }
.switch:checked { background: var(--accent); border-color: var(--accent); }
.switch:checked::after { inset-inline-start: 20px; background: var(--accent-ink); }
.switch:disabled { opacity: .5; cursor: not-allowed; }
.switch-row { display: flex; gap: 12px; align-items: center; cursor: pointer; }

/* Tags, badges, statuses */
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 500; line-height: 1; padding: 4px 8px; border-radius: var(--r-pill); background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.tag-sim { background: var(--warn-soft); color: var(--warn); }
.tag-live { background: var(--accent-2-soft); color: var(--accent-2); }
.tag-kb { background: var(--accent-soft); color: var(--accent); }
.tag-warn { background: var(--warn-soft); color: var(--warn); }
.tag-sample { background: var(--accent-2-soft); color: var(--accent-2); }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); font-weight: 500; padding: 6px 10px; border-radius: var(--r-pill); border: 1px solid; white-space: nowrap; }
.badge-demo { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: var(--warn-soft); }
.badge-live { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: var(--ok-soft); }
.status { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500; padding: 3px 9px; border-radius: var(--r-pill); white-space: nowrap; }
.status-ok { background: var(--ok-soft); color: var(--ok); } .status-proc { background: var(--accent-2-soft); color: var(--accent-2); }
.status-pend { background: var(--surface-3); color: var(--text-2); } .status-err { background: var(--err-soft); color: var(--err); }
.spin { width: 11px; height: 11px; border-radius: 50%; border: 2px solid currentColor; border-top-color: transparent; animation: spin .9s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
.dot-ok { background: var(--ok); } .dot-warn { background: var(--warn); }
.notice { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: var(--r); background: var(--accent-2-soft); color: var(--text); font-size: var(--fs-sm); margin-bottom: var(--sp-4); }
.notice .ic { color: var(--accent-2); margin-top: 2px; }
.notice-err { background: var(--err-soft); } .notice-err .ic { color: var(--err); }

/* ---------------- App shell ---------------- */
.app { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 100dvh; }
.rail { position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: var(--sp-6); padding: var(--sp-5) var(--sp-3); background: var(--bg-2); border-inline-end: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; color: var(--text); text-decoration: none; }
.brand-mark { width: 32px; height: 32px; color: var(--accent); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 600; font-size: 17px; letter-spacing: .02em; }
.brand-sub { font-size: var(--fs-xs); color: var(--text-3); }
.nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r); color: var(--text-2); text-decoration: none; font-weight: 500; transition: background var(--t-fast), color var(--t-fast); position: relative; }
.nav a:hover { background: var(--surface); color: var(--text); }
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"]::before { content: ""; position: absolute; inset-inline-start: -12px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
[dir="rtl"] .nav a[aria-current="page"]::before { border-radius: 3px 0 0 3px; }
.nav a[aria-current="page"] .ic { color: var(--accent); }
.rail-foot { margin-top: auto; padding: 0 8px; }
.mode-chip { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-xs); color: var(--text-2); }
.main { min-width: 0; outline: none; }
.view.enter { animation: viewIn .26s cubic-bezier(.2, .7, .2, 1); }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------------- Assistant workspace ---------------- */
.view-assistant { display: flex; flex-direction: column; height: 100dvh; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3) var(--sp-4); flex-wrap: wrap; padding: var(--sp-4) var(--sp-6); border-bottom: 1px solid var(--border); background: var(--bg); }
.session { min-width: 0; flex: 1 1 260px; }
.eyebrow { font-family: var(--f-mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
:lang(ar) .eyebrow { font-family: var(--f-sans); letter-spacing: 0; font-size: 12px; }
/* Single-line labels: own bidi for their text, but aligned with the interface direction. */
.conv-title, .hi-title, .hi-prev, .src-title, .reader-head h2, #srcTitle, .cite-t, .file-pick b { unicode-bidi: plaintext; }
[dir="ltr"] :is(.conv-title, .hi-title, .hi-prev, .src-title, .reader-head h2, #srcTitle, .cite-t, .file-pick b) { text-align: left; }
[dir="rtl"] :is(.conv-title, .hi-title, .hi-prev, .src-title, .reader-head h2, #srcTitle, .cite-t, .file-pick b) { text-align: right; }
.conv-title { font-size: var(--fs-lg); line-height: 1.3; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-meta { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

.workspace { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); }
.workspace.text-only { grid-template-columns: minmax(0, 1fr); }
.workspace.text-only .stage-col { display: none; }
.stage-col { display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-5); border-inline-end: 1px solid var(--border); overflow-y: auto; min-height: 0; background: var(--bg); }

/* Stage */
.stage { --state: var(--border-strong); position: relative; border-radius: var(--r-lg); background: radial-gradient(120% 80% at 50% 20%, #17304A 0%, var(--stage) 62%); color: #E9F0F8; padding: var(--sp-4); display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); min-height: 380px; overflow: hidden; border: 1px solid rgba(255, 255, 255, .06); box-shadow: var(--sh-2); }
.stage-top { align-self: stretch; display: flex; justify-content: space-between; align-items: center; gap: 8px; z-index: 2; }
.stage-tools { display: flex; gap: 6px; align-items: center; }
.state-pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 10px; border-radius: var(--r-pill); background: rgba(0, 0, 0, .28); border: 1px solid rgba(255, 255, 255, .1); font-size: var(--fs-xs); font-weight: 500; color: #DCE6F2; min-width: 0; }
.state-pill span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.state-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--state); flex: 0 0 auto; transition: background var(--t); }
.avatar-wrap { position: relative; width: min(232px, 70%); aspect-ratio: 200 / 220; margin-top: 4px; }
.avatar { width: 100%; height: 100%; display: block; position: relative; z-index: 1; }
.halo { position: absolute; left: 50%; top: 47%; width: 96%; aspect-ratio: 1; transform: translate(-50%, -50%); border-radius: 50%; border: 2px solid var(--state); opacity: .9; transition: border-color var(--t), box-shadow var(--t); z-index: 0; }
.stage[data-state="idle"] { --state: #5B6E88; }
.stage[data-state="listening"] { --state: var(--accent); }
.stage[data-state="processing"] { --state: #77B8FF; }
.stage[data-state="speaking"] { --state: var(--accent); }
.stage[data-state="paused"] { --state: #F0B45C; }
.stage[data-state="error"] { --state: #F07178; }
.stage[data-state="listening"] .halo { animation: ring 1.6s ease-out infinite; }
.stage[data-state="speaking"] .halo { box-shadow: 0 0 0 6px rgba(66, 214, 197, .1), 0 0 40px rgba(66, 214, 197, .18); }
.stage[data-state="processing"] .halo { border-style: dashed; animation: spin 6s linear infinite; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(66, 214, 197, .35); } 100% { box-shadow: 0 0 0 18px rgba(66, 214, 197, 0); } }

/* Avatar art (from the original player, refined) */
.p-lina { --skin: #C68E6C; --skin2: #AF7756; --hair: #2A1912; --shirt: #3F7F95; }
.p-karim { --skin: #D7A884; --skin2: #BE8D69; --hair: #231C19; --shirt: #4E6CA8; }
.a-skin { fill: var(--skin); } .a-skin2 { fill: var(--skin2); } .a-hair { fill: var(--hair); } .a-shirt { fill: var(--shirt); }
.a-dark { fill: #1B1412; } .a-lip { fill: #8E4B3E; } .a-steth { fill: none; stroke: #2E3A48; stroke-width: 3; stroke-linecap: round; }
.p-lina .karim-only, .p-karim .lina-only { display: none; }
.eyes { transform-box: fill-box; transform-origin: center; animation: blink 4.6s infinite; }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.08); } }
.mouth-in { transform-box: fill-box; transform-origin: center; transform: scaleY(.22); transition: transform .15s; }
.stage[data-state="speaking"]:not(.captions-only) .mouth-in { animation: talk .42s infinite alternate; }
.stage.captions-only[data-state="speaking"] .mouth-in { animation: talk 1.2s infinite alternate; }
@keyframes talk { 0% { transform: scaleY(.3); } 25% { transform: scaleY(1); } 50% { transform: scaleY(.5); } 75% { transform: scaleY(.9); } 100% { transform: scaleY(.35); } }
.head { transform-box: view-box; transform-origin: 100px 150px; transition: transform .4s ease; }
.stage[data-state="speaking"] .head { animation: bob 3.2s ease-in-out infinite; }
.stage[data-state="listening"] .head { transform: rotate(-3deg); }
.stage[data-state="processing"] .eyes { transform: translateY(-2px); animation: none; }
.stage[data-state="error"] .brows { transform: translateY(2px); }
@keyframes bob { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(1.4deg); } 70% { transform: rotate(-1.2deg); } }

/* Listening waveform, thinking dots, paused badge */
.wave { position: absolute; z-index: 2; inset-inline: 0; bottom: 4%; display: none; justify-content: center; align-items: flex-end; gap: 4px; height: 30px; }
.wave i { width: 4px; height: 30%; border-radius: 3px; background: var(--accent); animation: wave 1s ease-in-out infinite; }
.wave i:nth-child(2) { animation-delay: .12s; } .wave i:nth-child(3) { animation-delay: .24s; } .wave i:nth-child(4) { animation-delay: .36s; }
.wave i:nth-child(5) { animation-delay: .24s; } .wave i:nth-child(6) { animation-delay: .12s; } .wave i:nth-child(7) { animation-delay: 0s; }
@keyframes wave { 0%, 100% { height: 25%; } 50% { height: 100%; } }
.stage[data-state="listening"] .wave { display: flex; }
.think { position: absolute; z-index: 2; top: 6%; inset-inline-end: 4%; display: none; gap: 5px; padding: 8px 10px; border-radius: 14px; background: rgba(0, 0, 0, .4); border: 1px solid rgba(255, 255, 255, .12); }
.think i { width: 7px; height: 7px; border-radius: 50%; background: #77B8FF; animation: dots 1.2s infinite; }
.think i:nth-child(2) { animation-delay: .15s; } .think i:nth-child(3) { animation-delay: .3s; }
@keyframes dots { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.stage[data-state="processing"] .think { display: flex; }
.state-badge { position: absolute; z-index: 2; bottom: 6%; inset-inline-end: 12%; display: none; width: 40px; height: 40px; border-radius: 50%; place-items: center; background: #F0B45C; color: #2A1A02; box-shadow: var(--sh-2); }
.stage[data-state="paused"] .state-badge { display: grid; }
.stage[data-state="paused"] .avatar, .stage[data-state="error"] .avatar { filter: saturate(.7) brightness(.9); }
.caption { min-height: 3em; width: 100%; text-align: center; font-size: var(--fs-sm); line-height: 1.5; color: #DCE6F2; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; z-index: 2; }
.stage-error { position: absolute; inset: auto var(--sp-4) var(--sp-4); z-index: 4; background: rgba(36, 12, 16, .92); border: 1px solid rgba(240, 113, 120, .5); border-radius: var(--r); padding: var(--sp-3); display: flex; flex-direction: column; gap: 8px; font-size: var(--fs-sm); }
.stage-error .ic { color: #F07178; }
.stage-video { position: absolute; inset: 0; z-index: 5; background: #000; display: flex; align-items: center; justify-content: center; }
.stage-video video { width: 100%; height: 100%; object-fit: contain; }
.stage-video-close { position: absolute; top: 10px; inset-inline-end: 10px; }

/* Playback toolbar */
.playback { display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--border); }
.pb-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; min-width: 38px; border-radius: var(--r); border: 0; background: transparent; color: var(--text-2); padding: 0 8px; transition: background var(--t-fast), color var(--t-fast); }
.pb-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.pb-btn:disabled { opacity: .4; }
.pb-btn[aria-pressed="true"] { color: var(--warn); background: var(--warn-soft); }
.pb-main { flex: 1; background: var(--surface-2); color: var(--text); font-weight: 500; font-size: var(--fs-sm); }
.pb-main:hover:not(:disabled) { background: var(--surface-3); }
.playback .sel-sm { margin-inline-start: auto; }
.pb-note { font-size: var(--fs-xs); color: var(--warn); padding-inline: 4px; }
.kb-indicator { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--border); color: var(--text); text-decoration: none; transition: border-color var(--t-fast), background var(--t-fast); }
.kb-indicator:hover { border-color: var(--accent-line); background: var(--surface-2); }
.kb-indicator > .ic:first-child { color: var(--accent); }
.kb-indicator.is-empty > .ic:first-child { color: var(--warn); }
.kb-ind-text { display: flex; flex-direction: column; flex: 1; min-width: 0; font-size: var(--fs-xs); color: var(--text-2); }
.kb-ind-text b { font-size: var(--fs-sm); color: var(--text); font-weight: 500; }

/* Conversation column */
.chat-col { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.transcript { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: var(--sp-6) var(--sp-6) var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-4); scroll-behavior: auto; }
.transcript > * { width: 100%; max-width: 780px; margin-inline: auto; }
.transcript:focus-visible { outline-offset: -2px; }
.msg { display: flex; gap: 10px; animation: msgIn .26s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-user { flex-direction: column; align-items: flex-end; }
.bubble { padding: 10px 14px; border-radius: 14px; max-width: min(620px, 92%); overflow-wrap: anywhere; unicode-bidi: plaintext; }
.msg-user .bubble { background: var(--user-bubble); border-end-end-radius: 4px; white-space: pre-wrap; }
.msg-assistant .bubble { background: var(--surface); border: 1px solid var(--border); border-end-start-radius: 4px; max-width: 100%; }
.msg-av { width: 32px; height: 32px; flex: 0 0 auto; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); margin-top: 22px; }
.msg-av .ic { width: 22px; height: 22px; }
.msg-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.msg-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: var(--fs-xs); color: var(--text-3); }
.who { font-weight: 600; color: var(--text-2); margin-inline-end: 2px; }
.msg-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 11.5px; color: var(--text-3); }
.msg-meta .lang-code { font-size: 11px; padding: 1px 5px; border-radius: 4px; background: var(--surface-2); }
.via { display: inline-flex; align-items: center; gap: 4px; }
.msg-actions { display: inline-flex; gap: 2px; margin-inline-start: 4px; }
.mini-btn { width: 30px; height: 30px; border-radius: 8px; border: 0; background: transparent; color: var(--text-3); display: inline-grid; place-items: center; }
.mini-btn:hover { background: var(--surface-2); color: var(--text); }
.msg-assistant.is-speaking .bubble { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.msg-assistant.is-speaking [data-speak] { color: var(--accent); }
.rich p { margin: 0 0 8px; } .rich p:last-child { margin: 0; }
.rich ul { margin: 4px 0 8px; padding-inline-start: 20px; } .rich ul:last-child { margin-bottom: 0; }
.rich li { margin: 2px 0; }
.rich a { color: var(--accent); }
.blk { transition: background var(--t-fast); border-radius: 4px; }
.blk.speaking { background: var(--accent-soft); box-shadow: 0 0 0 3px var(--accent-soft); }
.cite-ref { border: 0; background: var(--accent-soft); color: var(--accent); font-family: var(--f-mono); font-size: 11px; border-radius: 4px; padding: 0 5px; margin-inline: 2px; vertical-align: 1px; line-height: 1.6; }
.cite-ref:hover { background: var(--accent); color: var(--accent-ink); }
.msg-note { display: flex; gap: 6px; align-items: flex-start; font-size: var(--fs-xs); color: var(--text-2); }
.msg-note .ic { margin-top: 3px; color: var(--accent-2); }
.cites { width: 100%; }
.cites-lbl { font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
:lang(ar) .cites-lbl { text-transform: none; letter-spacing: 0; font-size: 12px; }
.cites ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.cite { display: inline-flex; align-items: center; gap: 7px; max-width: 100%; border: 1px solid var(--border); background: var(--surface-2); border-radius: var(--r); padding: 6px 10px; font-size: var(--fs-xs); text-align: start; transition: border-color var(--t-fast), background var(--t-fast); }
.cite:hover { border-color: var(--accent-line); background: var(--surface-3); }
.cite .ic { color: var(--text-3); }
.cite-n { font-family: var(--f-mono); font-size: 11px; color: var(--accent); }
.cite-t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.cite-loc { font-variant-numeric: tabular-nums; font-size: 11.5px; color: var(--text-2); padding-inline-start: 7px; border-inline-start: 1px solid var(--border-strong); }
.cites-note { font-size: 11.5px; color: var(--text-3); margin-top: 6px; }
.msg-system { text-align: center; font-size: var(--fs-xs); color: var(--text-3); display: flex; align-items: center; gap: 12px; }
.msg-system::before, .msg-system::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.msg-error { align-items: flex-start; padding: 12px 14px; border-radius: var(--r); background: var(--err-soft); border: 1px solid color-mix(in srgb, var(--err) 35%, transparent); font-size: var(--fs-sm); }
.msg-error > .ic { color: var(--err); margin-top: 2px; }
.msg-error div { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.msg-pending .bubble { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; color: var(--text-2); font-size: var(--fs-sm); }
.msg-pending #partial:empty { display: none; }
.msg-pending #partial { flex-basis: 100%; color: var(--text); font-size: var(--fs); }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-2); animation: dots 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }

/* Empty state */
.transcript.is-empty { justify-content: center; }
.empty-chat { display: flex; flex-direction: column; gap: var(--sp-5); padding-block: var(--sp-4); }
.empty-chat h2 { font-size: var(--fs-xl); }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; color: var(--text-2); }
.step-n { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; flex: 0 0 auto; background: var(--surface-2); border: 1px solid var(--border-strong); font-family: var(--f-mono); font-size: 12px; color: var(--accent); }
.sugg { display: flex; flex-direction: column; gap: 8px; }
.sugg-lbl { font-size: var(--fs-xs); color: var(--text-3); font-weight: 500; }
.sugg-btn { display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: start; padding: 12px 14px; border-radius: var(--r); border: 1px solid var(--border); background: var(--surface); color: var(--text); transition: border-color var(--t-fast), background var(--t-fast); }
.sugg-btn:hover { border-color: var(--accent-line); background: var(--surface-2); }
.sugg-btn .ic { color: var(--text-3); }
.demo-note { display: flex; gap: 8px; align-items: flex-start; font-size: var(--fs-xs); color: var(--text-3); padding: 10px 12px; border-radius: var(--r); border: 1px dashed var(--border-strong); }
.demo-note .ic { margin-top: 1px; color: var(--warn); }

/* Composer */
.composer { padding: var(--sp-3) var(--sp-6) var(--sp-4); border-top: 1px solid var(--border); background: var(--bg); display: flex; flex-direction: column; gap: 8px; }
.composer > * { width: 100%; max-width: 780px; margin-inline: auto; }
.lang-row { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; }
.lang-field { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1 1 200px; }
.lang-field label { font-size: 11.5px; color: var(--text-3); font-weight: 500; }
.lang-ctl { display: flex; align-items: center; gap: 6px; min-width: 0; }
.lang-ctl .sel { flex: 1; min-width: 0; }
.lang-code { font-size: 11px; color: var(--text-3); background: var(--surface-2); border: 1px solid var(--border); padding: 3px 6px; border-radius: 5px; white-space: nowrap; direction: ltr; }
.lang-row .icon-btn { margin-bottom: 0; }
.lang-hint { font-size: var(--fs-xs); color: var(--warn); }
.scope-chip { display: inline-flex; align-self: flex-start; width: auto !important; margin-inline: 0 auto !important; align-items: center; gap: 6px; padding: 4px 4px 4px 10px; border-radius: var(--r-pill); background: var(--accent-soft); color: var(--accent); font-size: var(--fs-xs); max-width: 100%; }
@media (min-width: 821px) { .scope-chip { margin-inline-start: max(0px, calc((100% - 780px) / 2)) !important; } }
.scope-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-x { border: 0; background: transparent; color: inherit; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; }
.chip-x:hover { background: rgba(255, 255, 255, .1); }
.input-row { display: flex; align-items: flex-end; gap: 8px; padding: 6px; border-radius: 16px; border: 1px solid var(--border-strong); background: var(--surface); transition: border-color var(--t-fast), box-shadow var(--t-fast); }
.input-row:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.input-wrap textarea { border: 0; background: transparent; resize: none; padding: 10px 6px; font-size: var(--fs); line-height: 1.45; min-height: 44px; max-height: 160px; width: 100%; box-shadow: none !important; }
.voice-review { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--accent); padding: 0 6px 4px; }
.mic, .send { position: relative; flex: 0 0 auto; width: 44px; height: 44px; border-radius: 12px; border: 0; display: grid; place-items: center; transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast); }
.mic { background: var(--surface-2); color: var(--text); }
.mic:hover:not(:disabled) { background: var(--surface-3); }
.mic.is-unavailable { color: var(--text-3); }
.mic.is-rec { background: var(--err); color: #fff; }
.mic-rings { position: absolute; inset: 0; border-radius: inherit; pointer-events: none; }
.mic.is-rec .mic-rings { animation: micPulse 1.3s ease-out infinite; }
@keyframes micPulse { 0% { box-shadow: 0 0 0 0 rgba(240, 113, 120, .5); } 100% { box-shadow: 0 0 0 12px rgba(240, 113, 120, 0); } }
.send { background: var(--accent); color: var(--accent-ink); }
.send:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, white); }
.send:active, .mic:active { transform: scale(.96); }
.send.is-stop { background: var(--surface-3); color: var(--text); }
[dir="rtl"] .send .ic { transform: scaleX(-1); }
.composer-note { font-size: var(--fs-xs); padding: 8px 10px; border-radius: var(--r-sm); background: var(--surface-2); color: var(--text-2); }
.note-warn { background: var(--warn-soft); color: var(--warn); } .note-err { background: var(--err-soft); color: var(--err); }
.composer-hint { font-size: 11.5px; color: var(--text-3); text-align: center; }

/* ---------------- Pages (Knowledge, History, Settings) ---------------- */
.view-page { padding: var(--sp-8) var(--sp-8) var(--sp-8); max-width: 1180px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-6); }
.page-head h1 { font-size: var(--fs-xl); }
.page-sub { color: var(--text-2); margin-top: 4px; max-width: 64ch; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-5); }
.stat { padding: 14px 16px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; border-top: 3px solid var(--border-strong); }
.stat-ok { border-top-color: var(--ok); } .stat-proc { border-top-color: var(--accent-2); } .stat-err { border-top-color: var(--err); } .stat-pend { border-top-color: var(--warn); }
.stat-n { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-l { font-size: var(--fs-xs); color: var(--text-2); }
.toolbar { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-4); }
.search { position: relative; flex: 1 1 240px; display: flex; }
.search .ic { position: absolute; inset-inline-start: 11px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search input { width: 100%; min-height: 40px; padding-inline-start: 38px; }
.kb-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
.kb-list:has(.empty-card) { border: 0; background: transparent; }
.src-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--sp-3) var(--sp-4); padding: var(--sp-4); border-top: 1px solid var(--border); align-items: start; transition: background var(--t-fast); }
.src-row:first-child { border-top: 0; }
.src-row:hover { background: var(--bg-2); }
.src-row.is-inactive .src-main { opacity: .65; }
.src-ic { width: 40px; height: 40px; border-radius: var(--r); display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); flex: 0 0 auto; }
.type-video .ic, .type-video_url .ic { color: var(--accent-2); } .type-pdf .ic, .type-docx .ic, .type-txt .ic, .type-text .ic { color: var(--accent); } .type-web_url .ic { color: var(--warn); }
.src-main { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.src-title { border: 0; background: none; padding: 0; text-align: start; font-weight: 600; font-size: var(--fs); color: var(--text); overflow-wrap: anywhere; }
.src-title:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.src-meta { font-size: var(--fs-xs); color: var(--text-3); display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.src-err, .src-note { display: flex; gap: 6px; align-items: flex-start; font-size: var(--fs-xs); }
.src-err { color: var(--err); } .src-note { color: var(--text-2); }
.src-err .ic, .src-note .ic { margin-top: 3px; }
.src-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.src-actions { display: flex; gap: 4px; align-items: center; }
.progress { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; max-width: 420px; margin-top: 4px; }
.progress i { display: block; height: 100%; border-radius: 3px; background: var(--accent-2); transition: width .5s ease; }
.progress.is-indet i { animation: indet 1.4s ease-in-out infinite; }
@keyframes indet { 0% { margin-inline-start: -35%; } 100% { margin-inline-start: 100%; } }
.prog-lbl { font-size: 11.5px; color: var(--accent-2); }
.empty-card { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: var(--sp-8) var(--sp-5); border: 1px dashed var(--border-strong); border-radius: var(--r-lg); color: var(--text-2); }
.empty-card .ic-lg { color: var(--text-3); }
.empty-card h2 { font-size: var(--fs-md); color: var(--text); }

/* History */
.hist-layout { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: var(--sp-5); align-items: start; }
.hist-side .toolbar { flex-direction: column; }
.hist-side .toolbar .sel { width: 100%; }
.hist-list { display: flex; flex-direction: column; gap: 4px; }
.group-h { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin: var(--sp-3) 0 4px; }
:lang(ar) .group-h { text-transform: none; letter-spacing: 0; font-size: 12.5px; }
.hist-item { display: flex; flex-direction: column; gap: 2px; text-align: start; padding: 10px 12px; border-radius: var(--r); border: 1px solid transparent; background: transparent; transition: background var(--t-fast), border-color var(--t-fast); }
.hist-item:hover { background: var(--surface); }
.hist-item[aria-current="true"] { background: var(--surface-2); border-color: var(--border-strong); }
.hi-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hi-meta { font-size: 11.5px; color: var(--text-3); }
.hi-prev { font-size: var(--fs-xs); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-line { font-size: var(--fs-sm); padding: 8px 12px; }
.hist-reader { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-5); min-height: 320px; }
.reader-back { display: none; margin-bottom: var(--sp-3); }
.reader-head { display: flex; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; padding-bottom: var(--sp-4); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-4); }
.reader-head h2 { font-size: var(--fs-lg); margin-top: 2px; overflow-wrap: anywhere; }
.reader-body { display: flex; flex-direction: column; gap: var(--sp-4); }
.reader-body .msg-assistant .bubble { background: var(--bg-2); }

/* Settings */
.set-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: var(--sp-6); align-items: start; }
.set-nav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: var(--sp-5); }
.set-tab { text-align: start; padding: 9px 12px; border-radius: var(--r); border: 0; background: transparent; color: var(--text-2); font-weight: 500; font-size: var(--fs-sm); transition: background var(--t-fast), color var(--t-fast); }
.set-tab:hover { background: var(--surface); color: var(--text); }
.set-tab[aria-current="true"] { background: var(--surface-2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
[dir="rtl"] .set-tab[aria-current="true"] { box-shadow: inset -3px 0 0 var(--accent); }
.set-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-6); max-width: 760px; }
.set-h { font-size: var(--fs-lg); margin-bottom: var(--sp-4); }
.set-sub { font-size: var(--fs-md); margin: var(--sp-6) 0 4px; }
.set-intro { color: var(--text-2); margin-bottom: var(--sp-4); }
.set-row { padding: var(--sp-4) 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.set-h + .set-row, .set-intro + .set-row { border-top: 0; padding-top: 0; }
.set-label { font-weight: 500; }
.set-row .sel { align-self: flex-start; min-width: min(320px, 100%); }
.set-help { font-size: var(--fs-xs); color: var(--text-3); }
.switch-row + .set-help { padding-inline-start: 52px; }
.set-note { display: flex; gap: 8px; align-items: flex-start; font-size: var(--fs-xs); color: var(--text-2); padding: 10px 12px; border-radius: var(--r); background: var(--bg-2); margin-top: var(--sp-3); }
.set-note .ic { margin-top: 1px; color: var(--accent-2); }
.set-warn { display: flex; gap: 10px; align-items: flex-start; font-size: var(--fs-sm); color: var(--text); padding: 12px 14px; border-radius: var(--r); background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); margin-bottom: var(--sp-3); }
.set-warn .ic { margin-top: 2px; color: var(--warn); flex: none; }
.set-warn p { margin: 4px 0 0; color: var(--text-2); overflow-wrap: anywhere; }
.set-warn a { color: var(--accent-2); }
.set-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-4); }
.bullets { margin: 0 0 var(--sp-3); padding-inline-start: 20px; color: var(--text-2); display: grid; gap: 4px; }
.prov-list { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.prov { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--r); cursor: pointer; }
.prov:has(input:disabled) { cursor: not-allowed; opacity: .75; }
.prov:has(input:checked) { border-color: var(--accent-line); background: var(--accent-soft); }
.prov input { margin-top: 3px; }
.prov-main { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: var(--fs-sm); }
.prov-main span { color: var(--text-2); font-size: var(--fs-xs); }
.cap-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }
.cap-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border); font-size: var(--fs-sm); flex-wrap: wrap; }
.cap-row:first-child { border-top: 0; }

/* ---------------- Dialogs ---------------- */
.dlg { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); border-radius: var(--r-lg); padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); box-shadow: var(--sh-3); }
.dlg-sm { width: min(440px, calc(100vw - 32px)); }
.dlg-wide { width: min(880px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(5, 10, 20, .62); backdrop-filter: blur(2px); }
.dlg[open] { animation: dlgIn .2s cubic-bezier(.2, .7, .2, 1); }
@keyframes dlgIn { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
.dlg-body { padding: var(--sp-6); display: flex; flex-direction: column; }
.dlg-body > h2 { font-size: var(--fs-lg); margin-bottom: var(--sp-2); }
.dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: var(--sp-4); }
.dlg-head h2 { font-size: var(--fs-lg); overflow-wrap: anywhere; }
.dlg-text { color: var(--text-2); margin-bottom: var(--sp-5); }
.dlg-note { font-size: var(--fs-xs); color: var(--text-3); margin-top: var(--sp-2); }
.dlg-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-5); }
.dlg-actions-split { justify-content: space-between; align-items: center; padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: var(--r); background: var(--bg-2); margin-bottom: var(--sp-4); }
.seg [role="tab"] { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 10px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text-2); font-weight: 500; font-size: var(--fs-sm); }
.seg [role="tab"][aria-selected="true"] { background: var(--surface-3); color: var(--text); box-shadow: var(--sh-1); }
.drop { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: var(--sp-6) var(--sp-4); border: 2px dashed var(--border-strong); border-radius: var(--r-lg); cursor: pointer; color: var(--text-2); transition: border-color var(--t-fast), background var(--t-fast); }
.drop:hover, .drop.is-over { border-color: var(--accent); background: var(--accent-soft); }
.drop:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.drop .ic-lg { color: var(--accent); }
.drop-main { font-weight: 500; color: var(--text); }
.drop-sub { font-size: var(--fs-xs); }
.file-pick { display: flex; align-items: center; gap: 12px; margin-top: var(--sp-3); padding: 10px 12px; border-radius: var(--r); background: var(--surface-2); }
.file-pick > .ic { color: var(--accent); }
.file-pick div { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: var(--fs-sm); }
.file-pick b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-pick span { font-size: var(--fs-xs); color: var(--text-3); }
.form-error { color: var(--err); background: var(--err-soft); padding: 8px 12px; border-radius: var(--r-sm); font-size: var(--fs-sm); margin-top: var(--sp-3); }
.src-head-l { display: flex; gap: 12px; align-items: flex-start; min-width: 0; }
.src-head-l .src-meta { margin-top: 4px; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--sp-5); margin-bottom: var(--sp-5); }
.meta-list { margin: 0; display: flex; flex-direction: column; }
.meta-list div { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); }
.meta-list dt { color: var(--text-3); }
.meta-list dd { margin: 0; overflow-wrap: anywhere; }
.pipeline h3, .sec-h { font-size: var(--fs-sm); font-weight: 600; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.pipeline ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.pipeline li { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: var(--fs-sm); color: var(--text-3); position: relative; }
.pipeline li:not(:last-child)::after { content: ""; position: absolute; inset-inline-start: 9px; top: 28px; height: 12px; width: 2px; background: var(--border-strong); }
.pipe-dot { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border-strong); display: grid; place-items: center; flex: 0 0 auto; }
.pipe-done { color: var(--text); } .pipe-done .pipe-dot { background: var(--ok); border-color: var(--ok); color: #04150D; }
.pipe-current { color: var(--text); font-weight: 500; } .pipe-current .pipe-dot { border-color: var(--accent-2); border-top-color: transparent; animation: spin 1s linear infinite; }
.pipe-failed { color: var(--err); } .pipe-failed .pipe-dot { background: var(--err); border-color: var(--err); color: #1A0507; }
.pipe-note { font-size: 11.5px; color: var(--text-3); margin-top: 8px; }
.src-video { margin-bottom: var(--sp-5); }
.src-video video { width: 100%; max-height: 320px; border-radius: var(--r); background: #000; display: block; }
.chunks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 340px; overflow-y: auto; }
.chunk { padding: 10px 12px; border-radius: var(--r); background: var(--bg-2); border: 1px solid transparent; font-size: var(--fs-sm); }
.chunk.is-focus { border-color: var(--accent-line); background: var(--accent-soft); }
.chunk-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.chunk-head .btn { margin-inline-start: auto; }
.loc { font-variant-numeric: tabular-nums; font-size: 11.5px; font-weight: 500; color: var(--accent); background: var(--accent-soft); padding: 2px 6px; border-radius: 4px; }
.chunk p { color: var(--text-2); }

/* Toasts */
.toasts { position: fixed; z-index: 60; inset-inline-end: 20px; top: 20px; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: none; display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r); background: var(--surface-3); border: 1px solid var(--border-strong); box-shadow: var(--sh-2); font-size: var(--fs-sm); animation: toastIn .22s cubic-bezier(.2, .7, .2, 1); transition: opacity .3s, transform .3s; }
.toast .ic { margin-top: 1px; }
.toast-ok .ic { color: var(--ok); } .toast-warn .ic { color: var(--warn); } .toast-err .ic { color: var(--err); } .toast-info .ic { color: var(--accent-2); }
.toast.out { opacity: 0; transform: translateY(-6px); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------- Responsive ---------------- */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); }
  .view-page { padding: var(--sp-6); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { position: fixed; z-index: 40; inset-inline: 0; bottom: 0; top: auto; height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px)); padding: 0 0 env(safe-area-inset-bottom, 0px); flex-direction: row; gap: 0; border-inline-end: 0; border-top: 1px solid var(--border); background: color-mix(in srgb, var(--bg-2) 94%, transparent); backdrop-filter: blur(8px); }
  .brand, .rail-foot { display: none; }
  .nav { flex-direction: row; flex: 1; }
  .nav li { flex: 1; }
  .nav a { flex-direction: column; gap: 3px; padding: 9px 4px; font-size: 11.5px; border-radius: 0; height: var(--nav-h); justify-content: center; text-align: center; }
  .nav a:hover { background: transparent; }
  .nav a[aria-current="page"] { background: transparent; color: var(--accent); }
  .nav a[aria-current="page"]::before { inset-inline-start: 30%; inset-inline-end: 30%; top: 0; bottom: auto; width: auto; height: 3px; border-radius: 0 0 3px 3px; }
  .main { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px)); }
  .view-assistant { height: calc(100dvh - var(--nav-h) - env(safe-area-inset-bottom, 0px)); }
  .toasts { top: 12px; inset-inline: 12px; max-width: none; }

  /* Compact header: title + icon actions on one row (labels stay available to screen readers). */
  .topbar { padding: 8px 12px; gap: 8px; flex-wrap: nowrap; }
  .session { flex: 1 1 auto; min-width: 0; }
  .eyebrow, .session-meta { display: none; }
  .conv-title { font-size: var(--fs-md); margin: 0; }
  .topbar-actions { flex-wrap: nowrap; gap: 6px; }
  .topbar-actions .badge span, .topbar-actions .btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .topbar-actions .badge { padding: 7px; }
  .topbar-actions .btn { padding: 0 10px; min-height: 36px; }
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .stage-col { border-inline-end: 0; border-bottom: 1px solid var(--border); padding: 8px 12px; overflow: visible; gap: 6px; }
  .stage { min-height: 0; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px 10px; gap: 4px 12px; box-shadow: none; }
  .stage-top { order: 2; flex: 1 1 0; min-width: 0; flex-direction: column; align-items: flex-start; gap: 6px; }
  .avatar-wrap { order: 1; width: 60px; flex: 0 0 60px; margin: 0; }
  .playback { padding: 3px; gap: 2px; }
  .pb-btn { height: 34px; min-width: 34px; }
  .pb-note { display: none; }
  .caption { order: 3; flex-basis: 100%; min-height: 0; text-align: start; -webkit-line-clamp: 2; }
  .caption:empty { display: none; }
  .wave { bottom: -4px; height: 18px; gap: 3px; } .wave i { width: 3px; }
  .think { top: -4px; inset-inline-end: -8px; padding: 5px 7px; } .think i { width: 5px; height: 5px; }
  .state-badge { width: 26px; height: 26px; inset-inline-end: -4px; bottom: 0; } .state-badge .ic { width: 14px; height: 14px; }
  .stage-error { position: static; order: 4; flex-basis: 100%; }
  .kb-indicator { display: none; }
  .transcript { padding: 16px; gap: 14px; }
  .composer { padding: 10px 16px 12px; }
  .lang-field { flex-basis: 140px; }
  .lang-code { display: none; }
  .composer-hint { display: none; }
  .msg-av { display: none; }
  .bubble { max-width: 100%; }
  .msg-user .bubble { max-width: 88%; }

  .view-page { padding: 20px 16px 28px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .src-row { grid-template-columns: auto minmax(0, 1fr); }
  .src-side { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: center; }
  .hist-layout { grid-template-columns: minmax(0, 1fr); }
  .hist-layout .hist-reader { display: none; }
  .hist-layout.show-reader .hist-side { display: none; }
  .hist-layout.show-reader .hist-reader { display: block; padding: 16px; }
  .reader-back { display: inline-flex; }
  .set-layout { grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); }
  .set-nav { position: static; flex-direction: row; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
  .set-tab { white-space: nowrap; flex: 0 0 auto; }
  .set-tab[aria-current="true"] { box-shadow: inset 0 -2px 0 var(--accent) !important; }
  .set-panel { padding: var(--sp-4); }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .dlg-body { padding: var(--sp-4); }
  .meta-list div { grid-template-columns: 100px minmax(0, 1fr); }
}
@media (max-width: 420px) {
  .pb-main span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .lang-row .icon-btn { width: 32px; }
  .seg [role="tab"] span { font-size: 12px; }
}
@media (max-width: 900px) and (max-height: 560px) {
  .stage-col { display: none; }
  .workspace { grid-template-rows: minmax(0, 1fr); }
}

/* ---------------- Motion preferences ---------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .stage[data-state="speaking"] .mouth-in { animation: talk .9s infinite alternate !important; animation-duration: .9s !important; animation-iteration-count: infinite !important; }
  .spin, .pipe-current .pipe-dot { animation: spin 3s linear infinite !important; animation-iteration-count: infinite !important; animation-duration: 3s !important; }
}
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
.reduce-motion .stage[data-state="speaking"] .mouth-in { animation: talk .9s infinite alternate !important; animation-duration: .9s !important; animation-iteration-count: infinite !important; }
.reduce-motion .spin, .reduce-motion .pipe-current .pipe-dot { animation: spin 3s linear infinite !important; animation-duration: 3s !important; animation-iteration-count: infinite !important; }

/* =====================================================================
   0.3 — voice workflow, provider settings, Knowledge workspace
   ===================================================================== */
:root { --lvl: 0; }
body.modal-open { overflow: hidden; }
.nav-btn { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; border-radius: var(--r); border: 0; background: transparent; color: var(--text-2); font-weight: 500; text-align: start; transition: background var(--t-fast), color var(--t-fast); }
.nav-btn:hover { background: var(--surface); color: var(--text); }
button.kb-indicator { width: 100%; text-align: start; font: inherit; cursor: pointer; }

/* Provider status chips in the header */
.status-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 240px; padding: 6px 10px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 500; text-decoration: none; border: 1px solid; white-space: nowrap; }
.status-chip span { overflow: hidden; text-overflow: ellipsis; }
.chip-ok { color: var(--ok); background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.chip-warn, .chip-pend { color: var(--warn); background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.chip-err { color: var(--err); background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 35%, transparent); }
.status-chip:hover { filter: brightness(1.1); }

/* New avatar states */
.stage[data-state="permission"] { --state: #77B8FF; }
.stage[data-state="permission"] .halo { animation: ring 1.6s ease-out infinite; }
.stage[data-state="review"] { --state: #77B8FF; }
.stage[data-state="generating"] { --state: var(--accent); }
.stage[data-state="generating"] .halo { border-style: dashed; animation: spin 4s linear infinite; }
.stage[data-state="generating"] .think { display: flex; }
.stage[data-state="generating"] .think i { background: var(--accent); }
/* The listening waveform follows the real microphone level (--lvl, 0–1). */
.stage[data-state="listening"] .wave i { animation: none; height: calc(18% + var(--lvl) * 82%); transition: height .08s linear; }
.stage[data-state="listening"] .wave i:nth-child(2n) { height: calc(14% + var(--lvl) * 60%); }
.stage[data-state="listening"] .wave i:nth-child(3n) { height: calc(10% + var(--lvl) * 95%); }

/* Playback progress */
.playback { flex-direction: column; align-items: stretch; }
.pb-row { display: flex; align-items: center; gap: 6px; }
.pb-row .sel-sm { margin-inline-start: auto; }
.pb-progress { display: flex; align-items: center; gap: 10px; padding: 4px 6px 2px; }
.pb-bar { flex: 1; height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.pb-bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .25s linear; }
.pb-bar.is-indet i { width: 30% !important; animation: indet 1.4s ease-in-out infinite; }
.pb-time { font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pb-main.is-loading .ic { animation: pulseOp 1s ease-in-out infinite; }
@keyframes pulseOp { 50% { opacity: .35; } }

/* Voice panel (recording / transcribing / review / error) */
.voice-panel { width: 100%; max-width: 780px; margin-inline: auto; }
.vp { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 14px; border-radius: 16px; border: 1px solid var(--border-strong); background: var(--surface); }
.vp-main { flex: 1 1 200px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.vp-main b { font-weight: 600; }
.vp-sub { font-size: var(--fs-xs); color: var(--text-3); }
.vp-live { font-size: var(--fs-sm); color: var(--text-2); font-style: italic; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vp-live:empty { display: none; }
.vp-rec { border-color: color-mix(in srgb, var(--err) 55%, transparent); box-shadow: 0 0 0 3px var(--err-soft); }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--err); flex: 0 0 auto; animation: pulseOp 1.2s ease-in-out infinite; }
.rec-time { font-variant-numeric: tabular-nums; color: var(--err); font-weight: 600; margin-inline-start: 6px; }
.meter { display: inline-flex; align-items: center; gap: 3px; height: 26px; }
.meter i { width: 4px; border-radius: 2px; background: var(--err); height: calc(20% + var(--lvl) * 80%); transition: height .08s linear; }
.meter i:nth-child(2), .meter i:nth-child(4) { height: calc(15% + var(--lvl) * 60%); }
.meter i:nth-child(3) { height: calc(25% + var(--lvl) * 75%); }
.vp-wait .spin { width: 16px; height: 16px; color: var(--accent-2); }
.vp-review { border-color: var(--accent-line); background: var(--accent-soft); }
.vp-review > .ic { color: var(--accent); }
.vp-err { border-color: color-mix(in srgb, var(--err) 45%, transparent); background: var(--err-soft); }
.vp-err > .ic { color: var(--err); }

/* Live Voice */
.live-btn { flex: 0 0 auto; height: 44px; display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--accent-line); background: transparent; color: var(--accent); font-weight: 600; font-size: var(--fs-sm); }
.live-btn:hover { background: var(--accent-soft); }
.live-panel { width: 100%; max-width: 780px; margin-inline: auto; padding: 12px 14px; border-radius: 16px; border: 1px solid var(--accent-line); background: var(--surface); display: flex; flex-direction: column; gap: 8px; }
.live-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.live-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--text-3); flex: 0 0 auto; }
.live-dot.is-on { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.live-turns { display: flex; flex-direction: column; gap: 4px; max-height: 140px; overflow-y: auto; font-size: var(--fs-sm); }
.lt-user { color: var(--text-2); }
.tts-err { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: var(--fs-xs); color: var(--err); padding: 6px 10px; border-radius: var(--r-sm); background: var(--err-soft); }
.tts-slot:empty { display: none; }

/* Knowledge Base workspace dialog */
.kb-dlg { width: min(1180px, calc(100vw - 48px)); height: min(860px, calc(100dvh - 48px)); max-height: none; }
.kb-shell { display: flex; flex-direction: column; height: 100%; }
.kb-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 18px 22px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.kb-head-l { display: flex; gap: 12px; align-items: center; min-width: 0; }
.kb-head-ic { color: var(--accent); }
.kb-head h2 { font-size: var(--fs-lg); }
.kb-head .page-sub { margin-top: 2px; font-size: var(--fs-sm); }
.kb-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
.kb-main { overflow-y: auto; padding: 18px 22px; border-inline-end: 1px solid var(--border); }
.kb-main .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.kb-main .stat { padding: 10px 12px; }
.kb-main .stat-n { font-size: 22px; }
.kb-detail { overflow-y: auto; padding: 18px 22px; display: flex; flex-direction: column; gap: 14px; }
.kb-detail h3 { font-size: var(--fs-md); overflow-wrap: anywhere; }
.kb-detail h4 { font-size: var(--fs-sm); font-weight: 600; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.kb-detail .detail-grid { margin-bottom: 0; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.kb-detail .chunks { max-height: none; }
.kb-detail .notice { margin-bottom: 0; }
.kb-detail-empty { margin: auto; text-align: center; color: var(--text-3); display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 260px; }
.kb-back { display: none; align-self: flex-start; }
.detail-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding-top: 12px; border-top: 1px solid var(--border); }
.src-row.is-selected { background: var(--accent-soft); }
.src-row.is-selected .src-title { color: var(--accent); }
.kb-list .empty-card h3 { font-size: var(--fs-md); color: var(--text); }

/* Provider settings */
.server-off, .server-on { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r); margin-bottom: 14px; font-size: var(--fs-sm); }
.server-off { background: var(--warn-soft); }
.server-off .ic { color: var(--warn); margin-top: 2px; }
.server-off p { color: var(--text-2); margin: 4px 0 8px; }
.server-off code { display: inline-block; padding: 4px 8px; border-radius: 6px; background: var(--bg-2); margin-bottom: 8px; direction: ltr; }
.server-on { background: var(--ok-soft); color: var(--ok); align-items: center; }
.admin-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.admin-form { padding: 12px 14px; border: 1px dashed var(--border-strong); border-radius: var(--r); margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.admin-form input, .cred-form input { flex: 1 1 220px; min-height: 36px; }
.cred-card { border: 1px solid var(--border); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 10px; margin: 8px 0 14px; background: var(--bg-2); }
.cred-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.cred-msg { color: var(--err); }
.cred-meta { margin: 0; display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-sm); }
.cred-meta div { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 8px; }
.cred-meta dt { color: var(--text-3); }
.cred-meta dd { margin: 0; overflow-wrap: anywhere; }
.cred-form { display: flex; gap: 8px; flex-wrap: wrap; }
.cred-settings { margin-bottom: 8px; }
.cred-settings input[type="number"] { max-width: 160px; display: block; min-height: 36px; border: 1px solid var(--border-strong); background: var(--bg-2); border-radius: var(--r); padding: 6px 10px; color: var(--text); }
.prov-list legend.set-label { margin-bottom: 8px; padding: 0; }
.prov.is-pref { border-color: var(--accent-line); }
.table-wrap { overflow-x: auto; margin-bottom: 10px; }
table.usage { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table.usage th, table.usage td { text-align: start; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.usage thead th { color: var(--text-3); font-weight: 500; font-size: var(--fs-xs); }
table.usage td { font-variant-numeric: tabular-nums; }

@media (max-width: 900px) {
  .status-chip { max-width: 44px; padding: 7px; }
  .status-chip span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .nav-btn { flex-direction: column; gap: 3px; padding: 9px 4px; font-size: 11.5px; border-radius: 0; height: var(--nav-h); justify-content: center; text-align: center; }
  .kb-dlg { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; border-radius: 0; border: 0; }
  .kb-head { padding: 12px 14px; }
  .kb-head .page-sub { display: none; }
  .kb-body { grid-template-columns: minmax(0, 1fr); }
  .kb-main { padding: 14px; border-inline-end: 0; }
  .kb-detail { padding: 14px; display: none; }
  .kb-body.has-detail .kb-main { display: none; }
  .kb-body.has-detail .kb-detail { display: flex; }
  .kb-back { display: inline-flex; }
  .kb-main .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .vp { padding: 10px; gap: 8px; }
  .live-btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .live-btn { padding: 0 10px; }
  .cred-meta div { grid-template-columns: 90px minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .vp-review .vp-sub, .vp-rec .vp-sub { display: none; }
  .vp-review .row-gap .btn { padding: 0 8px; }
}

/* ===================== Laravel build: accounts, knowledge-base selector, sign-in ===================== */
@media (min-width: 901px) { .rail-foot { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; } }
.user-chip { font-size: var(--fs-xs); color: var(--text-2); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-logout { min-height: 32px; min-width: 32px; }
.kb-sel-wrap { display: inline-flex; align-items: center; gap: 6px; min-width: 0; padding-inline-start: 8px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); color: var(--text-2); }
.kb-sel-wrap[hidden] { display: none; }
.kb-sel-wrap .sel { border: 0; background-color: transparent; max-width: 260px; min-width: 0; text-overflow: ellipsis; }
.kb-bar { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.kb-bar .sel { min-width: 0; max-width: 100%; flex: 1 1 220px; }
.kb-table td .row-gap { flex-wrap: wrap; }
.cred-settings textarea, .cred-settings input[type="text"], .cred-settings input[type="email"], .cred-settings input[type="password"], .cred-settings input[type="date"] { width: 100%; max-width: 480px; }
.cred-settings .row-gap input[type="date"] { width: auto; }
@media (max-width: 900px) {
  /* The knowledge-base selector gets its own full-width row under the compact header. */
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  .kb-sel-wrap { order: 10; flex: 1 1 100%; }
  .kb-sel-wrap .sel { max-width: none; width: 100%; }
}
.auth-body { min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 600px at 20% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.auth { width: 100%; max-width: 420px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: calc(var(--r) * 2); padding: 28px 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; color: var(--accent); }
.auth-brand .brand-mark { width: 34px; height: 34px; }
.auth-title { margin: 0 0 4px; font-size: 1.5rem; }
.auth-sub { margin: 0 0 18px; color: var(--text-2); font-size: var(--fs-sm); }
.auth-form .field input { width: 100%; }
.auth-submit { width: 100%; margin-top: 8px; }
.auth-foot { margin: 16px 0 0; color: var(--text-3); font-size: var(--fs-xs); }

/* ===================== Learning workspace: Transcript and Assessment modes ===================== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-5); min-width: 0; }
.card-h { font-size: 1.05rem; margin: 0 0 var(--sp-4); }
.btn-block { width: 100%; }
.queue-banner { display: flex; gap: 8px; align-items: flex-start; margin: var(--sp-3) var(--sp-6) 0; padding: 10px 12px; border-radius: var(--r); background: var(--warn-soft); border: 1px solid var(--warn); font-size: var(--fs-sm); }
.queue-banner[hidden] { display: none; }
.queue-banner .ic { color: var(--warn); margin-top: 2px; flex: 0 0 auto; }
.pending-elapsed { font-variant-numeric: tabular-nums; }
.tts-alts { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; }
mark { background: var(--warn-soft); color: inherit; border-radius: 3px; padding: 0 1px; box-shadow: 0 0 0 1px var(--warn) inset; }

/* Transcript */
.tr-layout { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: var(--sp-5); padding: 0 var(--sp-6) var(--sp-6); align-items: start; }
.tr-side { display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }
.tr-input { display: flex; flex-direction: column; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.drop-sm { padding: var(--sp-4) var(--sp-3); }
.tr-or { display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: var(--fs-xs); }
.tr-or::before, .tr-or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
#trRec.is-recording { border-color: var(--err); color: var(--err); background: var(--err-soft); }
.tr-langs { display: grid; grid-template-columns: 1fr; gap: 0; }
.tr-langs .field { margin-bottom: var(--sp-2); }
.tr-langs .sel { width: 100%; }
.tr-history .search { margin-bottom: var(--sp-2); }
.tr-history .hist-item { width: 100%; }
.hist-item .status { font-size: 11px; padding: 1px 6px; }
.hist-item.is-uploading { opacity: .8; }
.tr-main { min-height: 420px; }
.tr-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-3); }
.tr-head h2 { margin: 2px 0 4px; font-size: 1.25rem; overflow-wrap: anywhere; }
.tr-head-l { min-width: 0; flex: 1 1 260px; }
.tr-rename input { min-width: 0; flex: 1 1 200px; }
.tr-langsum { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--sp-2) var(--sp-4); margin: 0 0 var(--sp-4); }
.tr-langsum div { display: flex; flex-direction: column; gap: 2px; }
.tr-langsum dt { font-size: var(--fs-xs); color: var(--text-3); }
.tr-langsum dd { margin: 0; font-weight: 500; }
.tr-steps { list-style: none; padding: 0; margin: 0 0 var(--sp-4); display: flex; flex-wrap: wrap; gap: 6px 14px; }
.tr-steps li { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-3); }
.tr-audio { width: 100%; margin-bottom: var(--sp-4); }
.tr-tabs { margin-top: var(--sp-2); }
.tr-tools { display: flex; justify-content: space-between; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-3); }
.tr-tools .search { flex: 1 1 220px; }
.tr-tools .check { margin: 0; }
.tr-body { max-height: 52vh; overflow-y: auto; padding: var(--sp-3); border: 1px solid var(--border); border-radius: var(--r); background: var(--bg-2); }
.tr-segs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.tr-segs li { display: flex; gap: 10px; align-items: baseline; line-height: 1.55; }
.tr-time { font-family: var(--f-mono, monospace); font-size: 12px; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.tr-time:hover, .tr-time:focus-visible { text-decoration: underline; }
.tr-spk { flex: 0 0 auto; font-size: var(--fs-sm); color: var(--accent-2); }
.tr-text p { margin: 0 0 var(--sp-3); line-height: 1.6; }
.tr-actions-box { margin-top: var(--sp-5); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.tr-actions-box .sel { max-width: 100%; min-width: 0; }
.tr-reprocess { margin-top: var(--sp-3); }
@media (min-width: 1100px) { .tr-reprocess .tr-langs { grid-template-columns: repeat(3, 1fr); gap: var(--sp-3); } }

/* Assessment */
.as-layout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); gap: var(--sp-5); padding: 0 var(--sp-6) var(--sp-6); align-items: start; }
.as-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--sp-3); }
.as-grid .sel, .as-setup input[type="text"] { width: 100%; }
.as-types { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--sp-3); border: 0; padding: 0; }
.as-types legend { margin-bottom: 4px; }
.as-types .check { margin: 4px 0; }
.as-rules { margin-top: var(--sp-4); font-size: var(--fs-sm); color: var(--text-2); }
.as-rules summary { cursor: pointer; color: var(--accent); }
.as-hist { display: flex; align-items: center; gap: 6px; padding: 0; }
.as-open { flex: 1; text-align: start; background: none; border: 0; color: inherit; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; cursor: pointer; min-width: 0; }
.as-session { display: flex; flex-direction: column; gap: var(--sp-4); padding: 0 var(--sp-6) var(--sp-6); max-width: 980px; }
.as-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--sp-3); }
.as-head h2 { margin: 2px 0 0; font-size: 1.2rem; overflow-wrap: anywhere; }
.as-head-l { min-width: 0; flex: 1 1 240px; }
.as-stats { display: flex; flex-wrap: wrap; gap: var(--sp-3) var(--sp-5); }
.as-stat { display: flex; flex-direction: column; gap: 4px; min-width: 110px; }
.as-stat-l { font-size: var(--fs-xs); color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.as-stat-v { font-weight: 600; font-variant-numeric: tabular-nums; }
.as-stat-v.is-bump { animation: bump .6s ease; }
@keyframes bump { 40% { transform: scale(1.15); color: var(--ok); } }
.as-pips { display: flex; gap: 4px; list-style: none; margin: 0; padding: 0; }
.as-pips li { width: 18px; height: 6px; border-radius: 3px; background: var(--border-strong); }
.as-pips li.is-past { background: var(--accent-line); }
.as-pips li.is-current { background: var(--accent); }
.as-pips li.is-out { opacity: .35; }
.as-bar { display: block; width: 140px; height: 6px; border-radius: 3px; background: var(--border-strong); overflow: hidden; }
.as-bar i { display: block; height: 100%; background: var(--accent); }
.as-timer.is-low { color: var(--err); }
.as-q-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--sp-3); }
.as-prompt { font-size: 1.05rem; line-height: 1.55; margin: 0 0 var(--sp-4); font-weight: 600; }
.as-options { border: 0; padding: 0; margin: 0 0 var(--sp-3); display: flex; flex-direction: column; gap: 8px; }
.as-opt { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--border-strong); border-radius: var(--r); cursor: pointer; background: var(--surface-2); flex-wrap: wrap; }
.as-opt:hover { border-color: var(--accent-line); }
.as-opt:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.as-opt.is-sel { border-color: var(--accent); background: var(--accent-soft); }
.as-opt.is-correct { border-color: var(--ok); background: var(--ok-soft); }
.as-opt.is-wrong { border-color: var(--err); background: var(--err-soft); }
.as-options[disabled] .as-opt { cursor: default; }
.as-opt input { accent-color: var(--accent); width: 18px; height: 18px; flex: 0 0 auto; }
.as-opt > span[dir] { flex: 1 1 200px; }
.as-mark { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: 600; }
.as-mark-ok { color: var(--ok); } .as-mark-err { color: var(--err); }
.as-text { width: 100%; min-height: 120px; resize: vertical; margin-bottom: var(--sp-3); }
.as-hint { display: flex; gap: 6px; align-items: flex-start; padding: 10px 12px; border-radius: var(--r); background: var(--accent-2-soft); font-size: var(--fs-sm); }
.as-hint .ic { margin-top: 3px; flex: 0 0 auto; }
.as-actions { justify-content: flex-end; }
.as-feedback { border-inline-start: 4px solid var(--accent); }
.as-fb-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.as-outcome { font-size: var(--fs-sm); }
.as-pts { font-weight: 600; font-variant-numeric: tabular-nums; }
.as-fb-msg { font-weight: 500; }
.as-feedback p { margin: 6px 0; line-height: 1.55; }
.as-src { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: var(--fs-sm); }
.cite-link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; display: inline-flex; gap: 4px; align-items: center; }
.as-level-change { display: inline-flex; gap: 6px; align-items: center; font-weight: 600; padding: 6px 10px; border-radius: var(--r-pill); }
.as-level-change.is-up { background: var(--ok-soft); color: var(--ok); }
.as-level-change.is-down { background: var(--warn-soft); color: var(--warn); }
.as-next { justify-content: flex-end; }
.as-session-foot { justify-content: space-between; }
.as-response { margin: 0 0 var(--sp-3); padding: 10px 14px; border-inline-start: 3px solid var(--border-strong); background: var(--surface-2); border-radius: var(--r-sm); white-space: pre-wrap; }
.as-score { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-4); }
.as-big { display: flex; flex-direction: column; gap: 4px; padding: var(--sp-3); border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--border); }
.as-big-v { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.as-big-l { font-size: var(--fs-xs); color: var(--text-3); }
.as-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--sp-4); }
.as-review { display: flex; flex-direction: column; gap: var(--sp-4); }

@media (max-width: 1100px) {
  .tr-layout, .as-layout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .tr-layout, .as-layout, .as-session { padding: 0 var(--sp-4) calc(var(--nav-h, 64px) + var(--sp-4)); }
  .queue-banner { margin: var(--sp-2) var(--sp-4) 0; }
  .card { padding: var(--sp-4); }
  .as-grid, .as-types { grid-template-columns: minmax(0, 1fr); }
  .tr-body { max-height: none; }
  .as-bar { width: 100px; }
}
@media (prefers-reduced-motion: reduce) { .as-stat-v.is-bump { animation: none; } }
:root.reduce-motion .as-stat-v.is-bump { animation: none; }

/* ================= Learning workspace (v1.2): navigation groups, dashboard, library, picker, assignments, builder ================= */
.nav-group { margin: 0 0 6px; padding: 0 12px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.nav-admin[hidden] { display: none; }
.nav-admin { padding-top: var(--sp-3); border-top: 1px solid var(--border); }
.nav-tail { margin-top: auto; }
.rail-foot { margin-top: 0; }
#view-settings.is-admin .page-head h1::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--accent-2); margin-inline-end: 10px; vertical-align: middle; }

/* Shared building blocks */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--sp-4); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.card-title { font-size: var(--fs-md); margin: 0; line-height: 1.3; }
.card-desc { color: var(--text-2); font-size: var(--fs-sm); margin: 0 0 var(--sp-3); }
.card-meta { color: var(--text-2); font-size: var(--fs-sm); margin: 0 0 var(--sp-3); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.card-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; margin: 0 0 var(--sp-4); font-size: var(--fs-sm); }
.card-facts dt { color: var(--text-3); font-size: var(--fs-xs); }
.card-facts dd { margin: 2px 0 0; font-weight: 500; }
.card-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: auto; }
.card { display: flex; flex-direction: column; }
.card.is-current, .kb-card.is-current { border-color: var(--accent-line); box-shadow: 0 0 0 1px var(--accent-line) inset; }
.eyebrow { font-size: var(--fs-xs); color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; margin: 0 0 4px; }
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-3); padding: var(--sp-8) var(--sp-4); border: 1px dashed var(--border-strong); border-radius: var(--r-lg); color: var(--text-2); }
.empty-state h2 { margin: 0; font-size: var(--fs-lg); color: var(--text); }
.empty-state .ic-lg { color: var(--text-3); width: 32px; height: 32px; }
.status-pill { display: inline-flex; align-items: center; font-size: 11.5px; font-weight: 600; padding: 4px 10px; border-radius: var(--r-pill); background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.status-pill.st-progress { background: var(--accent-2-soft); color: var(--accent-2); }
.status-pill.st-ok { background: var(--ok-soft); color: var(--ok); }
.status-pill.st-info { background: var(--accent-soft); color: var(--accent); }
.status-pill.st-err { background: var(--err-soft); color: var(--err); }
.status-pill.st-muted { background: var(--surface-2); color: var(--text-3); }
.level-badge { display: inline-flex; padding: 3px 9px; border-radius: var(--r-pill); background: var(--accent-2-soft); color: var(--accent-2); font-size: 11.5px; font-weight: 600; }
.score-pill { font-size: var(--fs-xs); font-weight: 600; padding: 3px 9px; border-radius: var(--r-pill); white-space: nowrap; }
.score-pill.is-pass { background: var(--ok-soft); color: var(--ok); } .score-pill.is-fail { background: var(--surface-3); color: var(--text-2); }
.link-btn { display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none; color: var(--accent-2); font: inherit; cursor: pointer; text-align: start; }
.link-btn:hover { text-decoration: underline; }
.btn-lg { min-height: 48px; padding: 0 22px; font-size: var(--fs-md); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--sp-4); }
.muted { color: var(--text-3); }
.field-error { color: var(--err); font-size: var(--fs-xs); margin: 4px 0 0; }
.req { color: var(--err); }
.plain-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.plain-list li { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); padding: 10px 0; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); }
.plain-list li:last-child { border-bottom: 0; }
.plain-list a, .plain-list .link-btn { display: inline-flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; min-width: 0; }
.plain-list a span, .plain-list .link-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plain-list a:hover span, .plain-list .link-btn:hover span { text-decoration: underline; }
.skeleton-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--sp-4); }
.skeleton { height: 150px; border-radius: var(--r-lg); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: skel 1.4s ease infinite; }
@keyframes skel { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.lib-toolbar .sel { min-width: 160px; }

/* Dashboard */
.stat-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-5); }
.stat-card { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); }
.stat-card > .ic { width: 28px; height: 28px; padding: 6px; box-sizing: content-box; border-radius: var(--r); background: var(--accent-soft); color: var(--accent); flex: none; }
.stat-card b { display: block; font-size: var(--fs-lg); line-height: 1.1; }
.stat-card span { color: var(--text-2); font-size: var(--fs-xs); }
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: var(--sp-4); align-items: start; }
.dash-main, .dash-side { display: flex; flex-direction: column; gap: var(--sp-4); }
.card-hero { background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%); border-color: var(--accent-line); }
.card-hero .card-title { font-size: var(--fs-lg); margin-bottom: 6px; }
.dash-list .card-title { font-size: var(--fs); margin-bottom: var(--sp-2); }

/* Knowledge library + picker */
.lib-active { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; padding: 10px 14px; margin-bottom: var(--sp-4); border-radius: var(--r); background: var(--accent-soft); font-size: var(--fs-sm); }
.lib-active > span { flex: 1 1 auto; }
.kb-pick-btn { display: inline-flex; align-items: center; gap: 8px; max-width: 320px; min-height: 36px; padding: 0 12px; border-radius: var(--r-pill); border: 1px solid var(--accent-line); background: var(--accent-soft); color: var(--text); font: inherit; font-size: var(--fs-sm); cursor: pointer; }
.kb-pick-btn[hidden] { display: none; }
.kb-pick-btn:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.kb-pick-btn:disabled { opacity: .55; cursor: not-allowed; }
.kb-pick-btn .ic { color: var(--accent); flex: none; }
.kb-pick-btn .ic-xs { transform: rotate(90deg); color: var(--text-3); }
.kb-pick-lbl { color: var(--text-3); font-size: var(--fs-xs); }
.kb-pick-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-pick-dlg { width: min(560px, calc(100vw - 32px)); }
.kb-pick-search { margin: var(--sp-3) 0; }
.kb-pick-list { display: flex; flex-direction: column; gap: 6px; max-height: min(55vh, 460px); overflow: auto; padding: 2px; }
.kb-opt { display: flex; align-items: center; gap: var(--sp-3); width: 100%; padding: 12px 14px; border-radius: var(--r); border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; text-align: start; cursor: pointer; }
.kb-opt:hover, .kb-opt:focus-visible { border-color: var(--accent-line); background: var(--surface-2); }
.kb-opt.is-current { border-color: var(--accent); background: var(--accent-soft); }
.kb-opt-main { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.kb-opt-desc { color: var(--text-2); font-size: var(--fs-sm); }
.kb-opt-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--text-3); font-size: var(--fs-xs); }
.kb-opt-cur { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; }
.kb-opt-empty { padding: var(--sp-4); text-align: center; }

/* Assignments: library, intro, player, results */
.practice-link { display: flex; align-items: center; gap: var(--sp-3); margin-top: var(--sp-5); padding: 14px 16px; border-radius: var(--r-lg); border: 1px solid var(--border); background: var(--surface); color: var(--text-2); text-decoration: none; font-size: var(--fs-sm); }
.practice-link:hover { border-color: var(--accent-line); }
.practice-link b { color: var(--text); }
.practice-link > span { flex: 1; }
.lock-note { display: flex; gap: 6px; align-items: flex-start; color: var(--text-2); font-size: var(--fs-sm); margin: 0 0 var(--sp-3); }
.player-wrap { max-width: 860px; margin: 0 auto; }
.intro-card { gap: var(--sp-2); }
.intro-title { font-size: var(--fs-xl); margin: 0 0 var(--sp-2); }
.instructions { padding: 12px 14px; border-radius: var(--r); background: var(--surface-2); margin: var(--sp-2) 0; }
.instructions h3 { margin: 0 0 4px; font-size: var(--fs-sm); }
.instructions p { margin: 0; white-space: pre-wrap; }
.rule-list { list-style: none; margin: 0 0 var(--sp-4); padding: 0; display: grid; gap: 8px; }
.rule-list li { display: flex; gap: 10px; align-items: flex-start; font-size: var(--fs-sm); color: var(--text-2); }
.rule-list .ic { color: var(--accent); margin-top: 2px; flex: none; }
.player-head { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-3); }
.player-title { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.player-title h2 { margin: 0; font-size: var(--fs-lg); }
.player-stats { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.stat-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--r-pill); background: var(--surface-2); border: 1px solid var(--border); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.stat-chip .ic { color: var(--accent); }
.stat-chip.timer.is-low { background: var(--warn-soft); border-color: var(--warn); }
.stat-chip.timer.is-low .ic { color: var(--warn); }
.progress { height: 6px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; margin-bottom: var(--sp-3); }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width var(--t); }
.q-dots { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 var(--sp-4); padding: 0; }
.q-dot { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font: inherit; font-size: var(--fs-xs); font-weight: 600; cursor: pointer; }
.q-dot:disabled { cursor: default; }
.q-dot.is-current { border-color: var(--accent); color: var(--text); box-shadow: 0 0 0 2px var(--accent-soft); }
.q-dot.is-ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.q-dot.is-partial { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.q-dot.is-bad { background: var(--err-soft); border-color: var(--err); color: var(--err); }
.q-dot.is-done { background: var(--surface-3); }
.question-card { gap: var(--sp-3); }
.q-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; }
.q-num { font-weight: 600; font-size: var(--fs-sm); margin-inline-end: 4px; }
.q-prompt { font-size: var(--fs-md); line-height: 1.45; margin: var(--sp-2) 0; }
.q-prompt-sm { margin: 6px 0; font-weight: 500; }
.scenario { padding: 12px 14px; border-inline-start: 3px solid var(--accent-2); background: var(--accent-2-soft); border-radius: var(--r-sm); }
.scenario p:last-child { margin: 0; white-space: pre-wrap; }
.choices { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.choice { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); cursor: pointer; }
.choice:hover { border-color: var(--border-strong); }
.choice.is-on { border-color: var(--accent); background: var(--accent-soft); }
.choice.is-correct { border-color: var(--ok); background: var(--ok-soft); }
.choice.is-wrong { border-color: var(--err); background: var(--err-soft); }
.choice > span { flex: 1; }
.choice input { width: 18px; height: 18px; accent-color: var(--accent); }
.choices:disabled .choice { cursor: default; }
.char-count { margin: 4px 0 0; font-size: var(--fs-xs); color: var(--text-3); text-align: end; }
.hint-box { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: var(--r); background: var(--warn-soft); font-size: var(--fs-sm); margin: 0; }
.hint-box .ic { color: var(--warn); margin-top: 2px; }
.result-box { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r); font-size: var(--fs-sm); }
.result-box p { margin: 4px 0 0; }
.result-box.is-ok { background: var(--ok-soft); } .result-box.is-ok > .ic { color: var(--ok); }
.result-box.is-partial { background: var(--warn-soft); } .result-box.is-partial > .ic { color: var(--warn); }
.result-box.is-bad { background: var(--err-soft); } .result-box.is-bad > .ic { color: var(--err); }
.result-box.is-neutral { background: var(--surface-2); } .result-box.is-neutral > .ic { color: var(--accent-2); }
.solution { padding: 12px 14px; border-radius: var(--r); border: 1px solid var(--border); font-size: var(--fs-sm); }
.solution p { margin: 0 0 6px; } .solution p:last-child { margin: 0; }
.q-actions { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); flex-wrap: wrap; padding-top: var(--sp-3); border-top: 1px solid var(--border); }
.results-card { align-items: flex-start; gap: var(--sp-2); }
.score-big { display: flex; align-items: baseline; gap: var(--sp-3); margin: var(--sp-2) 0; }
.score-big b { font-size: 44px; line-height: 1; }
.score-big.is-pass b { color: var(--ok); } .score-big.is-fail b { color: var(--text); }
.score-big span { color: var(--text-2); }
.result-line { display: flex; gap: 8px; align-items: center; color: var(--text-2); margin: 0 0 var(--sp-3); }
.review-list { list-style: none; margin: var(--sp-4) 0 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: var(--sp-3); }
.review-item { padding: var(--sp-4); border: 1px solid var(--border); border-radius: var(--r-lg); display: flex; flex-direction: column; gap: 8px; }
.review-item p { margin: 0; }

/* Assignment builder (administration) */
.aa-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-3); flex-wrap: wrap; }
.aa-head .set-intro { flex: 1 1 320px; margin: 0; }
.aa-table th[scope="row"] { font-weight: 600; }
.aa-results { margin-top: var(--sp-5); }
.aa-ed-head { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-3); }
.aa-ed-title { margin: 0; font-size: var(--fs-lg); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stepper { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 var(--sp-5); padding: 0; }
.step { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: var(--r-pill); border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font: inherit; font-size: var(--fs-sm); cursor: pointer; }
.step.is-current { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }
.step.is-done { color: var(--text); }
.step-n { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--surface-3); font-size: var(--fs-xs); font-weight: 600; }
.step.is-current .step-n { background: var(--accent); color: var(--accent-ink); }
.step.is-done .step-n { background: var(--ok-soft); color: var(--ok); }
.aa-step { min-height: 200px; }
.aa-foot { display: flex; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; margin-top: var(--sp-5); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.aq-list { list-style: none; margin: 0 0 var(--sp-3); padding: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.aq { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
.aq.is-open { border-color: var(--border-strong); }
.aq-head { display: flex; align-items: center; gap: var(--sp-2); padding: 6px 8px 6px 4px; }
.aq-toggle { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 8px 10px; border: 0; background: none; color: var(--text); font: inherit; text-align: start; cursor: pointer; }
.aq-toggle .q-num { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--surface-3); flex: none; margin: 0; }
.aq-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aq-tools .icon-btn { min-width: 32px; min-height: 32px; }
.aq-body { padding: var(--sp-4); border-top: 1px solid var(--border); }
.aq-options { border: 0; padding: 0; margin: 0 0 var(--sp-4); }
.aq-opt { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.aq-opt .aq-opt-text { flex: 1; min-height: 38px; }
.aq-correct { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: var(--r); border: 1px solid var(--border); cursor: pointer; }
.aq-correct input { width: 18px; height: 18px; accent-color: var(--ok); }
.aq-add { align-items: center; }
.rot-up { transform: rotate(-90deg); } .rot-down { transform: rotate(90deg); }
.publish-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: var(--sp-5); align-items: start; }
.problem-list { list-style: none; margin: 0 0 var(--sp-3); padding: 0; display: flex; flex-direction: column; gap: 6px; }
.problem-list li { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: var(--r-sm); font-size: var(--fs-sm); }
.problem-list .is-err { background: var(--err-soft); } .problem-list .is-err .ic { color: var(--err); }
.problem-list .is-warn { background: var(--warn-soft); } .problem-list .is-warn .ic { color: var(--warn); }
.ok-line { display: flex; gap: 8px; align-items: center; color: var(--ok); font-weight: 600; }
.preview { pointer-events: none; }
.question-card.preview { padding: var(--sp-3); border: 1px dashed var(--border-strong); border-radius: var(--r); display: flex; flex-direction: column; gap: 8px; margin-bottom: var(--sp-3); }

@media (max-width: 1100px) {
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid, .publish-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  /* Bottom bar: every destination stays reachable by scrolling it sideways. */
  .rail { overflow-x: auto; scrollbar-width: none; }
  .rail::-webkit-scrollbar { display: none; }
  .rail .nav, .nav-admin, .nav-admin .nav, .nav-tail { flex: 0 0 auto; display: flex; flex-direction: row; margin: 0; padding: 0; border: 0; }
  .nav-admin[hidden] { display: none; }
  .nav-group { display: none; }
  .rail .nav li { flex: 0 0 auto; }
  .rail .nav a { min-width: 76px; padding-inline: 6px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .kb-pick-btn { max-width: 100%; }
  .kb-pick-lbl { display: none; }
  .q-actions, .q-actions > .row-gap { width: 100%; }
  .q-actions > .row-gap:last-child { justify-content: flex-end; }
  .score-big b { font-size: 36px; }
}
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } .progress > span { transition: none; } }

/* ================= AI assignment drafting (builder) ================= */
.btn-ai { border-color: var(--accent-2); color: var(--accent-2); background: var(--accent-2-soft); }
.btn-ai:hover:not(:disabled) { background: color-mix(in srgb, var(--accent-2) 24%, transparent); }
.step-ai .step-n { background: var(--accent-2-soft); color: var(--accent-2); }
.step-ai.is-current { border-color: var(--accent-2); background: var(--accent-2-soft); }
.ai-panel { display: flex; flex-direction: column; gap: var(--sp-2); }
.ai-intro { display: flex; gap: var(--sp-3); align-items: flex-start; padding: 14px 16px; border-radius: var(--r-lg); background: linear-gradient(135deg, var(--accent-2-soft), var(--accent-soft)); margin-bottom: var(--sp-3); }
.ai-intro > .ic { color: var(--accent-2); width: 22px; height: 22px; flex: none; margin-top: 2px; }
.ai-intro p { margin: 4px 0 0; color: var(--text-2); font-size: var(--fs-sm); }
.ai-types { border: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.ai-types legend { margin-bottom: 8px; }
.chip-check { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--r-pill); font-size: var(--fs-sm); cursor: pointer; background: var(--surface); }
.chip-check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.chip-check input { accent-color: var(--accent); }
.ai-result { margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.ai-list { list-style: none; margin: var(--sp-3) 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.ai-card { border: 1px solid var(--border-strong); border-radius: var(--r-lg); padding: var(--sp-4); background: var(--surface); display: flex; flex-direction: column; gap: 8px; }
.ai-card.is-dropped { opacity: .55; border-style: dashed; }
.ai-card .q-prompt { margin: 0; }
.ai-card p { margin: 0; }
.ai-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ai-keep { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); font-weight: 600; margin-inline-end: 6px; cursor: pointer; }
.ai-keep input { width: 18px; height: 18px; accent-color: var(--accent); }
.ai-opts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-sm); }
.ai-opts li { display: flex; gap: 8px; align-items: center; padding: 6px 10px; border-radius: var(--r-sm); background: var(--surface-2); }
.ai-opts li.is-correct { background: var(--ok-soft); color: var(--text); }
.ai-opts li.is-correct .ic { color: var(--ok); }
.dot-sp { display: inline-block; width: 12px; }
.ai-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; padding: 8px 10px; border-radius: var(--r); background: var(--accent-2-soft); }
.ai-tools > .ic { color: var(--accent-2); }
.ai-tools-lbl { font-size: var(--fs-xs); font-weight: 600; color: var(--accent-2); margin-inline-end: 4px; }
.ai-custom { flex: 1 1 200px; min-height: 32px; font-size: var(--fs-sm); }
.ai-tools .field-error { flex-basis: 100%; }
.ai-chat { display: flex; flex-direction: column; gap: 8px; padding: var(--sp-3); border-radius: var(--r-lg); background: var(--surface-2); }
.ai-history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ai-msg { max-width: 85%; padding: 8px 12px; border-radius: var(--r-lg); font-size: var(--fs-sm); }
.ai-msg.ai-you { align-self: flex-end; background: var(--user-bubble); }
.ai-msg.ai-ai { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); }
.ai-change-row { display: flex; gap: 8px; align-items: flex-end; }
.ai-change-row textarea { flex: 1; }
.ai-foot { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; margin-top: var(--sp-3); }

/* ================= Learner knowledge pages ================= */
.card-link { color: inherit; text-decoration: none; }
.card-link:hover { text-decoration: underline; }
.kb-page { display: flex; flex-direction: column; gap: var(--sp-4); max-width: 1000px; }
.kb-hero { flex-direction: row; justify-content: space-between; align-items: flex-end; gap: var(--sp-4); flex-wrap: wrap; background: linear-gradient(135deg, var(--surface), var(--surface-2)); }
.kb-hero > div:first-child { flex: 1 1 360px; }
.kb-hero .card-actions { margin-top: 0; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--sp-3); }
.doc-card { flex-direction: row; flex-wrap: wrap; align-items: center; gap: var(--sp-3); }
.doc-card .card-actions { flex-basis: 100%; }
.doc-ic { display: grid; place-items: center; width: 44px; height: 44px; border-radius: var(--r); background: var(--accent-soft); color: var(--accent); flex: none; }
.doc-main { flex: 1; min-width: 0; }
.doc-title { margin: 0 0 2px; font-size: var(--fs); line-height: 1.35; overflow-wrap: anywhere; }
.doc-main .muted { margin: 0; font-size: var(--fs-xs); }
.reader-head { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.reader-head > div:nth-child(2) { flex: 1 1 260px; }
.reader-head .intro-title { margin: 0; }
.reader-video { width: 100%; max-height: 420px; border-radius: var(--r-lg); background: #000; }
.reader-body { display: flex; flex-direction: column; gap: var(--sp-4); padding: var(--sp-5); border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--border); line-height: 1.7; font-size: var(--fs-md); }
.passage { scroll-margin-top: 80px; }
.passage h3 { font-size: var(--fs-md); margin: 0 0 4px; }
.passage p:last-child { margin: 0; white-space: pre-wrap; }
.passage.is-focus { padding: var(--sp-3); margin: calc(var(--sp-3) * -1); border-radius: var(--r); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent-line) inset; }
.passage-loc { display: inline-flex; align-items: center; gap: 4px; margin: 0 0 4px; padding: 0; border: 0; background: none; font: inherit; font-size: var(--fs-xs); color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
button.passage-loc { color: var(--accent-2); cursor: pointer; }
mark { background: var(--warn-soft); color: var(--text); border-radius: 3px; padding: 0 2px; }
@media (max-width: 900px) {
  .ai-change-row { flex-direction: column; align-items: stretch; }
  .reader-body { padding: var(--sp-4); font-size: var(--fs); }
}

/* ================= LMS (v1.4): two workspaces, AI Tutor sidebar, learning journey ================= */
/* Rail: learner and admin modes */
.nav-mode { display: flex; flex-direction: column; gap: 2px; }
.nav-mode[hidden] { display: none; }
.nav-mode .nav-group { margin: var(--sp-4) 0 6px; }
.nav-back { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: var(--sp-2); border-radius: var(--r); color: var(--accent-2); text-decoration: none; font-weight: 600; font-size: var(--fs-sm); }
.nav-back:hover { background: var(--surface); }
.admin-entry { border: 1px solid var(--border-strong); }
.admin-entry .ic { color: var(--accent-2) !important; }
body.admin-mode .rail { background: color-mix(in srgb, var(--bg-2) 82%, var(--accent-2) 18%); }
body.admin-mode .nav a[aria-current="page"]::before { background: var(--accent-2); }
body.admin-mode .nav a[aria-current="page"] .ic { color: var(--accent-2); }
#view-settings.is-admin .set-nav { display: none; }
#view-settings.is-admin .set-layout { grid-template-columns: minmax(0, 1fr); }
#view-settings.is-admin .set-panel { max-width: 1100px; }
.stat-link { color: inherit; text-decoration: none; }
.stat-link:hover { border-color: var(--accent-line); }
.quick-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-3); }

/* AI Tutor: conversation sidebar */
.workspace { grid-template-columns: 250px minmax(280px, 330px) minmax(0, 1fr); }
.workspace.text-only { grid-template-columns: 250px minmax(0, 1fr); }
.conv-side { display: flex; flex-direction: column; min-height: 0; border-inline-end: 1px solid var(--border); background: var(--bg-2); }
.conv-side-head { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-3); border-bottom: 1px solid var(--border); }
.conv-side-head .search { flex: 0 0 auto; } /* the generic .search grows along the row; here it sits in a column */
.conv-side-head .search input { min-height: 36px; font-size: var(--fs-sm); }
.conv-list { flex: 1; min-height: 0; overflow-y: auto; padding: var(--sp-2); display: flex; flex-direction: column; gap: 2px; }
.conv-group { margin: var(--sp-3) 8px 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); }
.conv-item { position: relative; display: flex; align-items: center; border-radius: var(--r); }
.conv-item:hover, .conv-item:focus-within { background: var(--surface); }
.conv-item.is-current { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
[dir="rtl"] .conv-item.is-current { box-shadow: inset -3px 0 0 var(--accent); }
.conv-open { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border: 0; background: none; color: var(--text); font: inherit; text-align: start; cursor: pointer; }
.conv-title { font-size: var(--fs-sm); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-meta { font-size: 11.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-more { min-width: 30px; min-height: 30px; opacity: 0; }
.conv-item:hover .conv-more, .conv-item:focus-within .conv-more, .conv-more[aria-expanded="true"] { opacity: 1; }
.conv-menu { position: absolute; inset-inline-end: 6px; top: 100%; z-index: 5; display: flex; flex-direction: column; min-width: 150px; padding: 4px; border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--border-strong); box-shadow: var(--sh-2); }
.conv-menu button { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 0; border-radius: var(--r-sm); background: none; color: var(--text); font: inherit; font-size: var(--fs-sm); text-align: start; cursor: pointer; }
.conv-menu button:hover, .conv-menu button:focus-visible { background: var(--surface-3); }
.conv-menu .is-danger { color: var(--err); }
.conv-rename { width: 100%; margin: 4px; min-height: 34px; font-size: var(--fs-sm); }
.conv-empty { padding: var(--sp-3); font-size: var(--fs-sm); }
.conv-toggle { display: none; }
.conv-scrim { position: fixed; inset: 0; z-index: 55; background: rgba(0, 0, 0, .45); }
.conv-scrim[hidden] { display: none; }

/* Composer: knowledge + context row */
.ctx-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ctx-row .scope-chip { margin: 0 !important; }
.scope-chip.is-lesson { border-color: var(--accent-2); background: var(--accent-2-soft); }
.scope-chip.is-lesson .ic { color: var(--accent-2); }

/* My learning */
.continue-card { flex-direction: row; justify-content: space-between; align-items: center; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-6); padding: var(--sp-6);
  background: linear-gradient(135deg, var(--surface) 0%, color-mix(in srgb, var(--surface-2) 70%, var(--accent) 30%) 100%); border-color: var(--accent-line); }
.continue-card > div { flex: 1 1 320px; display: flex; flex-direction: column; gap: 6px; }
.continue-card .card-title { font-size: var(--fs-xl); }
.continue-card .card-meta { margin: 0; }
.mini-progress { height: 6px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; max-width: 420px; }
.mini-progress > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.home-section { margin-bottom: var(--sp-6); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.section-head h2 { margin: 0; font-size: var(--fs-lg); }
.section-head .card-title { margin: 0; }
.section-title { font-size: var(--fs-lg); margin: var(--sp-6) 0 var(--sp-3); }
.home-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: var(--sp-4); }
.home-sub { margin-top: var(--sp-4); }
.module-card { gap: 6px; }
.module-cover { display: grid; place-items: center; height: 84px; margin: calc(var(--sp-5) * -1) calc(var(--sp-5) * -1) var(--sp-3); border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: linear-gradient(135deg, var(--accent-soft), var(--accent-2-soft)); color: var(--accent); }
.module-cover .ic { width: 30px; height: 30px; }
.module-card .mini-progress { margin: 4px 0 var(--sp-3); }

/* Module page */
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: var(--sp-4); font-size: var(--fs-sm); color: var(--text-3); }
.crumbs a { color: var(--accent-2); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.module-hero { flex-direction: row; justify-content: space-between; align-items: flex-end; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-4); }
.module-hero-main { flex: 1 1 380px; display: flex; flex-direction: column; gap: 6px; }
.module-hero .card-actions { margin: 0; }
.objectives { margin-bottom: var(--sp-2); }
.lesson-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.lesson-row { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
.lesson-row:hover { border-color: var(--border-strong); }
.lesson-num { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--surface-3); font-weight: 700; font-size: var(--fs-sm); }
.lesson-row.is-done .lesson-num { background: var(--ok-soft); color: var(--ok); }
.lesson-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lesson-main p { margin: 0; }
.lesson-title { color: var(--text); font-weight: 600; text-decoration: none; }
.lesson-title:hover { text-decoration: underline; }
.lesson-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px !important; }
.asg-mini { gap: 4px; }

/* Lesson workspace */
.lesson-head { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-4); }
.lesson-head > div:first-child { flex: 1 1 360px; }
.lesson-head .intro-title { margin: 0 0 4px; }
.lesson-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.btn-ok { border-color: var(--ok); color: var(--ok); background: var(--ok-soft); }
.lesson-notes { margin-bottom: var(--sp-4); }
.notes-body { line-height: 1.7; }
.mat-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--sp-3); }
.mat-tab { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--r-pill); background: var(--surface); color: var(--text-2); font: inherit; font-size: var(--fs-sm); cursor: pointer; max-width: 320px; }
.mat-tab span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mat-tab[aria-selected="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.lesson-material { display: flex; flex-direction: column; gap: var(--sp-3); }
.mat-head { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.mat-head > div:nth-child(2) { flex: 1 1 220px; }
.mat-head .doc-title { margin: 0; }
.lesson-nav { display: flex; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; margin-top: var(--sp-6); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.lesson-nav .btn span { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Progress */
.prog-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.prog-list li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(120px, 260px) auto; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
.prog-list a { color: var(--text); font-weight: 600; text-decoration: none; }
.progress-links { margin-top: var(--sp-6); }

/* Admin: modules & lessons */
.am-lessons { list-style: none; margin: 0 0 var(--sp-3); padding: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.am-lesson { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; padding: var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
.am-lesson .lesson-main { flex: 1 1 260px; }
.lesson-editor { margin: var(--sp-3) 0; }
.mat-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.mat-order { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; }
.chip-check.is-warn { border-style: dashed; color: var(--text-3); }
.am-asg-hint { margin-top: var(--sp-5); }

@media (max-width: 1280px) {
  .workspace { grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); }
  .workspace.text-only { grid-template-columns: minmax(0, 1fr); }
  .conv-toggle { display: inline-flex; }
  /* The sidebar becomes a drawer: out of the layout until opened. */
  .conv-side { position: fixed; z-index: 60; top: 0; bottom: 0; inset-inline-start: 0; width: min(320px, 86vw); transform: translateX(-105%); transition: transform var(--t); box-shadow: var(--sh-3); }
  [dir="rtl"] .conv-side { transform: translateX(105%); }
  body.conv-open .conv-side { transform: none; }
}
@media (min-width: 1281px) { .conv-scrim { display: none !important; } }
@media (max-width: 900px) {
  .workspace, .workspace.text-only { grid-template-columns: minmax(0, 1fr); }
  .conv-side { bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px)); }
  .continue-card { padding: var(--sp-4); }
  .continue-card .btn-lg { width: 100%; }
  .lesson-row { flex-wrap: wrap; }
  .lesson-row > .btn { margin-inline-start: 46px; }
  .prog-list li { grid-template-columns: minmax(0, 1fr); }
  .nav-back { min-width: 76px; flex-direction: column; gap: 3px; padding: 9px 4px; font-size: 11.5px; height: var(--nav-h); justify-content: center; margin: 0; border-radius: 0; flex: 0 0 auto; }
  .rail .nav-mode { flex-direction: row; flex: 0 0 auto; }
  .rail .nav-mode .nav { flex-direction: row; }
}
@media (prefers-reduced-motion: reduce) { .conv-side { transition: none; } }

/* =====================================================================================================
   Learner site (body.ws-learner): real pages — /learn (video library), /learn/lessons/{id} (player),
   /learn/lessons/{id}/assistant (the lesson's AI Assistant). No navigation bar: a slim header (logo, contextual back
   link, progress, account menu) at every width. Only ChatbotMeppo's existing tokens: slate surfaces, the gray surface
   gradient (--surface → --surface-2) and the teal accent. The administration page keeps its sidebar layout.
   ===================================================================================================== */
:root { --hdr-h: 60px; --surface-gradient: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%); }

/* ---- Header ---- */
body.ws-learner .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
body.ws-learner .rail { position: sticky; top: 0; bottom: auto; inset-inline: auto; z-index: 30; height: var(--hdr-h); display: flex; flex-direction: row; align-items: center;
  gap: var(--sp-4); padding: 0 clamp(16px, 3vw, 32px); border: 0; border-bottom: 1px solid var(--border); background: var(--bg-2); overflow: visible; backdrop-filter: none; }
body.ws-learner .brand { display: flex; padding: 0; flex: none; }
body.ws-learner .brand-mark { width: 28px; height: 28px; }
body.ws-learner .main { padding-bottom: 0; }
body.ws-learner .view-assistant { height: calc(100dvh - var(--hdr-h)); }
body.ws-learner .conv-side { top: var(--hdr-h); bottom: 0; }
.hdr-spacer { flex: 1; }
.hdr-back { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: var(--r); color: var(--text-2); text-decoration: none; font-weight: 500; font-size: var(--fs-sm); border-inline-start: 1px solid var(--border); margin-inline-start: var(--sp-2); }
.hdr-back:hover { color: var(--text); background: var(--surface); }
.hdr-progress { display: flex; align-items: center; gap: 10px; font-size: var(--fs-sm); color: var(--text-2); white-space: nowrap; }
.hdr-bar { width: 120px; height: 5px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.hdr-bar i { display: block; height: 100%; background: var(--accent); }

/* ---- Account menu ---- */
.hdr-menu { position: relative; flex: none; }
.hdr-menu > summary { list-style: none; display: flex; align-items: center; gap: 8px; padding: 5px 10px 5px 5px; border-radius: var(--r-pill); border: 1px solid var(--border); cursor: pointer; color: var(--text-2); }
[dir="rtl"] .hdr-menu > summary { padding: 5px 5px 5px 10px; }
.hdr-menu > summary::-webkit-details-marker { display: none; }
.hdr-menu > summary:hover, .hdr-menu[open] > summary { background: var(--surface); color: var(--text); }
.hdr-caret { transform: rotate(90deg); opacity: .7; }
.hdr-avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 12px; flex: none; }
.hdr-user .user-chip { max-width: 200px; font-size: var(--fs-sm); }
.hdr-pop { position: absolute; inset-inline-end: 0; top: calc(100% + 8px); z-index: 50; min-width: 250px; padding: 8px; border-radius: var(--r-lg);
  background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--sh-2); display: flex; flex-direction: column; gap: 4px; }
.hdr-pop .nav { display: flex; flex-direction: column; gap: 2px; margin: 0; }
.hdr-pop .nav a, .hdr-pop .nav-btn { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--r); width: 100%; height: auto; font-size: 14px; color: var(--text-2); text-decoration: none; flex-direction: row; justify-content: flex-start; }
.hdr-pop .nav a:hover, .hdr-pop .nav-btn:hover { background: var(--surface-2); color: var(--text); }
.hdr-pop .nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); }
.hdr-pop .nav a[aria-current="page"]::before { display: none; }
.hdr-pop .rail-foot { display: flex !important; flex-direction: column; align-items: stretch; gap: 6px; padding: 6px 0 0; margin: 4px 0 0; border-top: 1px solid var(--border); }
.hdr-pop .hdr-logout { width: 100%; }
.hdr-pop .mode-chip { padding: 0 10px 4px; }
@media (max-width: 640px) {
  body.ws-learner .brand-text, body.ws-learner .hdr-user .user-chip, body.ws-learner .hdr-progress > span:first-child { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .hdr-bar { width: 64px; }
  .hdr-back { border: 0; margin: 0; padding-inline: 4px; }
}

/* ---- Page headings ---- */
.vl-eyebrow { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
:lang(ar) .vl-eyebrow, :lang(ar) .vl-pill, :lang(ar) .vl-badge { letter-spacing: 0; }
.vl-head { align-items: flex-end; }
.vl-head h1 { font-size: clamp(24px, 3vw, 32px); margin-top: 4px; }
.vl-lede { max-width: 56ch; }
.view-page.vl { max-width: 1240px; margin-inline: auto; width: 100%; }

/* ---- Continue banner (the gray surface gradient) ---- */
.vl-resume { display: flex; align-items: center; gap: var(--sp-5); flex-wrap: wrap; background: var(--surface-gradient); border: 1px solid var(--accent-line); border-radius: var(--r-lg); padding: 18px 22px; margin-bottom: var(--sp-8); }
.vl-resume-text { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 4px; }
.vl-resume-k { font-size: var(--fs-sm); color: var(--text-2); }
.vl-resume h2 { font-size: var(--fs-md); }
.vl-resume-bar { height: 5px; border-radius: 99px; background: var(--surface-3); overflow: hidden; max-width: 360px; margin-top: 8px; }
.vl-resume-bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

/* ---- Library: one section per module, a 3 / 2 / 1-column grid ---- */
.vl-module + .vl-module { margin-top: var(--sp-8); }
.vl-section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; margin: 0 0 var(--sp-4); }
.vl-section-head h2 { font-size: var(--fs-lg); }
.vl-section-head p { margin-top: 2px; max-width: 70ch; font-size: var(--fs-sm); }
.vl-count { font-size: var(--fs-sm); white-space: nowrap; }
.vl-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
@media (max-width: 1100px) { .vl-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .vl-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; } }
.vl-card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; display: flex; flex-direction: column; min-width: 0; cursor: pointer;
  transition: border-color var(--t-fast), box-shadow var(--t), transform var(--t); }
.vl-card:hover { border-color: var(--border-strong); box-shadow: var(--sh-2); transform: translateY(-2px); }
.vl-card:has(.vl-card-title a:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.vl-cover { position: relative; aspect-ratio: 16 / 9; overflow: hidden; background: linear-gradient(135deg, var(--surface-2) 0%, var(--surface-3) 100%); }
.vl-cover .vl-mark { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-3); }
.vl-cover .vl-mark .ic { width: 40px; height: 40px; opacity: .5; }
.vl-thumb { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; opacity: 0; transition: opacity .3s ease; pointer-events: none; }
.vl-thumb.is-ready { opacity: 1; }
.vl-play { position: absolute; inset: 0; margin: auto; width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; z-index: 1;
  background: color-mix(in srgb, var(--bg) 62%, transparent); border: 1px solid color-mix(in srgb, var(--text) 25%, transparent); transition: background var(--t-fast), transform var(--t-fast); }
.vl-play .ic { width: 22px; height: 22px; color: var(--text); }
.vl-card:hover .vl-play { background: var(--accent); transform: scale(1.04); }
.vl-card:hover .vl-play .ic { color: var(--accent-ink); }
.vl-badge, .vl-dur { position: absolute; z-index: 1; bottom: 12px; font-size: 12px; color: #fff; background: rgba(0, 0, 0, .62); padding: 3px 8px; border-radius: 6px; }
.vl-badge { inset-inline-start: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; font-size: 11px; }
.vl-dur { inset-inline-end: 12px; font-family: var(--f-mono); }
.vl-bar { position: absolute; z-index: 1; inset-inline: 0; bottom: 0; height: 4px; background: rgba(255, 255, 255, .16); }
.vl-bar i { display: block; height: 100%; background: var(--accent); }
.vl-card-body { padding: 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; }
.vl-card-title { font-size: 16.5px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.vl-card-title a { color: var(--text); text-decoration: none; }
.vl-card-title a:focus-visible { outline: none; }
.vl-desc { font-size: var(--fs-sm); color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.vl-card-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 8px; }
.vl-pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); color: var(--text-3); white-space: nowrap; }
.vl-pill.is-ok { background: var(--ok-soft); color: var(--ok); }
.vl-pill.is-prog { background: var(--accent-soft); color: var(--accent); }
.vl-skel { cursor: default; }
.vl-skel .vl-cover { background: var(--surface-2); }
.vl-sk { display: block; height: 12px; border-radius: 6px; background: var(--surface-2); width: 80%; }
.vl-sk.short { width: 45%; }

/* ---- Player ---- */
.vp-back { display: inline-flex; align-items: center; gap: 6px; margin-bottom: var(--sp-4); color: var(--text-2); text-decoration: none; font-weight: 500; }
.vp-back:hover { color: var(--text); }
.vp-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 28px; align-items: start; }
.vp-main { min-width: 0; }
.vp-video { position: relative; background: #000; border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--sh-2); aspect-ratio: 16 / 9; }
.vp-video video { display: block; width: 100%; height: 100%; background: #000; }
.vp-loading { display: grid; place-items: center; background: var(--surface-2); }
.vp-error { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 20px; text-align: center; background: rgba(5, 10, 20, .88); color: #E9F0F8; }
.vp-note { min-height: 22px; margin-top: 8px; font-size: var(--fs-sm); color: var(--text-2); }
.vp-meta { display: flex; flex-direction: column; gap: 8px; margin-top: 2px; }
.vp-meta h1 { font-size: clamp(21px, 2.4vw, 28px); }
.vp-desc { color: var(--text-2); max-width: 72ch; }
.vp-status { font-size: var(--fs-sm); }
.vp-after { margin-top: 16px; padding: 14px 16px; border-radius: var(--r-lg); background: var(--surface-gradient); border: 1px solid var(--accent-line); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: space-between; }
.vp-block { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }
.vp-block h2 { font-size: var(--fs-md); margin-bottom: 10px; }
.vp-notes { white-space: pre-line; color: var(--text-2); line-height: 1.7; max-width: 76ch; }
.vp-links { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.vp-links li { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.vp-links a { display: inline-flex; gap: 8px; align-items: center; color: var(--accent-2); text-decoration: none; }
.vp-links a:hover { text-decoration: underline; }
.vp-tr-none { display: flex; gap: 8px; align-items: flex-start; margin-top: 24px; font-size: var(--fs-sm); color: var(--text-2); }
.vp-tr-none .ic { color: var(--text-3); margin-top: 2px; }
.vp-transcript { margin-top: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); }
.vp-transcript summary { display: flex; align-items: center; gap: 8px; padding: 12px 16px; cursor: pointer; font-weight: 600; }
.vp-tr-list { list-style: none; margin: 0; padding: 0 8px 10px; max-height: 340px; overflow-y: auto; }
.vp-tr-list li { display: flex; gap: 10px; align-items: flex-start; padding: 8px; border-radius: var(--r-sm); font-size: var(--fs-sm); color: var(--text-2); }
.vp-tr-list li.is-now { background: var(--accent-soft); color: var(--text); }
.vp-tr-time { flex: 0 0 auto; border: 1px solid var(--border); background: var(--surface-2); border-radius: 6px; padding: 2px 7px; font-family: var(--f-mono); font-size: 12px; color: var(--accent-2); }
.vp-side { position: sticky; top: calc(var(--hdr-h) + 16px); min-width: 0; }
.vp-playlist { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.vp-playlist h2 { font-size: 14px; font-weight: 600; padding: 14px 16px; border-bottom: 1px solid var(--border); color: var(--text-2); }
.vp-pl { list-style: none; margin: 0; padding: 0; max-height: min(70vh, 640px); overflow-y: auto; }
.vp-pl li + li { border-top: 1px solid var(--border); }
.vp-pl-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; color: var(--text); text-decoration: none; }
.vp-pl-item:hover { background: var(--surface-2); }
.vp-pl-item[aria-current="true"] { background: var(--surface-gradient); box-shadow: inset 3px 0 0 var(--accent); }
[dir="rtl"] .vp-pl-item[aria-current="true"] { box-shadow: inset -3px 0 0 var(--accent); }
.vp-pl-num { width: 26px; height: 26px; flex: none; border-radius: 50%; border: 2px solid var(--border-strong); display: grid; place-items: center; font-size: 12px; font-weight: 600; color: var(--text-3); }
.vp-pl-num.is-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.vp-pl-num.is-prog { border-color: var(--accent); color: var(--accent); }
.vp-pl-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.vp-pl-text b { font-size: 14px; line-height: 1.3; font-weight: 600; }
.vp-pl-text span { font-size: 12.5px; color: var(--text-3); }
@media (max-width: 1000px) {
  .vp-layout { grid-template-columns: minmax(0, 1fr); }
  .vp-side { position: static; order: 2; }
  .vp-pl { max-height: none; }
}
@media (max-width: 640px) { .vp-video { border-radius: var(--r); margin-inline: -4px; } }

/* ---- Floating AI Assistant button (player only) ---- */
.ai-dock { position: fixed; z-index: 35; inset-inline-end: 24px; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }
.ai-fab { display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 20px; border-radius: var(--r-pill); border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-ink); font-weight: 600; text-decoration: none; box-shadow: var(--sh-2); transition: transform var(--t-fast), box-shadow var(--t-fast); }
.ai-fab:hover { transform: translateY(-1px); box-shadow: var(--sh-3); }
.ai-fab:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.ai-fab .ic { width: 18px; height: 18px; }
@media (max-width: 640px) { .ai-dock { inset-inline-end: 14px; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); } }

.back-to-video { white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { .vl-card, .vl-thumb, .ai-fab { transition: none; } }

/* Media controls are not mirrored in RTL; leave room under the floating button. */
.view-watch { padding-bottom: 96px; }

/* The assistant's way back to the lesson keeps its label on phones (other header buttons are icon-only there). */
@media (max-width: 900px) { body.ws-learner .topbar-actions .back-to-video span { position: static !important; width: auto; height: auto; overflow: visible; clip: auto; font-size: 13px; } }
