/* ─── Fonts ───────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,700;1,400&family=DM+Sans:wght@300;400;500;600&display=swap');

/* ─── Design Tokens ──────────────────────────────────────────────────────── */
:root {
  --teal-50:   #effefb; --teal-100:  #ccfef4; --teal-200:  #9afcea;
  --teal-300:  #5ef4da; --teal-400:  #2de4c9; --teal-500:  #13c9b1;
  --teal-600:  #0ba191; --teal-700:  #0e8075; --teal-800:  #116560;
  --teal-900:  #135450; --teal-950:  #042f2e;
  --sand-50:   #faf9f6;
  --ink:       #1a2628; --ink-soft:  #3d5457; --ink-muted: #6d8d8f;
  --white:     #ffffff;
  --radius-sm: 8px; --radius-md: 14px; --radius-lg: 22px; --radius-xl: 32px;
  --shadow-card:     0 2px 12px rgba(11,161,145,.10), 0 1px 3px rgba(0,0,0,.06);
  --shadow-elevated: 0 8px 32px rgba(11,161,145,.18), 0 2px 8px rgba(0,0,0,.08);
  --transition: 0.22s cubic-bezier(.4,0,.2,1);
  --pad: clamp(1rem, 4vw, 2rem);
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body { font-family: 'DM Sans', sans-serif; background: var(--sand-50); color: var(--ink); min-height: 100vh; line-height: 1.6; overflow-x: hidden; }
h1,h2,h3,h4 { font-family: 'Playfair Display', serif; line-height: 1.25; }
a { color: var(--teal-600); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--teal-800); }
img { max-width: 100%; display: block; }

/* ─── Header ─────────────────────────────────────────────────────────────── */
.site-header {
  background: linear-gradient(135deg, var(--teal-950) 0%, var(--teal-800) 60%, var(--teal-600) 100%);
  padding: 0 var(--pad); position: sticky; top: 0; z-index: 200;
  box-shadow: 0 2px 16px rgba(4,47,46,.25);
}
.header-inner {
  max-width: 1280px; margin: 0 auto; display: flex;
  align-items: center; justify-content: space-between; height: 60px; gap: 1rem;
}
.logo {
  display: flex; align-items: center; gap: .55rem; color: var(--white);
  font-family: 'Playfair Display', serif; font-size: clamp(1.05rem, 4vw, 1.45rem);
  font-weight: 700; letter-spacing: -.02em; white-space: nowrap; flex-shrink: 0;
}
.logo-icon { font-size: 1.35rem; }
.nav-links { display: flex; gap: .3rem; flex-shrink: 0; }
.nav-links a {
  color: rgba(255,255,255,.82); padding: .38rem .7rem;
  border-radius: var(--radius-sm); font-size: clamp(.76rem, 2.5vw, .9rem);
  font-weight: 500; transition: background var(--transition), color var(--transition); white-space: nowrap;
}
.nav-links a:hover, .nav-links a.active { background: rgba(255,255,255,.15); color: var(--white); }

/* ─── Hero ───────────────────────────────────────────────────────────────── */
.page-hero {
  background: linear-gradient(160deg, var(--teal-900) 0%, var(--teal-700) 55%, var(--teal-500) 100%);
  padding: clamp(1.75rem, 5vw, 4rem) var(--pad) clamp(1.75rem, 4vw, 3.5rem);
  text-align: center; color: var(--white); position: relative; overflow: hidden;
}
.page-hero::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.page-hero h1 { font-size: clamp(1.55rem, 5vw, 3.2rem); margin-bottom: .5rem; position: relative; }
.page-hero p  { font-size: clamp(.88rem, 2.5vw, 1.1rem); opacity: .82; max-width: 520px; margin: 0 auto; position: relative; }

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.container { max-width: 1280px; margin: 0 auto; padding: 0 var(--pad); }
.section    { padding: clamp(1.5rem, 4vw, 3rem) 0; }

