/* PDF-Stift – ruhige Arbeitsfläche: weiße Seiten auf Schreibtisch-Grau, Navy als Akzent, Lime markiert das aktive Werkzeug */
:root {
  --desk: #E9ECF2;
  --bar: #FFFFFF;
  --surface: #FFFFFF;
  --soft: #F1F3F8;
  --fg: #151A2E;
  --muted: #5E6578;
  --line: #D5DAE4;
  --accent: #1E2F6E;
  --accent-soft: #E6EBFA;
  --mark: #B8E62E;
  --ok: #13804A;
  --warn: #B45309;
  --bad: #C0262D;
  --shadow: 0 2px 10px rgba(21, 26, 46, .12);
  --font: 'Atkinson Hyperlegible', -apple-system, 'Segoe UI', Roboto, system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --desk: #12151C;
    --bar: #1B1F29;
    --surface: #222733;
    --soft: #262B38;
    --fg: #E8EAF0;
    --muted: #9AA0B0;
    --line: #2F3442;
    --accent: #9FB4FF;
    --accent-soft: #263156;
    --mark: #B8E62E;
    --ok: #4ADE80;
    --warn: #FBBF24;
    --bad: #F87171;
    --shadow: 0 2px 10px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--desk);
  color: var(--fg);
  font: 15px/1.45 var(--font);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, button { -webkit-user-select: none; user-select: none; }
input[type=search], input[type=password], input:not([type]) { -webkit-user-select: text; user-select: text; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Buttons ---------- */
.btn {
  height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); display: inline-flex; align-items: center; gap: 8px; font-weight: 700;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--bar); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn svg { width: 18px; height: 18px; stroke-width: 2.2; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 10px; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; color: var(--fg);
}
.icon-btn:disabled { color: var(--line); cursor: default; }
.text-btn {
  height: 44px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent;
  display: inline-flex; align-items: center; gap: 6px; color: var(--fg);
}
.text-btn[aria-pressed=true] { background: var(--accent-soft); color: var(--accent); }
@media (hover: hover) {
  .icon-btn:not(:disabled):hover, .text-btn:hover { background: var(--soft); }
}

/* ---------- Anmeldung ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: min(400px, 100%); background: var(--surface); border-radius: 18px; box-shadow: var(--shadow);
  padding: 32px; display: flex; flex-direction: column; gap: 10px;
}
.auth-card h1 { margin: 8px 0 0; font-size: 26px; }
.auth-card p { margin: 0 0 6px; }
.auth-card label { font-weight: 700; font-size: 14px; }
.auth-card input { height: 48px; border-radius: 12px; border: 1px solid var(--line); padding: 0 14px; font: inherit; font-size: 17px; background: var(--bar); color: var(--fg); }
.auth-card .btn { justify-content: center; margin-top: 8px; height: 48px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.err { color: var(--bad); min-height: 1.4em; margin: 0; }

/* ---------- Grundgerüst ---------- */
.shell { height: 100%; display: flex; flex-direction: column; }
.topbar {
  flex-shrink: 0; display: flex; align-items: center; gap: 8px;
  padding: calc(6px + var(--safe-top)) 12px 6px; background: var(--bar); border-bottom: 1px solid var(--line);
}
.tabs { flex: 1; min-width: 0; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 1 220px; min-width: 120px; height: 40px; display: flex; align-items: center; gap: 4px;
  border-radius: 10px; background: transparent; border: 1px solid transparent; padding: 0 4px 0 12px; color: var(--muted);
}
.tab.active { background: var(--accent-soft); color: var(--fg); border-color: var(--line); }
.tab .name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; border: 0; background: none; padding: 0; height: 100%; font-size: 14px; }
.tab.active .name { font-weight: 700; }
.tab .close { width: 32px; height: 32px; border: 0; background: none; border-radius: 8px; display: grid; place-items: center; color: inherit; }
.tab .close svg { width: 16px; height: 16px; }
#btnLib.active { background: var(--accent-soft); color: var(--accent); }

.sync { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; padding: 0 6px; }
.sync .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }
.sync[data-state=saving] .dot { background: var(--accent); animation: pulse 1s infinite; }
.sync[data-state=offline] .dot { background: var(--warn); }
.sync[data-state=error] .dot { background: var(--bad); }
@keyframes pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .sync .dot { animation: none !important; } }

