/* ═══════════════════════════════════════════════════
   THE BOOK NOOK — Stylesheet
   Aesthetic: Warm library, aged paper, ink & leather
   ═══════════════════════════════════════════════════ */

:root {
  --paper: #f5f0e8;
  --paper-dark: #ede6d6;
  --warm-white: #faf7f2;
  --ink: #2a2118;
  --ink-light: #4a3f32;
  --muted: #8a7a68;
  --amber: #b87333;
  --amber-light: #d4956a;
  --amber-pale: #f5ede0;
  --teal: #4a7c7e;
  --border: #ddd4c4;
  --shadow-sm: 0 1px 3px rgba(42,33,24,0.08);
  --shadow-md: 0 4px 16px rgba(42,33,24,0.12);
  --shadow-lg: 0 12px 40px rgba(42,33,24,0.2);
  --radius: 8px;
  --radius-lg: 14px;
  --sidebar-w: 240px;
  --font-display: 'Libre Baskerville', Georgia, serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font-body); background: var(--paper); color: var(--ink); font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }

/* ─── Auth ──────────────────────────────────────────── */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--paper); background-image: repeating-linear-gradient(0deg, transparent, transparent 28px, rgba(184,115,51,0.04) 28px, rgba(184,115,51,0.04) 29px); }

.auth-card { width: 100%; max-width: 420px; background: var(--warm-white); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 2.5rem 2rem; box-shadow: var(--shadow-lg); margin: 1rem; }

.auth-logo { text-align: center; margin-bottom: 2rem; }
.book-icon { font-size: 2.5rem; display: block; margin-bottom: 0.5rem; }
.auth-logo h1 { font-family: var(--font-display); font-size: 1.9rem; font-weight: 700; color: var(--ink); }
.tagline { font-size: 0.82rem; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; margin-top: 0.3rem; font-style: italic; }
.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.auth-footer { text-align: center; margin-top: 1.5rem; font-size: 0.9rem; color: var(--muted); }
.auth-footer a { color: var(--amber); text-decoration: none; margin-left: 0.4em; }
.auth-footer a:hover { text-decoration: underline; }

/* ─── App Layout ────────────────────────────────────── */
#page-app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

/* ─── Sidebar ───────────────────────────────────────── */
#sidebar { background: var(--ink); color: #e8dfd0; display: flex; flex-direction: column; padding: 1.5rem 1rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar-logo { display: flex; align-items: center; gap: 0.75rem; padding: 0.5rem 0.5rem 1.5rem; border-bottom: 1px solid rgba(255,255,255,0.08); margin-bottom: 1rem; }
.book-icon-sm { font-size: 1.4rem; }
.sidebar-title { font-family: var(--font-display); font-size: 1rem; font-weight: 700; color: #f5ede0; }
.sidebar-tagline { font-size: 0.68rem; color: rgba(255,255,255,0.3); font-style: italic; margin-top: 0.1rem; }
.sidebar-nav { display: flex; flex-direction: column; gap: 0.2rem; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 0.6rem; padding: 0.65rem 0.75rem; border-radius: var(--radius); color: rgba(255,255,255,0.55); text-decoration: none; font-size: 0.9rem; transition: all 0.15s; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: rgba(184,115,51,0.25); color: var(--amber-light); }
.nav-icon { font-size: 1rem; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,0.08); padding-top: 1rem; margin-top: auto; }
.user-info { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--amber); color: white; display: flex; align-items: center; justify-content: center; font-size: 0.85rem; font-weight: 600; flex-shrink: 0; }
.user-name { font-size: 0.88rem; color: #e8dfd0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.user-email { font-size: 0.75rem; color: rgba(255,255,255,0.3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.btn-logout { display: block; text-align: center; padding: 0.45rem; border-radius: var(--radius); background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.45); text-decoration: none; font-size: 0.82rem; transition: all 0.15s; }
.btn-logout:hover { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.8); }

/* ─── Mobile Header ─────────────────────────────────── */
.mobile-header { display: none; align-items: center; justify-content: space-between; padding: 0.75rem 1rem; background: var(--ink); color: white; position: sticky; top: 0; z-index: 100; }
.mobile-title { font-family: var(--font-display); font-size: 1rem; color: #f5ede0; }
.mobile-menu-btn, .btn-icon-sm { background: none; border: none; color: white; font-size: 1.2rem; cursor: pointer; padding: 0.25rem 0.5rem; border-radius: 4px; }

/* ─── Main ──────────────────────────────────────────── */
#main-content { background: var(--paper); overflow-y: auto; min-height: 100vh; }
.view { padding: 2rem 2.5rem; max-width: 1100px; }
.view-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem; }
.view-header h2 { font-family: var(--font-display); font-size: 1.9rem; font-weight: 700; color: var(--ink); }
.view-subtitle { font-size: 0.85rem; color: var(--muted); margin-top: 0.2rem; }

