/* Studienportal – Layout: Seitenleiste (Module) · Inhalt (Übersicht / Modul mit Blatt + Lösungen nebeneinander) · Chat-Schublade rechts.
   Zeichnungen und Original-Blätter liegen auf "Papier" (immer hell), damit sie wie auf dem Blatt aussehen. */
:root {
  --bg: #f3f4f7; --panel: #ffffff; --panel-2: #f8f9fb; --ink: #171c28; --muted: #5a6274; --faint: #8a91a1; --line: #dde1e8; --soft: #eceef3;
  --paper: #ffffff; --paper-ink: #1a1a1a; --paper-line: #d9d9d9;
  --ok: #18834a; --warn: #c2410c; --bad: #b42318; --say: #6b7280;
  --m-analysis: #3b57d6; --m-algebra: #0b7c84; --m-c: #2c7a31; --m-dt: #b06500; --m-ss: #a2337d;
  --code-bg: #12161d; --code-ink: #e4e8ef;
  --shadow: 0 1px 2px rgba(20,24,35,.05), 0 6px 24px rgba(20,24,35,.06);
  --f-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --acc: var(--m-analysis);
  --nav-w: 248px; --chat-w: 430px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #0f1218; --panel: #171b23; --panel-2: #1c212b; --ink: #e6e8ee; --muted: #9ba3b4; --faint: #6f7789; --line: #2a303c; --soft: #222833;
  --paper: #f4f4f1; --paper-ink: #1a1a1a; --paper-line: #d6d6d0;
  --ok: #4cc483; --warn: #fb923c; --bad: #f97066; --say: #9ca3af;
  --m-analysis: #8ea1f6; --m-algebra: #4cc6cc; --m-c: #6fcf75; --m-dt: #f2ae48; --m-ss: #e585c8;
  --code-bg: #0a0c10; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 28px rgba(0,0,0,.25); color-scheme: dark } }
:root[data-theme="dark"] {
  --bg: #0f1218; --panel: #171b23; --panel-2: #1c212b; --ink: #e6e8ee; --muted: #9ba3b4; --faint: #6f7789; --line: #2a303c; --soft: #222833;
  --paper: #f4f4f1; --paper-ink: #1a1a1a; --paper-line: #d6d6d0;
  --ok: #4cc483; --warn: #fb923c; --bad: #f97066; --say: #9ca3af;
  --m-analysis: #8ea1f6; --m-algebra: #4cc6cc; --m-c: #6fcf75; --m-dt: #f2ae48; --m-ss: #e585c8;
  --code-bg: #0a0c10; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 28px rgba(0,0,0,.25); color-scheme: dark }

* { box-sizing: border-box }
html, body { height: 100% }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.6 var(--f-body); -webkit-font-smoothing: antialiased }
a { color: var(--acc) }
button { font: inherit; color: inherit; cursor: pointer }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px }
[hidden] { display: none !important }
h1, h2, h3 { text-wrap: balance }
.tab-num, .num { font-variant-numeric: tabular-nums }

/* ---------- Buttons ---------- */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 6px 12px; font-size: .88rem; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap }
.btn:hover { border-color: var(--acc) }
.btn-accent { background: var(--acc); border-color: var(--acc); color: var(--panel) }
.btn-accent:hover { filter: brightness(1.08) }
.btn-ghost { background: none; border-color: transparent }
.btn-ghost:hover { background: var(--soft); border-color: transparent }
.btn:disabled { opacity: .5; cursor: default }
.btn.on { border-color: var(--ok); color: var(--ok) }
.icon-btn { border: 0; background: none; border-radius: 8px; width: 34px; height: 34px; display: inline-grid; place-items: center; font-size: 1rem; color: var(--muted) }
.icon-btn:hover { background: var(--soft); color: var(--ink) }
.seg { display: inline-flex; background: var(--soft); border-radius: 10px; padding: 3px; gap: 2px }
.seg button { border: 0; background: none; border-radius: 8px; padding: 5px 12px; font-size: .85rem; color: var(--muted); font-weight: 500 }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08) }

