/* Read-on — Design System & Layout */

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

:root {
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --bg: #0a0a0f;
  --bg-soft: #16161e;
  --bg-elevated: #1c1c28;
  --bg-card: #1e1e2a;
  --text: #e8e8ed;
  --text-muted: #a0a0b0;
  --text-dim: #64647a;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --accent: #818cf8;
  --accent-2: #a78bfa;
  --accent-glow: rgba(129, 140, 248, 0.25);
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --glass: rgba(28, 28, 40, 0.8);
  --viewer-bg: #111118;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.5);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --sidebar-w: 280px;
  --toolbar-h: 48px;
  --statusbar-h: 30px;
}

[data-theme="light"] {
  --bg: #f5f5f7;
  --bg-soft: #e8e8ec;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --text: #1a1a2e;
  --text-muted: #555568;
  --text-dim: #8888a0;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);
  --glass: rgba(255, 255, 255, 0.85);
  --viewer-bg: #e0e0e6;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.15);
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

button {
  font-family: inherit;
  font-size: inherit;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
}

input {
  font-family: inherit;
  font-size: inherit;
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-soft);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  line-height: 1.3;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes cardPop {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Ambient Background */
.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.15;
  animation: orbFloat 20s ease-in-out infinite alternate;
}

.orb-1 {
  width: 600px;
  height: 600px;
  background: var(--accent);
  top: -200px;
  left: -100px;
}

.orb-2 {
  width: 500px;
  height: 500px;
  background: var(--accent-2);
  bottom: -150px;
  right: -100px;
  animation-delay: -7s;
}

.orb-3 {
  width: 350px;
  height: 350px;
  background: #38bdf8;
  top: 50%;
  left: 50%;
  animation-delay: -14s;
}

@keyframes orbFloat {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(30px, -40px) scale(1.1); }
  100% { transform: translate(-20px, 30px) scale(0.95); }
}

/* App Main Layout Grid */
.app {
  display: flex;
  flex-direction: row;
  height: 100vh;
  width: 100vw;
  position: relative;
  z-index: 1;
  overflow: hidden;
}

/* Left Sidebar (Expandable / Shrinkable / Resizable Navigation) */
.left-sidebar {
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w, 280px);
  max-width: 500px;
  min-width: 0;
  height: 100vh;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  z-index: 30;
  flex-shrink: 0;
  position: relative;
  transition: width 0.3s var(--ease), opacity 0.25s var(--ease), min-width 0.3s var(--ease);
  user-select: none;
  overflow-x: hidden;
}

.left-sidebar.resizing {
  transition: none !important;
}

/* State 2: Compact / Collapsed (56px Icon Strip) */
.left-sidebar.compact,
.left-sidebar.collapsed {
  width: 56px !important;
  min-width: 56px !important;
}

/* State 3: Fully Hidden (0px) */
.left-sidebar.hidden-sidebar {
  width: 0px !important;
  min-width: 0px !important;
  border-right: none !important;
  opacity: 0;
  pointer-events: none;
}

/* Expand tab — visible when sidebar is collapsed, anchored to left edge of main area */
.sidebar-expand-tab {
  position: absolute;
  top: 50%;
  right: -18px;
  transform: translateY(-50%);
  width: 18px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease), background 0.2s;
  color: var(--text-muted);
}

.sidebar-expand-tab:hover {
  background: var(--bg-soft);
  color: var(--accent);
}

.sidebar-expand-tab svg {
  width: 12px;
  height: 12px;
  transition: transform 0.3s var(--ease);
}

.left-sidebar.compact .sidebar-expand-tab,
.left-sidebar.collapsed .sidebar-expand-tab {
  opacity: 1;
  pointer-events: auto;
}

/* Collapse button arrow rotation */
.ls-collapse-btn {
  transition: transform 0.3s var(--ease), background 0.2s;
}

.ls-collapse-btn .collapse-arrow {
  transition: transform 0.3s var(--ease);
  display: flex;
  align-items: center;
  justify-content: center;
}

.left-sidebar.compact .ls-collapse-btn .collapse-arrow,
.left-sidebar.collapsed .ls-collapse-btn .collapse-arrow {
  transform: rotate(180deg);
}

