/* modal.css – generic modal styling */
@import url("variables.css");

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
html.oh-dark .modal,
html[data-theme="dark"] .modal {
  background: rgba(0, 0, 0, 0.6);
}

.modal-content {
  position: relative;           /* anchor abs-pos children */
  background: #fff;
  padding: 1rem;
  border-radius: 6px;
  max-width: 640px;
  width: 90%;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
html.oh-dark .modal-content,
html[data-theme="dark"] .modal-content {
  background: var(--container-bg);
  border: 1px solid var(--container-border);
}

/* PDF viewer modal: large but leaves breathing room so bottom controls remain visible */
.modal-content.pdf-viewer {
  width: 95vw !important;
  max-width: 95vw !important;
  max-height: 94vh !important; /* leave consistent vertical margin */
  height: 96vh !important;      /* balanced with 95vw width margin */
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.pdf-viewer .modal-header {
  margin-bottom: 0.5rem;
}
.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
}
html.oh-dark .modal-close-btn,
html[data-theme="dark"] .modal-close-btn { color: var(--fg-muted); }

/* -------------------- PDF Viewer Layout -------------------- */
/* grid fills remaining vertical space flexibly so textarea remains visible */
.pdf-viewer .viewer-grid {
  display: grid;
  grid-template-columns: minmax(0,60%) minmax(320px,40%); /* widen chat */
  flex: 1 1 auto;
  min-height: 0; /* allow children to scroll */
  gap: 0;
  overflow: hidden;
}

.pdf-viewer embed,
.pdf-viewer iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.pdf-viewer .pdf-container {
  width: 100%;
  height: 100%;
  overflow-y: auto;
}

/* -------------------- Reader-mode tabs + text pane -------------------- */
.pdf-viewer .doc-pane-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.pdf-viewer .viewer-tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--oh-border, #ddd);
  padding: 0 6px;
  flex: 0 0 auto;
}

.pdf-viewer .viewer-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 5px 12px;
  font-size: 0.72rem;
  cursor: pointer;
  color: #888;
}

.pdf-viewer .viewer-tab.active {
  color: var(--fg, #222);
  border-bottom-color: var(--oh-accent, #0d6e63);
}

.pdf-viewer #doc-pane-slot {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.pdf-viewer #doc-pane-slot > * {
  flex: 1 1 auto;
  min-height: 0;
}

.paper-text-pane {
  overflow-y: auto;
  padding: 1.2rem 1.6rem;
}

.paper-text-body {
  white-space: pre-wrap;
  font-family: var(--oh-font-serif, Georgia, 'Times New Roman', serif);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--fg, #222);
  max-width: 70ch;
  margin: 0 auto;
}

.paper-text-empty {
  color: #888;
  font-size: 0.85rem;
  padding: 1rem;
}

.pdf-viewer .pdf-container canvas {
  display: block;
  margin: 0 auto 8px auto;
  background: #fff;
}

.pdf-viewer .chat-column {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--oh-border, #ddd);
  background: #fafafa;
  overflow: hidden;
  font-size: 0.8rem;   /* smaller bubble text */
  font-family: var(--oh-font-sans, Arial, Helvetica, sans-serif);
  padding: 0.5rem;          /* adjust padding */
  gap: 0.6rem;               /* vertical breathing room */
  min-width: 320px;       /* chat shouldn't shrink below 320px */
}
html.oh-dark .pdf-viewer .chat-column {
  background: var(--container-bg);
}

.pdf-viewer .chat-column .modal-body,
.pdf-viewer .chat-column .chat-log-container {
  flex: 1 1 auto;
  overflow-y: auto;
}

.pdf-viewer .chat-column form {
  flex-shrink: 0;
}

.pdf-viewer .chat-column textarea {
  width: 100%;
  box-sizing: border-box;
}

.chat-panel textarea {
  resize: vertical;
}

/* Override bubble font sizes inside viewer chat */
.pdf-viewer .chat-column .user-message,
.pdf-viewer .chat-column .assistant-message {
  font-size: 0.78rem; /* slightly smaller */
  font-family: inherit;
}

/* Ensure list bullets render inside viewer chat bubbles */
.pdf-viewer .chat-column .assistant-message ul,
.pdf-viewer .chat-column .assistant-message ol {
  margin: 0.4rem 0 0.4rem 1.2rem;
  padding-left: 0;
  list-style-position: inside; /* keep markers visible but let list type cascade */
  color: inherit;
}

/* First-level list types – match standalone chat */
.pdf-viewer .chat-column .assistant-message > ul { list-style-type: disc; }
.pdf-viewer .chat-column .assistant-message > ol { list-style-type: decimal; }

.pdf-viewer .chat-column .assistant-message li {
  list-style-position: inside;
}

/* Blinking caret in streaming assistant bubble */
.caret {
  animation: ohCaretBlink 1s steps(1) infinite;
  opacity: 1;
}

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

/* In two-pane viewer the global Stop button overlaps; hide it */
.pdf-viewer .stop-btn {
  display: none !important;
}

/* PDF loading overlay */
.pdf-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.85);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 14px;
  color: #555;
  display: flex;
  align-items: center;
  z-index: 5; /* above pdf canvas */
}

