/**
 * OCP Digital Critical Edition Reader Stylesheet
 * Optimized for polyglot ancient language typography, multi-pane alignment, and critical apparatus.
 */

:root {
  --bg-app: #fcfbfa;
  --bg-header: #ffffff;
  --bg-panel: #ffffff;
  --bg-panel-secondary: #f6f3ec;
  --bg-panel-hover: #f1ede4;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-gold: #b08920;
  --border-color: #e2dcce;
  --border-focus: #c59b27;
  
  --accent-gold: #c59b27;
  --accent-gold-dark: #9a7616;
  --accent-gold-light: #fdf8ec;
  --accent-navy: #0d1b2a;
  --accent-navy-light: #1b263b;
  
  --unit-hover-bg: #fff5d6;
  --unit-active-bg: #fde89c;
  --unit-variant-dot: #c59b27;
  --omission-color: #94a3b8;
  
  --font-title: 'Cinzel', Georgia, serif;
  --font-body: 'Crimson Pro', Georgia, serif;
  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'Fira Code', monospace;
  
  --font-greek: 'SBL Greek', 'Gentium Plus', 'Crimson Pro', serif;
  --font-syriac: 'Estrangelo Edessa', 'East Syriac Adiabene', 'SBL Hebrew', serif;
  --font-ethiopic: 'Abyssinica SIL', serif;
  --font-hebrew: 'SBL Hebrew', serif;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

[data-theme="dark"] {
  --bg-app: #0c1017;
  --bg-header: #141b24;
  --bg-panel: #182230;
  --bg-panel-secondary: #121924;
  --bg-panel-hover: #1f2c3e;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-gold: #f0c64c;
  --border-color: #27354a;
  --border-focus: #e5b945;
  
  --accent-gold: #e5b945;
  --accent-gold-dark: #c59b27;
  --accent-gold-light: #2a2211;
  --accent-navy: #06090e;
  --accent-navy-light: #0d141e;
  
  --unit-hover-bg: #2d2613;
  --unit-active-bg: #4a3b10;
  --unit-variant-dot: #e5b945;
  --omission-color: #64748b;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.5);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.6);
}

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

body {
  font-family: var(--font-ui);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* App Header */
.reader-header {
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-color);
  padding: 0 18px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.reader-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}
.brand-badge {
  background: linear-gradient(135deg, #1b263b, #0d1b2a);
  border: 1px solid var(--accent-gold);
  color: var(--accent-gold);
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 0.95rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.05em;
}
.doc-selector-wrapper {
  position: relative;
  min-width: 280px;
}
.doc-select {
  width: 100%;
  appearance: none;
  background: var(--bg-panel-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 7px 32px 7px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-title);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
}
.doc-select:focus {
  border-color: var(--border-focus);
}
.doc-selector-wrapper svg {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

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

.btn-header {
  background: var(--bg-panel-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn-header:hover {
  background: var(--bg-panel-hover);
  border-color: var(--border-focus);
  color: var(--accent-gold-dark);
}
[data-theme="dark"] .btn-header:hover {
  color: var(--accent-gold);
}

.btn-primary-header {
  background: var(--accent-gold);
  color: #ffffff;
  border-color: var(--accent-gold);
}
.btn-primary-header:hover {
  background: var(--accent-gold-dark);
  color: #ffffff;
}

.icon-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}
.icon-btn:hover {
  color: var(--text-main);
  border-color: var(--text-muted);
}

/* Global Navigation & Reference Bar */
.reader-navbar {
  background: var(--bg-panel-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 8px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.nav-range-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.nav-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.ref-select {
  appearance: none;
  background: var(--bg-header);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 5px 26px 5px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}
.ref-select:focus {
  border-color: var(--border-focus);
}

.nav-step-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.btn-nav-step {
  background: var(--bg-header);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}
.btn-nav-step:hover:not(:disabled) {
  border-color: var(--border-focus);
  background: var(--bg-panel-hover);
}
.btn-nav-step:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.active-range-badge {
  font-family: var(--font-title);
  font-weight: 700;
  color: var(--accent-gold-dark);
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
[data-theme="dark"] .active-range-badge {
  color: var(--accent-gold);
}

/* Parallel Panes Workspace */
.reader-workspace {
  flex: 1;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--bg-app);
  padding: 12px;
  gap: 12px;
}

.version-pane {
  flex: 1 1 0px;
  min-width: 380px;
  max-width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: border-color 0.15s ease;
}
.version-pane:hover {
  border-color: var(--border-focus);
}

/* Pane Header */
.pane-header {
  background: var(--bg-panel-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}
.pane-selectors {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  overflow: hidden;
}
.pane-select {
  appearance: none;
  background: var(--bg-header);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 4px 22px 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  max-width: 170px;
}
.pane-select:focus {
  border-color: var(--border-focus);
}

.pane-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.pane-close-btn:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

/* Upper Text Frame */
.pane-text-frame {
  flex: 3;
  overflow-y: auto;
  padding: 18px 20px;
  line-height: 1.8;
  border-bottom: 2px solid var(--border-color);
  background: var(--bg-panel);
}

.section-ref-heading {
  font-family: var(--font-title);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent-gold-dark);
  margin-top: 14px;
  margin-bottom: 6px;
  display: inline-block;
  padding: 2px 6px;
  background: var(--accent-gold-light);
  border-radius: 4px;
  letter-spacing: 0.04em;
}
[data-theme="dark"] .section-ref-heading {
  color: var(--accent-gold);
}
.section-ref-heading:first-child {
  margin-top: 0;
}

/* Interactive Text Units */
.ocp-unit {
  position: relative;
  cursor: pointer;
  border-radius: 3px;
  padding: 1px 2px;
  transition: all 0.12s ease;
  white-space: normal;
  display: inline;
}
.ocp-unit:hover {
  background-color: var(--unit-hover-bg);
}
.ocp-unit.has-variants {
  border-bottom: 1.5px dotted var(--unit-variant-dot);
}
.ocp-unit.active {
  background-color: var(--unit-active-bg);
  box-shadow: 0 0 0 2px var(--accent-gold);
}
.ocp-unit.is-omitted {
  color: var(--omission-color);
  font-size: 0.75rem;
  font-style: italic;
}

/* Ancient Script Specific Classes */
.script-greek {
  font-family: var(--font-greek);
  font-size: 1.22rem;
  line-height: 1.75;
}
.script-syriac {
  font-family: var(--font-syriac);
  font-size: 1.35rem;
  line-height: 1.9;
  direction: rtl;
  text-align: right;
}
.script-ethiopic {
  font-family: var(--font-ethiopic);
  font-size: 1.18rem;
  line-height: 1.75;
}
.script-latin {
  font-family: var(--font-body);
  font-size: 1.15rem;
  line-height: 1.7;
}
.script-aramaic, .script-hebrew {
  font-family: var(--font-hebrew);
  font-size: 1.3rem;
  line-height: 1.85;
  direction: rtl;
  text-align: right;
}

/* Lower Apparatus Frame */
.pane-apparatus-frame {
  flex: 2;
  overflow-y: auto;
  padding: 12px 16px;
  background: var(--bg-panel-secondary);
  font-size: 0.86rem;
}
.apparatus-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-color);
}
.apparatus-title {
  font-family: var(--font-title);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.apparatus-unit-badge {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  background: var(--bg-header);
  border: 1px solid var(--border-color);
  padding: 1px 6px;
  border-radius: 4px;
}

/* Collation Table */
.apparatus-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 4px;
}
.apparatus-table th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 4px 6px;
  border-bottom: 1px solid var(--border-color);
}
.apparatus-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
}
.apparatus-table tr:last-child td {
  border-bottom: none;
}
.apparatus-table tr:hover td {
  background: var(--bg-panel-hover);
}
.col-mss {
  width: 35%;
  font-weight: 600;
}
.ms-chip {
  display: inline-block;
  background: var(--bg-header);
  border: 1px solid var(--border-color);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  cursor: pointer;
  margin: 2px 2px 2px 0;
  transition: all 0.1s ease;
}
.ms-chip:hover {
  background: var(--accent-gold);
  color: #ffffff;
  border-color: var(--accent-gold);
}
.reading-text-cell {
  font-size: 1.05rem;
}
.omission-notice {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border-color);
}

/* Slide-out Drawer */
.info-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(3px);
  z-index: 1000;
  display: none;
  justify-content: flex-end;
}
.info-drawer-backdrop.open {
  display: flex;
}
.info-drawer {
  background: var(--bg-panel);
  width: 100%;
  max-width: 520px;
  height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: drawerSlide 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes drawerSlide {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
.drawer-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-panel-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.drawer-body {
  padding: 24px 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.drawer-section h4 {
  font-family: var(--font-title);
  font-size: 1.05rem;
  color: var(--text-main);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-color);
}
.drawer-section p {
  font-family: var(--font-body);
  font-size: 1.05rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* Introduction / body fields imported from the database export
   (static/docs/intros.json). The stored content is arbitrary HTML, so give
   common block elements sane spacing and colors inside the drawer. */
.intro-body-content {
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--text-muted);
  line-height: 1.6;
}
.intro-body-content p { margin: 0 0 10px; }
.intro-body-content h1, .intro-body-content h2,
.intro-body-content h3, .intro-body-content h4 {
  font-family: var(--font-title);
  color: var(--text-main);
  margin: 14px 0 6px;
}
.intro-body-content ul, .intro-body-content ol {
  margin: 0 0 10px;
  padding-left: 22px;
}
.intro-body-content li { margin-bottom: 4px; }
.intro-body-content table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
  margin-bottom: 10px;
}
.intro-body-content th, .intro-body-content td {
  border: 1px solid var(--border-color);
  padding: 5px 8px;
  text-align: left;
  vertical-align: top;
}
.intro-body-content blockquote {
  margin: 0 0 10px;
  padding-left: 12px;
  border-left: 3px solid var(--border-color);
}

/* Manuscript Tooltip Popover */
.ms-popover {
  position: absolute;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  max-width: 320px;
  font-size: 0.84rem;
  display: none;
  pointer-events: auto;
}
.ms-popover.open {
  display: block;
}
.ms-popover h5 {
  font-family: var(--font-title);
  font-size: 0.95rem;
  color: var(--accent-gold-dark);
  margin-bottom: 4px;
}
[data-theme="dark"] .ms-popover h5 {
  color: var(--accent-gold);
}
.ms-popover-meta {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 6px;
}
.ms-popover-bib {
  font-size: 0.8rem;
  line-height: 1.4;
  border-top: 1px solid var(--border-color);
  padding-top: 6px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .reader-header { height: auto; padding: 10px 14px; flex-wrap: wrap; }
  .doc-selector-wrapper { min-width: 100%; }
  .reader-navbar { flex-direction: column; align-items: stretch; }
  .version-pane { min-width: 100%; }
}