/* Content opacity transition for smooth fade */
.ls-brand-text,
.ls-nav-btn span,
.ls-panels {
  transition: opacity 0.2s var(--ease), max-height 0.3s var(--ease);
}

.ls-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  color: var(--accent);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.02em;
  border-bottom: 1px solid var(--border);
  min-width: 0;
  overflow: hidden;
  transition: padding 0.3s var(--ease), justify-content 0.3s;
}

.ls-brand-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
}

.ls-brand-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ls-brand svg {
  flex-shrink: 0;
}

.left-sidebar.compact .ls-brand-text,
.left-sidebar.compact .ls-nav-btn span,
.left-sidebar.compact .ls-panels,
.left-sidebar.collapsed .ls-brand-text,
.left-sidebar.collapsed .ls-nav-btn span,
.left-sidebar.collapsed .ls-panels {
  display: none !important;
}

.left-sidebar.compact .ls-brand,
.left-sidebar.collapsed .ls-brand {
  justify-content: center;
  padding: 12px 4px;
}

.left-sidebar.compact .ls-collapse-btn,
.left-sidebar.collapsed .ls-collapse-btn {
  display: none !important;
}

.left-sidebar.compact .ls-nav,
.left-sidebar.collapsed .ls-nav {
  grid-template-columns: 1fr;
  gap: 6px;
  padding: 8px 4px;
}

/* Tooltip for compact nav buttons */
.left-sidebar.compact .ls-nav-btn,
.left-sidebar.collapsed .ls-nav-btn {
  position: relative;
}

.left-sidebar.compact .ls-nav-btn::after,
.left-sidebar.collapsed .ls-nav-btn::after {
  content: attr(title);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%) scale(0.9);
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  z-index: 100;
  transition: opacity 0.15s, transform 0.15s var(--ease-spring);
  box-shadow: var(--shadow);
}

.left-sidebar.compact .ls-nav-btn:hover::after,
.left-sidebar.collapsed .ls-nav-btn:hover::after {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

/* Sidebar Resizer Handle */
.ls-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 100;
  transition: background 0.2s ease;
}

.ls-resizer:hover, .ls-resizer.resizing {
  background: var(--accent);
}

.ls-nav {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
  min-width: 0;
  overflow: hidden;
}

.ls-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px;
  border-radius: var(--radius);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.2s var(--ease);
  min-width: 0;
  overflow: hidden;
}

.ls-nav-btn span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.ls-nav-btn:hover {
  background: var(--bg-elevated);
  color: var(--text);
}

.ls-nav-btn.active {
  background: linear-gradient(135deg, rgba(129, 140, 248, 0.2), rgba(167, 139, 250, 0.15));
  color: var(--accent);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(129, 140, 248, 0.3);
}

.ls-nav-btn svg {
  flex-shrink: 0;
  opacity: 0.8;
}

.ls-nav-btn.active svg {
  opacity: 1;
}

.ls-panels {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

.ls-panel {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  padding: 14px;
  gap: 12px;
}

.ls-panel.active {
  display: flex;
}

.ls-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 2px 8px;
}

.ls-panel-header h3 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.btn-icon-sm {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  transition: background 0.2s;
  color: var(--text-muted);
}

.btn-icon-sm:hover {
  background: var(--bg-soft);
  color: var(--text);
}

/* Shelf List in Sidebar */
.shelf-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.shelf-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  animation: fadeIn 0.3s var(--ease) both;
}

.shelf-item:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.shelf-item.active {
  background: rgba(129, 140, 248, 0.12);
  border-color: var(--accent);
}

.shelf-thumb {
  width: 36px;
  height: 48px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg);
  flex-shrink: 0;
}

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

.shelf-item-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.shelf-item-title {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.shelf-item-meta {
  font-size: 10px;
  color: var(--text-dim);
  display: flex;
  gap: 6px;
}

.shelf-item-progress {
  height: 3px;
  border-radius: 3px;
  background: var(--bg);
  overflow: hidden;
  margin-top: 2px;
}

.shelf-item-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.3s;
}

.shelf-item-remove {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 0.2s;
  color: var(--text-dim);
  flex-shrink: 0;
}

.shelf-item:hover .shelf-item-remove {
  opacity: 1;
}

