/* ── Fonts ─────────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300..600;1,9..40,300..400&family=DM+Mono:wght@400;500&family=Lora:ital,wght@0,400..600;1,400&display=swap');

/* ── Design tokens ────────────────────────────────────────────────────────── */
:root {
  --bg:         #0d0d0d;
  --surface:    #141414;
  --surface2:   #1a1a1a;
  --surface3:   #202020;
  --border:     #272727;
  --border2:    #333;
  --text:       #c8c8c8;
  --text-dim:   #888;
  --text-faint: #555;
  --yellow:     #d4a017;
  --radius:     5px;
  --sidebar:    360px;
  --header:     44px;
  --font-ui:    'DM Sans', system-ui, sans-serif;
  --font-mono:  'DM Mono', 'Courier New', monospace;
  --font-read:  'Lora', Georgia, serif;
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; overscroll-behavior-y: none; }
#_ptrInd {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  z-index: 9999;
  width: 34px;
  height: 34px;
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 15px;
  transition: opacity .1s;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
input, textarea, select {
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  font: inherit;
  border-radius: var(--radius);
  padding: 5px 8px;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--text-dim); }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
select option { background: var(--surface2); }

/* ── Layout ──────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* topbar */
#topbar {
  height: var(--header);
  min-height: var(--header);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 10px;
  z-index: 100;
  flex-shrink: 0;
}
#topbar .logo {
  display: flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
  background: none;
  border: none;
  padding: 0;
  opacity: 0.9;
  text-decoration: none;
}
#topbar .logo:hover { opacity: 1; }
#topbar .logo img, #topbar .logo #appLogo {
  height: 28px;
  width: auto;
  display: block;
  border-radius: 4px;
}
#topbar .spacer { flex: 1; }
#topbar .top-user {
  color: var(--text-dim);
  font-size: 13px;
}
#topbar .top-btn {
  color: var(--text-dim);
  font-size: 13px;
  padding: 4px 6px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
}
#topbar .top-btn:hover { background: var(--surface3); color: var(--text); }
#topbar .top-btn-active { color: var(--text); }
#adminLink { display: none; }
#sidebarToggle { display: none !important; }

/* nav icon spans */
.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: calc(18px * var(--icon-scale, 1));
  height: calc(18px * var(--icon-scale, 1));
  flex-shrink: 0;
}
.nav-icon svg { display: block; width: 100%; height: 100%; }

/* topnav: icon-only on desktop; icon+text in mobile dropdowns */
/* negative spacing: clamp padding at 0 and use negative margin for overlap */
.topnav .top-btn { gap: 0; padding: 4px max(0px, var(--menu-item-spacing, 6px)); margin-inline: min(0px, var(--menu-item-spacing, 6px)); }
.topnav-drop .top-btn { gap: 7px; padding: 8px 10px; }

/* toolbar icon-only buttons (share/download/search/settings) — scale with icon size */
.tb-icon-btn { padding: 4px 6px; }

/* settings page icon preview bar */
.icon-preview-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  background: var(--surface2);
  border: 1px dashed var(--border2);
  border-radius: var(--radius);
  padding: 6px 8px;
  gap: 0;
}
.icon-preview-btn {
  color: var(--text-dim);
  padding: 4px max(0px, var(--menu-item-spacing, 6px));
  margin-inline: min(0px, var(--menu-item-spacing, 6px));
  display: flex;
  align-items: center;
  border-radius: var(--radius);
  cursor: default;
  user-select: none;
}

/* icon style picker */
.rs-style-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-dim);
  background: none;
  cursor: pointer;
  margin-bottom: 2px;
}
.rs-style-btn:hover { background: var(--surface3); color: var(--text); }
.rs-style-btn.active { color: var(--yellow); }

.pdf-mode-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.pdf-mode-tab {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.pdf-mode-tab:hover { background: var(--surface3); color: var(--text); }
.pdf-mode-tab.active { background: var(--surface3); color: var(--yellow); border-color: var(--yellow); }

/* main area */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* reader pane */
#readerPane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  min-width: 0;
}

/* reader toolbar */
#readerToolbar {
  height: var(--header);
  min-height: var(--header);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 6px;
  flex-shrink: 0;
}
#readerTitle {
  font-size: 13px;
  color: var(--text-dim);
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
}
#toolbarSep { width: 1px; height: 20px; background: var(--border2); flex-shrink: 0; }
.tb-btn {
  color: var(--text-dim);
  padding: 4px 7px;
  border-radius: var(--radius);
  font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
}
.tb-btn:hover { background: var(--surface3); color: var(--text); }
.tb-btn.active { background: var(--surface3); color: var(--text); }
#pdfControls {
  display: none;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}
#pdfControls.visible { display: flex; }
#pdfPageInput {
  width: 42px;
  text-align: center;
  padding: 3px 5px;
  font-size: 12px;
}
#pdfPageTotal { color: var(--text-faint); font-size: 12px; }
#pdfSearch {
  width: 130px;
  font-size: 12px;
  padding: 3px 6px;
}
#pdfSearchCount { font-size: 11px; color: var(--text-dim); min-width: 30px; }
.tb-spacer { flex: 1; }
#readerInfo { font-size: 11px; color: var(--text-faint); }
.admin-quick-edit {
  background: transparent;
  border: none;
  border-bottom: 1px dashed rgba(74,136,90,0.5);
  color: var(--text);
  font-family: inherit;
  padding: 1px 3px;
  outline: none;
  flex-shrink: 0;
}
.admin-quick-edit:focus { border-bottom: 1px solid var(--yellow, #e6a817); }
.admin-title-field { font-size: 13px; color: var(--text-dim); max-width: 250px; min-width: 60px; }
.admin-ext-field  { font-size: 11px; color: var(--text-faint); width: 52px; text-align: center; }

/* Recent views in empty state */
.recent-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 28px;
}
.recent-label {
  font-size: 12px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}
.recent-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  padding: 0 20px;
  max-width: 700px;
}
.recent-card {
  width: 110px;
  cursor: pointer;
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform .15s;
}
.recent-card:hover { transform: translateY(-2px); }
.recent-cover {
  width: 110px;
  height: 150px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
}
.recent-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.recent-cover-fallback {
  color: var(--text-faint);
  opacity: 0.5;
}
.recent-cover-fallback svg { width: 40px; height: 40px; }
.recent-title {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.4;
}

