/* ============================================================
   Pharmmy BookClub — app.css
   Shared layout + components (vanilla CSS, no build step)
   ============================================================ */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
h1,h2,h3,h4,h5 { margin: 0; font-weight: var(--weight-semibold); line-height: var(--leading-tight); }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
img { max-width: 100%; display: block; }
button { font-family: inherit; font-size: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; }
ul { margin: 0; padding: 0; list-style: none; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: var(--radius-xs); }
.serif { font-family: var(--font-display); }
.mono { font-family: var(--font-mono); }
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; border:0; }

/* ============================================================
   APP SHELL
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar (desktop) ---------- */
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-4);
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-2) var(--space-4);
}
.brand-mark {
  width: 42px; height: 42px;
  border-radius: var(--radius-md);
  background: linear-gradient(150deg, var(--clay-400), var(--clay-600));
  color: #fff;
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  box-shadow: var(--shadow-sm);
  flex: none;
}
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: var(--text-md); letter-spacing: -0.01em; }
.brand-sub { font-size: var(--text-xs); color: var(--ink-3); margin-top: -2px; }

.nav-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  padding: var(--space-3) var(--space-2) var(--space-1);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--ink-2);
  font-weight: var(--weight-medium);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-item svg { width: 21px; height: 21px; flex: none; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: var(--weight-semibold); }
:root[data-theme="dark"] .nav-item.active,
.nav-item.active { }
.nav-count { margin-left: auto; font-size: var(--text-xs); color: var(--ink-3); background: var(--surface-2); padding: 1px 8px; border-radius: var(--radius-full); }
.nav-item.active .nav-count { background: rgba(255,255,255,0.5); color: var(--primary); }

.sidebar-foot { margin-top: auto; padding-top: var(--space-4); }

/* ---------- Main + Topbar ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-6);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}
.topbar .page-title { font-family: var(--font-display); font-weight: 700; font-size: var(--text-lg); white-space: nowrap; }

.search {
  flex: 1;
  max-width: 460px;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  height: 42px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-full);
  color: var(--ink-3);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.search:focus-within { border-color: var(--clay-300); box-shadow: 0 0 0 3px var(--primary-soft); }
.search svg { width: 18px; height: 18px; flex: none; }
.search input { border: 0; background: transparent; outline: none; flex: 1; color: var(--ink); }
.search input::placeholder { color: var(--ink-3); }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }

.content { padding: var(--space-6); max-width: var(--content-max); width: 100%; margin: 0 auto; }
.content.narrow { max-width: 860px; }

.page-head { margin-bottom: var(--space-5); }
.page-head h1 { font-family: var(--font-display); font-size: var(--text-2xl); font-weight: 700; letter-spacing: -0.02em; }
.page-head .lede { color: var(--ink-2); margin-top: var(--space-1); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  --bg: var(--surface); --fg: var(--ink); --bd: var(--line);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: 42px; padding: 0 var(--space-4);
  border: 1px solid var(--bd);
  border-radius: var(--radius-full);
  background: var(--bg); color: var(--fg);
  font-weight: var(--weight-semibold);
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast), border-color var(--dur-fast), box-shadow var(--dur-fast);
  white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover { border-color: var(--line-strong); }
.btn:active { transform: translateY(1px); }
.btn-primary { --bg: var(--primary); --fg: var(--primary-ink); --bd: transparent; box-shadow: var(--shadow-sm); }
.btn-primary:hover { --bg: var(--primary-hover); border-color: transparent; }
.btn-accent { --bg: var(--accent); --fg: #fff; --bd: transparent; }
.btn-ghost { --bg: transparent; --bd: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { --bg: var(--danger-soft); --fg: var(--danger); --bd: transparent; }
.btn-sm { height: 34px; padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn-lg { height: 50px; padding: 0 var(--space-5); font-size: var(--text-md); }
.btn-icon { width: 42px; height: 42px; padding: 0; border-radius: var(--radius-full); }
.btn-icon.btn-sm { width: 34px; height: 34px; }
.btn-block { width: 100%; }

/* icon-only round toggle in topbar */
.icon-toggle {
  width: 42px; height: 42px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--radius-full);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.icon-toggle:hover { color: var(--ink); border-color: var(--line-strong); }
.icon-toggle svg { width: 20px; height: 20px; }
.theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .theme-toggle .sun { display: none; }
  :root[data-theme="auto"] .theme-toggle .moon { display: block; }
}

/* ============================================================
   BADGES / CHIPS / PILLS
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  background: var(--surface-2);
  color: var(--ink-2);
  line-height: 1.4;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.badge-unread  { background: color-mix(in srgb, var(--status-unread) 16%, transparent); color: var(--status-unread); }
.badge-reading { background: var(--primary-soft); color: var(--primary); }
.badge-done    { background: var(--accent-soft); color: var(--accent); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger  { background: var(--danger-soft); color: var(--danger); }
.badge-info    { background: var(--info-soft); color: var(--info); }

/* Filter chips */
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 var(--space-4);
  border-radius: var(--radius-full);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-size: var(--text-sm); font-weight: var(--weight-medium);
  transition: all var(--dur-fast) var(--ease);
}
.chip:hover { border-color: var(--line-strong); color: var(--ink); }
.chip.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip .chip-count { opacity: 0.6; font-size: var(--text-xs); }

