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

:root {
  --sidebar-w: 220px;
  --topbar-h: 56px;
  --bnav-h:   64px;

  --bg:        #fdf8fe;
  --bg2:       #f6ecfb;
  --card:      #ffffff;
  --border:    #efe2f6;
  --sidebar:   #efe3fb;
  --sidebar2:  #e3d2f4;
  --stext:     #5b3a86;
  --stext2:    #9a82bd;
  --accent:    #a855f7;
  --accent2:   #9333ea;
  --accentlt:  #f5ebff;
  --txt:       #3a2e49;
  --txt2:      #8a7ca0;
  --txt3:      #b6abc7;
  --star:      #f5a623;
  --green:     #10b981;
  --blue:      #6366f1;
  --purple:    #a855f7;
  --pink:      #ec4899;
  --red:       #ef4444;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.12);
  --radius:    12px;
  --radius-sm: 8px;
  --trans:     .18s ease;
}

[data-theme="dark"] {
  --bg:       #15101d;
  --bg2:      #201830;
  --card:     #251c38;
  --border:   #382b52;
  --sidebar:  #100b18;
  --sidebar2: #1d1430;
  --stext:    #f0e6fb;
  --stext2:   #9483b0;
  --txt:      #f0e6fb;
  --txt2:     #b3a6c9;
  --txt3:     #6f6388;
  --accentlt: #2c2042;
  --shadow:    0 1px 3px rgba(0,0,0,.3);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.4);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--txt);
  line-height: 1.5;
  overflow-x: hidden;
}

/* ── Layout ── */
#app {
  display: flex;
  min-height: 100vh;
}

#sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
  transition: transform var(--trans);
}

#main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  padding: 32px;
  max-width: calc(100vw - var(--sidebar-w));
}

#topbar  { display: none; }
#bottom-nav { display: none; }

/* ── Sidebar ── */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 20px 20px;
  color: var(--stext);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: .5px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand-icon { font-size: 1.5rem; }

.nav-links {
  list-style: none;
  padding: 12px 0;
  flex: 1;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 20px;
  color: var(--stext2);
  text-decoration: none;
  font-size: .92rem;
  font-weight: 500;
  border-radius: 0;
  transition: background var(--trans), color var(--trans);
  border-left: 3px solid transparent;
}
.nav-link:hover { background: var(--sidebar2); color: var(--stext); }
.nav-link.active {
  background: var(--sidebar2);
  color: var(--stext);
  border-left-color: var(--accent);
}
.nav-link span { font-size: 1.1rem; width: 22px; text-align: center; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.07);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.theme-btn, .reset-btn {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,.12);
  background: transparent;
  color: var(--stext2);
  font-size: .82rem;
  cursor: pointer;
  transition: background var(--trans), color var(--trans);
}
.theme-btn:hover, .reset-btn:hover {
  background: var(--sidebar2);
  color: var(--stext);
}
.reset-btn { font-size: .75rem; opacity: .6; }

/* ── Mobile ── */
@media (max-width: 768px) {
  #sidebar { display: none; }
  #topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: var(--topbar-h);
    background: var(--sidebar);
    color: var(--stext);
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 100;
  }
  .brand-mobile { font-weight: 700; font-size: 1.1rem; }
  #bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--bnav-h);
    background: var(--sidebar);
    border-top: 1px solid rgba(255,255,255,.08);
    z-index: 100;
  }
  .bnav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--stext2);
    text-decoration: none;
    font-size: 1.3rem;
    transition: color var(--trans);
  }
  .bnav-item small { font-size: .68rem; }
  .bnav-item.active { color: var(--accent); }
  #main {
    margin-left: 0;
    max-width: 100vw;
    padding: 16px;
    padding-top: calc(var(--topbar-h) + 16px);
    padding-bottom: calc(var(--bnav-h) + 16px);
  }
  .icon-btn {
    background: none; border: none; color: var(--stext);
    font-size: 1.2rem; cursor: pointer; padding: 4px;
  }
}

/* ── Page headings ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-title {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--txt);
  letter-spacing: -.3px;
}
.page-subtitle {
  color: var(--txt2);
  font-size: .9rem;
  margin-top: 2px;
}

/* ── Cards ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--trans);
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent2); }
.btn-secondary {
  background: var(--bg2);
  color: var(--txt);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }
.btn-ghost {
  background: transparent;
  color: var(--txt2);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg2); color: var(--txt); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: .85; }
.btn-sm { padding: 6px 12px; font-size: .82rem; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--txt2);
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 9px 13px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--txt);
  font-size: .9rem;
  transition: border-color var(--trans);
  font-family: inherit;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }

/* ── Status badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-tbr      { background: #e0e7ff; color: #4338ca; }
.badge-read     { background: #dbeafe; color: var(--blue); }
.badge-reading  { background: #d1fae5; color: var(--green); }
.badge-owned    { background: #ede9fe; color: #7c3aed; }
.badge-wishlist { background: #fce7f3; color: var(--pink); }
[data-theme="dark"] .badge-tbr      { background: #312e81; color: #c7d2fe; }
[data-theme="dark"] .badge-read     { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .badge-reading  { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .badge-owned    { background: #3b1f6e; color: #c4b5fd; }
[data-theme="dark"] .badge-wishlist { background: #5b1e3a; color: #f9a8d4; }

/* ── Stars ── */
.stars { display: inline-flex; gap: 2px; }
.star  { color: var(--border); font-size: .9rem; cursor: pointer; transition: color var(--trans); }
.star.filled { color: var(--star); }