/* ---------- App-Gerüst ---------- */
.app { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); height: 100%; padding-top: env(safe-area-inset-top, 0px) }
.app.chat-open { grid-template-columns: var(--nav-w) minmax(0, 1fr) var(--chat-w) }
.nav { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; padding-left: env(safe-area-inset-left, 0px) }
.nav-brand { display: flex; gap: 10px; align-items: center; padding: 16px 18px 14px; text-decoration: none; color: var(--ink) }
.nav-brand span { font: 750 1.2rem/1 var(--f-display); letter-spacing: -.01em }
.nav-brand small { display: block; font: 400 .72rem/1.3 var(--f-body); color: var(--muted); letter-spacing: .02em; margin-top: 4px }
.nav-list { flex: 1; overflow-y: auto; padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 2px }
.nav-sec { font: 600 .68rem/1 var(--f-body); text-transform: uppercase; letter-spacing: .09em; color: var(--faint); padding: 14px 10px 6px }
.nav-item { display: grid; grid-template-columns: 10px minmax(0,1fr) auto; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; text-decoration: none; color: var(--ink); font-weight: 500; font-size: .93rem }
.nav-item:hover { background: var(--soft) }
.nav-item[aria-current="page"] { background: color-mix(in srgb, var(--mc, var(--acc)) 13%, transparent) }
.nav-item .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--mc, var(--muted)) }
.nav-item .cnt { font: 500 .72rem var(--f-mono); color: var(--muted) }
.nav-item .new { background: var(--warn); color: #fff; font: 600 .66rem var(--f-body); border-radius: 99px; padding: 1px 7px }
.nav-foot { padding: 10px; border-top: 1px solid var(--line); display: flex; gap: 6px; padding-bottom: max(10px, env(safe-area-inset-bottom, 0px)) }
.nav-small { flex: 1; border: 1px solid var(--line); background: none; border-radius: 8px; padding: 5px; font-size: .78rem; color: var(--muted) }
.main-wrap { display: flex; flex-direction: column; min-width: 0; min-height: 0 }
.top { display: flex; align-items: center; gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--panel); min-height: 56px }
.menu-btn { display: none }
.crumbs { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
.crumbs b { color: var(--ink); font-weight: 600 }
.crumbs a { color: var(--muted); text-decoration: none }
.crumbs a:hover { color: var(--ink) }
.top-actions { display: flex; gap: 8px; align-items: center }
.sync-pill { font-size: .78rem; border-radius: 99px; padding: 4px 10px; background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); font-weight: 600 }
.view { flex: 1; min-height: 0; overflow-y: auto; outline: none }
.pad { padding: 24px max(16px, 3vw) 60px; max-width: 1240px; margin: 0 auto }

/* ---------- Übersicht ---------- */
.hello { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 12px; margin-bottom: 18px }
.hello h1 { font: 750 clamp(1.7rem, 3vw, 2.3rem)/1.1 var(--f-display); margin: 0; letter-spacing: -.02em }
.hello p { margin: 4px 0 0; color: var(--muted) }
.alert { border-radius: 12px; padding: 14px 16px; display: flex; gap: 14px; align-items: center; margin-bottom: 16px; border: 1px solid }
.alert.mfa { background: color-mix(in srgb, var(--warn) 9%, var(--panel)); border-color: color-mix(in srgb, var(--warn) 45%, var(--line)) }
.alert .bignum { font: 750 2.2rem/1 var(--f-display); color: var(--warn); min-width: 64px; text-align: center }
.grid-mods { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px }
.mod-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px 16px 14px; display: flex; flex-direction: column; gap: 10px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); position: relative; overflow: hidden; min-width: 0 }
.mod-card::before { content: ""; position: absolute; inset: 0 0 auto; height: 4px; background: var(--mc) }
.mod-card:hover { border-color: var(--mc) }
.mod-card h3 { margin: 0; font: 650 1.08rem/1.25 var(--f-display) }
.mod-card .who { color: var(--muted); font-size: .8rem; margin-top: 2px }
.bar { height: 7px; background: var(--soft); border-radius: 99px; overflow: hidden }
.bar > i { display: block; height: 100%; background: var(--mc, var(--acc)); border-radius: 99px }
.mod-stats { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted) }
.mod-next { font-size: .85rem; border-top: 1px dashed var(--line); padding-top: 9px; color: var(--muted) }
.mod-next b { color: var(--ink); font-weight: 600 }
.tag-new { background: var(--warn); color: #fff; font: 600 .66rem var(--f-body); border-radius: 99px; padding: 1px 7px; vertical-align: 2px; letter-spacing: .02em }
.cols { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; margin-top: 18px }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; min-width: 0 }
.card h2 { font: 650 1rem var(--f-display); margin: 0 0 10px; display: flex; align-items: center; gap: 8px }
.card h2 small { font: 400 .78rem var(--f-body); color: var(--muted) }
.list { display: flex; flex-direction: column }
.li { display: grid; grid-template-columns: 8px minmax(0,1fr) auto; gap: 10px; align-items: baseline; padding: 8px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); font-size: .9rem }
.li:last-child { border-bottom: 0 }
.li .dot { width: 8px; height: 8px; border-radius: 2px; background: var(--mc); align-self: center }
.li small { color: var(--muted); font-size: .78rem }
.li:hover b { color: var(--acc) }
.post { padding: 9px 2px; border-bottom: 1px solid var(--line); font-size: .87rem }
.post:last-child { border-bottom: 0 }
.post b { display: block; font-weight: 600 }
.post p { margin: 2px 0 0; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden }
.empty { color: var(--muted); font-size: .88rem; padding: 6px 2px }
.sync-card { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; font-size: .86rem; color: var(--muted) }
.sync-card b { color: var(--ink) }
.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; background: var(--ok) }
.status-dot.warn { background: var(--warn) }

