/* PDF Comparison Tool – styles (Greenstone Central–style dark theme) */

:root {
  --bg-page: #0A0A0A;
  --bg-container: #0A0A0A;
  --bg-elevated: #1C1C1C;
  --border: #444444;
  --border-light: #282828;
  --primary: #2E8B57;
  --primary-hover: #368C5E;
  --primary-disabled: #6c757d;
  --text: #E0E0E0;
  --text-muted: #A0A0A0;
  --error-bg: rgba(220, 53, 69, 0.15);
  --error-border: rgba(220, 53, 69, 0.4);
  --red: #dc3545;
  --green: #28A745;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --radius: 8px;
  --toolbar-h: 40px;
  --footer-h: 38px;
}

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

html, body { margin: 0; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ===== SITE TOP BAR ===== */

.site-topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 90px;
  padding: 0 1.25rem;
  background: var(--bg-page);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
}

.brand-logo {
  flex-shrink: 0;
  height: 72px;
  width: auto;
  object-fit: contain;
  border-radius: 4px;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.topbar-link {
  padding: 0.4rem 0.75rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.topbar-link:hover {
  color: var(--text);
  background: var(--bg-elevated);
}

.topbar-link.active {
  color: var(--primary);
  font-weight: 600;
}

/* Tool panels: only the active one is visible */
.tool-panel[hidden] {
  display: none !important;
}

.tool-placeholder {
  text-align: center;
  padding: 3rem 2rem;
}

.tool-placeholder h2 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
}

.tool-placeholder p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ===== PAGE BACKGROUND & CONTAINER ===== */

.page-background {
  flex: 1;
  min-height: 0;
  background: var(--bg-page);
  padding: 1.5rem;
}

.container {
  max-width: 880px;
  margin: 0 auto;
  background: var(--bg-container);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* When results are showing: fill space below top bar, keep footer visible */
body.has-results .page-background {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.has-results .container {
  max-width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  flex-direction: column;
}

body.has-results .container .tool-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.has-results .setup-view { display: none; }

/* ===== SETUP VIEW ===== */

.header { text-align: center; margin-bottom: 2rem; }
.header h1 { margin: 0 0 0.4rem; font-size: 1.6rem; font-weight: 700; }
.subtitle { margin: 0; color: var(--text-muted); font-size: 0.9rem; }

/* Upload */
.upload-section { margin-bottom: 2rem; }

.upload-zones {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  min-width: 0;
}

.upload-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.upload-col-label {
  margin: 0 0 0.45rem;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text);
  letter-spacing: 0.01em;
  text-align: center;
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.75rem 1rem;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
  min-height: 120px;
  min-width: 0; /* allow shrinking so long filenames don't stretch the box */
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
}

.upload-zone.drag-over { border-color: var(--primary); background: rgba(46, 139, 87, 0.12); }
.upload-zone.has-file { border-color: var(--green); border-style: solid; }

.zone-label { margin: 0 0 0.4rem; font-weight: 600; font-size: 0.95rem; }
.zone-hint { margin: 0 0 0.4rem; color: var(--text-muted); font-size: 0.85rem; }

.browse-btn {
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  color: var(--text);
  background: #000000;
  border: 1px solid var(--text);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.browse-btn:hover { background: var(--bg-elevated); color: var(--text); }

.filename {
  margin: 0.5rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-sizing: border-box;
}

/* Controls */
.controls-section { margin-bottom: 1.5rem; }

.compare-wrapper {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 52px;
}

.compare-btn {
  padding: 0.75rem 1.75rem;
  font-size: 1.05rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.compare-btn:disabled { background: var(--primary-disabled); color: var(--text); cursor: not-allowed; opacity: 0.7; }
.compare-btn:not(:disabled) { background: var(--primary); color: #FFFFFF; }
.compare-btn:not(:disabled):hover { transform: translateY(-1px); background: var(--primary-hover); }

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 10, 0.95);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  border-radius: var(--radius);
  z-index: 10;
  color: var(--text);
  padding: 0 1.5rem;
}
.loading-overlay.visible { display: flex; }

.progress-bar-wrap {
  width: 100%;
  max-width: 260px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-text {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-banner {
  padding: 0.6rem 0.9rem;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: var(--radius);
  color: #f08080;
  margin-bottom: 1rem;
}

/* ===== RESULTS VIEW ===== */

.results-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.results-view[hidden] {
  display: none !important;
}

/* Only one mode visible at a time - the other is fully hidden and takes no space */
.results-overlay[hidden],
.results-semantic[hidden] {
  display: none !important;
}

/* Toolbar */
.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--toolbar-h);
  padding: 0 0.75rem;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-page);
  flex-shrink: 0;
}

.toolbar-left, .toolbar-right { display: flex; align-items: center; min-width: 120px; }
.toolbar-right { justify-content: flex-end; }
.toolbar-center { display: flex; align-items: center; gap: 0; }

.toolbar-sync {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text-muted);
}
.toolbar-sync input { margin: 0; }

.toolbar-mode {
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
  transition: background 0.15s;
  color: var(--text-muted);
}
.toolbar-mode:first-child { border-radius: 5px 0 0 5px; }
.toolbar-mode:last-child { border-radius: 0 5px 5px 0; border-left: none; }
.toolbar-mode.active { background: var(--primary); color: #FFFFFF; border-color: var(--primary); }
.toolbar-mode:hover:not(.active) { background: var(--border-light); color: var(--text); }

.toolbar-mode {
  position: relative;
}
.toolbar-mode[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.45rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 400;
  line-height: 1.35;
  color: var(--text);
  background: #1C1C1C;
  border: 1px solid var(--border);
  border-radius: 5px;
  white-space: nowrap;
  z-index: 50;
  pointer-events: none;
  box-shadow: 0 3px 10px rgba(0,0,0,0.35);
}
.toolbar-mode[data-tooltip]:hover::before {
  content: '';
  position: absolute;
  top: calc(100% + 1px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-bottom-color: var(--border);
  z-index: 51;
  pointer-events: none;
}

.toolbar-close {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: 4px;
  transition: background 0.15s;
}
.toolbar-close:hover { background: var(--bg-elevated); color: var(--text); }

/* ---------- OVERLAY MODE ---------- */

.results-overlay {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.overlay-main {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 0.5rem;
  background: var(--bg-page);
  overflow: auto;
}

.overlay-main canvas {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 2px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.12);
}

.overlay-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--footer-h);
  padding: 0 0.75rem;
  border-top: 1px solid var(--border-light);
  background: var(--bg-page);
  flex-shrink: 0;
  gap: 0.5rem;
}

.footer-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.footer-nav { gap: 0.25rem; }
.footer-page { font-size: 0.78rem; min-width: 2.5rem; text-align: center; }
.footer-zoom { font-size: 0.78rem; min-width: 2.5rem; text-align: center; }
.footer-label { font-size: 0.75rem; }
.footer-stats { font-weight: 600; font-size: 0.82rem; color: var(--text); }
.footer-stats-detail { font-size: 0.72rem; }

.legend-chip {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 3px;
  vertical-align: middle;
}
.legend-chip-match { background: linear-gradient(135deg, var(--border-light) 50%, var(--text-muted) 50%); border: 1px solid var(--border); }
.legend-chip-diff { background: var(--red); }
.legend-chip-old { background: rgba(220,53,69,0.5); border: 1px solid var(--red); }
.legend-chip-new { background: rgba(40,167,69,0.5); border: 1px solid var(--green); }

.foot-btn {
  padding: 0.2rem 0.5rem;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s;
}
.foot-btn:hover:not(:disabled) { background: var(--border-light); }
.foot-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.download-foot-btn {
  background: var(--primary);
  color: #FFFFFF;
  border-color: var(--primary);
  margin-left: 0.3rem;
}
.download-foot-btn:hover { background: var(--primary-hover); }

/* ---------- SEMANTIC MODE ---------- */

.results-semantic {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.semantic-loading {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: rgba(10, 10, 10, 0.92);
  color: var(--text-muted);
  font-size: 0.85rem;
}

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

.results-semantic {
  position: relative;
}

.semantic-layout {
  flex: 1;
  min-height: 0;
  display: flex;
}

.semantic-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-light);
}

