:root {
    --bg: #f6f1e7;
    --surface: #ffffff;
    --ink: #2c2420;
    --muted: #7a6f63;
    --line: #e6ddcf;
    --primary: #8a5a2b;
    --primary-dark: #6f4620;
    --accent: #2f6f4f;
    --accent-soft: #e4f0e8;
    --danger: #b3402f;
    --shadow: 0 2px 8px rgba(60, 40, 20, .08);
    --radius: 14px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1000px; margin: 0 auto; padding: 0 20px; }

/* Header */
.site-header {
    background: linear-gradient(120deg, var(--primary), var(--primary-dark));
    color: #fff;
    padding: 22px 0;
    box-shadow: var(--shadow);
}
.site-header .container { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.site-header .brand { color: #fff; }
.user-chip { color: #fff; font-size: .9rem; font-weight: 600; opacity: .95; padding: 0 4px; }

/* Auth-Seiten */
.auth-wrap { max-width: 420px; margin: 40px auto; }
.auth-card h1 { margin: 0 0 4px; font-size: 1.5rem; }
.auth-card .subtitle { margin: 0 0 20px; }
.auth-alt { margin: 18px 0 0; text-align: center; font-size: .9rem; color: var(--muted); }
.auth-remember { display: flex; align-items: center; gap: 7px; font-weight: 400; font-size: .9rem; }
.auth-remember input { width: auto; }
.brand { display: flex; align-items: center; gap: 12px; font-size: 1.5rem; font-weight: 700; }
.brand .logo { font-size: 1.8rem; }

main { padding: 32px 0 64px; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 7px;
    background: var(--primary); color: #fff;
    border: none; border-radius: 10px;
    padding: 10px 16px; font-size: .95rem; font-weight: 600;
    cursor: pointer; transition: background .15s, transform .05s;
    text-decoration: none; font-family: inherit;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 6px 11px; font-size: .82rem; border-radius: 8px; }
.btn-light { background: #fff; color: var(--primary); border: 1px solid var(--line); }
.btn-light:hover { background: #faf6ee; }
.btn-accent { background: var(--accent); }
.btn-accent:hover { background: #245a3f; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn-ghost:hover { background: #faf6ee; color: var(--ink); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid #e7c9c3; }
.btn-danger:hover { background: #fbeeeb; }

/* Flash message */
.flash {
    background: var(--accent-soft); border: 1px solid #bfe0cd; color: #245a3f;
    padding: 12px 16px; border-radius: 10px; margin-bottom: 22px;
    display: flex; align-items: center; gap: 8px;
}

/* Cards grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }

.card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
    overflow: hidden; display: flex; flex-direction: column;
}
.card-body { padding: 18px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-cover {
    height: 150px; background: #efe6d6; display: flex; align-items: center; justify-content: center;
    color: var(--muted); overflow: hidden;
}
.card-cover img { width: 100%; height: 100%; object-fit: cover; }

/* Generierter Cover-Platzhalter, wenn kein Bild vorhanden ist */
.cover-gen {
    width: 100%; height: 100%; box-sizing: border-box;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    text-align: center; gap: 6px; padding: 16px;
    background: linear-gradient(155deg, hsl(var(--h, 28) 46% 85%), hsl(var(--h, 28) 44% 66%));
    color: #34291d;
}
.cover-gen-title { font-weight: 800; font-size: 1rem; line-height: 1.2; }
.cover-gen-author { font-size: .76rem; opacity: .78; }
.cover-hero-box { width: 160px; height: 220px; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); flex: none; }

/* Filter-Reiter */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 24px; }
.filter-tab {
    padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line);
    background: #fff; color: var(--muted); font-size: .88rem; font-weight: 600;
}
.filter-tab:hover { background: #faf6ee; color: var(--ink); text-decoration: none; }
.filter-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.filter-tab .cnt { opacity: .7; font-weight: 500; margin-left: 3px; }
.card-title { font-size: 1.15rem; font-weight: 700; margin: 0; }
.card-author { color: var(--muted); font-size: .9rem; margin: 0; }

.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .82rem; color: var(--muted); margin-top: 4px; }
.meta span { display: inline-flex; align-items: center; gap: 5px; }

/* Progress bar */
.progress { background: #eee3d2; height: 8px; border-radius: 6px; overflow: hidden; margin-top: 6px; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.progress-label { font-size: .78rem; color: var(--muted); margin-top: 4px; }

/* Seiten-Fortschritt (Bücher ohne Kapitel) */
.page-form { margin-top: 14px; }
.page-form label { font-size: .82rem; margin-bottom: 6px; display: block; }
.page-form-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-form-row input { width: 100px; }
.page-of { color: var(--muted); font-size: .9rem; }

/* Badges */
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.badge-done { background: var(--accent-soft); color: #245a3f; }
.badge-reading { background: #fdf0dd; color: #92601d; }
.badge-open { background: #efe9df; color: var(--muted); }
.badge-abandoned { background: #f3e6e2; color: #8a4b3b; }

/* Forms */
.panel {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px;
}
.form-row { margin-bottom: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
input[type=text], input[type=number], input[type=date], input[type=url], input[type=email], input[type=password], textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
    font-size: .95rem; font-family: inherit; background: #fffdf9; color: var(--ink);
}
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
textarea { resize: vertical; min-height: 70px; }
.hint { font-size: .8rem; color: var(--muted); margin-top: 5px; }
.error { color: var(--danger); font-size: .82rem; margin-top: 5px; }
.input-with-btn { display: flex; gap: 8px; }
.input-with-btn input { flex: 1; }

/* Cover hochladen (Formular) */
.cover-edit { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.cover-edit-preview { width: 84px; flex: none; }
.cover-edit-preview img { width: 84px; height: 116px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.cover-edit-empty { width: 84px; height: 116px; border-radius: 8px; background: #efe6d6; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .75rem; text-align: center; }
.cover-edit-fields { flex: 1; min-width: 220px; }
.cover-remove { font-weight: 400; font-size: .85rem; display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.cover-remove input { width: auto; }

/* Page heads */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 1.6rem; }
.subtitle { color: var(--muted); margin: 2px 0 0; }

/* Book detail header */
.book-hero { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.book-hero .cover { width: 160px; min-height: 220px; border-radius: 12px; background: #efe6d6; box-shadow: var(--shadow); object-fit: cover; }
.book-hero .cover-empty { width: 160px; height: 220px; border-radius: 12px; background: #efe6d6; display: flex; align-items: center; justify-content: center; font-size: 3rem; color: var(--muted); box-shadow: var(--shadow); }
.book-info { flex: 1; min-width: 260px; }
.book-info h1 { margin: 0 0 4px; }
.stat-row { display: flex; flex-wrap: wrap; gap: 18px; margin: 16px 0; }
.stat { background: #fffdf9; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; min-width: 90px; }
.stat .label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.15rem; font-weight: 700; }

/* Chapters */
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 34px 0 14px; }
.section-title h2 { margin: 0; font-size: 1.3rem; }
.chapter-list { display: flex; flex-direction: column; gap: 10px; }
.chapter {
    background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
    padding: 12px 16px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.chapter.done { background: #f4faf6; border-color: #cfe7d8; }
.chapter .num {
    width: 34px; height: 34px; flex: none; border-radius: 8px; background: #efe6d6;
    display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--primary-dark);
}
.chapter.done .num { background: var(--accent); color: #fff; }
.chapter .ch-main { flex: 1; min-width: 180px; }
.chapter .ch-title { font-weight: 600; }
.chapter .ch-dates { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.chapter .ch-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.chapter .ch-name { font-weight: 600; }

/* Drei-Punkte-Menü (⋯) */
.menu { position: relative; }
.menu > summary {
    list-style: none; cursor: pointer; user-select: none;
    width: 34px; height: 34px; border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.25rem; line-height: 1; color: var(--muted);
    border: 1px solid var(--line); background: #fff;
}
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary::marker { content: ""; }
.menu > summary:hover { background: #faf6ee; color: var(--ink); }
.menu[open] > summary { background: #faf6ee; color: var(--ink); }
.menu-panel {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
    background: #fff; border: 1px solid var(--line); border-radius: 12px;
    box-shadow: 0 10px 30px rgba(60, 40, 20, .18); padding: 14px; width: 250px;
}
.menu-panel .form-row { margin-bottom: 12px; }
.menu-panel label { font-size: .8rem; margin-bottom: 4px; }
.menu-panel input { padding: 8px 10px; font-size: .88rem; }
.menu-divider { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
.menu-panel .btn { width: 100%; justify-content: center; }

/* Menü, dessen Auslöser wie ein normaler Button aussieht (Buch „fertig") */
.menu-btn > summary {
    width: auto; height: auto; border: none;
    padding: 10px 16px; gap: 7px; font-size: .95rem; font-weight: 600;
    background: var(--accent); color: #fff;
}
.menu-btn > summary:hover { background: #245a3f; color: #fff; }
.menu-btn[open] > summary { background: #245a3f; color: #fff; }
.menu-btn .menu-panel { left: 0; right: auto; width: 260px; }
.menu-panel .menu-note { font-size: .78rem; color: var(--muted); margin: 0 0 8px; }

/* Kapitel „Fertig"-Auslöser: kleiner grüner Button mit Datums-Auswahl */
.menu-finish > summary {
    width: auto; height: auto; border: none;
    padding: 6px 11px; font-size: .82rem; font-weight: 600; gap: 6px;
    background: var(--accent); color: #fff;
}
.menu-finish > summary:hover { background: #245a3f; color: #fff; }
.menu-finish[open] > summary { background: #245a3f; color: #fff; }
.menu-finish .menu-panel { right: 0; left: auto; width: 230px; }

/* „Aufgeben"-Auslöser: dezent, nicht alarmierend */
.menu-abandon > summary { background: #fff; color: var(--muted); border: 1px solid var(--line); }
.menu-abandon > summary:hover { background: #faf6ee; color: var(--ink); }
.menu-abandon[open] > summary { background: #faf6ee; color: var(--ink); }

.inline-form { display: inline; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty .big { font-size: 3rem; }

.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
hr.soft { border: none; border-top: 1px solid var(--line); margin: 22px 0; }

@media (max-width: 640px) {
    .form-grid { grid-template-columns: 1fr; }
}
