/* ==========================================================================
   DOC DETAIL PAGE — Redesigned UI
   Extracted from style.css; styles for doc-detail-page.js.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Doc Detail Layout
   -------------------------------------------------------------------------- */
.doc-detail {
  display: grid;
  grid-template-columns: 1fr var(--pdf-panel-width, 40%);
  /* top bar / title bar / live line / content row. Rows must be declared:
     with every track implicit `auto`, `align-content: stretch` splits the
     slack up to the 100vh floor EVENLY across all of them, so the chrome
     bands inflate on a short page. `1fr` is `minmax(auto, 1fr)` — the content
     row absorbs the slack and never shrinks below its content. The tab strip
     is `display: none` up here, so it generates no track; the ≤1024 override
     below adds its row (without that override the `1fr` would land on the
     tab strip).
     The THIRD `auto` is .doc-live-line, which spans 1 / -1 like the two bands
     above it. Count the full-bleed bands when you add one: an undeclared row
     makes `1fr` land on the band instead of the content. */
  grid-template-rows: auto auto auto 1fr;
  min-height: 100vh;
  transition: grid-template-columns 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: grid-template-columns;
}

.doc-detail.pdf-collapsed {
  grid-template-columns: 1fr 0px;
}

.doc-detail.pdf-collapsed .pdf-panel {
  overflow: hidden;
  border-left: none;
  width: 0;
  min-width: 0;
}

.doc-detail.pdf-collapsed .doc-detail-content {
  border-right: none;
}

.doc-detail-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--ink-06);
}

/* --------------------------------------------------------------------------
   Doc Consolidated Top Bar — Self-contained sticky bar for doc-detail
   Three-zone flex: left (breadcrumb) | center (stepper) | right (actions)
   Status tint overlay reflects document status with breathing animation.
   -------------------------------------------------------------------------- */
.doc-top-bar {
  grid-column: 1 / -1;
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-5);
  background: var(--color-white);
  border-bottom: 1px solid var(--ink-06);
  min-height: 48px;
  overflow: visible;
  isolation: isolate;
}

/* Status tint overlay — absolute fill behind bar content */
.doc-top-bar::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  border-radius: 0;
  transition: background 0.4s ease;
}

/* Status tint colors — 4% opacity washes */
.doc-top-bar[data-tint="processing"]::before {
  background: rgba(31, 122, 212, 0.04);
  animation: tint-breathe-bg 5s ease-in-out infinite;
}
.doc-top-bar[data-tint="error"]::before {
  background: rgba(227, 66, 52, 0.04);
}
.doc-top-bar[data-tint="reviewed"]::before {
  background: rgba(59, 117, 88, 0.035);
}
.doc-top-bar[data-tint="needs_review"]::before {
  background: rgba(232, 168, 48, 0.04);
}
.doc-top-bar[data-tint="not_relevant"]::before {
  background: var(--ink-03);
}

/* Breathing animation — smooth background-color cycle (4% → 6% → 4%, 5s) */
@keyframes tint-breathe-bg {
  0%, 100% { background: rgba(31, 122, 212, 0.04); }
  50% { background: rgba(31, 122, 212, 0.06); }
}

@media (prefers-reduced-motion: reduce) {
  .doc-top-bar[data-tint="processing"]::before {
    animation: none;
    background: rgba(31, 122, 212, 0.04);
  }
}

/* --- Left zone: back + breadcrumb --- */
.tb-left {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
  flex-shrink: 1;
}

.doc-back-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-40);
  cursor: pointer;
  border: none;
  background: none;
  transition: all 0.1s;
  flex-shrink: 0;
}

.doc-back-btn:hover {
  background: var(--ink-03);
  color: var(--ink);
}

.tb-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 12px;
  color: var(--ink-40);
}

.doc-bc-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.doc-bc-link:hover { text-decoration: underline; }

/* (.doc-bc-sep / .doc-bc-current removed — the breadcrumb carries the
   space only now; DocTopBar no longer renders a filename segment.) */

/* Source attribution chip (Task 17) — neutral ink by default; the portal
   variant is an actual link (Collection tab), so it borrows the
   interactive-green treatment per the design system's "green = interactive"
   rule rather than the logo blue. */
.doc-source-chip {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  background: var(--ink-03);
  color: var(--ink-40);
  border: none;
}

.doc-source-chip--link {
  cursor: pointer;
  background: var(--color-action-soft, rgba(59, 117, 88, 0.07));
  color: var(--color-action, #3B7558);
  transition: background 0.15s ease;
}

.doc-source-chip--link:hover {
  background: var(--color-action-glow, rgba(59, 117, 88, 0.175));
  text-decoration: underline;
}

.doc-source-chip--link:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--color-action-glow, rgba(59, 117, 88, 0.175));
}

[data-theme="dark"] .doc-source-chip {
  background: var(--ink-06, rgba(255, 255, 255, 0.06));
}