/* ---------- Modul ---------- */
.mod-head { padding: 18px max(16px, 2vw) 0; border-bottom: 1px solid var(--line); background: var(--panel) }
.mod-head .eyebrow { font: 600 .72rem/1 var(--f-body); text-transform: uppercase; letter-spacing: .09em; color: var(--acc) }
.mod-head h1 { font: 750 clamp(1.4rem, 2.4vw, 1.9rem)/1.15 var(--f-display); margin: 6px 0 2px; letter-spacing: -.015em }
.mod-head .meta { color: var(--muted); font-size: .84rem; display: flex; flex-wrap: wrap; gap: 4px 16px }
.tabs { display: flex; gap: 2px; margin-top: 12px; overflow-x: auto }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--muted); font-weight: 500; font-size: .9rem; border-bottom: 2px solid transparent; white-space: nowrap }
.tabs a[aria-current="page"] { color: var(--ink); border-color: var(--acc) }
.mod-body { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 0 }
.sheets { border-right: 1px solid var(--line); padding: 12px 10px 40px; overflow-y: auto; background: var(--panel-2); position: sticky; top: 0; align-self: start; max-height: calc(100vh - 56px); max-height: calc(100dvh - 56px) }
.sheets h3 { font: 600 .68rem/1 var(--f-body); text-transform: uppercase; letter-spacing: .09em; color: var(--faint); margin: 14px 8px 8px }
.sheets h3:first-child { margin-top: 4px }
.sh { display: block; width: 100%; text-align: left; border: 0; background: none; border-radius: 9px; padding: 8px 10px; margin-bottom: 2px; text-decoration: none; color: var(--ink) }
.sh:hover { background: var(--soft) }
.sh[aria-current="page"] { background: color-mix(in srgb, var(--acc) 13%, transparent) }
.sh b { display: block; font-size: .9rem; font-weight: 600 }
.sh[aria-current="page"] b { color: var(--acc) }
.sh span { display: block; font-size: .78rem; color: var(--muted); line-height: 1.35 }
.sh .bar { height: 4px; margin-top: 6px }
.sheet-pick { display: none }