/* ── Home page ── */
.home-hero {
  background: linear-gradient(135deg, #c026d3 0%, #7c3aed 100%);
  border-radius: var(--radius);
  padding: 32px;
  color: #fff;
  margin-bottom: 28px;
  position: relative;
  overflow: hidden;
}
.home-hero::before {
  content: '📚';
  position: absolute;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 5rem;
  opacity: .25;
}
.hero-greeting { font-size: 1rem; opacity: .85; margin-bottom: 4px; }
.hero-title { font-size: 1.9rem; font-weight: 700; margin-bottom: 8px; }
.hero-sub { font-size: .9rem; opacity: .8; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  text-align: center;
}
.stat-num { font-size: 2rem; font-weight: 700; color: var(--accent); line-height: 1; }
.stat-label { font-size: .8rem; color: var(--txt2); margin-top: 4px; }

.home-sections {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 900px) { .home-sections { grid-template-columns: 1fr; } }

.section-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.reading-card {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding: 14px;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  border: 1px solid var(--border);
}
.reading-card-cover {
  width: 52px;
  height: 76px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--border);
}
.reading-card-info { flex: 1; min-width: 0; }
.reading-card-title { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reading-card-author { font-size: .8rem; color: var(--txt2); margin-bottom: 8px; }
.progress-bar-wrap { background: var(--border); border-radius: 4px; height: 6px; overflow: hidden; }
.progress-bar { height: 6px; background: var(--green); border-radius: 4px; transition: width .3s; }
.progress-label { font-size: .75rem; color: var(--txt2); margin-top: 4px; }

.activity-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-icon { font-size: 1.2rem; width: 32px; text-align: center; }
.activity-text { flex: 1; font-size: .85rem; }
.activity-text strong { font-weight: 600; }
.activity-date { font-size: .75rem; color: var(--txt3); }

.goal-bar-wrap { margin-top: 8px; }
.goal-bar-bg { background: var(--bg2); border-radius: 8px; height: 10px; overflow: hidden; border: 1px solid var(--border); }
.goal-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--star)); border-radius: 8px; transition: width .5s; }
.goal-label { font-size: .8rem; color: var(--txt2); margin-top: 6px; }

/* ── Library page ── */
.library-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 180px;
}
.search-input-wrap .search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--txt3);
  pointer-events: none;
}
.search-filter-input {
  width: 100%;
  padding: 9px 13px 9px 34px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--txt);
  font-size: .9rem;
}
.search-filter-input:focus { outline: none; border-color: var(--accent); }

.filter-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.filter-tab {
  padding: 7px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--txt2);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--trans);
}
.filter-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.filter-tab:hover:not(.active) { border-color: var(--accent); color: var(--accent); }

.view-toggle { display: flex; gap: 4px; }
.view-btn {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--txt2);
  cursor: pointer;
  transition: all var(--trans);
  font-size: .9rem;
}
.view-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}
.books-list { display: flex; flex-direction: column; gap: 10px; }

.book-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--trans), box-shadow var(--trans);
  box-shadow: var(--shadow);
}
.book-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }

.book-cover-wrap {
  position: relative;
  padding-top: 148%;
  background: var(--bg2);
  overflow: hidden;
}
.book-cover-wrap img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.book-cover-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 2.5rem;
  color: var(--txt3);
  background: linear-gradient(135deg, var(--bg2), var(--border));
  padding: 10px;
  text-align: center;
}
.book-cover-placeholder .placeholder-title {
  font-size: .7rem;
  color: var(--txt3);
  line-height: 1.2;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.book-status-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #fff;
}
.book-status-dot.tbr     { background: #6366f1; }
.book-status-dot.read    { background: var(--blue); }
.book-status-dot.reading { background: var(--green); }
.book-status-dot.owned   { background: var(--purple); }
.book-status-dot.wishlist{ background: var(--pink); }

.book-own-tag {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(236,72,153,.92);
  color: #fff;
  font-size: .62rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  letter-spacing: .3px;
}

.book-card-info { padding: 12px; }
.book-card-title { font-size: .85rem; font-weight: 600; line-height: 1.3; margin-bottom: 3px;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.book-card-author { font-size: .75rem; color: var(--txt2); }

/* List view */
.book-list-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 12px 16px;
  cursor: pointer;
  transition: border-color var(--trans), box-shadow var(--trans);
  box-shadow: var(--shadow);
}
.book-list-item:hover { border-color: var(--accent); box-shadow: var(--shadow-lg); }
.book-list-cover {
  width: 44px;
  height: 64px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--bg2);
}
.book-list-info { flex: 1; min-width: 0; }
.book-list-title { font-weight: 600; font-size: .93rem; }
.book-list-author { font-size: .82rem; color: var(--txt2); }
.book-list-meta { display: flex; align-items: center; gap: 10px; margin-top: 6px; flex-wrap: wrap; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--txt2);
}
.empty-state .empty-icon { font-size: 4rem; margin-bottom: 16px; }
.empty-state h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 8px; color: var(--txt); }
.empty-state p { font-size: .88rem; margin-bottom: 20px; }

/* ── Search page ── */
.search-bar-big {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}
.search-bar-big input {
  flex: 1;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--card);
  color: var(--txt);
  font-size: 1rem;
  transition: border-color var(--trans);
}
.search-bar-big input:focus { outline: none; border-color: var(--accent); }