/* ============================================================
   BOOK COVER + CARD  (ปกคือพระเอก)
   ============================================================ */
.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--space-5) var(--space-4);
}
.book-card {
  display: flex; flex-direction: column; gap: var(--space-2);
  color: var(--ink);
  transition: transform var(--dur) var(--ease);
}
.book-card:hover { color: var(--ink); transform: translateY(-4px); }

.cover {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--g, linear-gradient(150deg, var(--clay-400), var(--clay-600)));
  box-shadow: var(--shadow-book);
  display: flex; flex-direction: column;
  padding: 16px 15px;
  color: #fff;
  isolation: isolate;
}
/* spine + gloss + paper edge */
.cover::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background:
    linear-gradient(105deg, rgba(255,255,255,0.16) 0%, rgba(255,255,255,0) 28%),
    linear-gradient(to right, rgba(0,0,0,0.28) 0, rgba(0,0,0,0.08) 5%, rgba(0,0,0,0) 11%),
    radial-gradient(120% 80% at 50% 0%, rgba(255,255,255,0.14), rgba(0,0,0,0.22));
}
.cover::after { /* right page edge */
  content: ""; position: absolute; top: 3%; bottom: 3%; right: 0; width: 5px;
  background: linear-gradient(to right, rgba(255,255,255,0.32), rgba(255,255,255,0));
  border-radius: 2px;
}
.cover-brandline { font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; opacity: 0.72; }
.cover-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.02rem;
  line-height: 1.2;
  margin-top: 6px;
  text-wrap: balance;
  text-shadow: 0 1px 3px rgba(0,0,0,0.28);
}
.cover-author { margin-top: auto; font-size: 0.72rem; opacity: 0.85; }
.cover-vol {
  position: absolute; left: 14px; bottom: 12px;
  font-family: var(--font-display); font-weight: 700; font-size: 0.7rem;
  opacity: 0.9;
}
/* status corner on cover */
.cover .status-tag {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  padding: 3px 8px; border-radius: var(--radius-full);
  font-size: 10px; font-weight: 700;
  background: rgba(0,0,0,0.42); color:#fff; backdrop-filter: blur(4px);
}
.cover .status-tag.reading { background: rgba(0,0,0,0.35); }

.book-meta { padding: 0 2px; }
.book-title { font-weight: var(--weight-semibold); font-size: var(--text-sm); line-height: 1.3; }
.book-title.clamp, .cover-title.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-sub { font-size: var(--text-xs); color: var(--ink-3); margin-top: 1px; }
.book-price { font-size: var(--text-xs); color: var(--ink-2); font-weight: var(--weight-semibold); margin-top: 2px; }

/* small horizontal cover for lists */
.cover-sm {
  width: 52px; aspect-ratio: 2/3; border-radius: var(--radius-xs);
  flex: none; box-shadow: var(--shadow-sm);
  background: var(--g, linear-gradient(150deg,var(--clay-400),var(--clay-600)));
  display:flex; align-items:flex-end; padding:6px; color:#fff;
  font-family: var(--font-display); font-size: 8px; font-weight:700; line-height:1.1;
  overflow: hidden;
}

/* ============================================================
   CARD / PANEL
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}
.card-pad-lg { padding: var(--space-6); }
.card-title { font-family: var(--font-display); font-weight: 700; font-size: var(--text-md); }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); gap: var(--space-4); }
.section-head h2 { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 700; }

.divider { height: 1px; background: var(--line); border: 0; margin: var(--space-5) 0; }

/* ============================================================
   FORMS
   ============================================================ */
.field { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
.label { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--ink-2); }
.hint { font-size: var(--text-xs); color: var(--ink-3); }
.input, .select, .textarea {
  width: 100%;
  height: 46px;
  padding: 0 var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  color: var(--ink);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.textarea { height: auto; min-height: 96px; padding: var(--space-3) var(--space-4); resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--clay-400); box-shadow: 0 0 0 3px var(--primary-soft); }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a7c6c' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 40px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }

/* ============================================================
   MODAL / TOAST
   ============================================================ */