/* Playlist detail view */
.pl-detail {
  width: 100%;
  max-width: 700px;
  padding: 20px 20px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.pl-detail-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
  width: 100%;
  justify-content: center;
}
.pl-detail-icon { color: var(--text-faint); opacity: 0.7; flex-shrink: 0; }
.pl-detail-name {
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.pl-detail-play {
  flex-shrink: 0;
  background: var(--surface3);
  border: 1px solid var(--border2);
  color: var(--text);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 20px;
  cursor: pointer;
  transition: background .15s;
  margin-left: 6px;
}
.pl-detail-play:hover { background: var(--border2); }
.pl-track-num {
  position: absolute;
  bottom: 4px;
  right: 5px;
  font-size: 10px;
  color: var(--text-faint);
  background: rgba(0,0,0,.55);
  border-radius: 3px;
  padding: 1px 4px;
  line-height: 1.4;
}
.recent-cover { position: relative; }

/* Recent hero card */
.recent-hero {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  width: 100%;
  max-width: 560px;
  padding: 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s;
  margin-bottom: 20px;
  box-sizing: border-box;
}
.recent-hero:hover { background: var(--surface3); }
.recent-hero-cover {
  width: 88px;
  height: 120px;
  flex-shrink: 0;
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface3);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}
.recent-hero-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.recent-hero-cover .recent-cover-fallback { opacity: 0.6; }
.recent-hero-cover .recent-cover-fallback svg { width: 48px; height: 48px; }
.recent-hero-info {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-top: 2px;
  flex: 1;
  min-width: 0;
}
.recent-hero-label {
  font-size: 10px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.recent-hero-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.recent-hero-meta {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
}
.recent-hero-time {
  font-size: 11px;
  color: var(--text-faint);
}

/* Help modal */
#helpModal .modal {
  max-width: 820px;
  width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 16px 20px 20px;
}
.help-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
  flex-shrink: 0;
}
.help-tab {
  padding: 5px 18px;
  font-size: 13px;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  background: none;
  border-top: none; border-left: none; border-right: none;
}
.help-tab.active { color: var(--text); border-bottom-color: var(--text); }
.help-tab-pane { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.help-content-pane { flex-direction: row; gap: 16px; }
.help-file-list {
  width: 150px;
  flex-shrink: 0;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding-right: 10px;
}
.help-file-item {
  padding: 6px 8px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: var(--radius);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.help-file-item:hover { background: var(--surface2); color: var(--text); }
.help-file-item.active { background: var(--surface2); color: var(--text); }
.help-file-body {
  flex: 1;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.75;
  color: var(--text);
  min-width: 0;
}
.help-file-body h1 { font-size: 17px; margin: 0 0 14px; }
.help-file-body h2 { font-size: 14px; font-weight: 600; margin: 18px 0 8px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.help-file-body h3 { font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
.help-file-body p  { margin: 0 0 10px; }
.help-file-body a  { color: #4a8fff; }
.help-file-body code { font-family: var(--font-mono); font-size: 11px; background: var(--surface2); padding: 1px 5px; border-radius: 3px; }
.help-file-body pre { background: var(--surface2); padding: 10px 12px; border-radius: var(--radius); overflow-x: auto; margin: 0 0 10px; }
.help-file-body pre code { background: none; padding: 0; }
.help-file-body ul, .help-file-body ol { margin: 0 0 10px 18px; }
.help-file-body li { margin-bottom: 3px; }
.help-file-body table { border-collapse: collapse; width: 100%; margin-bottom: 10px; font-size: 12px; }
.help-file-body th, .help-file-body td { border: 1px solid var(--border); padding: 5px 8px; text-align: left; }
.help-file-body th { background: var(--surface2); color: var(--text-dim); font-weight: 600; }
.help-fb-location {
  font-size: 11px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px 7px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
}
.help-fb-select {
  font-size: 13px; padding: 4px 8px;
  background: var(--bg); border: 1px solid var(--border2);
  color: var(--text); border-radius: var(--radius);
}
.help-fb-textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 100px;
  max-height: 300px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  background: var(--bg);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: var(--radius);
  overflow: hidden;
  padding: 6px 8px;
}
.help-preview-body {
  min-height: 80px;
  padding: 8px 10px;
  background: var(--surface2);
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  overflow-y: auto;
  max-height: 300px;
}
.help-edit-tabs {
  display: flex;
  margin-bottom: 6px;
}
.help-edit-tab {
  padding: 3px 14px;
  font-size: 12px;
  color: var(--text-faint);
  border: 1px solid var(--border);
  cursor: pointer;
  background: none;
}
.help-edit-tab:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.help-edit-tab:last-child  { border-radius: 0 var(--radius) var(--radius) 0; margin-left: -1px; }
.help-edit-tab.active      { background: var(--surface2); color: var(--text); }
@media (max-width: 600px) {
  .help-content-pane { flex-direction: column; }
  .help-file-list { width: 100%; border-right: none; border-bottom: 1px solid var(--border); padding-bottom: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
  .help-file-item { padding: 4px 8px; border: 1px solid var(--border); border-radius: var(--radius); }
}

/* Image gallery */
.img-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  padding: 16px 20px;
  max-width: 860px;
  width: 100%;
}
.img-thumb {
  width: 130px;
  cursor: pointer;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface2);
  transition: transform .15s, border-color .15s;
  display: flex;
  flex-direction: column;
}
.img-thumb:hover { transform: translateY(-2px); border-color: var(--border2); }
.img-thumb img {
  width: 130px;
  height: 130px;
  object-fit: cover;
  display: block;
}
.img-thumb-fallback {
  width: 130px;
  height: 130px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  opacity: 0.5;
}
.img-thumb-fallback svg { width: 40px; height: 40px; }
.img-thumb-label {
  font-size: 11px;
  color: var(--text-dim);
  padding: 5px 7px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* List fold-down */
.list-expand-btn {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  color: var(--text-faint);
  transition: transform .15s, color .15s;
  padding: 0;
  margin-right: 2px;
}
.list-expand-btn:hover { color: var(--text); }
.list-expand-btn.expanded { transform: rotate(90deg); color: var(--text-dim); }
.list-subitem {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px 5px 34px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  transition: background .1s;
}
.list-subitem:hover { background: var(--surface2); }
.list-subitem-num {
  font-size: 10px;
  color: var(--text-faint);
  min-width: 16px;
  text-align: right;
}
.list-subitem-icon { opacity: 0.6; flex-shrink: 0; }
.list-subitem-title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  flex: 1;
}
.list-subitem-empty {
  color: var(--text-faint);
  font-style: italic;
  cursor: default;
  padding-left: 42px;
}
.list-subitem-empty:hover { background: var(--surface); }

/* reader content */
#readerBody {
  flex: 1;
  overflow: hidden;
  position: relative;
}
/* Image adjustment dialog */
#imgAdjustDlg {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 30;
  width: 250px;
  max-height: calc(100% - 16px);
  overflow-y: auto;
  background: rgba(13,13,13,0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  box-shadow: 0 6px 28px rgba(0,0,0,.7);
  flex-direction: column;
  gap: 0;
  pointer-events: all;
}
.iad-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.iad-title { font-size: 12px; color: var(--text-dim); flex: 1; letter-spacing: .04em; text-transform: uppercase; }
.iad-reset-btn {
  font-size: 11px;
  color: var(--text-faint);
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  background: none;
  transition: color .1s, border-color .1s;
}
.iad-reset-btn:hover { color: var(--text); border-color: var(--border2); }
.iad-close-btn {
  font-size: 13px;
  color: var(--text-faint);
  cursor: pointer;
  background: none;
  border: none;
  line-height: 1;
  padding: 0 2px;
  transition: color .1s;
}
.iad-close-btn:hover { color: var(--text); }
.iad-sliders { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 6px; }
.iad-row {
  display: grid;
  grid-template-columns: 74px 1fr 38px;
  align-items: center;
  gap: 6px;
}
.iad-label { font-size: 11px; color: var(--text-faint); text-align: right; white-space: nowrap; }
.iad-slider {
  width: 100%;
  height: 3px;
  cursor: pointer;
  accent-color: #6a9;
  -webkit-appearance: none;
  appearance: none;
  background: var(--surface3);
  border-radius: 2px;
  outline: none;
}
.iad-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #8bc;
  cursor: pointer;
  border: none;
}
.iad-val { font-size: 11px; color: var(--text-dim); text-align: right; font-variant-numeric: tabular-nums; }
#imgAdjustBtn.active { color: #8bc; }

.reader-settings-dlg {
  position: absolute;
  top: 8px;
  right: 12px;
  z-index: 31;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 220px;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.rsd-row { display: flex; flex-direction: column; gap: 6px; }
.rsd-row label { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; }
.rsd-ctrl { display: flex; align-items: center; gap: 6px; }
.rsd-ctrl input[type=range] { flex: 1; accent-color: var(--accent, #4a8); cursor: pointer; }
.rsd-ctrl span { font-size: 12px; color: var(--text-dim); min-width: 32px; }
.rsd-choice {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface3);
  color: var(--text-dim);
  cursor: pointer;
}
.rsd-choice:hover { color: var(--text); border-color: var(--accent,#4a8); }
.rsd-choice.active { background: var(--accent,#4a8); color: #000; border-color: transparent; }
/* Light reading mode */
#readerBody.reader-light #textViewer,
#readerBody.reader-light #pdfViewer,
#readerBody.reader-light #epubViewer {
  background: #f9f6ef;
  color: #1a1a1a;
}
/* Dark reading mode (explicit, for re-applying after light) */
#readerBody.reader-dark #textViewer {
  background: #0d0d0d;
  color: #c8c8c8;
}
#emptyState {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  padding: 24px 16px 16px;
  box-sizing: border-box;
  color: var(--text-faint);
}
.empty-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.empty-placeholder .empty-icon, #emptyState .empty-icon { font-size: 48px; opacity: 0.3; }
.empty-placeholder p, #emptyState p { font-size: 13px; }

/* iframe viewer */
#iframeViewer {
  width: 100%;
  height: 100%;
  border: none;
  display: none;
  background: #fff;
}

/* text/md viewer */
#textViewer {
  display: none;
  height: 100%;
  overflow-y: auto;
  padding: 32px;
  font-family: var(--font-read);
  font-size: 16px;
  line-height: 1.75;
  color: var(--text);
  max-width: 780px;
  margin: 0 auto;
  touch-action: pan-y;
}
#textViewer.image-mode {
  max-width: none;
  padding: 16px;
  display: flex !important;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}
#textViewer.image-mode img {
  transform-origin: center center;
  will-change: transform;
  transition: none;
}
#textViewer pre {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--surface2);
  padding: 12px;
  border-radius: var(--radius);
  overflow-x: auto;
  white-space: pre-wrap;
}

/* PDF viewer */
#pdfViewer {
  display: none;
  height: 100%;
  overflow-y: auto;
  overflow-x: auto;
  background: var(--bg);
  padding: 16px;
}
#pdfPages {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  min-width: min-content;
}
.pdf-page-wrapper {
  position: relative;
  box-shadow: 0 2px 12px rgba(0,0,0,.6);
  line-height: 0;
  margin-left: auto;
  margin-right: auto;
}
.pdf-page-wrapper canvas {
  display: block;
  max-width: 100%;
}
.pdf-text-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  pointer-events: none;
}
.pdf-text-layer span {
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
  color: transparent;
  pointer-events: auto;
}
mark.pdf-match {
  background: rgba(212,160,23,.45);
  color: transparent;
  border-radius: 2px;
}
/* T button 3-stage active states */
.tb-btn.active-strong { color: var(--yellow) !important; }
/* Stage 1: visible text overlaid on image */
#pdfViewer.pdf-text-overlay .pdf-text-layer span,
#slPPg2.pdf-text-overlay .pdf-text-layer span {
  color: #1a1a1a;
  text-shadow: 0 0 4px rgba(248,246,240,.95), 0 0 2px rgba(248,246,240,.8);
}
#readerBody.reader-dark #pdfViewer.pdf-text-overlay .pdf-text-layer span { color: #ddd; text-shadow: 0 0 4px rgba(10,10,10,.95), 0 0 2px rgba(10,10,10,.8); }
/* Stage 2: hide JPEG, reveal text on plain background */
#pdfViewer.pdf-text-only .pdf-page-wrapper img,
#slPPg2.pdf-text-only .pdf-page-wrapper img { display: none; }
#pdfViewer.pdf-text-only .pdf-page-wrapper,
#slPPg2.pdf-text-only .pdf-page-wrapper { background: #f8f6f0; box-shadow: 0 1px 6px rgba(0,0,0,.15); }
#pdfViewer.pdf-text-only .pdf-text-layer span,
#slPPg2.pdf-text-only .pdf-text-layer span { color: #1a1a1a; text-shadow: none; }
#readerBody.reader-dark #pdfViewer.pdf-text-only .pdf-page-wrapper { background: #1a1a1a; }
#readerBody.reader-dark #pdfViewer.pdf-text-only .pdf-text-layer span { color: #c8c8c8; text-shadow: none; }
mark.rs-search-match {
  background: rgba(212,160,23,.3);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}