/* ─── Search Panel ───────────────────────────────────────────────────────── */
.search-panel {
  background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow-elevated);
  padding: clamp(1rem, 3vw, 2rem) clamp(1rem, 3vw, 2.5rem) clamp(1.1rem, 3vw, 2.5rem);
  margin: clamp(-.75rem, -2vw, -2rem) auto 0; max-width: 1100px; position: relative; z-index: 10;
}
.search-panel-title { font-size: .98rem; font-weight: 600; color: var(--teal-700); margin-bottom: .9rem; display: flex; align-items: center; gap: .5rem; }
.search-grid { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: .85rem; }
.search-full { grid-column: 1 / -1; }
.search-half { grid-column: span 2; }
.field-group { display: flex; flex-direction: column; gap: .32rem; }
.field-group label { font-size: .76rem; font-weight: 600; color: var(--ink-soft); letter-spacing: .04em; text-transform: uppercase; }
input[type=text], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: .62rem .9rem; border: 1.5px solid var(--teal-200);
  border-radius: var(--radius-sm); font-family: inherit;
  font-size: 1rem; /* must be ≥16px to prevent iOS auto-zoom */
  color: var(--ink); background: var(--teal-50);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none; -webkit-appearance: none; appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%230e8075' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .75rem center; padding-right: 2.2rem;
}
input:focus, select:focus, textarea:focus { border-color: var(--teal-400); box-shadow: 0 0 0 3px rgba(45,228,201,.18); background: var(--white); }
.year-range   { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.search-actions { grid-column: 1/-1; display: flex; gap: .6rem; justify-content: flex-end; margin-top: .2rem; flex-wrap: wrap; }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .65rem 1.3rem; border-radius: var(--radius-md); font-family: inherit;
  font-size: .93rem; font-weight: 600; cursor: pointer; border: 2px solid transparent;
  transition: all var(--transition); white-space: nowrap;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; min-height: 44px;
}
.btn-primary { background: linear-gradient(135deg, var(--teal-600), var(--teal-500)); color: var(--white); box-shadow: 0 2px 8px rgba(11,161,145,.35); }
.btn-primary:hover  { background: linear-gradient(135deg, var(--teal-700), var(--teal-600)); box-shadow: 0 4px 16px rgba(11,161,145,.45); color: var(--white); }
.btn-primary:active { transform: scale(.97); }
.btn-outline { background: transparent; color: var(--teal-700); border-color: var(--teal-300); }
.btn-outline:hover  { background: var(--teal-50); border-color: var(--teal-500); color: var(--teal-800); }
.btn-outline:active { transform: scale(.97); }
.btn-danger  { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; }
.btn-danger:hover   { background: #fecaca; border-color: #f87171; }
.btn-sm  { padding: .42rem .85rem; font-size: .83rem; min-height: 40px; }
.btn-icon{ padding: .5rem; aspect-ratio: 1; }

/* ─── Sort Bar ───────────────────────────────────────────────────────────── */
.sort-bar { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.sort-bar .result-count { font-size: .9rem; color: var(--ink-muted); margin-right: auto; }
.sort-group { display: flex; align-items: center; gap: .38rem; }
.sort-group label  { font-size: .82rem; font-weight: 600; color: var(--ink-soft); white-space: nowrap; }
.sort-group select { width: auto; padding: .38rem .7rem; font-size: .83rem; min-height: 38px; }

/* ─── Book Grid & Cards ──────────────────────────────────────────────────── */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 190px), 1fr));
  gap: 1.1rem;
}
a.book-card {
  background: var(--white); border-radius: var(--radius-md); box-shadow: var(--shadow-card);
  overflow: hidden; display: flex; flex-direction: column;
  transition: transform var(--transition), box-shadow var(--transition);
  border: 1.5px solid transparent; text-decoration: none; color: inherit;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
a.book-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-elevated); border-color: var(--teal-200); }
.book-cover {
  aspect-ratio: 3/4; background: linear-gradient(145deg, var(--teal-100), var(--teal-200));
  position: relative; overflow: hidden; flex-shrink: 0;
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-cover-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: .5rem; color: var(--teal-600); font-size: .8rem; font-weight: 500; }
.book-cover-placeholder span { font-size: 3rem; }
.book-genre-badge { position: absolute; top: .5rem; left: .5rem; background: rgba(4,47,46,.72); color: var(--teal-200); font-size: .66rem; font-weight: 600; padding: .16rem .48rem; border-radius: 100px; backdrop-filter: blur(4px); letter-spacing: .05em; text-transform: uppercase; }
.book-body    { padding: .8rem .9rem .95rem; display: flex; flex-direction: column; gap: .22rem; flex: 1; }
.book-title   { font-size: .95rem; font-weight: 700; line-height: 1.3; color: var(--ink); }
.book-author  { font-size: .8rem; color: var(--ink-soft); }
.book-meta    { font-size: .74rem; color: var(--ink-muted); margin-top: .08rem; }
.book-rating  { display: flex; align-items: center; gap: .28rem; margin-top: .3rem; }
.stars        { color: #f59e0b; font-size: .8rem; letter-spacing: -.05em; }
.rating-num   { font-size: .76rem; font-weight: 600; color: var(--ink-soft); }
.book-snippet { font-size: .75rem; color: var(--ink-muted); line-height: 1.5; margin-top: .3rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.book-view-link { display: inline-block; margin-top: .5rem; font-size: .75rem; font-weight: 600; color: var(--teal-600); letter-spacing: .02em; }
a.book-card:hover .book-view-link { color: var(--teal-800); }

/* ─── Section Header ─────────────────────────────────────────────────────── */
.section-header { display: flex; align-items: center; gap: .9rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.section-header h2 { font-size: clamp(1.25rem, 3.5vw, 1.8rem); color: var(--ink); }
.section-header .pill { background: var(--teal-100); color: var(--teal-700); font-size: .73rem; font-weight: 700; padding: .2rem .65rem; border-radius: 100px; letter-spacing: .04em; text-transform: uppercase; }
.section-divider { flex: 1; height: 1.5px; background: linear-gradient(90deg, var(--teal-200), transparent); min-width: 20px; }

/* ─── Empty State ────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--ink-muted); grid-column: 1/-1; }
.empty-state .icon { font-size: 3rem; margin-bottom: .7rem; }
.empty-state h3    { font-size: 1.1rem; color: var(--ink-soft); margin-bottom: .4rem; }

/* ─── Flash ──────────────────────────────────────────────────────────────── */
.flash { padding: .82rem 1rem; border-radius: var(--radius-sm); font-size: .9rem; font-weight: 500; margin-bottom: 1.1rem; display: flex; align-items: flex-start; gap: .5rem; }
.flash-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* ─── Admin Table (desktop) ──────────────────────────────────────────────── */
.admin-table-wrap { background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); overflow: hidden; }
.admin-table { width: 100%; border-collapse: collapse; font-size: .87rem; }
.admin-table thead tr { background: linear-gradient(90deg, var(--teal-800), var(--teal-700)); color: var(--white); }
.admin-table th { padding: .82rem 1rem; text-align: left; font-weight: 600; font-size: .76rem; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.admin-table tbody tr { border-bottom: 1px solid var(--teal-100); transition: background var(--transition); }
.admin-table tbody tr:hover { background: var(--teal-50); }
.admin-table td { padding: .78rem 1rem; vertical-align: middle; }
.admin-table .thumb    { width: 40px; height: 52px; object-fit: cover; border-radius: 5px; border: 1px solid var(--teal-200); }
.admin-table .no-thumb { width: 40px; height: 52px; border-radius: 5px; background: var(--teal-100); display: flex; align-items: center; justify-content: center; font-size: 1.1rem; border: 1px solid var(--teal-200); }
.table-actions { display: flex; gap: .4rem; }

/* ─── Admin Card List (mobile replacement for table) ─────────────────────── */
.admin-card-list { display: none; flex-direction: column; gap: .7rem; }
.admin-book-card {
  background: var(--white); border-radius: var(--radius-md);
  box-shadow: var(--shadow-card); border: 1.5px solid var(--teal-100);
  display: grid; grid-template-columns: 62px 1fr; overflow: hidden;
}
.abc-thumb {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--teal-100), var(--teal-200));
  padding: .75rem .5rem;
}
.abc-thumb img      { width: 44px; height: 58px; object-fit: cover; border-radius: 5px; border: 1px solid var(--teal-300); }
.abc-thumb .no-img  { width: 44px; height: 58px; border-radius: 5px; background: var(--white); display: flex; align-items: center; justify-content: center; font-size: 1.3rem; border: 1px solid var(--teal-300); }
.abc-body    { padding: .85rem 1rem; display: flex; flex-direction: column; gap: .2rem; }
.abc-title   { font-size: .97rem; font-weight: 700; color: var(--ink); line-height: 1.25; }
.abc-author  { font-size: .82rem; color: var(--ink-soft); }
.abc-meta    { display: flex; flex-wrap: wrap; gap: .22rem .55rem; margin-top: .2rem; }
.abc-tag     { background: var(--teal-100); color: var(--teal-800); padding: .1rem .48rem; border-radius: 100px; font-size: .7rem; font-weight: 600; }
.abc-isbn    { font-size: .72rem; color: var(--ink-muted); font-family: monospace; }
.abc-actions { display: flex; gap: .5rem; margin-top: .55rem; }
.abc-actions .btn { flex: 1; }

/* ─── Admin header bar ───────────────────────────────────────────────────── */
.admin-bar { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: .75rem; margin-bottom: 1.5rem; }
.admin-bar h2   { font-size: clamp(1.25rem, 3.5vw, 1.75rem); color: var(--ink); }
.admin-bar .meta{ font-size: .87rem; color: var(--ink-muted); }
.admin-bar-actions  { display: flex; gap: .55rem; align-items: center; flex-wrap: wrap; }
.admin-search-form  { display: flex; gap: .4rem; }
.admin-search-form input { flex: 1; min-width: 0; }

/* ─── Stats ──────────────────────────────────────────────────────────────── */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 2rem; }
.stat-card { background: var(--white); border-radius: var(--radius-md); box-shadow: var(--shadow-card); padding: 1.1rem 1.25rem; display: flex; align-items: center; gap: .85rem; border-top: 3px solid var(--teal-400); }
.stat-icon      { font-size: 1.75rem; flex-shrink: 0; }
.stat-info .num { font-size: 1.65rem; font-weight: 700; color: var(--teal-700); line-height: 1; font-family: 'Playfair Display', serif; }
.stat-info .lbl { font-size: .76rem; color: var(--ink-muted); font-weight: 500; }

