/* ==========================================================================
   Base
   ========================================================================== */

:root {
  --maroon: #8c1d40;
  --gold: #ffc627;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --border: #e2e2e2;
  --bg: #faf9f7;
  --ok: #1e7e34;
  --bad: #b02a2a;
  --warn: #a06a00;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.hidden {
  display: none !important;
}

.wrap {
  max-width: none;
  margin: 0 auto;
  padding: 24px 32px 60px;
}

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
  margin-bottom: 18px;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* ==========================================================================
   Header
   ========================================================================== */

header {
  background: var(--maroon);
  color: #fff;
  padding: 20px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

/* Ghost button on the maroon bar: quiet outline so it doesn't compete with the
   title, gold focus ring for keyboard users. */
.header-reset {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background 0.15s,
    border-color 0.15s;
}

.header-reset:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.8);
}

.header-reset:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

header h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
}

header p {
  margin: 6px 0 0;
  font-size: 0.88rem;
  opacity: 0.9;
}

header .v2tag {
  display: inline-block;
  background: var(--gold);
  color: #3a2a00;
  font-weight: 700;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
  vertical-align: middle;
}

/* ==========================================================================
   Upload / drop zone
   ========================================================================== */

.drop {
  border: 2px dashed #c9a8b6;
  border-radius: 10px;
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s;
}

.drop.dragover {
  border-color: var(--maroon);
  background: #fbf1f4;
}

.drop p {
  margin: 6px 0;
  color: var(--muted);
}

.drop strong {
  color: var(--maroon);
}

input[type="file"] {
  display: none;
}

textarea#pasteArea {
  width: 100%;
  min-height: 100px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  resize: vertical;
}

.err {
  color: var(--bad);
  font-size: 0.85rem;
  margin-top: 8px;
}

.filename {
  font-size: 0.82rem;
  color: var(--muted);
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  background: var(--maroon);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 0.88rem;
  cursor: pointer;
  font-weight: 600;
}

.btn:hover {
  background: #711633;
}

.btn.secondary {
  background: #fff;
  color: var(--maroon);
  border: 1px solid var(--maroon);
}

.btn.secondary:hover {
  background: #fbf1f4;
}

/* ==========================================================================
   Summary stats + program breakdown chips
   ========================================================================== */

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  min-width: 0;
  overflow: hidden;
}

.stat .num {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--maroon);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat .lbl {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.prog-breakdown {
  margin-top: 14px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.chip {
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--border);
}

.chip.sub {
  background: #eaf3ea;
  color: var(--ok);
  border-color: #c9e4c9;
}

.chip.unsub {
  background: #eef1fb;
  color: #2b4fb0;
  border-color: #cdd7f2;
}

.chip.grad {
  background: #fbeee0;
  color: #a0621a;
  border-color: #f2d8b8;
}

.chip.parent {
  background: #f6e9f0;
  color: var(--maroon);
  border-color: #e6c3d3;
}

/* Status pills (2026-08-13): legacy split and NEW AWARD TEST outcome counts,
   shown after the program chips. */
.chip.legacy {
  background: #f3edfb;
  color: #5b3d99;
  border-color: #dccdf0;
}

.chip.nonlegacy {
  background: #f0f0f0;
  color: #555;
  border-color: #d9d9d9;
}

.chip.award-match {
  background: #eaf3ea;
  color: var(--ok);
  border-color: #c9e4c9;
}

.chip.award-mismatch {
  background: #fdeaea;
  color: #b03030;
  border-color: #f0c5c5;
}

/* ==========================================================================
   Results controls (search / filters)
   ========================================================================== */

.controls-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}

.controls-row input[type="search"],
.controls-row select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}

.controls-row input[type="search"] {
  flex: 1;
  min-width: 180px;
}

