/* ==========================================================================
   SALA LETTURA — Design System & Temi di Lettura (Giorno, Seppia, Notte)
   Ottimizzato per Desktop Windows, iPadOS (Touch & Apple Pencil) e Android
   ========================================================================== */

:root,
html[data-theme="sepia"] {
  --bg-main: #f5efe2;
  --bg-surface: #fbf7ee;
  --bg-elevated: #efe6d4;
  --bg-page: #fdf9f0;
  --text-primary: #2d2319;
  --text-secondary: #685642;
  --text-muted: #8c7862;
  --accent: #8b4513;
  --accent-hover: #6f360e;
  --accent-soft: rgba(139, 69, 19, 0.12);
  --border-color: #dfd3be;
  --shadow-sm: 0 2px 8px rgba(45, 35, 25, 0.07);
  --shadow-md: 0 8px 24px rgba(45, 35, 25, 0.12);
  --shadow-lg: 0 14px 36px rgba(45, 35, 25, 0.2);
}

html[data-theme="day"] {
  --bg-main: #f3f5f8;
  --bg-surface: #ffffff;
  --bg-elevated: #e8ecf2;
  --bg-page: #ffffff;
  --text-primary: #1a202c;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.11);
  --border-color: #dbe2ec;
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.1);
  --shadow-lg: 0 14px 36px rgba(15, 23, 42, 0.16);
}

html[data-theme="night"] {
  --bg-main: #12151c;
  --bg-surface: #1b202b;
  --bg-elevated: #252c3b;
  --bg-page: #181c26;
  --text-primary: #e4e8f0;
  --text-secondary: #a3afc2;
  --text-muted: #6f7c91;
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --accent-soft: rgba(245, 158, 11, 0.16);
  --border-color: #2d3648;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.65);
}

/* Colori semantici sottolineature (Giallo evidenziatore fluorescente realistico) */
:root {
  --hl-yellow: rgba(255, 242, 0, 0.55);
  --hl-yellow-solid: #ffeb00;
  --hl-green: rgba(74, 222, 128, 0.46);
  --hl-green-solid: #22c55e;
  --hl-blue: rgba(56, 189, 248, 0.45);
  --hl-blue-solid: #0ea5e9;
  --hl-pink: rgba(244, 114, 182, 0.45);
  --hl-pink-solid: #ec4899;
  --hl-purple: rgba(192, 132, 252, 0.45);
  --hl-purple-solid: #a855f7;

  --epub-font-family: Georgia, "Palatino Linotype", "Book Antiqua", Palatino, serif;
  --epub-font-size: 19px;
  --epub-line-height: 1.8;
}

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

html, body {
  height: 100%;
  width: 100%;
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

.view {
  display: none;
  height: 100vh;
  width: 100vw;
  flex-direction: column;
}

.view.active {
  display: flex;
}

/* ==========================================================================
   HEADER & BOTTONI COMUNI
   ========================================================================== */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 22px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  gap: 14px;
  flex-wrap: wrap;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  font-size: 28px;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand h1 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 9px;
  font-size: 0.88rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  filter: brightness(0.96);
}

.btn-ghost {
  background: transparent;
  color: var(--text-primary);
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--bg-elevated);
}

.btn-tool {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  padding: 7px 12px;
}

.btn-tool.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.btn-block {
  width: 100%;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.15s;
}

.icon-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.icon-btn.active {
  background: var(--accent);
  color: #fff;
}

.icon-btn-sm {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn-sm:hover {
  background: var(--bg-elevated);
}

/* Sync status pill */
.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  cursor: pointer;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #f59e0b;
}

