/* PHOS Katalog-Manager – Oberfläche */

:root {
  color-scheme: light dark;
  --bg: light-dark(#f4f4f2, #111111);
  --bg-elev: light-dark(#ffffff, #1a1a1a);
  --bg-sunken: light-dark(#ebebe7, #0b0b0b);
  --bg-hover: light-dark(#ececE8, #232323);
  --bg-active: light-dark(#1c1c1a, #f1f1ee);
  --line: light-dark(#e3e3de, #2a2a2a);
  --line-strong: light-dark(#cdcdc7, #3b3b3b);
  --text: light-dark(#1c1c1a, #ededea);
  --text-2: light-dark(#5d5d58, #a6a6a1);
  --text-3: light-dark(#8b8b85, #74746f);
  --text-on-active: light-dark(#ffffff, #121212);
  --accent: light-dark(#1c1c1a, #f1f1ee);
  --accent-text: light-dark(#ffffff, #121212);
  --gold: #e3a008;
  --gold-text: light-dark(#8a5a00, #f5c451);
  --gold-soft: light-dark(#fdf4dd, #33280e);
  --danger: light-dark(#c42b1c, #ff7a6b);
  --danger-soft: light-dark(#fdecea, #3a1714);
  --ok: light-dark(#1f7a3a, #6fd08c);
  --ok-soft: light-dark(#e7f5ec, #13301c);
  --warn: light-dark(#a35a00, #ffb760);
  --warn-soft: light-dark(#fff3e0, #36260f);
  --info-soft: light-dark(#eef2ff, #18203a);
  --focus: light-dark(#2563eb, #8ab4ff);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-1: 0 1px 2px rgb(0 0 0 / .06), 0 1px 3px rgb(0 0 0 / .05);
  --shadow-2: 0 10px 28px -8px rgb(0 0 0 / .22), 0 2px 6px rgb(0 0 0 / .06);
  --shadow-3: 0 28px 70px -16px rgb(0 0 0 / .45);
  /* Apple-Systemschrift zuerst: Windows kennt die beiden Namen nicht und nimmt weiter Segoe UI; auf dem Mac greift
     sonst eine lokal installierte Inter – fehlt dort der aufrechte Schnitt, wird die ganze Oberfläche kursiv. */
  --font: -apple-system, BlinkMacSystemFont, "Inter var", "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --topbar-h: 58px;
  --sidebar-w: 304px;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.45 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
code, kbd, pre { font-family: var(--mono); font-size: .92em; }
kbd {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px;
  background: var(--bg-elev); color: var(--text-3); font-size: 11px; line-height: 16px; white-space: nowrap;
}
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.ic { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ic-sm { width: 15px; height: 15px; }
.ic-lg { width: 26px; height: 26px; }
.ic-fill { fill: currentColor; stroke: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ------------------------------------------------------------------ Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--bg-elev); color: var(--text);
  font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .08s;
}
.btn:hover { background: var(--bg-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn-primary:hover { background: color-mix(in oklab, var(--accent) 86%, var(--bg)); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-danger { color: var(--danger); border-color: color-mix(in oklab, var(--danger) 35%, transparent); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger-solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; gap: 6px; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; flex: none;
  border: 0; border-radius: 8px; background: transparent; color: var(--text-2); cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.is-on { color: var(--gold); }
.link-btn { border: 0; background: none; padding: 0; color: var(--text-2); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.link-btn:hover { color: var(--text); }

/* --------------------------------------------------------------- Felder */
.field { display: grid; gap: 6px; }
.field > span, .field-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field-hint { font-size: 12.5px; color: var(--text-3); }
.input, .field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--bg-elev); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .field input:focus, .field select:focus {
  border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in oklab, var(--focus) 22%, transparent);
}
.input:disabled, .field input:disabled { background: var(--bg-sunken); color: var(--text-2); }
.input-group { display: flex; align-items: stretch; }
.input-group .addon {
  display: inline-flex; align-items: center; padding: 0 10px; border: 1px solid var(--line-strong); border-right: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm); background: var(--bg-sunken); color: var(--text-3); font-size: 13px; white-space: nowrap;
}
.input-group .input, .input-group input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0 !important; }
.check-sm { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); cursor: pointer; }
.check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.check input, .check-sm input { accent-color: var(--accent); width: 16px; height: 16px; }
.form-stack { display: grid; gap: 16px; }

.search-field {
  position: relative; display: flex; align-items: center;
}
.search-field input {
  width: 100%; height: 36px; padding: 0 34px 0 34px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg-sunken); outline: none;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.search-field input:focus { background: var(--bg-elev); border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in oklab, var(--focus) 18%, transparent); }
.search-field::before {
  content: ""; position: absolute; left: 11px; width: 15px; height: 15px; pointer-events: none; opacity: .55;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") center / contain no-repeat;
}
.search-field kbd { position: absolute; right: 8px; pointer-events: none; }
.search-field input:focus ~ kbd, .search-field input:not(:placeholder-shown) ~ kbd { display: none; }
.search-field input::-webkit-search-cancel-button { cursor: pointer; }

/* Segmentierte Auswahl */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 9px; background: var(--bg-sunken); border: 1px solid var(--line); }
.seg button {
  border: 0; background: transparent; padding: 5px 10px; border-radius: 6px; cursor: pointer;
  color: var(--text-2); font-size: 13px; font-weight: 500; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center;
}
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"], .seg button[aria-pressed="true"] { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-1); }
.seg-sm button { padding: 4px 8px; font-size: 12px; }
.seg .count { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* Chips & Badges */
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px;
  border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--bg-sunken); color: var(--text-2); border: 1px solid var(--line);
}
.chip .ic { width: 13px; height: 13px; }
.chip-gold { background: var(--gold-soft); color: var(--gold-text); border-color: transparent; }
.chip-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.chip-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge-count {
  min-width: 20px; height: 18px; padding: 0 6px; border-radius: 999px; display: inline-grid; place-items: center;
  font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; background: var(--bg-sunken); color: var(--text-2);
}

/* Hinweise */
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); font-size: 13.5px; line-height: 1.5; }
.alert .ic { margin-top: 1px; }
.alert-info { background: var(--info-soft); }
.alert-warn { background: var(--warn-soft); color: var(--text); }
.alert-warn .ic { color: var(--warn); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-gold { background: var(--gold-soft); }
.alert-gold .ic { color: var(--gold); }
.alert-actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.error-box { white-space: pre-wrap; background: var(--danger-soft); color: var(--danger); padding: 12px; border-radius: var(--radius-sm); }

/* ------------------------------------------------------------------ Layout */
.app {
  display: grid; height: 100dvh;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-areas: "top top" "side main";
}
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 18px; padding: 0 16px 0 18px;
  background: var(--bg-elev); border-bottom: 1px solid var(--line); z-index: 20;
}
.brand { display: inline-flex; align-items: baseline; gap: 10px; text-decoration: none; white-space: nowrap; }
.brand { align-items: center; }
/* Logo nie stauchen – bei Platzmangel gibt in der Kopfleiste das Suchfeld nach, nicht .brand */
.brand-mark { display: inline-flex; flex-shrink: 0; }
.brand-mark img { display: block; width: auto; height: 20px; flex-shrink: 0; }
.topbar .brand { flex-shrink: 0; }
.brand-sub { color: var(--text-2); font-size: 13px; font-weight: 500; }
.brand-lg .brand-mark img { height: 28px; }
/* Logo: dunkle Version im hellen Theme, helle Version im dunklen Theme */
.brand-mark .logo-hell { display: none; }
:root[data-theme="dark"] .brand-mark .logo-dunkel { display: none; }
:root[data-theme="dark"] .brand-mark .logo-hell { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand-mark .logo-dunkel { display: none; }
  :root:not([data-theme="light"]) .brand-mark .logo-hell { display: block; }
}
.brand-lg .brand-sub { font-size: 15px; }
.topnav { display: flex; gap: 2px; }
.topnav a {
  text-decoration: none; padding: 7px 12px; border-radius: 8px; color: var(--text-2); font-weight: 500;
}
.topnav a:hover { background: var(--bg-hover); color: var(--text); }
.topnav a.is-active { color: var(--text); background: var(--bg-sunken); }
.search-trigger {
  display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 8px 0 34px; margin-left: auto;
  width: min(380px, 32vw); border: 1px solid var(--line); border-radius: 9px; background: var(--bg-sunken);
  color: var(--text-3); cursor: pointer; position: relative; text-align: left;
}
.search-trigger::before {
  content: ""; position: absolute; left: 11px; width: 15px; height: 15px; background: currentColor; opacity: .8;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") center / contain no-repeat;
}
.search-trigger:hover { border-color: var(--line-strong); color: var(--text-2); }
.search-trigger, .brand { min-width: 0; }
.search-trigger-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-end { display: flex; align-items: center; gap: 6px; }
.sync-chip {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--text-2); cursor: pointer; font-size: 12.5px; font-weight: 500; white-space: nowrap;
}
.sync-chip:hover { background: var(--bg-hover); color: var(--text); }
.sync-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.sync-chip.is-stale .dot { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.sync-chip.is-off .dot { background: var(--text-3); box-shadow: none; }
.sync-chip.is-error .dot { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.sync-chip.is-error { color: var(--danger); }
.sync-chip.is-busy .ic { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.user-chip {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 4px 0 4px; border: 0; border-radius: 999px;
  background: transparent; cursor: pointer; color: var(--text-2);
}
.user-chip:hover { background: var(--bg-hover); }
.user-chip .name { white-space: nowrap; font-weight: 500; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 11.5px; font-weight: 700;
  background: var(--accent); color: var(--accent-text); letter-spacing: .02em;
}
.only-narrow { display: none; }

/* --------------------------------------------------------------- Sidebar */
.sidebar {
  grid-area: side; display: flex; flex-direction: column; min-height: 0;
  background: var(--bg-elev); border-right: 1px solid var(--line);
}
.sidebar-head { display: grid; gap: 10px; padding: 14px 14px 10px; border-bottom: 1px solid var(--line); }
.sidebar-head .seg { width: 100%; }
.sidebar-head .seg button { flex: 1; justify-content: center; }
.sidebar-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px;
  border-top: 1px solid var(--line);
}
.tree { flex: 1; overflow: auto; padding: 8px 8px 24px; overscroll-behavior: contain; scrollbar-width: thin; }
.tree-row {
  --depth: 0;
  display: flex; align-items: center; gap: 2px; min-height: 32px; border-radius: 7px;
  padding-left: calc(var(--depth) * 16px); position: relative;
}
.tree-row:hover { background: var(--bg-hover); }
.tree-row.is-active { background: var(--bg-active); color: var(--text-on-active); }
.tree-row.is-active .tree-meta, .tree-row.is-active .tree-toggle { color: inherit; opacity: .85; }
.tree-row.is-active .badge-count { background: color-mix(in oklab, var(--text-on-active) 18%, transparent); color: inherit; }
.tree-row.is-hidden .tree-name { opacity: .5; text-decoration: line-through; text-decoration-thickness: 1px; }
.tree-row.is-dim .tree-name { opacity: .55; }
.tree-row.is-droptarget { background: var(--gold-soft); color: var(--text); box-shadow: inset 0 0 0 2px var(--gold); }
.tree-row.is-filedrop { box-shadow: inset 0 0 0 2px var(--focus); background: var(--info-soft); color: var(--text); }
.tree-toggle {
  width: 24px; height: 28px; display: grid; place-items: center; border: 0; background: transparent; padding: 0;
  color: var(--text-3); cursor: pointer; border-radius: 5px; flex: none;
}
.tree-toggle .ic { width: 14px; height: 14px; transition: transform .15s var(--ease); }
.tree-row[aria-expanded="true"] > .tree-toggle .ic { transform: rotate(90deg); }
.tree-toggle-spacer { width: 24px; flex: none; }
.tree-link {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 2px;
  text-decoration: none; border-radius: 6px; outline-offset: -2px;
}
.tree-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-name mark { background: var(--gold-soft); color: inherit; border-radius: 2px; }
.tree-meta { display: inline-flex; align-items: center; gap: 5px; color: var(--text-3); flex: none; }
.tree-meta .ic { width: 13px; height: 13px; }
.tree-star { color: var(--gold); }
.tree-warn { color: var(--warn); }
.tree-tag {
  font-size: 9.5px; font-weight: 700; letter-spacing: .06em; padding: 1px 4px; border-radius: 4px;
  border: 1px solid currentColor; opacity: .6;
}
.tree-empty { padding: 24px 12px; color: var(--text-3); text-align: center; font-size: 13px; }
.sidebar-scrim { display: none; }

/* ------------------------------------------------------------------ Main */
.main { grid-area: main; overflow: auto; outline: none; view-transition-name: km-main; }
.view { max-width: 1320px; margin: 0 auto; padding: 28px 36px 96px; }
.view-head { display: grid; gap: 10px; margin-bottom: 26px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 13px; color: var(--text-3); }
.crumbs a { text-decoration: none; padding: 2px 4px; border-radius: 4px; }
.crumbs a:hover { color: var(--text); background: var(--bg-hover); }
.crumbs .sep { opacity: .5; }
.title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; }
.view h1 { margin: 0; font-size: 28px; line-height: 1.2; font-weight: 650; letter-spacing: -.015em; }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--text-2); }
.meta-row a, .meta-row button.link-btn { display: inline-flex; align-items: center; gap: 5px; text-decoration: none; color: var(--text-2); }
.meta-row a:hover { color: var(--text); text-decoration: underline; }
.meta-row .ic { width: 14px; height: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }
.actions .spacer { flex: 1; }
.section { margin-top: 44px; }
.section-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.section-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.section-head .muted { font-size: 13px; }
.hint-line { margin-top: 28px; font-size: 12.5px; color: var(--text-3); display: flex; gap: 16px; flex-wrap: wrap; }
.hint-line kbd { margin: 0 2px; }
.stack { display: grid; gap: 12px; }

/* ----------------------------------------------------------------- Kacheln */
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
  gap: 30px 24px; align-items: start;
}
.tile {
  position: relative; display: flex; flex-direction: column; gap: 11px; border-radius: 8px;
  user-select: none; -webkit-user-select: none; cursor: grab; outline-offset: 4px;
}
.tile:active { cursor: grabbing; }
.tile-cover {
  position: relative; aspect-ratio: 210 / 297; border-radius: 4px; overflow: hidden;
  background: var(--bg-elev); border: 1px solid var(--line); box-shadow: var(--shadow-1);
  transition: transform .2s var(--ease), box-shadow .2s var(--ease), border-color .2s;
}
.tile-cover img { width: 100%; height: 100%; object-fit: cover; -webkit-user-drag: none; pointer-events: none; }
.tile:hover .tile-cover, .tile:focus-visible .tile-cover { transform: translateY(-3px); box-shadow: var(--shadow-2); }
.tile.is-main .tile-cover { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold), var(--shadow-1); }
.tile.is-main:hover .tile-cover { box-shadow: 0 0 0 2px var(--gold), var(--shadow-2); }
.tile-title { font-size: 15px; line-height: 1.35; font-weight: 500; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tile-sub { margin-top: -6px; font-size: 12px; color: var(--text-3); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tile-badge {
  position: absolute; left: 8px; bottom: 8px; display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px 3px 6px; border-radius: 999px; font-size: 11.5px; font-weight: 650;
  background: var(--gold); color: #1c1400; box-shadow: 0 2px 8px rgb(0 0 0 / .2);
}
.tile-badge .ic { width: 13px; height: 13px; fill: currentColor; stroke: none; }
/* Positionsnummer: CSS-Zähler, damit sie beim Ziehen sofort mitwandert (Rendern ist dann aufgeschoben) */
.grid[data-cat] { counter-reset: km-pos; }
.grid[data-cat] > .tile[data-id] { counter-increment: km-pos; }
.tile-num {
  position: absolute; left: 8px; bottom: 8px; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 999px;
  display: grid; place-items: center; font-size: 13px; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1;
  background: #1c1c1a; color: #fff; box-shadow: 0 2px 8px rgb(0 0 0 / .2);
}
.tile-num::before { content: counter(km-pos); text-box: trim-both cap alphabetic; }
/* ohne text-box sitzen die Ziffern wegen des Unterlängen-Raums zu tief */
@supports not (text-box: trim-both cap alphabetic) { .tile-num::before { transform: translateY(-.06em); } }
.tile.is-main .tile-badge { left: 40px; bottom: 9px; }
.tile-actions {
  position: absolute; top: 8px; right: 8px; display: flex; flex-direction: column; gap: 6px;
  opacity: 0; transform: translateX(4px); transition: opacity .15s, transform .15s var(--ease);
}
.tile:hover .tile-actions, .tile:focus-within .tile-actions { opacity: 1; transform: none; }
.tile-actions .icon-btn {
  width: 32px; height: 32px; border-radius: 50%; color: #1c1c1a;
  background: rgb(255 255 255 / .9); backdrop-filter: blur(6px); box-shadow: 0 2px 8px rgb(0 0 0 / .18);
}
.tile-actions .icon-btn:hover { background: #fff; color: #000; }
.tile-actions .icon-btn.is-on { color: #b37800; }
.tile-actions .icon-btn.is-on .ic { fill: var(--gold); stroke: #b37800; }
.tile-actions .icon-btn.is-danger:hover { color: #c42b1c; }
.tile-grip {
  position: absolute; top: 8px; left: 8px; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: rgb(255 255 255 / .9); color: #555; box-shadow: 0 2px 8px rgb(0 0 0 / .15); cursor: grab;
  opacity: 0; transition: opacity .15s; touch-action: none;
}
.tile:hover .tile-grip, .tile:focus-within .tile-grip { opacity: 1; }
@media (hover: none) {
  .tile-actions, .tile-grip { opacity: 1; transform: none; }
  /* auf Touch-Geräten nur Stern + Bearbeiten, der Rest steht im Bearbeiten-Panel */
  .grid:not(.lib) .tile-actions > :nth-child(n+3) { display: none; }
}
.tile.is-placeholder .tile-cover { opacity: .28; border-style: dashed; border-color: var(--line-strong); box-shadow: none; transform: none; }
.tile.is-placeholder .tile-cover img { filter: grayscale(1); }
.tile.is-placeholder .tile-title, .tile.is-placeholder .tile-sub, .tile.is-placeholder .tile-actions, .tile.is-placeholder .tile-grip, .tile.is-placeholder .tile-badge { opacity: 0; }
.tile-ghost {
  position: fixed; z-index: 1000; pointer-events: none; margin: 0; will-change: transform;
}
.tile-ghost .tile-cover { box-shadow: var(--shadow-3); transform: none !important; }
.tile-ghost .tile-actions, .tile-ghost .tile-grip, .tile-ghost .tile-num { opacity: 0 !important; }
.tile.is-new .tile-cover { animation: flash 1.6s var(--ease); }
/* Auswahl (Klick, Strg/⇧ + Klick) – outline, damit der goldene Rahmen des Hauptkatalogs sichtbar bleibt */
.tile.is-selected .tile-cover { outline: 3px solid var(--focus); outline-offset: 3px; }
.tile.is-selected .tile-title { color: var(--focus); }
.tile-ghost.is-selected .tile-cover { outline: none; }
.selbar {
  position: sticky; bottom: 16px; z-index: 5; margin-top: 24px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 10px 10px 16px; border-radius: var(--radius-lg); background: var(--bg-elev); border: 1px solid var(--line); box-shadow: var(--shadow-3);
}
.selbar-count { font-size: 14px; }
@keyframes flash {
  0% { box-shadow: 0 0 0 0 var(--focus); transform: scale(.96); }
  25% { box-shadow: 0 0 0 4px var(--focus); transform: none; }
  100% { box-shadow: var(--shadow-1); }
}
body.is-dragging, body.is-dragging * { cursor: grabbing !important; }
body.is-dragging .tile:not(.is-placeholder):hover .tile-cover { transform: none; }

/* Kachel „hinzufügen“ */
.tile-add {
  aspect-ratio: 210 / 297; border: 2px dashed var(--line-strong); border-radius: 6px; background: transparent;
  display: grid; place-content: center; justify-items: center; gap: 10px; padding: 16px; text-align: center;
  color: var(--text-2); cursor: pointer; transition: border-color .15s, background .15s, color .15s;
}
.tile-add:hover, .tile-add.is-over { border-color: var(--text-2); background: var(--bg-elev); color: var(--text); }
.tile-add strong { font-size: 14px; font-weight: 600; color: var(--text); }
.tile-add small { font-size: 12px; line-height: 1.4; color: var(--text-3); }
.tile-add .ic { width: 28px; height: 28px; stroke-width: 1.5; }
.grid.is-empty { grid-template-columns: 1fr; }
.grid.is-empty .tile-add { aspect-ratio: auto; min-height: 300px; border-radius: var(--radius-lg); }
.grid.is-empty .tile-add strong { font-size: 18px; }
.grid.is-empty .tile-add small { font-size: 13.5px; max-width: 46ch; }

/* Platzhalter-Cover */
.cover-missing {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px; padding: 12px; text-align: center;
  background: repeating-linear-gradient(-45deg, var(--bg-sunken) 0 10px, var(--bg-elev) 10px 20px); color: var(--text-3); font-size: 12px;
}
.cover-missing .ic { width: 28px; height: 28px; stroke-width: 1.4; }

/* Unvollständige Einträge */
.incomplete-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.incomplete {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center; padding: 10px 12px 10px 10px;
  border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--bg-elev);
}
.incomplete.is-over { border-color: var(--focus); background: var(--info-soft); }
.incomplete-cover { position: relative; width: 64px; aspect-ratio: 210/297; border-radius: 3px; overflow: hidden; border: 1px solid var(--line); background: var(--bg-sunken); }
.incomplete-cover img { width: 100%; height: 100%; object-fit: cover; }
.incomplete-cover .cover-missing { font-size: 0; gap: 0; }
.incomplete-cover .cover-missing .ic { width: 20px; height: 20px; }
.incomplete-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.incomplete-info { font-size: 12.5px; color: var(--warn); display: flex; gap: 6px; align-items: center; margin-top: 2px; }

/* Unterkategorien */
.subcats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.subcat {
  display: grid; grid-template-columns: 44px 1fr; gap: 12px; align-items: center; padding: 10px 12px 10px 10px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); text-decoration: none;
  transition: border-color .15s, box-shadow .15s, transform .15s var(--ease);
}
.subcat:hover { border-color: var(--line-strong); box-shadow: var(--shadow-1); transform: translateY(-1px); }
.subcat-cover { width: 44px; aspect-ratio: 210/297; border-radius: 3px; overflow: hidden; background: var(--bg-sunken); border: 1px solid var(--line); position: relative; }
.subcat-cover img { width: 100%; height: 100%; object-fit: cover; }
.subcat-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subcat-meta { font-size: 12px; color: var(--text-3); display: flex; gap: 8px; align-items: center; }
.subcat-meta .ic { width: 12px; height: 12px; }

/* ----------------------------------------------------------------- Startseite */
.home-hello { font-size: 30px; font-weight: 650; letter-spacing: -.02em; margin: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-top: 24px; }
.stat {
  text-align: left; padding: 16px 18px; border-radius: var(--radius-lg); background: var(--bg-elev); border: 1px solid var(--line);
  display: grid; gap: 4px; cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .15s var(--ease);
}
.stat:hover { border-color: var(--line-strong); box-shadow: var(--shadow-1); transform: translateY(-1px); }
.stat-label { font-size: 12.5px; color: var(--text-2); font-weight: 500; display: flex; gap: 6px; align-items: center; }
.stat-value { font-size: 30px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-note { font-size: 12px; color: var(--text-3); }
.stat.is-warn .stat-value { color: var(--warn); }
.stat.is-gold .stat-label .ic { color: var(--gold); }
.home-cols { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 28px; margin-top: 32px; align-items: start; }
.card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px 20px; }
.card h2 { margin: 0 0 12px; font-size: 15px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.todo { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.todo li + li { border-top: 1px solid var(--line); }
.todo a, .todo button {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 4px; text-decoration: none;
  border: 0; background: none; cursor: pointer; text-align: left; border-radius: 6px;
}
.todo a:hover, .todo button:hover { background: var(--bg-hover); }
.todo .todo-icon { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; flex: none; }
.todo .todo-icon.warn { background: var(--warn-soft); color: var(--warn); }
.todo .todo-icon.gold { background: var(--gold-soft); color: var(--gold); }
.todo .todo-icon.danger { background: var(--danger-soft); color: var(--danger); }
.todo .todo-icon.info { background: var(--info-soft); color: var(--focus); }
.todo .todo-text { flex: 1; min-width: 0; }
.todo .todo-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.todo .todo-sub { font-size: 12.5px; color: var(--text-3); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-ok { display: flex; gap: 10px; align-items: center; color: var(--ok); padding: 8px 0; font-weight: 500; }
.steps { margin: 0; padding: 0; list-style: none; display: grid; gap: 14px; counter-reset: step; }
.steps li { display: grid; grid-template-columns: 28px 1fr; gap: 12px; align-items: start; counter-increment: step; font-size: 13.5px; color: var(--text-2); }
.steps li::before {
  content: counter(step); width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--bg-sunken); color: var(--text); font-weight: 650; font-size: 12.5px;
}
.steps strong { color: var(--text); font-weight: 600; display: block; }
.recent { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 18px 14px; }
.recent .tile { cursor: pointer; }
.recent .tile-title { font-size: 13px; }

/* ------------------------------------------------------------- Bibliothek */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 22px; }
.toolbar .search-field { flex: 1 1 260px; max-width: 420px; }
.toolbar .spacer { flex: 1; }
/* Filterleiste wird auf schmalen Bildschirmen in sich seitlich scrollbar statt die Seite zu verbreitern */
.toolbar .seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.toolbar .seg::-webkit-scrollbar { display: none; }
.toolbar .seg button { flex: none; }
.select {
  height: 36px; padding: 0 30px 0 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--bg-elev);
}
.lib .tile { cursor: pointer; }
.lib-empty { padding: 60px 20px; text-align: center; color: var(--text-3); grid-column: 1 / -1; }

/* --------------------------------------------------------------- Dialoge */
dialog { border: 0; padding: 0; background: transparent; color: var(--text); max-width: none; max-height: none; overflow: visible; }
dialog::backdrop { background: rgb(15 15 14 / .5); backdrop-filter: blur(3px); }
dialog[open]::backdrop { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(560px, calc(100vw - 32px)); margin: auto; }
.modal.modal-lg { width: min(860px, calc(100vw - 32px)); }
.modal.modal-xl { width: min(1080px, calc(100vw - 32px)); }
.modal-panel {
  background: var(--bg-elev); border-radius: var(--radius-lg); box-shadow: var(--shadow-3);
  display: flex; flex-direction: column; max-height: calc(100dvh - 48px); overflow: hidden;
  animation: pop .22s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.985); } }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 650; }
.modal-head p { margin: 3px 0 0; font-size: 13px; }
.modal-head .icon-btn { margin: -4px -6px 0 auto; }
.modal-body { padding: 18px 20px; overflow: auto; flex: 1; }
.modal-foot { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--bg-elev); flex-wrap: wrap; }
.modal-foot .spacer { flex: 1; }
.modal-foot .note { font-size: 12.5px; color: var(--text-2); }

/* Drawer (Katalog bearbeiten) */
.drawer { margin: 0 0 0 auto; height: 100dvh; width: min(500px, 100vw); }
.drawer .modal-panel { height: 100%; max-height: 100dvh; border-radius: var(--radius-lg) 0 0 var(--radius-lg); animation: slide .26s var(--ease); }
@keyframes slide { from { transform: translateX(32px); opacity: 0; } }
.drawer-cover {
  position: relative; width: 210px; margin: 4px auto 22px; aspect-ratio: 210/297; border-radius: 5px; overflow: hidden;
  border: 1px solid var(--line); box-shadow: var(--shadow-2); background: var(--bg-sunken);
}
.drawer-cover img { width: 100%; height: 100%; object-fit: cover; }
.drawer-cover.is-over { outline: 3px solid var(--focus); outline-offset: 3px; }
.drawer-cover-actions {
  position: absolute; inset: auto 0 0 0; display: flex; gap: 6px; justify-content: center; padding: 30px 8px 10px;
  background: linear-gradient(transparent, rgb(0 0 0 / .55)); opacity: 0; transition: opacity .15s;
}
.drawer-cover:hover .drawer-cover-actions, .drawer-cover:focus-within .drawer-cover-actions { opacity: 1; }
@media (hover: none) { .drawer-cover-actions { opacity: 1; } }
.drawer-cover-actions .btn { height: 30px; font-size: 12.5px; padding: 0 10px; background: rgb(255 255 255 / .94); color: #1c1c1a; border: 0; }
.drawer-section { margin-top: 22px; }
.drawer-section > h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin: 0 0 8px; font-weight: 650; display: flex; gap: 8px; align-items: center; }
.file-row {
  display: grid; grid-template-columns: 36px 1fr auto; gap: 12px; align-items: center; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg);
}
.file-row + .file-row { margin-top: 8px; }
.file-row.is-over { border-color: var(--focus); background: var(--info-soft); }
.file-row.is-missing { border-style: dashed; }
.file-icon { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; background: var(--bg-elev); border: 1px solid var(--line); }
.file-icon.pdf { color: #c42b1c; }
.file-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-actions { display: flex; gap: 4px; }
.progress { height: 4px; border-radius: 99px; background: var(--bg-sunken); overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.usage { display: grid; gap: 6px; }
.usage-row {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 4px; padding: 4px 4px 4px 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
}
.usage-row a { text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; }
.usage-row a:hover { text-decoration: underline; }
.usage-row .icon-btn { width: 30px; height: 30px; }
.usage-row .icon-btn.is-on .ic { fill: var(--gold); stroke: var(--gold); }
.save-state { font-size: 12px; color: var(--text-3); display: inline-flex; align-items: center; gap: 4px; min-height: 18px; }
.save-state.ok { color: var(--ok); }
.save-state.err { color: var(--danger); }
.title-field { display: flex; gap: 8px; align-items: center; }
.title-field .input { flex: 1; font-size: 15px; font-weight: 500; height: 40px; }
.meta-list { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 12.5px; color: var(--text-2); margin: 0; }
.meta-list dt { color: var(--text-3); }
.meta-list dd { margin: 0; overflow: hidden; text-overflow: ellipsis; }

/* Combobox */
.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); max-height: 280px; overflow: auto;
  background: var(--bg-elev); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow-2); padding: 4px;
}
.combo-list[hidden] { display: none; }
.combo-opt {
  display: flex; flex-direction: column; gap: 1px; padding: 7px 10px; border-radius: 6px; cursor: pointer;
}
.combo-opt[aria-selected="true"] { background: var(--bg-hover); }
.combo-opt .opt-name { font-weight: 550; }
.combo-opt .opt-path { font-size: 11.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-empty { padding: 10px; color: var(--text-3); font-size: 13px; }

/* Upload-Dialog */
.up-list { display: grid; gap: 10px; }
.up-row {
  display: grid; grid-template-columns: 72px 1fr auto; gap: 16px; align-items: start; padding: 12px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); transition: border-color .15s, background .15s;
}
.up-row.is-over { border-color: var(--focus); background: var(--info-soft); }
.up-row.is-done { opacity: .55; }
.up-row.is-error { border-color: var(--danger); }
.up-cover {
  position: relative; width: 72px; aspect-ratio: 210/297; border-radius: 4px; overflow: hidden; border: 1px solid var(--line);
  background: var(--bg-elev); cursor: pointer; padding: 0;
}
.up-cover img { width: 100%; height: 100%; object-fit: cover; }
.up-cover .cover-missing { font-size: 10.5px; gap: 4px; padding: 4px; }
.up-cover .cover-missing .ic { width: 20px; height: 20px; }
.up-main { display: grid; gap: 8px; min-width: 0; }
.up-title { display: flex; gap: 6px; align-items: center; }
.up-title .input { height: 36px; font-weight: 500; }
.up-files { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.file-pill {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; height: 28px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg-elev); font-size: 12.5px; cursor: pointer;
}
.file-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.file-pill .ic { width: 14px; height: 14px; }
.file-pill.pdf .ic { color: #c42b1c; }
.file-pill.missing { border-style: dashed; color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.file-pill.generated .ic { color: var(--focus); }
.up-side { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.up-status { font-size: 12px; display: flex; gap: 6px; align-items: center; }
.up-status.ok { color: var(--ok); }
.up-status.warn { color: var(--warn); }
.up-status.err { color: var(--danger); }
.up-drop {
  margin-top: 12px; border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--text-2);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.up-drop:hover, .up-drop.is-over { border-color: var(--text-2); background: var(--bg); color: var(--text); }
.up-target { display: flex; align-items: center; gap: 10px; flex: 1 1 320px; min-width: 0; }
.up-target .combo { flex: 1; min-width: 0; }
.up-target .field-label { white-space: nowrap; }

/* Picker / Scan */
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 18px 14px; margin-top: 16px; }
.pick { position: relative; display: grid; gap: 8px; cursor: pointer; border: 0; background: none; padding: 0; text-align: left; }
.pick .tile-cover { transition: box-shadow .15s, transform .15s; }
.pick-check {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: rgb(255 255 255 / .92); border: 1.5px solid #bbb; color: transparent; box-shadow: 0 1px 4px rgb(0 0 0 / .2);
}
.pick[aria-pressed="true"] .tile-cover { box-shadow: 0 0 0 3px var(--focus); }
.pick[aria-pressed="true"] .pick-check { background: var(--focus); border-color: var(--focus); color: #fff; }
.pick[disabled] { opacity: .45; cursor: not-allowed; }
.pick-title { font-size: 13px; line-height: 1.3; font-weight: 500; }
.pick-sub { font-size: 11.5px; color: var(--text-3); }
.scan-row { display: grid; grid-template-columns: 24px 48px 1fr; gap: 12px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.scan-row .incomplete-cover { width: 48px; }
.scan-row .input { height: 32px; }
.scan-row .file-meta { margin-top: 3px; }

/* Abgleich */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13.5px; margin: 0; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.change-groups { display: grid; gap: 8px; margin-top: 16px; }
.change-groups details { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.change-groups summary { padding: 10px 12px; cursor: pointer; display: flex; gap: 10px; align-items: center; font-weight: 550; list-style: none; }
.change-groups summary::-webkit-details-marker { display: none; }
.change-groups summary .badge-count { margin-left: auto; }
.change-groups ul { margin: 0; padding: 0 12px 10px 34px; font-size: 13px; color: var(--text-2); max-height: 220px; overflow: auto; }
.code-block { position: relative; }
.code-block pre {
  margin: 0; padding: 12px 44px 12px 14px; border-radius: var(--radius-sm); background: var(--bg-sunken); border: 1px solid var(--line);
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12.5px; line-height: 1.55;
}
.code-block .icon-btn { position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; }

/* Befehlspalette */
.palette { width: min(640px, calc(100vw - 24px)); margin: 12vh auto auto; }
.palette .modal-panel { max-height: 70vh; }
.palette-input { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.palette-input input { flex: 1; height: 54px; border: 0; outline: none; background: transparent; font-size: 16px; }
.palette-list { overflow: auto; padding: 6px; }
.palette-group { padding: 8px 10px 4px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.palette-item { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.palette-item[aria-selected="true"] { background: var(--bg-hover); }
.palette-item .thumb { width: 26px; aspect-ratio: 210/297; border-radius: 2px; overflow: hidden; background: var(--bg-sunken); flex: none; border: 1px solid var(--line); }
.palette-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.palette-item .p-icon { width: 26px; display: grid; place-items: center; color: var(--text-2); flex: none; }
.palette-item .p-text { flex: 1; min-width: 0; }
.palette-item .p-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item .p-sub { display: block; font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-foot { display: flex; gap: 14px; padding: 8px 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--text-3); }

/* Menü */
.menu {
  position: fixed; z-index: 60; min-width: 220px; padding: 5px; margin: 0; border: 1px solid var(--line-strong);
  border-radius: var(--radius); background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-2); inset: auto;
}
.menu button, .menu a {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; background: none; border-radius: 6px;
  text-align: left; cursor: pointer; text-decoration: none; font-size: 13.5px;
}
.menu button:hover, .menu a:hover, .menu button:focus-visible { background: var(--bg-hover); outline: none; }
.menu .danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 2px; }
.menu .menu-label { padding: 6px 10px 4px; font-size: 12px; color: var(--text-3); }

/* Toasts */
.toasts {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 2000; margin: 0; padding: 0; border: 0; background: none; overflow: visible;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); inset: auto auto 24px 50%;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 6px 6px 14px; border-radius: 12px;
  background: light-dark(#1c1c1a, #f1f1ee); color: light-dark(#fff, #121212); box-shadow: var(--shadow-2); font-size: 13.5px;
  animation: toast-in .25s var(--ease);
}
.toast.is-leaving { animation: toast-out .2s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }
.toast-success .toast-ic { color: light-dark(#7ee2a0, #1f7a3a); }
.toast-error { background: var(--danger); color: #fff; }
.toast-msg { max-width: 56ch; }
.toast-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border: 0; border-radius: 8px; cursor: pointer;
  background: rgb(255 255 255 / .14); color: inherit; font-weight: 600;
}
:root[data-theme="dark"] .toast-btn { background: rgb(0 0 0 / .08); }
.toast-btn:hover { background: rgb(255 255 255 / .24); }
.toast-x { width: 32px; height: 32px; border: 0; background: transparent; color: inherit; opacity: .7; cursor: pointer; border-radius: 8px; display: grid; place-items: center; }
.toast-x:hover { opacity: 1; }

/* Datei-Drop-Overlay */
.dropveil {
  position: fixed; inset: 12px; z-index: 900; border: 3px dashed var(--focus); border-radius: 22px;
  background: color-mix(in oklab, var(--bg) 82%, transparent); backdrop-filter: blur(4px);
  display: grid; place-items: center; pointer-events: none; opacity: 0; transition: opacity .15s;
}
body.is-filedrag .dropveil { opacity: 1; }
body.is-filedrag-tree .dropveil { opacity: 0; }
.dropveil-inner { display: grid; justify-items: center; gap: 14px; text-align: center; }
.dropveil-icon { width: 72px; height: 72px; border-radius: 22px; display: grid; place-items: center; background: var(--focus); color: #fff; }
.dropveil-icon .ic { width: 34px; height: 34px; }
.dropveil-text { font-size: 19px; font-weight: 600; max-width: 32ch; }
.dropveil-text small { display: block; font-size: 13.5px; font-weight: 400; color: var(--text-2); margin-top: 6px; }

/* ------------------------------------------------------------------ Login */
.login-page { display: grid; place-items: center; min-height: 100dvh; padding: 24px 16px; background: var(--bg); }
.login-card {
  width: min(400px, 100%); background: var(--bg-elev); border: 1px solid var(--line); border-radius: 20px; padding: 32px 28px;
  box-shadow: var(--shadow-2); display: grid; gap: 18px;
}
.login-title { font-size: 20px; margin: 4px 0 0; font-weight: 650; }
.login-hint { margin: 0; font-size: 13px; color: var(--text-2); text-align: center; }

/* View Transitions */
::view-transition-old(km-main) { animation: vt-out .14s ease both; }
::view-transition-new(km-main) { animation: vt-in .2s var(--ease) both; }
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; transform: translateY(6px); } }

/* -------------------------------------------------------------- Responsive */
@media (max-width: 1100px) {
  .home-cols { grid-template-columns: minmax(0, 1fr); }
  .search-trigger { width: 220px; }
}
@media (max-width: 920px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; }
  .only-narrow { display: inline-grid; }
  .sidebar {
    position: fixed; z-index: 40; top: var(--topbar-h); bottom: 0; left: 0; width: min(340px, 88vw);
    transform: translateX(-102%); transition: transform .25s var(--ease), box-shadow .25s var(--ease);
  }
  /* Schatten nur, wenn offen – sonst ragt er bei geschlossener Leiste in den linken Bildrand */
  .app.is-nav-open .sidebar { transform: none; box-shadow: var(--shadow-3); }
  /* Beim Wechsel über den Umbruchpunkt nicht animieren – sonst gleitet die Seitenleiste sichtbar hinaus */
  .app.is-snapping .sidebar { transition: none; }
  .sidebar-scrim { position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 39; background: rgb(0 0 0 / .35); }
  .app.is-nav-open .sidebar-scrim { display: block; }
  .topnav, .brand-sub { display: none; }
  .search-trigger { width: auto; flex: 1; }
  .search-trigger kbd { display: none; }
  .view { padding: 22px 16px 88px; }
  .sync-chip .label { display: none; }
}
@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 14px; }
  .view h1 { font-size: 23px; }
  .up-row { grid-template-columns: 56px 1fr; }
  .up-cover { width: 56px; }
  .up-side { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; }
  .incomplete-list { grid-template-columns: 1fr; }
  .topbar { gap: 6px; padding: 0 10px; }
  .topbar-end { gap: 2px; }
  .user-chip .name { display: none; }
  .search-trigger { flex: 0 0 36px; width: 36px; padding: 0; }
  .search-trigger::before { left: 10px; }
  .search-trigger-label { display: none; }
  .sync-chip { padding: 0 11px; }
}
