/* ------------------------------------------------------------------
   Bibliothek – Basis-Styles (warm-neutrales Farbschema)
   ------------------------------------------------------------------ */
:root {
    --bg: #faf8f5;
    --fg: #222;
    --muted: #6b6b6b;
    --accent: #8a4b2a;
    --accent-dark: #6e3a1f;
    --accent-soft: #f3e7df;
    --line: #e2ddd6;
    --card: #fff;
    --danger: #a3271b;
    --danger-soft: #fdecea;
    --success: #1e5a2e;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 2px 8px rgba(60, 40, 20, .05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--fg);
    line-height: 1.5;
}
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
img { max-width: 100%; height: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hint { color: var(--muted); font-size: .85rem; margin: .3rem 0 0; }
.hint a, .hint-link { color: var(--accent); }

.container { max-width: 1200px; margin: 0 auto; padding: 1rem; }

/* Kopfzeile ------------------------------------------------------- */
.site-header { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.site-nav { max-width: 1200px; margin: 0 auto; padding: .6rem 1rem; display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap; }
.site-nav a { color: var(--fg); text-decoration: none; padding: .2rem 0; border-bottom: 2px solid transparent; }
.site-nav a:hover, .site-nav a.is-active { border-bottom-color: var(--accent); color: var(--accent-dark); }
.site-nav .brand { font-weight: 700; margin-right: auto; border-bottom: 0; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; padding: 0 .5em; font-size: .8em; font-weight: 600; }

/* Meldungen ------------------------------------------------------- */
.flash { max-width: 1200px; margin: .8rem auto 0; padding: .6rem 1rem; border-radius: 6px; }
.flash-success { background: #e6f4ea; color: var(--success); }
.flash-error { background: var(--danger-soft); color: #7a1c14; }
.form-errors { margin: 0 0 1rem; }
.form-errors ul { margin: 0; padding-left: 1.2rem; }

/* Buttons --------------------------------------------------------- */
.btn {
    display: inline-block;
    padding: .45rem .9rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--fg);
    font: inherit;
    font-size: .95rem;
    line-height: 1.3;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--accent-soft); border-color: #d8c6b8; color: var(--fg); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #7f1d13; border-color: #7f1d13; color: #fff; }
.btn-danger-outline { color: var(--danger); border-color: #e7b8b2; }
.btn-danger-outline:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn-link { border-color: transparent; background: transparent; color: var(--muted); }
.btn-link:hover { background: transparent; color: var(--fg); }

/* Formularelemente ------------------------------------------------ */
input[type="text"], input[type="url"], input[type="search"], input[type="number"], input[type="email"], textarea, select {
    width: 100%;
    padding: .45rem .6rem;
    border: 1px solid #cfc7bd;
    border-radius: 6px;
    background: #fff;
    color: var(--fg);
    font: inherit;
}
textarea { resize: vertical; min-height: 4rem; }
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(138, 75, 42, .35); outline-offset: 1px; border-color: var(--accent); }
input[type="file"] { font: inherit; font-size: .9rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem 1rem; margin: 0 0 1rem; background: var(--card); }
legend { font-weight: 600; padding: 0 .4rem; }
label { display: block; font-size: .9rem; font-weight: 500; margin-bottom: .2rem; }
.field { margin-bottom: .9rem; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 1rem; }
.req { color: var(--danger); }
.check { display: flex; align-items: center; gap: .4rem; font-weight: 400; }
.check input { margin: 0; }
.input-row { display: flex; gap: .5rem; }
.input-row input { flex: 1; }

/* Listenseite: Layout --------------------------------------------- */
.books-layout { display: grid; grid-template-columns: 1fr; gap: 1.2rem; align-items: start; }
@media (min-width: 900px) {
    .books-layout { grid-template-columns: 260px minmax(0, 1fr); }
}
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.list-head h1 { margin: 0; }
.list-head .count { color: var(--muted); font-size: .95rem; font-weight: 400; margin-left: .4rem; }

/* Filter-Sidebar -------------------------------------------------- */
.filter-panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.filter-toggle { list-style: none; cursor: pointer; padding: .7rem 1rem; font-weight: 600; display: flex; align-items: center; gap: .5rem; }
.filter-toggle::-webkit-details-marker { display: none; }
.filter-toggle::after { content: "▾"; margin-left: auto; color: var(--muted); }
.filter-panel[open] > .filter-toggle::after { content: "▴"; }
@media (min-width: 900px) {
    .filter-panel { position: sticky; top: 3.6rem; max-height: calc(100vh - 4.4rem); overflow: auto; }
    .filter-toggle { display: none; }
}
.filters { padding: .8rem 1rem 1rem; }
.filter-search { display: flex; gap: .4rem; margin-bottom: .9rem; }
.filter-search input { flex: 1; min-width: 0; }
.filter-sort { margin-bottom: .9rem; }
.filter-sort-row { display: flex; gap: .4rem; }
.filter-sort-row select { min-width: 0; }
.filter-group { border-top: 1px solid var(--line); }
.filter-group summary { cursor: pointer; padding: .55rem 0; font-weight: 600; font-size: .95rem; display: flex; align-items: center; gap: .5rem; list-style: none; }
.filter-group summary::-webkit-details-marker { display: none; }
.filter-group summary::before { content: "›"; color: var(--muted); transition: transform .15s; display: inline-block; width: .8em; }
.filter-group[open] summary::before { transform: rotate(90deg); }
.filter-options { list-style: none; margin: 0 0 .6rem; padding: 0; }
.filter-options li { padding-left: calc(var(--depth, 0) * .9rem); }
.filter-options label { display: flex; align-items: center; gap: .4rem; font-weight: 400; font-size: .9rem; padding: .15rem 0; margin: 0; cursor: pointer; }
.filter-options input { margin: 0; flex: none; }
.filter-options .opt-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-options .opt-count { color: var(--muted); font-size: .8rem; }
.filter-options .is-empty label { color: #a39c93; }
.filter-options .opt-unassigned { margin-top: .3rem; padding-top: .3rem; border-top: 1px dashed var(--line); font-style: italic; }
.filter-apply { width: 100%; margin-top: .8rem; }
.filter-reset { display: block; margin-top: .8rem; font-size: .9rem; }

/* Chips ----------------------------------------------------------- */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .65rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent-dark); font-size: .85rem; text-decoration: none; border: 1px solid #e6d4c8; }
.chip:hover { background: #ead9cc; }
.chip-x { font-weight: 700; }
.chip-reset { background: transparent; border-color: var(--line); color: var(--muted); }
.chip-reset:hover { background: #f0ece7; color: var(--fg); }

/* Buch-Grid & Karten ---------------------------------------------- */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; }
.book-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; transition: transform .12s, box-shadow .12s; }
.book-card:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(60, 40, 20, .12); }
.book-cover { display: block; aspect-ratio: 2 / 3; background: #efe9e2; overflow: hidden; }
.book-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-placeholder {
    display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; padding: .8rem;
    background: linear-gradient(160deg, #e9dfd4, #d9c9ba); color: #5a4030; text-align: center; font-weight: 600; font-size: .9rem; line-height: 1.3;
}
.cover-placeholder span { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.book-body { padding: .6rem .7rem .75rem; display: flex; flex-direction: column; gap: .2rem; }
.book-title { font-size: .95rem; margin: 0; }
.book-title a { color: var(--fg); text-decoration: none; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.book-title a:hover { color: var(--accent-dark); }
.book-authors { margin: 0; font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-meta { margin: 0; font-size: .8rem; color: var(--muted); }
.badges { margin: .3rem 0 0; display: flex; flex-wrap: wrap; gap: .25rem; }

/* Tags / Badges --------------------------------------------------- */
.tag { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .75rem; background: #efe9e2; color: #4c3a2d; line-height: 1.5; white-space: nowrap; }
.tag-prio, .tag-prioritaet { background: #e5edf7; color: #24466e; }
.tag-qual, .tag-qualitaet { background: #fbf1d6; color: #6c4d00; }
.tag-genre { background: var(--accent-soft); color: var(--accent-dark); }
.tag-ort { background: #e4f1e7; color: #245a33; }
.tag-link { text-decoration: none; }
.tag-link:hover { filter: brightness(.94); }

/* Leerer Zustand -------------------------------------------------- */
.empty-state { text-align: center; padding: 3rem 1rem; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); }
.empty-state p { margin: .4rem 0; }

/* Pagination ------------------------------------------------------ */
.pagination { display: flex; flex-wrap: wrap; gap: .3rem; justify-content: center; margin: 1.5rem 0 .5rem; }
.page-link { display: inline-block; min-width: 2.2rem; text-align: center; padding: .35rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--fg); text-decoration: none; font-size: .9rem; }
.page-link:hover { background: var(--accent-soft); }
.page-link.is-current { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-gap { padding: .35rem .2rem; color: var(--muted); }

/* Formularseite --------------------------------------------------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; box-shadow: var(--shadow); }
.import-panel { margin-bottom: 1.5rem; border-left: 4px solid var(--accent); }
.import-form label { margin-bottom: .3rem; }
.section-title { color: var(--muted); font-weight: 600; margin: 1.5rem 0 .8rem; text-transform: uppercase; letter-spacing: .04em; font-size: .85rem; }
.form-columns { display: grid; grid-template-columns: 1fr; gap: 1.2rem; align-items: start; }
@media (min-width: 900px) {
    .form-columns { grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr); }
    .form-side { position: sticky; top: 3.6rem; }
}
.form-actions { display: flex; gap: .6rem; align-items: center; padding: 1rem 0; position: sticky; bottom: 0; background: linear-gradient(to top, var(--bg) 70%, rgba(250, 248, 245, 0)); }
.cover-edit { display: flex; gap: 1rem; margin-bottom: .5rem; }
.cover-preview { flex: none; width: 120px; aspect-ratio: 2 / 3; border-radius: 6px; overflow: hidden; background: #efe9e2; border: 1px solid var(--line); }
.cover-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-fields { flex: 1; min-width: 0; }

/* Kategorie-Felder im Formular ------------------------------------ */
.category-fields-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .5rem; }
.category-fields-head h2 { margin: 0; }
.category-fields-head a { font-size: .85rem; }
.category-group { padding-bottom: .6rem; }
.category-group legend .hint { display: inline; font-weight: 400; }
.option-list { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: 1rem; }
.option-list li { break-inside: avoid; }
.option-list label { display: flex; align-items: center; gap: .4rem; font-weight: 400; font-size: .9rem; padding: .12rem 0; margin: 0; cursor: pointer; }
.option-list input { margin: 0; flex: none; }
.option-tree { columns: 1; }
.option-tree .option-tree { padding-left: 1.3rem; border-left: 1px solid var(--line); margin-left: .45rem; }
.option-tree .level-hint { color: #b0a79c; font-size: .7rem; margin-left: auto; }

/* Detailseite ----------------------------------------------------- */
.book-detail { display: grid; grid-template-columns: 1fr; gap: 1.5rem; align-items: start; }
@media (min-width: 720px) {
    .book-detail { grid-template-columns: 260px minmax(0, 1fr); }
}
.detail-cover { display: flex; flex-direction: column; gap: .8rem; }
.detail-cover img, .detail-cover .cover-placeholder { width: 100%; max-width: 260px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: var(--radius); box-shadow: 0 6px 18px rgba(60, 40, 20, .18); }
.detail-cover .cover-placeholder { font-size: 1.05rem; }
.detail-actions { display: flex; flex-direction: column; gap: .5rem; max-width: 260px; }
.detail-actions .btn { width: 100%; text-align: center; }
.detail-actions form { margin: 0; }
.danger-zone summary { list-style: none; }
.danger-zone summary::-webkit-details-marker { display: none; }
.confirm-box { margin-top: .5rem; padding: .8rem; border: 1px solid #e7b8b2; background: var(--danger-soft); border-radius: var(--radius); }
.confirm-box p { margin: 0 0 .6rem; font-size: .9rem; color: #7a1c14; }
.detail-head h1 { font-size: 1.8rem; margin-bottom: .2rem; }
.detail-authors { margin: 0 0 1rem; font-size: 1.05rem; color: var(--muted); }
.detail-categories { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; padding: .8rem 1rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.cat-row { display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap; }
.cat-label { flex: none; width: 6.5rem; font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.cat-values { display: flex; flex-wrap: wrap; gap: .3rem; }
.detail-sample { margin: 0 0 1rem; }
.detail-description, .detail-notes { margin-bottom: 1.2rem; }
.detail-description p, .detail-notes p { margin: 0 0 .7rem; max-width: 70ch; }
.detail-notes { padding: .8rem 1rem; background: #fdf8ea; border-left: 4px solid #e2c56b; border-radius: 0 var(--radius) var(--radius) 0; }
.detail-notes h2 { font-size: 1rem; }

/* Tabellen -------------------------------------------------------- */
.meta-table { border-collapse: collapse; width: 100%; max-width: 560px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; font-size: .92rem; }
.meta-table th, .meta-table td { padding: .4rem .7rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.meta-table tr:last-child th, .meta-table tr:last-child td { border-bottom: 0; }
.meta-table th { width: 8.5rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.meta-table td { word-break: break-word; }

/* Fehlerseite ----------------------------------------------------- */
.error-page { text-align: center; padding: 3rem 1rem; }

/* === KI-Vorschläge === */
.flash-info { background: #eef3fb; color: #1f3a6b; }
.ai-bar { margin: 0 0 1rem; }
.ai-suggestion { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: .8rem 1rem; }
.ai-suggestion-head { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.ai-suggestion-head form { margin-left: auto; }
.ai-suggestion p { margin: .4rem 0; }
.ai-reasons { margin: .3rem 0 .3rem 1.1rem; padding: 0; font-size: .92em; }
.inline-form { display: inline-flex; gap: .6rem; align-items: center; }
.new-paths { margin-top: .4rem; padding-top: .4rem; border-top: 1px dashed var(--line); }
.new-path span { color: var(--accent); font-weight: 600; }

/* === Autor:innen === */
.authors-table td:nth-child(2) { text-align: center; }
.author-bio, .author-notes { max-width: 70ch; margin-bottom: 1.5rem; }
.author-form { max-width: 70ch; }
.author-form textarea { width: 100%; font: inherit; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px; }
.detail-authors a { color: inherit; text-decoration: underline dotted; }
.detail-authors a:hover { color: var(--accent); }

/* === Bestellliste === */
.nav-order .badge { background: #2f6b3a; }
.book-card { position: relative; }
.order-toggle-compact { position: absolute; top: .4rem; right: .4rem; z-index: 2; margin: 0; }
.btn-icon { border: 1px solid var(--line); background: rgba(255, 255, 255, .92); border-radius: 999px; width: 2rem; height: 2rem; cursor: pointer; font-size: 1rem; line-height: 1; opacity: .75; }
.btn-icon:hover { opacity: 1; box-shadow: var(--shadow); }
.btn-icon.is-on { background: #2f6b3a; border-color: #2f6b3a; opacity: 1; }
.book-card.on-order-list { outline: 2px solid #2f6b3a; }
.btn.btn-on { background: #2f6b3a; color: #fff; border-color: #2f6b3a; }
.order-table td { vertical-align: middle; }
.order-cover img { width: 44px; height: auto; border-radius: 3px; display: block; }
.order-actions form { margin: 0; }
.btn-small { padding: .25rem .6rem; font-size: .85em; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }

/* === Detailseite: Kategorie-Pills einheitlich grau, ohne Farbcodierung === */
.detail-categories .tag { background: #e9e6e1; color: #3b3b3b; }
.detail-categories .tag-link:hover { background: #dedad4; filter: none; }

/* === Detailseite: Autor:innen · Seitenzahl === */
.detail-authors .sep { margin: 0 .4em; color: var(--muted); }
.detail-authors .detail-pages { color: var(--muted); white-space: nowrap; }