.search-results { display: flex; flex-direction: column; gap: 12px; }
.search-result-item {
  display: flex;
  gap: 16px;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 14px;
  box-shadow: var(--shadow);
}
.search-result-cover {
  width: 60px;
  height: 88px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--bg2);
}
.search-result-info { flex: 1; min-width: 0; }
.search-result-title { font-weight: 700; font-size: .95rem; margin-bottom: 3px; }
.search-result-author { font-size: .85rem; color: var(--txt2); margin-bottom: 6px; }
.search-result-meta { font-size: .8rem; color: var(--txt3); margin-bottom: 10px; }
.search-result-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--txt2);
  gap: 12px;
}
.spin {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Scanner ── */
.scanner-container {
  max-width: 500px;
  margin: 0 auto;
  text-align: center;
}
.scanner-box {
  background: var(--card);
  border-radius: var(--radius);
  border: 2px dashed var(--border);
  padding: 24px;
  margin-bottom: 20px;
}
#reader { border-radius: var(--radius-sm); overflow: hidden; }
.scanner-result {
  background: var(--accentlt);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
  text-align: left;
}

/* ── Stats ── */
.stats-overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.stat-big {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-big-num { font-size: 2.2rem; font-weight: 800; color: var(--accent); line-height: 1; }
.stat-big-label { font-size: .78rem; color: var(--txt2); margin-top: 5px; text-transform: uppercase; letter-spacing: .5px; }

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
@media (max-width: 700px) { .charts-grid { grid-template-columns: 1fr; } }
.chart-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.chart-title { font-size: .9rem; font-weight: 700; margin-bottom: 14px; color: var(--txt); }
.chart-wrap { position: relative; height: 200px; }

.top-list { list-style: none; }
.top-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: .88rem;
}
.top-list-item:last-child { border-bottom: none; }
.top-list-rank { font-weight: 700; color: var(--accent); width: 24px; }
.top-list-num { color: var(--txt2); font-size: .82rem; }

/* ── Calendar ── */
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.cal-month-label { font-size: 1.1rem; font-weight: 700; }
.cal-nav-btn {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  cursor: pointer;
  color: var(--txt);
  font-size: .9rem;
  transition: all var(--trans);
}
.cal-nav-btn:hover { border-color: var(--accent); color: var(--accent); }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-day-header {
  text-align: center;
  font-size: .75rem;
  font-weight: 700;
  color: var(--txt3);
  padding: 6px 0;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.cal-day {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 70px;
  padding: 6px;
  cursor: pointer;
  transition: all var(--trans);
  position: relative;
}
.cal-day:hover { border-color: var(--accent); }
.cal-day.empty { background: transparent; border-color: transparent; cursor: default; }
.cal-day.today { border-color: var(--accent); background: var(--accentlt); }
.cal-day.has-event { border-color: var(--blue); }
.cal-day-num { font-size: .82rem; font-weight: 600; color: var(--txt2); }
.cal-day.today .cal-day-num { color: var(--accent); font-weight: 700; }
.cal-events { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }
.cal-event {
  font-size: .65rem;
  padding: 2px 5px;
  border-radius: 3px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-event.started  { background: #d1fae5; color: #065f46; }
.cal-event.finished { background: #dbeafe; color: #1e40af; }
[data-theme="dark"] .cal-event.started  { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .cal-event.finished { background: #1e3a5f; color: #93c5fd; }

.cal-legend {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.cal-legend-item { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--txt2); }
.cal-legend-dot {
  width: 10px; height: 10px; border-radius: 50%;
}
.cal-legend-dot.started  { background: var(--green); }
.cal-legend-dot.finished { background: var(--blue); }
.cal-legend-dot.today    { background: var(--accent); }

.cal-detail {
  margin-top: 24px;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
}
.cal-detail-title { font-size: 1rem; font-weight: 700; margin-bottom: 12px; }
.cal-detail-item { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.cal-detail-item:last-child { border-bottom: none; }

/* ── Modal ── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
  backdrop-filter: blur(4px);
}
#modal-overlay.hidden { display: none; }
#modal {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
  position: relative;
  box-shadow: var(--shadow-lg);
}
.modal-close-btn {
  position: absolute;
  top: 16px; right: 16px;
  background: var(--bg2);
  border: none;
  border-radius: 50%;
  width: 32px; height: 32px;
  font-size: .9rem;
  cursor: pointer;
  color: var(--txt2);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--trans);
}
.modal-close-btn:hover { background: var(--red); color: #fff; }
.modal-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 20px; padding-right: 40px; }

.book-detail-header {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  align-items: flex-start;
}
.book-detail-cover {
  width: 90px;
  height: 132px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--bg2);
  box-shadow: 4px 4px 12px rgba(0,0,0,.2);
}
.book-detail-info { flex: 1; }
.book-detail-title { font-size: 1.15rem; font-weight: 700; line-height: 1.3; margin-bottom: 4px; }
.book-detail-author { color: var(--txt2); font-size: .9rem; margin-bottom: 10px; }
.book-detail-meta { font-size: .82rem; color: var(--txt3); line-height: 1.8; }
.book-detail-desc { font-size: .88rem; color: var(--txt2); line-height: 1.6; margin-bottom: 16px; max-height: 100px; overflow-y: auto; }
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--txt);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  animation: slideUp .25s ease;
  max-width: 320px;
}
#toast.hidden { display: none; }
#toast.success { background: var(--green); color: #fff; }
#toast.error   { background: var(--red);   color: #fff; }
@keyframes slideUp { from { opacity:0; transform: translateY(12px); } to { opacity:1; transform: translateY(0); } }

/* ── Utility ── */
.hidden { display: none !important; }
.flex-row { display: flex; align-items: center; gap: 10px; }
.text-muted { color: var(--txt2); font-size: .85rem; }
.mt-2 { margin-top: 8px; }
.mb-2 { margin-bottom: 8px; }
.full-width { width: 100%; }

/* ── Floating add button (FAB) ── */
.fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 2.1rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(168,85,247,.45);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--trans), background var(--trans);
}
.fab:hover  { background: var(--accent2); transform: scale(1.07); }
.fab:active { transform: scale(.95); }
.fab.on-add { background: var(--accent2); transform: rotate(45deg); }
@media (max-width: 768px) {
  .fab {
    bottom: calc(var(--bnav-h) + env(safe-area-inset-bottom, 0) + 14px);
    right: 16px;
    width: 54px;
    height: 54px;
  }
}

/* ── Add-a-Book tabs ── */
.add-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.add-tab {
  padding: 10px 18px;
  border-radius: 22px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--txt2);
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: all var(--trans);
}
.add-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.add-tab:hover:not(.active) { border-color: var(--accent); color: var(--accent); }

/* ── Install banner (PWA) ── */
#install-banner {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bnav-h) + 16px);
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 300;
  font-size: .88rem;
  font-weight: 600;
  color: var(--txt);
  animation: slideUp .25s ease;
}
#install-banner.hidden { display: none !important; }
.install-banner-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.install-banner-actions .icon-btn { color: var(--txt2); font-size: 1rem; }
@media (min-width: 769px) {
  #install-banner { bottom: 24px; left: auto; right: 24px; transform: none; }
}

/* ── Safe-area insets (phone notches / home bars) ── */
@media (max-width: 768px) {
  #topbar {
    padding-top: env(safe-area-inset-top, 0);
    height: calc(var(--topbar-h) + env(safe-area-inset-top, 0));
  }
  #bottom-nav {
    padding-bottom: env(safe-area-inset-bottom, 0);
    height: calc(var(--bnav-h) + env(safe-area-inset-bottom, 0));
  }
  #main {
    padding-top: calc(var(--topbar-h) + env(safe-area-inset-top, 0) + 16px);
    padding-bottom: calc(var(--bnav-h) + env(safe-area-inset-bottom, 0) + 16px);
  }
}

/* No-books state placeholder cover */
.cover-fallback {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  font-size: 2rem; gap: 6px;
  background: linear-gradient(135deg, #e9ddd0, #d4c5b2);
  color: #8b7355;
}
[data-theme="dark"] .cover-fallback { background: linear-gradient(135deg, #2a211a, #1a1310); color: #7a6a5e; }
