/* ============================================================
   books-style.css  –  Physiology Books Portal
   ============================================================ */

/* ── Tokens ─────────────────────────────────────────────── */
:root {
  --primary:          #00288e;
  --primary-dark:     #001453;
  --primary-light:    #dde1ff;
  --on-primary:       #ffffff;

  --surface:          #f7f9fb;
  --surface-card:     #ffffff;
  --surface-low:      #f2f4f6;
  --surface-high:     #e6e8ea;
  --border:           #e2e8f0;

  --text-heading:     #0f172a;
  --text-body:        #334155;
  --text-secondary:   #515f74;
  --text-muted:       #757684;

  /* accent palette */
  --accent-pulm:      #3b82f6;
  --accent-renal:     #10b981;
  --accent-cardio:    #ef4444;
  --accent-neural:    #8b5cf6;
  --accent-heme:      #ba1a1a;
  --accent-general:   #515f74;

  --sidebar-w:        280px;
  --nav-h:            64px;
  --radius:           12px;
  --radius-sm:        8px;

  --font-display:     'Sora', sans-serif;
  --font-body:        'DM Sans', sans-serif;

  --shadow-sm:        0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-card:      0 4px 16px rgba(0,0,0,0.06);
  --shadow-card-hover:0 8px 24px rgba(0,0,0,0.10);

  --transition: 0.18s ease;
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--surface);
  color: var(--text-body);
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ── Top Nav ─────────────────────────────────────────────── */
.topnav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.topnav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-icon {
  font-size: 1.4rem;
  color: var(--primary);
  font-variation-settings: 'FILL' 1;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
}

.topnav-search {
  flex: 1;
  max-width: 520px;
  margin: 0 auto;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon-inline {
  position: absolute;
  left: 12px;
  color: var(--text-secondary);
  font-size: 1.15rem;
  pointer-events: none;
}

.topnav-search input {
  width: 100%;
  padding: 9px 40px 9px 40px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-low);
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text-heading);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.topnav-search input:focus {
  border-color: var(--primary);
  background: var(--surface-card);
  box-shadow: 0 0 0 3px rgba(0,40,142,0.10);
}

.clear-btn {
  position: absolute;
  right: 12px;
  font-size: 1.3rem;
  color: var(--text-muted);
  cursor: pointer;
  display: none;
  line-height: 1;
  user-select: none;
  transition: color var(--transition);
}
.clear-btn:hover { color: #ef4444; }

.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 7px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-low);
  white-space: nowrap;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  flex-shrink: 0;
}
.back-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}
.back-btn .material-symbols-outlined { font-size: 1rem; }

/* ── App Shell ───────────────────────────────────────────── */
.app-shell {
  display: flex;
  padding-top: var(--nav-h);
  flex: 1;
  min-height: calc(100vh - var(--nav-h));
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: fixed;
  top: var(--nav-h);
  left: 0;
  bottom: 0;
  background: var(--surface-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0 24px;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }

.sidebar-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 20px;
  margin-bottom: 4px;
}

.sidebar-total {
  font-size: 0.82rem;
  color: var(--text-secondary);
  padding: 0 20px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 12px;
}

.sidebar-nav .btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background var(--transition), color var(--transition);
  position: relative;
}

.sidebar-nav .btn:hover {
  background: var(--surface-low);
  color: var(--text-heading);
}

.sidebar-nav .btn.primary {
  background: #eef2ff;
  color: var(--primary);
  font-weight: 700;
}

.sidebar-nav .btn.primary::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}

.sidebar-nav .btn .btn-count {
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-high);
  padding: 1px 7px;
  border-radius: 999px;
}

.sidebar-nav .btn.primary .btn-count {
  background: var(--primary);
  color: var(--on-primary);
}

.sidebar-loading {
  display: flex;
  justify-content: center;
  padding: 20px 0;
  color: var(--text-muted);
}

/* ── Main Content ────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 28px 80px;
  max-width: calc(1280px + var(--sidebar-w));
}

/* ── Stats Row ───────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.stat-number {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}

/* ── Notice ──────────────────────────────────────────────── */
#noticeArea .notice {
  background: #fff7ed;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid #ffe4c4;
  color: #92400e;
  font-size: 0.88rem;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Book Grid ───────────────────────────────────────────── */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

/* ── Book Card ───────────────────────────────────────────── */
.book-card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  transition: transform var(--transition), box-shadow var(--transition);
  animation: fadeUp 0.3s ease both;
}

.book-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
}

