
/* ==========================================================================
   SahajPatra PDF Study Desk — Complete Stylesheet (app.css)
   Scholarly Warm Library Light Theme + Slate Dark Theme + Responsive Mobile Dock
   ========================================================================== */

:root {
  --bg-app: #F6F3EC;
  --bg-surface: #FFFFFF;
  --bg-elevated: #FAF8F3;
  --bg-canvas: #E6E1D6;
  --bg-subtle: #EFECE4;
  --text-primary: #18202C;
  --text-secondary: #475569;
  --text-muted: #64748B;
  --border-color: #DDD6C7;
  --border-strong: #C5BBAE;
  --accent-primary: #B84A27;
  --accent-primary-hover: #9A3B1C;
  --accent-secondary: #1E3A8A;
  --accent-soft: #FDECE6;
  --accent-blue-soft: #DBEAFE;
  --success-color: #15803D;
  --success-bg: #DCFCE7;
  --warning-color: #B45309;
  --warning-bg: #FEF3C7;
  --danger-color: #B91C1C;
  --danger-bg: #FEE2E2;
  --shadow-sm: 0 1px 3px rgba(24, 32, 44, 0.08);
  --shadow-md: 0 4px 14px rgba(24, 32, 44, 0.10);
  --shadow-lg: 0 12px 32px rgba(24, 32, 44, 0.16);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font-sans: "Inter", "Noto Sans Devanagari", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: "Merriweather", "Noto Serif Devanagari", Georgia, serif;
}

[data-theme="dark"] {
  --bg-app: #0F141C;
  --bg-surface: #171F2C;
  --bg-elevated: #1E293B;
  --bg-canvas: #090D12;
  --bg-subtle: #243044;
  --text-primary: #F1F5F9;
  --text-secondary: #CBD5E1;
  --text-muted: #94A3B8;
  --border-color: #2D3B4E;
  --border-strong: #3E5068;
  --accent-primary: #E06D44;
  --accent-primary-hover: #F0825B;
  --accent-secondary: #60A5FA;
  --accent-soft: rgba(224, 109, 68, 0.18);
  --accent-blue-soft: rgba(96, 165, 250, 0.18);
  --success-color: #4ADE80;
  --success-bg: rgba(21, 128, 61, 0.25);
  --warning-color: #FBBF24;
  --warning-bg: rgba(180, 83, 9, 0.25);
  --danger-color: #F87171;
  --danger-bg: rgba(185, 28, 28, 0.25);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.65);
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
}

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent-secondary);
  outline-offset: 1px;
}

/*App Shell Layout*/
.study-desk-app {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/*Top Brand & Document Status Bar*/
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  min-height: 46px;
  flex-shrink: 0;
  z-index: 30;
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent-primary), #8F3214);
  color: #FFFFFF;
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.brand-titles {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-meta-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.save-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--success-bg);
  color: var(--success-color);
}

.save-badge.save-failed {
  background: var(--danger-bg);
  color: var(--danger-color);
}

.save-badge.save-pending {
  background: var(--warning-bg);
  color: var(--warning-color);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/*Buttons & Controls*/
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.08s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

.btn.active, .tool-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

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

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

.btn-secondary {
  background: var(--accent-secondary);
  border-color: var(--accent-secondary);
  color: #FFFFFF;
}

.btn-danger {
  background: var(--danger-bg);
  border-color: var(--danger-color);
  color: var(--danger-color);
}

.btn-icon {
  padding: 5px 7px;
  min-width: 30px;
  min-height: 30px;
}

/*Primary Annotation Toolbar*/
.main-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 10px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
  z-index: 25;
}

.main-toolbar::-webkit-scrollbar {
  display: none;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.toolbar-divider {
  width: 1px;
  height: 22px;
  background: var(--border-color);
  margin: 0 3px;
  flex-shrink: 0;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.tool-btn:hover {
  background: var(--bg-subtle);
  border-color: var(--border-color);
}

/*Secondary Context & Navigation Sub-Toolbar*/
.sub-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  font-size: 12px;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
  z-index: 20;
}

.sub-toolbar::-webkit-scrollbar {
  display: none;
}

.style-controls, .page-nav-controls, .view-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.color-swatch {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.18);
}

