/* ── Variables — dark mode (default) ── */
:root {
  --bg:        #1c1917;
  --surface:   #252220;
  --surface2:  #2f2b28;
  --border:    #3d3830;
  --text:      #e8e0d5;
  --text-dim:  #8a7f75;
  --accent:    #c4622d;
  --green:     #5a9a5a;
  --yellow:    #c49a30;
  --orange:    #c4622d;
  --red:       #b84545;
  --radius:    4px;
}

/* ── Variables — light mode ── */
html.light {
  --bg:        #f2ece0;
  --surface:   #faf6ef;
  --surface2:  #ede6d9;
  --border:    #d0c8ba;
  --text:      #2a2420;
  --text-dim:  #7a7068;
  --accent:    #c4622d;
  --green:     #3a6b3a;
  --yellow:    #8a6010;
  --orange:    #a04010;
  --red:       #9e2c2c;
  --radius:    4px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; font-size: inherit; touch-action: manipulation; }
a { touch-action: manipulation; }
input, select, textarea {
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.7rem;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-dim); }

/* ── Nav ── */
#nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 48px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: 860px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0 1rem;
}
.nav-logo {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  margin-right: 1rem;
  letter-spacing: -0.02em;
}
.nav-logo:hover { color: var(--accent); text-decoration: none; }
.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
}
.theme-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 0.3rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  transition: color 0.15s;
}
.theme-toggle:hover { color: var(--text); }
.nav-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  transition: color 0.15s, background 0.15s;
}
.nav-btn:hover, .nav-btn.active { color: var(--text); background: var(--surface2); text-decoration: none; }

/* Dropdown */
.nav-dropdown { position: relative; }
.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 140px;
  z-index: 200;
}
.nav-dropdown-menu.open { display: block; }
.nav-dropdown:hover .nav-dropdown-menu { display: block; }
.nav-dropdown-item {
  display: block;
  padding: 0.5rem 1rem;
  color: var(--text-dim);
  font-size: 0.9rem;
}
.nav-dropdown-item:hover { color: var(--text); background: var(--surface2); text-decoration: none; }

/* ── Banner ── */
.banner-abs {
  background: #2e2300;
  border-bottom: 1px solid #4a3800;
  color: var(--yellow);
  padding: 0.5rem 1rem;
  text-align: center;
  font-size: 0.9rem;
}
.banner-abs.hidden { display: none; }