/* Second controls row (2026-08-13): dedicated test/check filters. */
.filters-row {
  margin-top: -4px;
  padding: 8px 10px;
  background: #faf7f4;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.filters-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* ==========================================================================
   Results table
   ========================================================================== */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

thead th {
  position: sticky;
  top: 0;
  background: #f4f0ee;
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  white-space: nowrap;
}

tbody td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr:hover {
  background: #fbf8f5;
}

/* Review Reason active-state: the row whose notes dialog is currently open gets a
   gold wash plus an accent bar, cleared when the dialog closes. No persistent
   viewed marker (2026-08-14 ruling). */
tbody tr.notes-active {
  background: #f9e9b4;
  transition: background-color 0.15s;
}

tbody tr.notes-active td:first-child {
  box-shadow: inset 3px 0 0 var(--gold);
}

.tablewrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 560px;
  border: 1px solid var(--border);
  border-radius: 8px;
  /* Breathing room below the last row: macOS-style overlay scrollbars float on top of
     the content, so with only a few result rows the horizontal scrollbar sits directly
     over the final row and hides it. */
  padding-bottom: 16px;
}

.amount {
  font-weight: 700;
}

.amount.zero {
  color: var(--muted);
  font-weight: 400;
}

/* ==========================================================================
   Eligibility badges + source tags
   ========================================================================== */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 700;
}

.badge.elig {
  background: #eaf3ea;
  color: var(--ok);
}

.badge.inelig {
  background: #fbeaea;
  color: var(--bad);
}

.badge.gate {
  background: #fff3d6;
  color: var(--warn);
}

/* Neutral pill (2026-08-13): informational statuses that are neither pass nor
   fail (NOT_APPLICABLE, ZERO_EXPLAINED_BY_REVIEW, REACHED_*, N/A, etc.) so every
   value in a status column renders as a consistent badge. */
.badge.neutral {
  background: #efefef;
  color: #5f5e5a;
}

.note-icon {
  color: var(--warn);
  cursor: help;
  font-weight: 700;
}

/* ==========================================================================
   Pagination
   ========================================================================== */

.pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.pagination .btns {
  display: flex;
  gap: 6px;
}

.pagination button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 0.82rem;
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ==========================================================================
   Reference panel — tabs
   ========================================================================== */

details {
  margin-top: 6px;
}

summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--maroon);
  font-size: 0.9rem;
}

.tab-row {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
  margin-bottom: 16px;
  gap: 2px;
}

.tab-btn {
  background: transparent;
  border: none;
  padding: 7px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
}

.tab-btn:hover {
  color: var(--maroon);
}

.tab-btn.active {
  background: var(--maroon);
  color: #fff;
}

.tab-btn.active:hover {
  color: #fff;
}

.tab-panel.hidden {
  display: none;
}

/* ==========================================================================
   Reference panel — methodology content
   ========================================================================== */

.methodology {
  font-size: 0.82rem;
  color: #444;
  line-height: 1.6;
}

.methodology p {
  margin: 0 0 10px;
}

.methodology ul {
  margin: 0 0 12px;
  padding-left: 20px;
}

.methodology li {
  margin-bottom: 7px;
}

.methodology li:last-child {
  margin-bottom: 0;
}

.methodology code {
  background: #f1eeee;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.78rem;
}

.methodology h4 {
  font-weight: 600;
  color: var(--ink);
  margin: 22px 0 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.92rem;
}

.methodology h4:first-of-type {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.callout {
  background: #fff8e6;
  border: 1px solid #f2ddaa;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.83rem;
  color: #5c4a10;
  margin-bottom: 14px;
}

.callout div + div {
  margin-top: 6px;
}

/* ==========================================================================
   Reference panel — SOR reference table
   ========================================================================== */

#sorRefBody td:first-child {
  white-space: normal;
}

#sorRefBody tr.group-start td {
  border-top: 2px solid var(--border);
}

#sorRefBody tr.group-total td {
  font-weight: 700;
  background: #fbf8f5;
}

/* ==========================================================================
   Reference panel — Column Mapping table
   ========================================================================== */

#columnMappingTable {
  min-width: 900px;
}

#columnMappingTable .mapping-number-cell,
#columnMappingTable tbody td:first-child {
  display: none;
}

#columnMappingTable th:nth-child(2),
#columnMappingTable td:nth-child(2) {
  width: 20%;
}

#columnMappingTable th:nth-child(3),
#columnMappingTable td:nth-child(3) {
  width: 25%;
}

#columnMappingTable th:nth-child(4),
#columnMappingTable td:nth-child(4) {
  width: 18%;
}