.modal-scrim {
  position: fixed; inset: 0; z-index: 100;
  background: var(--overlay);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  padding: var(--space-4);
  opacity: 0; visibility: hidden;
  transition: opacity var(--dur) var(--ease), visibility var(--dur);
}
.modal-scrim.open { opacity: 1; visibility: visible; }
.modal {
  width: 100%; max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6);
  transform: translateY(14px) scale(0.98);
  transition: transform var(--dur) var(--ease);
}
.modal-scrim.open .modal { transform: none; }
.modal-icon { width: 52px; height: 52px; border-radius: var(--radius-md); display: grid; place-items: center; margin-bottom: var(--space-4); }
.modal-icon svg { width: 26px; height: 26px; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  max-width: 440px; margin: 0 auto;
}
.empty-art {
  width: 108px; height: 108px; margin: 0 auto var(--space-5);
  border-radius: var(--radius-xl);
  display: grid; place-items: center;
  background: var(--surface-2);
  color: var(--clay-400);
}
.empty-art svg { width: 52px; height: 52px; }
.empty h3 { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 700; }
.empty p { color: var(--ink-2); margin: var(--space-2) 0 var(--space-5); }

/* ============================================================
   STAT TILES (dashboard)
   ============================================================ */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-4); }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-1);
}
.stat-ico { width: 38px; height: 38px; border-radius: var(--radius-sm); display: grid; place-items: center; margin-bottom: var(--space-2); }
.stat-ico svg { width: 20px; height: 20px; }
.stat-value { font-family: var(--font-display); font-size: var(--text-3xl); font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.stat-value .unit { font-size: var(--text-md); font-weight: 600; color: var(--ink-3); margin-left: 3px; }
.stat-label { font-size: var(--text-sm); color: var(--ink-2); }
.stat-trend { font-size: var(--text-xs); font-weight: 600; }
.trend-up { color: var(--success); }

/* progress bar */
.progress { height: 9px; border-radius: var(--radius-full); background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--primary); }
.progress.accent > span { background: var(--accent); }

/* bar chart (pure css) */
.bars { display: flex; align-items: flex-end; gap: var(--space-3); height: 180px; padding-top: var(--space-4); }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: var(--space-2); height: 100%; justify-content: flex-end; }
.bar {
  width: 100%; max-width: 40px; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: linear-gradient(to top, var(--clay-500), var(--clay-300));
  min-height: 4px; transition: height var(--dur-slow) var(--ease);
}
.bar-label { font-size: var(--text-xs); color: var(--ink-3); }
.bar-val { font-size: var(--text-xs); font-weight: 700; color: var(--ink-2); }

/* ============================================================
   RATING STARS
   ============================================================ */
.stars { display: inline-flex; gap: 2px; color: var(--gold-500); }
.stars svg { width: 16px; height: 16px; }
.stars .empty-star { color: var(--line-strong); }

/* ============================================================
   MOBILE BOTTOM NAV + FAB
   ============================================================ */
.bottom-nav { display: none; }
.fab { display: none; }

/* ============================================================
   TABS
   ============================================================ */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--line); margin-bottom: var(--space-5); overflow-x: auto; }
.tab {
  padding: var(--space-3) var(--space-4); border: 0; background: transparent;
  color: var(--ink-3); font-weight: var(--weight-semibold); white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color var(--dur-fast);
}
.tab:hover { color: var(--ink-2); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* utility */
.row { display: flex; align-items: center; gap: var(--space-3); }
.between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--ink-3); }
.stack { display: flex; flex-direction: column; }
.gap-2 { gap: var(--space-2); } .gap-3 { gap: var(--space-3); } .gap-4 { gap: var(--space-4); } .gap-5 { gap: var(--space-5); }
.mt-2{margin-top:var(--space-2)} .mt-3{margin-top:var(--space-3)} .mt-4{margin-top:var(--space-4)} .mt-5{margin-top:var(--space-5)} .mt-6{margin-top:var(--space-6)}
.hide { display: none !important; }

/* ============================================================
   RESPONSIVE  — มือถือสำคัญเท่าเดสก์ท็อป
   ============================================================ */
@media (max-width: 1080px) {
  .shelf { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding: 0 var(--space-4); }
  .content { padding: var(--space-4); padding-bottom: calc(var(--space-8) + 40px); }
  .page-head h1 { font-size: var(--text-xl); }

  /* covers: 2–3 columns on mobile */
  .shelf { grid-template-columns: repeat(2, 1fr); gap: var(--space-4) var(--space-3); }

  /* bottom nav */
  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bn-item {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 6px 0; color: var(--ink-3); font-size: 10px; font-weight: var(--weight-medium);
  }
  .bn-item svg { width: 23px; height: 23px; }
  .bn-item.active { color: var(--primary); }
  .bn-item.bn-add { position: relative; }
  .bn-add .bn-plus {
    width: 46px; height: 46px; margin-top: -20px; border-radius: var(--radius-full);
    background: var(--primary); color: var(--primary-ink);
    display: grid; place-items: center; box-shadow: var(--shadow-md);
    border: 3px solid var(--paper);
  }
  .bn-add .bn-plus svg { width: 24px; height: 24px; }

  .field-row { grid-template-columns: 1fr; }
  .topbar .page-title { display: none; }
}

@media (min-width: 481px) and (max-width: 860px) {
  .shelf { grid-template-columns: repeat(3, 1fr); }
}
