/* valuation: page styles on top of the design-system primitives in /styles.css.
   Tokens only (var(--...)); no hex, no rgba, no new hues. */

/* The screen toggles sections with the hidden attribute; several of them carry
   classes that set display, so hidden must win inside the page. */
.val-page [hidden] { display: none !important; }
.val-page { display: flex; flex-direction: column; min-width: 0; }

/* The "New book" hero action belongs to the library only. */
.val-page:has(#library-section[hidden]) > .page-head .page-actions { display: none; }

/* ── Shared bits ─────────────────────────────────────────────────── */
.val-meta { font-size: var(--fs-meta); color: var(--ink-3); margin: 0; }
.val-strong { font-weight: 600; color: var(--ink); }
.val-grow { flex: 1; min-width: 0; }
.val-ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.val-nowrap { white-space: nowrap; }
.val-dim { color: var(--ink-3); }
.val-alert-text { color: var(--alert-ink); font-size: var(--fs-meta); }
.val-good-ic { display: inline-grid; place-items: center; color: var(--good); }

.val-section { display: flex; flex-direction: column; gap: 16px; }
.val-sec-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.val-sec-head--stack { flex-direction: column; align-items: flex-start; gap: 4px; }
.val-sec-head h2 { font-size: var(--fs-section); }

/* A thin progress bar (confirm queue, PDF extraction). The fill's width is set inline. */
.val-bar { display: block; height: 4px; border-radius: 4px; background: var(--line-2); overflow: hidden; }
.val-bar > span { display: block; height: 100%; width: 0; background: var(--green); border-radius: inherit; transition: width 300ms var(--ease-out); }
.val-bar--thin { height: 3px; }

/* ── Library ─────────────────────────────────────────────────────── */
.val-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.val-card {
  position: relative; display: flex; flex-direction: column; gap: 8px; min-width: 0;
  padding: 20px; cursor: pointer;
  transition: border-color 200ms var(--ease-out), box-shadow 300ms var(--ease-out), opacity 200ms;
}
.val-card[role="button"]:hover { border-color: color-mix(in oklch, var(--line) 40%, var(--ink-3)); box-shadow: var(--shadow); }
.val-card:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: var(--r-lg); }
.val-card--loading { opacity: .55; pointer-events: none; }
.val-card-name { font-size: var(--fs-lead); font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.val-card-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: var(--fs-meta); color: var(--ink-2); }
.val-card-foot { display: flex; align-items: center; gap: 8px; margin-top: 4px; min-height: 34px; }
.val-card-foot > .val-meta { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.val-card-actions { display: inline-flex; align-items: center; gap: 4px; opacity: 0; transition: opacity 160ms var(--ease-out); }
.val-card:hover .val-card-actions,
.val-card:focus-within .val-card-actions { opacity: 1; }
@media (hover: none) { .val-card-actions { opacity: 1; } }
.val-rename-input { height: 32px; padding: 0 8px; font-size: var(--fs-lead); font-weight: 600; }

/* ── Upload ──────────────────────────────────────────────────────── */
.val-upload { display: flex; flex-direction: column; gap: 20px; }
.val-upload-head { display: flex; flex-direction: column; gap: 6px; }
.val-upload-head h2 { font-size: var(--fs-section); }
.val-drop {
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  padding: 40px 24px; border: 1.5px dashed var(--line); border-radius: var(--r-lg);
  cursor: pointer; transition: border-color 160ms var(--ease-out), background 160ms var(--ease-out);
}
.val-drop:hover, .val-drop.drag-over { border-color: var(--ink-3); background: var(--soft); }
.val-drop--compact { padding: 28px 20px; }
.val-drop-icon { width: 44px; height: 44px; border-radius: var(--r-md); display: grid; place-items: center; background: var(--soft); color: var(--ink-2); margin-bottom: 4px; }
.val-drop:hover .val-drop-icon, .val-drop.drag-over .val-drop-icon { background: var(--panel); }
.val-drop-title { font-size: var(--fs-body); font-weight: 600; }
.val-drop .btn { margin-top: 6px; pointer-events: none; }
.val-run { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ── Results ─────────────────────────────────────────────────────── */
.val-results { display: flex; flex-direction: column; gap: 28px; }
/* While the confirmation queue is active the results section shows ONLY the
   confirmation card; summary, banner, table and resolve panel return once
   every group is confirmed (onAllConfirmationsDone lifts .confirming). */
#results-section.confirming > :not(#confirm-card) { display: none !important; }

.val-sum { display: flex; flex-direction: column; gap: 24px; }
.val-hero { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.val-hero .figure--hero { overflow-wrap: anywhere; }
.val-sum .figures > * { align-items: flex-start; }
.val-errors-link { margin-top: 2px; }
.val-errors-link svg { color: var(--alert); }

/* Unresolved insurers (caution banner) */
.val-ins-banner { align-items: flex-start; }
.val-ins-hint { margin: 4px 0 8px; color: var(--ink-2); font-size: var(--fs-meta); }
.val-ins-list { display: flex; flex-direction: column; }
.val-ins-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid color-mix(in oklch, var(--caution) 22%, transparent); }
.val-ins-main { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 4px 12px; flex-wrap: wrap; }

/* Confirmation card */
.val-confirm { width: 100%; max-width: 600px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; box-shadow: var(--shadow); }
.val-progress-head { display: flex; justify-content: space-between; align-items: baseline; font-size: var(--fs-meta); color: var(--ink-3); }
.val-progress-head + .val-bar { margin-top: -8px; }
.val-submitted {
  display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center;
  padding: 20px; margin-top: 8px; border-radius: var(--r-md); background: var(--soft);
}
.val-submitted-name { font-size: var(--fs-title); font-weight: 700; letter-spacing: -0.025em; line-height: 1.2; margin-top: 6px; overflow-wrap: anywhere; }
.val-confirm-ctx { text-align: center; font-size: var(--fs-meta); color: var(--ink-3); min-height: 20px; }
.val-options { display: flex; flex-direction: column; gap: 8px; }
.val-hint { font-size: var(--fs-meta); }
.val-option {
  display: flex; flex-direction: column; align-items: stretch; gap: 4px; width: 100%;
  padding: 14px 16px; text-align: left;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--panel); color: var(--ink);
  transition: border-color 160ms var(--ease-out), background 160ms var(--ease-out), transform 160ms var(--ease-out);
}
.val-option:hover { border-color: var(--ink-3); background: var(--soft); }
.val-option:active { transform: scale(.99); }
.val-option-main { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.val-option-name { flex: 1; min-width: 0; font-size: var(--fs-body); font-weight: 600; }
.val-option-rate { margin-left: auto; font-weight: 600; }
.val-option--none { align-items: center; text-align: center; border-style: dashed; color: var(--ink-2); font-size: var(--fs-ui); background: transparent; }
.val-remember { font-size: var(--fs-ui); color: var(--ink-2); }
.val-confirm-foot { display: flex; justify-content: center; }
.val-confirm-foot:not(:has(> :not([hidden]))) { display: none; }

/* Results table */
.val-table-sec { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.val-table-head { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; }
.val-table-title { display: flex; align-items: baseline; gap: 10px 12px; flex-wrap: wrap; min-width: 0; }
.val-table-title h2 { font-size: var(--fs-section); }
.val-table-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.val-saved { font-size: var(--fs-meta); color: var(--ink-3); white-space: nowrap; }
.val-saved.val-saved--error { color: var(--caution-ink); }
.val-conflicts-btn svg { color: var(--caution); }
.val-pdf-wrap { position: relative; display: inline-flex; }
.val-pdf-wrap > .val-bar { position: absolute; left: 10px; right: 10px; bottom: -7px; }
.val-pdf-done svg { color: var(--good); }

.val-toolbar { display: flex; gap: 10px; flex-wrap: wrap; }
.val-toolbar select { width: auto; min-width: 180px; max-width: 100%; }

.val-fund {
  display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap;
  padding: 12px 16px; border-radius: var(--r-md); background: var(--soft);
}
.val-fund-label { margin: 0; font-size: var(--fs-ui); font-weight: 600; color: var(--ink); }
.val-fund-input { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-3); font-size: var(--fs-ui); }
.val-fund-input input { width: 76px; height: 34px; text-align: right; font-weight: 600; -moz-appearance: textfield; appearance: textfield; }
.val-fund-input input::-webkit-outer-spin-button,
.val-fund-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.val-fund-only { margin-left: auto; font-size: var(--fs-ui); color: var(--ink-2); }

/* Fixed layout: column widths are computed once, not re-measured across
   2,000+ rows on every DOM change. */
.val-table { table-layout: fixed; min-width: 1040px; }
.val-table th, .val-table td { font-size: var(--fs-meta); padding: 9px 6px; }
.val-table th { font-size: var(--fs-min); }
.val-table th:first-child, .val-table td:first-child { padding-left: 0; }
.val-table th:last-child, .val-table td:last-child { padding-right: 0; }
.val-col-client { width: 128px; }
.val-col-insurer { width: 84px; }
.val-col-policy_number { width: 100px; }
.val-col-issue_date { width: 92px; }
.val-col-year { width: 46px; }
.val-col-premium { width: 96px; }
.val-col-share { width: 58px; }
.val-col-rate { width: 76px; }
.val-col-valuation { width: 100px; }
.val-col-confidence { width: 112px; }
.val-sort-th { cursor: pointer; user-select: none; transition: color 140ms; }
.val-sort-th:hover, .val-sort-th--on { color: var(--ink); }
.val-sort-ind { display: inline-flex; vertical-align: -2px; margin-left: 4px; }
.val-row-empty td { background: color-mix(in oklch, var(--tint-y) 45%, transparent); }
.val-empty-row td { padding: 0; }
.val-freed { font-style: italic; color: var(--ink-3); }
.val-tags { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }

/* Editable cells: seamless until hovered or focused. */
.val-cell-input {
  height: 30px; padding: 0 6px; min-width: 0; text-align: right;
  font-size: var(--fs-meta); font-variant-numeric: tabular-nums;
  background: transparent; border-color: transparent; border-radius: var(--r-xs);
  -moz-appearance: textfield; appearance: textfield;
}
.val-cell-input::-webkit-outer-spin-button,
.val-cell-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.val-cell-input:hover { border-color: var(--line); }
.val-cell-input:focus { background: var(--panel); }
.val-cell-input--empty::placeholder { color: var(--caution-ink); }

/* ── Resolve panel ───────────────────────────────────────────────── */
.val-resolve { display: flex; flex-direction: column; gap: 16px; }
.val-groups { display: flex; flex-direction: column; gap: 10px; }
.val-group { border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; transition: border-color 200ms; }
.val-group--ok { border-color: color-mix(in oklch, var(--good) 35%, var(--line)); }
.val-group-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.val-group-id { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; min-width: 0; }
.val-group-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.val-insurer-select { width: auto; max-width: 240px; height: 34px; font-size: var(--fs-ui); }
.val-subpanel { display: flex; flex-direction: column; gap: 12px; padding: 14px; border-radius: var(--r-md); background: var(--soft); }
.val-subpanel .menu { background: var(--panel); }
.val-subpanel > .btn, .val-subpanel > .check-label { align-self: flex-start; }
.val-picked { display: flex; align-items: baseline; gap: 4px 10px; flex-wrap: wrap; }
.val-create h3 { font-size: var(--fs-body); }
.val-create-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.val-create-grid .field { margin: 0; }
.val-brackets { display: flex; flex-direction: column; gap: 8px; }
.val-brackets:empty { display: none; }
.val-bracket-row { display: flex; align-items: center; gap: 8px; }
.val-bracket-row input { width: 140px; }
.val-create-foot { padding-top: 12px; border-top: 1px solid var(--line); }
.val-resolved > summary {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; list-style: none;
  font-size: var(--fs-ui); font-weight: 500; color: var(--ink-2);
}
.val-resolved > summary::-webkit-details-marker { display: none; }
.val-resolved > summary:hover { color: var(--ink); }
.val-resolved > summary svg { transition: transform 200ms var(--ease-out); }
.val-resolved[open] > summary svg { transform: rotate(90deg); }
.val-resolved > .val-groups { margin-top: 12px; }

/* ── Dialog contents ─────────────────────────────────────────────── */
.val-dlg-search { margin-bottom: 10px; }
.val-pick-list {
  max-height: 320px; overflow-y: auto; overscroll-behavior: contain;
  border: 1px solid var(--line); border-radius: var(--r-md);
}
.val-pick-list > button { height: auto; min-height: 40px; padding: 8px 10px; }
.val-list { display: flex; flex-direction: column; }
.val-list-row { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line-2); }
.val-list-row:first-child { border-top: 0; padding-top: 0; }
.val-list-row--stack { flex-direction: column; align-items: flex-start; gap: 2px; }
.val-cf-line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.val-pdf-status { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; margin-bottom: 14px; border-radius: var(--r-md); background: var(--soft); }
.val-pdf-status-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.val-files { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.val-files:empty { display: none; }
.val-file { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 12px; border: 1px solid var(--line); border-radius: var(--r-md); font-size: var(--fs-ui); color: var(--ink-2); }
.val-file .icon-btn { width: 32px; height: 32px; }

/* ── Small screens ───────────────────────────────────────────────── */
@media (max-width: 640px) {
  .val-create-grid { grid-template-columns: 1fr; }
  .val-ins-row { flex-wrap: wrap; }
  .val-fund-only { margin-left: 0; }
  .val-toolbar select { flex: 1 1 160px; min-width: 0; }
  .val-submitted-name { font-size: 22px; }
}
