/*
 * Writing two-pane review widget — SHARED styling.
 *
 * Rendered by public/js/scan-exams/writing-review.js, which is used by BOTH the
 * desktop Review Scans page (scan-review.html) and the phone scan flow
 * (scan-exams.html). This file is the single source of truth for the widget so
 * the panes are styled identically wherever the detail view opens. Relies on the
 * --scan-* / --sr-* custom properties defined by each page's own stylesheet.
 */

/* ---------------------------------------------- writing two-pane review */

/* Writing scans replace the MC bubble overlay with a per-part stack: the
   scanned page on top, the editable OCR transcription beneath, both A4-width
   and a short fixed height so the teacher sees ~4–5 lines and scrolls. The
   two panes scroll in sync. Tunable knobs are CSS vars so the width / height /
   font can be fine-tuned against real student writing. */
.sr-writing-review {
  /* Max display width of a pane. The image zooms to fill it, so a wider pane =
     a more zoomed-in scan. Capped well above A4 (794px) so it keeps zooming on
     bigger screens, but still bounded on huge monitors. On narrow screens it
     falls back to 100% of the available area. */
  --sr-a4-width: 1600px;
  --sr-pane-height: 85px; /* per pane; teacher-adjustable via the drag handle (JS overrides) */
  /* OCR font scales with the PANE'S real width (cqw), not the viewport — so it
     tracks the scan's zoom and automatically accounts for the side menu eating
     screen width. 2.86cqw ≈ 20px at a 700px-wide pane; rem bounds keep it
     readable on phones and from getting huge on very wide monitors. */
  --sr-ocr-font: clamp(0.875rem, 2.86cqw, 2rem);
}

.sr-writing-pane-group {
  position: relative; /* anchor for the bottom-right resize handle */
  /* Query container so the OCR pane's cqw font-size resolves against the pane
     width (panes are 100% of the group). */
  container-type: inline-size;
  width: min(var(--sr-a4-width), 100%);
  margin: 0 auto 1.75rem;
}

/* Bottom-right drag handle — vertical resize only (makes the panes shorter or
   taller). Sits over the OCR pane's bottom-right corner. */
.sr-writing-resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  cursor: ns-resize;
  touch-action: none;
  z-index: 2;
  border-bottom-right-radius: 12px;
  background:
    linear-gradient(135deg, transparent 0 50%, var(--scan-muted) 50% 60%,
      transparent 60% 70%, var(--scan-muted) 70% 80%, transparent 80%);
  opacity: 0.55;
}
.sr-writing-resize-handle:hover { opacity: 0.9; }

.sr-writing-pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 0 0 0.5rem;
}

.sr-writing-pane-label {
  font-size: 1rem;
  font-weight: 700;
  color: var(--scan-primary);
}

.sr-writing-pane {
  width: 100%;
  height: var(--sr-pane-height);
  overflow-y: auto;
  overflow-x: hidden;
  box-sizing: border-box;
  border: 1px solid var(--scan-border);
  background: var(--scan-card);
  -webkit-overflow-scrolling: touch;
}

/* Top pane — the scanned page image(s). Squared bottom corners + no bottom
   border so it reads as one stacked unit with the OCR pane below. */
.sr-writing-pane-img {
  border-radius: 12px 12px 0 0;
  border-bottom: none;
  background: #1a1a2e;
}
.sr-writing-pane-img img {
  display: block;
  width: 100%;
  height: auto;
}

/* Bottom pane — editable OCR text. pre-wrap keeps the OCR's paragraph breaks
   (deliberate "\n\n") and lets long lines wrap inside the fixed width. */
.sr-writing-pane-ocr {
  border-radius: 0 0 12px 12px;
  padding: 0.55rem 0.8rem;
  font-family: inherit;
  font-size: var(--sr-ocr-font);
  line-height: 1.5;
  color: var(--scan-text);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.sr-writing-pane-ocr:focus {
  outline: 2px solid var(--scan-primary);
  outline-offset: -2px;
}

/* Committed scan — read-only transcription (still shows pre-commit edits). */
.sr-writing-pane-ocr--readonly {
  cursor: default;
  background: #f6f7fb;
  color: var(--scan-muted);
}

/* Characters the teacher changed or added — pale yellow, native "was: …"
   tooltip on hover. */
.sr-ocr-edited {
  background: #fff7c2;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.35);
  cursor: help;
}

/* A place where the teacher deleted text — a thin yellow vertical bar. Empty
   and contenteditable=false, so it adds nothing to the text or caret math. */
.sr-ocr-deleted {
  display: inline-block;
  width: 0;
  height: 1em;
  margin: 0 1px;
  vertical-align: text-bottom;
  border-left: 2px solid var(--scan-warning);
  cursor: help;
}

/* Part-2 writing-type chooser, right-aligned in the part head. */
.sr-writing-type {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.sr-writing-type-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--scan-muted);
}
.sr-writing-type-select {
  min-width: 9rem;
}
.sr-writing-type-hint {
  font-size: 0.78rem;
  color: var(--scan-warning);
}

/* Invisible stand-in that reserves the writing-type chooser's row space on a
   pane head before the real chooser appears (see buildTypeChooserPlaceholder).
   It's a real disabled <select>, so it self-sizes to the live chooser's height;
   we only need to hide it. */
.sr-writing-type-placeholder {
  visibility: hidden;
}

.sr-writing-note {
  padding: 0.75rem 0.9rem;
  font-size: 0.9rem;
  color: var(--scan-muted);
}
.sr-writing-note-warn { color: var(--scan-warning); }

/* "Edit on a computer" notice. Hidden everywhere except on a touch phone (see
   the media query below), where editing the OCR panes is too fiddly. */
.sr-writing-rotate { display: none; }
.sr-writing-rotate-icon { font-size: 1.5rem; line-height: 1; }

/* Touch phone in EITHER orientation: portrait phones by width (≤600px) and
   landscape phones by their short height (≤600px tall) — the height test keeps
   landscape tablets, which are taller and have room to edit, out of scope.
   Surface the notice and lock the OCR panes read-only so editing happens on a
   computer; the Upload button stays usable. */
@media (hover: none) and (pointer: coarse) and (orientation: portrait) and (max-width: 600px),
       (hover: none) and (pointer: coarse) and (orientation: landscape) and (max-height: 600px) {
  .sr-writing-review .sr-writing-rotate {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: min(var(--sr-a4-width), 100%);
    margin: 0 auto 1rem;
    padding: 0.7rem 0.9rem;
    border: 1px solid var(--scan-warning);
    border-radius: 12px;
    background: #fff8e6;
    color: #8a6500;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.35;
  }

  .sr-writing-review .sr-writing-pane-ocr:not(.sr-writing-pane-ocr--readonly) {
    pointer-events: none;
    opacity: 0.55;
  }
}

/* ---------------------------------------------- deskew quality flag */

/* Deskew quality flag — stronger (red) than the amber exam-mismatch hint
   because it means the scan itself may be unreliable, not just a stray digit.
   Created by the shared scan-exams/review.js (renderQualityWarnings), so it
   lives here in the shared sheet rather than duplicated per page. */
.scan-quality-warning {
  background: #fdecea;
  border: 1px solid #f5c2c0;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  font-size: 0.9rem;
  color: #9b1c1c;
  margin-bottom: 1rem;
}