.status-dot.online {
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.status-dot.offline {
  background: #3b82f6;
}

.theme-QuickSwitch {
  display: inline-flex;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 9px;
  padding: 2px;
}

.theme-chip {
  border: none;
  background: transparent;
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.theme-chip.active {
  background: var(--bg-surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   VISTA LIBRERIA (SCAFFALI & GRIGLIA LIBRI)
   ========================================================================== */

.library-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.library-sidebar {
  width: 255px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar-section h3 {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding: 0 8px;
}

.section-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.section-header-row h3 {
  margin-bottom: 0;
}

.filter-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.filter-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  background: transparent;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.filter-item:hover {
  background: var(--bg-elevated);
}

.filter-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.count-badge {
  font-size: 0.75rem;
  background: var(--bg-elevated);
  padding: 2px 7px;
  border-radius: 99px;
  color: var(--text-secondary);
}

.format-chips {
  display: flex;
  gap: 6px;
  padding: 0 4px;
}

.chip {
  flex: 1;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.sidebar-card-info {
  margin-top: auto;
  padding: 12px;
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-card-info h4 {
  font-size: 0.85rem;
}

.sidebar-card-info p {
  color: var(--text-secondary);
  line-height: 1.4;
}

.library-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px 26px;
  position: relative;
}

.library-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 240px;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  font-size: 0.95rem;
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  font-size: 0.92rem;
}

.search-box input:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

.sort-box {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.sort-box select {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  font-weight: 500;
}

/* Griglia Libri */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 20px;
  padding-bottom: 36px;
}

.book-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
  position: relative;
}

.book-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.book-cover-wrap {
  height: 235px;
  background: var(--bg-elevated);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  border-bottom: 1px solid var(--border-color);
}

.book-cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-cover-fallback {
  width: 82%;
  height: 88%;
  border-radius: 6px 12px 12px 6px;
  background: linear-gradient(135deg, #6d4c3d 0%, #3e2723 100%);
  color: #fdf8f0;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: inset 5px 0 10px rgba(0,0,0,0.25), 0 6px 16px rgba(0,0,0,0.2);
}

.book-cover-fallback.epub-cover {
  background: linear-gradient(135deg, #1e40af 0%, #1e1b4b 100%);
}

.book-cover-fallback .fallback-title {
  font-family: Georgia, serif;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-cover-fallback .fallback-author {
  font-size: 0.78rem;
  opacity: 0.85;
}

.card-badges-top {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.format-badge {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 6px;
  letter-spacing: 0.04em;
  background: #b91c1c;
  color: #fff;
}

.format-badge.epub {
  background: #1d4ed8;
}

.fav-btn {
  pointer-events: auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.48);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.fav-btn.active {
  background: #f59e0b;
}

.book-card-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.book-card-title {
  font-size: 0.96rem;
  font-weight: 700;
  line-height: 1.3;
  cursor: pointer;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-card-title:hover {
  color: var(--accent);
}

.book-card-author {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-card-tags {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.tag-chip {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.progress-row {
  margin-top: auto;
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--text-muted);
}

.progress-bar-bg {
  width: 100%;
  height: 6px;
  border-radius: 99px;
  background: var(--bg-elevated);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.25s ease;
}

.book-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-elevated);
}

.card-actions {
  display: flex;
  gap: 4px;
}

/* Stato Vuoto & Drag Overlay */
.empty-state {
  margin: auto;
  max-width: 520px;
  text-align: center;
  padding: 40px 24px;
  background: var(--bg-surface);
  border: 2px dashed var(--border-color);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.empty-illustration {
  font-size: 52px;
}

.empty-state p {
  color: var(--text-secondary);
  line-height: 1.5;
  font-size: 0.92rem;
}

.empty-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}

.drop-overlay {
  position: absolute;
  inset: 14px;
  background: rgba(139, 69, 19, 0.92);
  color: #fff;
  border-radius: 16px;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.drop-box .drop-icon {
  font-size: 54px;
  display: block;
  margin-bottom: 10px;
}

/* ==========================================================================
   VISTA LETTORE (READER) — PDF, EPUB, DISEGNO E NOTE
   ========================================================================== */

.reader-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  gap: 12px;
  z-index: 30;
}

.reader-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.reader-book-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.reader-title {
  font-size: 0.98rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-nav-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.86rem;
  font-weight: 600;
}

.page-indicator input {
  width: 54px;
  padding: 5px 6px;
  text-align: center;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  font-weight: 700;
}

.reader-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: flex-end;
}

.badge-pill {
  background: rgba(255, 255, 255, 0.25);
  padding: 1px 7px;
  border-radius: 99px;
  font-size: 0.75rem;
}

/* Barra Disegno a mano libera (PDF) */
.drawing-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 8px 16px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  z-index: 25;
}

.draw-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.draw-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.draw-tool-btn {
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.draw-tool-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.color-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s;
}

.color-dot.active {
  transform: scale(1.2);
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px var(--bg-surface);
}

/* Popover Tipografia e Temi */
.typography-popover {
  position: absolute;
  top: 56px;
  right: 110px;
  width: 290px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 14px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.popover-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.popover-section label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
}

.theme-selector-row,
.btn-group-row,
.zoom-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.theme-opt,
.font-opt,
.line-opt {
  flex: 1;
  padding: 7px 8px;
  border-radius: 7px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.theme-opt.active,
.font-opt.active,
.line-opt.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#zoomValueLabel {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 0.88rem;
}

/* Corpo del Lettore */
.reader-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

.reader-stage-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: var(--bg-main);
}

/* Menu Flottante Selezione Testo */
.selection-toolbar {
  position: fixed;
  z-index: 100;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: popIn 0.14s ease-out;
}

@keyframes popIn {
  from { opacity: 0; transform: translateY(6px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.hl-colors-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.hl-color-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.15);
  cursor: pointer;
  transition: transform 0.12s;
}

.hl-color-btn:hover,
.hl-color-btn.active {
  transform: scale(1.18);
  border-color: var(--text-primary);
}

.hl-yellow { background-color: var(--hl-yellow-solid); }
.hl-green  { background-color: var(--hl-green-solid); }
.hl-blue   { background-color: var(--hl-blue-solid); }
.hl-pink   { background-color: var(--hl-pink-solid); }
.hl-purple { background-color: var(--hl-purple-solid); }

.hl-actions-row {
  display: flex;
  gap: 6px;
  border-left: 1px solid var(--border-color);
  padding-left: 8px;
}

.hl-action-btn {
  padding: 5px 9px;
  border-radius: 7px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.hl-action-btn:hover {
  background: var(--accent);
  color: #fff;
}

/* ==========================================================================
   STAGE PDF (Canvas + Highlight Layer + Text Layer + Ink Canvas)
   ========================================================================== */

.pdf-stage {
  flex: 1;
  overflow: auto;
  display: block;
  text-align: center;
  padding: 20px 16px;
  -webkit-overflow-scrolling: touch;
}

.pdf-page-wrapper {
  position: relative;
  display: inline-block;
  text-align: left;
  background: #ffffff;
  box-shadow: var(--shadow-lg);
  border-radius: 4px;
  overflow: hidden;
  margin: 0 auto;
}

html[data-theme="sepia"] #pdfCanvas {
  filter: sepia(0.14) contrast(0.99) brightness(0.99);
}

html[data-theme="night"] #pdfCanvas {
  filter: invert(0.88) hue-rotate(180deg);
}

/* Controlli Zoom rapidi nella barra superiore del lettore */
.quick-zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 2px 4px;
}

.quick-zoom-btn {
  border: none;
  background: transparent;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.quick-zoom-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.quick-zoom-label {
  font-size: 0.78rem;
  font-weight: 700;
  min-width: 42px;
  text-align: center;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}

.quick-zoom-label:hover {
  background: var(--accent-soft);
}

#pdfCanvas {
  display: block;
}

.pdf-highlight-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.pdf-hl-rect {
  position: absolute;
  border-radius: 3px;
  mix-blend-mode: multiply;
  cursor: pointer;
  pointer-events: auto;
  transition: filter 0.12s;
}

html[data-theme="night"] .pdf-hl-rect {
  mix-blend-mode: screen;
}

.pdf-hl-rect:hover {
  outline: 2px solid var(--accent);
}

.pdf-hl-rect.hl-yellow { background: var(--hl-yellow); }
.pdf-hl-rect.hl-green  { background: var(--hl-green); }
.pdf-hl-rect.hl-blue   { background: var(--hl-blue); }
.pdf-hl-rect.hl-pink   { background: var(--hl-pink); }
.pdf-hl-rect.hl-purple { background: var(--hl-purple); }

/* Text Layer selezionabile di PDF.js */
.pdf-text-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: 1;
  z-index: 3;
  user-select: text;
  -webkit-user-select: text;
}

.pdf-text-layer span {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}

.pdf-text-layer ::selection {
  background: rgba(37, 99, 235, 0.28);
}

/* Ink Canvas per Disegno a Mano Libera (Mouse, Touch, Apple Pencil) */
.pdf-ink-canvas {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.pdf-ink-canvas.drawing-active {
  pointer-events: auto;
  touch-action: none;
  cursor: crosshair;
}

/* ==========================================================================
   STAGE EPUB (Rendering Tipografico Fluido & Sottolineature)
   ========================================================================== */

.epub-stage {
  flex: 1;
  overflow-y: auto;
  padding: 28px 20px 44px;
  -webkit-overflow-scrolling: touch;
}

.epub-content {
  max-width: 760px;
  margin: 0 auto;
  background: var(--bg-page);
  color: var(--text-primary);
  padding: 44px 52px;
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  font-family: var(--epub-font-family);
  font-size: var(--epub-font-size);
  line-height: var(--epub-line-height);
  user-select: text;
  -webkit-user-select: text;
  word-wrap: break-word;
}

.epub-content h1,
.epub-content h2,
.epub-content h3,
.epub-content h4 {
  margin-top: 1.4em;
  margin-bottom: 0.6em;
  line-height: 1.3;
  color: var(--text-primary);
}

.epub-content h1:first-child,
.epub-content h2:first-child {
  margin-top: 0;
}

.epub-content p {
  margin-bottom: 1.1em;
  text-align: justify;
}

.epub-content img,
.epub-content svg {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 18px auto;
  border-radius: 6px;
}

.epub-content blockquote {
  border-left: 4px solid var(--accent);
  padding-left: 16px;
  margin: 1.2em 0;
  color: var(--text-secondary);
  font-style: italic;
}

/* Sottolineature iniettate nel testo EPUB */
mark.epub-hl {
  padding: 2px 0;
  border-radius: 3px;
  color: inherit;
  cursor: pointer;
  transition: box-shadow 0.15s;
}

mark.epub-hl:hover {
  box-shadow: 0 0 0 2px var(--accent);
}

mark.epub-hl.hl-yellow { background-color: var(--hl-yellow); border-bottom: 2px solid var(--hl-yellow-solid); }
mark.epub-hl.hl-green  { background-color: var(--hl-green);  border-bottom: 2px solid var(--hl-green-solid); }
mark.epub-hl.hl-blue   { background-color: var(--hl-blue);   border-bottom: 2px solid var(--hl-blue-solid); }
mark.epub-hl.hl-pink   { background-color: var(--hl-pink);   border-bottom: 2px solid var(--hl-pink-solid); }
mark.epub-hl.hl-purple { background-color: var(--hl-purple); border-bottom: 2px solid var(--hl-purple-solid); }

/* Barra Inferiore Progresso Lettore */
.reader-bottom-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 20px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.reader-bottom-bar input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ==========================================================================
   PANNELLO LATERALE LETTORE (NOTE, INDICE, SEGNALIBRI)
   ========================================================================== */

.reader-sidebar {
  width: 360px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: margin-right 0.22s ease;
  z-index: 35;
}

.reader-sidebar.collapsed {
  display: none;
}

.sidebar-tabs {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-elevated);
  padding: 6px 8px;
  gap: 4px;
}

.sidebar-tab {
  flex: 1;
  padding: 7px 8px;
  border-radius: 7px;
  border: none;
  background: transparent;
  font-size: 0.79rem;
  font-weight: 600;
  cursor: pointer;
}

.sidebar-tab.active {
  background: var(--bg-surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.sidebar-tab-content {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-tab-content.active {
  display: flex;
}

.annotations-filters {
  padding: 12px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.color-filter-bar {
  display: flex;
  align-items: center;
  gap: 7px;
}

.color-filter-chip {
  height: 24px;
  min-width: 24px;
  padding: 0 8px;
  border-radius: 99px;
  border: 2px solid transparent;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}

.color-filter-chip[data-filter-color="all"] {
  background: var(--bg-elevated);
}

.color-filter-chip.active {
  border-color: var(--text-primary);
  transform: scale(1.08);
}

.annotations-filters input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 7px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  font-size: 0.82rem;
}

.annotations-list,
.toc-list,
.bookmarks-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.annotation-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-left: 5px solid var(--hl-yellow-solid);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: transform 0.12s;
}

.annotation-card:hover {
  transform: translateX(-2px);
}

.annotation-card.border-yellow { border-left-color: var(--hl-yellow-solid); }
.annotation-card.border-green  { border-left-color: var(--hl-green-solid); }
.annotation-card.border-blue   { border-left-color: var(--hl-blue-solid); }
.annotation-card.border-pink   { border-left-color: var(--hl-pink-solid); }
.annotation-card.border-purple { border-left-color: var(--hl-purple-solid); }

.ann-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.ann-location-badge {
  font-weight: 700;
  color: var(--accent);
}

.ann-quote {
  font-size: 0.84rem;
  font-style: italic;
  color: var(--text-primary);
  background: var(--bg-surface);
  padding: 6px 9px;
  border-radius: 6px;
  line-height: 1.4;
}

.ann-comment {
  font-size: 0.85rem;
  color: var(--text-primary);
  line-height: 1.45;
  white-space: pre-wrap;
}

.ann-card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.toc-item,
.bookmark-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  cursor: pointer;
  font-size: 0.86rem;
}

.toc-item:hover,
.bookmark-item:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 8px;
  background: var(--bg-surface);
}

.sidebar-footer .btn {
  flex: 1;
}

/* ==========================================================================
   MODALI & TOAST
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-card.modal-lg {
  max-width: 720px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-elevated);
}

.modal-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 75vh;
  overflow-y: auto;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  font-size: 0.92rem;
}

.note-quote-preview {
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  background: var(--bg-elevated);
  border-radius: 6px;
  font-style: italic;
  font-size: 0.86rem;
  max-height: 110px;
  overflow-y: auto;
}

.modal-color-picker {
  display: flex;
  gap: 10px;
}

.connect-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.connect-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.86rem;
}

.lan-url-box {
  padding: 10px;
  border-radius: 8px;
  background: var(--bg-surface);
  border: 1px dashed var(--accent);
  font-family: monospace;
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  color: var(--accent);
  user-select: all;
}

.compact-list {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text-secondary);
}

.backup-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
}

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--text-primary);
  color: var(--bg-surface);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  animation: popIn 0.18s ease-out;
}

/* ==========================================================================
   RESPONSIVE PER IPAD & TABLET/SMARTPHONE ANDROID
   ========================================================================== */

@media (max-width: 960px) {
  .library-layout {
    flex-direction: column;
  }

  .library-sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 12px;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    max-height: 175px;
  }

  .sidebar-card-info {
    display: none;
  }

  .reader-sidebar {
    width: 300px;
  }

  .epub-content {
    padding: 26px 22px;
  }

  .connect-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .reader-sidebar {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 310px;
    max-width: 88vw;
    box-shadow: var(--shadow-lg);
  }
}

@media (max-width: 640px) {
  .hide-sm {
    display: none;
  }

  .theme-QuickSwitch {
    display: none;
  }

  .books-grid {
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  }
}
