/* ==========================================================================
   Click-through demo of the chat interface (/demo).
   
   Self-contained: the demo runs in its own document, either as a page or in
   the home page's iframe. So it brings its own token set instead of building
   on tokens.css — the colour roles of an application interface (sidebar,
   panel, bubble) have no counterpart on the website.
   
   Where the same role exists, the values are deliberately identical:
   --ink = --color-text, --ink-2 = --color-muted.
   ========================================================================== */

/* The same two cuts as the website — the browser rounds 500 to 400 and 700
   to 600, exactly as there. No Google Fonts call: the site advertises giving
   no data to public services. */

@font-face {
  font-family: "Inter";
  src: url("../fonts/inter-400-poxsSdI.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Inter";
  src: url("../fonts/inter-600-keCwlca.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

/* ---------- Tokens ---------- */
:root {
  --ink:            #172033;
  --ink-2:          #556377;
  --ink-3:          #5D6B7D;   /* 5.4:1 on white, 4.9:1 on --surface-3 */
  --line:           rgba(15, 23, 42, .10);
  --line-soft:      rgba(15, 23, 42, .06);

  --brand:          #0B6D61;
  --brand-hi:       #0F8577;
  --brand-teal:     #19C3AF;
  --brand-navy:     #16324F;
  --coral:          #FF9D8A;

  --bg:             #F4F7F8;
  --surface:        #FFFFFF;
  --surface-2:      #F8FAFB;
  --surface-3:      #EEF4F7;

  --nav-bg:         #12233A;
  --nav-bg-2:       #0D1B2E;
  --nav-ink:        #E8EEF4;
  --nav-ink-dim:    #93A7BD;
  --nav-line:       rgba(255, 255, 255, .09);
  --nav-hover:      rgba(255, 255, 255, .07);
  --nav-active:     rgba(25, 195, 175, .14);

  --logo-disc:      #FFFFFF;
  --logo-mark:      #16324F;
  --logo-word:      #16324F;

  --ok:             #12886F;
  --warn:           #B8791C;
  --warn-bg:        #FDF6E7;
  --warn-line:      #F0DDB4;

  --shadow-sm:      0 1px 2px rgba(15, 23, 42, .05);
  --shadow:         0 4px 16px -6px rgba(15, 23, 42, .14), 0 1px 3px rgba(15, 23, 42, .05);
  --shadow-lg:      0 24px 48px -20px rgba(15, 23, 42, .28), 0 2px 8px rgba(15, 23, 42, .06);

  --r-sm: 8px;  --r: 12px;  --r-lg: 16px;  --r-xl: 22px;
  --sidebar-w: 276px;
  --doc-w: 428px;
  --thread-w: 768px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --ink:            #E7EDF3;
  --ink-2:          #9DAFC1;
  --ink-3:          #8DA3BB;   /* dunkles Thema: heller = mehr Kontrast */
  --line:           rgba(255, 255, 255, .11);
  --line-soft:      rgba(255, 255, 255, .06);

  --brand:          #19C3AF;
  --brand-hi:       #35D6C2;
  --bg:             #0B1524;
  --surface:        #10203A;
  --surface-2:      #142743;
  --surface-3:      #17304F;

  --nav-bg:         #081120;
  --nav-bg-2:       #060D19;
  --nav-ink:        #E7EDF3;
  --nav-ink-dim:    #8098B2;

  --logo-disc:      #E7EDF3;
  --logo-word:      #FFFFFF;

  --ok:             #35D6C2;
  --warn:           #E8C079;
  --warn-bg:        rgba(232, 192, 121, .10);
  --warn-line:      rgba(232, 192, 121, .28);

  --shadow-sm:      0 1px 2px rgba(0, 0, 0, .3);
  --shadow:         0 4px 16px -6px rgba(0, 0, 0, .5);
  --shadow-lg:      0 24px 48px -20px rgba(0, 0, 0, .7);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* beats the components' display:flex/grid */
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100vh;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
:focus-visible { outline: 2px solid var(--brand-teal); outline-offset: 2px; border-radius: 4px; }
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.dal-disc { fill: var(--logo-disc); }
.dal-mark { fill: var(--logo-mark); }
.dal-word { fill: var(--logo-word); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(120, 140, 160, .32); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(120, 140, 160, .5); border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- App shell ---------- */
.app { display: flex; flex: 1; min-height: 0; overflow: hidden; }

/* ---------- Sidebar ---------- */
.nav {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--nav-bg) 0%, var(--nav-bg-2) 100%);
  color: var(--nav-ink);
  border-right: 1px solid rgba(0, 0, 0, .2);
  transition: margin-left .28s cubic-bezier(.4, 0, .2, 1);
}
.app.nav-collapsed .nav { margin-left: calc(var(--sidebar-w) * -1); }

.nav__head { padding: 18px 18px 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.nav__logo { height: 30px; width: auto; display: block; }
.nav__logo use { pointer-events: none; }
/* Colours of images/logo/digital-admiral-blue-white.svg. Custom properties,
   not descendant selectors: those do not reach into the <use> shadow tree. */
.nav__logo { --logo-disc: #ffffff; --logo-mark: #16324f; --logo-word: #ffffff; }

.icon-btn {
  width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm); color: var(--nav-ink-dim); transition: background .14s, color .14s;
}
.icon-btn:hover { background: var(--nav-hover); color: var(--nav-ink); }
.icon-btn svg { width: 17px; height: 17px; }

.nav__new {
  margin: 2px 14px 14px; padding: 10px 14px; display: flex; align-items: center; gap: 9px;
  background: var(--brand); color: #fff; border-radius: var(--r);
  font-size: 14px; font-weight: 600; letter-spacing: -.01em;
  box-shadow: 0 2px 8px -2px rgba(11, 109, 97, .6);
  transition: background .14s, transform .1s;
}
.nav__new:hover { background: var(--brand-hi); }
.nav__new:active { transform: translateY(1px); }
.nav__new svg { width: 16px; height: 16px; }

.nav__section { padding: 0 14px; margin-bottom: 6px; }
.nav__label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--nav-ink-dim); opacity: .8; padding: 10px 6px 6px; display: flex; align-items: center; justify-content: space-between;
}

/* Wissensbasis-Auswahl */
.kb {
  width: 100%; text-align: left; padding: 11px 12px; border-radius: var(--r);
  background: rgba(255, 255, 255, .05); border: 1px solid var(--nav-line);
  display: flex; gap: 10px; align-items: center; transition: background .14s, border-color .14s;
}
.kb:hover { background: rgba(255, 255, 255, .09); border-color: rgba(255, 255, 255, .16); }
.kb__icon {
  width: 30px; height: 30px; flex: none; border-radius: 9px; display: grid; place-items: center;
  background: var(--nav-active); color: var(--brand-teal);
}
.kb__icon svg { width: 16px; height: 16px; }
.kb__body { min-width: 0; flex: 1; }
.kb__name { font-size: 13.5px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kb__meta { font-size: 11.5px; color: var(--nav-ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kb__chev { color: var(--nav-ink-dim); flex: none; }
.kb__chev svg { width: 14px; height: 14px; }

.nav__history { flex: 1; overflow-y: auto; padding: 0 14px 8px; }
.hist-group + .hist-group { margin-top: 4px; }
.hist {
  width: 100%; text-align: left; padding: 8px 10px; border-radius: var(--r-sm);
  font-size: 13.5px; color: var(--nav-ink); opacity: .78;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: block; transition: background .12s, opacity .12s;
}
.hist:hover { background: var(--nav-hover); opacity: 1; }
.hist.is-active { background: var(--nav-active); opacity: 1; font-weight: 600; box-shadow: inset 2px 0 0 var(--brand-teal); }

.nav__foot { border-top: 1px solid var(--nav-line); padding: 10px 14px; display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; letter-spacing: .02em; color: #fff;
  background: linear-gradient(135deg, var(--brand-hi), var(--brand-navy));
}
.nav__user { flex: 1; min-width: 0; }
.nav__user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav__user-role { font-size: 11.5px; color: var(--nav-ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); position: relative; }

.topbar {
  height: 58px; flex: none; display: flex; align-items: center; gap: 12px;
  padding: 0 18px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.topbar .icon-btn { color: var(--ink-2); }
.topbar .icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.topbar__title { font-size: 14.5px; font-weight: 600; letter-spacing: -.012em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__sub { font-size: 12px; color: var(--ink-3); }
.topbar__grow { flex: 1; min-width: 0; }
.topbar__actions { display: flex; align-items: center; gap: 4px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 8px;
  border-radius: 999px; font-size: 11.5px; font-weight: 600; letter-spacing: -.005em;
  background: var(--surface-3); color: var(--brand); border: 1px solid transparent;
}
.pill svg { width: 13px; height: 13px; }
.pill--ghost { background: transparent; border-color: var(--line); color: var(--ink-2); font-weight: 500; }
.pill--local { background: transparent; border-color: rgba(11, 109, 97, .3); color: var(--brand); }
.pill--local svg { color: var(--brand); }
[data-theme="dark"] .pill { background: rgba(25, 195, 175, .13); }

/* ---------- Thread ---------- */
.thread { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.thread__inner { max-width: var(--thread-w); margin: 0 auto; padding: 28px 24px 12px; }

.msg { margin-bottom: 30px; animation: rise .32s cubic-bezier(.2, .7, .3, 1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: none; } }

.msg--user { display: flex; justify-content: flex-end; }
.msg--user .bubble {
  max-width: 84%; padding: 11px 16px; border-radius: var(--r-lg) var(--r-lg) 5px var(--r-lg);
  background: var(--brand); color: #fff; font-size: 14.5px; line-height: 1.5;
  box-shadow: 0 2px 10px -4px rgba(11, 109, 97, .55);
}
[data-theme="dark"] .msg--user .bubble { background: #12564E; color: #EAFBF7; }

.msg__head { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.bot-avatar {
  width: 28px; height: 28px; flex: none; border-radius: 50%; background: var(--brand-navy);
  display: grid; place-items: center; box-shadow: var(--shadow-sm);
}
.bot-avatar svg { width: 26px; height: 26px; }
.bot-avatar .dal-disc { fill: #fff; }
.bot-avatar .dal-mark { fill: var(--brand-navy); }
.msg__name { font-size: 12.5px; font-weight: 700; letter-spacing: .015em; }
.msg__time { font-size: 11.5px; color: var(--ink-3); }

/* ---------- Reasoning ---------- */
.reason {
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface);
  margin-bottom: 14px; overflow: hidden; box-shadow: var(--shadow-sm);
}
.reason__bar {
  width: 100%; display: flex; align-items: center; gap: 9px; padding: 9px 13px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-2); text-align: left;
}
.reason__bar:hover { background: var(--surface-2); }
.reason__bar .chev { margin-left: auto; transition: transform .2s; color: var(--ink-3); }
.reason__bar .chev svg { width: 14px; height: 14px; display: block; }
.reason.is-open .chev { transform: rotate(180deg); }
.reason__glyph { width: 15px; height: 15px; color: var(--brand); flex: none; }
.reason__glyph svg { width: 15px; height: 15px; display: block; }
.reason__body { display: none; padding: 2px 13px 12px 13px; border-top: 1px solid var(--line-soft); }
.reason.is-open .reason__body { display: block; }

.step { display: flex; gap: 10px; padding: 7px 0 7px 2px; font-size: 12.5px; color: var(--ink-2); animation: rise .26s ease both; }
.step__dot { width: 15px; height: 15px; flex: none; margin-top: 2px; position: relative; }
.step__dot svg { width: 15px; height: 15px; color: var(--ok); display: block; }
.step.is-running .step__dot::after {
  content: ""; position: absolute; inset: 1px; border-radius: 50%;
  border: 1.8px solid var(--brand-teal); border-top-color: transparent; animation: spin .7s linear infinite;
}
.step.is-running .step__dot svg { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.step__txt strong { color: var(--ink); font-weight: 600; }
.step__meta { color: var(--ink-3); font-size: 11.5px; }

/* ---------- Answer body ---------- */
.answer { font-size: 15px; line-height: 1.68; letter-spacing: -.003em; }
.answer p { margin: 0 0 13px; }
.answer h4 { font-size: 13.5px; font-weight: 700; margin: 20px 0 8px; letter-spacing: -.01em; }
.answer ul, .answer ol { margin: 0 0 13px; padding-left: 20px; }
.answer li { margin-bottom: 6px; }
.answer li::marker { color: var(--ink-3); }
.answer strong { font-weight: 600; }
.answer > *:last-child { margin-bottom: 0; }

.answer table { width: 100%; border-collapse: collapse; margin: 4px 0 16px; font-size: 13.5px; }
.answer th, .answer td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.answer th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 700; background: var(--surface-2); }
.answer tr:last-child td { border-bottom: 0; }
.answer table { border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }

.note {
  display: flex; gap: 10px; padding: 11px 14px; border-radius: var(--r-sm); margin: 0 0 14px;
  background: var(--warn-bg); border: 1px solid var(--warn-line); font-size: 13.5px; line-height: 1.55; color: var(--ink);
}
.note svg { width: 16px; height: 16px; flex: none; margin-top: 2px; color: var(--warn); }

/* Zitat-Chips */
.cite {
  display: inline-flex; align-items: center; justify-content: center; min-width: 17px; height: 17px;
  padding: 0 5px; margin: 0 0 0 1px; vertical-align: 2px;
  font-size: 10.5px; font-weight: 700; line-height: 1;
  color: var(--brand); background: var(--surface-3); border-radius: 5px;
  cursor: pointer; transition: background .12s, color .12s, transform .12s;
}
.cite:hover { background: var(--brand); color: #fff; transform: translateY(-1px); }
.cite.is-active { background: var(--brand); color: #fff; }
[data-theme="dark"] .cite { background: rgba(25, 195, 175, .16); }

.caret { display: inline-block; width: 7px; height: 15px; vertical-align: -3px; margin-left: 2px; background: var(--brand); border-radius: 1px; animation: blink .9s steps(2) infinite; }
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

/* ---------- Sources ---------- */
.sources { margin-top: 18px; }
.sources__head svg { width: 13px; height: 13px; }
.sources__head { display: flex; align-items: center; gap: 7px; font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 9px; }
.sources__list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.src {
  display: flex; gap: 10px; padding: 10px 11px; text-align: left; width: 100%;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface);
  transition: border-color .14s, box-shadow .14s, transform .14s;
}
.src:hover { border-color: rgba(11, 109, 97, .45); box-shadow: var(--shadow); transform: translateY(-1px); }
.src.is-active { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(11, 109, 97, .14); }
.src__n {
  width: 19px; height: 19px; flex: none; border-radius: 5px; display: grid; place-items: center;
  font-size: 10.5px; font-weight: 700; color: #fff; background: var(--brand); margin-top: 1px;
}
.src__body { min-width: 0; }
.src__title { font-size: 12.8px; font-weight: 600; letter-spacing: -.01em; line-height: 1.35; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src__meta { font-size: 11.5px; color: var(--ink-3); display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.src__meta .dot { width: 2.5px; height: 2.5px; border-radius: 50%; background: currentColor; opacity: .6; }
.score { display: inline-flex; align-items: center; gap: 4px; color: var(--ok); font-weight: 600; }
.score__bar { width: 22px; height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.score__fill { height: 100%; background: var(--ok); border-radius: 2px; }

/* ---------- Action bar ---------- */
.actions { display: flex; align-items: center; gap: 2px; margin-top: 14px; }
.act {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: var(--r-sm);
  font-size: 12px; color: var(--ink-3); transition: background .12s, color .12s;
}
.act:hover { background: var(--surface-3); color: var(--ink-2); }
.act svg { width: 14.5px; height: 14.5px; }
.act.is-on { color: var(--brand); background: var(--surface-3); }
.act.is-off { color: var(--coral); background: rgba(255, 157, 138, .14); }
.act--sep { margin-left: auto; font-size: 11.5px; color: var(--ink-3); cursor: default; }
.act--sep:hover { background: none; }

/* ---------- Empty state ---------- */
.hero { max-width: 720px; margin: 0 auto; padding: 6vh 24px 24px; text-align: center; animation: rise .4s ease both; }
.hero__logo { height: 46px; width: auto; margin-bottom: 22px; }
.hero__logo .dal-disc { fill: var(--brand-navy); }
.hero__logo .dal-mark { fill: #fff; }
.hero__logo .dal-word { fill: var(--ink); }
[data-theme="dark"] .hero__logo .dal-disc { fill: #fff; }
[data-theme="dark"] .hero__logo .dal-mark { fill: var(--brand-navy); }
.hero__title { font-size: 27px; font-weight: 700; letter-spacing: -.032em; margin: 0 0 8px; line-height: 1.2; }
.hero__sub { font-size: 14.5px; color: var(--ink-2); margin: 0 auto 26px; max-width: 480px; }
.hero__kb { display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 12px; color: var(--ink-2); margin-bottom: 26px; box-shadow: var(--shadow-sm); }
.hero__kb svg { width: 13px; height: 13px; color: var(--brand); }
.hero__kb b { color: var(--ink); font-weight: 600; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; }
.card {
  padding: 13px 15px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface);
  transition: border-color .15s, box-shadow .15s, transform .15s; display: flex; gap: 11px; align-items: flex-start;
}
.card:hover { border-color: rgba(11, 109, 97, .45); box-shadow: var(--shadow); transform: translateY(-2px); }
.card__icon { width: 26px; height: 26px; flex: none; border-radius: 8px; display: grid; place-items: center; background: var(--surface-3); color: var(--brand); }
.card__icon svg { width: 14px; height: 14px; }
.card__q { font-size: 13.5px; line-height: 1.45; font-weight: 500; letter-spacing: -.008em; }
.card__tag { font-size: 11px; color: var(--ink-3); margin-top: 3px; }

/* ---------- Composer ---------- */
.composer { flex: none; padding: 6px 24px 16px; background: linear-gradient(180deg, transparent, var(--bg) 22%); }
.composer__inner { max-width: var(--thread-w); margin: 0 auto; }
.chips { display: flex; gap: 7px; margin-bottom: 9px; flex-wrap: wrap; }
.chip {
  padding: 5px 11px; border-radius: 999px; font-size: 12.5px; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--line); transition: all .14s; white-space: nowrap;
}
.chip:hover { color: var(--brand); border-color: rgba(11, 109, 97, .4); background: var(--surface); box-shadow: var(--shadow-sm); }

.box {
  border: 1px solid var(--line); border-radius: var(--r-xl); background: var(--surface);
  box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s; overflow: hidden;
}
.box:focus-within { border-color: rgba(11, 109, 97, .55); box-shadow: 0 0 0 3px rgba(11, 109, 97, .09), var(--shadow); }
.box__input {
  width: 100%; border: 0; outline: 0; resize: none; background: transparent; color: var(--ink);
  font: inherit; font-size: 14.8px; line-height: 1.5; padding: 14px 18px 6px; max-height: 168px;
}
.box__input::placeholder { color: var(--ink-3); }
.box__bar { display: flex; align-items: center; gap: 4px; padding: 4px 8px 8px 10px; }
.tool {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: var(--r-sm);
  font-size: 12.5px; color: var(--ink-2); transition: background .12s, color .12s;
}
.tool:hover { background: var(--surface-3); color: var(--ink); }
.tool svg { width: 15px; height: 15px; }
.send {
  margin-left: auto; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand); color: #fff; transition: background .14s, opacity .14s, transform .1s;
}
.send:hover { background: var(--brand-hi); }
.send:active { transform: scale(.94); }
.send:disabled { opacity: .32; cursor: default; background: var(--ink-3); }
.send svg { width: 16px; height: 16px; }
.legal { text-align: center; font-size: 11px; color: var(--ink-3); margin-top: 9px; }
.legal b { font-weight: 600; color: var(--ink-2); }

/* ---------- Document panel ---------- */
.doc {
  width: var(--doc-w); flex: 0 0 var(--doc-w); background: var(--surface);
  border-left: 1px solid var(--line); display: flex; flex-direction: column;
  margin-right: calc(var(--doc-w) * -1); opacity: 0; visibility: hidden;
  transition: margin-right .3s cubic-bezier(.4, 0, .2, 1), opacity .22s;
}
.app.doc-open .doc { margin-right: 0; opacity: 1; visibility: visible; }

.doc__head { flex: none; padding: 13px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.doc__ico { width: 34px; height: 34px; flex: none; border-radius: 9px; display: grid; place-items: center; background: var(--surface-3); color: var(--brand); }
.doc__ico svg { width: 17px; height: 17px; }
.doc__t { flex: 1; min-width: 0; }
.doc__title { font-size: 13.5px; font-weight: 600; letter-spacing: -.012em; line-height: 1.35; }
.doc__meta { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.doc__head .icon-btn { color: var(--ink-3); }
.doc__head .icon-btn:hover { background: var(--surface-3); color: var(--ink); }

.doc__nav { flex: none; display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); font-size: 12px; color: var(--ink-2); }
.doc__nav .icon-btn { width: 24px; height: 24px; color: var(--ink-2); }
.doc__nav .icon-btn:hover { background: var(--surface-3); }
.doc__nav .icon-btn svg { width: 14px; height: 14px; }
.doc__nav-grow { flex: 1; }

.doc__page { flex: 1; overflow-y: auto; padding: 20px; }
.page {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 26px 26px 30px; box-shadow: var(--shadow-sm); font-size: 12.5px; line-height: 1.72; color: var(--ink-2);
}
[data-theme="dark"] .page { background: var(--surface-2); }
.page__crumb { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); border-bottom: 1px solid var(--line-soft); padding-bottom: 9px; margin-bottom: 16px; display: flex; justify-content: space-between; }
.page h3 { font-size: 14px; color: var(--ink); margin: 0 0 12px; font-weight: 700; letter-spacing: -.012em; }
.page h4 { font-size: 12.5px; color: var(--ink); margin: 18px 0 7px; font-weight: 600; }
.page p { margin: 0 0 11px; }
.page ul { margin: 0 0 11px; padding-left: 17px; }
.page li { margin-bottom: 4px; }
.page table { width: 100%; border-collapse: collapse; margin: 0 0 12px; font-size: 11.5px; }
.page th, .page td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; }
.page th { background: var(--surface-3); font-weight: 600; color: var(--ink); }
.page__foot { margin-top: 20px; padding-top: 10px; border-top: 1px solid var(--line-soft); font-size: 10px; color: var(--ink-3); display: flex; justify-content: space-between; }

mark.hl {
  background: linear-gradient(180deg, rgba(25, 195, 175, .0) 52%, rgba(25, 195, 175, .32) 52%);
  color: var(--ink); padding: 1px 2px; border-radius: 2px; box-decoration-break: clone; -webkit-box-decoration-break: clone;
  animation: hlin .7s ease both;
}
@keyframes hlin { from { background-size: 0 100%; } to { background-size: 100% 100%; } }
mark.hl { background-repeat: no-repeat; background-size: 100% 100%; }
.hl-ring { position: relative; }
.hl-ring::before {
  content: ""; position: absolute; left: -14px; right: -14px; top: -8px; bottom: -8px;
  border: 1.5px dashed rgba(11, 109, 97, .38); border-radius: var(--r-sm); background: rgba(25, 195, 175, .05); pointer-events: none;
}

.doc__foot { flex: none; padding: 11px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.btn {
  flex: 1; padding: 8px 12px; border-radius: var(--r-sm); font-size: 12.5px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); transition: all .14s;
}
.btn:hover { background: var(--surface-2); color: var(--ink); border-color: var(--ink-3); }
.btn svg { width: 14px; height: 14px; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-hi); border-color: var(--brand-hi); color: #fff; }

/* ---------- Demo control ---------- */
.demo-fab {
  position: fixed; right: 16px; bottom: 16px; z-index: 60;
  width: 38px; height: 38px; border-radius: 50%; background: var(--brand-navy); color: #fff;
  display: grid; place-items: center; box-shadow: var(--shadow-lg); opacity: .55; transition: opacity .16s, transform .16s;
}
.demo-fab:hover { opacity: 1; transform: rotate(45deg); }
.demo-fab svg { width: 17px; height: 17px; }
.app.doc-open ~ .demo-fab { right: calc(var(--doc-w) + 16px); }

.demo {
  position: fixed; right: 16px; bottom: 16px; z-index: 61; width: 300px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); padding: 14px; display: none; animation: rise .2s ease both;
}
.demo.is-open { display: block; }
.demo__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.demo__title { font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.demo__head .icon-btn { color: var(--ink-3); }
.demo__head .icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.demo__label { font-size: 11.5px; font-weight: 600; color: var(--ink-2); margin: 12px 0 6px; }
.demo__label:first-of-type { margin-top: 0; }
.seg { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 3px; }
.seg button { flex: 1; padding: 5px 8px; border-radius: 5px; font-size: 11.5px; font-weight: 600; color: var(--ink-2); transition: all .12s; }
.seg button:hover { color: var(--ink); }
.seg button.is-on { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-sm); font-weight: 600; }
.demo__scen { display: grid; gap: 5px; }
.scen {
  display: flex; gap: 9px; align-items: center; padding: 8px 10px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface); text-align: left; transition: all .14s;
}
.scen:hover { border-color: rgba(11, 109, 97, .4); background: var(--surface-2); }
.scen.is-on { border-color: var(--brand); background: var(--surface-3); }
.scen__ico { width: 24px; height: 24px; flex: none; border-radius: 7px; display: grid; place-items: center; background: var(--surface-3); color: var(--brand); }
.scen.is-on .scen__ico { background: var(--brand); color: #fff; }
.scen__ico svg { width: 13px; height: 13px; }
.scen__n { font-size: 12.5px; font-weight: 600; letter-spacing: -.01em; }
.scen__m { font-size: 11px; color: var(--ink-3); }
.demo__hint { font-size: 10.5px; color: var(--ink-3); margin-top: 12px; line-height: 1.5; border-top: 1px solid var(--line-soft); padding-top: 10px; }
kbd { font: inherit; font-size: 10px; font-weight: 600; padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: var(--surface-2); color: var(--ink-2); }

/* ---------- KB dropdown ---------- */
.kbmenu {
  position: absolute; z-index: 70; width: 268px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow-lg); padding: 5px; display: none; animation: rise .16s ease both;
}
.kbmenu.is-open { display: block; }
.kbmenu__t { font-size: 10.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-3); padding: 8px 10px 6px; }
.kbitem { width: 100%; display: flex; gap: 9px; align-items: center; padding: 8px 10px; border-radius: var(--r-sm); text-align: left; transition: background .12s; }
.kbitem:hover { background: var(--surface-2); }
.kbitem__ico { width: 26px; height: 26px; flex: none; border-radius: 7px; display: grid; place-items: center; background: var(--surface-3); color: var(--brand); }
.kbitem__ico svg { width: 14px; height: 14px; }
.kbitem__n { font-size: 13px; font-weight: 600; letter-spacing: -.01em; }
.kbitem__m { font-size: 11px; color: var(--ink-3); }
.kbitem__check { margin-left: auto; color: var(--brand); opacity: 0; }
.kbitem.is-on .kbitem__check { opacity: 1; }
.kbitem__check svg { width: 15px; height: 15px; display: block; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 12px); z-index: 80;
  background: var(--brand-navy); color: #fff; font-size: 12.5px; font-weight: 500;
  padding: 9px 16px; border-radius: 999px; box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) { :root { --doc-w: 380px; } }
@media (max-width: 1000px) {
  .nav { position: absolute; z-index: 50; height: 100%; }
  .app.nav-open .nav { box-shadow: var(--shadow-lg); }
  .app .nav { margin-left: calc(var(--sidebar-w) * -1); }
  .app.nav-open .nav { margin-left: 0; }
  .doc { position: absolute; right: 0; height: 100%; z-index: 40; }
  .sources__list, .cards { grid-template-columns: 1fr; }

  /* Click catcher behind the open sidebar: without it there is no way back on
     mobile except the menu button. */
  .app.nav-open::before {
    content: ""; position: absolute; inset: 0; z-index: 45;
    background: rgba(15, 23, 42, .45);
  }
}

/* ---------- Autoplay: simulierter Mauszeiger ---------- */
.cursor {
  position: fixed; left: 0; top: 0; z-index: 200; width: 22px; height: 22px;
  pointer-events: none; opacity: 0; margin: -3px 0 0 -3px;
  transition: opacity .35s ease, transform .78s cubic-bezier(.35, .05, .2, 1);
  filter: drop-shadow(0 2px 4px rgba(15, 23, 42, .35));
}
.cursor.is-on { opacity: 1; }
.cursor svg { display: block; }
.cursor__ring {
  position: absolute; left: 50%; top: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border-radius: 50%; border: 2px solid var(--brand); opacity: 0;
}
.cursor.is-click .cursor__ring { animation: ripple .55s cubic-bezier(.2, .7, .3, 1); }
@keyframes ripple {
  0%   { transform: scale(.3); opacity: .9; }
  100% { transform: scale(1.5); opacity: 0; }
}
body.is-autoplay .thread { scroll-behavior: auto; }
body.is-autoplay .demo-fab,
body.is-autoplay .demo,
body.no-controls .demo-fab,
body.no-controls .demo { display: none !important; }

/* In playback the interface is a moving picture, not a control panel.
   Without this the visitor competes with the simulated pointer: a stray
   click opens a document that the playback closes again right away.
   Programmatic clicks from the sequence are unaffected. */
body.is-autoplay .app {
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

/* The way back belongs to the page, not to the playback: embedded, the home
   page hides it anyway; opened directly it stays usable. */
body.is-embedded .demo-banner { display: none; }
body.is-autoplay ::-webkit-scrollbar { width: 0; height: 0; }

/* ---------- Reduced motion ----------
   Answers then appear at once instead of word by word, autoplay does not
   start at all (see demo.js). No loss of content — only the way there is
   dropped. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }

  .thread,
  body.is-autoplay .thread { scroll-behavior: auto; }
  .caret,
  .cursor { display: none !important; }
}

/* ---------- Header of the standalone page ----------
   Names the context before the first answer and leads back to the website.
   Dropped in embedded autoplay: the section caption carries the hint there. */
.demo-banner {
  flex: none; display: flex; align-items: center; gap: 16px;
  height: 52px; padding: 0 18px;
  background: var(--nav-bg); color: var(--nav-ink);
  border-bottom: 1px solid rgba(0, 0, 0, .25);
}
.demo-banner__home {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  padding: 6px 10px 6px 6px; margin-left: -6px; border-radius: var(--r-sm);
  color: var(--nav-ink); text-decoration: none; font-size: 12.5px; font-weight: 600;
  transition: background .14s;
}
.demo-banner__home:hover { background: var(--nav-hover); }
.demo-banner__home svg { width: 16px; height: 16px; flex: none; }
.demo-banner__note {
  flex: 1; min-width: 0; margin: 0; display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--nav-ink-dim);
}
.demo-banner__note svg { width: 15px; height: 15px; flex: none; }
.demo-banner__cta {
  flex: none; padding: 7px 14px; border-radius: var(--r-sm);
  background: var(--brand); color: #fff; text-decoration: none;
  font-size: 12.5px; font-weight: 600; transition: background .14s;
}
.demo-banner__cta:hover { background: var(--brand-hi); }


@media (max-width: 640px) {
  .demo-banner { gap: 10px; padding: 0 12px; }
  .demo-banner__note { font-size: 11.5px; }
  .demo-banner__note svg { display: none; }
}

/* ---------- Phone widths ----------
   The interface stays the same, only cut narrower: the welcome area shrinks
   to what fits above the input, and the header may wrap. */
@media (max-width: 767px) {
  .demo-banner {
    height: auto; min-height: 52px; flex-wrap: wrap; gap: 8px 10px; padding: 8px 12px;
  }
  .demo-banner__note { flex-basis: 100%; order: 3; font-size: 11px; line-height: 1.35; }
  .demo-banner__cta { margin-left: auto; padding: 6px 12px; font-size: 12px; }

  .topbar { height: 52px; padding: 0 10px; gap: 6px; }
  .topbar .pill--local,
  .topbar__actions .icon-btn { display: none; }

  .thread__inner { padding: 18px 14px 8px; }
  .hero { padding: 3vh 14px 16px; }
  .hero__logo { height: 34px; margin-bottom: 14px; }
  .hero__title { font-size: 21px; margin-bottom: 6px; }
  .hero__sub { font-size: 13.5px; margin-bottom: 16px; }
  .hero__kb { display: none; }          /* lives in the sidebar */
  .card { padding: 11px 13px; }
  .card__q { font-size: 13px; }
  .card__tag { display: none; }

  .msg--user .bubble { max-width: 92%; font-size: 14px; }
  .answer { font-size: 14.5px; }
  .answer table { font-size: 12.5px; }
  .answer th, .answer td { padding: 6px 8px; }

  .composer { padding: 4px 14px 12px; }
  .box__input { font-size: 16px; }      /* below 16px iOS zooms on focus */
  .legal { font-size: 10px; }

  .doc { width: 100%; flex-basis: 100%; margin-right: -100%; }
  .app.doc-open .doc { margin-right: 0; }
}

/* Very narrow: the way back makes do with the arrow, the label would
   otherwise take the hint's space. */
@media (max-width: 420px) {
  .demo-banner__home { font-size: 0; gap: 0; padding: 6px; }
  .demo-banner__home svg { width: 18px; height: 18px; }
}


/* ---------- Justified text for nested spans ---------- */
.kb__name, .kb__meta, .card__q, .card__tag, .src__title,
.kbitem__n, .kbitem__m, .scen__n, .scen__m { display: block; }
.card > span:last-child,
.src__body,
.kbitem > span:nth-child(2),
.scen > span:nth-child(2) { display: block; min-width: 0; flex: 1; }
.card { text-align: left; }

/* Fallback: embedded icons without their own size */
.answer svg:not([class]), .sources svg:not([class]) { width: 13px; height: 13px; }
