/* =========================================================================
   Document Viewer Panels — Spec v0.8.0 §6.3.4
   Shared CSS for PDF, EPUB, and Markdown viewer modals.
   Loaded in both admin (Article Editor) and front-end (CVV) contexts.
   ========================================================================= */

/* --- Overlay & panel --- */

/* Prevent background scrolling while a viewer is open */
body.ot-viewer-body-lock {
  overflow: hidden !important;
}

.ot-viewer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100050;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.ot-viewer-panel {
  background: #fff;
  border-radius: 12px;
  box-shadow:
    0 4px 6px rgba(0, 0, 0, 0.07),
    0 12px 40px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  max-width: 90vw;
  max-height: 90vh;
  width: 900px;
  height: 80vh;
  overflow: hidden;
  position: relative;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
}

/* --- Custom resize handles --- */
.ot-resize-handle {
  position: absolute;
  z-index: 10;
}
.ot-resize-handle-n { top: -3px; left: 6px; right: 6px; height: 6px; cursor: ns-resize; }
.ot-resize-handle-s { bottom: -3px; left: 6px; right: 6px; height: 6px; cursor: ns-resize; }
.ot-resize-handle-w { left: -3px; top: 6px; bottom: 6px; width: 6px; cursor: ew-resize; }
.ot-resize-handle-e { right: -3px; top: 6px; bottom: 6px; width: 6px; cursor: ew-resize; }
.ot-resize-handle-nw { top: -3px; left: -3px; width: 10px; height: 10px; cursor: nwse-resize; }
.ot-resize-handle-ne { top: -3px; right: -3px; width: 10px; height: 10px; cursor: nesw-resize; }
.ot-resize-handle-sw { bottom: -3px; left: -3px; width: 10px; height: 10px; cursor: nesw-resize; }
.ot-resize-handle-se { bottom: -3px; right: -3px; width: 10px; height: 10px; cursor: nwse-resize; }

/* --- Title bar --- */
.ot-viewer-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: linear-gradient(135deg, #1e1e2e, #2d2d44);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.ot-viewer-title {
  font-weight: 600;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.9);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
  letter-spacing: 0.2px;
}

.ot-viewer-title-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.ot-viewer-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  color: rgba(255, 255, 255, 0.65);
  text-decoration: none;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 6px;
  margin-right: 8px;
  transition: color 150ms, background 150ms;
}
.ot-viewer-download svg {
  width: 16px;
  height: 16px;
}
.ot-viewer-download:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}
.ot-viewer-download:focus {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 1px;
}

.ot-viewer-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.65);
  padding: 0;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: color 150ms, background 150ms;
}
.ot-viewer-close:hover {
  color: #fff;
  background: rgba(220, 53, 56, 0.8);
}
.ot-viewer-close:focus {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
  border-radius: 6px;
}

/* --- Toolbar (PDF page nav, zoom, search) --- */
.ot-viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.ot-viewer-content {
  flex: 1;
  overflow: auto;
  padding: 16px;
  position: relative;
  background: #f5f5f3;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.04);
}

/* Custom scrollbar for webkit browsers */
.ot-viewer-content::-webkit-scrollbar {
  width: 8px;
}
.ot-viewer-content::-webkit-scrollbar-track {
  background: transparent;
}
.ot-viewer-content::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
}
.ot-viewer-content::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

.ot-viewer-page-input {
  width: 50px;
  text-align: center;
  font-size: 13px;
  padding: 4px 6px;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  background: #fff;
}

.ot-viewer-page-total {
  font-size: 13px;
  color: #646970;
  margin-right: 4px;
}

.ot-viewer-zoom-label {
  font-size: 12px;
  color: #646970;
  min-width: 40px;
  text-align: center;
}

.ot-viewer-sep {
  color: #dcdcde;
  margin: 0 2px;
}

.ot-viewer-search-input {
  font-size: 13px;
  padding: 4px 8px;
  width: 140px;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  background: #fff;
  transition: border-color 150ms, box-shadow 150ms;
}
.ot-viewer-search-input:focus {
  border-color: #2271b1;
  box-shadow: 0 0 0 2px rgba(34, 113, 177, 0.15);
  outline: none;
}

.ot-viewer-search-notice {
  padding: 6px 10px;
  font-size: 12px;
  color: #135e96;
  background: #f0f6fc;
  border: 1px solid #c3d4e0;
  margin-bottom: 8px;
  border-radius: 3px;
}
.ot-viewer-search-not-found {
  color: #996800;
  background: #fcf9e8;
  border-color: #dba617;
}

/* --- PDF viewer --- */
.ot-viewer-pdf-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.ot-viewer-pdf-canvas {
  max-width: 100%;
  height: auto;
  display: block;
}

.ot-viewer-pdf-page-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  box-sizing: border-box;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.08),
    0 4px 12px rgba(0, 0, 0, 0.04);
}

.ot-viewer-pdf-placeholder {
  color: #999;
  font-size: 14px;
}

.ot-viewer-search-count {
  font-size: 12px;
  color: #646970;
  margin: 0 4px;
  white-space: nowrap;
}

