/*
 * Book Library — Responsive Stylesheet
 * Compatible with Safari, Chrome, Edge, Firefox
 */

/* ============================
   Reset & Base
   ============================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary-color:  #2563eb;
    --primary-hover:  #1d4ed8;
    --text-color:     #1f2937;
    --text-muted:     #6b7280;
    --bg-color:       #f9fafb;
    --card-bg:        #ffffff;
    --border-color:   #e5e7eb;
    --shadow:         0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md:      0 4px 6px rgba(0, 0, 0, 0.1);
    --radius:         8px;
    --transition:     0.2s ease;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    width: 100%;
    max-width: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ============================
   Accessibility
   ============================ */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #000;
    color: #fff;
    padding: 0.5rem 1rem;
    z-index: 1000;
    text-decoration: none;
    font-weight: 600;
    transition: top 0.2s ease;
}
.skip-link:focus { top: 0; outline: 3px solid #fbbf24; outline-offset: 2px; }

.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

*:focus { outline: 2px solid var(--primary-color); outline-offset: 2px; }
*:focus:not(:focus-visible) { outline: none; }
*:focus-visible { outline: 3px solid var(--primary-color); outline-offset: 2px; }

/* ============================
   Layout
   ============================ */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

main {
    padding: 2rem 0;
}

/* ============================
   Header & Navigation
   ============================ */
.site-header {
    background: var(--card-bg);
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 70px;
}

.logo a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: var(--text-color);
}
.logo-icon { font-size: 1.75rem; }
.logo-text  { font-size: 1.25rem; font-weight: 700; color: var(--primary-color); }

/* Desktop: show nav, hide hamburger */
.main-nav { display: flex; }

.nav-list {
    display: flex;
    list-style: none;
    gap: 0.5rem;
}
.nav-list a {
    display: block;
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: var(--text-color);
    font-weight: 500;
    border-radius: var(--radius);
    transition: background-color var(--transition), color var(--transition);
}
.nav-list a:hover { background-color: var(--bg-color); color: var(--primary-color); }
.nav-list a.active { background-color: var(--primary-color); color: #fff; }

/* Hamburger */
.hamburger-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 44px; height: 44px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    gap: 5px;
}
.hamburger-line {
    display: block;
    width: 24px; height: 3px;
    background-color: var(--text-color);
    border-radius: 2px;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

@media (min-width: 901px) {
    .hamburger-btn { display: none !important; }
    .main-nav { display: flex !important; position: static; background: none; box-shadow: none; }
}

@media (max-width: 900px) {
    .hamburger-btn { display: flex !important; }
    .main-nav {
        position: absolute;
        top: 70px; left: 0; right: 0;
        background: var(--card-bg);
        box-shadow: var(--shadow-md);
        flex-direction: column;
        z-index: 999;
        width: 100%;
    }
    .nav-list { flex-direction: column; gap: 0; width: 100%; }
    .nav-list li { width: 100%; }
    .nav-list a {
        padding: 1rem;
        border-radius: 0;
        border-bottom: 1px solid var(--border-color);
        width: 100%;
    }
    .nav-list li:last-child a { border-bottom: none; }
}

/* Header search (site-wide) */
.header-search {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: 1rem;
}
.header-search .search-input {
    width: 18rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.95rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--card-bg);
}
.header-search .search-btn {
    padding: 0.45rem 0.75rem;
    font-size: 0.95rem;
    font-weight: 600;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}
.header-search .search-btn:hover { background: var(--primary-hover); }
.scan-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem 0.5rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
}
.scan-btn:hover { background: var(--bg-color); }

@media (max-width: 900px) {
    /* hide the inline header search on small screens to keep header compact */
    .header-search { display: none; }
}

/* When the lightweight test widget is placed in the header, show result beside the form */
.site-header .test-search-widget {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.45rem 0;
}
.site-header .test-search-widget .header-search {
    margin: 0;
}
.site-header .test-search-widget .book-result {
    flex: 0 0 520px;
    max-width: 520px;
    margin: 0;
}
.site-header .test-search-widget .alert { margin: 0; align-self: flex-start; }

@media (max-width: 900px) {
    .site-header .test-search-widget { display: block; }
    .site-header .test-search-widget .book-result { max-width: none; margin-top: 0.75rem; }
}

/* ============================
   Category summary column themes
   ============================ */