/* ─── Modal ──────────────────────────────────────────────────────────────── */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(4,47,46,.55); z-index: 1000;
  backdrop-filter: blur(4px); align-items: center; justify-content: center; padding: 1.5rem;
}
.modal-backdrop.active { display: flex; }
.modal {
  background: var(--white); border-radius: var(--radius-xl);
  box-shadow: 0 24px 80px rgba(4,47,46,.3);
  width: 100%; max-width: 620px; max-height: 92vh;
  overflow-y: auto; overflow-x: hidden;
  padding: 2rem 2rem 1.75rem;
  animation: slideUp .28s cubic-bezier(.4,0,.2,1);
  -webkit-overflow-scrolling: touch;
}
@keyframes slideUp { from { opacity:0; transform: translateY(24px); } to { opacity:1; transform: none; } }
.modal-handle { display: none; width: 40px; height: 4px; background: var(--teal-200); border-radius: 100px; margin: 0 auto .9rem; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.4rem; }
.modal-header h2 { font-size: 1.35rem; color: var(--ink); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.form-full  { grid-column: 1/-1; }
.form-group { display: flex; flex-direction: column; gap: .34rem; }
.form-group label { font-size: .76rem; font-weight: 600; color: var(--ink-soft); letter-spacing: .04em; text-transform: uppercase; }
.form-group textarea { min-height: 80px; resize: vertical; }
.cover-preview {
  width: 100%; aspect-ratio: 16/9; border-radius: var(--radius-sm);
  background: var(--teal-50); border: 2px dashed var(--teal-300);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  cursor: pointer; transition: border-color var(--transition);
}
.cover-preview:hover { border-color: var(--teal-500); }
.cover-preview img   { width: 100%; height: 100%; object-fit: contain; }
.cover-preview-label { color: var(--teal-600); font-size: .88rem; font-weight: 500; flex-direction: column; gap: .4rem; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; text-align: center; padding: 1rem; }
.cover-preview-label span { font-size: 2rem; }
.modal-footer { display: flex; gap: .65rem; justify-content: flex-end; margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--teal-100); }