.shelf-item-remove:hover {
  background: rgba(248, 113, 113, 0.2);
  color: var(--danger);
}

.shelf-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 40px 16px;
  color: var(--text-dim);
}

.shelf-empty p {
  font-size: 13px;
  font-weight: 500;
}

.shelf-empty span {
  font-size: 11px;
  opacity: 0.7;
}

/* Reading Panel */
.reading-empty {
  text-align: center;
  padding: 24px 8px;
  color: var(--text-dim);
}

.reading-empty p {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
}

.reading-empty span {
  font-size: 11px;
  opacity: 0.7;
}

.reading-active {
  display: flex;
  gap: 12px;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

.reading-cover {
  width: 50px;
  height: 66px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg);
  flex-shrink: 0;
}

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

.reading-details {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.reading-details h4 {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reading-meta {
  font-size: 10px;
  color: var(--text-dim);
  display: flex;
  gap: 6px;
}

.reading-progress-bar {
  height: 3px;
  border-radius: 3px;
  background: var(--bg);
  overflow: hidden;
  margin-top: 4px;
}

.reading-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.3s;
}

.reading-progress-text {
  font-size: 10px;
  color: var(--text-dim);
}

/* Thumbnails */
.thumbs-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.thumb:hover {
  background: var(--bg-soft);
}

.thumb.active {
  background: rgba(129, 140, 248, 0.15);
  outline: 1.5px solid var(--accent);
}

.thumb canvas {
  width: 100%;
  border-radius: 4px;
  background: #fff;
}

.thumb-label {
  font-size: 10px;
  color: var(--text-dim);
}

/* Bookmarks Panel */
.bookmarks-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bookmark-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s;
  animation: fadeIn 0.3s var(--ease) both;
}

.bookmark-item:hover {
  border-color: var(--accent);
}

.bm-page {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  min-width: 32px;
}

.bm-label {
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bm-remove {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 0.2s;
  color: var(--text-dim);
}

.bookmark-item:hover .bm-remove {
  opacity: 1;
}

.bm-remove:hover {
  background: rgba(248, 113, 113, 0.2);
  color: var(--danger);
}

.empty-hint {
  font-size: 12px;
  color: var(--text-dim);
  padding: 16px 4px;
  text-align: center;
}

/* Settings Panel */
.settings-group {
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}

.settings-group:last-child {
  border-bottom: none;
}

.settings-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.setting-buttons-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.setting-option-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--bg-soft);
  transition: all 0.2s ease;
  user-select: none;
}

.setting-option-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--bg-elevated);
}

.setting-option-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(129, 140, 248, 0.15);
  font-weight: 600;
  box-shadow: 0 0 12px rgba(129, 140, 248, 0.1);
}

.theme-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  display: inline-block;
  flex-shrink: 0;
}

.dark-swatch { background: #1c1c28; }
.light-swatch { background: #f5f5f7; }
.system-swatch { background: linear-gradient(135deg, #1c1c28 50%, #f5f5f7 50%); }

.setting-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-label-inline {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 20px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--bg-soft);
  border: 1px solid var(--border-strong);
  transition: .3s;
  border-radius: 20px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text-muted);
  transition: .3s;
  border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--accent);
  border-color: var(--accent);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(18px);
  background-color: #ffffff;
}

.setting-actions-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-secondary-sm, .btn-danger-sm {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
  transition: all 0.2s ease;
}

.btn-secondary-sm {
  background: var(--bg-soft);
  color: var(--text-muted);
}
.btn-secondary-sm:hover {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-danger-sm {
  background: rgba(248, 113, 113, 0.1);
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.25);
}
.btn-danger-sm:hover {
  background: rgba(248, 113, 113, 0.2);
  border-color: var(--danger);
}

.shortcuts-mini {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.shortcuts-mini span {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-dim);
}

/* Main Area (Header Toolbar + Viewer + Footer Statusbar) */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
  position: relative;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--toolbar-h);
  padding: 0 14px;
  gap: 8px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  z-index: 20;
  flex-shrink: 0;
}

.toolbar-left, .toolbar-center, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-left {
  flex: 1;
}

.toolbar-center {
  flex: 1;
  justify-content: center;
}