.category-summary .summary-table { border-collapse: separate !important; border-spacing: 10px; }
.category-summary table thead th { color: #0b1221; }
.category-summary table td { color: #0b1221; }

/* High-contrast, vibrant column themes */
.category-summary .quran-commentaries {
    background: linear-gradient(90deg, #0f766e 0%, #14b8a6 100%);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(20,184,166,0.18);
}
.category-summary .seerah-hadith {
    background: linear-gradient(90deg, #7c3aed 0%, #6d28d9 100%);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(109,40,217,0.18);
}
.category-summary .spirituality-sufism {
    background: linear-gradient(90deg, #16a34a 0%, #059669 100%);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(5,150,105,0.14);
}
.category-summary .muslim-america {
    background: linear-gradient(90deg, #0ea5e9 0%, #0284c7 100%);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(2,132,199,0.14);
}
.category-summary .sociology-anthropology {
    background: linear-gradient(90deg, #06b6d4 0%, #0ea5a4 100%);
    color: #052f2f;
    box-shadow: 0 2px 6px rgba(6,182,212,0.12);
}
.category-summary .congregational-study {
    background: linear-gradient(90deg, #f97316 0%, #f59e0b 100%);
    color: #1a1206;
    box-shadow: 0 2px 6px rgba(245,158,11,0.12);
}
.category-summary .poetry-literature {
    background: linear-gradient(90deg, #c084fc 0%, #7c3aed 100%);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(124,58,237,0.12);
}
.category-summary .children {
    background: linear-gradient(90deg, #fb923c 0%, #f59e0b 100%);
    color: #1a1206;
    box-shadow: 0 2px 6px rgba(245,158,11,0.12);
}
.category-summary .others {
    background: linear-gradient(90deg, #6b7280 0%, #374151 100%);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(55,65,81,0.16);
}

/* Improve header cell appearance (rounding and separation) */
.category-summary table thead th { padding-top: 0.95rem; padding-bottom: 0.95rem; }
.category-summary table td { background: transparent; }

/* Page-header banner variants when category-summary is used as banner */
.page-header.category-summary {
    /* light bluish-yellow banner background */
    background: linear-gradient(135deg, #fff9c4 0%, #e6f0ff 100%) !important;
    background-color: #fff9c4 !important;
    color: var(--text-color) !important;
    padding: 0.6rem 0.75rem;
}
.page-header.category-summary .summary-table th,
.page-header.category-summary .summary-table td {
    border-bottom: none;
    color: var(--text-color);
}
.page-header.category-summary .quran-commentaries {
    background: linear-gradient(180deg, #0f766e 0%, #14b8a6 100%);
    color: #fff;
}
.page-header.category-summary .seerah-hadith {
    background: linear-gradient(180deg, #8b5cf6 0%, #6d28d9 100%);
    color: #fff;
}
.page-header.category-summary .spirituality-sufism {
    background: linear-gradient(180deg, #34d399 0%, #059669 100%);
    color: #052f21;
}
.page-header.category-summary .muslim-america {
    background: linear-gradient(180deg, #0ea5e9 0%, #0284c7 100%);
    color: #fff;
}
.page-header.category-summary .sociology-anthropology {
    background: linear-gradient(180deg, #5eead4 0%, #06b6d4 100%);
    color: #052f2f;
}
.page-header.category-summary .congregational-study {
    background: linear-gradient(180deg, #fb923c 0%, #f97316 100%);
    color: #1a1206;
}
.page-header.category-summary .poetry-literature {
    background: linear-gradient(180deg, #c084fc 0%, #7c3aed 100%);
    color: #fff;
}
.page-header.category-summary .children {
    background: linear-gradient(180deg, #fb923c 0%, #f97316 100%);
    color: #1a1206;
}
.page-header.category-summary .others {
    background: linear-gradient(180deg, #6b7280 0%, #374151 100%);
    color: #fff;
}

.page-header.category-summary .summary-table th,
.page-header.category-summary .summary-table td {
    border-radius: 8px;
    padding: 0.6rem 0.9rem;
}

.page-header.category-summary .summary-table a { color: inherit; text-decoration: none; font-weight: 800; }
.page-header.category-summary .summary-table a:hover { text-decoration: underline; opacity: 0.95; }

@media (max-width: 700px) {
    .page-header.category-summary .summary-table th,
    .page-header.category-summary .summary-table td { padding: 0.4rem 0.5rem; font-size: 0.95rem; }
}

/* Library-specific banner: green theme */
.page-header.category-summary.library-banner {
    /* keep library banner same light bluish-yellow for consistency */
    background: linear-gradient(135deg, #fff9c4 0%, #e6f0ff 100%) !important;
    background-color: #fff9c4 !important;
    color: var(--text-color) !important;
}
.page-header.category-summary.library-banner .summary-table th,
.page-header.category-summary.library-banner .summary-table td {
    color: rgba(255,255,255,0.98);
}
.page-header.category-summary.library-banner .quran-commentaries { background: linear-gradient(180deg, #0f766e 0%, #14b8a6 100%); }
.page-header.category-summary.library-banner .seerah-hadith { background: linear-gradient(180deg, #9f7aea 0%, #7c3aed 100%); }
.page-header.category-summary.library-banner .spirituality-sufism { background: linear-gradient(180deg, #34d399 0%, #10b981 100%); }
.page-header.category-summary.library-banner .muslim-america { background: linear-gradient(180deg, #38bdf8 0%, #0ea5e9 100%); }
.page-header.category-summary.library-banner .sociology-anthropology { background: linear-gradient(180deg, #5eead4 0%, #06b6d4 100%); }
.page-header.category-summary.library-banner .congregational-study { background: linear-gradient(180deg, #fbbf24 0%, #fb923c 100%); }
.page-header.category-summary.library-banner .poetry-literature { background: linear-gradient(180deg, #c084fc 0%, #7c3aed 100%); }
.page-header.category-summary.library-banner .children { background: linear-gradient(180deg, #fbbf24 0%, #fb923c 100%); }
.page-header.category-summary.library-banner .others { background: linear-gradient(180deg, #4b5563 0%, #1f2937 100%); }
.page-header.category-summary.library-banner .total { background: linear-gradient(180deg, #60a5fa 0%, #3b82f6 100%); color: #fff; }

/* make cells slightly rounded and separated */
.page-header.category-summary .summary-table th,
.page-header.category-summary .summary-table td {
    border-radius: 6px;
}

/* ============================
   Page Header Banner
   ============================ */
.page-header {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: #fff;
    padding: 2.5rem 1rem;
    text-align: center;
    margin-bottom: 2rem;
}
.page-header h1 { font-size: 2rem; font-weight: 700; margin-bottom: 0.25rem; }
.page-header p  { font-size: 1.1rem; opacity: 0.9; }

/* ============================
   Search Form
   ============================ */
.search-section {
    max-width: 600px;
    margin: 0 auto 2.5rem;
}

.search-form {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.search-input {
    flex: 1;
    min-width: 200px;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--card-bg);
    color: var(--text-color);
    transition: border-color var(--transition);
}
.search-input:focus { border-color: var(--primary-color); outline: none; }
.search-input::placeholder { color: var(--text-muted); }

.search-btn {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background-color var(--transition), transform var(--transition);
    white-space: nowrap;
}
.search-btn:hover  { background: var(--primary-hover); transform: translateY(-1px); }
.search-btn:active { transform: translateY(0); }

.search-hint {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    text-align: center;
}

/* ============================
   Alerts / Messages
   ============================ */
.alert {
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}
.alert-error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

/* ============================
   Book Detail Card (search result)
   ============================ */
.book-result {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    max-width: 860px;
    margin: 0 auto;
}

/* Two-column library list for unauthenticated index view */
.two-column-books {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}
.two-column-books .table-wrapper { flex: 1; }
.two-column-books .library-table { width: 100%; }

@media (max-width: 900px) {
    .two-column-books { flex-direction: column; }
}

/* Library table (used by index.php) */
.table-wrapper { margin-bottom: 1rem; }
.library-table { width: 100%; border-collapse: collapse; }
.library-table thead th { text-align: left; padding: 0.6rem; font-weight: 700; color: var(--text-muted); border-bottom: 1px solid var(--border-color); }
.library-table tbody td { padding: 0.6rem; vertical-align: middle; border-bottom: 1px solid var(--border-color); background: var(--card-bg); }
.col-cover { width: 84px; }
.tbl-thumb { width: 64px; height: 96px; object-fit: cover; border-radius: 4px; display: block; }
.tbl-thumb-placeholder { width: 64px; height: 96px; display: flex; align-items: center; justify-content: center; background: var(--bg-color); color: var(--text-muted); border-radius: 4px; font-size: 1.25rem; border: 1px dashed var(--border-color); }
.col-book .tbl-title { font-weight: 700; color: var(--text-color); text-decoration: none; }
.col-book .tbl-sub { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.25rem; }
.col-subjects .tbl-subjects { color: var(--text-muted); font-size: 0.9rem; white-space: normal; word-break: break-word; max-width: none; overflow: visible; text-overflow: unset; }

@media (max-width: 900px) {
    .col-cover { width: 64px; }
    .tbl-thumb, .tbl-thumb-placeholder { width: 48px; height: 72px; }
    .library-table { display: block; }
    .library-table thead { display: none; }
    .library-table tbody tr { display: block; margin-bottom: 1rem; border: 1px solid var(--border-color); border-radius: var(--radius); background: var(--card-bg); padding: 0.75rem; }
    .library-table tbody td { display: grid; grid-template-columns: auto 1fr; gap: 0.65rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border-color); }
    .library-table tbody td:last-child { border-bottom: none; }
    .library-table tbody td::before { content: attr(data-label); font-weight: 700; color: var(--text-muted); white-space: nowrap; }
    .library-table tbody td .cat-picker,
    .library-table tbody td .notes-input { width: 100%; }
    .library-table tbody td .cat-options { max-width: 100%; }
}

.book-result-inner {
    display: flex;
    gap: 2rem;
    padding: 2rem;
    align-items: flex-start;
    flex-wrap: wrap;
}

.book-thumbnail {
    flex-shrink: 0;
    width: 160px;
}
.book-thumbnail img {
    width: 100%;
    height: auto;
    border-radius: 4px;
    box-shadow: var(--shadow-md);
    display: block;
}
.book-thumbnail-placeholder {
    width: 160px;
    height: 220px;
    background: var(--bg-color);
    border: 2px dashed var(--border-color);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 3rem;
}

.book-details {
    flex: 1;
    min-width: 200px;
}
.book-details h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 1rem;
    line-height: 1.3;
}

.book-meta {
    list-style: none;
    margin-bottom: 1rem;
}
.book-meta li {
    display: flex;
    gap: 0.5rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.95rem;
    flex-wrap: wrap;
}
.book-meta li:last-child { border-bottom: none; }
.book-meta .label {
    font-weight: 600;
    color: var(--text-muted);
    min-width: 90px;
}
.book-meta .value { color: var(--text-color); }

.book-description {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.95rem;
    color: var(--text-muted);
    line-height: 1.7;
}
.book-description strong { display: block; color: var(--text-color); margin-bottom: 0.25rem; }

/* Source badge */
.source-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 600;
    margin-top: 1rem;
}
.source-badge.api   { background: #ecfdf5; color: #065f46; }
.source-badge.cache { background: #eff6ff; color: #1e40af; }

/* ============================
   Library Grid (all books)
   ============================ */
.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1.5rem;
}

.book-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    display: block;
    transition: transform var(--transition), box-shadow var(--transition);
}
.book-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.book-card-thumb {
    width: 100%;
    aspect-ratio: 2 / 3;
    overflow: hidden;
    background: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
}
.book-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.book-card-thumb-placeholder {
    font-size: 3.5rem;
    color: var(--border-color);
}

.book-card-body {
    padding: 0.75rem;
}
.book-card-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 0.25rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.book-card-author {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.book-card-isbn {
    font-size: 0.75rem;
    color: var(--border-color);
    margin-top: 0.25rem;
    font-family: monospace;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 4rem; margin-bottom: 1rem; }
.empty-state h2 { font-size: 1.5rem; color: var(--text-color); margin-bottom: 0.5rem; }
.empty-state p  { margin-bottom: 1.5rem; }
.empty-state a  {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: #fff;
    border-radius: var(--radius);
    text-decoration: none;
    font-weight: 600;
    transition: background var(--transition);
}
.empty-state a:hover { background: var(--primary-hover); }

/* Library count */
.library-count {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* ============================
   Footer
   ============================ */
.site-footer {
    background: #1f2937;
    color: #f9fafb;
    padding: 1.5rem 0;
    margin-top: 4rem;
}
.footer-container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }
.footer-bottom { text-align: center; }
.footer-bottom p { color: #9ca3af; font-size: 0.875rem; }
.footer-bottom a { color: #60a5fa; text-decoration: none; }
.footer-bottom a:hover { text-decoration: underline; }

/* ============================
   Responsive tweaks
   ============================ */
@media (max-width: 600px) {
    .book-result-inner { flex-direction: column; padding: 1.25rem; }
    .book-thumbnail    { width: 120px; }
    .book-thumbnail-placeholder { width: 120px; height: 170px; }
    .page-header h1 { font-size: 1.5rem; }
    .library-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 1rem; }
}

/* Optional barcode scan section (below search form) */
.scan-alt {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1rem;
}
.scan-alt-sep {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted, #6b7280);
    font-weight: 600;
}

/* Scan button */
.scan-btn {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    background: #059669;
    color: #fff;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
    white-space: nowrap;
}
.scan-btn:hover { background: #047857; transform: translateY(-1px); }
.scan-btn:active { transform: translateY(0); }

/* ============================
   Barcode Scanner Modal
   ============================ */
.scanner-modal {
    display: none;          /* hidden by default — do NOT use 'display:flex' here,
                               it overrides the [hidden] attribute */
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.scanner-modal:not([hidden]) {
    display: flex;          /* only flex when the hidden attribute is removed */
}

.scanner-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
}

.scanner-box {
    position: relative;
    background: #fff;
    border-radius: var(--radius);
    overflow: hidden;
    width: min(420px, 95vw);
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

.scanner-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--primary-color);
    color: #fff;
    font-weight: 600;
}

.scanner-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 0 0.25rem;
}
.scanner-close:hover { opacity: 0.8; }

.scanner-viewport {
    position: relative;
    width: 100%;
    height: 300px;
    background: #000;
    overflow: hidden;
}

/* Quagga renders its own <video> and <canvas> inside #scanner-reader */
#scanner-reader {
    width: 100%;
    height: 100%;
    min-height: 240px;
}
#scanner-reader video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
/* Hide Quagga's debug drawing canvas */
#scanner-reader canvas.drawingBuffer { display: none; }

#scanner-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.scanner-status {
    text-align: center;
    padding: 0.6rem 1rem;
    font-size: 0.875rem;
    color: #374151;
    margin: 0;
    min-height: 2.2rem;
}

/* Add to Library button */
.add-btn {
    display: inline-block;
    padding: 0.6rem 1.25rem;
    font-size: 0.95rem;
    font-weight: 600;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
}
.add-btn:hover:not(:disabled) { background: var(--primary-hover); transform: translateY(-1px); }
.add-btn:disabled { opacity: 0.6; cursor: default; }

/* ============================
   Library Table
   ============================ */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    background: var(--card-bg);
}

.library-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.library-table thead {
    background: var(--primary-color);
    color: #fff;
}

.library-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
}

.library-table tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background-color var(--transition);
    vertical-align: top;
}

.library-table tbody tr:last-child {
    border-bottom: none;
}

.library-table tbody tr:hover {
    background-color: #f0f7ff;
}

.library-table td {
    padding: 0.75rem 1rem;
}

/* Column widths */
.col-cover       { width: 72px;  min-width: 72px; }
.col-book        { min-width: 200px; }
.col-publisher   { min-width: 120px; }
.col-pubdate     { width: 110px; min-width: 100px; white-space: nowrap; }
.col-subjects    { min-width: 160px; }
.col-description { min-width: 180px; }
.col-edition     { width: 100px; min-width: 90px; }
.col-apinotes    { min-width: 160px; }
.col-category    { width: 170px; min-width: 150px; }
.col-notes       { min-width: 200px; }
.col-save        { width: 80px;  min-width: 80px; white-space: nowrap; }
.col-delete      { width: 80px;  min-width: 80px; white-space: nowrap; }

/* Search bar */
.search-bar-wrapper {
    margin-bottom: 1rem;
}

.library-search-input {
    width: 100%;
    max-width: 420px;
    padding: 0.5rem 0.875rem;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-color);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.library-search-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
    outline: none;
}

/* Delete button */
.del-btn {
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    background: #dc2626;
    color: #fff;
    transition: background var(--transition), transform var(--transition);
    white-space: nowrap;
    width: 100%;
}
.del-btn:hover:not(:disabled) { background: #b91c1c; transform: translateY(-1px); }
.del-btn:disabled              { opacity: 0.6; cursor: default; }
.del-btn.del-err               { background: #7f1d1d; }

/* Clamp long text fields to 4 lines */
.tbl-clamp {
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Subjects — allow full subject text to wrap as needed */
.tbl-subjects {
    white-space: normal;
    word-break: break-word;
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Inline field label inside Book cell */
.tbl-field-label {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.78rem;
}

/* Thumbnail in table */
.tbl-thumb {
    width: 56px;
    height: auto;
    display: block;
    border-radius: 3px;
    box-shadow: var(--shadow);
}

.tbl-thumb-placeholder {
    width: 56px;
    height: 76px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    background: var(--bg-color);
    border: 1px dashed var(--border-color);
    border-radius: 3px;
    color: var(--text-muted);
}

/* Book info in table */
.tbl-title {
    font-weight: 600;
    color: var(--primary-color);
    text-decoration: none;
    display: block;
    line-height: 1.3;
    margin-bottom: 0.2rem;
}
.tbl-title:hover { text-decoration: underline; }

.tbl-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.3;
}
.tbl-publisher { font-style: italic; }

.tbl-isbn {
    font-family: monospace;
    font-size: 0.82rem;
    color: var(--text-muted);
    word-break: break-all;
}

/* Notes textarea */
.notes-input {
    width: 100%;
    padding: 0.5rem 0.625rem;
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    resize: vertical;
    background: var(--bg-color);
    transition: border-color var(--transition);
    min-height: 72px;
}
.notes-input:focus {
    border-color: var(--primary-color);
    background: #fff;
    outline: none;
}

/* Save button */
.save-btn {
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    background: var(--primary-color);
    color: #fff;
    transition: background var(--transition), transform var(--transition);
    white-space: nowrap;
    width: 100%;
}
.save-btn:hover:not(:disabled)  { background: var(--primary-hover); transform: translateY(-1px); }
.save-btn:disabled               { opacity: 0.6; cursor: default; }
.save-btn.save-ok                { background: #16a34a; }
.save-btn.save-err               { background: #dc2626; }

/* ============================
   Category Multi-Select Picker
   ============================ */
.cat-picker {
    position: relative;
}

.cat-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.25rem;
    padding: 0.45rem 0.75rem;
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--text-color);
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    text-align: left;
    transition: border-color var(--transition);
}
.cat-btn:hover,
.cat-btn[aria-expanded="true"] {
    border-color: var(--primary-color);
    background: #fff;
}

.cat-label {
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 0.82rem;
}

.cat-arrow {
    flex-shrink: 0;
    font-size: 0.75rem;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}
.cat-btn[aria-expanded="true"] .cat-arrow {
    transform: rotate(180deg);
}

.cat-options {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    min-width: 160px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 200;
    padding: 0.4rem 0;
    max-height: 240px;
    overflow-y: auto;
}
.cat-options[hidden] { display: none; }

.cat-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background var(--transition);
}
.cat-option:hover { background: #f0f7ff; }
.cat-option input[type="checkbox"] {
    width: 15px;
    height: 15px;
    accent-color: var(--primary-color);
    cursor: pointer;
    flex-shrink: 0;
}

/* ============================
   Login Page
   ============================ */
body.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-color);
}

.login-wrap {
    width: 100%;
    padding: 1rem;
}

.login-box {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: 0 4px 24px rgba(0,0,0,0.08);
    padding: 2.5rem 2rem;
    max-width: 400px;
    margin: 0 auto;
}

.login-logo {
    text-align: center;
    margin-bottom: 2rem;
}
.login-logo .logo-icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 0.5rem;
}
.login-logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-color);
    margin: 0;
}

.login-field {
    margin-bottom: 1.25rem;
}
.login-field label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 0.35rem;
}
.login-field input {
    width: 100%;
    padding: 0.65rem 0.85rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 1rem;
    background: #fff;
    color: var(--text-color);
    transition: border-color var(--transition);
}
.login-field input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

.login-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), transform 0.1s;
    margin-top: 0.5rem;
}
.login-btn:hover  { background: var(--primary-hover); }
.login-btn:active { transform: translateY(1px); }

.login-alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
    line-height: 1.5;
}
.login-alert--error {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    color: #b91c1c;
}

/* ============================
   Nav user / logout
   ============================ */
.nav-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: 0.5rem;
    padding-left: 0.75rem;
    border-left: 1px solid rgba(255,255,255,0.25);
}
.nav-username {
    font-size: 0.85rem;
    opacity: 0.85;
    color: #fff;
}
.nav-logout {
    font-size: 0.85rem;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.35);
    border-radius: var(--radius);
    padding: 0.25rem 0.7rem;
    color: #fff;
    text-decoration: none;
    transition: background var(--transition);
    white-space: nowrap;
}
.nav-logout:hover { background: rgba(255,255,255,0.3); }
