/* =========================================================================
   EXTERNAL REVIEWER PORTAL — standalone stylesheet.
   Shares the suite's warm palette and JetBrains Mono micro-labels, but is a
   deliberately quieter, single-purpose surface: no funnel, no tool tabs, no
   internal signals. Self-contained so the admin app's CSS can change freely.
   ========================================================================= */
:root {
  --bg: #e9e7e2;
  --card: #ffffff;
  --border: #d9d6d0;
  --border-soft: #e6e3dd;
  --ink: #2a2926;
  --ink-soft: #4a4843;
  --muted: #8a877f;
  --muted2: #a8a59d;
  --blue: #2f6fb0;

  --met-bg: #eaf0e4;    --met-border: #cdddbf;   --met-text: #5a7c46;
  --notmet-bg: #f5e6e3; --notmet-border: #e3c4bd; --notmet-text: #a85a4f;
  --review-bg: #f3edd9; --review-border: #e3d4a8; --review-text: #9a8a46;
  --danger: #b01c1c;
  --danger-bg: #fbeae8;

  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body.portal {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* The LDI wordmark is dark blue on transparent, so it sits on a light chip
   inside the dark topbar; the login card is already light. */
.logo-chip {
  display: inline-flex; align-items: center;
  background: #f7f5f0; border-radius: 8px; padding: 5px 10px;
}
.logo-chip img { height: 26px; display: block; }
.login-logo { height: 34px; display: block; margin: 0 auto; }

.pv-view { display: none; }
.pv-view.active { display: block; }

.help { color: var(--muted); font-size: 0.82rem; margin: 6px 0; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 18px; }
.card.no-pad { padding: 0; overflow: hidden; }
.table-scroll { overflow-x: auto; }
.back-link {
  display: inline-block; margin-bottom: 14px; color: var(--ink-soft);
  text-decoration: none; font-size: 0.86rem;
}
.back-link:hover { text-decoration: underline; }
.cell-id { font-family: var(--mono); font-size: 0.78rem; color: var(--muted); }
.cell-sub { display: block; font-size: 0.72rem; color: var(--muted2); }
.empty-cell { padding: 28px; text-align: center; color: var(--muted); }

/* ---- Buttons ---- */
.btn-primary, .btn-ghost {
  font-family: var(--sans); font-size: 0.88rem; border-radius: 7px;
  padding: 10px 18px; cursor: pointer; border: 1px solid var(--ink);
}
.btn-primary { background: var(--ink); color: #f7f5f0; }
.btn-primary:hover:not(:disabled) { background: #3c3a35; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { border-color: var(--ink); }
.btn-primary:disabled, .btn-ghost:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-ghost.sm, .btn-primary.sm { padding: 6px 12px; font-size: 0.78rem; }
a.btn-ghost { text-decoration: none; display: inline-block; }
a.btn-ghost[hidden] { display: none; }
.block { width: 100%; }

/* =========================================================================
   Login
   ========================================================================= */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 28px; background:
    radial-gradient(1100px 520px at 50% -10%, #f3f1ec 0%, var(--bg) 62%);
}
.login-card {
  width: 100%; max-width: 400px; background: var(--card);
  border: 1px solid var(--border); border-radius: 14px; padding: 32px 30px;
  box-shadow: 0 14px 44px rgba(42, 41, 38, 0.09);
}
.login-brand { margin-bottom: 20px; }
.login-card h1 { font-size: 1.24rem; margin: 0 0 4px; letter-spacing: -0.3px; }
.login-sub { color: var(--muted); font-size: 0.85rem; margin: 0 0 22px; }
.login-error {
  background: var(--danger-bg); border: 1px solid var(--notmet-border);
  color: var(--notmet-text); border-radius: 7px; padding: 9px 12px;
  font-size: 0.83rem; margin-bottom: 14px;
}
.login-foot { color: var(--muted2); font-size: 0.74rem; margin: 18px 0 0; }

.fld { display: block; margin-bottom: 16px; }
.fld > span {
  display: block; font-family: var(--mono); font-size: 0.68rem;
  text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted);
  margin-bottom: 6px;
}
.fld input[type="text"], .fld input[type="password"], .fld textarea {
  width: 100%; font-family: var(--sans); font-size: 0.9rem; color: var(--ink);
  background: #fdfcfa; border: 1px solid var(--border); border-radius: 7px;
  padding: 10px 12px;
}
.fld textarea { resize: vertical; line-height: 1.55; }
.fld input:focus, .fld textarea:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(47, 111, 176, 0.12);
}
.fld textarea:disabled, .fld input:disabled { background: #f4f2ee; color: var(--ink-soft); }

/* Amber, not red — the suggested length is a nudge, never a blocker. */
.counter {
  display: block; font-family: var(--mono); font-size: 0.68rem;
  color: #8a6d1a; margin-top: 5px;
}
.counter.ok { color: var(--met-text); }

/* =========================================================================
   Shell
   ========================================================================= */
.pv-topbar {
  display: flex; align-items: center; gap: 14px;
  background: var(--ink); color: #f3f1ec; padding: 12px 28px;
}
.pv-brand { display: flex; align-items: center; gap: 14px; }
.pv-title { font-size: 1rem; font-weight: 600; letter-spacing: -0.2px; }
.pv-sub { font-size: 0.72rem; color: #b4b0a6; }
.pv-spacer { flex: 1; }
.pv-progress {
  font-family: var(--mono); font-size: 0.72rem; padding: 5px 11px;
  border-radius: 20px; background: rgba(255, 255, 255, 0.1); color: #ddd9d0;
}
.pv-progress.done { background: rgba(90, 124, 70, 0.45); color: #e7efdf; }
.pv-who { font-size: 0.82rem; color: #ddd9d0; }
.pv-topbar .btn-ghost { color: #ddd9d0; border-color: #5a584f; }
.pv-topbar .btn-ghost:hover { border-color: #b4b0a6; }

.pv-status {
  max-width: 1280px; margin: 0 auto; padding: 0 28px;
  font-size: 0.84rem; color: var(--muted); min-height: 0;
}
.pv-status:not(:empty) { padding-top: 14px; }
.pv-status.error { color: var(--notmet-text); }
.pv-status.ok { color: var(--met-text); }
.pv-status.warn { color: #8a6d1a; }

/* ---- Finals panel (program officers) ---- */
/* Medal decision buttons — one selected at a time; re-click clears. */
.finals-decision { margin-top: 6px; }
.fld-label {
  display: block; font-family: var(--sans); font-size: 0.78rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted);
  margin-bottom: 8px;
}
.medal-row { display: flex; flex-wrap: wrap; gap: 10px; }
.medal-btn {
  font-family: var(--sans); font-size: 0.92rem; color: var(--ink);
  border: 1.5px solid var(--border); border-radius: 12px; padding: 10px 18px;
  background: #fdfcfa; cursor: pointer;
}
.medal-btn:hover { border-color: var(--ink); }
.medal-btn.selected {
  border-color: var(--ink); background: var(--ink); color: #fdfcfa;
  font-weight: 600;
}
/* Abstain (conflict of interest): same row, deliberately quieter than the
   medals — smaller, gray, dashed — but with a clear selected state. */
.medal-btn--abstain {
  font-size: 0.82rem; color: var(--muted); padding: 8px 14px;
  border-style: dashed; background: transparent; align-self: center;
}
.medal-btn--abstain:hover { border-color: var(--muted); color: var(--ink); }
.medal-btn--abstain.selected {
  border-style: solid; border-color: var(--muted); background: var(--muted);
  color: #fdfcfa; font-weight: 600;
}
/* Soft per-track medal-conflict advisory on the dashboard. Amber, not red —
   it is a heads-up, never a validation error. */
.finals-advisory {
  margin: 0 0 14px; padding: 12px 16px; border: 1px solid #e3d5a8;
  border-radius: 10px; background: #faf5e4; color: #6d5810;
  font-size: 0.86rem;
}
.finals-advisory[hidden] { display: none; }
.finals-advisory ul { margin: 6px 0 0; padding-left: 20px; }
.finals-advisory li { margin-bottom: 3px; }
.finals-advisory .help { color: #8a6d1a; }
/* The PO's own Winner/Runner-up pick beside a dashboard row's status pill. */
.dash-medal { margin-left: 7px; font-size: 0.95rem; vertical-align: middle; }

#pv-dashboard, #pv-review { max-width: 1280px; margin: 0 auto; padding: 24px 28px 72px; }

.pv-head { margin-bottom: 18px; }
.pv-head h1 { font-size: 1.34rem; margin: 4px 0 6px; letter-spacing: -0.4px; }
.pv-lede { color: var(--ink-soft); font-size: 0.88rem; margin: 0; }
.pv-pi { color: var(--ink-soft); font-size: 0.86rem; margin: 0 0 4px; }
.pv-pi b { color: var(--ink); font-weight: 600; }
.meta-chip {
  display: inline-block; font-family: var(--mono); font-size: 0.68rem;
  background: #f0eee9; border: 1px solid var(--border-soft); border-radius: 5px;
  padding: 2px 8px; margin: 4px 5px 0 0; color: var(--ink-soft);
}

/* ---- Dashboard filter chips ---- */
.dash-filters { display: flex; gap: 8px; margin: 0 0 12px; flex-wrap: wrap; }
.dash-filters .chip {
  font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.4px;
  padding: 5px 13px; border-radius: 20px; cursor: pointer;
  background: transparent; border: 1px solid var(--border); color: var(--ink-soft);
}
.dash-filters .chip:hover { border-color: var(--ink); }
.dash-filters .chip.active {
  background: var(--ink); border-color: var(--ink); color: #f3f1ec;
}
.dash-track { display: inline-flex; align-items: center; gap: 7px; margin-left: auto; }
/* The author display above beats the UA [hidden] rule — restore it, so the
   selector really disappears for single-track reviewers. */
.dash-track[hidden] { display: none; }
.dash-track > span {
  font-family: var(--mono); font-size: 0.67rem; text-transform: uppercase;
  letter-spacing: 0.7px; color: var(--muted);
}
.dash-track select {
  font-family: var(--sans); font-size: 0.82rem; color: var(--ink);
  background: var(--card); border: 1px solid var(--border); border-radius: 7px;
  padding: 5px 9px;
}

/* ---- Dashboard table ---- */
.pv-tbl { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.pv-tbl th {
  text-align: left; font-family: var(--mono); font-size: 0.67rem;
  text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted);
  padding: 12px 16px; background: #f6f4f0; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.pv-tbl td { padding: 13px 16px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
.pv-tbl tr:last-child td { border-bottom: none; }
.pv-tbl tbody tr:hover { background: #faf9f6; }
.row-actions a { color: var(--blue); text-decoration: none; font-size: 0.84rem; }
.row-actions a:hover { text-decoration: underline; }

/* Bookmark star — a personal marker, per reviewer account. */
.pv-tbl th.col-star, .pv-tbl td.cell-star { width: 34px; padding-right: 0; }
.star-btn {
  background: none; border: 0; cursor: pointer; padding: 0 4px;
  font-size: 1.05rem; line-height: 1; color: var(--muted2);
}
.star-btn:hover { color: var(--ink-soft); }
.star-btn.on { color: #b8860b; }

.pill {
  display: inline-block; font-family: var(--mono); font-size: 0.68rem;
  padding: 3px 9px; border-radius: 20px; border: 1px solid transparent; white-space: nowrap;
}
.pill-idle { background: #f0eee9; border-color: var(--border); color: var(--muted); }
.pill-progress { background: var(--review-bg); border-color: var(--review-border); color: var(--review-text); }
.pill-done { background: var(--met-bg); border-color: var(--met-border); color: var(--met-text); }

/* =========================================================================
   Scoring form
   ========================================================================= */
.pv-section {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 22px 24px; margin: 0 0 18px; min-width: 0;
}
/* Legends render as a pill: the solid background hides the fieldset border
   behind the text (a bare legend only notches the first line, so wrapped
   titles got struck through by the border). */
.pv-section legend {
  font-size: 1.02rem; font-weight: 600; letter-spacing: -0.2px;
  display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap;
  max-width: 100%;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 14px; margin-left: -4px;
}
.legend-tag {
  font-family: var(--mono); font-size: 0.64rem; text-transform: uppercase;
  letter-spacing: 0.7px; color: var(--muted); font-weight: 400;
}
.section-help { color: var(--muted); font-size: 0.83rem; margin: 2px 0 16px; }
.section-note {
  background: #f6f4f0; border-left: 3px solid var(--border); border-radius: 0 6px 6px 0;
  padding: 9px 13px; font-size: 0.82rem; color: var(--ink-soft); margin: 0 0 16px;
}

/* ---- Scored criteria ---- */
.scale-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.scale-chip {
  font-family: var(--mono); font-size: 0.68rem; background: #f6f4f0;
  border: 1px solid var(--border-soft); border-radius: 5px; padding: 3px 9px; color: var(--ink-soft);
}
.crit-block { border-top: 1px solid var(--border-soft); padding-top: 20px; margin-top: 20px; }
.crit-block:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }
.crit-mean {
  border-top: 1px solid var(--border-soft); padding-top: 16px; margin-top: 20px;
  font-size: 0.86rem; color: var(--ink-soft);
}
.crit-mean b { font-family: var(--mono); font-size: 0.95rem; color: var(--ink); }
.crit-head { display: flex; align-items: center; gap: 11px; margin-bottom: 8px; }
.crit-index {
  font-family: var(--mono); font-size: 0.7rem; width: 22px; height: 22px;
  border-radius: 50%; background: var(--ink); color: #f3f1ec;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.crit-head h3 { font-size: 0.99rem; margin: 0; font-weight: 600; }

/* Collapsed by default — the track-specific guidance note. */
.guidance {
  background: #f6f4f0; border: 1px solid var(--border-soft); border-radius: 7px;
  padding: 9px 13px; margin-bottom: 14px;
}
.guidance summary {
  cursor: pointer; font-family: var(--mono); font-size: 0.7rem;
  text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted);
}
.guidance summary:hover { color: var(--ink); }
.guidance p { margin: 10px 0 2px; font-size: 0.84rem; color: var(--ink-soft); line-height: 1.6; }
.scale-meanings ul { margin: 10px 0 2px; padding-left: 18px; }
.scale-meanings li { font-size: 0.84rem; color: var(--ink-soft); line-height: 1.6; margin-bottom: 6px; }

.score-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.score-opt {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 14px; cursor: pointer; background: #fdfcfa; flex: 1 1 auto;
}
.score-opt input { accent-color: var(--ink); }
.score-num { font-family: var(--mono); font-weight: 700; font-size: 0.94rem; }
.score-lbl { font-size: 0.8rem; color: var(--ink-soft); white-space: nowrap; }
.score-opt:has(input:checked) { border-color: var(--ink); background: #f0eee9; }
.score-4:has(input:checked) { border-color: var(--met-border); background: var(--met-bg); }
.score-3:has(input:checked) { border-color: var(--met-border); background: #f1f5ec; }
.score-2:has(input:checked) { border-color: var(--review-border); background: var(--review-bg); }
.score-1:has(input:checked) { border-color: var(--notmet-border); background: var(--notmet-bg); }
.score-opt:has(input:disabled) { cursor: not-allowed; opacity: 0.75; }

/* ---- Actions / validation ---- */
.pv-actions {
  display: flex; align-items: center; gap: 12px; padding: 16px 0 0;
  position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 24%);
}
.action-note { font-size: 0.8rem; color: var(--muted); }
.action-note.dirty { color: var(--review-text); }
.action-note.ok { color: var(--met-text); }
.action-note.error { color: var(--notmet-text); }
.problem-box {
  background: var(--danger-bg); border: 1px solid var(--notmet-border);
  border-radius: 9px; padding: 15px 18px; margin-bottom: 16px; color: var(--notmet-text);
}
.problem-box ul { margin: 9px 0 0; padding-left: 20px; font-size: 0.85rem; }
.problem-box li { margin-bottom: 4px; }
.problem-box .help { color: var(--notmet-text); opacity: 0.85; }

/* =========================================================================
   Split layout — form + inline document preview
   Side-by-side on wide screens; stacked on narrow screens with the preview
   panel ABOVE the form so it never hides at the bottom of a long page.
   ========================================================================= */
.pv-split { display: flex; flex-direction: column; }
.pv-preview-col { order: -1; }
.pv-form-col { min-width: 0; }
.pv-preview-col {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  margin-bottom: 18px; overflow: hidden; min-width: 0;
}
.preview-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft); background: #f6f4f0;
  flex-wrap: wrap;
}
.preview-head .btn-ghost.sm { white-space: nowrap; }
.preview-title {
  font-family: var(--mono); font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.7px; color: var(--muted); flex: 1;
}
/* Materials strip — one chip per submitted document, always visible (it sits
   outside .preview-body so minimizing the preview never hides it). */
.materials-strip {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 10px 16px; border-bottom: 1px solid var(--border-soft); background: #fbfaf8;
  /* A fully expanded chip list scrolls within the strip instead of swallowing
     the column — in side-by-side mode the sticky preview column clips its
     overflow, which made a tall strip (and the preview under it) unreachable.
     flex-shrink: 0 matters: overflow-y gives the strip min-height 0 inside the
     side-by-side flex column, and without it the preview body squeezed the
     strip down to a single row. */
  max-height: max(25vh, 160px); overflow-y: auto; flex-shrink: 0;
}
.materials-strip[hidden] { display: none; }
.mat-chip-group { display: inline-flex; align-items: center; gap: 2px; }
.mat-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--sans); font-size: 0.78rem; color: var(--ink);
  border: 1px solid var(--border); border-radius: 14px; padding: 4px 11px;
  background: #fdfcfa; cursor: pointer; text-decoration: none;
}
.mat-chip:hover { border-color: var(--ink); }
.mat-chip.active { background: var(--ink); color: #fdfcfa; border-color: var(--ink); }
.mat-chip-ext {
  font-size: 0.78rem; color: var(--muted); text-decoration: none;
  border: 1px solid transparent; border-radius: 10px; padding: 3px 6px;
}
.mat-chip-ext:hover { color: var(--ink); border-color: var(--border); }
/* Finals-panel materials layout: the four reading essentials up front, the
   supporting files in collapsible groups. */
.mat-primary { display: contents; }
.mat-chip.mat-chip-primary {
  font-weight: 600; border-color: var(--ink-soft); background: #f6f4f0;
}
.mat-chip.mat-chip-primary.active { background: var(--ink); border-color: var(--ink); }
.mat-group { flex-basis: 100%; margin: 2px 0 0; }
.mat-group > summary {
  cursor: pointer; font-family: var(--sans); font-size: 0.76rem;
  color: var(--muted); padding: 3px 2px; user-select: none;
}
.mat-group > summary:hover { color: var(--ink); }
.mat-group[open] > summary { color: var(--ink); }
.mat-group-chips {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 0 4px 14px;
}
.open-all-note { font-size: 0.72rem; color: var(--muted); margin-left: 4px; }
/* Collapsed tail of a long attachment list — chips flow inline when open. */
.mat-overflow { display: contents; }
.mat-overflow.hidden { display: none; }
.mat-chip-more { color: var(--muted); border-style: dashed; }
.preview-zoom { display: flex; align-items: center; gap: 4px; }
.preview-zoom[hidden] { display: none; }
.preview-zoom .btn-ghost.sm { padding: 4px 9px; }
.zoom-level {
  font-family: var(--mono); font-size: 0.7rem; color: var(--muted);
  min-width: 38px; text-align: center;
}
.preview-body { padding: 14px 16px; max-height: 320px; overflow: auto; }
/* Minimized = header + materials strip only. Without this the 320px body kept
   eating vertical space after "Hide preview". Zoom/Download act on the hidden
   body, so they collapse with it. */
.pv-split:not(.preview-open) .preview-body,
.pv-split:not(.preview-open) .preview-zoom,
.pv-split:not(.preview-open) #preview-download { display: none; }
.preview-frame { width: 100%; height: 60vh; border: none; }
.pdf-pages { display: flex; flex-direction: column; gap: 12px; }
.pdf-page { width: 100%; height: auto; border: 1px solid var(--border-soft); border-radius: 4px; }
.docx-render { font-size: 0.86rem; line-height: 1.65; }
.docx-render img { max-width: 100%; height: auto; }
.docx-render table { border-collapse: collapse; width: 100%; font-size: 0.8rem; }
.docx-render td, .docx-render th { border: 1px solid var(--border-soft); padding: 5px 7px; }
.doc-text {
  white-space: pre-wrap; word-break: break-word; font-family: var(--mono);
  font-size: 0.76rem; line-height: 1.6; color: var(--ink-soft); margin: 0;
}
/* The CSV narrative — question headings over prose answers. */
.narrative-render { font-size: 0.86rem; line-height: 1.65; color: var(--ink-soft); }
.narrative-render h3 {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted); margin: 18px 0 6px;
}
.narrative-render h3:first-child { margin-top: 0; }
.narrative-render p { margin: 0 0 10px; }

/* Side-by-side once the preview is open and there is room for two columns.
   Explicit grid placement is required — the stacked layout's order:-1 would
   otherwise drop the preview into the left column. */
@media (min-width: 1080px) {
  .pv-split.preview-open {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 42%);
    gap: 18px; align-items: start;
  }
  .pv-split.preview-open .pv-form-col { grid-column: 1; grid-row: 1; }
  .pv-split.preview-open .pv-preview-col {
    grid-column: 2; grid-row: 1; order: 0;
    position: sticky; top: 16px; max-height: calc(100vh - 40px); display: flex;
    flex-direction: column; margin-bottom: 0;
  }
  .pv-split.preview-open .preview-body { max-height: none; flex: 1; }
}

@media (max-width: 720px) {
  .pv-topbar { flex-wrap: wrap; padding: 10px 16px; }
  #pv-dashboard, #pv-review, .pv-status { padding-left: 16px; padding-right: 16px; }
  .pv-section { padding: 18px 16px; }
  .score-opt { flex: 1 1 100%; }
  .pv-actions { flex-wrap: wrap; }
}