.toolbar-right {
  flex: 1;
  justify-content: flex-end;
}

.toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  transition: background 0.15s, color 0.15s;
  color: var(--text-muted);
}

.btn-icon:hover:not(:disabled) {
  background: var(--bg-soft);
  color: var(--text);
}

.btn-icon:disabled {
  opacity: 0.35;
  cursor: default;
}

.btn-icon.active {
  background: rgba(129, 140, 248, 0.15);
  color: var(--accent);
}

#btn-bookmark-toggle.active {
  background: rgba(251, 191, 36, 0.18);
  color: #fbbf24;
}

#btn-bookmark-toggle.active svg {
  fill: #fbbf24;
}

.page-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.page-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.page-input {
  width: 40px;
  text-align: center;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 3px 4px;
  font-size: 12px;
}

.page-input:focus {
  outline: none;
  border-color: var(--accent);
}

.page-sep {
  opacity: 0.5;
}

.zoom-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.zoom-label {
  font-size: 11px;
  color: var(--text-dim);
  min-width: 44px;
  text-align: center;
  font-weight: 500;
}

.tool-mode {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tool-label {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: 4px;
  font-weight: 500;
}

/* Search Bar */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  animation: fadeIn 0.2s;
}

.search-bar[hidden] {
  display: none;
}

.search-input {
  flex: 1;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  color: var(--text);
  font-size: 13px;
  min-width: 0;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.search-case-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
}

.search-count {
  font-size: 11px;
  color: var(--text-dim);
  min-width: 40px;
  text-align: center;
}

/* Viewer Container */
.viewer-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--viewer-bg);
}

.welcome-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 5;
  animation: cardPop 0.5s var(--ease-spring);
}

.welcome-state.hidden {
  display: none !important;
}

.welcome-icon {
  color: var(--accent);
  opacity: 0.7;
}

.welcome-state h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.welcome-state p {
  color: var(--text-muted);
  max-width: 340px;
  text-align: center;
  line-height: 1.5;
}

.btn-primary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  box-shadow: 0 4px 16px var(--accent-glow);
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px var(--accent-glow);
}

.viewer {
  position: absolute;
  inset: 0;
  overflow: auto;
  scroll-behavior: auto;
}

.pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px 0 60px;
}

.page-shell {
  position: relative;
  background: #fff;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
  border-radius: 2px;
  overflow: hidden;
  transform-origin: center top;
}

.page-shell canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: -webkit-optimize-contrast;
}

.text-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: 1;
  opacity: 0.3;
}

.text-layer span {
  position: absolute;
  white-space: pre;
  color: transparent;
  pointer-events: auto;
}

.text-layer ::selection {
  background: rgba(129, 140, 248, 0.35);
}

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

.annotation-layer.active {
  pointer-events: auto;
  cursor: crosshair;
}

.annotation-layer canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.highlight {
  background: rgba(251, 191, 36, 0.35);
  border-radius: 2px;
}

.highlight.current {
  background: rgba(251, 191, 36, 0.6);
  outline: 2px solid #fbbf24;
}

/* Reading Theme Styles */
[data-reading-theme="sepia"] .page-shell canvas.page-canvas {
  filter: sepia(0.35) brightness(1.02);
}
[data-reading-theme="sepia"] .page-shell {
  background: #fbf0d9;
}

[data-reading-theme="warm"] .page-shell canvas.page-canvas {
  filter: sepia(0.18) saturate(1.2) brightness(1.02);
}
[data-reading-theme="warm"] .page-shell {
  background: #f4ecd8;
}

[data-reading-theme="night"] .page-shell canvas.page-canvas {
  filter: invert(0.9) hue-rotate(180deg);
}
[data-reading-theme="night"] .page-shell {
  background: #18181b;
}

[data-reading-theme="paper"] .page-shell canvas.page-canvas {
  filter: sepia(0.08) brightness(0.97) contrast(1.05);
}
[data-reading-theme="paper"] .page-shell {
  background: #f7f5ee;
}

[data-reading-theme="eyecare"] .page-shell canvas.page-canvas {
  filter: sepia(0.2) hue-rotate(60deg) brightness(0.98);
}
[data-reading-theme="eyecare"] .page-shell {
  background: #e8f3e8;
}