/* Blatt-Ansicht */
.sheet-top { position: sticky; top: 0; z-index: 3; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding: 10px max(16px, 2vw); display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center }
.sheet-top h2 { margin: 0; font: 650 1.1rem/1.2 var(--f-display); flex: 1; min-width: 200px }
.sheet-top h2 small { display: block; font: 400 .8rem var(--f-body); color: var(--muted) }
.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 }
.split.both { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) }
.split.both .pdf-pane { border-right: 1px solid var(--line) }
.pdf-pane { background: var(--soft); min-width: 0; position: sticky; top: 64px; height: calc(100vh - 56px - 64px - env(safe-area-inset-top, 0px)); height: calc(100dvh - 56px - 64px - env(safe-area-inset-top, 0px)); overflow: auto; padding: 14px }
.split:not(.both) .pdf-pane { position: static; height: auto; overflow: visible }
.pdf-page { background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.15); margin: 0 auto 14px; position: relative; max-width: 100% }
.pdf-page canvas { display: block; width: 100%; height: auto }
.pdf-page .pnum { position: absolute; right: 8px; bottom: 6px; font: 500 .7rem var(--f-mono); color: #777 }
.pdf-page.flash { outline: 3px solid var(--acc); outline-offset: 3px }
.pdf-none { color: var(--muted); padding: 30px; text-align: center }
.tasks-pane { min-width: 0; padding: 18px max(16px, 2vw) 80px; display: flex; flex-direction: column; gap: 14px }
.intro { background: color-mix(in srgb, var(--acc) 7%, var(--panel)); border: 1px solid color-mix(in srgb, var(--acc) 22%, var(--line)); border-radius: 12px; padding: 14px 16px }
.intro h3, .sec-h { margin: 0 0 4px; font: 600 .72rem var(--f-body); text-transform: uppercase; letter-spacing: .08em; color: var(--acc) }
.sec-h { margin: 12px 0 0; font: 650 1.05rem var(--f-display); text-transform: none; letter-spacing: 0; color: var(--ink); display: flex; gap: 10px; align-items: baseline }
.sec-h small { font: 400 .8rem var(--f-body); color: var(--muted) }
.hint { border: 1px dashed var(--line); border-radius: 12px; padding: 12px 14px; font-size: .88rem; color: var(--muted) }
.hint b { color: var(--ink) }
.hint.lab { border-style: solid; border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); background: color-mix(in srgb, var(--warn) 6%, var(--panel)) }
.task { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0 }
.task.done { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)) }
.task.focus { box-shadow: 0 0 0 2px var(--acc) }
.task-top { display: flex; gap: 12px; align-items: flex-start }
.nr { font: 600 .82rem var(--f-mono); color: var(--acc); background: color-mix(in srgb, var(--acc) 11%, transparent); border-radius: 6px; padding: 2px 8px; white-space: nowrap }
.lvl { font: 600 .68rem var(--f-body); text-transform: uppercase; letter-spacing: .07em; border-radius: 99px; padding: 3px 9px; white-space: nowrap }
.lvl.leicht { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent) }
.lvl.mittel { color: var(--acc); background: color-mix(in srgb, var(--acc) 12%, transparent) }
.lvl.klausur { color: var(--warn); background: color-mix(in srgb, var(--warn) 13%, transparent) }
.task-text { flex: 1; min-width: 0 }
.task-text > :first-child { margin-top: 0 }
.task-actions { display: flex; flex-wrap: wrap; gap: 6px }
details.sol { border-top: 1px solid var(--line); padding-top: 6px }
details.sol > summary { cursor: pointer; font-weight: 600; color: var(--acc); list-style: none; display: flex; align-items: center; gap: 8px; padding: 4px 0 }
details.sol > summary::-webkit-details-marker { display: none }
details.sol > summary::before { content: "▸"; transition: transform .15s }
details.sol[open] > summary::before { transform: rotate(90deg) }
.part { margin-top: 12px }
.part h4 { margin: 0 0 3px; font: 600 .7rem var(--f-body); text-transform: uppercase; letter-spacing: .08em; color: var(--muted) }
ol.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; display: flex; flex-direction: column; gap: 9px }
ol.steps > li { counter-increment: s; display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 8px }
ol.steps > li::before { content: counter(s); font: 600 .78rem/26px var(--f-mono); text-align: center; width: 26px; height: 26px; border-radius: 50%; background: var(--soft) }
ol.steps > li > div { min-width: 0 }
.result { border-left: 3px solid var(--ok); padding: 8px 12px; background: color-mix(in srgb, var(--ok) 7%, transparent); border-radius: 0 8px 8px 0; min-width: 0 }
.trap { border-left: 3px solid var(--warn); padding: 8px 12px; background: color-mix(in srgb, var(--warn) 7%, transparent); border-radius: 0 8px 8px 0; min-width: 0 }
.say { color: var(--say); font-size: .85rem; font-style: italic; margin: -2px 0 6px }
.mine { border-top: 1px solid var(--line); padding-top: 8px }
.mine textarea { width: 100%; min-height: 90px; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; background: var(--panel-2); color: var(--ink); font: 14px/1.5 var(--f-mono); resize: vertical }
.mine .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; align-items: center; font-size: .8rem; color: var(--muted) }
pre { background: var(--code-bg); color: var(--code-ink); border-radius: 8px; padding: 10px 12px; overflow-x: auto; font: 13px/1.5 var(--f-mono); margin: 6px 0 }
code { font-family: var(--f-mono); font-size: .9em }
:not(pre) > code { background: var(--soft); border-radius: 4px; padding: 1px 5px }
.task table, .intro table, .chat-msg table { border-collapse: collapse; margin: 6px 0; font-variant-numeric: tabular-nums }
.task td, .task th, .intro td, .intro th, .chat-msg td, .chat-msg th { border: 1px solid var(--line); padding: 3px 9px; text-align: center }
.task th, .chat-msg th { background: var(--soft) }
.scroll-x { overflow-x: auto; max-width: 100% }
mjx-container { max-width: 100%; overflow-x: auto; overflow-y: hidden }