/* ── Main / Page ── */
#main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}
.narrow-page {
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}
.user-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; margin-top: 0.75rem; }
.user-card-name { font-weight: 600; font-size: 1rem; }
.badge-warn { background: #2a2200; color: #e0b820; }
html.light .badge-warn { background: #fffbe0; color: #7a5e00; }

/* ── Pending approval cards ── */
.pending-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--border);
}
.pending-card:first-child { border-top: 1px solid var(--border); }
.pending-card--done { opacity: 0.55; }
.pending-card-body { flex: 1; min-width: 0; }
.pending-card-title { font-size: 0.95rem; margin-bottom: 0.35rem; }
.pending-card-title a { font-weight: 500; }
.pending-card-row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.pending-card-pills { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.pending-card-actions { display: flex; align-items: center; flex-shrink: 0; }
.book-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s;
}
.book-card:hover { border-color: var(--accent); }
.book-card-cover {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
  background: var(--surface2);
}
.series-pos-badge {
  position: absolute;
  top: 0.3rem;
  left: 0.3rem;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  pointer-events: none;
  line-height: 1.3;
}
.book-card-cover-placeholder {
  width: 100%;
  aspect-ratio: 2/3;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 2rem;
}
.book-card-body { padding: 0.75rem; }
.book-card-title {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.book-card-author { font-size: 0.75rem; color: var(--text-dim); margin-top: 0.25rem; }
.book-card-meta { margin-top: 0.5rem; display: flex; gap: 0.25rem; flex-wrap: wrap; }

/* Search result card */
.search-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: grid;
  grid-template-columns: 64px 1fr;
  grid-template-rows: auto auto;
  column-gap: 0.75rem;
  padding: 0.75rem;
  padding-bottom: 0;
  margin-bottom: 0.65rem;
}
.search-card-cover-link { grid-column: 1; grid-row: 1; display: block; line-height: 0; align-self: flex-start; }
.search-card-cover, .search-card-cover-placeholder { grid-column: unset; grid-row: unset; }
.search-card-body { grid-column: 2; grid-row: 1; }
.search-card-cover {
  width: 64px; min-width: 64px;
  aspect-ratio: 2/3; object-fit: contain;
  border-radius: 2px; background: var(--surface2); align-self: flex-start;
}
.search-card-cover-placeholder {
  width: 64px; min-width: 64px;
  aspect-ratio: 2/3; background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); border-radius: 2px; align-self: flex-start;
}
.search-card-body { flex: 1; min-width: 0; }
.search-card-title-row { display: flex; align-items: flex-start; gap: 0.4rem; }
.search-card-title { font-size: 0.95rem; font-weight: 600; flex: 1; min-width: 0; }
.search-card-title-link { color: inherit; text-decoration: none; }
.search-card-title-link:not([href]) { cursor: default; }
.search-card-title-link:not([href]):hover { text-decoration: none; color: inherit; }
.search-card-title-link[href]:hover { color: var(--accent); text-decoration: underline; }
.search-card-hc-link { display: flex; align-items: center; flex-shrink: 0; opacity: 0.7; margin-top: 1px; }
.search-card-hc-link:hover { opacity: 1; }
.hc-icon { height: auto; transform: rotate(-12deg); display: block; flex-shrink: 0; filter: invert(1); }
html.light .hc-icon { filter: none; }
.search-card-author { font-size: 0.82rem; color: var(--text-dim); margin-top: 0.15rem; }
.search-card-series { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.1rem; }
.search-card-link { color: inherit; text-decoration: none; }
.search-card-link:hover { color: var(--accent); text-decoration: underline; }
.search-card-meta { margin-top: 0.35rem; display: flex; gap: 0.35rem; align-items: center; flex-wrap: wrap; }
.search-card-rating { font-size: 0.78rem; color: var(--text-dim); }
.search-card-lib-link { display: inline-flex; gap: 0.25rem; align-items: center; }
.search-card-lib-badge {
  display: inline-flex; align-items: center; gap: 0.2rem;
  font-size: 0.72rem; padding: 0.15rem 0.4rem;
  border-radius: 999px;
}
/* Format row (single row: Request label | ebook pill | sep | audiobook pill | narrator) */
.search-card-fmt-rows { grid-column: 1 / -1; grid-row: 2; border-top: 1px solid var(--border); margin-top: 0.5rem; }
/* Detail page format rows */
.fmt-standalone { margin-top: 0.25rem; }
.fmt-standalone-rows { grid-column: unset; grid-row: unset; border-top: none; margin-top: 0; }
.fmt-row { display: flex; align-items: center; gap: 0.4rem; padding: 0.3rem 0; }
.fmt-label { font-size: 0.78rem; color: var(--text-dim); margin-right: 0.1rem; }
.fmt-sep { font-size: 0.78rem; color: var(--border); }
.fmt-pill { cursor: pointer; border: none; transition: opacity 0.15s; }
.fmt-pill:disabled { cursor: default; }
.fmt-pill:not(:disabled):hover { opacity: 0.75; }
.badge-neutral { background: var(--surface2); color: var(--text-dim); opacity: 0.6; }
html.light .badge-neutral { background: var(--surface2); color: var(--text-dim); }
.fmt-narrator-input {
  flex: 1; padding: 0.1rem 0.4rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 16px;
}
.fmt-narrator-input:focus { outline: none; border-color: var(--accent); }
.fmt-narrator-text { font-size: 0.78rem; color: var(--text-dim); font-style: italic; margin-left: 0.2rem; }
.fmt-add-series-row { border-top: 1px solid var(--border); padding-top: 0.5rem; margin-top: 0.1rem; }