/* --- EPUB viewer --- */
.ot-epub-wrapper {
  display: flex;
  height: 100%;
  gap: 0;
}

.ot-epub-toc {
  width: 240px;
  border-right: 1px solid #e9ecef;
  padding: 16px;
  overflow-y: auto;
  flex-shrink: 0;
  background: #f8f9fa;
}
.ot-epub-toc h3 {
  font-size: 11px;
  margin: 0 0 12px;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 700;
}
.ot-epub-toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.ot-epub-toc-list li {
  margin: 1px 0;
}
.ot-epub-toc-list a {
  font-size: 13px;
  color: #495057;
  text-decoration: none;
  display: block;
  padding: 6px 10px;
  border-radius: 6px;
  transition: background 120ms, color 120ms;
  line-height: 1.4;
}
.ot-epub-toc-list a:hover {
  background: #e9ecef;
  color: #1d2327;
}
.ot-epub-toc-list ul {
  list-style: none;
  margin: 0;
  padding-left: 14px;
}

.ot-epub-reader {
  flex: 1;
  min-width: 0;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  background: #fafaf8;
  position: relative;
}

/* Paginated mode uses epub.js flow:'paginated'; page-block styling below
   enhances the visual separation when spread is disabled */

/* Paginated: sections styled as discrete page blocks with shadow/border */
.ot-epub-reader.ot-epub-paginated .epub-container > * {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.08),
    0 4px 12px rgba(0, 0, 0, 0.04);
  margin-bottom: 20px;
  box-sizing: border-box;
}
.ot-epub-reader.ot-epub-paginated .epub-container > *:last-child {
  margin-bottom: 0;
}

/* Reflowable mode: visible separators between spine items (epub.js views) */
.ot-epub-reader:not(.ot-epub-paginated) .epub-container > * {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid #e0e0e0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
.ot-epub-reader:not(.ot-epub-paginated) .epub-container > *:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
  box-shadow: none;
}

/* EPUB loading overlay */
.ot-epub-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(250, 250, 248, 0.92);
  z-index: 10;
  font-size: 14px;
  color: #555;
  transition: opacity 0.3s ease;
}
.ot-epub-loading .ot-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #ddd;
  border-top-color: #2271b1;
  border-radius: 50%;
  animation: ot-spin 0.8s linear infinite;
}
.ot-epub-loading--hidden {
  opacity: 0;
  pointer-events: none;
}
@keyframes ot-spin {
  to { transform: rotate(360deg); }
}

/* EPUB page indicator (paginated mode) */
.ot-epub-page-indicator {
  font-size: 12px;
  color: #6c757d;
  padding: 4px 10px;
  background: #f0f0f0;
  border-radius: 4px;
  margin-left: auto;
  white-space: nowrap;
  user-select: none;
}

/* --- Markdown viewer --- */
.ot-md-notice {
  padding: 8px 14px;
  font-size: 13px;
  color: #996800;
  background: #fcf9e8;
  border: 1px solid #dba617;
  border-radius: 4px;
  margin-bottom: 12px;
}
/*
 * .ot-md-rendered — host-context-independent typography for the in-browser
 * Markdown viewer. The viewer is mounted directly under document.body, so it
 * inherits styles from whichever host page opened it (WP admin, front-end
 * theme, etc.). To ensure rendering is identical in every host context, we
 * explicitly re-declare typography for every markdown element instead of
 * relying on browser/admin/theme defaults. Do not remove these rules without
 * also re-verifying both the editor (wp-admin) and the front-end (Core
 * Version Viewer / shortcode) viewers side-by-side.
 */