/* ─── Footer ─────────────────────────────────────────────────────────────── */
.site-footer { background: var(--teal-950); color: rgba(255,255,255,.6); text-align: center; padding: 1.75rem var(--pad); font-size: .86rem; margin-top: 3rem; }
.site-footer strong { color: var(--teal-300); }

/* ─── Book Detail Page ───────────────────────────────────────────────────── */
.detail-wrap  { max-width: 960px; margin: 2rem auto; padding: 0 var(--pad) 3rem; }
.detail-back  { display: inline-flex; align-items: center; gap: .4rem; font-size: .88rem; font-weight: 600; color: var(--teal-700); margin-bottom: 1.5rem; padding: .45rem .9rem; border-radius: var(--radius-sm); border: 1.5px solid var(--teal-200); background: var(--white); transition: all var(--transition); min-height: 44px; }
.detail-back:hover  { background: var(--teal-50); border-color: var(--teal-400); color: var(--teal-900); }
.detail-back:active { transform: scale(.97); }
.detail-card  { background: var(--white); border-radius: var(--radius-xl); box-shadow: var(--shadow-elevated); overflow: hidden; display: grid; grid-template-columns: 260px 1fr; }
.detail-cover-col { background: linear-gradient(160deg, var(--teal-900), var(--teal-700)); display: flex; align-items: stretch; justify-content: center; min-height: 380px; position: relative; }
.detail-cover-col img { width: 100%; object-fit: cover; display: block; }
.detail-cover-placeholder { width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .75rem; color: var(--teal-300); padding: 3rem 2rem; }
.detail-cover-placeholder span { font-size: 5rem; }
.detail-cover-placeholder p    { font-size: .85rem; opacity: .7; }
.detail-genre-stamp { position: absolute; top: 1rem; left: 1rem; background: rgba(4,47,46,.75); color: var(--teal-200); font-size: .72rem; font-weight: 700; padding: .25rem .65rem; border-radius: 100px; letter-spacing: .06em; text-transform: uppercase; backdrop-filter: blur(6px); }
.detail-body  { padding: clamp(1.25rem, 3vw, 2.5rem); display: flex; flex-direction: column; gap: .9rem; }
.detail-title { font-size: clamp(1.3rem, 3vw, 2.1rem); font-family: 'Playfair Display', serif; color: var(--ink); line-height: 1.2; }
.detail-author{ font-size: 1rem; color: var(--teal-700); font-weight: 500; }
.detail-rating { display: flex; align-items: center; gap: .5rem; }
.detail-rating .stars { font-size: 1.2rem; color: #f59e0b; letter-spacing: .05em; }
.detail-rating .num   { font-size: .92rem; font-weight: 700; color: var(--ink-soft); }
.detail-divider       { height: 1px; background: var(--teal-100); }
.detail-meta-grid     { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem .7rem; }
.detail-meta-item     { display: flex; flex-direction: column; gap: .1rem; }
.detail-meta-item .lbl{ font-size: .68rem; font-weight: 700; color: var(--teal-600); text-transform: uppercase; letter-spacing: .06em; }
.detail-meta-item .val{ font-size: .92rem; color: var(--ink); font-weight: 500; }
.detail-description-box { background: var(--teal-50); border-left: 3px solid var(--teal-400); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; padding: .9rem 1.1rem; }
.detail-description-box h3 { font-size: .72rem; font-weight: 700; color: var(--teal-600); text-transform: uppercase; letter-spacing: .07em; margin-bottom: .42rem; }
.detail-description-box p { font-size: .92rem; color: var(--ink-soft); line-height: 1.75; white-space: pre-wrap; }
.detail-no-desc { font-style: italic; color: var(--ink-muted); font-size: .88rem; }
.related-section { margin-top: 2.5rem; }

/* ─── Login extras ───────────────────────────────────────────────────────── */
.attempts-bar .label { font-size: .78rem; color: var(--ink-muted); margin-bottom: .3rem; display: flex; justify-content: space-between; }
.bar-track { height: 5px; background: var(--teal-100); border-radius: 100px; overflow: hidden; }
.bar-fill  { height: 100%; border-radius: 100px; transition: width .4s, background .4s; }

/* ══════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════ */

/* Tablet ≤ 900px */
@media (max-width: 900px) {
  .search-grid { grid-template-columns: 1fr 1fr; }
  .search-half { grid-column: span 1; }
  .stats-row   { grid-template-columns: 1fr 1fr; gap: .75rem; }
  .detail-card { grid-template-columns: 220px 1fr; }
  .detail-cover-col { min-height: 320px; }
}

/* Mobile ≤ 640px */
@media (max-width: 640px) {
  :root { --pad: 1rem; }

  /* Header */
  .header-inner { height: 54px; }

  /* Hero */
  .page-hero h1 { font-size: 1.5rem; }

  /* Search */
  .search-panel   { margin-top: -.5rem; }
  .search-grid    { grid-template-columns: 1fr; }
  .search-full, .search-half { grid-column: 1; }
  .search-actions { justify-content: stretch; }
  .search-actions .btn { flex: 1; }

  /* Sort bar */
  .sort-bar { gap: .5rem; }

  /* Book grid — 2 col on mobile */
  .books-grid  { grid-template-columns: repeat(2, 1fr); gap: .7rem; }
  .book-body   { padding: .65rem .7rem .8rem; }
  .book-title  { font-size: .88rem; }
  .book-snippet{ display: none; }

  /* Stats */
  .stats-row   { grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: 1.25rem; }
  .stat-card   { padding: .85rem .9rem; gap: .6rem; }
  .stat-icon   { font-size: 1.4rem; }
  .stat-info .num { font-size: 1.35rem; }
  .stat-info .lbl { font-size: .72rem; }

  /* Admin bar */
  .admin-bar         { flex-direction: column; }
  .admin-bar-actions { flex-direction: column; width: 100%; }
  .admin-search-form { width: 100%; }
  .admin-search-form input { width: 100%; }
  .admin-bar .btn    { width: 100%; }

  /* Admin table → card list */
  .admin-table-wrap { display: none; }
  .admin-card-list  { display: flex; }

  /* Modal → bottom sheet */
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    max-width: 100%; max-height: 96vh;
    padding: .5rem 1rem calc(1.25rem + env(safe-area-inset-bottom));
  }
  .modal-handle { display: block; }
  .form-grid    { grid-template-columns: 1fr; }
  .modal-footer { flex-direction: column-reverse; }
  .modal-footer .btn { width: 100%; }

  /* Detail page */
  .detail-wrap  { margin: 1rem auto; padding: 0 .9rem 2.5rem; }
  .detail-back  { margin-bottom: 1rem; font-size: .83rem; }
  .detail-card  { grid-template-columns: 1fr; border-radius: var(--radius-lg); }
  .detail-cover-col { min-height: 200px; max-height: 280px; }
  .detail-cover-col img { object-position: center top; }
  .detail-body  { padding: 1.1rem; gap: .7rem; }
  .detail-title { font-size: 1.3rem; }
  .related-section { margin-top: 1.75rem; }

  /* Section header */
  .section-header { gap: .55rem; margin-bottom: 1rem; }
  .section-divider{ display: none; }
}

