/* ============================================================================
   Hub forms & overlays — the shared component layer for any Hub app that has
   an upload drawer, a document reader, data-entry fields, or loading/empty
   states. Extracted verbatim from the utilities module so utilities and
   mortgage (and future apps) share ONE source of truth instead of each page
   re-declaring the drawer/reader/form chrome.

   Load AFTER css/hub.css (it depends on the canonical tokens) and BEFORE any
   page-local <style> (so an app can still override a primitive if it must).

   App-specific bits stay page-local — e.g. utilities' meter segmented control
   (.meter-seg / .meter-sw) lives in utilities.html, not here.
   ========================================================================= */

/* ──────────────────────────────────────────────────────────────────────────
   States: loading, empty
   ────────────────────────────────────────────────────────────────────────── */
.loading-bar {
  height: 1px; background: var(--line);
  position: relative; overflow: hidden;
}
.loading-bar::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(to right, transparent, var(--text-secondary), transparent);
  transform: translateX(-100%);
  animation: shimmer 1400ms linear infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }

.empty {
  font-family: 'Migra', serif; font-style: italic; font-weight: 200;
  font-size: clamp(1.5rem, 4vw, 2rem); line-height: 1.3;
  color: var(--text-muted);
  max-width: 32ch;
}

/* ──────────────────────────────────────────────────────────────────────────
   Drawer (native <dialog>)
   ────────────────────────────────────────────────────────────────────────── */
dialog.drawer {
  background: var(--ground);
  color: var(--text);
  border: none;
  padding: 0;
  margin: 0; margin-left: auto;     /* anchor right edge on desktop */
  width: 100%;
  max-width: 480px;
  min-height: 100vh; max-height: 100vh;
  border-left: 1px solid var(--line);
}
dialog.drawer::backdrop {
  background: oklch(0.10 0.012 305 / 0.6);
  backdrop-filter: none;
}
dialog.drawer[open] { animation: slide-in var(--dur-slow) var(--ease-out) forwards; }
@keyframes slide-in {
  from { transform: translateX(40px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@media (max-width: 640px) {
  dialog.drawer {
    max-width: 100%;
    border-left: none;
    margin: 0 auto;
  }
}
@media (prefers-reduced-motion: reduce) {
  dialog.drawer[open] { animation: none; }
}

.drawer-inner {
  padding: var(--space-2xl) var(--space-2xl);
  padding-bottom: max(var(--space-2xl), env(safe-area-inset-bottom));
  padding-top: max(var(--space-2xl), env(safe-area-inset-top));
  display: flex; flex-direction: column; gap: var(--space-lg);
  min-height: 100vh;
}

.drawer-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: var(--space-md);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--line);
}
.drawer-eyebrow {
  font-size: var(--t-eyebrow); letter-spacing: 0.4em; text-transform: uppercase;
  color: var(--text-muted);
}
.drawer-close {
  background: none; border: none; padding: var(--space-2xs);
  color: var(--text-muted);
  font: inherit;
  font-size: var(--t-eyebrow); letter-spacing: 0.3em; text-transform: uppercase;
}
.drawer-close:hover { color: var(--text); }

.drawer-title {
  font-family: 'Migra', serif; font-weight: 800;
  font-size: clamp(2rem, 6vw, 2.75rem); line-height: 0.96;
  letter-spacing: -0.015em; color: var(--text);
}
.drawer-title .it { font-weight: 200; font-style: italic; }
.drawer-helper {
  font-family: 'Migra', serif; font-style: italic; font-weight: 200;
  color: var(--text-secondary);
  font-size: var(--t-lead); line-height: 1.5; max-width: 30ch;
}

/* Shared text-link affordance inside the drawer */
.linklike {
  background: none; border: none; padding: 0; font: inherit;
  color: var(--text); text-underline-offset: 4px;
  text-decoration: underline; text-decoration-color: var(--text-faint);
  transition: text-decoration-color var(--dur-mid) var(--ease-out), color var(--dur-mid) var(--ease-out);
}
.linklike:hover { text-decoration-color: var(--text); }
.linklike.muted { color: var(--text-muted); }
.linklike.muted:hover { color: var(--text); }
.linklike:focus-visible { outline: 1px solid var(--text); outline-offset: 3px; }

/* Step: Drop — the whole panel is the target, no dashed box */
.dropzone {
  margin-top: var(--space-xl);
  min-height: 220px;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-lg);
  border: 1px solid var(--line);
  background:
    linear-gradient(var(--ground), var(--ground)) padding-box,
    repeating-linear-gradient(transparent 0 11px, var(--line-soft) 11px 12px) border-box;
  transition: background-color var(--dur-mid) var(--ease-out),
              border-color var(--dur-mid) var(--ease-out),
              box-shadow var(--dur-mid) var(--ease-out);
}
.dropzone.is-drag {
  background-color: var(--veil);
  border-color: var(--text);
  box-shadow: inset 0 0 0 1px var(--text);
}
.dropzone-cue {
  font-family: 'Migra', serif; font-style: italic; font-weight: 200;
  font-size: var(--t-h3); color: var(--text-secondary);
  pointer-events: none;
}
.dropzone.is-drag .dropzone-cue { color: var(--text); }
.dropzone-aside { margin-top: var(--space-md); font-size: var(--t-meta); }
.drop-msg {
  margin-top: var(--space-sm);
  font-family: 'Migra', serif; font-style: italic; font-weight: 200;
  font-size: var(--t-lead); color: var(--error);
}