.semantic-panel-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 32px;
  padding: 0 0.6rem;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.panel-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--border);
}
.dot-close { background: #ff5f56; }

.panel-title { font-size: 0.78rem; font-weight: 600; color: var(--text); }

.semantic-canvas-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;
  background: var(--bg-page);
}

.semantic-stack {
  display: block;
  width: 100%;
}

.semantic-page-row {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  line-height: 0;
}

.semantic-canvas-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
}

.semantic-html-view {
  display: block;
  width: 100%;
  min-height: 100%;
  padding: 1rem 1.1rem;
  margin: 0;
  background: #fff;
  color: #1a1a1a;
  font-size: 0.95rem;
  line-height: 1.55;
  white-space: normal;
  word-wrap: break-word;
}

.semantic-html-view p { margin: 0 0 0.65em; }
.semantic-html-view p:last-child { margin-bottom: 0; }
.semantic-html-view h1, .semantic-html-view h2, .semantic-html-view h3,
.semantic-html-view h4, .semantic-html-view h5, .semantic-html-view h6 {
  margin: 0.5em 0 0.35em;
  font-weight: 700;
  line-height: 1.25;
}
.semantic-html-view h1 { font-size: 1.35rem; }
.semantic-html-view h2 { font-size: 1.2rem; }
.semantic-html-view h3 { font-size: 1.08rem; }
.semantic-html-view ul, .semantic-html-view ol {
  margin: 0 0 0.65em;
  padding-left: 1.35rem;
}
.semantic-html-view li { margin: 0.15em 0; }
.semantic-html-view blockquote {
  margin: 0.5em 0;
  padding-left: 0.85rem;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}