/* Very small ≤ 380px */
@media (max-width: 380px) {
  .books-grid { grid-template-columns: 1fr; }
  .nav-links a { padding: .32rem .52rem; font-size: .73rem; }
  .stats-row   { grid-template-columns: 1fr 1fr; }
}

/* ─── Login Page ─────────────────────────────────────────────────────────── */
.login-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: linear-gradient(160deg, var(--teal-950) 0%, var(--teal-800) 55%, var(--teal-600) 100%);
}
.login-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(.75rem, 4vw, 2rem);
}
.login-card {
  background: var(--white);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 80px rgba(4,47,46,.45);
  width: 100%;
  max-width: 420px;
  padding: clamp(1.5rem, 5vw, 2.75rem) clamp(1.25rem, 4vw, 2.5rem);
  animation: loginSlideUp .3s cubic-bezier(.4,0,.2,1);
}
@keyframes loginSlideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: none; }
}
.login-logo { text-align: center; margin-bottom: clamp(1.25rem, 4vw, 2rem); }
.login-logo .icon { font-size: clamp(2.2rem, 7vw, 3rem); display: block; margin-bottom: .5rem; }
.login-logo h1    { font-size: clamp(1.3rem, 4vw, 1.75rem); color: var(--teal-800); margin-bottom: .2rem; }
.login-logo p     { font-size: .86rem; color: var(--ink-muted); }