#columnMappingTable th:nth-child(5),
#columnMappingTable td:nth-child(5) {
  width: 37%;
}

/* Multi-line mapping cells: align to the top, give wrapped lines breathing
   room, and zebra-stripe the rows so the eye can track the full mapping. */
#tabPanelConversions td {
  vertical-align: top;
  line-height: 1.55;
  padding-top: 11px;
  padding-bottom: 11px;
}

#tabPanelConversions tbody tr:nth-child(even) {
  background: #faf7f4;
}

#tabPanelConversions tbody tr:hover {
  background: #fffaf0;
}

#tabPanelConversions td:nth-child(2) {
  font-weight: 600;
  white-space: normal;
}

/* The global tbody td rule is white-space: nowrap, which forces long cells into
   one line and a wide horizontal scroll on smaller screens. Let the descriptive
   columns wrap; min-widths keep them from being squeezed unreadably narrow. */
#tabPanelConversions th:last-child,
#tabPanelConversions td:last-child {
  white-space: normal;
  overflow-wrap: anywhere;
}

/* Source field(s) and Raw value in file columns wrap too, so multi-field
   derivations (e.g. SUB CMB LIMIT TEST's four source fields) don't stretch
   the table. code chunks break at the field-name level, not mid-name. */
#tabPanelConversions th:nth-child(3),
#tabPanelConversions td:nth-child(3) {
  white-space: normal;
}

#tabPanelConversions th:nth-child(4),
#tabPanelConversions td:nth-child(4) {
  white-space: normal;
}

#tabPanelConversions td code {
  white-space: nowrap; /* wrap between field names, never inside one */
}

/* TEST NOTES column: fail reasons wrap instead of stretching the table, and stay
   visually quiet next to the PASS/FAIL badges. */
.test-notes {
  display: block;
  white-space: normal;
  min-width: 320px;
  max-width: 460px;
  font-size: 0.76rem;
  color: var(--muted);
}

.review-notes-button {
  padding: 4px 8px;
  border: 1px solid #c9a8b6;
  border-radius: 4px;
  background: #fff;
  color: var(--maroon);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.review-notes-button:hover {
  border-color: var(--maroon);
  background: #fbf1f4;
}

.review-notes-button:focus-visible,
.review-notes-dialog-close:focus-visible {
  outline: 2px solid var(--maroon);
  outline-offset: 2px;
}

.review-notes-dialog {
  width: min(680px, calc(100vw - 32px));
  max-width: none;
  max-height: min(82vh, 760px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
}

.review-notes-dialog::backdrop {
  background: rgba(26, 26, 26, 0.48);
}

.review-notes-dialog-shell {
  display: flex;
  max-height: min(82vh, 760px);
  flex-direction: column;
}

.review-notes-dialog-header {
  display: flex;
  flex: 0 0 auto;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  background: #faf9f7;
  color: var(--ink);
}

.review-notes-dialog-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
}

.review-notes-dialog-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.4;
}

.review-notes-dialog-close {
  display: inline-grid;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-family: inherit;
  font-size: 1.25rem;
  line-height: 1;
}

.review-notes-dialog-close:hover {
  border-color: #aaa;
  background: #f2f2f2;
}

.review-notes-dialog-body {
  min-height: 0;
  padding: 18px 20px 22px;
  overflow-y: auto;
}

.review-notes-list {
  display: grid;
  gap: 12px;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  white-space: normal;
}

.review-notes-list li {
  padding-left: 10px;
  border-left: 3px solid #d7b14d;
}

.review-note-heading,
.review-note-summary,
.review-note-detail {
  display: block;
}

.review-note-heading {
  margin-bottom: 2px;
  color: var(--ink);
  font-size: 0.76rem;
}

.review-note-summary {
  color: #444;
  font-size: 0.76rem;
  line-height: 1.45;
}

.review-note-detail {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.73rem;
  line-height: 1.4;
}

@media (max-width: 640px) {
  .review-notes-dialog {
    width: 100vw;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .review-notes-dialog-shell {
    height: 100dvh;
    max-height: none;
  }

  .review-notes-dialog-header {
    padding: 16px;
  }

  .review-notes-dialog-body {
    padding: 16px 16px 24px;
  }
}