.book-card:active {
  transform: scale(0.98);
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Card icon ───────────────────────────────────────────── */
.book-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.book-icon .material-symbols-outlined {
  font-size: 1.25rem;
}

.icon-general { background: rgba(81,95,116,0.10);  color: #3a485b; }
.icon-cardio  { background: rgba(239,68,68,0.10);  color: #c0392b; }
.icon-renal   { background: rgba(16,185,129,0.10); color: #047857; }
.icon-neural  { background: rgba(139,92,246,0.10); color: #6d28d9; }
.icon-pulm    { background: rgba(59,130,246,0.10); color: #1d4ed8; }
.icon-heme    { background: rgba(186,26,26,0.10);  color: #9b1c1c; }

/* ── Card body ───────────────────────────────────────────── */
.book-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.book-title-text {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-heading);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  word-break: break-word;
  overflow-wrap: break-word;
}

.book-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.system-badge {
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.badge-general { background: rgba(81,95,116,0.12); color: #3a485b; }
.badge-cardio  { background: rgba(239,68,68,0.12);  color: #c0392b; }
.badge-renal   { background: rgba(16,185,129,0.12); color: #047857; }
.badge-neural  { background: rgba(139,92,246,0.12); color: #6d28d9; }
.badge-pulm    { background: rgba(59,130,246,0.12); color: #1d4ed8; }
.badge-heme    { background: rgba(186,26,26,0.12);  color: #9b1c1c; }

.book-size {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 0.72rem;
  color: var(--text-muted);
}
.book-size .material-symbols-outlined { font-size: 0.9rem; }

.book-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 2px;
}

.book-download-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary);
  padding: 5px 12px;
  border-radius: 6px;
  background: var(--primary-light);
  transition: background var(--transition), color var(--transition);
}
.book-download-btn:hover {
  background: var(--primary);
  color: var(--on-primary);
}
.book-download-btn .material-symbols-outlined { font-size: 0.88rem; }

/* ── Skeleton ────────────────────────────────────────────── */
.book-card.skeleton {
  pointer-events: none;
  background: var(--surface-card);
  min-height: 72px;
  position: relative;
  overflow: hidden;
}

.book-card.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(255,255,255,0.65) 50%,
    transparent 100%);
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

/* ── Empty / Error State ─────────────────────────────────── */
.empty-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  color: var(--text-muted);
  gap: 12px;
  text-align: center;
}

.empty-state .material-symbols-outlined {
  font-size: 3.5rem;
  font-variation-settings: 'FILL' 0, 'wght' 200;
}

.empty-state p {
  font-size: 1rem;
  color: var(--text-secondary);
}

/* ── Footer ──────────────────────────────────────────────── */
.page-footer {
  margin-top: 48px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
}

/* ── Spinner ─────────────────────────────────────────────── */
.spin {
  animation: spin 1s linear infinite;
  display: inline-block;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ── Mobile Bottom Nav ───────────────────────────────────── */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 60px;
  background: var(--surface-card);
  border-top: 1px solid var(--border);
  align-items: center;
  justify-content: space-around;
  z-index: 200;
}

.mobile-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.6rem;
  font-family: var(--font-body);
  font-weight: 600;
  padding: 6px 16px;
  transition: color var(--transition);
}

.mobile-nav-btn.active { color: var(--primary); }
.mobile-nav-btn .material-symbols-outlined { font-size: 1.4rem; }

/* ── Mobile Bottom Sheet ─────────────────────────────────── */
.sheet-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 300;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sheet-overlay.visible { opacity: 1; }

.systems-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface-card);
  border-radius: 20px 20px 0 0;
  padding: 12px 20px 80px;
  z-index: 400;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32,0.72,0,1);
  max-height: 70vh;
  overflow-y: auto;
}

.systems-sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  margin: 0 auto 16px;
}

.sheet-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-heading);
  margin-bottom: 14px;
}

.sheet-filters {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sheet-filters .btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-low);
  color: var(--text-body);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background var(--transition), color var(--transition);
}

.sheet-filters .btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
  font-weight: 700;
}

/* ── Mobile System Header ────────────────────────────────── */
.mobile-system-header {
  display: none;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar       { display: none; }
  .mobile-nav    { display: flex; }
  .main-content  { margin-left: 0; padding: 16px 14px 80px; width: 100%; }
  .stats-row     { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .stat-card     { padding: 12px 14px; }
  .stat-number   { font-size: 1.2rem; }
  .topnav        { padding: 0 14px; gap: 10px; }
  .topnav-search { max-width: 100%; }
  .topnav-search input { font-size: 16px; }
  .back-btn span:not(.material-symbols-outlined) { display: none; }
  .back-btn      { padding: 7px 10px; }
  .brand-title   { font-size: 0.9rem; }
  .books-grid    { grid-template-columns: 1fr; gap: 10px; width: 100%; }

  .mobile-system-header {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: border-color var(--transition), box-shadow var(--transition);
  }

  .mobile-system-header:active {
    border-color: var(--primary);
  }

  .mobile-system-badge-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: rgba(0, 40, 142, 0.10);
    color: var(--primary);
    transition: background var(--transition), color var(--transition);
  }

  .mobile-system-badge-icon .material-symbols-outlined {
    font-size: 1.3rem;
  }

  .mobile-system-details {
    flex: 1;
    min-width: 0;
  }

  .mobile-system-kicker {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    line-height: 1.2;
  }

  .mobile-system-name {
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-heading);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-system-filter-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--surface-low);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: var(--font-body);
    color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--transition), border-color var(--transition);
  }

  .mobile-system-filter-btn:active {
    background: var(--primary-light);
    border-color: var(--primary);
  }

  .mobile-system-filter-btn .material-symbols-outlined {
    font-size: 1rem;
  }
}

@media (max-width: 480px) {
  .books-grid    { grid-template-columns: 1fr; }
  .book-card     { padding: 12px 14px; }
  .book-title-text { font-size: 0.85rem; }
}

/* search highlight */
mark {
  background: #fef08a;
  color: #0f172a;
  font-weight: 700;
  border-radius: 2px;
  padding: 0 2px;
}