.toolbar {
  flex-shrink: 0; display: flex; flex-direction: column; gap: 4px; padding: 4px 12px;
  background: var(--bar); border-bottom: 1px solid var(--line);
}
.tb-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; min-width: 0; }
.tools-row { border-top: 1px solid var(--line); padding-top: 4px; }
.favs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; min-width: 0; max-width: min(640px, 100%); flex: 0 1 auto; }
/* erste Zeile nie umbrechen: die Favoriten werden bei Platzmangel waagerecht scrollbar */
.toolbar > .tb-row:first-child { flex-wrap: nowrap; }
.toolbar > .tb-row:first-child > :not(.favs) { flex-shrink: 0; }
@media (max-width: 1320px) { #toolsToggle span { display: none; } }
.favs::-webkit-scrollbar { display: none; }
.fav {
  width: 42px; height: 44px; flex-shrink: 0; border: 0; border-radius: 10px; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--fg); position: relative;
}
.fav::after { content: ""; width: 16px; height: 3px; border-radius: 2px; background: transparent; }
.fav.active { background: var(--accent-soft); }
.fav.active::after { background: var(--mark); }
.fav .txa { width: 26px; height: 24px; border-radius: 4px; display: grid; place-items: center; font-weight: 700; font-size: 16px; color: #151A2E; line-height: 1; }
.fav .txa.ul { text-decoration: underline 2.5px; text-underline-offset: 3px; background: transparent; color: var(--fg); }
.fav .txa.st { text-decoration: line-through 2.5px; background: transparent; color: var(--fg); }
.kind { width: 44px; height: 42px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); display: grid; place-items: center; }
.kind.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
#finger[aria-pressed=true] { background: var(--accent-soft); color: var(--accent); }
.toolbar .group { display: flex; align-items: center; gap: 2px; }
.toolbar .seg { background: var(--soft); border-radius: 14px; padding: 3px; }
.toolbar .sep { width: 1px; height: 28px; background: var(--line); margin: 0 4px; }
.toolbar .spacer { flex: 1; }
.tool {
  width: 50px; height: 42px; border: 0; border-radius: 11px; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.tool::after { content: ""; width: 18px; height: 3px; border-radius: 2px; background: transparent; }
.tool.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.tool.active::after { background: var(--mark); }
.swatch { width: 40px; height: 44px; border: 0; background: transparent; display: grid; place-items: center; padding: 0; }
.swatch span { width: 26px; height: 26px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.swatch.active span { box-shadow: 0 0 0 3px var(--bar), 0 0 0 5px var(--accent); }
.width { width: 40px; height: 44px; border: 0; border-radius: 10px; background: transparent; display: grid; place-items: center; }
.width span { border-radius: 50%; background: var(--fg); }
.width.active { background: var(--accent-soft); }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 48px; z-index: 30; min-width: 280px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column;
}
.menu button { height: 44px; border: 0; background: none; text-align: left; padding: 0 14px; border-radius: 10px; }
.menu button:hover { background: var(--soft); }

/* ---------- Bibliothek ---------- */
.library { flex: 1; overflow-y: auto; padding: 28px clamp(16px, 4vw, 56px) calc(28px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 22px; background: var(--desk); }
.lib-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 16px; }
.lib-head h1 { margin: 2px 0 0; font-size: clamp(28px, 4vw, 38px); line-height: 1.1; text-wrap: balance; }
.eyebrow { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.lib-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.lib-actions input { height: 44px; width: min(280px, 60vw); border-radius: 12px; border: 1px solid var(--line); padding: 0 14px; font: inherit; background: var(--surface); color: var(--fg); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
#folders { justify-content: space-between; align-items: center; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; min-width: 0; }
.crumb { height: 40px; padding: 0 10px; border: 0; border-radius: 10px; background: transparent; color: var(--accent); font-weight: 700; font-size: 16px; }
.crumb.cur { color: var(--fg); }
.crumb:not(.cur):hover { background: var(--soft); }
.crumb-sep { color: var(--muted); font-size: 18px; }
.lib-tools { display: flex; align-items: center; gap: 8px; }
.view-toggle button { width: 44px; padding: 0; display: grid; place-items: center; }
.card.folder .thumb { background: var(--accent-soft); color: var(--accent); box-shadow: none; }
.card.folder .thumb svg { width: 56px; height: 56px; stroke-width: 1.4; }
.card.folder.up .thumb { background: var(--soft); color: var(--muted); }
.lbadges { display: none; }
/* Listenansicht */
.files.list { display: flex; flex-direction: column; gap: 0; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); padding: 4px 0; }
.files.list .card { flex-direction: row; align-items: center; gap: 14px; padding: 6px 12px; border-bottom: 1px solid var(--line); }
.files.list .card:last-child { border-bottom: 0; }
.files.list .thumb { width: 56px; aspect-ratio: 4 / 3; flex-shrink: 0; border-radius: 6px; box-shadow: 0 0 0 1px var(--line); }
.files.list .thumb .ph { width: 24px !important; height: 24px !important; }
.files.list .card.folder .thumb svg { width: 28px; height: 28px; }
.files.list .thumb .badges { display: none; }
.files.list .meta { flex: 1; align-items: center; }
.files.list .txt, .card.folder .txt { cursor: pointer; }
.files.list .lbadges { display: flex; gap: 6px; flex-shrink: 0; }
.chip { height: 38px; padding: 0 16px; border-radius: 19px; border: 1px solid var(--line); background: var(--surface); }
.chip.active { background: var(--fg); color: var(--desk); border-color: var(--fg); }
.folder-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: -10px; }
.folder-bar .text-btn { color: var(--accent); font-weight: 700; }
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 22px; }
.card { display: flex; flex-direction: column; gap: 10px; min-width: 0; position: relative; }
.card .thumb {
  aspect-ratio: 4 / 3; background: #FFFFFF; border-radius: 10px; box-shadow: var(--shadow); border: 0; padding: 0; overflow: hidden;
  display: grid; place-items: center; position: relative;
}
.card .thumb canvas { max-width: 100%; max-height: 100%; }
.card .thumb .ph { color: #A3A9B8; }
.card .badges { position: absolute; left: 8px; bottom: 8px; display: flex; gap: 6px; }
.badge { padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; background: #EEF0F5; color: #3B4256; }
.badge.offline { background: #DDF5C2; color: #2F4A06; }
.badge.notes { background: #FFF1A8; color: #5A4500; }
.card .meta { display: flex; align-items: flex-start; gap: 4px; min-width: 0; }
.card .meta .txt { flex: 1; min-width: 0; }
.card .meta .n { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta .d { font-size: 13px; color: var(--muted); }
.card .more { width: 36px; height: 36px; }
.card .menu { top: auto; bottom: 40px; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.lib-foot { margin-top: auto; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; font-size: 14px; }

/* ---------- Ansicht ---------- */
.viewer {
  flex: 1; overflow: auto; position: relative; background: var(--desk);
  -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y; overscroll-behavior: contain; overflow-anchor: none;
}
.viewer.finger { touch-action: none; }
.pages { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 18px 16px calc(80px + var(--safe-bottom)); width: max-content; min-width: 100%; transform-origin: 0 0; }
.pages, .page { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.page { position: relative; background: #FFFFFF; box-shadow: var(--shadow); border-radius: 3px; flex-shrink: 0; }
.page canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
.page canvas.blend { mix-blend-mode: multiply; }
.page .pno { position: absolute; right: -2px; bottom: -22px; font-size: 12px; color: var(--muted); }
.page-badge {
  position: fixed; right: 14px; bottom: calc(16px + var(--safe-bottom)); z-index: 20; padding: 6px 12px; border-radius: 10px;
  background: var(--fg); color: var(--desk); font-size: 14px; pointer-events: none; opacity: .9;
}

/* ---------- Textfelder ---------- */
.fav .txa.tt { background: transparent; font-family: Georgia, 'Times New Roman', serif; font-size: 20px; }
.fsz { font-weight: 700; line-height: 1; }
.txt-editor { position: absolute; z-index: 15; display: flex; flex-direction: column; gap: 6px; }
.txt-editor textarea {
  margin: 0; padding: 0; border: 0; outline: 1.5px dashed var(--accent); outline-offset: 3px; border-radius: 2px;
  background: rgba(255, 255, 255, .75); resize: none; overflow: hidden; white-space: pre; line-height: 1.25;
  -webkit-user-select: text; user-select: text; min-height: 1.25em;
}
.te-bar { display: flex; gap: 6px; }
.te-bar button { height: 36px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--fg); font-size: 14px; box-shadow: var(--shadow); }
.te-bar button.ok { background: var(--accent); border-color: var(--accent); color: var(--bar); font-weight: 700; }

/* ---------- Suche ---------- */
.search-row { border-top: 1px solid var(--line); padding-top: 4px; }
.search-row input { height: 40px; flex: 1 1 220px; max-width: 420px; border-radius: 10px; border: 1px solid var(--line); padding: 0 12px; font: inherit; background: var(--surface); color: var(--fg); }
.hits { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.hit { position: absolute; background: rgba(255, 170, 0, .32); border-radius: 2px; }
.hit.cur { background: rgba(255, 120, 0, .5); outline: 2px solid #E65C00; }

/* ---------- Präsentation ---------- */
.present-btn[aria-pressed=true] { background: var(--accent); color: var(--bar); }
body.present .topbar, body.present .toolbar, body.present .page-badge { display: none !important; }
body.present .viewer { background: #0D0F14; }
body.present .page { box-shadow: none; }
body.present .page .pno { display: none; }
.present-panel {
  position: fixed; right: 16px; bottom: calc(16px + var(--safe-bottom)); z-index: 35;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px; transition: opacity .3s;
}
.present-panel.idle { opacity: .3; }
.pp-row { display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: 14px; background: rgba(21, 26, 46, .85); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.pp-row .icon-btn { color: #FFFFFF; }
.pp-page { color: #FFFFFF; font-size: 14px; min-width: 60px; text-align: center; }
.present-favs { background: var(--bar); border-radius: 14px; padding: 4px; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.present-favs .favs { max-width: 100%; }
@media (prefers-reduced-motion: reduce) { .present-panel { transition: none; } }
#ppMirror[aria-pressed=true] { background: rgba(255, 255, 255, .22); }
body.mirror .viewer { transform: scaleX(-1); }
body.prompter .pages { pointer-events: none; }
body.prompter .viewer { overflow: hidden; }
.prompter-hint {
  position: fixed; left: 50%; top: 20px; transform: translateX(-50%); z-index: 50; padding: 10px 16px; border-radius: 12px;
  background: rgba(21, 26, 46, .9); color: #FFFFFF; font-size: 15px; transition: opacity .4s; pointer-events: none;
}
.prompter-hint.gone { opacity: 0; }
.foot-actions { display: flex; gap: 4px; flex-wrap: wrap; }

/* ---------- Seitenübersicht ---------- */
.overview {
  position: fixed; inset: 0; z-index: 40; background: var(--desk); display: flex; flex-direction: column;
  padding-top: var(--safe-top);
}
.ov-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; background: var(--bar); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.seg2 { display: flex; background: var(--soft); border-radius: 12px; padding: 3px; }
.seg2 button { height: 38px; padding: 0 16px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); }
.seg2 button.active { background: var(--surface); color: var(--fg); font-weight: 700; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.ov-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px; padding: 22px 16px calc(22px + var(--safe-bottom)); align-content: start; }
.ov-item { display: flex; flex-direction: column; align-items: center; gap: 8px; border: 0; background: none; padding: 0; color: var(--muted); font-size: 13px; }
.ov-item .pg { width: 100%; background: #FFFFFF; box-shadow: var(--shadow); border-radius: 3px; position: relative; overflow: hidden; border: 3px solid transparent; }
.ov-item.current .pg { border-color: var(--accent); }
.ov-item.current .n { background: var(--accent); color: var(--bar); }
.ov-item .n { padding: 1px 8px; border-radius: 6px; font-variant-numeric: tabular-nums; }
.ov-item canvas { display: block; width: 100%; height: 100%; }
.ov-item .dot { position: absolute; right: 6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--mark); box-shadow: 0 0 0 2px #fff; }

/* ---------- Dialoge, Hinweise ---------- */
.dlg { border: 0; border-radius: 18px; padding: 0; width: min(460px, calc(100% - 32px)); background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(10, 14, 28, .45); }
.dlg form { padding: 24px; display: flex; flex-direction: column; gap: 10px; }
.dlg h2 { margin: 0 0 6px; font-size: 22px; }
.dlg label { font-weight: 700; font-size: 14px; }
.dlg input { min-height: 44px; border-radius: 12px; border: 1px solid var(--line); padding: 8px 12px; font: inherit; background: var(--bar); color: var(--fg); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); z-index: 50;
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px; background: var(--fg); color: var(--desk); box-shadow: var(--shadow);
}

@media (max-width: 700px) {
  .sync #syncText { display: none; }
  .toolbar .sep { display: none; }
  #toolsToggle span { display: none; }
  .present-btn span { display: none; }
  .toolbar > .tb-row:first-child { flex-wrap: wrap; }
  .favs { max-width: 100%; }
  .colors { flex-wrap: wrap; }
}