mark.rs-search-active {
  background: rgba(212,160,23,.75);
  outline: 2px solid #f59e0b;
  border-radius: 2px;
}

/* EPUB viewer */
#mediaViewer {
  display: none;
  height: 100%;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 32px;
  box-sizing: border-box;
}
#mediaViewer audio { border-radius: var(--radius); }
#mediaViewer video { border-radius: var(--radius); max-height: 100%; }

/* ── List player: chapter panel always visible beside the reader ─────────── */
.lv-player {
  display: flex;
  height: 100%;
  width: 100%;
  overflow: hidden;
}
/* Chapter list panel (left) — flex column so header/rows/footer stack cleanly */
.lv-chapter-list {
  width: 260px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  transition: width .18s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.lv-chapter-scroll { flex: 1; overflow-y: auto; }
/* Collapsed: narrow strip — only toggle button remains */
.lv-cl-collapsed {
  width: 36px !important;
  overflow: hidden;
}
.lv-cl-collapsed .chapter-row-item,
.lv-cl-collapsed .coll-row,
.lv-cl-collapsed .lv-chapter-list-header span,
.lv-cl-collapsed .lv-chapter-list-header .lv-header-btns,
.lv-cl-collapsed .lv-cl-footer { display: none !important; }
.lv-cl-collapsed .lv-chapter-list-header { justify-content: center; padding: 8px 0; }
@media (max-width: 640px) {
  .lv-cl-collapsed { flex: 0 0 36px !important; height: 36px !important; width: 100% !important; }
}
.lv-chapter-list-header {
  padding: 8px 10px 7px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: .05em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.lv-header-btns { display: flex; gap: 4px; }
.lv-hdr-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-faint);
  font-size: 13px;
  padding: 3px 5px;
  border-radius: 4px;
  line-height: 1;
  transition: color .12s, background .12s;
}
.lv-hdr-btn:hover { color: var(--text); background: var(--surface2); }
/* Persistent footer: compact prev/play-pause/next + shuffle/auto-next */
.lv-cl-footer {
  border-top: 1px solid var(--border);
  padding: 5px 6px;
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  background: var(--surface);
}
.lv-cl-now-playing {
  flex: 1;
  font-size: 10px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  padding: 0 3px;
}
.lv-ctrl-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-faint);
  font-size: 12px;
  padding: 3px 5px;
  border-radius: 4px;
  line-height: 1;
  flex-shrink: 0;
  transition: color .12s, background .12s;
}
.lv-ctrl-btn:hover { color: var(--text); background: var(--surface2); }
.lv-ctrl-btn.active { color: var(--accent, #4a8); }
/* readerBody in list-active mode: chapter list lives beside the viewer area */
#readerBody.lv-active {
  display: flex;
  overflow: hidden;
}
/* Only target the viewer elements — do NOT use :not() which would match dialogs/tap-zones */
#readerBody.lv-active > #emptyState,
#readerBody.lv-active > #iframeViewer,
#readerBody.lv-active > #textViewer,
#readerBody.lv-active > #pdfViewer,
#readerBody.lv-active > #mediaViewer,
#readerBody.lv-active > #epubViewer {
  flex: 1;
  min-width: 0;
}
/* Idle grid (thumbnail list shown before first track plays) */
.lv-idle-list {
  padding: 8px 0;
  overflow-y: auto;
  height: 100%;
}
.lv-idle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.lv-idle-row:hover { background: var(--surface2); }
.lv-idle-thumb {
  width: 36px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 3px;
  overflow: hidden;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-faint);
}
.lv-idle-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lv-idle-info { flex: 1; min-width: 0; }
.lv-idle-title { font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lv-idle-sub   { font-size: 11px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lv-idle-tag   { font-size: 10px; color: var(--text-faint); background: var(--surface2); border: 1px solid var(--border); padding: 1px 4px; border-radius: 3px; flex-shrink: 0; }
.chapter-row-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 12px;
  transition: background .1s;
}
.chapter-row-item:last-child { border-bottom: none; }
.chapter-row-item:hover { background: var(--surface2); }
.chapter-row-item.active {
  background: var(--surface3);
  border-left: 3px solid var(--accent, #4a8);
  padding-left: 11px;
}
.chapter-pos  { color: var(--text-faint); min-width: 24px; text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.chapter-name { flex: 1; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-row-item.active .chapter-name { color: var(--text); }
.chapter-dur-label { color: var(--text-faint); flex-shrink: 0; font-size: 11px; font-variant-numeric: tabular-nums; }
.chapter-unlink-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.4;
  transition: color .12s, background .12s;
  flex-shrink: 0;
}
.chapter-unlink-btn:hover,
.chapter-unlink-btn:focus { color: #fff; background: #c0392b; }
.coll-row-unlink {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  padding: 4px 7px;
  border-radius: 4px;
  font-size: 13px;
  line-height: 1;
  flex-shrink: 0;
  transition: color .12s, background .12s;
}
.coll-row-unlink:hover,
.coll-row-unlink:focus { color: #fff; background: #c0392b; }
.perm-row  { display:flex; align-items:center; gap:8px; font-size:13px; }
.perm-icon { font-size:14px; }
.perm-name { flex:1; color:var(--text); }
.perm-revoke-btn { background:none; border:none; cursor:pointer; color:var(--text-faint); font-size:13px; padding:2px 6px; border-radius:3px; }
.perm-revoke-btn:hover { color:#e55; background:var(--surface2); }

.lv-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0;
  background: var(--bg);
  overflow: hidden;
}
.lv-counter {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 4px;
}

/* Custom audio player stage */
.ap-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px 40px;
  width: 100%;
  box-sizing: border-box;
}
.ap-disc {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
  border: none;
  background: var(--ap-disc-bg, var(--surface2));
  box-shadow: var(--ap-disc-shadow, 0 4px 18px rgba(0,0,0,.5));
  transition: box-shadow .2s, transform .1s;
  color: var(--text-dim);
  padding: 0;
  overflow: hidden;
}
.ap-disc:hover { transform: scale(1.05); }
.ap-disc:active { transform: scale(0.97); }
.ap-disc.playing { animation: ap-spin 12s linear infinite; }
.ap-disc.playing:hover { animation-play-state: paused; }
@keyframes ap-spin { to { transform: rotate(360deg); } }
.ap-disc-overlay {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .15s;
  color: var(--ap-accent, #4a8);
}
.ap-disc:not(.playing) .ap-disc-overlay { opacity: 1; }
.ap-disc.playing:hover .ap-disc-overlay { opacity: 1; }
.ap-disc-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}
.ap-nav-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ap-accent, #4a8);
  opacity: 0.65;
  transition: opacity .15s, transform .12s;
  padding: 0;
  display: flex;
  align-items: center;
  border-radius: 50%;
  flex-shrink: 0;
}
.ap-nav-btn:hover  { opacity: 1; transform: scale(1.1); }
.ap-nav-btn:active { transform: scale(0.93); }
.ap-title    { font-size: 15px; font-weight: 600; color: var(--text); text-align: center; max-width: 360px; line-height: 1.4; }
.ap-subtitle { font-size: 12px; color: var(--text-dim); text-align: center; max-width: 360px; min-height: 16px; }
.ap-progress-wrap  { width: 100%; max-width: 340px; cursor: pointer; }
.ap-progress-track { height: 4px; border-radius: 2px; background: var(--ap-track, var(--surface3)); position: relative; }
.ap-progress-fill  { height: 100%; background: var(--ap-accent, #4a8); border-radius: 2px; width: 0%; pointer-events: none; }
.ap-time { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-faint); margin-top: 5px; font-variant-numeric: tabular-nums; }
.ap-vol-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 280px;
  margin-top: 6px;
}
.ap-vol-btn { opacity: 0.55; }
.ap-vol-slider {
  --vol-pct: 100%;
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--ap-accent, #4a8) 0%, var(--ap-accent, #4a8) var(--vol-pct), var(--ap-track, var(--surface3)) var(--vol-pct));
  cursor: pointer;
  outline: none;
  border: none;
}
.ap-vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ap-accent, #4a8);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.ap-vol-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ap-accent, #4a8);
  border: none;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}

/* Player styles */
.ap-style-default { --ap-disc-bg: radial-gradient(circle at 38% 38%, #1e2820 0%, #141414 100%); --ap-accent: #4a8; }
.ap-style-glow    { --ap-disc-bg: radial-gradient(circle at 38% 38%, #0d1a0d 0%, #060806 100%); --ap-disc-shadow: 0 0 0 2px #3d8c65, 0 0 26px rgba(61,140,101,.4), 0 4px 18px rgba(0,0,0,.8); --ap-accent: #3d8c65; }
.ap-style-warm    { --ap-disc-bg: radial-gradient(circle at 38% 38%, #2a1c08 0%, #110b03 100%); --ap-disc-shadow: 0 4px 20px rgba(80,50,0,.55); --ap-accent: #d4a017; }
.ap-style-ocean   { --ap-disc-bg: radial-gradient(circle at 38% 38%, #071c2a 0%, #04111b 100%); --ap-disc-shadow: 0 4px 20px rgba(0,50,90,.5); --ap-accent: #2a8aac; }
.ap-style-minimal { --ap-disc-bg: transparent; --ap-disc-shadow: none; --ap-accent: var(--text-faint); --ap-track: var(--border); }
.ap-style-minimal .ap-disc { border: 1.5px solid var(--border2); }

/* Player style picker */
.player-style-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  background: none;
  color: var(--text-dim);
}
.player-style-btn.active { background: var(--surface3); color: var(--yellow); border-color: var(--yellow); }
.player-style-btn:hover:not(.active) { background: var(--surface3); color: var(--text); }
.ps-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* List countdown bar */
#listCountdownBar {
  display: none;
  position: absolute;
  bottom: 0; left: 0; right: 0;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface2);
  border-top: 1px solid var(--border2);
  font-size: 12px;
  color: var(--text-dim);
  z-index: 20;
}
.lcd-next { flex: 1; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lcd-timer { color: var(--text-faint); flex-shrink: 0; }
.lcd-timer strong { color: var(--yellow); }
.lcd-btn {
  padding: 3px 12px;
  border-radius: 12px;
  border: 1px solid var(--border2);
  background: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
}
.lcd-btn:hover { background: var(--surface3); color: var(--text); }
.lcd-stay { color: var(--text-faint); }

/* Book tag in list track list */
.list-book-tag { color: var(--text-faint); font-style: italic; }

/* ── Video player ──────────────────────────────────────────────────────────── */
.vp-stage {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
}
.vp-video-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-height: 0;
}
.vp-video-wrap video {
  max-width: 100%;
  max-height: 100%;
  display: block;
  background: #000;
}
.vp-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(0,0,0,.85);
  border-top: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}
.vp-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,.8);
  padding: 3px;
  border-radius: 4px;
  line-height: 0;
  flex-shrink: 0;
  transition: color .1s;
}
.vp-btn:hover { color: #fff; }
.vp-btn svg { display: block; }
.vp-progress-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  cursor: pointer;
  min-width: 0;
}
.vp-progress-track {
  height: 3px;
  border-radius: 2px;
  background: rgba(255,255,255,.2);
  position: relative;
}
.vp-progress-fill {
  height: 100%;
  background: var(--accent, #4a8);
  border-radius: 2px;
  width: 0%;
  pointer-events: none;
}
.vp-time {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: rgba(255,255,255,.45);
  font-variant-numeric: tabular-nums;
}
.vp-title-bar {
  padding: 5px 12px 4px;
  font-size: 11px;
  color: rgba(255,255,255,.5);
  background: rgba(0,0,0,.85);
  border-top: 1px solid rgba(255,255,255,.05);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
}
.vp-vol-slider {
  width: 64px;
  flex-shrink: 0;
  accent-color: var(--accent, #4a8);
  cursor: pointer;
  height: 3px;
}

/* ── Collection list ───────────────────────────────────────────────────────── */
.coll-list {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  background: var(--bg);
}
.coll-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  cursor: pointer;
  transition: background .1s;
}
.coll-row:hover { background: var(--surface2); }
.coll-row.active { background: var(--surface3); border-left: 3px solid var(--accent,#4a8); padding-left: 13px; }
.coll-row-num  { color: var(--text-faint); min-width: 24px; text-align: right; font-variant-numeric: tabular-nums; font-size: 11px; flex-shrink: 0; }
.coll-row-icon { flex-shrink: 0; font-size: 15px; }
.coll-row-info { flex: 1; min-width: 0; }
.coll-row-title { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.coll-row-meta  { font-size: 11px; color: var(--text-faint); margin-top: 1px; }
.coll-row-tag  { color: var(--text-faint); font-size: 11px; flex-shrink: 0; }
.coll-row-dl   { background: none; border: none; cursor: pointer; color: var(--text-faint); padding: 4px 6px; border-radius: 4px; flex-shrink: 0; line-height: 0; transition: color .1s; }
.coll-row-dl:hover { color: var(--accent,#4a8); }
.coll-type-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-faint);
  background: none;
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 2px 8px;
  cursor: pointer;
  transition: color .12s, border-color .12s;
}
.coll-type-toggle:hover { color: var(--accent,#4a8); border-color: var(--accent,#4a8); }

/* Bulk metadata edit modal */
#bulkMetaModal .modal-content { max-width: 400px; }

/* List controls (shuffle / auto-next toggle buttons) */
.pl-controls {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.pl-ctrl-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid var(--border2);
  background: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.pl-ctrl-btn svg { flex-shrink: 0; }
.pl-ctrl-btn:hover { background: var(--surface3); color: var(--text); }
.pl-ctrl-btn.active { background: var(--surface2); border-color: var(--yellow); color: var(--yellow); }

/* File selection mode */
.file-item.selected { background: var(--surface2); border-left: 2px solid #4a8; }
.file-select-cb {
  width: 14px; height: 14px;
  border: 1.5px solid var(--border2);
  border-radius: 3px;
  flex-shrink: 0;
  margin-top: 3px;
  position: relative;
  background: var(--surface3);
}
.file-select-cb.checked { background: #4a8; border-color: #4a8; }
.file-select-cb.checked::after {
  content: '';
  position: absolute;
  left: 2px; top: 1px;
  width: 6px; height: 4px;
  border-left: 1.5px solid #fff;
  border-bottom: 1.5px solid #fff;
  transform: rotate(-45deg);
}

/* Selection action bar */
#selectionBar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#selectionBar .sel-count { font-size: 12px; color: var(--text-dim); flex: 1; }

/* Playlist badge */
.badge-pl { border-color: #3a2a5a; color: #a88; }

/* Add to playlist modal */
#addToPlaylistModal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,.6);
  align-items: center;
  justify-content: center;
}
#addToPlaylistModal.open { display: flex; }
.apl-box {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 20px;
  min-width: 300px;
  max-width: 420px;
  width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.apl-box h3 { margin: 0; font-size: 15px; color: var(--text); }
.apl-new-row { display: flex; gap: 8px; }
.apl-new-row input { flex: 1; }
.apl-existing { overflow-y: auto; max-height: 220px; display: flex; flex-direction: column; gap: 4px; }
.apl-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 5px;
  cursor: pointer;
  border: 1px solid transparent;
}
.apl-row:hover { background: var(--surface3); border-color: var(--border2); }
.apl-name { flex: 1; font-size: 13px; color: var(--text); }
.apl-count { font-size: 11px; color: var(--text-faint); }
.apl-section-label { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; margin-top: 4px; }

@media (max-width: 640px) {
  .lv-player { flex-direction: column; }
  .lv-chapter-list { width: 100%; flex: 0 0 40%; border-right: none; border-bottom: 1px solid var(--border); }
  #readerBody.lv-active { flex-direction: column; }
  #readerBody.lv-active > .lv-chapter-list { width: 100% !important; flex: 0 0 40%; border-right: none; border-bottom: 1px solid var(--border); }
  .ap-stage { padding: 20px; gap: 12px; }
  .ap-disc { width: 90px; height: 90px; }
}

#epubViewer {
  display: none;
  height: 100%;
  position: relative;
  background: var(--surface2);
  overflow-y: auto;
}
#epubViewer iframe {
  background: var(--surface2);
}
.epub-toc-item {
  padding: 6px 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  border-radius: var(--radius);
  line-height: 1.4;
}
.epub-toc-item:hover { background: var(--surface3); }
.epub-toc-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-faint);
  padding: 10px 8px 4px;
}
#epubNav {
  display: none;
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  z-index: 10;
}
#epubNav button {
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 6px 18px;
  font-size: 18px;
  color: var(--text-dim);
}
#epubNav button:hover { background: var(--border2); color: var(--text); }
.epub-tap-zone {
  position: absolute;
  top: 0;
  height: 100%;
  width: 30%;
  z-index: 5;
  cursor: pointer;
}
#epubTapLeft, #sepTapLeft   { left: 0; }
#epubTapRight, #sepTapRight { right: 0; }

/* sidebar toggle strip */
#sidebarToggle {
  width: 14px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-faint);
  font-size: 10px;
  transition: background .15s;
  user-select: none;
}
#sidebarToggle:hover { background: var(--surface3); color: var(--text-dim); }

/* sidebar */
#sidebar {
  width: var(--sidebar);
  min-width: var(--sidebar);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .2s ease, min-width .2s ease;
  flex-shrink: 0;
  min-height: 0;
}
#listSection {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
#listHeader {
  display: flex;
  align-items: center;
  padding: 3px 8px 3px 12px;
  border-bottom: 1px solid var(--border);
  gap: 6px;
  flex-shrink: 0;
}
.list-header-count {
  font-size: 11px;
  color: var(--text-faint);
  flex: 1;
}
.list-sel-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-faint);
  padding: 3px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: none;
  cursor: pointer;
  transition: color .12s, border-color .12s, background .12s;
  white-space: nowrap;
}
.list-sel-btn:hover { color: var(--text-dim); border-color: var(--border2); }
.list-sel-btn.active { color: #4a8; border-color: #4a8; background: rgba(70,180,120,.08); }
.lib-view-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  color: var(--text-faint);
  background: none;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
  gap: 3px;
}
.lib-view-icon-btn:hover { color: var(--text-dim); border-color: var(--border2); }
.lib-view-icon-btn.active { color: var(--yellow); border-color: var(--yellow); background: rgba(212,160,23,0.08); }
#fileList {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
}
/* grid view */
/* cover mini in list view */
.file-cover-mini {
  width: 36px;
  min-width: 36px;
  height: 50px;
  border-radius: 2px;
  overflow: hidden;
  background: var(--surface3);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}