/* --- Center zone: pipeline stepper --- */
.tb-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tb-center::-webkit-scrollbar { display: none; }

/* React island wrapper inside center zone */
.tb-center > .ri-root {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Right zone: utility + decision --- */
.tb-right {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
  overflow: visible;
}

.doc-top-bar .nav-band__actions,
.doc-top-bar .nav-band__end {
  overflow: visible;
}

.tb-utility {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tb-decision {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: var(--space-1);
  transition: opacity 80ms ease;
}

/* --------------------------------------------------------------------------
   Document Title Bar — Compact single-line below consolidated bar
   -------------------------------------------------------------------------- */
.doc-title-bar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-5);
  border-bottom: 1px solid var(--ink-06);
  background: var(--color-white);
  min-height: 36px;
}

.doc-title-bar .dtb-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.doc-title-bar .dtb-thumb {
  width: 24px;
  height: 24px;
  display: block;
}

.doc-title-bar .dtb-icon.pdf { background: var(--error-wash); color: var(--error); }
.doc-title-bar .dtb-icon.invoice { background: var(--alembic-wash); color: var(--alembic); }
.doc-title-bar .dtb-icon.image { background: var(--purple-wash); color: var(--purple); }
.doc-title-bar .dtb-icon.contract { background: var(--alembic-wash); color: var(--alembic); }
.doc-title-bar .dtb-icon.default { background: var(--ink-06); color: var(--ink-40); }

.doc-title-bar .dtb-title {
  flex: 1;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.3;
  letter-spacing: -0.15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.doc-title-bar .dtb-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 11px;
  color: var(--ink-40);
  flex-shrink: 0;
}

.doc-title-bar .dtb-chip {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--ink-06);
  background: var(--color-white);
}

.doc-title-bar .dtb-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--ink-12);
  flex-shrink: 0;
}

/* (.doc-cost-badge removed — processing cost moved from the title bar into
   the review card's quiet accounting footer, .drc-cost-line.) */

/* Utility icon buttons */
.tb-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-40);
  cursor: pointer;
  transition: all 0.15s ease;
}
.tb-icon-btn:hover { background: var(--ink-04); color: var(--ink-70); }
.tb-icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.tb-icon-btn:disabled:hover { background: transparent; }

/* Re-extract button — state variants */
.tb-icon-btn--error { color: var(--error); }
.tb-icon-btn--error:hover { background: var(--error-wash); color: var(--error); }
.tb-icon-btn--warn { color: var(--warn); }
.tb-icon-btn--warn:hover { background: var(--warn-wash); color: var(--warn); }

/* Re-extract: check icon hidden by default, shown on success */
.tb-reextract-check { display: none; }
.tb-icon-btn--done .tb-reextract-icon { display: none; }
.tb-icon-btn--done .tb-reextract-check {
  display: block;
  color: var(--complete);
  animation: tb-check-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.tb-icon-btn--done {
  background: var(--complete-wash);
  border-color: var(--complete);
  opacity: 1 !important;
}

/* Re-extract: working state — spin the icon */
.tb-icon-btn--working .tb-reextract-icon {
  animation: tb-spin 0.8s linear infinite;
}
.tb-icon-btn--working {
  opacity: 0.7;
  pointer-events: none;
}

@keyframes tb-spin {
  to { transform: rotate(-360deg); }
}
@keyframes tb-check-pop {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .tb-icon-btn--working .tb-reextract-icon { animation: none; }
  .tb-icon-btn--done .tb-reextract-check { animation: none; }
  .skeleton-line { animation: none; opacity: 0.7; }
  .field-flash { animation: none; }
  .tb-reject-chips { animation: none; }
  .tb-reject-input-row { animation: none; }
}

/* Export dropdown */
.tb-export-dropdown { position: relative; }
.tb-export-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--color-white);
  border: 1px solid var(--ink-12);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 10;
  min-width: 140px;
}
.tb-export-dropdown.open .tb-export-menu { display: block; }
.tb-export-option {
  display: block;
  width: 100%;
  padding: 8px 14px;
  border: none;
  background: none;
  text-align: left;
  font-size: 13px;
  color: var(--ink-70);
  cursor: pointer;
}
.tb-export-option:hover { background: var(--ink-04); color: var(--ink); }

/* Legacy .tb-btn kept for backward compat — new buttons use .al-btn */
.tb-btn {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid var(--ink-12);
  background: var(--color-white);
  color: var(--ink-60);
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.tb-btn:hover { border-color: var(--ink-25); color: var(--ink-80); }
.tb-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Status badges (post-decision) */
.tb-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
}
.tb-badge-approved { background: var(--color-green-bg); color: var(--color-green-text); }
.tb-badge-rejected { background: var(--color-red-bg); color: var(--color-red-text); }
/* Outcome Model v2 — waiting (pending) and working (open) outcome states */
.tb-badge-pending { background: var(--color-amber-bg); color: var(--color-amber-text); }
.tb-badge-open { background: var(--ink-04); color: var(--ink-70); }