/* ─── Search/Filter ─────────────────────────────────── */
.search-bar { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.5rem; }
.search-bar input[type="search"] { width: 100%; padding: 0.7rem 1rem; border: 1.5px solid var(--border); border-radius: var(--radius); background: var(--warm-white); font-size: 0.95rem; font-family: var(--font-body); color: var(--ink); outline: none; transition: border-color 0.15s; }
.search-bar input[type="search"]:focus { border-color: var(--amber); }
.filters { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.filters select, .filters input { padding: 0.5rem 0.75rem; border: 1.5px solid var(--border); border-radius: var(--radius); background: var(--warm-white); font-family: var(--font-body); font-size: 0.88rem; color: var(--ink); outline: none; transition: border-color 0.15s; min-width: 130px; }
.filters select:focus, .filters input:focus { border-color: var(--amber); }

/* ─── Books Grid ────────────────────────────────────── */
.books-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1.25rem; }

.book-card { background: var(--warm-white); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; box-shadow: var(--shadow-sm); }
.book-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }

.book-cover { width: 100%; aspect-ratio: 2/3; background: var(--paper-dark); display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; }
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-cover-placeholder { font-size: 2.5rem; color: var(--border); }

.book-status-badge { position: absolute; top: 0.4rem; right: 0.4rem; font-size: 0.65rem; padding: 0.15rem 0.4rem; border-radius: 4px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.badge-loaned { background: #fff3cd; color: #856404; }
.badge-library { background: #cce5ff; color: #004085; }
.badge-read { background: #d4edda; color: #155724; }
.badge-in-progress { background: #e8d5f5; color: #5a2d82; }

.book-body { padding: 0.6rem 0.7rem; }
.book-author { font-size: 0.7rem; color: var(--amber); font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-title { font-family: var(--font-display); font-size: 0.85rem; font-weight: 700; color: var(--ink); line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-series { font-size: 0.7rem; color: var(--muted); margin-top: 0.2rem; font-style: italic; }
.book-rating { margin-top: 0.3rem; font-size: 0.7rem; color: var(--amber); }

/* ─── Star Rating ───────────────────────────────────── */
.star-rating { display: flex; gap: 0.2rem; }
.star { font-size: 1.4rem; color: var(--border); cursor: pointer; transition: color 0.1s; user-select: none; }
.star.active, .star:hover { color: var(--amber); }
.star-display { color: var(--amber); font-size: 0.9rem; }

/* ─── Loans/Checkouts List ──────────────────────────── */
.loans-list { display: flex; flex-direction: column; gap: 1rem; }
.loan-card { background: var(--warm-white); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.25rem 1.5rem; display: flex; gap: 1.25rem; align-items: flex-start; }
.loan-cover { width: 60px; height: 90px; border-radius: 4px; object-fit: cover; background: var(--paper-dark); flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; color: var(--border); overflow: hidden; }
.loan-cover img { width: 100%; height: 100%; object-fit: cover; }
.loan-info { flex: 1; }
.loan-book-title { font-family: var(--font-display); font-size: 1.05rem; font-weight: 700; color: var(--ink); margin-bottom: 0.3rem; }
.loan-book-author { font-size: 0.82rem; color: var(--muted); margin-bottom: 0.5rem; }
.loan-meta { font-size: 0.83rem; color: var(--ink-light); display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 0.75rem; }
.loan-meta span { display: flex; align-items: center; gap: 0.3rem; }
.due-soon { color: #856404; font-weight: 600; }
.overdue { color: #b30000; font-weight: 600; }
.loan-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ─── Detail Modal ──────────────────────────────────── */
.detail-content { padding: 1.5rem 2rem 2rem; }
.detail-top { display: flex; gap: 1.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.detail-cover { width: 120px; flex-shrink: 0; }
.detail-cover img { width: 100%; border-radius: var(--radius); box-shadow: var(--shadow-md); }
.detail-cover-placeholder { width: 120px; height: 180px; background: var(--paper-dark); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; font-size: 3rem; color: var(--border); }
.detail-meta { flex: 1; }
.detail-title { font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; color: var(--ink); margin-bottom: 0.25rem; }
.detail-author { font-size: 1rem; color: var(--amber); margin-bottom: 0.75rem; }
.detail-series { font-size: 0.85rem; color: var(--muted); font-style: italic; margin-bottom: 0.5rem; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.75rem; margin-bottom: 1.25rem; }
.detail-field label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); display: block; margin-bottom: 0.15rem; }
.detail-field .value { font-size: 0.92rem; color: var(--ink); }
.detail-description { background: var(--paper-dark); border-radius: var(--radius); padding: 0.75rem 1rem; font-size: 0.88rem; color: var(--ink-light); line-height: 1.65; margin-bottom: 1.25rem; font-style: italic; }
.detail-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 1rem; }
.detail-section { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.detail-section h4 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); margin-bottom: 0.75rem; }

/* ─── Add Book Methods ──────────────────────────────── */
.add-book-methods { display: flex; gap: 0.5rem; padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); }
.method-btn { flex: 1; padding: 0.6rem; background: var(--paper); border: 1.5px solid var(--border); border-radius: var(--radius); font-family: var(--font-body); font-size: 0.85rem; cursor: pointer; transition: all 0.15s; color: var(--ink-light); }
.method-btn.active { background: var(--amber-pale); border-color: var(--amber); color: var(--amber); font-weight: 500; }
.add-method { padding: 1.25rem 1.5rem; }
.lookup-bar { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.lookup-bar input { flex: 1; padding: 0.6rem 0.85rem; border: 1.5px solid var(--border); border-radius: var(--radius); font-family: var(--font-body); font-size: 0.92rem; outline: none; }
.lookup-bar input:focus { border-color: var(--amber); }
.method-hint { font-size: 0.88rem; color: var(--muted); margin-bottom: 1rem; }
.isbn-scan-area { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
#barcode-video { width: 100%; border-radius: var(--radius); max-height: 220px; object-fit: cover; background: #000; }

/* ─── Search Results ────────────────────────────────── */
.search-results { display: flex; flex-direction: column; gap: 0.75rem; max-height: 350px; overflow-y: auto; }
.result-item { display: flex; gap: 0.75rem; padding: 0.75rem; background: var(--paper); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: background 0.1s; align-items: flex-start; }
.result-item:hover { background: var(--amber-pale); border-color: var(--amber); }
.result-cover { width: 45px; height: 68px; object-fit: cover; border-radius: 3px; background: var(--paper-dark); flex-shrink: 0; }
.result-info { flex: 1; }
.result-title { font-family: var(--font-display); font-size: 0.92rem; font-weight: 700; color: var(--ink); }
.result-author { font-size: 0.8rem; color: var(--amber); margin-top: 0.15rem; }
.result-meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.2rem; }
.result-source { font-size: 0.68rem; color: var(--teal); font-weight: 500; margin-top: 0.25rem; }
.no-results { text-align: center; padding: 1.5rem; color: var(--muted); font-size: 0.9rem; }

/* ─── Cover Upload ──────────────────────────────────── */
.cover-col { align-items: center; }
.cover-preview-wrap { display: flex; flex-direction: column; align-items: center; gap: 0.75rem; }
.cover-preview { width: 140px; height: 210px; background: var(--paper-dark); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; overflow: hidden; border: 2px dashed var(--border); }
.cover-preview img { width: 100%; height: 100%; object-fit: cover; }
.cover-placeholder { font-size: 3rem; }
.cover-hint { font-size: 0.75rem; color: var(--muted); text-align: center; }
.upload-label { cursor: pointer; }

/* ─── Admin ─────────────────────────────────────────── */
.admin-grid { display: grid; grid-template-columns: 1fr 1.2fr; gap: 1.5rem; align-items: start; }
.admin-card { background: var(--warm-white); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.5rem; }
.admin-card h3 { font-family: var(--font-display); font-size: 1.2rem; font-weight: 700; color: var(--ink); margin-bottom: 1.25rem; }
.admin-card h4 { font-family: var(--font-display); font-size: 0.95rem; color: var(--ink-light); }
.admin-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.users-list { display: flex; flex-direction: column; }
.user-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.7rem 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
.user-row:last-child { border-bottom: none; }
.user-row-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--amber-pale); color: var(--amber); display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 600; flex-shrink: 0; }
.user-row-info { flex: 1; min-width: 0; }
.user-row-name { font-weight: 500; color: var(--ink); }
.user-row-email { font-size: 0.78rem; color: var(--muted); }
.role-badge { font-size: 0.68rem; padding: 0.15rem 0.5rem; border-radius: 20px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.role-badge.admin { background: var(--amber-pale); color: var(--amber); }
.role-badge.user { background: #e8f4f8; color: var(--teal); }
.user-row-actions { display: flex; gap: 0.4rem; }
.save-msg { font-size: 0.85rem; color: var(--teal); margin-left: 0.75rem; }

/* ─── Forms ─────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field label { font-size: 0.82rem; font-weight: 500; color: var(--ink-light); }
.field input, .field select, .field textarea { padding: 0.6rem 0.85rem; border: 1.5px solid var(--border); border-radius: var(--radius); background: var(--warm-white); font-family: var(--font-body); font-size: 0.92rem; color: var(--ink); outline: none; transition: border-color 0.15s; width: 100%; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--amber); }
.field textarea { resize: vertical; min-height: 70px; }
.checkbox-field { flex-direction: row !important; align-items: center; gap: 0.5rem !important; }
.checkbox-field label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; font-weight: 400; }
.checkbox-field input[type="checkbox"] { width: auto; padding: 0; border: none; accent-color: var(--amber); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.req { color: var(--amber); }
.hint { font-size: 0.78rem; color: var(--muted); font-weight: 400; }
.form-error { background: #fdf0ee; color: #b85242; border: 1px solid #f0c4be; border-radius: var(--radius); padding: 0.6rem 0.9rem; font-size: 0.85rem; }
.form-success { background: #edf5f0; color: #3a7a56; border: 1px solid #b8dfc8; border-radius: var(--radius); padding: 0.6rem 0.9rem; font-size: 0.85rem; }
.share-intro { font-size: 0.9rem; color: var(--ink-light); }

/* ─── Buttons ───────────────────────────────────────── */
.btn-primary { padding: 0.65rem 1.5rem; background: var(--amber); color: white; border: none; border-radius: var(--radius); font-family: var(--font-body); font-size: 0.9rem; font-weight: 500; cursor: pointer; transition: background 0.15s; white-space: nowrap; }
.btn-primary:hover { background: #a0622a; }
.btn-secondary { padding: 0.6rem 1.25rem; background: transparent; color: var(--ink); border: 1.5px solid var(--border); border-radius: var(--radius); font-family: var(--font-body); font-size: 0.88rem; cursor: pointer; transition: all 0.15s; white-space: nowrap; }
.btn-secondary:hover { border-color: var(--ink-light); background: var(--paper); }
.btn-ghost { padding: 0.6rem 1.25rem; background: transparent; color: var(--muted); border: none; border-radius: var(--radius); font-family: var(--font-body); font-size: 0.88rem; cursor: pointer; transition: all 0.15s; }
.btn-ghost:hover { color: var(--ink); background: var(--paper); }
.btn-full { width: 100%; }
.btn-sm { padding: 0.4rem 0.9rem; font-size: 0.82rem; }
.btn-danger { background: #c0392b !important; }
.btn-danger:hover { background: #a93226 !important; }

/* ─── Modals ────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-overlay { position: absolute; inset: 0; background: rgba(42,33,24,0.55); backdrop-filter: blur(2px); }
.modal-box { position: relative; background: var(--warm-white); border-radius: var(--radius-lg); width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); animation: modal-in 0.2s ease; }
.modal-large { max-width: 820px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1.25rem 1.5rem 1rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--warm-white); z-index: 1; }
.modal-header h3 { font-family: var(--font-display); font-size: 1.3rem; font-weight: 700; color: var(--ink); }
.modal-close { background: none; border: none; font-size: 1.1rem; color: var(--muted); cursor: pointer; padding: 0.25rem 0.5rem; border-radius: 4px; }
.modal-close:hover { color: var(--ink); }
.modal-form { padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 0.5rem; }
.form-cols { display: grid; grid-template-columns: 1fr 160px; gap: 1.5rem; }
.form-col { display: flex; flex-direction: column; gap: 1rem; }

/* ─── Empty/Loading ─────────────────────────────────── */
.empty-state { grid-column: 1/-1; text-align: center; padding: 4rem 2rem; color: var(--muted); }
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h3 { font-family: var(--font-display); font-size: 1.4rem; font-weight: 700; margin-bottom: 0.5rem; color: var(--ink-light); }
.loading-spinner { grid-column: 1/-1; text-align: center; padding: 3rem; color: var(--muted); font-style: italic; }

/* ─── Responsive ────────────────────────────────────── */
@media (max-width: 768px) {
  #page-app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #sidebar { display: none; position: fixed; inset: 0; z-index: 200; height: 100vh; padding-top: 4rem; }
  #sidebar.open { display: flex; }
  .mobile-header { display: flex; }
  .view { padding: 1.25rem 1rem; }
  .view-header .btn-primary { display: none; }
  .admin-grid { grid-template-columns: 1fr; }
  .form-cols { grid-template-columns: 1fr; }
  .books-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .loan-card { flex-direction: column; }
}
@media (max-width: 480px) {
  .filters { flex-direction: column; }
  .field-row { grid-template-columns: 1fr; }
  .add-book-methods { flex-direction: column; }
}