.color-swatch.active {
  border-color: var(--text-primary);
  transform: scale(1.14);
}

.compact-select, .compact-input {
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  font-size: 12px;
  height: 26px;
}

.page-num-input {
  width: 46px;
  text-align: center;
}

/*Search Bar Drawer*/
.search-bar-strip {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-color);
  font-size: 12px;
  flex-shrink: 0;
  z-index: 19;
}

.search-bar-strip.open {
  display: flex;
  flex-wrap: wrap;
}

/*Main 3-Column Study Workspace*/
.workspace-body {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

/*Left Panel (Thumbnails, Chapters/TOC, Bookmarks)*/
.left-panel {
  width: 240px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: margin-left 0.2s ease;
  z-index: 15;
}

.left-panel.collapsed {
  display: none;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.panel-tab {
  flex: 1;
  padding: 8px 4px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
}

.panel-tab.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
  background: var(--bg-surface);
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.thumb-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px;
  margin-bottom: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  cursor: pointer;
}

.thumb-card.active {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.thumb-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 6px;
}

.thumb-actions {
  display: flex;
  gap: 2px;
}

.thumb-actions button {
  padding: 2px 5px;
  font-size: 10px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
}

/*Central Stage (Empty Dropzone + PDF Viewport + Optional Split View)*/
.center-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-canvas);
  position: relative;
}

.split-stage-container {
  flex: 1;
  display: flex;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.pdf-viewport-scroll {
  flex: 1;
  overflow: auto;
  padding: 20px 16px 80px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  position: relative;
}

.pdf-viewport-scroll.spread-mode {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
}

/*Comparison Split View Second Pane (Section 14)*/
.comparison-pane {
  display: none;
  flex: 1;
  flex-direction: column;
  border-left: 2px solid var(--border-strong);
  background: var(--bg-canvas);
  min-width: 0;
}

.comparison-pane.open {
  display: flex;
}

.comparison-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  font-size: 12px;
}

/*PDF Page Container & Layers*/
.pdf-page-wrapper {
  position: relative;
  background: #FFFFFF;
  box-shadow: var(--shadow-md);
  border-radius: 3px;
  flex-shrink: 0;
  user-select: none;
  transition: filter 0.2s ease;
}

/*Page Comfort Filters (Section 30) — Only affects visual display, never modifies PDF export*/
.pdf-page-wrapper[data-comfort="sepia"] .pdf-render-canvas {
  filter: sepia(0.38) contrast(0.95) brightness(0.97);
}
.pdf-page-wrapper[data-comfort="grey"] .pdf-render-canvas {
  filter: grayscale(0.85) contrast(0.94) brightness(0.95);
}
.pdf-page-wrapper[data-comfort="dim"] .pdf-render-canvas {
  filter: brightness(0.84) contrast(0.96);
}
.pdf-page-wrapper[data-comfort="invert"] .pdf-render-canvas {
  filter: invert(0.88) hue-rotate(180deg);
}

.pdf-render-canvas {
  display: block;
  pointer-events: none;
}

.textLayer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: 1;
  user-select: text;
  -webkit-user-select: text;
  z-index: 2;
}

/*When an ink/shape/eraser tool is active, let pointer events pass straight to the annotation canvas*/
.pdf-page-wrapper.drawing-mode .textLayer {
  pointer-events: none;
  user-select: none;
}

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

.pdf-text-span::selection {
  background: rgba(59, 130, 246, 0.28);
}

.pdf-search-match {
  background: rgba(250, 204, 21, 0.42);
  border-bottom: 2px solid #CA8A04;
  border-radius: 2px;
}

.pdf-search-match-active {
  background: rgba(249, 115, 22, 0.55);
  outline: 2px solid #EA580C;
}

.pdf-annot-canvas {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  touch-action: none;
}