/* Step: Reading — calm, determinate sweep */
.ellip::after {
  content: '…';
  animation: ellip-pulse 1.4s steps(4, end) infinite;
  clip-path: inset(0 100% 0 0);
}
@keyframes ellip-pulse { to { clip-path: inset(0 0 0 0); } }
.reading-file {
  margin-top: var(--space-md);
  font-size: var(--t-meta); letter-spacing: 0.04em;
  color: var(--text-muted); font-variant-numeric: tabular-nums;
}
.reading-sweep {
  margin-top: var(--space-lg);
  height: 1px; background: var(--line); overflow: hidden;
}
.reading-sweep-fill {
  display: block; height: 100%; width: 40%;
  background: var(--accent);
  animation: sweep 1.1s var(--ease-out) infinite;
}
@keyframes sweep {
  from { transform: translateX(-100%); }
  to   { transform: translateX(350%); }
}
.reading-detected {
  margin-top: var(--space-lg);
  font-family: 'Migra', serif; font-style: italic; font-weight: 200;
  font-size: var(--t-lead); color: var(--text);
}
@media (prefers-reduced-motion: reduce) {
  .reading-sweep-fill { animation: none; width: 100%; opacity: 0.5; }
  .ellip::after { animation: none; clip-path: none; }
}

/* Step: Review — header with source line */
.review-head { display: flex; flex-direction: column; gap: var(--space-md); }
.review-source {
  font-size: var(--t-meta); color: var(--text-muted);
  display: flex; align-items: baseline; gap: var(--space-sm); flex-wrap: wrap;
}

/* Already-filed notice — a duplicate exists. Full border, not a stripe. */
.dup-note {
  font-size: var(--t-meta); color: var(--text-secondary);
  display: flex; align-items: baseline; gap: var(--space-sm); flex-wrap: wrap;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--accent);
  background: color-mix(in oklch, var(--accent) 8%, transparent);
}

/* Quiet "we couldn't read this — check it" marker (never a red stripe) */
.check-flag {
  font-size: var(--t-eyebrow); letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--accent); margin-left: var(--space-xs);
}
.form-row.needs-check input { border-color: var(--accent); }

/* Data-entry fields */
.form-row { display: flex; flex-direction: column; gap: var(--space-xs); }
.form-row label, .form-legend {
  font-size: var(--t-eyebrow); letter-spacing: 0.35em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 500;
}
.form-row .period-pair {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md);
}
.form-row .num-with-suffix, .form-row .num-with-prefix {
  display: flex; align-items: baseline; gap: var(--space-xs);
  border-bottom: 1px solid var(--text-faint);
  padding-bottom: var(--space-2xs);
  transition: border-bottom-color var(--dur-mid) var(--ease-out);
}
.form-row .num-with-suffix:focus-within,
.form-row .num-with-prefix:focus-within,
.form-row input[type="date"]:focus { border-color: var(--text); }
.form-row input {
  background: transparent;
  border: none;
  color: var(--text);
  font: inherit;
  font-size: var(--t-lead);
  font-variant-numeric: tabular-nums;
  outline: none;
  flex: 1;
  caret-color: var(--accent);
  width: 100%;
}
.form-row input[type="date"] {
  border-bottom: 1px solid var(--text-faint);
  padding: var(--space-xs) 0;
  color-scheme: dark;
}
.form-row .suffix, .form-row .prefix {
  font-family: 'Migra', serif; font-style: italic; font-weight: 200;
  font-size: var(--t-lead); color: var(--text-muted);
}
.form-row .period-aside {
  font-family: 'Migra', serif; font-style: italic; font-weight: 200;
  font-size: var(--t-meta); color: var(--text-muted);
}