/* Cursor modes */
.viewer.hand-tool { cursor: grab; }
.viewer.hand-tool.panning { cursor: grabbing; }
.viewer.pen-tool { cursor: crosshair; }
.viewer.highlight-tool { cursor: crosshair; }

/* Loading State */
.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: color-mix(in srgb, var(--viewer-bg) 85%, transparent);
  backdrop-filter: blur(6px);
  z-index: 10;
  animation: fadeIn 0.25s;
}

.loading[hidden] {
  display: none !important;
}

.loader {
  position: relative;
  width: 56px;
  height: 56px;
}

.loader-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}

.loader-ring:nth-child(2) {
  inset: 6px;
  border-top-color: var(--accent-2);
  animation-duration: 1.4s;
  animation-direction: reverse;
}

.loader-ring:nth-child(3) {
  inset: 12px;
  border-top-color: #38bdf8;
  animation-duration: 0.9s;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#loading-text {
  color: var(--text-muted);
  font-weight: 500;
}

.progress-track {
  width: 200px;
  height: 4px;
  border-radius: 999px;
  background: var(--bg-soft);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.25s;
  box-shadow: 0 0 12px var(--accent-glow);
}

/* Status Bar */
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  height: var(--statusbar-h);
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  z-index: 20;
  flex-shrink: 0;
}

.status-left, .status-right, .status-center {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.status-left { flex: 1; }
.status-center { flex: 1; justify-content: center; }
.status-right { flex: 1; justify-content: flex-end; }

.doc-name {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-weight: 500;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  flex-shrink: 0;
}

.status-dot.busy {
  background: var(--warning);
  box-shadow: 0 0 8px var(--warning);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.status-sep {
  opacity: 0.4;
}

.scroll-progress {
  width: min(200px, 30vw);
  height: 3px;
  border-radius: 999px;
  background: var(--bg-soft);
  overflow: hidden;
}

.scroll-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.15s linear;
}

/* Drag & Drop Overlay */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  animation: fadeIn 0.2s;
}

.drop-overlay[hidden] {
  display: none !important;
}

.drop-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 56px;
  border-radius: var(--radius-xl);
  border: 2px dashed var(--accent);
  background: var(--bg-elevated);
  color: var(--text);
  animation: cardPop 0.35s var(--ease-spring);
}

.drop-card svg { color: var(--accent); }
.drop-card h2 { font-size: 22px; font-weight: 700; }
.drop-card p { color: var(--text-muted); }

/* Color Palette Popup */
.color-palette {
  position: fixed;
  z-index: 50;
  display: flex;
  gap: 6px;
  padding: 8px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: cardPop 0.25s var(--ease-spring);
}

.color-palette[hidden] {
  display: none !important;
}

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--c);
  border: 2px solid transparent;
  transition: transform 0.15s, box-shadow 0.15s;
}

.swatch:hover { transform: scale(1.15); }
.swatch.active {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--bg-elevated), 0 0 0 4px var(--c);
}

/* Toast Notifications */
.toasts {
  position: fixed;
  bottom: 48px;
  right: 16px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  animation: toastIn 0.35s var(--ease-spring) both;
  max-width: 320px;
}

.toast.out { animation: toastOut 0.3s var(--ease) both; }
.toast.success { border-left: 3px solid var(--success); }
.toast.info { border-left: 3px solid var(--accent); }
.toast.warning { border-left: 3px solid var(--warning); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px) scale(0.95); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateX(30px) scale(0.95); }
}

/* Scrollbars */
.viewer::-webkit-scrollbar, .ls-panel::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.viewer::-webkit-scrollbar-track, .ls-panel::-webkit-scrollbar-track {
  background: transparent;
}

.viewer::-webkit-scrollbar-thumb, .ls-panel::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

/* Print Overrides */
@media print {
  .ambient, .toolbar, .search-bar, .left-sidebar, .statusbar, .drop-overlay, .toasts, .color-palette, .loading, .welcome-state {
    display: none !important;
  }
  .app, .main-area, .viewer-wrap, .viewer {
    height: auto !important;
    overflow: visible !important;
  }
  .pages { padding: 0; gap: 0; }
  .page-shell { box-shadow: none; break-after: page; margin: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