.pdf-page-wrapper.drawing-mode .pdf-annot-canvas,
.pdf-page-wrapper.select-mode .pdf-annot-canvas {
  pointer-events: auto;
}

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

.pdf-widget-layer > * {
  pointer-events: auto;
}

.page-badge-footer {
  position: absolute;
  bottom: -22px;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary);
  padding: 0 4px;
}

.scanned-page-pill {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  background: rgba(15, 23, 42, 0.82);
  color: #F8FAFC;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  pointer-events: none;
}

.existing-annot-pin {
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  background: #FEF08A;
  border: 1.5px solid #CA8A04;
  color: #713F12;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

/*Floating Text Selection Quick Action Bar (Section 08A & 12)*/
.selection-quick-bar {
  position: fixed;
  display: none;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 60;
}

.selection-quick-bar.visible {
  display: flex;
}

/*Reading Ruler / Line Focus Guide (Section 13)*/
.reading-ruler-overlay {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  height: 38px;
  background: rgba(250, 204, 21, 0.16);
  border-top: 1.5px solid rgba(202, 138, 4, 0.65);
  border-bottom: 1.5px solid rgba(202, 138, 4, 0.65);
  pointer-events: none;
  z-index: 40;
}

.reading-ruler-overlay.active {
  display: block;
}

/*Empty / Upload Dropzone State (Section 03 & 04)*/
.empty-upload-card {
  max-width: 680px;
  width: 100%;
  margin: auto;
  padding: 24px;
  background: var(--bg-surface);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  text-align: center;
}

.empty-upload-card.drag-over {
  border-color: var(--accent-primary);
  background: var(--accent-soft);
}

.sample-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
  margin-top: 14px;
  text-align: left;
}

.sample-card {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease;
}

.sample-card:hover {
  border-color: var(--accent-primary);
  transform: translateY(-1px);
}

/*Right Study Notes & Annotations Panel (Section 11, 12, 37)*/
.right-panel {
  width: 340px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 15;
}

.right-panel.wide-notes {
  width: 480px;
}

.right-panel.collapsed {
  display: none;
}

.note-card, .annot-item-card {
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  margin-bottom: 8px;
  font-size: 12px;
}

.note-quote-block {
  margin: 6px 0;
  padding: 6px 8px;
  border-left: 3px solid var(--accent-primary);
  background: var(--bg-surface);
  font-style: italic;
  color: var(--text-secondary);
  border-radius: 0 4px 4px 0;
}

.inline-page-ref {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--accent-blue-soft);
  color: var(--accent-secondary);
  border: none;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
}

/*Modals & Toasts*/
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-backdrop.open {
  display: flex;
}

.modal-dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 520px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 18px 20px;
  box-shadow: var(--shadow-lg);
}

.toast-container {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 120;
  max-width: 340px;
}

.toast-item {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border-left: 4px solid var(--accent-primary);
  box-shadow: var(--shadow-lg);
  font-size: 12px;
  font-weight: 600;
}

/*Focus / Distraction-Free Mode*/
.study-desk-app.focus-mode .top-header,
.study-desk-app.focus-mode .left-panel,
.study-desk-app.focus-mode .right-panel {
  display: none !important;
}

/*Mobile Bottom Dock (<= 768px) (Section 27 & 32)*/
.mobile-bottom-dock {
  display: none;
  align-items: center;
  justify-content: space-around;
  padding: 6px 8px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 35;
}

@media (max-width: 900px) {
  .left-panel {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 260px;
    box-shadow: var(--shadow-lg);
  }
  .right-panel, .right-panel.wide-notes {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    width: min(340px, 92vw);
    box-shadow: var(--shadow-lg);
  }
}

@media (max-width: 640px) {
  .top-header {
    padding: 5px 8px;
  }
  .brand-h1 {
    font-size: 12px;
  }
  .hide-on-mobile {
    display: none !important;
  }
  .mobile-bottom-dock {
    display: flex;
  }
  .pdf-viewport-scroll {
    padding: 10px 6px 64px 6px;
  }
}