/* Generic collapsible (utilities' itemize; mortgage's transaction lines) */
.itemize {
  margin-top: var(--space-xs);
  border: 1px solid var(--line-soft);
  padding: 0;
}
.itemize summary {
  list-style: none;
  padding: var(--space-md);
  font-size: var(--t-eyebrow); letter-spacing: 0.35em; text-transform: uppercase;
  color: var(--text-muted);
}
.itemize summary::-webkit-details-marker { display: none; }
.itemize[open] summary { border-bottom: 1px solid var(--line-soft); color: var(--text); }
.itemize-grid {
  padding: var(--space-md);
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md);
}

.form-error {
  font-family: 'Migra', serif; font-style: italic; font-weight: 200;
  font-size: var(--t-lead); color: var(--error);
  line-height: 1.4;
}

.drawer-foot {
  margin-top: auto;
  padding-top: var(--space-lg);
  border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
  gap: var(--space-md);
}
.drawer-delete {
  background: none; border: none; color: var(--text-muted);
  font: inherit; font-size: var(--t-eyebrow);
  letter-spacing: 0.3em; text-transform: uppercase;
  padding: var(--space-xs) 0;
}
.drawer-delete:hover { color: var(--error); }
.drawer-save {
  font-family: inherit; font-size: var(--t-eyebrow);
  letter-spacing: 0.35em; text-transform: uppercase; font-weight: 500;
  background: var(--text); color: var(--ground); border: 1px solid var(--text);
  padding: var(--space-md) var(--space-2xl);
  margin-left: auto;
  transition: opacity var(--dur-mid) var(--ease-out);
}
.drawer-save:disabled { opacity: 0.4; }
.drawer-save:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (pointer: fine) {
  .drawer-close, .drawer-save, .drawer-delete { cursor: none; }
  .linklike, .r-cell, .r-stmt-btn, .stmt-attach, .stmt-view, .stmt-act, .reader-close { cursor: none; }
  /* The custom dot/ring cursor lives in normal DOM, so it can't paint into a
     modal <dialog>'s top layer — over the slide-out it would be invisible.
     Restore native cursors inside the drawer and reading view (and their
     backdrops) so they stay usable. Page elements keep the custom cursor. */
  dialog.drawer, dialog.drawer *, dialog.reader, dialog.reader *,
  dialog.drawer::backdrop, dialog.reader::backdrop { cursor: default; }
  dialog.drawer button, dialog.drawer .linklike, dialog.drawer .dropzone,
  dialog.drawer summary, dialog.reader button { cursor: pointer; }
  dialog.drawer input[type="text"], dialog.drawer input[type="date"] { cursor: text; }
}

/* ──────────────────────────────────────────────────────────────────────────
   Statements — drawer row, table mark, reading view.
   Functional voice: Hanken Grotesk, not Migra. Quiet by default; the
   statement is the paper trail, not a feature to advertise.
   ────────────────────────────────────────────────────────────────────────── */
