/* Marginalia – Web-UI. Palette: Papier/Tinte/Bernstein, hell und dunkel. */
:root {
  --paper: #EEF0E9; --surface: #F8F9F4; --ink: #1B211C; --ink-soft: #4C5A4E; --line: #D7DBCE;
  --accent: #A6690A; --accent-strong: #8C5606; --teal: #1F6F63; --teal-soft: rgba(31,111,99,.12);
  --danger: #A3401F; --shadow: rgba(27,33,28,.12);
  --on-accent: #fff; --sheet: #FFFDF7; --sheet-edge: #E6E2D4; --sheet-shadow: rgba(66,52,24,.26); --glow: #F8F6EE; --glow-edge: #E9EBE2;
  --line-soft: #E4E8DB; --hover: #E5E9DE; --current: #E1E6D9; --veil: rgba(27,33,28,.32); --danger-soft: rgba(163,64,31,.1);
  --hl-yellow: rgba(240,190,60,.45); --hl-green: rgba(120,190,90,.45); --hl-blue: rgba(90,160,230,.40);
  --hl-pink: rgba(240,120,160,.40); --hl-purple: rgba(170,120,230,.40); --hl-orange: rgba(245,150,60,.45);
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-read: Charter, "Iowan Old Style", Georgia, "Times New Roman", serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14170F; --surface: #1B201A; --ink: #E8EAE0; --ink-soft: #A5AE9B; --line: #2B3125;
    --accent: #EDBB55; --accent-strong: #F2C670; --teal: #59B8A7; --teal-soft: rgba(89,184,167,.16);
    --danger: #E08A66; --shadow: rgba(0,0,0,.4);
    --on-accent: #14170F; --sheet: #22261D; --sheet-edge: #343A2C; --sheet-shadow: rgba(0,0,0,.55); --glow: #1D2118; --glow-edge: #10130C;
    --line-soft: #242A20; --hover: #20261D; --current: #262C22; --veil: rgba(0,0,0,.5); --danger-soft: rgba(224,138,102,.14);
    --hl-yellow: rgba(237,187,85,.38); --hl-green: rgba(120,190,90,.35); --hl-blue: rgba(90,160,230,.35);
    --hl-pink: rgba(240,120,160,.35); --hl-purple: rgba(170,120,230,.35); --hl-orange: rgba(245,150,60,.38);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.5 var(--font-ui); }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h2 { font-size: 1.1rem; }
code, kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 0 .3em; }
.muted { color: var(--ink-soft); }
.small { font-size: .85em; }
.count { font-size: .75em; color: var(--ink-soft); background: var(--teal-soft); border-radius: 100px; padding: 1px 7px; vertical-align: middle; }
.pill { font-size: .75em; text-transform: uppercase; letter-spacing: .05em; color: var(--teal); }