/* .tb-undo-btn removed — undo now uses .al-btn--ghost */

/* Inline Reject Flow (chips -> input) */
.tb-reject-chips {
  display: flex;
  align-items: center;
  gap: 4px;
  animation: ep-slide-in 200ms ease;
}
.tb-reject-chip {
  padding: 4px 10px;
  border-radius: 100px;
  border: 1px solid var(--ink-12);
  background: var(--color-white);
  color: var(--ink-70);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.12s ease;
}
.tb-reject-chip:hover {
  border-color: var(--color-red);
  color: var(--color-red-text);
  background: var(--color-red-bg);
}
.tb-reject-cancel {
  padding: 4px 8px;
  border: none;
  background: none;
  color: var(--ink-30);
  font-size: 11px;
  cursor: pointer;
}
.tb-reject-cancel:hover { color: var(--ink-60); }

.tb-reject-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
  animation: ep-slide-in 150ms ease;
}
.tb-reject-input {
  width: 240px;
  padding: 5px 10px;
  border: 1px solid var(--color-red);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: var(--font-body);
  color: var(--ink);
  outline: none;
}
.tb-reject-input::placeholder { color: var(--ink-30); }
.tb-reject-input:focus { box-shadow: 0 0 0 2px var(--color-red-bg); }
.tb-reject-confirm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--color-red);
  color: white;
  cursor: pointer;
  transition: filter 0.15s cubic-bezier(0, 0, 0.2, 1);
}
.tb-reject-confirm:hover { filter: brightness(1.1); }

@keyframes ep-slide-in {
  from { opacity: 0; transform: translateX(8px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Status banner + pipeline expanded panel removed — stepper is now in topbar */

/* --------------------------------------------------------------------------
   Scroll Body + Section Nav Rail
   -------------------------------------------------------------------------- */
.scroll-body {
  flex: 1;
  display: flex;
  position: relative;
}

.section-nav {
  width: 160px;
  flex-shrink: 0;
  padding: 20px 0 20px 24px;
  position: sticky;
  top: 0;
  height: fit-content;
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  transition: width 0.2s ease, padding 0.2s ease;
}

.section-nav.collapsed {
  width: 40px;
  padding-left: 12px;
  padding-right: 4px;
}

.section-nav.collapsed .sn-item-label,
.section-nav.collapsed .sn-label,
.section-nav.collapsed .sn-collapse-btn svg {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

.section-nav.collapsed .sn-item {
  padding: 6px 4px;
  justify-content: center;
}

.section-nav.collapsed .sn-collapse-btn {
  transform: rotate(180deg);
}

.sn-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sn-label {
  font-size: 9px;
  font-weight: 600;
  color: var(--ink-25);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.sn-collapse-btn {
  width: 20px;
  height: 20px;
  border: none;
  background: none;
  color: var(--ink-25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

.sn-collapse-btn:hover { background: var(--ink-06); color: var(--ink-60); }

.sn-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--ink-40);
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 2px;
  border-left: 2px solid transparent;
}

.sn-item:hover { color: var(--ink-60); background: var(--ink-03); }

.sn-item.active {
  color: var(--alembic);
  border-left-color: var(--alembic);
  background: var(--alembic-ghost);
  font-weight: 500;
}

.sn-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}
.sn-dot.complete { background: var(--complete); }
.sn-dot.warn { background: var(--warn); }
.sn-dot.neutral { background: var(--ink-12); }

.sn-item-label {
  transition: opacity 0.2s ease;
}

/* --------------------------------------------------------------------------
   Doc Scroll Content
   -------------------------------------------------------------------------- */
.doc-scroll-content {
  flex: 1;
  padding: 20px 28px 60px 20px;
  min-width: 0;
  max-width: 1200px;
}

/* Old .doc-header removed — replaced by compact .doc-title-bar (see consolidated bar section above) */

/* --------------------------------------------------------------------------
   Section Card — Redesigned with icon headers, Fraunces titles
   -------------------------------------------------------------------------- */
.sc-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}

.sc-head:hover { background: var(--ink-03); }

.sc-head-icon {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sc-head-icon.kv { background: var(--alembic-wash); color: var(--alembic); }
.sc-head-icon.table { background: var(--purple-wash); color: var(--purple); }
.sc-head-icon.money { background: var(--complete-wash); color: var(--complete); }
.sc-head-icon.check { background: var(--complete-wash); color: var(--complete); }
.sc-head-icon.text { background: var(--ink-06); color: var(--ink-40); }

.sc-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
  flex: 1;
}

.sc-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sc-field-count {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  color: var(--ink-25);
  background: var(--ink-03);
  padding: 2px 6px;
  border-radius: 3px;
}

.sc-source-pills {
  display: flex;
  gap: 2px;
}

.sc-source-pill {
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--alembic-wash);
  color: var(--alembic);
  cursor: pointer;
  transition: all 0.1s;
  border: 1px solid transparent;
}

.sc-source-pill:hover {
  background: var(--alembic);
  color: white;
}

.sc-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.sc-head:hover .sc-actions { opacity: 1; }

.sc-action {
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--ink-40);
  transition: all 0.1s;
}

.sc-action:hover { background: var(--ink-03); color: var(--ink-60); }

.sc-chevron {
  color: var(--ink-25);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.section-card--collapsed .sc-chevron { transform: rotate(-90deg); }

.sc-body {
  padding: 0 16px 16px;
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.15s ease;
}

.section-card--collapsed .sc-body {
  max-height: 0 !important;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
}

/* Empty section styling */
.section-card--empty {
  border-style: dashed;
  opacity: 0.6;
}

.section-card--empty:hover { opacity: 0.8; }

.section-empty-placeholder {
  color: var(--ink-40);
  font-style: italic;
  font-size: 12px;
  padding: 8px 0;
}

/* --------------------------------------------------------------------------
   Field Grid — 2-column with 1px gap borders
   -------------------------------------------------------------------------- */
.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--ink-06);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.field-grid--empty { opacity: 0.5; }

.field-item {
  padding: 12px 16px;
  background: var(--color-white);
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}

.field-item:hover { background: var(--ink-03); }
.field-item.highlight { background: var(--alembic-ghost); }

.field-item.full-width { grid-column: 1 / -1; }

.field-item--empty .fi-value--empty {
  color: var(--ink-25);
  font-family: var(--font-mono);
  font-size: 13px;
}

.fi-label {
  font-size: 10px;
  color: var(--ink-40);
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.fi-label-name { font-weight: 500; }

/* Validation indicators on fields */
.fi-validation-warning { border-left: 3px solid var(--color-amber); padding-left: 8px; }
.fi-validation-error { border-left: 3px solid var(--color-red); padding-left: 8px; }
.fi-validation-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0;
}
.fi-validation-badge--warning { color: var(--color-amber-text); background: var(--color-amber-bg); }
.fi-validation-badge--error { color: var(--color-red-text); background: var(--color-red-bg); }

.fi-required {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--alembic);
  flex-shrink: 0;
}