.file-cover-mini img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-cover-mini-fallback {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
}
.file-cover-mini-fallback svg { width: 18px; height: 18px; }
#sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-left: none;
}
.sidebar-section {
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-section-header {
  padding: 8px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* upload section */
#uploadSection { padding: 10px 12px; }
#dropZone {
  border: 1px dashed var(--border2);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  cursor: pointer;
  color: var(--text-faint);
  font-size: 12px;
  transition: border-color .15s, background .15s;
}
#dropZone.dragover {
  border-color: var(--text-dim);
  background: var(--surface3);
  color: var(--text-dim);
}
#dropZone:hover { border-color: var(--text-dim); }
.upload-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  border: 1px dashed var(--border2);
  border-radius: var(--radius);
  background: none;
  color: var(--text-faint);
  font-size: 13px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.upload-icon-btn:hover { border-color: var(--text-dim); color: var(--text-dim); }
.upload-icon-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
#urlUploadRow {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
#urlUploadRow input { flex: 1; font-size: 12px; }
#urlUploadBtn {
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text-dim);
}
#urlUploadBtn:hover { color: var(--text); }

/* filter + file list */
#listSection {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}
#filterRow {
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#filterInput { width: 100%; font-size: 13px; }
#typeFilterRow {
  display: flex;
  gap: 4px;
}
.type-filter-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 7px;
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text-faint);
  cursor: pointer;
  font-size: 11px;
  line-height: 0;
  flex: 1;
}
.type-filter-btn:hover { color: var(--text-dim); border-color: var(--text-faint); }
.type-filter-btn.active { border-color: var(--yellow); color: var(--yellow); background: rgba(212,160,23,0.08); }
.lib-view-btn {
  display: block;
  text-align: center;
  padding: 5px 8px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-dim);
}
.lib-view-btn:hover { background: var(--surface3); color: var(--text); }
#fileList {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}
.file-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 12px;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  position: relative;
}
.file-item:hover { background: var(--surface3); }
.file-item.active { background: var(--surface2); border-left: 2px solid var(--border2); }
.file-type-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: 3px;
  padding: 2px 5px;
  color: var(--text-faint);
  flex-shrink: 0;
  margin-top: 2px;
  line-height: 0;
  user-select: none;
}
.file-type-icon.audio-toggle { cursor: pointer; }
.file-type-icon.audio-toggle:hover { color: var(--text); border-color: var(--text-faint); }
.file-info { flex: 1; min-width: 0; }
.file-title {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-meta {
  font-size: 11px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 1px;
}
.file-actions {
  display: none;
  gap: 3px;
  flex-shrink: 0;
  align-items: center;
}
.file-item:hover .file-actions { display: flex; }
.file-act-btn {
  font-size: 13px;
  padding: 2px 5px;
  border-radius: 3px;
  color: var(--text-faint);
}
.file-act-btn:hover { background: var(--border2); color: var(--text); }
.file-act-btn.del:hover { color: #d44; }
.status-badge {
  font-size: 10px;
  border-radius: 3px;
  padding: 1px 5px;
  border: 1px solid;
  flex-shrink: 0;
  margin-top: 2px;
}
.badge-ok  { border-color: var(--border2); color: var(--text-faint); }
.badge-idx { border-color: #2a4a2a; color: #4a8; }
.badge-err { border-color: #4a2a2a; color: #a44; }

/* collapsible panels */
.panel {
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-header {
  padding: 7px 12px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.panel-header:hover { background: var(--surface3); }
.panel-caret { font-size: 10px; color: var(--text-faint); transition: transform .15s; }
.panel.open .panel-caret { transform: rotate(90deg); }
.panel-body { display: none; padding: 8px 12px; }
.panel.open .panel-body { display: block; }

/* notes panel */
#notesPanel { display: none; }
#notesTextarea {
  width: 100%;
  min-height: 70px;
  resize: vertical;
  font-size: 12px;
  font-family: var(--font-mono);
  line-height: 1.5;
  background: var(--bg);
  border-color: var(--border);
}
.notes-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 5px;
}
.notes-saved { font-size: 11px; color: var(--text-faint); }
.notes-editor-btn {
  font-size: 11px;
  color: var(--text-dim);
  padding: 2px 7px;
  border: 1px solid var(--border2);
  border-radius: var(--radius);
}
.notes-editor-btn:hover { background: var(--surface3); }

/* links panel */
#linksPanel { display: none; }
.link-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  font-size: 12px;
  color: var(--text-dim);
}
.link-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  color: var(--text);
}
.link-title:hover { text-decoration: underline; }
.link-del { font-size: 11px; color: var(--text-faint); }
.link-del:hover { color: #d44; }
#linkAddRow {
  display: flex;
  gap: 5px;
  margin-top: 7px;
}
#linkAddRow select { flex: 1; font-size: 12px; }
#linkAddBtn {
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 3px 10px;
  font-size: 12px;
  color: var(--text-dim);
}
#linkAddBtn:hover { color: var(--text); }

/* quick grant panel */
#grantPanel { display: none; }
.grant-row {
  display: flex;
  gap: 5px;
  margin-bottom: 6px;
  align-items: center;
}
.grant-row select { flex: 1; font-size: 12px; }
.grant-btn {
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 3px 10px;
  font-size: 12px;
  color: var(--text-dim);
}
.grant-btn:hover { color: var(--text); }
.grant-label { font-size: 11px; color: var(--text-faint); width: 32px; }

/* ── Modals ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 20px;
  min-width: 320px;
  max-width: 600px;
  width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}
.modal h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text);
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  font-size: 18px;
  color: var(--text-faint);
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

/* info modal */
.meta-row { display: flex; gap: 8px; margin-bottom: 6px; font-size: 13px; }
.meta-key { color: var(--text-faint); min-width: 90px; flex-shrink: 0; }
.meta-val { color: var(--text); word-break: break-word; }

/* share modal */
#shareLink {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 7px 8px;
  background: var(--bg);
  border-color: var(--border2);
  cursor: pointer;
  user-select: all;
}
.share-copy-hint { font-size: 11px; color: var(--text-faint); margin-top: 5px; }