.ot-md-rendered {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: #1d2327;
  word-wrap: break-word;
}
.ot-md-rendered h1,
.ot-md-rendered h2,
.ot-md-rendered h3,
.ot-md-rendered h4,
.ot-md-rendered h5,
.ot-md-rendered h6 {
  margin: 1.2em 0 0.5em 0;
  padding: 0;
  font-weight: 600;
  line-height: 1.25;
  color: #1d2327;
}
.ot-md-rendered h1 { font-size: 1.75em; border-bottom: 1px solid #dcdcde; padding-bottom: 0.3em; }
.ot-md-rendered h2 { font-size: 1.4em; border-bottom: 1px solid #dcdcde; padding-bottom: 0.3em; }
.ot-md-rendered h3 { font-size: 1.2em; }
.ot-md-rendered h4 { font-size: 1em; }
.ot-md-rendered h5 { font-size: 0.95em; }
.ot-md-rendered h6 { font-size: 0.9em; color: #50575e; }
.ot-md-rendered p {
  margin: 0 0 1em 0;
  padding: 0;
  font-size: 14px;
  line-height: 1.6;
}
.ot-md-rendered a {
  color: #2271b1;
  text-decoration: underline;
}
.ot-md-rendered a:hover {
  color: #135e96;
}
.ot-md-rendered strong { font-weight: 600; }
.ot-md-rendered em { font-style: italic; }
.ot-md-rendered ul,
.ot-md-rendered ol {
  margin: 0 0 1em 0;
  padding-left: 2em;
  font-size: 14px;
  line-height: 1.6;
  list-style-position: outside;
}
.ot-md-rendered ul { list-style-type: disc; }
.ot-md-rendered ol { list-style-type: decimal; }
.ot-md-rendered ul ul { list-style-type: circle; }
.ot-md-rendered ul ul ul { list-style-type: square; }
.ot-md-rendered li {
  margin: 0.25em 0;
  padding: 0;
  display: list-item;
}
.ot-md-rendered li > p {
  margin: 0.25em 0;
}
.ot-md-rendered li > ul,
.ot-md-rendered li > ol {
  margin: 0.25em 0;
}
.ot-md-rendered blockquote {
  margin: 0 0 1em 0;
  padding: 0.5em 1em;
  border-left: 4px solid #dcdcde;
  color: #50575e;
  background: #f6f7f7;
}
.ot-md-rendered blockquote > :first-child { margin-top: 0; }
.ot-md-rendered blockquote > :last-child { margin-bottom: 0; }
.ot-md-rendered hr {
  border: 0;
  border-top: 1px solid #dcdcde;
  margin: 1.5em 0;
  height: 0;
}
.ot-md-rendered table {
  border-collapse: collapse;
  margin: 0 0 1em 0;
  width: auto;
  max-width: 100%;
  font-size: 13px;
  background: #fff;
}
.ot-md-rendered th,
.ot-md-rendered td {
  border: 1px solid #dcdcde;
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
}
.ot-md-rendered th {
  background: #f6f7f7;
  font-weight: 600;
}
.ot-md-rendered pre {
  background: #f6f7f7;
  padding: 12px;
  border-radius: 4px;
  overflow-x: auto;
  margin: 0 0 1em 0;
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.45;
}
.ot-md-rendered pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
  color: inherit;
}
.ot-md-rendered code {
  background: #f0f0f1;
  padding: 1px 4px;
  border-radius: 3px;
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: 13px;
  color: #1d2327;
}
.ot-md-rendered img {
  max-width: 100%;
  height: auto;
  display: inline-block;
}

/* --- Viewer toolbar buttons --- */
.ot-viewer-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  min-width: 30px;
  padding: 0 10px;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  background: #fff;
  color: #495057;
  font-size: 13px;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, color 120ms, box-shadow 120ms;
  gap: 4px;
}
.ot-viewer-btn:hover { background: #f0f6fc; border-color: #2271b1; color: #2271b1; }
.ot-viewer-btn:focus { outline: 2px solid #2271b1; outline-offset: 1px; }
.ot-viewer-btn:active { background: #e2edf7; }
.ot-viewer-btn.active { background: #2271b1; color: #fff; border-color: #2271b1; box-shadow: 0 1px 3px rgba(34, 113, 177, 0.3); }
.ot-viewer-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ot-viewer-btn svg { width: 14px; height: 14px; }

/* --- Fullscreen toggle button --- */
.ot-viewer-fullscreen-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.65);
  cursor: pointer;
  border-radius: 6px;
  padding: 0;
  transition: color 150ms, background 150ms;
}
.ot-viewer-fullscreen-btn svg {
  width: 16px;
  height: 16px;
}
.ot-viewer-fullscreen-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}
.ot-viewer-fullscreen-btn:focus {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 1px;
}

/* --- Fullscreen panel state --- */
.ot-viewer-panel--fullscreen {
  max-width: 100vw;
  max-height: 100vh;
  width: 100vw;
  height: 100vh;
  border-radius: 0;
}

/* --- Multi-page 2-column grid layout (PDF) --- */
.ot-viewer-pdf-pages--grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  justify-items: center;
  gap: 20px;
}
.ot-viewer-pdf-pages--grid .ot-viewer-pdf-page-container {
  width: 100% !important;
}
.ot-viewer-pdf-pages--grid .ot-viewer-pdf-canvas {
  max-width: 100%;
  height: auto;
}

/* --- PDF Text Layer (§6.3.4 — text selection accessibility) --- */
.ot-viewer-pdf-text-layer {
  overflow: hidden;
  opacity: 0.25;
  line-height: 1;
  pointer-events: all;
}
.ot-viewer-pdf-text-layer span,
.ot-viewer-pdf-text-layer br {
  color: transparent;
  position: absolute;
  white-space: pre;
  transform-origin: 0% 0%;
}
.ot-viewer-pdf-text-layer span::selection {
  background: rgba(0, 100, 200, 0.3);
}

/* --- Viewer Error Message --- */
.ot-viewer-error {
  padding: 32px 24px;
  color: #b32d2e;
  text-align: center;
  font-size: 14px;
  line-height: 1.6;
}

/* --- Responsive --- */
@media screen and (max-width: 782px) {
  .ot-viewer-panel {
    max-width: 100vw;
    max-height: 100vh;
    width: 100vw;
    height: 100vh;
    border-radius: 0;
  }
  .ot-epub-toc {
    display: none;
  }
}