.fi-value {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 6px;
}

.fi-value.missing {
  color: var(--warn);
  font-style: italic;
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 12px;
}

.fi-source {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  color: var(--alembic);
  opacity: 0;
  transition: opacity 0.15s;
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--alembic-wash);
  padding: 1px 5px;
  border-radius: 3px;
  cursor: pointer;
}

.fi-source:hover {
  background: var(--alembic-soft, rgba(37, 99, 235, 0.15));
}

.field-item:hover .fi-source { opacity: 1; }

/* Editable field input */
.fi-edit-input {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  background: var(--color-white);
  border: 1px solid var(--alembic);
  border-radius: 4px;
  padding: 2px 6px;
  width: 100%;
  outline: none;
  box-shadow: 0 0 0 3px var(--alembic-wash);
}

.fi-edit-input:not(.active) { display: none; }

/* --------------------------------------------------------------------------
   Table Section — Polished
   -------------------------------------------------------------------------- */
.line-table {
  width: 100%;
  border-collapse: collapse;
}

.line-table th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  color: var(--ink-40);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--ink-06);
  background: var(--ink-03);
}

.line-table th:last-child,
.line-table th.right,
.line-table td.right { text-align: right; }

.line-table td {
  padding: 10px 12px;
  font-size: 12px;
  color: var(--ink-80);
  border-bottom: 1px solid var(--ink-06);
}

.line-table td.mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

.line-table td.bold { font-weight: 600; color: var(--ink); }

.line-table tr:hover td { background: var(--ink-03); }

.line-table tfoot td {
  border-top: 2px solid var(--ink-12);
  border-bottom: none;
  font-weight: 600;
  color: var(--ink);
}

.table-empty-row {
  text-align: center;
  color: var(--ink-40);
  font-style: italic;
  padding: 16px !important;
}

/* --------------------------------------------------------------------------
   Financial / Metrics Grid
   -------------------------------------------------------------------------- */
.fin-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--ink-06);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 10px;
}

.fin-grid--empty { opacity: 0.4; }

.fin-item {
  padding: 14px;
  background: var(--color-white);
  text-align: center;
  cursor: pointer;
  transition: background 0.1s;
}

.fin-item:hover { background: var(--ink-03); }

.fin-amount {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1;
}

.fin-amount.muted { color: var(--ink-25); }
.fin-amount--empty { color: var(--ink-25); }

.fin-label {
  font-size: 9px;
  font-weight: 600;
  color: var(--ink-40);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
}

.fin-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--ink);
  border-radius: var(--radius-md);
  color: white;
}