.stmt {
  display: flex; flex-direction: column; align-items: flex-start;
  gap: var(--space-xs);
  font-family: 'Hanken Grotesk', sans-serif;
}
.stmt-attach, .stmt-view, .stmt-act {
  background: none; border: none; padding: var(--space-2xs) 0;
  font: inherit; font-size: var(--t-body);
  color: var(--text-muted);
  text-decoration: underline; text-underline-offset: 4px;
  text-decoration-color: var(--text-faint);
  transition: color var(--dur-mid) var(--ease-out),
              text-decoration-color var(--dur-mid) var(--ease-out);
}
.stmt-view { color: var(--text); text-decoration-color: var(--text-muted); }
.stmt-attach:hover, .stmt-view:hover, .stmt-act:hover {
  color: var(--text); text-decoration-color: var(--text);
}
.stmt-attach:focus-visible, .stmt-view:focus-visible, .stmt-act:focus-visible {
  outline: 1px solid var(--text); outline-offset: 3px;
}
.stmt-filed { display: flex; align-items: baseline; gap: var(--space-lg); }
.stmt-staged { display: flex; align-items: baseline; gap: var(--space-md); }
.stmt-name {
  font-size: var(--t-body); color: var(--text);
  max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.stmt-prog { display: flex; align-items: center; gap: var(--space-md); }
.stmt-prog-track {
  position: relative; display: block;
  width: 140px; height: 2px; background: var(--veil);
}
.stmt-prog-fill {
  position: absolute; inset: 0 auto 0 0; width: 100%;
  background: var(--text); transform: scaleX(0); transform-origin: left;
  transition: transform var(--dur-fast) var(--ease-out);
}
.stmt-prog-label {
  font-size: var(--t-meta); letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--text-muted); font-variant-numeric: tabular-nums;
}
.stmt-msg {
  font-size: var(--t-meta); line-height: 1.5; color: var(--error);
  max-width: 42ch;
}

/* Table per-cell controls + the "documented" mark */
.r-cell {
  background: none; border: none; padding: 0; margin: 0;
  font: inherit; color: inherit; text-align: left;
  transition: color var(--dur-mid) var(--ease-out);
}
.r-cell:hover, .r-cell:focus-visible { color: var(--text); }
.r-cell:focus-visible { outline: 1px solid var(--text); outline-offset: 4px; }
.r-stmt-btn {
  display: inline-flex; align-items: center;
  background: none; border: none; padding: 4px;
  margin-left: var(--space-sm); vertical-align: middle;
  color: var(--text-muted); line-height: 0;
  transition: color var(--dur-mid) var(--ease-out);
}
.r-stmt-btn:hover { color: var(--accent); }
.r-stmt-btn:focus-visible { outline: 1px solid var(--text); outline-offset: 2px; color: var(--text); }

/* Reading view — a focused panel, not a generic modal */
dialog.reader {
  background: var(--ground); color: var(--text);
  border: 1px solid var(--line); padding: 0; margin: auto;
  width: min(1100px, 92vw); height: min(90vh, 100%);
  max-width: 92vw; max-height: 92vh;
}
dialog.reader::backdrop {
  background: oklch(0.10 0.012 305 / 0.72); backdrop-filter: none;
}
dialog.reader[open] { animation: reader-in var(--dur-slow) var(--ease-out) forwards; }
@keyframes reader-in {
  from { transform: scale(0.985); opacity: 0; }
  to   { transform: scale(1);     opacity: 1; }
}
.reader-inner { display: flex; flex-direction: column; height: 100%; }
.reader-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: var(--space-md);
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--line);
}
.reader-title {
  font-family: 'Migra', serif; font-weight: 800;
  font-size: var(--t-h3); letter-spacing: -0.01em; color: var(--text);
}
.reader-title .it { font-weight: 200; font-style: italic; }
.reader-close {
  background: none; border: none; padding: var(--space-2xs);
  font-family: 'Hanken Grotesk', sans-serif;
  font-size: var(--t-eyebrow); letter-spacing: 0.3em; text-transform: uppercase;
  color: var(--text-muted);
  transition: color var(--dur-mid) var(--ease-out);
}
.reader-close:hover { color: var(--text); }
.reader-close:focus-visible { outline: 1px solid var(--text); outline-offset: 3px; }
.reader-body {
  flex: 1; min-height: 0; overflow: auto;
  display: grid; place-items: center;
  padding: var(--space-lg);
}
.reader-status {
  font-family: 'Migra', serif; font-style: italic; font-weight: 200;
  font-size: var(--t-lead); color: var(--text-muted);
}
.reader-doc { width: 100%; height: 100%; border: none; background: var(--bone); }
.reader-img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  background: var(--bone); padding: var(--space-lg);
  cursor: zoom-in;
}
.reader-img.zoomed {
  max-width: none; max-height: none; cursor: zoom-out;
  width: auto; height: auto;
}
@media (pointer: fine) { .reader-img { cursor: none; } }
@media (max-width: 640px) {
  dialog.reader { width: 100vw; height: 100vh; max-width: 100vw; max-height: 100vh; border: none; }
}
@media (prefers-reduced-motion: reduce) {
  dialog.reader[open] { animation: none; }
  .stmt-prog-fill { transition: none; }
}

[hidden] { display: none !important; }
</content>