.pdf-loading .spin {
  animation: oh-spin 1s linear infinite;
  margin-right: 6px;
}

@keyframes oh-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ============================================================ */
/* Blog customization modal                                       */
/* ============================================================ */
/* Used by the Blog button on the report page and by the "Revise"
 * button on the blog-view page. The base .modal / .modal-content
 * classes above handle the backdrop/centering; these rules style
 * the form contents. */

.oh-blog-modal {
  max-width: 640px;
  width: 92%;
  padding: 1.25rem 1.5rem;
  font-family: var(--oh-font-sans, "Inter", system-ui, sans-serif);
}

.oh-blog-modal .modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
  color: var(--oh-fg, #111);
}
html.oh-dark .oh-blog-modal .modal-header h2,
[data-theme="dark"] .oh-blog-modal .modal-header h2 {
  color: var(--fg);
}

#blog-modal-subtitle {
  margin: 0 0 0.5rem 0;
  color: var(--oh-fg-muted, #555);
  line-height: 1.4;
}
html.oh-dark #blog-modal-subtitle,
[data-theme="dark"] #blog-modal-subtitle {
  color: var(--fg-muted);
}

.oh-blog-modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin: 0.5rem 0 0.75rem 0;
}

.oh-blog-modal-fs {
  border: 1px solid var(--oh-border, #d5d5d5);
  border-radius: 8px;
  padding: 0.6rem 0.75rem 0.7rem 0.75rem;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}
html.oh-dark .oh-blog-modal-fs,
[data-theme="dark"] .oh-blog-modal-fs {
  border-color: var(--oh-border-strong);
}

.oh-blog-modal-fs legend {
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0 0.35rem;
  color: var(--oh-fg, #111);
}
html.oh-dark .oh-blog-modal-fs legend,
[data-theme="dark"] .oh-blog-modal-fs legend {
  color: var(--fg);
}

.oh-blog-modal-fs label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.88rem;
  cursor: pointer;
  color: var(--oh-fg, #222);
}
html.oh-dark .oh-blog-modal-fs label,
[data-theme="dark"] .oh-blog-modal-fs label {
  color: var(--fg);
}

.oh-blog-modal-fs input[type="radio"] {
  margin: 0;
  accent-color: var(--oh-accent, #2563eb);
}

.theme-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 2px;
}

.oh-blog-modal-textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--oh-border, #d5d5d5);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
  min-height: 4.5rem;
  background: var(--oh-bg, #fff);
  color: var(--oh-fg, #111);
}
.oh-blog-modal-textarea:focus {
  outline: 2px solid var(--oh-accent, #2563eb);
  outline-offset: 0;
  border-color: var(--oh-accent, #2563eb);
}
html.oh-dark .oh-blog-modal-textarea,
[data-theme="dark"] .oh-blog-modal-textarea {
  background: var(--oh-input-bg);
  color: var(--fg);
  border-color: var(--oh-border-strong);
}

.oh-blog-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--oh-border, #ececec);
}
html.oh-dark .oh-blog-modal-footer,
[data-theme="dark"] .oh-blog-modal-footer {
  border-top-color: var(--oh-border-strong);
}

/* Lock background scroll while the modal is open. */
body.oh-modal-open {
  overflow: hidden;
}

/* Hidden state — the base .modal rule always uses flex display, so we use
 * !important to win over it without rewriting the cascade. */
.modal.hidden {
  display: none !important;
}