/* notes editor modal */
#notesEditorModal .modal { max-width: 90vw; width: 860px; max-height: 90vh; }
#notesEditorTextarea {
  width: 100%;
  min-height: 400px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  background: var(--bg);
  border-color: var(--border2);
  resize: vertical;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}
.btn {
  padding: 6px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  border: 1px solid var(--border2);
  background: var(--surface3);
  color: var(--text-dim);
  cursor: pointer;
}
.btn:hover { color: var(--text); background: var(--border2); }
.btn-primary {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--text-faint);
}
.btn-primary:hover { border-color: var(--text); }

/* upload progress */
#uploadProgress {
  display: none;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface2);
}
#uploadBar {
  height: 2px;
  background: var(--text-faint);
  margin-top: 3px;
  border-radius: 1px;
  width: 0;
  transition: width .2s;
}

/* ── Sidebar tabs (Library / Messenger) ─────────────────────────────────── */
#sidebarTabs {
  display: none;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.sidebar-tab {
  flex: 1;
  padding: 7px 4px;
  font-size: 12px;
  font-weight: 500;
  border: none;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.sidebar-tab.active { color: var(--accent, #4aa); border-bottom-color: var(--accent, #4aa); }
.sidebar-tab:hover:not(.active) { color: var(--text-dim); }

/* Unread mail indicator — orange dot on messenger tab */
.sidebar-tab.mail-has-unread { position: relative; }
.sidebar-tab.mail-has-unread::after {
  content: '';
  position: absolute;
  top: 5px;
  right: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e07030;
  pointer-events: none;
}

/* Unread dot inline in conversation name */
.m-unread-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e07030;
  margin-left: 5px;
  vertical-align: middle;
  flex-shrink: 0;
}
.m-conv-unread .m-conv-name { font-weight: 600; color: var(--text); }

/* ── Messenger sidebar view ──────────────────────────────────────────────── */
#messengerView      { background: var(--surface); }
.m-panel            { display: flex; flex-direction: column; flex: 1; overflow: hidden; min-height: 0; }
.m-scrollable       { flex: 1; overflow-y: auto; }
.m-loading          { padding: 16px; text-align: center; font-size: 12px; color: var(--text-faint); }
.m-empty            { padding: 20px 12px; text-align: center; font-size: 12px; color: var(--text-faint); line-height: 1.6; }
.m-error            { padding: 10px 12px; font-size: 12px; color: var(--c-red, #a44); }

/* toolbar */
.m-toolbar          { display: flex; align-items: center; gap: 4px; padding: 7px 8px; border-bottom: 1px solid var(--border); background: var(--surface2); flex-shrink: 0; }
.m-toolbar-title    { flex: 1; font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-icon-btn         { border: none; background: none; cursor: pointer; color: var(--text-dim); font-size: 14px; padding: 3px 6px; border-radius: 4px; transition: background .12s; }
.m-icon-btn:hover   { background: var(--border); color: var(--text); }
.m-compose-btn      { font-size: 13px; }

/* conversation list */
.m-conv-row         { display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .1s; }
.m-conv-row:hover   { background: var(--surface2); }
.m-avatar           { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-dim, #1a3a3a); color: var(--accent, #4aa); font-size: 14px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.m-conv-info        { flex: 1; min-width: 0; }
.m-conv-name        { font-size: 13px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-conv-preview     { font-size: 11px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.m-conv-time        { font-size: 10px; color: var(--text-faint); flex-shrink: 0; align-self: flex-start; margin-top: 2px; }

/* thread */
.m-thread           { padding: 10px 8px; display: flex; flex-direction: column; gap: 8px; }
.m-bubble-wrap      { display: flex; }
.m-bw-in            { justify-content: flex-start; }
.m-bw-out           { justify-content: flex-end; }
.m-bubble           { max-width: 88%; padding: 7px 10px; border-radius: 12px; font-size: 12px; }
.m-bubble-in        { background: var(--surface2); border-bottom-left-radius: 3px; }
.m-bubble-out       { background: var(--accent-dim, #1a3a3a); border-bottom-right-radius: 3px; }
.m-bubble-subj      { font-size: 10px; font-weight: 600; color: var(--text-faint); margin-bottom: 3px; }
.m-bubble-body      { color: var(--text); line-height: 1.45; word-break: break-word; }
.m-bubble-time      { font-size: 10px; color: var(--text-faint); margin-top: 4px; text-align: right; display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.m-ch-badge         { font-size: 9px; font-weight: 700; padding: 1px 4px; border-radius: 3px; color: #fff; letter-spacing: .03em; flex-shrink: 0; }
.m-platform-btn     { border: none; cursor: pointer; padding: 4px 9px; border-radius: 4px; font-size: 11px; font-weight: 700; color: #fff; letter-spacing: .03em; }

/* Share-dialog send rows */
.share-send-row     { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.share-ch-label     { font-size: 10px; font-weight: 700; color: #fff; padding: 3px 6px; border-radius: 4px; flex-shrink: 0; min-width: 24px; text-align: center; letter-spacing: .03em; }
.share-ch-label.share-ch-email { background: var(--accent, #4aa); font-size: 14px; padding: 2px 5px; }
.share-ch-input     { font-size: 12px; padding: 4px 7px; border: 1px solid var(--border); border-radius: 4px; background: var(--input-bg, var(--bg2)); color: var(--text); min-width: 0; }
.share-ch-btn       { border: none; cursor: pointer; padding: 4px 10px; border-radius: 4px; font-size: 11px; font-weight: 600; color: #fff; white-space: nowrap; flex-shrink: 0; }
.share-ch-btn.share-ch-btn-email { background: var(--accent, #4aa); }

/* Toggle switch */
.rs-toggle { position:relative; display:inline-block; width:32px; height:18px; flex-shrink:0; }
.rs-toggle input { opacity:0; width:0; height:0; position:absolute; }
.rs-toggle-track { position:absolute; inset:0; background:var(--border2,#444); border-radius:18px; transition:background .2s; cursor:pointer; }
.rs-toggle-track:before { content:''; position:absolute; width:12px; height:12px; left:3px; top:3px; background:#fff; border-radius:50%; transition:transform .2s; }
.rs-toggle input:checked ~ .rs-toggle-track { background:var(--accent,#4aa); }
.rs-toggle input:checked ~ .rs-toggle-track:before { transform:translateX(14px); }
.rs-toggle-row { display:flex; align-items:center; gap:8px; font-size:13px; color:var(--text-dim); cursor:pointer; user-select:none; }

/* reply area */
.m-reply-area       { border-top: 1px solid var(--border); padding: 7px 8px; flex-shrink: 0; background: var(--surface); }
.m-reply-input      { width: 100%; box-sizing: border-box; font-size: 12px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--input-bg, var(--bg2)); color: var(--text); resize: none; font-family: inherit; }
.m-reply-footer     { display: flex; align-items: center; justify-content: space-between; margin-top: 5px; }
.m-status           { font-size: 11px; color: var(--text-faint); }

/* compose inputs */
.m-input            { width: 100%; box-sizing: border-box; font-size: 12px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; background: var(--input-bg, var(--bg2)); color: var(--text); font-family: inherit; }
textarea.m-input    { resize: vertical; }
.m-suggest-list     { display: none; position: absolute; top: 100%; left: 0; right: 0; margin: 2px 0 0; padding: 4px 0; list-style: none; background: var(--surface); border: 1px solid var(--border2); border-radius: 4px; box-shadow: 0 4px 16px rgba(0,0,0,.4); z-index: 10; max-height: 180px; overflow-y: auto; }
.m-link             { color: var(--accent, #4aa); text-decoration: underline; word-break: break-all; }
.m-link:hover       { opacity: .8; }
.m-action-bar       { display: flex; gap: 4px; padding: 5px 8px; border-bottom: 1px solid var(--border); background: var(--surface2); flex-shrink: 0; flex-wrap: wrap; }
.m-action-btn       { font-size: 11px; padding: 2px 8px; border: 1px solid var(--border); border-radius: 4px; background: none; cursor: pointer; color: var(--text-dim); transition: background .1s, color .1s; white-space: nowrap; }
.m-action-btn:hover { background: var(--border); color: var(--text); }
.m-action-btn.m-danger       { color: var(--c-red, #a44); border-color: transparent; }
.m-action-btn.m-danger:hover { background: rgba(170,68,68,.15); color: var(--c-red, #a44); }
.m-bubble-status  { font-size: 10px; margin-top: 3px; text-align: right; }
.m-sending        { color: var(--text-faint); font-style: italic; }
.m-failed         { color: var(--c-red, #a44); }

/* ── Task queue indicator (sidebar) ─────────────────────────────────────── */
#taskQueueIndicator {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--surface2);
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
}
#taskQueueIndicator:hover { background: var(--surface3, var(--border)); color: var(--text); }

#taskQueueDot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--c-blue, #4aa);
}
#taskQueueDot.tq-running  { background: #4aa; animation: tqPulse 1.2s ease-in-out infinite; }
#taskQueueDot.tq-waiting  { background: #88a; animation: tqPulse 1.8s ease-in-out infinite; }
#taskQueueDot.tq-cooldown { background: #a8a; }
#taskQueueDot.tq-pending  { background: #aa8; }
#taskQueueDot.tq-idle     { background: var(--text-faint); }

@keyframes tqPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .35; }
}

/* ── Admin page ──────────────────────────────────────────────────────────── */
.admin-layout {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--header));
}
.admin-nav {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  width: 100%;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
  flex-shrink: 0;
}
.admin-nav-item {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.admin-nav-item:hover { color: var(--text); }
.admin-nav-item.active {
  color: var(--text);
  border-bottom-color: var(--text-dim);
}
.admin-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.admin-section { display: none; }
.admin-section.active { display: block; }
.admin-section h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 18px;
  color: var(--text);
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card h3 { font-size: 13px; font-weight: 600; margin-bottom: 12px; color: var(--text-dim); }
.form-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.form-row label { font-size: 12px; color: var(--text-faint); min-width: 100px; }
.form-row input, .form-row select {
  flex: 1;
  min-width: 120px;
  font-size: 13px;
}
.form-row .btn { flex-shrink: 0; }
.form-inline {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.form-inline input, .form-inline select { font-size: 13px; }

/* table */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border2);
  color: var(--text-faint);
  font-weight: 500;
}
.data-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.data-table tr:hover td { background: var(--surface3); }

/* badge */
.badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  border: 1px solid var(--border2);
  color: var(--text-faint);
}
.badge-green  { border-color: #2a4a2a; color: #4a8; }
.badge-red    { border-color: #4a2a2a; color: #a44; }
.badge-yellow { border-color: #4a3a10; color: #b80; }

/* permissions panel */
.perm-mode-btns { display: flex; gap: 8px; margin-bottom: 14px; }
.perm-mode-btn {
  padding: 5px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border2);
  background: var(--surface2);
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
}
.perm-mode-btn.active {
  background: var(--surface3);
  color: var(--text);
  border-color: var(--text-faint);
}
#bookChecklist {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  background: var(--bg);
  margin: 8px 0;
}
.book-check-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 5px;
  border-radius: 3px;
  cursor: pointer;
}
.book-check-item:hover { background: var(--surface3); }
.book-check-item label {
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.book-check-item input[type=checkbox] { flex-shrink: 0; }
.fa-granted    { background: rgba(68,170,102,0.09); }
.fa-granted:hover { background: rgba(68,170,102,0.16); }
.fa-accessible { background: rgba(68,170,102,0.07); }
.fa-accessible:hover { background: rgba(68,170,102,0.14); }
#faChecklist {
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  margin: 4px 0;
}
.fa-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--text); }
.fa-sub   { color: var(--text-faint); font-size: 11px; }
.fa-badges { display: flex; gap: 3px; flex-shrink: 0; align-items: center; flex-wrap: wrap; }
.fa-direct-badge { background: rgba(68,170,102,0.18) !important; color: #4a8 !important; border-color: rgba(68,170,102,0.4) !important; }
.fa-group-badge  { background: rgba(80,130,220,0.14) !important; color: #7ab !important; border-color: rgba(80,130,220,0.3) !important; font-size: 10px !important; }
.fa-owner-badge  { background: rgba(200,160,50,0.14) !important; color: #b94 !important; border-color: rgba(200,160,50,0.3) !important; font-size: 10px !important; }

/* ── Progress bars ───────────────────────────────────────────────────────── */
.progress-wrap {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin: 8px 0 4px;
  overflow: hidden;
}
.progress-inner {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s;
}

/* ── Log panel ───────────────────────────────────────────────────────────── */
.log-panel {
  max-height: 420px;
  overflow-y: auto;
  background: #0d0d0d;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.6;
}
.log-line       { color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.log-line.ok    { color: #4a8; }
.log-line.err   { color: #a44; }
.log-line.warn  { color: #a84; }
.log-line.dim   { color: var(--text-faint); }
.log-thumb {
  width: 24px;
  height: 34px;
  object-fit: cover;
  border-radius: 2px;
  flex-shrink: 0;
  vertical-align: middle;
}
.fim-thumb {
  width: 11px;
  height: 15px;
  object-fit: cover;
  border-radius: 1px;
  display: block;
}

/* ── Seafile file browser ────────────────────────────────────────────────── */
.sf-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.sf-item:last-child { border-bottom: none; }
.sf-item:hover { background: var(--surface3); }
.sf-file { cursor: default; }
.sf-file:hover { background: var(--surface3); }
.sf-icon { flex-shrink: 0; font-size: 14px; }
.sf-name { flex: 1; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sf-dir .sf-name { color: var(--accent, #4a8); }
.sf-meta { font-size: 11px; color: var(--text-faint); flex-shrink: 0; }
.sf-crumb { color: var(--accent, #4a8); cursor: pointer; font-size: 13px; }
.sf-crumb:hover { text-decoration: underline; }

/* Two-pane Seafile browser */
.sf-panes { display: flex; height: 340px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-top: 8px; }
.sf-tree-pane { width: 220px; min-width: 140px; border-right: 1px solid var(--border); overflow-y: auto; background: var(--surface); flex-shrink: 0; }
.sf-files-pane { flex: 1; overflow-y: auto; background: var(--surface2); min-width: 0; }
.sf-tree-row { display: flex; align-items: center; gap: 4px; padding: 5px 6px; cursor: pointer; font-size: 12px; user-select: none; }
.sf-tree-row:hover { background: var(--surface3); }
.sf-tree-active { background: var(--surface3) !important; }
.sf-tree-active .sf-tree-label { color: var(--accent, #4a8); }
.sf-tree-arrow { width: 14px; flex-shrink: 0; text-align: center; font-size: 10px; color: var(--text-faint); cursor: pointer; }
.sf-tree-arrow:hover { color: var(--text); }
.sf-tree-icon { flex-shrink: 0; font-size: 13px; }
.sf-tree-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.sf-file-row { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-bottom: 1px solid var(--border); cursor: default; font-size: 13px; }
.sf-file-row:hover { background: var(--surface3); }
.sf-file-row.sf-file-dir .sf-name { color: var(--accent, #4a8); }
.sf-file-row input[type=checkbox] { flex-shrink: 0; cursor: pointer; }
.sf-nav-btn { margin-left: auto; padding: 1px 7px; font-size: 11px; background: var(--surface3); border: 1px solid var(--border2); border-radius: var(--radius); color: var(--text-dim); cursor: pointer; flex-shrink: 0; }
.sf-nav-btn:hover { color: var(--text); border-color: var(--text-faint); }

/* ── Operation row (button + log toggle) ─────────────────────────────────── */
.op-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.log-toggle-btn { margin-left: auto; }

/* ── Search-field clear button ───────────────────────────────────────────── */
.srch-wrap { position: relative; display: block; }
.srch-wrap input { width: 100%; box-sizing: border-box; padding-right: 26px; }
.srch-clr {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; padding: 3px 5px;
  color: var(--text-dim); font-size: 14px; line-height: 1;
  display: none; border-radius: 3px; min-width: 0;
}
.srch-clr.visible { display: block; }
.srch-clr:hover { color: var(--text); }

/* ── File Index Manager ──────────────────────────────────────────────────── */
.fim-filters { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.fim-filters .srch-wrap { flex: 1; min-width: 140px; }
.fim-filters input  { font-size: 13px; }
.fim-filters select { font-size: 13px; }
.bulk-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  padding: 6px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.fim-table td   { vertical-align: middle; }
th.sortable     { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
.sort-ind       { font-size: 10px; }

/* ES status indicator */
.es-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border2);
  color: var(--text-faint);
}
.es-badge.online  { border-color: #2a4a2a; color: #4a8; }
.es-badge.offline { border-color: #4a2a2a; color: #a44; }

/* ── Task badges ─────────────────────────────────────────────────────────── */
.task-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 10px;
  border: 1px solid var(--border2);
  color: var(--text-faint);
}
.task-badge.task-pending   { border-color: #3a3a22; color: #aa8; }
.task-badge.task-waiting   { border-color: #2a2a3a; color: #88a; animation: taskPulse 1.8s ease-in-out infinite; }
.task-badge.task-running   { border-color: #223a3a; color: #4aa; animation: taskPulse 1.4s ease-in-out infinite; }
.task-badge.task-cooldown  { border-color: #3a2a3a; color: #a8a; }
.task-badge.task-scheduled { border-color: #2a3a2a; color: #8a8; }
.task-badge.task-done      { border-color: #2a4a2a; color: #4a8; }
.task-badge.task-failed    { border-color: #4a2a2a; color: #a44; }
.task-badge.task-cancelled { border-color: #3a3a3a; color: #777; }

@keyframes taskPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .5; }
}

/* ── Login page ──────────────────────────────────────────────────────────── */
.login-page {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 32px;
  width: 320px;
}
.login-logo {
  font-family: var(--font-mono);
  font-size: 20px;
  text-align: center;
  margin-bottom: 24px;
  color: var(--text);
  letter-spacing: -1px;
}
.login-box label {
  display: block;
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 4px;
  margin-top: 12px;
}
.login-box input {
  width: 100%;
  padding: 8px;
  font-size: 14px;
}
.login-btn {
  width: 100%;
  margin-top: 18px;
  padding: 9px;
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  transition: background .15s;
}
.login-btn:hover { background: var(--border2); }
.login-error {
  margin-top: 10px;
  color: #c44;
  font-size: 12px;
  text-align: center;
}

/* ── Share page ──────────────────────────────────────────────────────────── */
.share-layout {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}
.share-topbar {
  min-height: var(--header);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 12px;
  flex-shrink: 0;
}
.share-filename {
  flex: 1;
  font-size: 13px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.share-body { flex: 1; overflow: hidden; position: relative; }
.share-body iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}
.sep-toc-item {
  padding: 9px 14px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sep-toc-item:hover { background: var(--surface2); color: var(--text); }
.share-text {
  height: 100%;
  overflow-y: auto;
  padding: 32px;
  font-family: var(--font-read);
  font-size: 16px;
  line-height: 1.75;
  color: var(--text);
  max-width: 780px;
  margin: 0 auto;
}
.share-text pre {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--surface2);
  padding: 12px;
  border-radius: var(--radius);
  overflow-x: auto;
}
#shareEpubViewer {
  height: 100%;
  position: relative;
  background: var(--surface2);
}
.share-download-center {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  color: var(--text-faint);
}

/* ── Scrollbars ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ── topnav (non-reader pages via _topbar.html) ──────────────────────────── */
.topnav-ham { display: none; }
.topnav { display: contents; }
.topnav-drop {
  display: none;
  position: fixed;
  top: var(--header);
  left: 0;
  right: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-direction: column;
  z-index: 150;
  padding: 4px 0;
  box-shadow: 0 4px 12px rgba(0,0,0,.35);
}
.topnav-drop.open { display: flex; }
.topnav-drop .top-btn {
  padding: 12px 20px;
  border-radius: 0;
  font-size: 14px;
}

/* ── settings ui-toggle table ────────────────────────────────────────────── */
.ui-toggle-table { border-collapse: collapse; width: 100%; }
.ui-toggle-table th {
  font-size: 12px; font-weight: 500; color: var(--text-faint);
  padding: 6px 16px; text-align: center;
}
.ui-toggle-table th:first-child { text-align: left; padding-left: 0; }
.ui-toggle-table td {
  padding: 10px 16px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-dim); text-align: center;
}
.ui-toggle-table td:first-child { text-align: left; padding-left: 0; color: var(--text); }

/* ── toggle switch ───────────────────────────────────────────────────────── */
.rs-switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.rs-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.rs-switch-track {
  width: 36px; height: 20px; background: var(--border2); border-radius: 10px;
  transition: background .2s; position: relative; flex-shrink: 0;
}
.rs-switch-track::after {
  content: ''; position: absolute; left: 2px; top: 2px;
  width: 16px; height: 16px; background: var(--text-faint);
  border-radius: 50%; transition: left .2s, background .2s;
}
.rs-switch input:checked + .rs-switch-track { background: var(--accent, #4a8); }
.rs-switch input:checked + .rs-switch-track::after { left: 18px; background: #fff; }

/* ── mobile-nav in reader sidebar ────────────────────────────────────────── */
.mobile-nav { display: none; }

/* ── reader topnav wrapper (display:contents on desktop) ─────────────────── */
#readerTopnav { display: contents; }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
#hamburger { display: none; }

@media (max-width: 700px) {
  #hamburger { display: flex; }
  #sidebarToggle { display: none; }
  #sidebarHam { display: flex !important; }
  #topUsername { display: none; }
  .topnav-ham { display: flex; align-items: center; }
  .topnav { display: none; }
  #readerTopnav { display: none; }
  .mobile-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    background: var(--surface2);
  }
  .mobile-nav a {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-dim);
    font-size: 13px;
    padding: max(4px, var(--menu-item-spacing, 7px)) 10px;
    border-radius: var(--radius);
    text-decoration: none;
  }
  .mobile-nav a:hover { background: var(--surface3); color: var(--text); }
  .mobile-nav.no-text .nav-text { display: none; }
  .mobile-nav.no-text a { gap: 0; justify-content: center; min-width: 36px; }
  #sidebarCloseMobile { margin-left: auto; }


  #sidebar {
    position: fixed;
    inset: 0;
    width: 100vw !important;
    min-width: 0 !important;
    z-index: 200;
    transform: translateX(100%);
    transition: transform .25s ease;
  }
  #sidebar.mobile-open {
    transform: translateX(0);
  }
  #sidebar.collapsed {
    transform: translateX(100%);
    width: 100vw !important;
  }

  #readerToolbar {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header);
    overflow-x: visible;
    padding: 4px 8px;
    gap: 3px;
    align-content: flex-start;
  }
  #readerTitle { display: none; }
  #readerInfo { display: none; }
  .tb-spacer { display: none; }
  .epub-tap-zone { display: none; }
}

/* ── Mobile modal bottom-sheet ───────────────────────────────────────────── */
@media (max-width: 540px) {
  .modal-overlay {
    align-items: flex-end;
    /* overlay itself scrolls so a tall modal is never clipped */
    overflow-y: auto;
  }
  .modal {
    min-width: 0 !important;
    width: 100%;
    max-width: 100%;
    /* no max-height cap — let the sheet be as tall as its content;
       the scrollable overlay handles any overflow */
    max-height: none;
    border-radius: 12px 12px 0 0;
    padding: 20px 16px 40px;
  }
  /* share action buttons: 2-column grid so each has a full tap target */
  #shareModal .share-copy-hint > div {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  #shareModal .share-copy-hint > div .btn {
    padding: 10px 8px;
    text-align: center;
  }
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.flex { display: flex; }
.gap-6 { gap: 6px; }
.mt-8 { margin-top: 8px; }
.text-faint { color: var(--text-faint); }
.text-dim { color: var(--text-dim); }
.fs-11 { font-size: 11px; }
.fs-12 { font-size: 12px; }

/* ── Search page ─────────────────────────────────────────────────────────── */
.search-page {
  max-width: 860px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}
.search-hero { margin-bottom: 32px; }
.search-hero h1 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 18px;
}
.search-input-wrap {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.search-input-wrap input {
  flex: 1;
  font-size: 15px;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
}
.search-input-wrap input:focus { border-color: var(--border2); outline: none; }
.search-input-wrap button {
  padding: 9px 18px;
  font-size: 14px;
  border-radius: var(--radius);
  background: var(--surface3);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
}
.search-input-wrap button:hover { border-color: var(--border2); color: #fff; }
.search-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.search-chip {
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
}
.search-chip:hover { border-color: var(--border2); color: var(--text); }
.search-chip.active {
  border-color: #4a8;
  color: #4a8;
  background: #0d1f14;
}
.search-tips {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 8px;
}
.search-tips code {
  font-family: var(--font-mono);
  color: var(--text-dim);
  background: var(--surface2);
  padding: 1px 5px;
  border-radius: 3px;
}
.search-meta {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 16px;
  min-height: 20px;
}
.search-results { display: flex; flex-direction: column; gap: 10px; }
.search-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  gap: 14px;
  cursor: pointer;
  transition: border-color .15s;
}
.search-card:hover { border-color: var(--border2); }
.search-card-thumb {
  width: 52px;
  height: 72px;
  object-fit: cover;
  border-radius: 3px;
  flex-shrink: 0;
  background: var(--surface2);
}
.search-card-body { flex: 1; min-width: 0; }
.search-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-card-author {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.search-card-author a { color: var(--text-dim); }
.search-card-author a:hover { color: var(--text); }
.search-card-snippets { font-size: 12px; color: var(--text-dim); line-height: 1.55; }
.search-card-snippets mark { background: rgba(212,160,23,.28); color: inherit; border-radius: 2px; padding: 0 2px; }
.search-card-snippet + .search-card-snippet { margin-top: 4px; }
.search-card-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.search-card-score {
  font-size: 11px;
  color: var(--text-faint);
  font-family: var(--font-mono);
}
.search-load-more {
  text-align: center;
  margin-top: 24px;
}
.search-load-more button {
  padding: 8px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
}
.search-load-more button:hover { border-color: var(--border2); color: var(--text); }
.search-empty {
  text-align: center;
  padding: 60px 0;
  color: var(--text-faint);
  font-size: 14px;
}

/* ── Annotation panel items ─────────────────────────────────────────────── */
.ann-empty { font-size: 12px; color: var(--text-faint); padding: 4px 0; }
.ann-item { padding: 8px 0; border-bottom: 1px solid var(--border2); }
.ann-item:last-child { border-bottom: none; }
.ann-pos { font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.ann-pos em { font-style: italic; color: var(--text-faint); }
.ann-pos-icon { font-size: 11px; }
.ann-clickable { cursor: pointer; }
.ann-clickable:hover { color: var(--text); }
.ann-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.ann-chip { font-size: 10px; border-radius: 10px; padding: 1px 7px; border: 1px solid var(--border2); color: var(--text-dim); background: var(--surface3); }
.ann-note { font-size: 12px; color: var(--text-dim); font-style: italic; margin-top: 4px; line-height: 1.5; }
.ann-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; font-size: 10px; color: var(--text-faint); }
.ann-del { background: none; border: none; color: var(--text-faint); cursor: pointer; font-size: 11px; padding: 0 2px; }
.ann-del:hover { color: var(--error, #e55); }
#annotateBtn.active, #imgAnnotateBtn.active { background: rgba(212,168,67,.15); border-color: rgba(212,168,67,.5); color: #d4a843; }

/* ── Tag chip input ─────────────────────────────────────────────────────── */
.tag-input-wrap {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  min-height: 38px;
  cursor: text;
  position: relative;
  transition: border-color .15s;
}
.tag-input-wrap:focus-within { border-color: rgba(212,168,67,.5); }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0;
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 2px 4px 2px 9px;
  font-size: 12px;
  color: var(--text-dim);
  user-select: none;
  white-space: nowrap;
}
.tag-chip-del {
  cursor: pointer;
  color: var(--text-faint);
  font-size: 14px;
  line-height: 1;
  padding: 0 4px;
  border-radius: 0 10px 10px 0;
}
.tag-chip-del:hover { color: #e55; background: rgba(229,85,85,.1); }
.tag-input-field {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  outline: none;
  min-width: 140px;
  flex: 1;
  padding: 2px 0;
  font-family: inherit;
}
.tag-input-field::placeholder { color: var(--text-faint); font-size: 12px; }
.tag-sug-box {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: var(--surface1);
  border: 1px solid var(--border);
  border-radius: 6px;
  z-index: 500;
  max-height: 200px;
  overflow-y: auto;
  display: none;
  box-shadow: 0 6px 18px rgba(0,0,0,.45);
}
.tag-sug-item {
  padding: 8px 13px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
}
.tag-sug-item:hover, .tag-sug-item.active {
  background: var(--surface2);
  color: var(--text);
}