.fin-total-label {
  font-size: 11px;
  font-weight: 500;
  color: rgba(255,255,255,0.5);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.fin-total-amount {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 500;
}

/* --------------------------------------------------------------------------
   Validation List — Pass/Warn/Fail items
   -------------------------------------------------------------------------- */
.val-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.val-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 12px;
  transition: background 0.1s;
  cursor: default;
}

.val-item:hover { background: var(--ink-03); }

.val-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
}

.val-icon.pass { background: var(--complete-wash); color: var(--complete); }
.val-icon.warn { background: var(--warn-wash); color: var(--warn); }
.val-icon.fail { background: var(--error-wash); color: var(--error); }

.val-text {
  flex: 1;
  color: var(--ink-80);
}

.val-text strong {
  font-weight: 600;
  color: var(--ink);
}

.val-detail {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-40);
}

.val-source-tag {
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 700;
  color: var(--alembic);
  background: var(--alembic-wash);
  padding: 1px 5px;
  border-radius: 3px;
  margin-right: 4px;
}

/* --------------------------------------------------------------------------
   Summary Card — Redesigned
   -------------------------------------------------------------------------- */
.summary-card {
  background: var(--alembic-ghost);
}

.summary-needs-review {
  background: var(--warn-wash);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 12px;
}

.summary-list-header {
  font-size: 11px;
  color: var(--ink-60);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.summary-list-header strong {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-80);
}

.list-count--warn {
  background: var(--warn);
  color: white;
}

.summary-review-list {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  color: var(--ink-80);
  line-height: 1.6;
}

.summary-review-item { margin-bottom: 4px; }

.summary-highlights-section {
  margin-top: 8px;
}

.summary-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.summary-chip {
  font-size: 11px;
  color: var(--ink-60);
  background: var(--ink-03);
  border: 1px solid var(--ink-06);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  line-height: 1.3;
}

/* --------------------------------------------------------------------------
   Skeleton / Loading States
   -------------------------------------------------------------------------- */