/* ---------- Zeichnungen (auf Papier) ---------- */
.dia { background: var(--paper); color: var(--paper-ink); border: 1px solid var(--paper-line); border-radius: 10px; padding: 12px; margin: 8px 0; overflow-x: auto; max-width: 100% }
.dia svg { display: block; margin: 0 auto; max-width: 100%; height: auto }
.dia[data-typ="schaltung"] svg { zoom: 1.7 }
.dia[data-typ="wavedrom"] svg { zoom: 1.15 }
.dia .dia-titel { font-size: .78rem; color: #555; text-align: center; margin-top: 6px }
.dia.dia-fehler { background: color-mix(in srgb, var(--bad) 8%, var(--panel)); color: var(--bad); font: 12px var(--f-mono); white-space: pre-wrap }
.dia-src { display: none }

/* ---------- Materialien ---------- */
.mat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px }
.mat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-width: 0 }
.mat h3 { margin: 0 0 6px; font: 600 .92rem/1.3 var(--f-body) }
.mat a.file { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; text-decoration: none; color: var(--ink); font-size: .86rem; word-break: break-word }
.mat a.file:hover { color: var(--acc) }
.ext { font: 600 .62rem var(--f-mono); text-transform: uppercase; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; flex: none }

/* ---------- Terminal ---------- */
.term-wrap { display: flex; flex-direction: column; height: calc(100% - 0px); padding: 12px max(12px, 1.5vw) 14px; gap: 10px; min-height: 0 }
.term-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: .84rem; color: var(--muted) }
.term-bar code { color: var(--ink) }
.term { flex: 1; min-height: 320px; background: #0c0f14; border-radius: 12px; padding: 10px; overflow: hidden; border: 1px solid #222 }
.term .xterm { height: 100% }
.term-state { font-size: .78rem }

/* ---------- Dateien ---------- */
.files { padding: 14px max(16px, 2vw) 60px; max-width: 1000px }
.files-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px }
.bc { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: .9rem; flex: 1; min-width: 200px }
.bc a { text-decoration: none }
.ftable { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden }
.frow { display: grid; grid-template-columns: 26px minmax(0, 1fr) 90px 150px auto; gap: 10px; align-items: center; padding: 7px 12px; border-bottom: 1px solid var(--line); font-size: .9rem }
.frow:last-child { border-bottom: 0 }
.frow:hover { background: var(--panel-2) }
.frow .fn { border: 0; background: none; text-align: left; padding: 0; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.frow .fn:hover { color: var(--acc); text-decoration: underline }
.frow .fmeta { color: var(--muted); font-size: .78rem; font-variant-numeric: tabular-nums }
.frow .fact { display: flex; gap: 2px; justify-content: flex-end }
.ficon { font: 600 .66rem var(--f-mono); color: var(--muted); text-align: center }
.ficon.dir { color: var(--acc) }
.confirm { display: flex; gap: 8px; align-items: center; background: color-mix(in srgb, var(--bad) 8%, var(--panel)); border: 1px solid color-mix(in srgb, var(--bad) 35%, var(--line)); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; font-size: .88rem }
.editor { width: 100%; min-height: 55vh; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--code-bg); color: var(--code-ink); font: 14px/1.5 var(--f-mono); resize: vertical; tab-size: 4 }
.inline-form { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap }
.inline-form input { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--panel); color: var(--ink); font: inherit; min-width: 220px }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--panel); padding: 8px 16px; border-radius: 99px; font-size: .88rem; z-index: 60; box-shadow: var(--shadow) }