/* Topbar */
.topbar { display: flex; align-items: center; gap: 18px; padding: 10px clamp(12px, 3vw, 32px); border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.brand { font-family: var(--font-read); font-weight: 700; font-size: 1.25rem; color: var(--ink); letter-spacing: .01em; }
.brand-sub { font-weight: 400; color: var(--teal); }
.mainnav { display: flex; gap: 4px; flex-wrap: wrap; }
.mainnav a { color: var(--ink-soft); padding: 6px 10px; border-radius: 6px; }
.mainnav a:hover { background: var(--paper); text-decoration: none; }
.mainnav a.active { color: var(--ink); background: var(--paper); font-weight: 600; }
.searchform { margin-left: auto; }
.searchform input { width: min(260px, 40vw); }
.iconlink { color: var(--ink-soft); font-size: 1.2rem; }
.iconlink.active { color: var(--ink); }

/* Layout */
.container { max-width: 980px; margin: 0 auto; padding: 24px clamp(12px, 3vw, 32px) 80px; }
.narrow { max-width: 720px; margin: 0 auto; }
.pagehead { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 24px 0 12px; }
.pagetitle { font-family: var(--font-read); font-size: 1.6rem; margin: 0; }
.pagetitle small { font-size: .6em; font-weight: 400; }
.empty { color: var(--ink-soft); padding: 40px 0; text-align: center; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.flash { padding: 10px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
.flash.error { border-color: var(--danger); color: var(--danger); }
.flash.ok { border-color: var(--teal); }
.flash.warn { border-color: var(--accent); }
.pager { display: flex; justify-content: space-between; margin-top: 20px; }

/* Formulare */
input[type=text], input[type=url], input[type=search], input[type=password], input[type=number], textarea, select {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input[type=file] { font: inherit; color: var(--ink-soft); }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .9em; color: var(--ink-soft); }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--teal); outline-offset: 1px; border-color: transparent; }
.btn { font: inherit; font-size: .9em; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; white-space: nowrap; display: inline-block; }
.btn:hover { border-color: var(--ink-soft); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.tiny { font-size: .8em; padding: 4px 9px; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.active { background: var(--teal-soft); border-color: var(--teal); }
.btn[disabled] { cursor: default; }
form { margin: 0; }

/* Karten (Quellen im Review) */
.chip { font-size: .8em; padding: 3px 10px; border-radius: 100px; border: 1px solid var(--line); color: var(--ink-soft); background: var(--surface); }
.chip.active { border-color: var(--teal); color: var(--teal); }
.chip.small { padding: 1px 8px; font-size: .75em; }
button.chip { font-family: inherit; cursor: pointer; }
.chip:hover { text-decoration: none; border-color: var(--ink-soft); }
.cards { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.card.doc { display: flex; gap: 16px; justify-content: space-between; align-items: flex-start; }
.card-main { min-width: 0; flex: 1; }
.card-title { font-family: var(--font-read); font-size: 1.15rem; font-weight: 600; color: var(--ink); display: block; }
.card-meta { margin: 4px 0 0; font-size: .82em; color: var(--ink-soft); display: flex; gap: 4px 12px; flex-wrap: wrap; }
.card-meta a { color: var(--ink); font-weight: 600; }
.card-tags { margin: 6px 0 0; display: flex; gap: 4px; flex-wrap: wrap; }
.card-actions { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
.table { width: 100%; border-collapse: collapse; font-size: .9em; margin-bottom: 10px; }
.table th, .table td { text-align: left; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line); }
.token { display: inline-block; padding: 6px 10px; font-size: 1em; user-select: all; }

/* Highlight-Karten */
.card.hl { border-left: 4px solid var(--hl-yellow); }
.card.hl.color-green, .review-card.color-green { border-left-color: var(--hl-green); }
.card.hl.color-blue, .review-card.color-blue { border-left-color: var(--hl-blue); }
.card.hl.color-pink, .review-card.color-pink { border-left-color: var(--hl-pink); }
.card.hl.color-purple, .review-card.color-purple { border-left-color: var(--hl-purple); }
.card.hl.color-orange, .review-card.color-orange { border-left-color: var(--hl-orange); }
.hl-text { margin: 0; font-family: var(--font-read); font-size: 1.05rem; line-height: 1.55; }
.hl-note { margin: 8px 0 0; padding-left: 10px; border-left: 2px solid var(--teal); color: var(--ink-soft); font-size: .95em; white-space: pre-wrap; }
.hl-edit { margin-top: 8px; font-size: .85em; color: var(--ink-soft); }
.hl-edit summary { cursor: pointer; }
.noteform { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.noteform select { width: auto; }
.source-edit { margin: -4px 0 16px; }
.source-edit summary { cursor: pointer; }
.source-edit .form { margin-top: 8px; }

/* Daily Review – der Stapel: ein Highlight nach dem anderen, wie Karteikarten unter der Leselampe */
body.page-review { background: radial-gradient(130% 80% at 50% 0%, var(--glow) 0%, var(--glow-edge) 100%) fixed; min-height: 100vh; }
.review-page { max-width: 42rem; margin: 0 auto; padding: 8px clamp(16px, 4vw, 24px) 64px; }
.linkbutton { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.linkbutton:hover { text-decoration: underline; }

.stack-step { display: flex; flex-direction: column; align-items: center; padding-top: 28px; }
@media (prefers-reduced-motion: no-preference) { .stack-step { animation: stack-in .5s ease-out; } }
@keyframes stack-in { from { opacity: 0; transform: translateY(8px); } }

.stack-head { text-align: center; margin-bottom: 36px; }
.stack-date { margin: 0; font-family: var(--font-read); font-style: italic; font-size: 1.1rem; color: var(--ink-soft); }
.stack-progress { display: flex; align-items: center; justify-content: center; gap: 11px; margin: 8px 0 0; font-size: .8rem; color: var(--ink-soft); }
.stack-dots { display: flex; gap: 5px; align-items: center; }
.stack-dot { width: 6px; height: 6px; border-radius: 3px; background: var(--ink-soft); opacity: .25; }
.stack-dot.is-done { opacity: .6; }
.stack-dot.is-here { width: 20px; background: var(--accent); opacity: 1; }

/* Die Karten darunter: leicht verrutscht, nur so viele, wie noch kommen */
.stack-pile { position: relative; width: 100%; }
.stack-pile::before, .stack-pile::after { content: ""; position: absolute; inset: 0; display: none; background: var(--sheet); border: 1px solid var(--sheet-edge); border-radius: 14px; }
.stack-pile::after { transform: translateY(11px) rotate(.8deg) scale(.975); }
.stack-pile::before { transform: translateY(21px) rotate(-1deg) scale(.95); opacity: .7; }
.stack-pile--1::after, .stack-pile--2::after, .stack-pile--2::before { display: block; }

.stack-card { position: relative; z-index: 1; width: 100%; background: var(--sheet); border: 1px solid var(--sheet-edge); border-radius: 14px;
  padding: clamp(26px, 6vw, 42px) clamp(20px, 6vw, 44px) 20px; box-shadow: 0 1px 2px var(--sheet-shadow), 0 22px 44px -28px var(--sheet-shadow); }
.stack-card:focus { outline: none; }
/* Farbige Highlights (z. B. Favoriten) tragen ein Lesebändchen; Gelb ist der Normalfall und bleibt ohne */
.stack-ribbon { position: absolute; top: -1px; right: clamp(20px, 6vw, 44px); width: 13px; height: 34px; opacity: .85; clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%); }
.stack-ribbon.color-green { background: #78BE5A; } .stack-ribbon.color-blue { background: #5AA0E6; } .stack-ribbon.color-pink { background: #F078A0; }
.stack-ribbon.color-purple { background: #AA78E6; } .stack-ribbon.color-orange { background: #F5963C; }

.stack-text { margin: 0; font-family: var(--font-read); font-size: clamp(1.4rem, 4.6vw, 1.8rem); line-height: 1.45; white-space: pre-wrap;
  overflow-wrap: anywhere; text-wrap: pretty; hanging-punctuation: first; transition: opacity .3s ease; }
.stack-text--medium { font-size: clamp(1.2rem, 3.6vw, 1.4rem); line-height: 1.55; }
.stack-text--long { font-size: 1.1rem; line-height: 1.65; }
.stack-note { margin: 18px 0 0; padding-left: 12px; border-left: 2px solid var(--accent); font-family: var(--font-read); font-style: italic; color: var(--ink-soft); white-space: pre-wrap; transition: opacity .3s ease; }
.stack-source { margin: 16px 0 0; font-family: var(--font-read); font-style: italic; color: var(--ink-soft); overflow-wrap: anywhere; transition: opacity .3s ease; }
.stack-source::before { content: "— "; }
.stack-source a { color: inherit; }

.stack-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; margin-top: 30px; padding-top: 14px; border-top: 1px solid var(--sheet-edge); font-size: .85rem; color: var(--ink-soft); }
.stack-aside { flex-basis: 100%; order: 1; font-style: italic; }
.stack-actions { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; margin-left: auto; }
.stack-actions a, .stack-actions .linkbutton { color: var(--ink-soft); }
.stack-actions a:hover, .stack-actions .linkbutton:hover { color: var(--ink); }
.stack-exclude, .stack-card.is-excluded .stack-include { display: inline; }
.stack-include, .stack-card.is-excluded .stack-exclude { display: none; }
.stack-card.is-excluded :is(.stack-text, .stack-note, .stack-source) { opacity: .4; }

/* Erinnern: Lücke im Text, Notiz erst nach dem Aufdecken (sie verrät oft das Wort) */
.cloze { border-bottom: 2px solid var(--accent); }
.stack-card.is-cloze:has(.stack-recall:not([open])) .cloze-word { visibility: hidden; }
.stack-card.is-cloze:has(.stack-recall:not([open])) .stack-note { display: none; }
.stack-reveal { display: block; width: fit-content; margin: 28px auto 0; padding: 9px 28px; border: 1px solid var(--line); border-radius: 999px;
  color: var(--ink); cursor: pointer; list-style: none; user-select: none; }
.stack-reveal::-webkit-details-marker { display: none; }
.stack-reveal:hover { border-color: var(--ink-soft); }
.stack-recall[open] > .stack-reveal, .stack-recall[open] + .stack-hint { display: none; }
.stack-hint { margin: 8px 0 0; text-align: center; font-size: .8rem; color: var(--ink-soft); }

/* Bald · Später · Irgendwann */
.stack-rate { margin-top: 28px; text-align: center; }
.stack-rate-ask { margin: 0 0 10px; font-size: .85rem; color: var(--ink-soft); }
.stack-choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.stack-choice { font: inherit; display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 7.2rem; padding: 8px 16px;
  border: 1px solid var(--line); border-radius: 12px; background: transparent; color: var(--ink); cursor: pointer; }
.stack-choice:hover { border-color: var(--ink-soft); }
.stack-choice-when { font-size: .75rem; color: var(--ink-soft); }
.stack-choice.is-chosen { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.stack-choice.is-chosen .stack-choice-when { color: inherit; opacity: .85; }
:is(.stack-reveal, .stack-choice):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.stack-rated { margin: 10px 0 0; font-family: var(--font-read); font-style: italic; font-size: .9rem; color: var(--ink-soft); }
.stack-rated:empty { display: none; }

/* Weiter steht immer in der Mitte, Zurück daneben – auf jeder Karte an derselben Stelle */
.stack-nav { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 20px; width: 100%; margin-top: 44px; }
.stack-nav .stack-back { justify-self: end; }
.stack-nav .stack-next { grid-column: 2; }
.stack-next { padding: 10px 30px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-weight: 600; }
.stack-next:hover { background: var(--accent-strong); color: var(--on-accent); text-decoration: none; }
.stack-back { padding: 10px 3px; color: var(--ink-soft); }
.stack-back:hover { color: var(--ink); text-decoration: none; }
.stack-keys { margin: 22px 0 0; text-align: center; font-size: .78rem; color: var(--ink-soft); opacity: .8; }
@media (hover: none) { .stack-keys { display: none; } }

/* Abschluss und leerer Stapel: dieselbe Karte, nur stiller */
.stack-card--quiet { text-align: center; padding: 38px clamp(20px, 6vw, 44px); }
.stack-card--quiet p { margin: 0 0 6px; }
.stack-card--quiet p:last-child { margin-bottom: 0; }
.stack-line { font-family: var(--font-read); font-size: 1.6rem; line-height: 1.3; }
.stack-card--quiet .stack-line { margin-bottom: 11px; }
.stack-links { margin: 28px 0 0; text-align: center; font-size: .9rem; color: var(--ink-soft); }

/* Reader */
.reader-page { max-width: 1240px; margin: 0 auto; padding: 24px clamp(12px, 3vw, 32px) 120px; }
.reader-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 40px; align-items: start; }
.reader { max-width: 720px; }
.doc-head { margin-bottom: 28px; }
.doc-head h1 { font-family: var(--font-read); font-size: clamp(1.6rem, 3.4vw, 2.3rem); font-weight: 600; margin: 8px 0 6px; }
.doc-head .author { margin: 0; color: var(--ink-soft); font-size: 1.05em; }
.doc-links { margin: 6px 0 0; font-size: .9em; display: flex; gap: 14px; }
.prose { font-family: var(--font-read); font-size: 1.15rem; line-height: 1.7; }
.prose p { margin: 0 0 1.1em; }
.prose h2, .prose h3, .prose h4 { font-family: var(--font-read); margin: 1.6em 0 .5em; }
.prose h2 { font-size: 1.45em; } .prose h3 { font-size: 1.2em; } .prose h4 { font-size: 1.05em; }
.prose img { max-width: 100%; height: auto; border-radius: 6px; display: block; margin: 1em auto; }
.prose figure { margin: 1.4em 0; } .prose figcaption { font-size: .85em; color: var(--ink-soft); text-align: center; }
.prose blockquote { margin: 1.2em 0; padding: 2px 0 2px 18px; border-left: 3px solid var(--line); color: var(--ink-soft); }
.prose pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8em; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; overflow-x: auto; line-height: 1.5; }
.prose code { font-size: .85em; }
.prose pre code { background: none; border: 0; padding: 0; font-size: 1em; }
.prose table { border-collapse: collapse; font-size: .9em; margin: 1em 0; display: block; overflow-x: auto; }
.prose td, .prose th { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin-bottom: .3em; }
.prose a { text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.prose .page { position: relative; }
.prose .page + .page { border-top: 1px dashed var(--line); margin-top: 1.5em; padding-top: 1.5em; }
.prose .page-marker { position: absolute; right: 100%; margin-right: 14px; top: 1.5em; font-family: var(--font-ui); font-size: .7rem; color: var(--ink-soft); user-select: none; }
.prose .chapter + .chapter { margin-top: 3em; }
.empty-doc { font-family: var(--font-ui); font-size: 1rem; }
.hint { margin-top: 30px; }
mark.hl { background: var(--hl-yellow); color: inherit; border-radius: 2px; padding: .05em 0; cursor: pointer; }
mark.hl.hl-green { background: var(--hl-green); } mark.hl.hl-blue { background: var(--hl-blue); }
mark.hl.hl-pink { background: var(--hl-pink); } mark.hl.hl-purple { background: var(--hl-purple); } mark.hl.hl-orange { background: var(--hl-orange); }
mark.hl.flash { outline: 2px solid var(--teal); }

.reader-side { position: sticky; top: 70px; display: flex; flex-direction: column; gap: 16px; max-height: calc(100vh - 90px); overflow-y: auto; }
.side-block { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: .9em; }
.side-block h2 { font-size: .95rem; margin-bottom: 8px; }
.side-links { margin: 8px 0 0; font-size: .85em; }
.hl-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.hl-item { padding: 6px 8px 6px 10px; border-left: 3px solid var(--hl-yellow); background: var(--paper); border-radius: 0 6px 6px 0; cursor: pointer; font-size: .85em; }
.hl-item.color-green { border-left-color: var(--hl-green); } .hl-item.color-blue { border-left-color: var(--hl-blue); }
.hl-item.color-pink { border-left-color: var(--hl-pink); } .hl-item.color-purple { border-left-color: var(--hl-purple); } .hl-item.color-orange { border-left-color: var(--hl-orange); }
.hl-item-note { display: block; color: var(--ink-soft); margin-top: 3px; font-style: italic; }
.hl-item:hover { background: var(--teal-soft); }

/* Highlight-Toolbar & Panel */
.hl-toolbar { position: absolute; z-index: 30; display: flex; gap: 6px; padding: 6px 8px; background: var(--ink); border-radius: 100px; box-shadow: 0 4px 16px var(--shadow); }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch-yellow { background: #F0BE3C; } .swatch-green { background: #78BE5A; } .swatch-blue { background: #5AA0E6; }
.swatch-pink { background: #F078A0; } .swatch-purple { background: #AA78E6; } .swatch-orange { background: #F5963C; }
.swatch.active, .swatch:hover { border-color: #fff; }
.hl-panel .swatch.active { border-color: var(--ink); }
.swatches { display: flex; gap: 4px; margin-right: auto; }
.hl-panel { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); width: min(640px, calc(100vw - 24px)); z-index: 40; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: 0 10px 30px var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.hl-panel blockquote { margin: 0; font-family: var(--font-read); color: var(--ink-soft); max-height: 5.5em; overflow: auto; font-size: .95em; border-left: 3px solid var(--line); padding-left: 10px; }

/* Reader-Rahmen: Seitenleiste links, Liste rechts (Bibliothek, Suche, Einstellungen) */
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.sep { color: var(--line); }
.shell { display: grid; grid-template-columns: 244px minmax(0, 1fr); min-height: 100vh; }
.side { display: flex; flex-direction: column; gap: 22px; padding: 22px 16px 18px; border-right: 1px solid var(--line);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side-brand { padding: 0 8px; }
.side-brand .brand { font-size: 1.2rem; display: block; }
.side-brand .brand:hover { text-decoration: none; }
.side-status { display: block; font-size: .76rem; color: var(--ink-soft); margin-top: 2px; }
.side-status:hover { color: var(--ink); }
.side-add { display: flex; align-items: center; justify-content: space-between; gap: 8px; font: inherit; font-size: .92em; font-weight: 600;
  text-align: left; padding: 9px 10px 9px 12px; border: 1px solid var(--accent); border-radius: 10px; background: var(--accent); color: var(--on-accent); cursor: pointer; }
.side-add:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.side-add kbd { font-size: .8em; font-weight: 500; line-height: 1; color: inherit; background: rgba(255,255,255,.2); border: 0; padding: 3px 5px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a, .side-foot a, .side-help { display: flex; align-items: center; gap: 8px; font: inherit; text-align: left; color: var(--ink-soft);
  background: none; border: 0; padding: 7px 12px; border-radius: 8px; cursor: pointer; }
.side-nav a { font-size: .95em; }
.side-nav a:hover, .side-foot a:hover, .side-help:hover { background: var(--hover); color: var(--ink); text-decoration: none; }
.side-nav a.active, .side-foot a.active { background: var(--current); color: var(--ink); font-weight: 600; }
.side-count { margin-left: auto; font-size: .78em; color: var(--ink-soft); font-weight: 400; font-variant-numeric: tabular-nums; }
.side-count.is-zero { opacity: .45; }
.side-tags { display: flex; flex-direction: column; gap: 8px; }
.side-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-soft); padding: 0 12px; }
.side-tag-list { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 10px; }
.tagchip { font-size: .78em; padding: 3px 10px; border-radius: 100px; border: 1px solid var(--line); color: var(--ink-soft); white-space: nowrap; }
.tagchip:hover { border-color: var(--teal); color: var(--teal); text-decoration: none; }
.tagchip.active { border-color: var(--teal); color: var(--teal); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; font-size: .9em; }
.side-help { font-size: 1em; }

.main { min-width: 0; background: var(--surface); }
.mainhead { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px; padding: 18px 32px 14px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line-soft); }
.mainhead-text { min-width: 0; }
.mainhead h1 { font-family: var(--font-read); font-size: 1.55rem; font-weight: 600; line-height: 1.2; margin: 0; }
.mainhead p { margin: 2px 0 0; font-size: .82em; color: var(--ink-soft); }
.mainhead p:empty { display: none; }
.headsearch { margin-left: auto; position: relative; display: flex; align-items: center; }
.headsearch-icon { position: absolute; left: 11px; color: var(--ink-soft); font-size: .9em; pointer-events: none; }
.headsearch input[type=search] { font-size: .92em; background: var(--paper); border-radius: 9px; padding: 8px 34px 8px 28px; width: min(300px, 34vw); }
.headsearch kbd { position: absolute; right: 10px; font-size: .74em; font-weight: 500; line-height: 1; color: var(--ink-soft); background: var(--surface); padding: 3px 5px; pointer-events: none; }
.headsearch input:focus ~ kbd, .headsearch input:not(:placeholder-shown) ~ kbd { display: none; }
.main > .narrow { padding: 24px 32px 80px; margin: 0; }

/* Listenzeilen */
.doclist { max-width: 900px; padding: 8px 32px 80px; }
.doclist > .flash { margin: 16px 0 4px; }
.doc-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 24px; align-items: start; padding: 18px 4px 20px; border-bottom: 1px solid var(--line-soft); }
.doc-row.htmx-swapping { opacity: 0; transition: opacity .18s ease-out; }
.doc-title { font-family: var(--font-read); font-size: 1.2rem; font-weight: 600; line-height: 1.3; color: var(--ink); display: block; text-wrap: pretty; overflow-wrap: anywhere; }
.doc-title:hover { color: var(--accent); text-decoration: none; }
.doc-meta { margin: 5px 0 0; font-size: .82em; color: var(--ink-soft); display: flex; align-items: center; gap: 4px 10px; flex-wrap: wrap; }
.doc-badge { font-size: .86em; text-transform: uppercase; letter-spacing: .06em; color: var(--teal); background: var(--teal-soft); border-radius: 4px; padding: 1px 6px; }
.doc-tags { display: inline-flex; flex-wrap: wrap; gap: 0 8px; }
.doc-tags a { color: var(--ink-soft); opacity: .8; }
.doc-tags a:hover { color: var(--teal); opacity: 1; text-decoration: none; }
.doc-quote { margin: 10px 0 0; padding: 1px 0 1px 12px; border-left: 2px solid rgba(240,190,60,.75); font-family: var(--font-read); font-size: .98rem; line-height: 1.5; color: var(--ink-soft); text-wrap: pretty; }
.doc-hls { margin: 8px 0 0; font-size: .78em; color: var(--ink-soft); }
.doc-progress { display: flex; align-items: center; gap: 9px; margin-top: 12px; max-width: 260px; font-size: .74em; color: var(--ink-soft); }
.doc-progress-bar { flex: 1; height: 3px; background: var(--line-soft); border-radius: 3px; overflow: hidden; }
.doc-progress-bar div { height: 100%; background: var(--teal); }
.doc-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.ghost { font: inherit; font-size: .82em; padding: 4px 10px; border-radius: 7px; border: 1px solid transparent; background: none; color: var(--ink-soft); cursor: pointer; white-space: nowrap; }
.ghost:hover { background: var(--paper); color: var(--ink); }
.ghost.danger { color: var(--danger); }
.ghost.danger:hover { background: var(--danger-soft); color: var(--danger); }
.list-empty { max-width: 460px; margin: 14vh auto 0; text-align: center; color: var(--ink-soft); text-wrap: pretty; }
.list-empty p { margin: 10px 0 0; }
.list-empty .list-empty-title { margin: 0; font-family: var(--font-read); font-size: 1.5rem; line-height: 1.35; color: var(--ink); }
.list-empty-actions { margin-top: 22px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.list-empty .list-empty-hint { margin: 0; font-size: .82em; }
.pill-button { font: inherit; font-size: .92em; font-weight: 600; padding: 10px 22px; border-radius: 999px; border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); cursor: pointer; }
.pill-button:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.doclist .pager { margin-top: 24px; }

/* Suche */
.searchpage { max-width: 900px; padding: 16px 32px 80px; }
.filterbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.filterbar-link { margin-left: auto; font-size: .85em; }
.doc-row--hit { grid-template-columns: minmax(0, 1fr); }
.doc-snippet { margin: 9px 0 0; font-family: var(--font-read); font-size: 1rem; line-height: 1.55; color: var(--ink-soft); text-wrap: pretty; overflow-wrap: anywhere; }
.doc-snippet mark { background: var(--hl-yellow); color: inherit; border-radius: 2px; }
.search-none { padding: 60px 0; text-align: center; color: var(--ink-soft); }

/* Einstellungen */
.settingspage { max-width: 680px; padding: 24px 32px 80px; display: flex; flex-direction: column; gap: 14px; }
.sheet { background: var(--sheet); border: 1px solid var(--sheet-edge); border-radius: 14px; padding: 18px 20px; }
.sheet h2 { font-family: var(--font-read); font-size: 1.05rem; margin: 0; }
.sheet > h2 + * { margin-top: 14px; }
.sheet > p { margin: 10px 0 0; color: var(--ink-soft); font-size: .92em; text-wrap: pretty; }
.sheet > .flash { color: var(--ink); }
.sheet > .flash.error { color: var(--danger); }
.sheet .sheet-note { font-size: .82em; }
.sheet-head { display: flex; align-items: baseline; gap: 10px; }
.state-badge { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: .78em; white-space: nowrap; color: var(--teal); background: var(--teal-soft); border-radius: 100px; padding: 3px 9px; }
.state-badge.is-error { color: var(--danger); background: var(--danger-soft); }
.state-badge.is-off { color: var(--ink-soft); background: var(--paper); }
.sheet-foot { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--sheet-edge); font-size: .85em; color: var(--ink-soft); }
.sheet-foot .btn { margin-left: auto; }
.sheet code { background: var(--paper); }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat-value { font-family: var(--font-read); font-size: 1.5rem; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: .78em; color: var(--ink-soft); margin-top: 3px; }
.token-list { display: flex; flex-direction: column; }
.token-row { display: flex; align-items: center; gap: 4px 14px; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--sheet-edge); font-size: .9em; }
.token-label { font-weight: 600; }
.token-meta { color: var(--ink-soft); font-size: .9em; }
.token-row form { margin-left: auto; }
.token-row .ghost.danger:hover { background: none; border-color: var(--danger); }
.token-form { display: flex; gap: 8px; margin-top: 14px; }
.token-form input[type=text] { flex: 1; width: auto; min-width: 0; }
.btn.quiet { background: none; color: var(--ink-soft); }
.btn.quiet:hover { color: var(--ink); }

/* Dialoge: Hinzufügen, Tastenkürzel */
.sheet-dialog { border: 0; padding: 0; background: transparent; color: var(--ink); width: min(620px, calc(100% - 32px)); max-width: none; max-height: none;
  margin: 14vh auto auto; overflow: visible; outline: none; }
.sheet-dialog--small { width: min(420px, calc(100% - 32px)); margin: auto; }
.sheet-dialog::backdrop { background: var(--veil); }
.dialog-body { background: var(--sheet); border: 1px solid var(--sheet-edge); border-radius: 16px; box-shadow: 0 24px 60px -24px var(--sheet-shadow); padding: 20px; }
@media (prefers-reduced-motion: no-preference) {
  .sheet-dialog[open] .dialog-body { animation: sheet-in .2s ease-out; }
  .sheet-dialog[open]::backdrop { animation: veil-in .16s ease-out; }
}
@keyframes sheet-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes veil-in { from { opacity: 0; } }
.dialog-body h2 { font-family: var(--font-read); font-size: 1.15rem; margin: 0; }
.dialog-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.dialog-aside { margin-left: auto; font-size: .8em; color: var(--ink-soft); }
.dialog-aside strong { font-weight: 600; color: var(--ink); }
.dialog-body .add-url { font-size: 1.02em; border-radius: 10px; padding: 12px 14px; }
.add-row { display: flex; gap: 8px; margin-top: 8px; }
.add-row input[type=text] { flex: 1; width: auto; min-width: 0; border-radius: 10px; padding: 9px 12px; font-size: .92em; }
.add-row .btn.primary { font-size: .92em; padding: 9px 18px; border-radius: 10px; }
.dropzone { display: block; margin-top: 14px; padding: 16px; border: 1px dashed var(--line); border-radius: 12px; text-align: center; color: var(--ink-soft); font-size: .88em; cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.is-over { border-color: var(--teal); background: var(--teal-soft); }
.dropzone:focus-within { outline: 2px solid var(--teal); outline-offset: 1px; }
.dropzone.is-busy { cursor: progress; border-style: solid; }
.linklike { color: var(--accent); }
.dropzone:hover .linklike { text-decoration: underline; }
.dialog-keys { display: flex; align-items: center; gap: 10px; margin: 14px 0 0; font-size: .78em; color: var(--ink-soft); }
.dialog-keys kbd, .keys kbd, .list-empty kbd { background: var(--paper); }
.keys { margin: 12px 0 0; }
.keys-row { display: grid; grid-template-columns: 56px minmax(0, 1fr); align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--sheet-edge); font-size: .92em; }
.keys-row:last-child { border-bottom: 0; }
.keys kbd { display: inline-block; min-width: 28px; text-align: center; border-radius: 5px; padding: 2px 7px; font-size: .86em; }
.keys dd { margin: 0; color: var(--ink-soft); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; padding: 8px 16px; border-radius: 100px; background: var(--ink); color: var(--paper); font-size: .9em; box-shadow: 0 6px 20px var(--shadow); }

/* Leseansicht: schmale Leiste statt Seitenleiste */
.readbar { position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
  padding: 10px clamp(12px, 3vw, 32px); background: color-mix(in srgb, var(--paper) 92%, transparent); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.readbar-back { justify-self: start; color: var(--ink-soft); font-size: .92em; padding: 4px 10px 4px 6px; border-radius: 8px; }
.readbar-back:hover { background: var(--hover); color: var(--ink); text-decoration: none; }
.readbar-brand { font-size: 1.05rem; }
.readbar-brand:hover { text-decoration: none; }
.readbar-links { justify-self: end; display: flex; align-items: center; gap: 2px; }
.readbar-links a, .readbar-help { font: inherit; font-size: 1.05rem; line-height: 1; color: var(--ink-soft); background: none; border: 0; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.readbar-links a:hover, .readbar-help:hover { background: var(--hover); color: var(--ink); text-decoration: none; }

@media (hover: none) {
  .side-add kbd, .headsearch kbd, .dialog-keys, .side-help, .readbar-help, .list-empty-hint { display: none; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; overflow: visible; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px;
    padding: 14px 16px 10px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side-brand { flex: 1; padding: 0; min-width: 0; }
  .side-add { order: 1; padding: 8px 14px; }
  .side-add kbd { display: none; }
  .side-foot { order: 2; margin-top: 0; flex-direction: row; }
  .side-foot a, .side-help { padding: 7px 9px; }
  .side-foot-label { display: none; }
  .side-nav { order: 3; flex-direction: row; width: 100%; overflow-x: auto; margin: 0 -4px; }
  .side-nav a { flex: none; padding: 6px 12px; }
  .side-nav .side-count { margin-left: 4px; }
  .side-tags { order: 4; width: 100%; }
  .side-label { display: none; }
  .side-tag-list { flex-wrap: nowrap; overflow-x: auto; padding: 0 0 4px; }
  .mainhead { position: static; flex-wrap: wrap; gap: 12px; padding: 16px 16px 12px; }
  .headsearch { margin-left: 0; width: 100%; }
  .headsearch input[type=search] { width: 100%; }
  .doclist, .searchpage, .settingspage, .main > .narrow { padding-left: 16px; padding-right: 16px; }
  .doc-row { grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 16px 0 18px; }
  .doc-actions { flex-direction: row; flex-wrap: wrap; align-items: center; margin-left: -10px; }
  .list-empty { margin-top: 8vh; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 16px; }
  .sheet { padding: 16px; }
  .sheet-foot { flex-direction: column; align-items: flex-start; gap: 4px; }
  .sheet-foot .sep { display: none; }
  .sheet-foot .btn { margin: 8px 0 0; }
  .sheet-dialog { margin-top: 8vh; }
  .add-row { flex-wrap: wrap; }
  .readbar-brand { display: none; }
  .readbar { grid-template-columns: 1fr auto; }
}

/* Login */
body.login { display: grid; place-items: center; min-height: 100vh; }
.loginbox { width: min(400px, 90vw); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.loginbox h1 { font-family: var(--font-read); }
.loginbox form { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }

@media (max-width: 900px) {
  .reader-layout { grid-template-columns: 1fr; }
  .reader-side { position: static; max-height: none; }
  .prose .page-marker { position: static; display: block; margin: 0 0 4px; }
  .card.doc { flex-direction: column; }
  .card-actions { flex-direction: row; flex-wrap: wrap; }
  .searchform { order: 3; width: 100%; margin-left: 0; }
  .searchform input { width: 100%; }
}

/* Adminpanel: Messwerte, Balken, Kurven, Journal */
.adminpage { max-width: 940px; display: flex; flex-direction: column; gap: 14px; }
.main > .adminpage { padding: 24px 32px 80px; }         /* im Reader: die Seitenleiste bringt kein Polster mit */
.adminpage .pagehead { margin: 0; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px 18px; margin-top: 14px; }
.metric-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: .84em; color: var(--ink-soft); }
.metric-top b { font-size: 1.15rem; color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 600; }
.metric-note { margin: 5px 0 0; font-size: .76em; color: var(--ink-soft); }
.bar { height: 6px; margin-top: 6px; border-radius: 6px; background: var(--line-soft); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--teal); transition: width .4s ease-out; }
.bar > span.is-warm { background: var(--accent); }
.bar > span.is-hot { background: var(--danger); }
.curves { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px 18px; margin-top: 18px; }
.curve { margin: 0; color: var(--teal); }
.curve figcaption { font-size: .84em; color: var(--ink-soft); }
.curve figcaption b { color: var(--ink); font-variant-numeric: tabular-nums; }
.curve svg { display: block; width: 100%; height: 34px; margin-top: 4px; }
.factlist { margin: 16px 0 0; display: flex; flex-direction: column; gap: 8px; font-size: .88em; }
.factlist > div { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 4px 14px; }
.factlist dt { color: var(--ink-soft); }
.factlist dd { margin: 0; overflow-wrap: anywhere; }
.admin-table { margin: 14px 0 0; }
.admin-table td { vertical-align: top; padding-top: 8px; padding-bottom: 8px; }
.admin-table td:not(:last-child) { padding-right: 12px; }
.admin-actions { display: flex; gap: 6px; justify-content: flex-end; }
.admin-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.admin-inline { flex-direction: row; align-items: center; gap: 8px; }
.admin-inline select { width: auto; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: var(--ink-soft); }
.dot.is-ok { background: var(--teal); }
.dot.is-off { background: var(--danger); }
.logbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 14px 0 10px; }
.logview { margin: 0; max-height: 340px; overflow: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .76em; line-height: 1.55; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.monthbars { display: flex; align-items: flex-end; gap: 6px; margin-top: 16px; height: 110px; }
.monthbar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 5px; height: 100%; text-align: center; }
.monthbar-col { flex: 1; display: flex; align-items: flex-end; }
.monthbar-col > span { display: block; width: 100%; min-height: 2px; border-radius: 4px 4px 0 0; background: var(--teal-soft); border-top: 2px solid var(--teal); }
.monthbar-label { font-size: .7em; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

@media (max-width: 700px) {
  .main > .adminpage { padding-left: 16px; padding-right: 16px; }
  .factlist > div { grid-template-columns: 1fr; }
  .admin-actions { justify-content: flex-start; }
}