.skeleton-line {
  height: 10px;
  background: var(--ink-06);
  border-radius: 4px;
  margin-bottom: 10px;
  animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.text-section--skeleton .skeleton-line {
  height: 10px;
}

.checklist-icon--pending {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px dashed var(--ink-12);
  border-radius: 50%;
}

.checklist-item--empty { opacity: 0.4; }

/* Phase Stepper Static (gated/error overrides live in the React island CSS,
   react-islands/src/islands/space-page/space-page.css) */

/* --------------------------------------------------------------------------
   Section Card animations override for new .sc-head pattern
   -------------------------------------------------------------------------- */
.section-card {
  background: var(--color-white);
  border: 1px solid var(--ink-06);
  border-radius: var(--radius-lg, 14px);
  margin-bottom: 20px;
  overflow: hidden;
  transition: border-color 0.15s;
}

.section-card:hover { border-color: var(--ink-12); }

/* --------------------------------------------------------------------------
   FieldQA trigger — hide until field hover
   -------------------------------------------------------------------------- */
.field-item .fqa-trigger { opacity: 0; }
.field-item:hover .fqa-trigger { opacity: 0.6; }
.field-item:hover .fqa-trigger:hover,
.fqa-trigger--active { opacity: 1; }

/* --------------------------------------------------------------------------
   Validation summary header
   -------------------------------------------------------------------------- */
.val-summary {
  font-size: 12px;
  font-weight: 500;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
}

.val-summary--clean {
  background: var(--complete-wash);
  color: var(--complete);
}

.val-summary--warn {
  background: var(--warn-wash);
  color: var(--warn);
}

.val-item--clickable {
  cursor: pointer;
}

.val-item--clickable:hover {
  background: var(--ink-06);
}

/* --------------------------------------------------------------------------
   Review Panel — Doc Detail
   -------------------------------------------------------------------------- */
.review-panel { background: var(--warn-wash); }
.review-panel .sc-head-icon.review { font-size: 14px; }

.rp-confidence { margin-bottom: 16px; }
.rp-conf-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.rp-conf-label { font-size: 12px; color: var(--ink-50); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.rp-conf-value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.rp-conf-bar { height: 6px; background: var(--ink-06); border-radius: 3px; overflow: hidden; }
.rp-conf-fill { height: 100%; border-radius: 3px; transition: width 0.4s ease; }
.rp-reasoning { font-size: 12px; color: var(--ink-50); margin-top: 6px; line-height: 1.4; }

.rp-section { margin-bottom: 16px; }
.rp-section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--ink-50); margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.rp-count { background: var(--ink-06); color: var(--ink-80); padding: 1px 6px; border-radius: 10px; font-size: 10px; font-weight: 600; }

.rp-issues { display: flex; flex-direction: column; gap: 4px; }
.rp-issue { display: flex; align-items: flex-start; gap: 8px; padding: 6px 8px; border-radius: 6px; font-size: 13px; line-height: 1.4; }
.rp-issue--error { background: var(--color-red-bg); }
.rp-issue--warning { background: var(--color-amber-bg); }
.rp-issue[data-target-field] { cursor: pointer; }
.rp-issue[data-target-field]:hover { background: var(--ink-06); }
.rp-issue-icon { flex-shrink: 0; font-size: 12px; margin-top: 1px; }
.rp-issue-text { color: var(--ink-80); }

.rp-review-list { margin: 0; padding: 0 0 0 18px; }
.rp-review-item { font-size: 13px; color: var(--ink-70); margin-bottom: 4px; line-height: 1.4; }

.rp-inbox-items { display: flex; flex-direction: column; gap: 10px; }
.rp-inbox-card { background: var(--ink-03); border: 1px solid var(--ink-06); border-radius: 8px; padding: 12px; }
.rp-inbox-question { font-size: 13px; font-weight: 500; color: var(--ink-90); margin-bottom: 4px; }
.rp-inbox-context { font-size: 12px; color: var(--ink-50); margin-bottom: 8px; line-height: 1.4; }
.rp-inbox-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.rp-chip { background: var(--ink-06); border: 1px solid var(--ink-10); color: var(--ink-80); padding: 4px 10px; border-radius: 14px; font-size: 12px; cursor: pointer; transition: all 0.15s; }
.rp-chip:hover { background: var(--brand-primary, var(--color-action)); color: white; border-color: var(--brand-primary, var(--color-action)); }
.rp-chip:disabled { opacity: 0.5; pointer-events: none; }
.rp-inline-input { display: flex; gap: 4px; flex: 1; min-width: 120px; }
.rp-text-input { flex: 1; background: var(--ink-00, #fff); border: 1px solid var(--ink-10); border-radius: 6px; padding: 4px 8px; font-size: 12px; color: var(--ink-90); outline: none; }
.rp-text-input:focus { border-color: var(--brand-primary, var(--color-action)); }
.rp-send-btn { background: var(--brand-primary, var(--color-action)); border: none; color: white; width: 28px; height: 28px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.rp-send-btn:hover { opacity: 0.85; }
.rp-send-btn:disabled { opacity: 0.5; pointer-events: none; }

.rp-approve { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--ink-06); }
.rp-approve-btn { display: flex; align-items: center; gap: 6px; background: var(--color-green); color: white; border: none; padding: 8px 16px; border-radius: var(--radius-md); font-size: 13px; font-weight: 500; cursor: pointer; transition: opacity 0.15s cubic-bezier(0, 0, 0.2, 1); }
.rp-approve-btn:hover { opacity: 0.85; }
.rp-approve-btn:disabled { opacity: 0.5; pointer-events: none; }

.field-flash {
  animation: fieldFlash 2s cubic-bezier(0, 0, 0.2, 1);
}
@keyframes fieldFlash {
  0%, 100% { background: transparent; }
  15%, 40% { background: var(--color-amber-bg); }
}

@media (prefers-reduced-motion: reduce) {
  .field-flash { animation: none; background: var(--color-amber-bg); }
}

/* ─── Mobile Doc Tabs ───────────────────────────────────────────── */

.mobile-doc-tabs {
  display: none; /* Hidden on desktop */
  grid-column: 1 / -1;
  position: sticky;
  top: 48px; /* Below consolidated top bar */
  z-index: var(--z-mobile-tab, 80);
  background: var(--color-white);
  border-bottom: 1px solid var(--ink-06);
  padding: 0 var(--space-5);
  height: var(--mobile-tab-height, 60px);
  align-items: center;
  gap: var(--space-4);
}

@media (max-width: 1024px) {
  .mobile-doc-tabs {
    display: flex;
  }
}

.mobile-tab {
  background: none;
  border: none;
  padding: var(--space-2) var(--space-1);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-40);
  cursor: pointer;
  position: relative;
  transition: color 200ms cubic-bezier(0.22, 1, 0.36, 1);
  /* Ensure touch target */
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.mobile-tab:hover {
  color: var(--ink-60);
}

.mobile-tab--active {
  color: var(--color-action);
}

.mobile-tab--active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--color-action);
  border-radius: 1px;
  /* Spring-physics underline slide */
  animation: tab-underline-in 280ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes tab-underline-in {
  from { transform: scaleX(0); opacity: 0; }
  to   { transform: scaleX(1); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-tab--active::after {
    animation: none;
  }
  .mobile-tab {
    transition: none;
  }
}

/* --------------------------------------------------------------------------
   Responsive — Doc Detail
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .doc-detail {
    grid-template-columns: 1fr;
    /* The tab strip becomes visible down here, so it generates a FIFTH
       track — top bar / title bar / live line / tabs / content — and the
       `1fr` has to move with it or the slack lands on the tabs instead of
       the content. It only misbehaves on a SHORT page: when the content
       already exceeds the viewport there is no slack to misplace, which is
       why a too-short template can sit here looking correct. */
    grid-template-rows: auto auto auto auto 1fr;
  }

  /* PDF panel hidden by default — tab swap controls visibility.
     The takeover starts BELOW the top bar / title bar / tab strip (a
     full-width in-flow grid row, not a fixed inset-0 overlay), so Back
     and Approve stay reachable while reading the PDF. */
  .pdf-panel {
    display: none;
    position: static;
    grid-column: 1 / -1;
    width: 100% !important;
    height: auto;
    min-height: 0;
    max-height: none;
    border-top: 1px solid var(--ink-06);
    border-left: none;
  }

  /* When tab swap makes PDF visible: the panel takes the remaining
     viewport below the chrome rows; the viewer scrolls internally. */
  .pdf-panel.mobile-visible {
    display: flex;
  }

  .doc-detail--pdf-mode {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    /* top bar / title bar / live line / mobile tabs / pdf panel */
    grid-template-rows: auto auto auto auto minmax(0, 1fr);
  }

  .pdf-toggle-btn {
    display: none;
  }

  .pdf-resize-handle {
    display: none;
  }

  .doc-detail-content {
    border-right: none;
  }

  /* Tab swap: hide the fields column while the PDF tab is active. Scoped to
     this breakpoint so widening past it (rotate a tablet, dock a laptop)
     restores the two-column layout — the tab bar disappears up there, so
     the tab choice must stop mattering too. */
  .doc-detail--pdf-mode .doc-detail-content {
    display: none;
  }
}

@media (max-width: 768px) {
  .section-nav {
    display: none;
  }

  .doc-scroll-content {
    padding: var(--space-4) var(--space-4) var(--space-10);
  }

  .doc-top-bar {
    padding: var(--space-2) var(--space-3);
    gap: var(--space-1);
  }

  .tb-utility {
    gap: 2px;
  }

  .tb-icon-btn {
    width: 28px;
    height: 28px;
  }

  .tb-btn {
    font-size: 10px;
    padding: 5px 8px;
  }

  .tb-reject-input {
    width: 160px;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .fin-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* Title bar compact on tablet */
  .doc-title-bar {
    padding: var(--space-2) var(--space-3);
  }

  .doc-title-bar .dtb-title {
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  /* Collapse breadcrumb to back-button only on mobile */
  .tb-breadcrumb {
    display: none;
  }

  .tb-utility {
    display: none;
  }

  /* Center zone takes remaining space on mobile */
  .tb-center {
    flex: 1;
    justify-content: flex-start;
  }

  /* Title bar: hide metadata on small screens, keep filename */
  .doc-title-bar .dtb-meta {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   Dark Mode
   -------------------------------------------------------------------------- */

/* Financial total bar — inverts badly without override */
[data-theme="dark"] .fin-total {
  background: var(--bg-surface-raised);
  color: var(--text-primary);
}
[data-theme="dark"] .fin-total-label {
  color: var(--text-secondary);
}
[data-theme="dark"] .fin-total-amount {
  color: var(--text-primary);
}

/* Financial grid cells */
[data-theme="dark"] .fin-item {
  background: var(--bg-card);
}
[data-theme="dark"] .fin-item:hover {
  background: var(--bg-surface-raised);
}

/* Top bar chrome */
[data-theme="dark"] .doc-top-bar {
  background: var(--bg-card);
  border-color: var(--border-light);
}

/* Export dropdown */
[data-theme="dark"] .tb-export-menu {
  background: var(--bg-card);
  border-color: var(--border-light);
}
[data-theme="dark"] .tb-export-option {
  color: var(--text-secondary);
}
[data-theme="dark"] .tb-export-option:hover {
  background: var(--bg-surface-raised);
  color: var(--text-primary);
}

/* Reject inline flow */
[data-theme="dark"] .tb-reject-chip {
  background: var(--bg-card);
  border-color: var(--border-light);
  color: var(--text-secondary);
}
[data-theme="dark"] .tb-reject-input {
  background: var(--bg-card);
  color: var(--text-primary);
}
[data-theme="dark"] .tb-reject-input::placeholder {
  color: var(--text-muted);
}

/* Status badges */
[data-theme="dark"] .tb-badge-approved {
  background: var(--color-green-100);
  color: var(--color-green-text);
}
[data-theme="dark"] .tb-badge-rejected {
  background: var(--color-red-100);
  color: var(--color-red-text);
}

/* Doc title bar (compact) */
[data-theme="dark"] .doc-title-bar {
  background: var(--bg-card);
  border-color: var(--border-light);
}
[data-theme="dark"] .doc-title-bar .dtb-chip {
  background: var(--bg-card);
  border-color: var(--border-light);
  color: var(--text-secondary);
}

/* Status tint — dark mode overrides with lower opacity */
[data-theme="dark"] .doc-top-bar[data-tint="processing"]::before {
  animation-name: tint-breathe-bg-dark;
}
[data-theme="dark"] .doc-top-bar[data-tint="error"]::before {
  background: rgba(227, 66, 52, 0.06);
}
[data-theme="dark"] .doc-top-bar[data-tint="reviewed"]::before {
  background: rgba(86, 159, 122, 0.06);
}
[data-theme="dark"] .doc-top-bar[data-tint="needs_review"]::before {
  background: rgba(232, 168, 48, 0.06);
}
[data-theme="dark"] .doc-top-bar[data-tint="not_relevant"]::before {
  background: var(--ink-06);
}

@keyframes tint-breathe-bg-dark {
  0%, 100% { background: rgba(31, 122, 212, 0.05); }
  50% { background: rgba(31, 122, 212, 0.08); }
}

/* Dark mode processing tint — reduced motion override.
   The dark variant sets animation-name after the generic reduce block,
   so we need a specific override here in cascade order. */
@media (prefers-reduced-motion: reduce) {
  [data-theme="dark"] .doc-top-bar[data-tint="processing"]::before {
    animation: none;
    background: rgba(31, 122, 212, 0.05);
  }
}

/* Legacy .doc-meta-chip compat */
[data-theme="dark"] .doc-meta-chip {
  background: var(--bg-card);
  border-color: var(--border-light);
  color: var(--text-secondary);
}

/* Field grid cells */
[data-theme="dark"] .field-item {
  background: var(--bg-card);
}
[data-theme="dark"] .field-item:hover {
  background: var(--bg-surface-raised);
}
[data-theme="dark"] .field-item.highlight {
  background: var(--alembic-wash);
}

/* Table headers */
[data-theme="dark"] .line-table th {
  background: var(--bg-tertiary);
  border-color: var(--border-light);
}
[data-theme="dark"] .line-table td {
  border-color: var(--border-light);
}
[data-theme="dark"] .line-table tr:hover td {
  background: var(--bg-surface-raised);
}
[data-theme="dark"] .line-table tfoot td {
  border-color: var(--border-medium);
}

/* Section card headers */
[data-theme="dark"] .sc-head:hover {
  background: var(--bg-surface-raised);
}
[data-theme="dark"] .sc-field-count {
  background: var(--bg-tertiary);
  color: var(--text-muted);
}

/* Section nav */
[data-theme="dark"] .sn-item:hover {
  background: var(--bg-surface-raised);
}
[data-theme="dark"] .sn-collapse-btn:hover {
  background: var(--bg-surface-raised);
}

/* Validation items */
[data-theme="dark"] .val-item:hover {
  background: var(--bg-surface-raised);
}

/* PDF panel */
[data-theme="dark"] .pdf-panel {
  background: var(--bg-card);
  border-color: var(--border-light);
}

/* Doc detail — dark mode backgrounds + borders */
[data-theme="dark"] .doc-detail-content {
  background: var(--bg-body);
  border-color: var(--border-light);
}

[data-theme="dark"] .doc-top-bar {
  background: var(--bg-body);
  border-color: var(--border-light);
}

[data-theme="dark"] .doc-title-bar {
  background: var(--bg-card);
  border-color: var(--border-light);
}

[data-theme="dark"] .tb-dropdown {
  background: var(--bg-card);
  border-color: var(--border-light);
}

[data-theme="dark"] .section-card { background: var(--bg-card); border-color: var(--border-light); }
[data-theme="dark"] .rp-inbox-card { background: var(--bg-surface-raised); border-color: var(--border-light); }
[data-theme="dark"] .rp-issue--error { background: var(--color-red-bg); }
[data-theme="dark"] .rp-issue--warning { background: var(--color-amber-bg); }

/* Mobile tab bar — dark mode */
[data-theme="dark"] .mobile-doc-tabs {
  background: var(--bg-card);
  border-color: var(--border-light);
}

[data-theme="dark"] .mobile-tab {
  color: var(--text-muted);
}

[data-theme="dark"] .mobile-tab:hover {
  color: var(--text-secondary);
}

[data-theme="dark"] .mobile-tab--active {
  color: var(--color-action);
}

/* --------------------------------------------------------------------------
   Touch: 44px minimum targets for the doc chrome (house recipe).
   Coarse-pointer only — desktop density is untouched. Adjacent icon
   buttons grow real size (not invisible ::after zones) so neighbouring
   hit areas never overlap ambiguously. min-height beats the inline
   30px height on the Approve/Reject .al-btn pair.
   -------------------------------------------------------------------------- */
@media (pointer: coarse) {
  .doc-back-btn,
  .tb-icon-btn {
    width: 44px;
    height: 44px;
  }

  .doc-top-bar .tb-decision .al-btn {
    min-height: 44px;
  }

  .tb-approve-chevron {
    min-width: 44px;
    min-height: 44px;
  }

  .tb-export-option {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}
