@import url('https://fonts.googleapis.com/css2?family=Libre+Baskerville:ital,wght@0,400;0,700;1,400&family=Source+Sans+3:wght@300;400;500;600&display=swap');

:root {
    --bg: #faf6f0;
    --bg-card: #ffffff;
    --bg-nav: #2c2418;
    --text: #2c2418;
    --text-muted: #7a6f63;
    --text-light: #a89e93;
    --accent: #c0553a;
    --accent-hover: #a8432a;
    --green: #4a7c59;
    --green-light: #e8f0ea;
    --blue: #3d6b8e;
    --blue-light: #e4eef5;
    --amber: #b8860b;
    --amber-light: #fdf3dc;
    --red: #9e3a3a;
    --red-light: #fbe8e8;
    --border: #e5ded4;
    --shadow: 0 1px 3px rgba(44, 36, 24, 0.08);
    --shadow-lg: 0 4px 12px rgba(44, 36, 24, 0.12);
    --radius: 6px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Source Sans 3', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

h1, h2, h3 {
    font-family: 'Libre Baskerville', serif;
    font-weight: 700;
    line-height: 1.3;
}

/* ── Nav ─────────────────────────────────────────── */

nav {
    background: var(--bg-nav);
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
}

nav .brand {
    font-family: 'Libre Baskerville', serif;
    color: #faf6f0;
    font-size: 1.1rem;
    text-decoration: none;
    letter-spacing: -0.01em;
}

nav .brand span { color: var(--accent); }

nav .links {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

nav .links a {
    color: #c4bdb3;
    text-decoration: none;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.88rem;
    font-weight: 500;
    transition: all 0.15s;
}

nav .links a:hover,
nav .links a.active {
    color: #faf6f0;
    background: rgba(255,255,255,0.08);
}

nav .links a.active { background: rgba(255,255,255,0.12); }

nav .user-info {
    color: var(--text-light);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

nav .user-info .username { color: #c4bdb3; }

/* ── Layout ──────────────────────────────────────── */

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 1.6rem;
    margin-bottom: 0.25rem;
}

.page-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* ── Search ──────────────────────────────────────── */

.search-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.search-form input[type="search"] {
    flex: 1;
    padding: 0.7rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
    background: var(--bg-card);
    transition: border-color 0.15s;
}

.search-form input[type="search"]:focus {
    outline: none;
    border-color: var(--accent);
}

.search-form button {
    padding: 0.7rem 1.5rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
}

.search-form button:hover { background: var(--accent-hover); }

/* ── Book Cards ──────────────────────────────────── */

.book-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.book-card {
    display: flex;
    gap: 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    transition: box-shadow 0.15s;
}

.book-card:hover { box-shadow: var(--shadow-lg); }

.book-cover {
    width: 80px;
    min-width: 80px;
    height: 120px;
    border-radius: 4px;
    object-fit: cover;
    background: var(--border);
}

.book-cover-placeholder {
    width: 80px;
    min-width: 80px;
    height: 120px;
    border-radius: 4px;
    background: linear-gradient(135deg, var(--border) 0%, #d4cdc3 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.7rem;
    text-align: center;
    padding: 0.5rem;
}

.book-info { flex: 1; min-width: 0; }

.book-info h3 {
    font-size: 1.05rem;
    margin-bottom: 0.15rem;
    font-family: 'Libre Baskerville', serif;
}

.book-info .author {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.book-info .meta {
    font-size: 0.82rem;
    color: var(--text-light);
    margin-bottom: 0.75rem;
}

.book-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

/* ── Badges & Buttons ────────────────────────────── */

.badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 99px;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.badge-requested { background: var(--blue-light); color: var(--blue); }
.badge-in-library { background: var(--green-light); color: var(--green); }
.status-pending { background: var(--amber-light); color: var(--amber); }
.status-approved { background: var(--blue-light); color: var(--blue); }
.status-acquired { background: var(--blue-light); color: var(--blue); }
.status-available { background: var(--green-light); color: var(--green); }
.status-rejected { background: var(--red-light); color: var(--red); }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem 0.75rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}

.btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.78rem;
}

.btn-primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: white;
}

.btn-green {
    background: var(--green);
    color: white;
    border-color: var(--green);
}

.btn-red {
    background: var(--red);
    color: white;
    border-color: var(--red);
}

/* ── Star Rating ──────────────────────────────── */

.star-rating {
    display: inline-flex;
    align-items: center;
    gap: 0.1rem;
}

.star-rating .star {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.3rem;
    color: var(--border);
    padding: 0.1rem;
    transition: color 0.1s, transform 0.1s;
    line-height: 1;
}

.star-rating .star:hover,
.star-rating .star:hover ~ .star { color: var(--amber); }

/* Reverse hover direction: highlight all stars up to hovered one */
.star-rating:hover .star { color: var(--amber); }
.star-rating .star:hover ~ .star { color: var(--border); }

.star-rating .star.active { color: var(--amber); }

.star-rating .star-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-left: 0.35rem;
    font-weight: 500;
}

/* ── Tables ──────────────────────────────────────── */

.request-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.request-table th {
    text-align: left;
    padding: 0.75rem 1rem;
    background: var(--bg-nav);
    color: #c4bdb3;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.request-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    vertical-align: middle;
}

.request-table tr:last-child td { border-bottom: none; }
.request-table tr:hover td { background: rgba(192, 85, 58, 0.02); }

/* ── Forms ───────────────────────────────────────── */

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
    color: var(--text);
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    background: var(--bg-card);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-row .form-group { flex: 1; }

.form-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.form-card h2 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

/* ── Alerts ──────────────────────────────────────── */

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.alert-success { background: var(--green-light); color: var(--green); border: 1px solid #b5d4be; }
.alert-error { background: var(--red-light); color: var(--red); border: 1px solid #e8b8b8; }

/* ── Login Page ──────────────────────────────────── */

.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
}

.login-card h1 {
    text-align: center;
    font-size: 1.4rem;
    margin-bottom: 0.25rem;
}

.login-card h1 span { color: var(--accent); }

.login-card p {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

/* ── Empty States ────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--text);
}

/* ── Vote count ──────────────────────────────────── */

.vote-count {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ── Spinner (used by admin sync buttons only) ───── */

.sync-spinner {
    display: none;
    width: 13px;
    height: 13px;
    border: 2px solid rgba(255,255,255,0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
.htmx-request .sync-spinner {
    display: inline-block;
}

/* ── Responsive ──────────────────────────────────── */

@media (max-width: 640px) {
    nav { padding: 0 1rem; }
    .container { padding: 1.25rem 1rem; }
    .book-card { flex-direction: column; align-items: center; text-align: center; }
    .book-actions { justify-content: center; }
    .form-row { flex-direction: column; }
    nav .links { gap: 0; }
    nav .links a { padding: 0.4rem 0.5rem; font-size: 0.8rem; }
}

/* ── Status Select (inline) ──────────────────────── */

.status-select {
    padding: 0.25rem 0.4rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.82rem;
    font-family: inherit;
    background: var(--bg-card);
    cursor: pointer;
}

/* ── Checkbox ────────────────────────────────────── */

input[type="checkbox"] {
    accent-color: var(--accent);
}

/* ── Reading Status Dropdown ─────────────────────── */

.reading-status-select {
    padding: 0.25rem 0.4rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-family: inherit;
    background: var(--bg-card);
    cursor: pointer;
}

.reading-status-select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ── Search progress bar ─────────────────────────────── */
/*
   HTMX adds .htmx-request directly to the element named in hx-indicator.
   So: form[hx-indicator="#search-progress"] causes HTMX to add .htmx-request
   to #search-progress while the request is in flight.
*/

.search-progress {
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    margin-bottom: 1.5rem;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: none;
}

.search-progress.htmx-request {
    opacity: 1;
}

.search-progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    width: 0%;
}

.search-progress.htmx-request .search-progress-bar {
    animation: search-progress-fill 8s cubic-bezier(0.1, 0.4, 0.2, 1) forwards;
}

@keyframes search-progress-fill {
    0%   { width: 0%;  }
    15%  { width: 30%; }
    40%  { width: 55%; }
    70%  { width: 75%; }
    90%  { width: 85%; }
    100% { width: 88%; }
}

/* ── Repeat / re-read buttons ────────────────────────── */

.repeat-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.repeat-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.22rem 0.65rem;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 500;
    font-family: inherit;
    border: 1.5px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.repeat-btn:hover {
    border-color: #aaa;
    color: var(--text);
}

.repeat-btn--active-read {
    border-color: var(--green);
    background: var(--green-light);
    color: var(--green);
}

.repeat-btn--active-listen {
    border-color: var(--blue);
    background: var(--blue-light);
    color: var(--blue);
}

/* ── Admin sync section ──────────────────────────────── */

.sync-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

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

.sync-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem;
}

.sync-card-header {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin-bottom: 0.65rem;
}

.sync-icon {
    font-size: 1.2rem;
    line-height: 1;
}

.btn-sync {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-sync--calibre {
    background: var(--green);
    color: #fff;
}

.btn-sync--calibre:hover { background: #3a6347; }

.btn-sync--abs {
    background: var(--blue);
    color: #fff;
}

.btn-sync--abs:hover { background: #2d5070; }

.btn-sync:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.sync-spinner {
    display: none;
    width: 13px;
    height: 13px;
    border: 2px solid rgba(255,255,255,0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.sync-spinner.htmx-request {
    display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Sync result partial ─────────────────────────────── */

.sync-result {
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius);
    font-size: 0.84rem;
    line-height: 1.5;
}

.sync-result--ok {
    background: var(--green-light);
    border: 1px solid var(--green);
    color: #1e4a28;
}

.sync-result--warn {
    background: var(--amber-light);
    border: 1px solid var(--amber);
    color: #5a3e00;
}

.sync-result-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.sync-errors {
    margin-top: 0.5rem;
    padding-left: 1.1rem;
    color: var(--red);
    font-size: 0.8rem;
}

/* ── My Reads toolbar ────────────────────────────── */

.reads-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.reads-count {
    font-size: 0.88rem;
    color: var(--text-muted);
}

.btn-ghost {
    background: none;
    border: 1.5px solid var(--border);
    color: var(--text-muted);
    font-size: 0.82rem;
    padding: 0.25rem 0.7rem;
    border-radius: var(--radius);
    text-decoration: none;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.btn-ghost:hover {
    border-color: #aaa;
    color: var(--text);
}

/* ── Won't read card state ───────────────────────── */

.book-card--wont-read {
    opacity: 0.55;
}

.book-title-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.15rem;
}

.book-format-badges {
    display: flex;
    gap: 0.25rem;
    flex-shrink: 0;
    margin-top: 0.1rem;
}

.wont-read-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.5rem;
}

.wont-read-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
}

/* ── Won't read repeat button variant ───────────── */

.repeat-btn--wont-read {
    color: var(--red);
    border-color: var(--red-light);
}

.repeat-btn--wont-read:hover {
    background: var(--red-light);
    border-color: var(--red);
}

/* ── My Reads — filter bar ───────────────────────── */

.reads-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1.1rem;
}

.filter-input {
    flex: 1;
    min-width: 160px;
    padding: 0.45rem 0.75rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.88rem;
    font-family: inherit;
    background: var(--bg-card);
    color: var(--text);
}

.filter-input:focus {
    outline: none;
    border-color: var(--accent);
}

.filter-select {
    padding: 0.45rem 0.6rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-family: inherit;
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
}

.reads-count {
    font-size: 0.84rem;
    color: var(--text-muted);
    margin-left: auto;
    white-space: nowrap;
}

/* ── My Reads — table ────────────────────────────── */

.reads-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    box-shadow: var(--shadow);
}

.reads-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.reads-table thead th {
    background: var(--bg);
    padding: 0.6rem 0.85rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    user-select: none;
}

.reads-table thead th.sortable:hover {
    color: var(--text);
}

.sort-icon {
    opacity: 0.45;
    font-size: 0.75rem;
    margin-left: 2px;
}

.reads-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

.reads-table tbody tr:last-child {
    border-bottom: none;
}

.reads-table tbody tr:hover {
    background: var(--bg);
}

.reads-table td {
    padding: 0.6rem 0.85rem;
    vertical-align: middle;
}

.col-title  { min-width: 200px; }
.col-author { min-width: 120px; color: var(--text-muted); }
.col-format { width: 70px; text-align: center; }
.col-rating { width: 110px; }
.col-status { width: 150px; }
.col-repeat { width: 70px; text-align: center; }
.col-actions { width: 40px; text-align: center; }

.title-cell {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.row-cover {
    width: 32px;
    height: 46px;
    object-fit: cover;
    border-radius: 3px;
    flex-shrink: 0;
    background: var(--border);
}

.fmt-badge {
    font-size: 0.95rem;
    line-height: 1;
}

.status-compact {
    padding: 0.2rem 0.4rem;
    border: 1.5px solid var(--border);
    border-radius: 4px;
    font-size: 0.78rem;
    font-family: inherit;
    color: var(--text);
    background: var(--bg-card);
    cursor: pointer;
    width: 100%;
}

/* ── Repeat pills (compact, icon-only for table) ─── */

.repeat-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    padding: 0;
    line-height: 1;
}

.repeat-pill:hover {
    border-color: #aaa;
    color: var(--text);
}

.repeat-pill--read {
    border-color: var(--green);
    background: var(--green-light);
    color: var(--green);
}

.repeat-pill--listen {
    border-color: var(--blue);
    background: var(--blue-light);
    color: var(--blue);
}

/* ── Won't read / restore icon buttons ───────────── */

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 4px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.82rem;
    transition: background 0.15s, color 0.15s;
    padding: 0;
}

.btn-wont-read {
    color: var(--text-light);
}

.btn-wont-read:hover {
    background: var(--red-light);
    color: var(--red);
}

.btn-restore {
    color: var(--green);
}

.btn-restore:hover {
    background: var(--green-light);
}

/* Won't-read rows are dimmed */
.read-row[data-wont-read="true"] {
    opacity: 0.45;
}

.no-results-msg {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem 0;
    font-size: 0.95rem;
}