/* ---------- Chat ---------- */
.chat { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; padding-right: env(safe-area-inset-right, 0px) }
.chat-head { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; align-items: flex-start }
.chat-head b { font: 650 1rem var(--f-display) }
.chat-ctx { font-size: .78rem; color: var(--muted); line-height: 1.3; margin-top: 2px }
.chat-ctx span { color: var(--acc); font-weight: 600 }
.chat-head-actions { display: flex }
.chat-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px }
.chat-msg { font-size: .92rem; min-width: 0 }
.chat-msg.me { align-self: flex-end; background: color-mix(in srgb, var(--acc) 12%, transparent); border-radius: 12px 12px 3px 12px; padding: 7px 11px; max-width: 90%; white-space: pre-wrap }
.chat-msg.me small { display: block; color: var(--muted); font-size: .72rem }
.chat-msg.ai p { margin: .4em 0 }
.chat-msg.ai ul, .chat-msg.ai ol { padding-left: 20px; margin: .4em 0 }
.chat-msg.err { color: var(--bad) }
.chat-msg .info { color: var(--muted); font-size: .8rem; font-style: italic }
.chat-empty { color: var(--muted); font-size: .88rem }
.chat-empty button { display: block; border: 1px solid var(--line); background: var(--panel-2); border-radius: 9px; padding: 7px 10px; margin-top: 6px; text-align: left; width: 100%; font-size: .85rem; color: var(--ink) }
.chat-empty button:hover { border-color: var(--acc) }
.chat-in { border-top: 1px solid var(--line); padding: 10px 12px 6px; display: flex; gap: 8px; align-items: flex-end }
.chat-in textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font: inherit; font-size: .92rem; background: var(--bg); color: var(--ink); max-height: 180px }
.chat-note { font-size: .72rem; color: var(--faint); padding: 0 14px max(8px, env(safe-area-inset-bottom, 0px)) }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(10,12,18,.5); z-index: 50; display: grid; place-items: center; padding: 16px }
.modal-box { background: var(--panel); border-radius: 14px; width: min(980px, 100%); max-height: 92vh; display: flex; flex-direction: column; box-shadow: var(--shadow); min-width: 0 }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); gap: 10px }
.modal-head b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.modal-body { overflow: auto; padding: 14px; min-height: 0 }

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; min-height: 100%; padding: 16px }
.login { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 30px 26px; box-shadow: var(--shadow) }
.login h1 { font: 750 2rem/1 var(--f-display); margin: 14px 0 4px; letter-spacing: -.02em }
.login-sub { color: var(--muted); margin: 0 0 22px; font-size: .88rem }
.login-mark { display: flex; gap: 5px; align-items: end; height: 34px }
.login-mark span { width: 9px; border-radius: 3px }
.login-mark span:nth-child(1) { height: 50%; background: var(--m-analysis) } .login-mark span:nth-child(2) { height: 75%; background: var(--m-algebra) }
.login-mark span:nth-child(3) { height: 100%; background: var(--m-c) } .login-mark span:nth-child(4) { height: 80%; background: var(--m-dt) } .login-mark span:nth-child(5) { height: 62%; background: var(--m-ss) }
.login label { font-size: .82rem; font-weight: 600; display: block; margin-bottom: 6px }
.login input { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; background: var(--bg); color: var(--ink) }
.login button { width: 100%; margin-top: 14px; border: 0; border-radius: 10px; padding: 11px; font-weight: 600; background: var(--m-analysis); color: #fff }
.login-err { color: var(--bad); font-size: .86rem; margin: 12px 0 0 }

/* ---------- Responsiv ---------- */
@media (max-width: 1500px) { .app.chat-open { grid-template-columns: var(--nav-w) minmax(0, 1fr) } .chat { position: fixed; right: 0; top: env(safe-area-inset-top, 0px); bottom: 0; width: min(var(--chat-w), 100%); z-index: 40; box-shadow: var(--shadow) } }
@media (max-width: 1250px) { .split.both { grid-template-columns: minmax(0, 1fr) } .split.both .pdf-pane { position: static; height: auto; max-height: 70vh; border-right: 0; border-bottom: 1px solid var(--line) } }
@media (max-width: 980px) {
  .app, .app.chat-open { grid-template-columns: minmax(0, 1fr) }
  .nav { position: fixed; inset: env(safe-area-inset-top, 0px) auto 0 0; width: min(290px, 85vw); z-index: 45; transform: translateX(-102%); transition: transform .2s; box-shadow: var(--shadow) }
  .app.nav-open .nav { transform: none }
  .menu-btn { display: inline-grid }
  .mod-body { grid-template-columns: minmax(0, 1fr) }
  .sheets { display: none }
  .sheet-pick { display: block; width: 100%; margin: 10px 0 0; padding: 8px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: inherit }
  .cols { grid-template-columns: minmax(0, 1fr) }
  .frow { grid-template-columns: 26px minmax(0, 1fr) auto }
  .frow .fmeta { display: none }
}
@media (max-width: 560px) { .top { padding: 8px 12px } .crumbs { font-size: .82rem } .sheet-top .seg button { padding: 5px 8px } .alert { flex-direction: column; align-items: flex-start } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important } }