.semantic-html-view table { border-collapse: collapse; width: 100%; margin: 0.5em 0; font-size: 0.9em; }
.semantic-html-view td, .semantic-html-view th { border: 1px solid var(--border-light); padding: 0.25em 0.4em; }
.semantic-html-view strong, .semantic-html-view b { font-weight: 700; }
.semantic-html-view em, .semantic-html-view i { font-style: italic; }
.semantic-html-view u { text-decoration: underline; }

.semantic-html-view hr.docx-page-break {
  margin: 1rem 0;
  border: 0;
  border-top: 1px dashed var(--border);
  height: 0;
}

.semantic-html-view .docx-diff-para { margin: 0 0 0.65em; }
.semantic-html-view .docx-diff-empty { min-height: 0.5em; }
.semantic-html-view .docx-diff-removed-block,
.semantic-html-view .docx-diff-added-block {
  margin: 0 0 0.65em;
  padding: 0.35rem 0.45rem;
  border-radius: 4px;
}
.semantic-html-view .docx-diff-removed-block {
  background: rgba(220, 53, 69, 0.08);
  outline: 1px solid rgba(220, 53, 69, 0.2);
}
.semantic-html-view .docx-diff-added-block {
  background: rgba(40, 167, 69, 0.08);
  outline: 1px solid rgba(40, 167, 69, 0.2);
}

.semantic-html-view[hidden] {
  display: none !important;
}

.semantic-html-view .docx-diff-removed {
  background: rgba(220, 53, 69, 0.38);
  border-radius: 2px;
}

.semantic-html-view .docx-diff-added {
  background: rgba(40, 167, 69, 0.38);
  border-radius: 2px;
}

.semantic-panel-foot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 30px;
  padding: 0 0.6rem;
  border-top: 1px solid var(--border-light);
  background: var(--bg-elevated);
  flex-shrink: 0;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.panel-zoom { font-weight: 600; min-width: 2.5rem; }

.panel-zoom-btns { display: flex; gap: 2px; }

.panel-zoom-btn {
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.9rem; line-height: 1;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
}
.panel-zoom-btn:hover { background: var(--border-light); }

.panel-filename {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sidebar */
.semantic-sidebar {
  width: 260px;
  min-width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border-light);
  overflow-y: auto;
}

.sidebar-heading {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.sidebar-legend {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
}

.sidebar-legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.sidebar-report {
  margin-bottom: 0.75rem;
}

.report-heading {
  margin: 0 0 0.35rem;
  font-weight: 600;
  font-size: 0.85rem;
}

.report-page-label {
  margin: 0 0 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.report-cards { display: flex; gap: 0.5rem; }

.report-card {
  flex: 1;
  padding: 0.5rem;
  border-radius: 6px;
}
.report-card-old { background: rgba(220,53,69,0.15); border: 1px solid rgba(220,53,69,0.4); }
.report-card-new { background: rgba(40,167,69,0.15); border: 1px solid rgba(40,167,69,0.4); }

.rc-label { display: block; font-weight: 600; font-size: 0.78rem; }
.rc-meta { display: block; font-size: 0.72rem; color: var(--text-muted); }
.rc-diff { display: block; font-size: 1rem; font-weight: 700; margin-top: 0.15rem; }
.report-card-old .rc-diff { color: var(--red); }
.report-card-new .rc-diff { color: var(--green); }

.sidebar-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.sidebar-download {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--primary);
  color: #FFFFFF;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: auto;
}
.sidebar-download:hover { background: var(--primary-hover); }

/* ===== Responsive ===== */

@media (max-width: 700px) {
  .upload-zones { grid-template-columns: 1fr; }

  .semantic-layout { flex-direction: column; }
  .semantic-sidebar { width: 100%; min-width: 0; flex-shrink: 1; max-height: 160px; }
  .semantic-panel { border-right: none; border-bottom: 1px solid var(--border-light); }
}