.login-form .field-group       { margin-bottom: 1rem; }
.login-form .field-group label { display: block; font-size: .79rem; font-weight: 600; color: var(--ink-soft); letter-spacing: .04em; text-transform: uppercase; margin-bottom: .38rem; }
.login-form input[type=text],
.login-form input[type=password] { width: 100%; font-size: 1rem; }
.login-form .btn-primary { width: 100%; padding: .85rem; font-size: 1rem; justify-content: center; margin-top: .5rem; min-height: 50px; }

.login-error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
  padding: .78rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .87rem;
  margin-bottom: 1.1rem;
  display: flex;
  align-items: flex-start;
  gap: .5rem;
}
.login-error.locked  { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.login-success       { background: #d1fae5; color: #065f46; border-color: #6ee7b7; }

.login-attempts-bar         { margin-top: .75rem; }
.login-attempts-bar .label  { font-size: .76rem; color: var(--ink-muted); margin-bottom: .3rem; display: flex; justify-content: space-between; }

.lockout-timer        { text-align: center; font-size: .85rem; color: var(--ink-muted); margin-top: 1rem; }
.lockout-timer strong { color: #92400e; font-size: 1.1rem; }

.login-divider     { height: 1px; background: var(--teal-100); margin: 1.25rem 0; }
.login-security    { display: flex; align-items: center; gap: .5rem; font-size: .76rem; color: var(--ink-muted); margin-top: .25rem; justify-content: center; text-align: center; flex-wrap: wrap; }

.pw-toggle         { position: relative; }
.pw-toggle input   { padding-right: 3rem; }
.pw-toggle button  {
  position: absolute; right: .75rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 1rem; color: var(--ink-muted);
  padding: 0; min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center;
  touch-action: manipulation;
}

@media (max-width: 380px) {
  .login-card { border-radius: var(--radius-lg); }
}