/* Author / series card */
.entity-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.entity-card:hover { border-color: var(--accent); }
.entity-card-name { font-weight: 600; }
.entity-card-meta { font-size: 0.8rem; color: var(--text-dim); margin-top: 0.25rem; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  transition: opacity 0.15s, background 0.15s;
  border: 1px solid transparent;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary  { background: var(--accent); color: #fff; border: none; }
.btn-primary:hover:not(:disabled)  { opacity: 0.85; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--text-dim); }
.btn-success  { background: var(--green); color: #fff; border: none; }
.btn-danger   { background: var(--red); color: #fff; border: none; }
.btn-danger:hover:not(:disabled) { opacity: 0.85; }
.btn-ghost    { background: none; color: var(--text-dim); border: none; padding: 0.4rem 0.6rem; }
.btn-ghost:hover:not(:disabled) { color: var(--text); }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.btn-warning { background: var(--orange); color: #fff; border: none; }
.btn-warning:hover:not(:disabled) { opacity: 0.85; }
.btn-icon { display:inline-flex; align-items:center; justify-content:center; width:2rem; height:2rem; border-radius:6px; border:1.5px solid; background:transparent; cursor:pointer; padding:0; transition:background 0.15s, color 0.15s; }
.btn-icon:disabled { opacity:0.4; cursor:default; }
.btn-icon-approve { color:var(--green); border-color:var(--green); }
.btn-icon-approve:hover:not(:disabled) { background:var(--green); color:#fff; }
.btn-icon-reject  { color:var(--red);   border-color:var(--red); margin-left:0.35rem; }
.btn-icon-reject:hover:not(:disabled)  { background:var(--red);   color:#fff; }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.72rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-weight: 500;
  white-space: nowrap;
}
/* Dark mode badges */
.badge-pending      { background: #2a2600; color: #c8a020; }
.badge-requested    { background: #1a2a40; color: #60a0d8; }
.badge-sso          { background: #183828; color: #50a060; }
.badge-snatched     { background: #3a2000; color: #e07020; }
.badge-downloading  { background: #382800; color: #d09020; }
.badge-downloaded   { background: #382800; color: #d09020; }
.badge-merging      { background: #281848; color: #9060d8; }
.badge-organizing   { background: #281848; color: #9060d8; }
.badge-completed    { background: #183828; color: #50a060; }
.badge-in_library   { background: #183828; color: #50a060; }
.badge-failed       { background: #3a1818; color: #c04040; }
.badge-missing      { background: #3a2010; color: #d05828; }
.badge-upcoming     { background: #181e40; color: #6078d0; }

/* Light mode badges */
html.light .badge-pending      { background: #fff8d0; color: #7a6000; }
html.light .badge-requested    { background: #d8eaf8; color: #185080; }
html.light .badge-sso          { background: #d8eedc; color: #185828; }
html.light .badge-snatched     { background: #feecd8; color: #8a3800; }
html.light .badge-downloading  { background: #fef0d0; color: #7a5000; }
html.light .badge-downloaded   { background: #fef0d0; color: #7a5000; }
html.light .badge-merging      { background: #ece0ff; color: #502898; }
html.light .badge-organizing   { background: #ece0ff; color: #502898; }
html.light .badge-completed    { background: #d8eedc; color: #185828; }
html.light .badge-in_library   { background: #d8eedc; color: #185828; }
html.light .badge-failed       { background: #fcd8d8; color: #881818; }
html.light .badge-missing      { background: #fde8d8; color: #883010; }
html.light .badge-upcoming     { background: #dde0f8; color: #283898; }

/* Light mode banner */
html.light .banner-abs {
  background: #fdefd0;
  border-bottom-color: #e0c880;
  color: #7a5000;
}

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
thead th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}
thead th.sortable { cursor: pointer; touch-action: manipulation; user-select: none; }
thead th.sortable:hover { color: var(--text); }
thead th.sort-active { color: var(--accent); }
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 0.6rem 0.75rem; vertical-align: middle; }
.td-dim { color: var(--text-dim); font-size: 0.8rem; }
.td-mono { font-family: monospace; font-size: 0.8rem; color: var(--text-dim); }

/* ── Table toolbar ── */
.table-toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.table-toolbar input[type="text"] { flex: 1; min-width: 180px; max-width: 320px; }

/* ── Page header ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-title { font-size: 1.4rem; font-weight: 600; }

/* ── View toggle ── */
.view-toggle { display: flex; gap: 0.25rem; }
.view-toggle-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius);
  display: flex; align-items: center;
}
.view-toggle-btn.active { background: var(--surface2); color: var(--text); border-color: var(--text-dim); }

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 0.35rem; }
.form-input { width: 100%; max-width: 650px; }
.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }
.form-hint { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.25rem; }
.form-actions { display: flex; align-items: center; gap: 0.75rem; margin-top: 1.25rem; }
.form-feedback { font-size: 0.85rem; }
.form-feedback.ok { color: var(--green); }
.form-feedback.err { color: var(--red); }

/* ── Dialog overlay ── */
.dialog-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.dialog-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}
.dialog-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 1.25rem; }

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  margin-bottom: -1px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Scroll-hint fades for overflowing tab bars */
.tabs-wrap { position: relative; }
.tabs-wrap::before,
.tabs-wrap::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 1px;
  width: 2.5rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 1;
}
.tabs-wrap::before { left: 0;  background: linear-gradient(to left,  transparent, var(--bg)); }
.tabs-wrap::after  { right: 0; background: linear-gradient(to right, transparent, var(--bg)); }
.tabs-wrap.tabs-fade-left::before  { opacity: 1; }
.tabs-wrap.tabs-fade-right::after  { opacity: 1; }

/* ── Tasks grid (settings) ── */
.task-cell-name {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.task-cell-name-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

/* ── State helpers ── */
.state-loading {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 200px;
  color: var(--text-dim);
}
.state-error {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 200px;
  color: var(--text-dim);
  gap: 0.5rem;
}
.state-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-dim);
  line-height: 2;
}
.state-empty a { color: var(--accent); }

/* ── Spinner ── */
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 0.8s linear infinite; display: inline-block; vertical-align: middle; }

/* ── Home inline title (mobile only — desktop keeps the nav logo) ── */
.home-title {
  display: none;
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  text-align: center;
  color: var(--text);
  margin-bottom: 1.25rem;
}
body.home-page .home-title { display: block; }

/* ── Search page ── */
.search-page {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}
.search-page.empty {
  min-height: calc(100vh - 48px - 3rem);
  justify-content: center;
}
.search-page.empty .search-container { align-self: center; }
.search-container { width: 100%; max-width: 640px; }
.search-input-row {
  position: relative;
  display: flex;
  align-items: center;
}
.search-input-main {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 0.65rem 5rem 0.65rem 1.25rem;
  font-size: 16px;
  color: var(--text);
  transition: border-color 0.15s;
}
.search-input-main:focus { border-color: var(--accent); outline: none; }
.search-input-icons {
  position: absolute;
  right: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.1rem;
}
.search-clear-btn, .search-advanced-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 0.3rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}
.search-clear-btn:hover, .search-advanced-btn:hover { color: var(--text); background: var(--surface2); }
.search-advanced-btn.active { color: var(--accent); }
.search-advanced-fields {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease, opacity 0.2s ease;
  opacity: 0;
  margin-top: 0;
}
.search-advanced-fields.open {
  max-height: 200px;
  opacity: 1;
  margin-top: 0.5rem;
}
.search-advanced-inner {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0 0.25rem;
}
.search-advanced-inner input {
  width: 100%;
  border-radius: var(--radius);
}
.search-results { width: 100%; }
.search-results-header {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}

/* ── Request form ── */
.request-form { padding: 0.75rem 0 0 0; }
.request-format-btns { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.request-narrator { margin-top: 0.5rem; }
.request-narrator input { width: 100%; max-width: 320px; }
.request-submit-row { margin-top: 0.75rem; display: flex; gap: 0.5rem; align-items: center; }

/* ── Stats cards (dashboard / detail) ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}
.stat-card.clickable { cursor: pointer; transition: border-color 0.15s; }
.stat-card.clickable:hover { border-color: var(--accent); }
.stat-card.stat-card-disabled { opacity: 0.45; }
.tasks-list { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.25rem; }
.tasks-list .stat-card { text-align: left; }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.35rem; }
.stat-value.red { color: var(--red); }

/* ── Downloads progress ── */
.progress-bar-track {
  background: var(--surface2);
  border-radius: 2px;
  height: 4px;
  overflow: hidden;
  margin-top: 0.35rem;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.5s;
}

/* ── Detail page sections ── */
.book-detail-card { display: flex; gap: 1rem; }
.book-detail-card-meta { flex: 1; min-width: 0; }
.detail-cover {
  width: 120px;
  min-width: 120px;
  aspect-ratio: 2/3;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--surface2);
  align-self: flex-start;
}
.detail-cover-placeholder {
  width: 120px;
  min-width: 120px;
  aspect-ratio: 2/3;
  background: var(--surface2);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 2rem;
  align-self: flex-start;
}
.detail-author { font-size: 1rem; color: var(--text-dim); }
.detail-series { font-size: 0.9rem; color: var(--text-dim); margin-top: 0.2rem; }
.detail-description { margin-top: 0.75rem; font-size: 0.9rem; color: var(--text-dim); line-height: 1.6; }
.detail-rating { margin-top: 0.5rem; font-size: 0.9rem; display: flex; align-items: center; gap: 0.3rem; }
.detail-link { color: inherit; text-decoration: none; }
.detail-link:hover { color: var(--accent); text-decoration: underline; }
.detail-hc-link {
  display: inline-flex; align-items: center; gap: 0.4rem;
  margin-top: 0.75rem; padding: 0.35rem 0.75rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.875rem; color: var(--text); text-decoration: none;
  background: var(--surface2);
}
.detail-hc-link:hover { border-color: var(--accent); color: var(--accent); }
/* Detail format rows */
.collapsible-chevron { margin-left: auto; display: flex; align-items: center; transition: transform 0.2s; color: var(--text-dim); }
.collapsible-chevron.open { transform: rotate(180deg); }
.detail-fmt-type { font-size: 0.9rem; font-weight: 500; }
.detail-fmt-narrator { font-size: 0.85rem; color: var(--text-dim); }
.detail-fmt-detail { padding: 0 0 0.75rem 2.25rem; }
.detail-fmt-kv { font-size: 0.85rem; margin-bottom: 0.3rem; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.detail-fmt-link { color: var(--accent); text-decoration: none; }
.detail-fmt-link:hover { text-decoration: underline; }
.detail-fmt-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; }
.detail-fmt-request-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.detail-fmt-narrator-input { font-size: 16px; padding: 0.25rem 0.5rem; flex: 1; min-width: 140px; }

/* ── Inline collapsible section ── */
.collapsible-row {
  border-bottom: 1px solid var(--border);
}
.collapsible-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0;
  cursor: pointer;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.9rem;
  text-align: left;
}
.collapsible-trigger:hover { color: var(--accent); }
.collapsible-content { padding-bottom: 0.75rem; }

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 1rem;
  font-size: 0.875rem;
  min-width: 240px;
  max-width: 360px;
  animation: slide-in 0.2s ease;
}
@keyframes slide-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
.toast-success { border-left: 3px solid var(--green); }
.toast-error   { border-left: 3px solid var(--red); }
.toast-info    { border-left: 3px solid var(--accent); }

/* ── Section heading ── */
/* ── Series stats block ── */
.series-stats-block { margin-bottom: 0.75rem; }
.series-progress-bar {
  height: 6px; border-radius: 3px; background: var(--surface2);
  margin-bottom: 0.5rem; overflow: hidden;
}
.series-progress-bar.series-progress-loading { opacity: 0.4; }
.series-progress-fill { height: 100%; background: var(--green); border-radius: 3px; transition: width 0.4s ease; }
.series-stats-summary { display: flex; align-items: center; flex-wrap: wrap; gap: 0.3rem; font-size: 0.85rem; }
.series-stat-sep { color: var(--text-dim); }
.series-stat-missing  { color: var(--red); font-weight: 500; text-decoration: none; }
.series-stat-missing:hover  { text-decoration: underline; }
.series-stat-upcoming { color: var(--yellow); font-weight: 500; text-decoration: none; }
.series-stat-upcoming:hover { text-decoration: underline; }
.series-stat-complete { color: var(--green); font-weight: 500; }

.section-heading {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.section-heading-row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.section-heading-row .section-heading {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0;
}
.missing-secondary-label {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  margin-left: auto;
}
.missing-secondary-label input[type="checkbox"] { cursor: pointer; }

/* ── ABS linking section ── */
.abs-link-candidate {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.abs-link-candidate:last-child { border-bottom: none; }
.abs-thumb {
  width: 40px;
  min-width: 40px;
  aspect-ratio: 2/3;
  object-fit: cover;
  border-radius: 2px;
  background: var(--surface2);
}
.abs-thumb-placeholder {
  width: 40px;
  min-width: 40px;
  aspect-ratio: 2/3;
  background: var(--surface2);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* ── Shared settings cards ── */
.settings-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 0.75rem;
}
.settings-card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  user-select: none;
  flex-wrap: wrap;
}
.settings-card-toggle {
  margin-left: auto;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: transform 0.18s;
}
.settings-card-toggle.open { transform: rotate(180deg); }
.settings-card-body {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.settings-card-body.hidden { display: none; }

/* ── Downloader cards ── */
.dl-card { margin-bottom: 0; }
.dl-card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.dl-type-badge {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 4px;
  padding: 0.15em 0.5em;
  white-space: nowrap;
}
.dl-card-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}
@media (max-width: 600px) {
  .dl-card-body { grid-template-columns: 1fr; }
}

/* ── Task cards ── */
.task-cards { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 1rem; }
.task-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.task-card-header strong { font-size: 1rem; }
.task-card-meta {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-top: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-dim);
}

/* ── Auto-search ranking stack ── */
.ranking-stack { display: flex; flex-direction: column; gap: 0.5rem; }
.ranking-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: default;
  transition: opacity 0.15s;
}
.ranking-item.dragging { opacity: 0.35; }
.ranking-item.drag-over-top { border-top: 2px solid var(--accent); }
.ranking-item.drag-over-bottom { border-bottom: 2px solid var(--accent); }
.drag-handle { color: var(--text-dim); cursor: grab; flex-shrink: 0; display: flex; align-items: center; }
.drag-handle:active { cursor: grabbing; }
.ranking-item-body { flex: 1; min-width: 0; }
.ranking-item-label { font-weight: 600; font-size: 0.88rem; }

/* ── Misc utilities ── */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.text-dim { color: var(--text-dim); }
.text-accent { color: var(--accent); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-mono { font-family: monospace; }
.flex { display: flex; }
.flex-gap { display: flex; gap: 0.5rem; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }

/* ── Mobile bottom nav ── */
#nav-bottom {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(56px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 100;
  justify-content: space-around;
  align-items: flex-start;
  padding-top: 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-bottom-btn {
  display: flex;
  flex: 1;
  height: 56px;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  background: none;
  border: none;
  text-decoration: none;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.nav-bottom-btn:hover,
.nav-bottom-btn.active { color: var(--accent); text-decoration: none; }

/* Library popup above bottom nav */
.nb-library-popup {
  position: fixed;
  bottom: calc(56px + env(safe-area-inset-bottom) + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 160px;
  z-index: 200;
  overflow: hidden;
}
.nb-library-popup-item {
  display: block;
  padding: 0.8rem 1.25rem;
  color: var(--text);
  font-size: 0.95rem;
  border-bottom: 1px solid var(--border);
  -webkit-tap-highlight-color: transparent;
}
.nb-library-popup-item:last-child { border-bottom: none; }
.nb-library-popup-item:hover { background: var(--surface2); text-decoration: none; }

/* ── Page header: pin view toggle to top-right on mobile so title wraps freely ── */
@media (max-width: 640px) {
  .page-header:has(.view-toggle) {
    position: relative;
    padding-right: 5rem;
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .page-header:has(.view-toggle) .view-toggle {
    position: absolute;
    top: 0;
    right: 0;
  }
}

/* ── Responsive ── */
@media (max-width: 640px) {
  /* Show bottom nav, hide top nav links, un-stick the top bar */
  #nav-bottom { display: flex; }
  .nav-links { display: none; }
  #nav { position: sticky; top: 0; }
  .nav-dropdown:hover .nav-dropdown-menu { display: none; }

  /* On home page: hide the nav bar entirely and show the inline title */
  body.home-page #nav { display: none; }
  body.home-page .home-title { display: block; }
  body.home-page #theme-toggle-home { display: flex; }

  #theme-toggle-home {
    display: none;
    position: fixed;
    top: 0.75rem;
    right: 0.75rem;
    z-index: 200;
  }

  /* Pad content above bottom nav */
  #main { padding: 1rem 0.75rem calc(56px + env(safe-area-inset-bottom) + 1rem); }

  .detail-cover, .detail-cover-placeholder { width: 90px; min-width: 90px; }
  .search-page.empty { min-height: calc(100vh - 48px - 2rem); }
  .stats-row { grid-template-columns: repeat(3, 1fr); }
  .tasks-row { grid-template-columns: 1fr; }
  .tasks-row .stat-card { text-align: left; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

}

/* ── Square covers mode ── */
body.square-covers .book-card-cover,
body.square-covers .book-card-cover-placeholder,
body.square-covers .detail-cover.abs-cover,
body.square-covers .detail-cover-placeholder.abs-cover {
  aspect-ratio: 1 / 1;
}

/* ── Search-all inline expansion ── */
@media (max-width: 640px) {
  .col-hide-mobile { display: none; }
}

.search-expansion-cell { padding: 0 !important; border-top: none !important; }
.search-expansion {
  padding: 0.25rem 1rem 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.search-all-card {
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0;
}
.search-all-card:first-child { border-top: 1px solid var(--border); }
.search-all-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.search-all-card-title { font-weight: 500; }
.search-all-format { display: flex; gap: 0.75rem; margin-top: 0.5rem; }
.search-all-format-label { padding-top: 0.4rem; flex-shrink: 0; }
.search-all-card-results { flex: 1; min-width: 0; }
.prowlarr-result-row {
  padding: 0.5rem 0;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}
.prowlarr-result-row:first-child { border-top: none; }
.prowlarr-result-title {
  word-break: break-word;
  margin-bottom: 0.3rem;
}
.prowlarr-result-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.prowlarr-result-info {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  color: var(--text-dim);
}
@media (max-width: 640px) {
  .prowlarr-dl-label { display: none; }
  .prowlarr-dl-btn { padding: 0.4rem 0.6rem; }
}

/* ── Request history timeline ── */
.history-timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.history-row {
  display: grid;
  grid-template-columns: 1.2rem 1fr auto;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
.history-row:last-child { border-bottom: none; }
.history-icon { display: flex; align-items: center; opacity: 0.6; }
.history-label { line-height: 1.4; }
.history-ts { white-space: nowrap; font-size: 0.75rem; }
