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

:root {
  --bg: #111318;
  --surface: #1c1f26;
  --surface2: #252930;
  --border: #2e3340;
  --text: #e2e6f0;
  --text-muted: #7a8196;
  --accent: #4f9cf8;
  --accent-hover: #6aadff;
  --active-color: #22c55e;
  --active-bg: #14281e;
  --badge-book: #1e3a5f;
  --badge-book-text: #7dd3fc;
  --badge-audio: #2d1f4a;
  --badge-audio-text: #c4b5fd;
}

html { font-size: 15px; }
body { background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, sans-serif; min-height: 100vh; }

/* NAV */
nav { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 20px; position: sticky; top: 0; z-index: 100; }
.nav-inner { display: flex; align-items: center; gap: 0; max-width: 1600px; margin: 0 auto; }
.nav-brand { font-weight: 700; font-size: 1rem; color: var(--text); padding: 14px 20px 14px 0; text-decoration: none; margin-right: 8px; border-right: 1px solid var(--border); }
.nav-link { color: var(--text-muted); text-decoration: none; padding: 14px 16px; font-size: 0.9rem; transition: color 0.15s; white-space: nowrap; }
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--accent); border-bottom: 2px solid var(--accent); }
.nav-count { font-size: 0.75rem; background: var(--surface2); padding: 2px 7px; border-radius: 10px; margin-left: 5px; }
.nav-spacer { flex: 1; }
.nav-active-bar { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; }
#active-indicator { color: var(--active-color); font-weight: 600; }
.save-btn { background: var(--accent); color: #fff; border: none; padding: 6px 16px; border-radius: 6px; cursor: pointer; font-size: 0.85rem; font-weight: 600; transition: background 0.15s; }
.save-btn:hover { background: var(--accent-hover); }
.save-btn.saved { background: var(--active-color); }
.save-btn:disabled { opacity: 0.5; cursor: default; }

/* LAYOUT */
.page { display: flex; max-width: 1600px; margin: 0 auto; padding: 20px; gap: 20px; min-height: calc(100vh - 50px); }

/* SIDEBAR */
aside { width: 220px; flex-shrink: 0; }
.sidebar-sticky { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.sidebar-sticky::-webkit-scrollbar { width: 4px; }
.sidebar-sticky::-webkit-scrollbar-track { background: transparent; }
.sidebar-sticky::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.search-box { position: relative; }
.search-box input { width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px 8px 34px; color: var(--text); font-size: 0.88rem; outline: none; }
.search-box input:focus { border-color: var(--accent); }
.search-box::before { content: '⌕'; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 1.1rem; pointer-events: none; }

.filter-section { display: flex; flex-direction: column; gap: 6px; }
.filter-label { font-size: 0.75rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; padding: 0 2px; }
.filter-search { width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; color: var(--text); font-size: 0.8rem; outline: none; margin-bottom: 4px; }
.filter-search:focus { border-color: var(--accent); }
.filter-list { display: flex; flex-direction: column; gap: 1px; max-height: 200px; overflow-y: auto; padding-right: 4px; }
.filter-list::-webkit-scrollbar { width: 3px; }
.filter-list::-webkit-scrollbar-thumb { background: var(--border); }
.filter-item { display: flex; align-items: center; gap: 7px; padding: 4px 4px; border-radius: 4px; cursor: pointer; font-size: 0.82rem; color: var(--text-muted); transition: color 0.12s; }
.filter-item:hover { color: var(--text); }
.filter-item input[type=checkbox] { accent-color: var(--accent); width: 13px; height: 13px; cursor: pointer; flex-shrink: 0; }
.filter-item.checked { color: var(--text); }
.filter-count { margin-left: auto; font-size: 0.72rem; background: var(--surface2); padding: 1px 5px; border-radius: 8px; color: var(--text-muted); }

.active-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { background: var(--surface2); border: 1px solid var(--accent); color: var(--accent); padding: 3px 10px 3px 8px; border-radius: 12px; font-size: 0.76rem; display: flex; align-items: center; gap: 5px; cursor: pointer; }
.chip:hover { background: var(--accent); color: #fff; }
.chip-x { font-size: 0.9rem; line-height: 1; }
.clear-all { font-size: 0.78rem; color: var(--text-muted); cursor: pointer; text-decoration: underline; padding: 2px 0; }
.clear-all:hover { color: var(--text); }
.filter-active-btn { width: 100%; padding: 7px 12px; background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; color: var(--text-muted); font-size: 0.83rem; cursor: pointer; text-align: left; transition: all 0.15s; }
.filter-active-btn:hover { border-color: var(--active-color); color: var(--text); }
.filter-active-btn-on { background: var(--active-bg) !important; border-color: var(--active-color) !important; color: var(--active-color) !important; }

/* MAIN */
main { flex: 1; min-width: 0; }
.results-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-size: 0.83rem; color: var(--text-muted); }
.results-bar strong { color: var(--text); }
.view-toggle { margin-left: auto; display: flex; gap: 4px; }
.view-btn { background: var(--surface); border: 1px solid var(--border); color: var(--text-muted); padding: 5px 10px; border-radius: 5px; cursor: pointer; font-size: 0.85rem; }
.view-btn.active { background: var(--surface2); color: var(--text); border-color: var(--accent); }

/* GRID */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.book-card { background: var(--surface); border-radius: 10px; overflow: hidden; cursor: pointer; position: relative; transition: transform 0.18s, box-shadow 0.18s; border: 2px solid transparent; }
.book-card:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(0,0,0,.4); }
.book-card.is-active { border-color: var(--active-color); }
.book-card.is-active .active-badge { opacity: 1; }
.active-badge { position: absolute; top: 6px; right: 6px; background: var(--active-color); color: #fff; border-radius: 50%; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; opacity: 0; transition: opacity 0.15s; box-shadow: 0 2px 6px rgba(0,0,0,.4); }
.cover-wrap { position: relative; width: 100%; aspect-ratio: 2/3; background: var(--surface2); overflow: hidden; }
.cover-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 2.2rem; font-weight: 700; color: rgba(255,255,255,.5); }
.card-body { padding: 9px 10px 10px; }
.card-title { font-size: 0.8rem; font-weight: 600; color: var(--text); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-bottom: 4px; }
.card-author { font-size: 0.73rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-series { font-size: 0.7rem; color: var(--accent); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-size { font-size: 0.68rem; color: var(--border); margin-top: 2px; }

/* LIST VIEW */
.book-list { display: flex; flex-direction: column; gap: 4px; }
.list-item { background: var(--surface); border-radius: 8px; display: flex; align-items: center; gap: 12px; padding: 8px 12px; cursor: pointer; border: 2px solid transparent; transition: background 0.12s; }
.list-item:hover { background: var(--surface2); }
.list-item.is-active { border-color: var(--active-color); }
.list-thumb { width: 36px; height: 54px; object-fit: cover; border-radius: 4px; flex-shrink: 0; background: var(--surface2); }
.list-thumb-placeholder { width: 36px; height: 54px; border-radius: 4px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 1rem; font-weight: 700; color: rgba(255,255,255,.4); }
.list-info { flex: 1; min-width: 0; }
.list-title { font-size: 0.9rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-meta { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.list-series { font-size: 0.75rem; color: var(--accent); margin-top: 1px; }
.list-size { font-size: 0.72rem; color: var(--text-muted); flex-shrink: 0; }
.list-active { width: 20px; flex-shrink: 0; color: var(--active-color); opacity: 0; }
.list-item.is-active .list-active { opacity: 1; }

/* EMPTY STATE */
.empty { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty h3 { font-size: 1.1rem; margin-bottom: 8px; }

/* MOBILE */
@media (max-width: 768px) {
  .page { flex-direction: column; padding: 12px; }
  aside { width: 100%; }
  .sidebar-sticky { position: static; max-height: none; flex-direction: row; flex-wrap: wrap; gap: 10px; }
  .search-box { width: 100%; }
  .filter-section { min-width: 140px; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  .nav-active-bar { display: none; }
}
@media (max-width: 480px) {
  .book-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Private/hidden items (admin only) */
.private-badge { position:absolute; top:6px; left:6px; z-index:10; font-size:0.8rem; cursor:pointer; opacity:0.35; transition:opacity .15s; background:var(--surface2); border-radius:4px; padding:2px 4px; }
.private-badge:hover { opacity:1; }
.private-badge.is-hidden { opacity:1; background:#7f1d1d; }
.is-hidden-item .cover-wrap { filter:brightness(0.5) grayscale(0.5); }
.is-hidden-item .card-title { color:var(--text-muted); }

/* Download buttons on selected books */
.download-row { display: flex; gap: 5px; margin-top: 7px; flex-wrap: wrap; }
.dl-btn { display: inline-block; padding: 4px 9px; background: var(--accent); color: #fff; border-radius: 5px; font-size: 0.7rem; font-weight: 700; text-decoration: none; letter-spacing: 0.04em; transition: opacity 0.15s; }
.dl-btn:hover { opacity: 0.85; }
.dl-btn-sm { padding: 3px 7px; font-size: 0.68rem; }
.list-dl-row { display: flex; gap: 4px; flex-shrink: 0; }
.dl-btn-play { background: #16a34a; }
