.detail-page {
  max-width: 1200px;
  margin: 0 auto;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--color-border);
}

.detail-header-left h2 {
  margin: 0.25rem 0 0;
}

.detail-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.back-link {
  color: var(--color-primary);
  text-decoration: none;
  font-size: 0.875rem;
}

.back-link:hover {
  text-decoration: underline;
}

/* Floating "← Envíos" (Phase 14, §7.5): shown once the header scrolls away. Bottom-left
   button by default; in the left margin beside the content when the window is wide enough. */
.back-floating {
  position: fixed;
  left: 20px;
  bottom: 20px;
  z-index: 50;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--color-primary);
  color: white;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.2);
}

.back-floating:hover {
  background: var(--color-primary-dark);
}

.back-floating[hidden] {
  display: none;
}

/* Room under the last section so the bottom-left button never covers it */
@media (max-width: 1399px) {
  .detail-page {
    padding-bottom: 56px;
  }
}

@media (min-width: 1400px) {
  .back-floating {
    top: 24px;
    bottom: auto;
    left: auto;
    /* .app-content is 1200px wide with 24px padding: sit 12px left of its content edge */
    right: calc(50vw + 588px);
    border-radius: var(--radius-sm);
  }
}

.detail-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  margin-bottom: 1rem;
  overflow: hidden;
}

/* Status timeline */
.status-timeline {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
}

.timeline-step {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.625rem 1rem;
  border-top: 3px solid var(--color-border);
  color: var(--color-text-secondary);
}

.timeline-step--done {
  border-top-color: var(--color-success);
  color: inherit;
}

.timeline-step--future {
  background: var(--color-bg);
  color: var(--color-text-muted);
}

.timeline-step__date:empty::before {
  content: '\00a0';
}

.timeline-step__label {
  font-size: 0.8125rem;
  font-weight: 600;
}

.timeline-step__date {
  font-size: 0.75rem;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem 1rem;
  border: none;
  cursor: pointer;
  background: var(--color-bg);
  color: inherit;
  font: inherit;
  text-align: left;
  user-select: none;
}

.section-header:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

.section-header__extra {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-count {
  min-width: 1.5rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--color-border);
  color: var(--color-text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
}

.section-header:hover {
  background: var(--color-border);
}

.section-header h3 {
  margin: 0;
  font-size: 1rem;
}

.toggle-icon {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
}

.section-content {
  padding: 1rem;
}

.section-content.collapsed {
  display: none;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 0.75rem;
}

.detail-field {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.detail-label {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.detail-value {
  font-size: 0.9375rem;
}

.upload-placeholder {
  text-align: center;
  padding: 2rem;
  border: 2px dashed var(--color-border);
  border-radius: 8px;
}

.upload-placeholder p {
  margin-bottom: 1rem;
  color: var(--color-text-secondary);
}

.upload-placeholder__actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.upload-placeholder__actions .bl-picker {
  width: min(560px, 100%);
}

.upload-placeholder__actions .hint-text {
  margin: 0;
}

.upload-btn {
  cursor: pointer;
  display: inline-block;
}

.upload-btn.disabled {
  opacity: 0.6;
  pointer-events: none;
}

.empty-text {
  color: var(--color-text-secondary);
  font-style: italic;
}

.doc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.doc-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--color-border);
}

.doc-item:last-child {
  border-bottom: none;
}

/* Liquidacion sub-sections */
.liq-subsection {
  margin-bottom: 1.5rem;
}

.liq-subsection:last-child {
  margin-bottom: 0;
}

.liq-subsection h4 {
  margin: 0 0 0.75rem;
  font-size: 0.9375rem;
  color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 0.375rem;
}

.manifest-text {
  background: var(--color-bg);
  padding: 0.75rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.875rem;
}

.table-scroll {
  overflow-x: auto;
}

.liq-items-table {
  font-size: 0.8125rem;
}

.cell-right {
  text-align: right;
}

.cell-nowrap {
  white-space: nowrap;
}

.exchange-rate {
  margin: 0 0 0.75rem;
  font-size: 0.875rem;
}

.financial-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

.financial-table {
  font-size: 0.8125rem;
}

.financial-table td:first-child {
  min-width: 180px;
}

/* Audit log severity badges */
.badge-sm {
  font-size: 0.6875rem;
  padding: 0.125rem 0.375rem;
}

.severity-info {
  background-color: #e3f2fd;
  color: #1565c0;
}

.severity-warning {
  background-color: #fff3e0;
  color: #e65100;
}

.severity-error {
  background-color: #ffebee;
  color: #c62828;
}

/* Bill of lading section, inbox and link diff modal */
.bl-picker {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.bl-select {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--color-surface);
}

.hint-text {
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
}

.bl-actions,
.section-actions {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.upload-disabled {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
}

.upload-disabled .btn:disabled,
.cell-actions .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.upload-disabled__note {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  width: min(720px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
}

.modal-subtitle {
  margin: 1.25rem 0 0.5rem;
  font-size: 0.875rem;
  color: var(--color-text-secondary);
}

.diff-table label {
  margin-right: 0.75rem;
  cursor: pointer;
}

.diff-changed td:last-child {
  font-weight: 600;
  color: var(--color-primary-dark);
}

.diff-status {
  margin-top: 1rem;
}

.modal-actions {
  margin-top: 1.5rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* BPD receipts: payment section, inbox and link modal */
.payment-progress {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.payment-progress__bar {
  flex: 1;
  height: 10px;
  background: var(--color-border);
  border-radius: 999px;
  overflow: hidden;
}

.payment-progress__fill {
  height: 100%;
  background: var(--color-success);
}

.payment-progress__fill--over {
  background: var(--color-warning);
}

.payment-progress__label {
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}

.payment-progress--compact {
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
  margin: 8px 0 0;
}

.payment-progress--compact .payment-progress__bar {
  flex: none;
  height: 6px;
}

.payment-progress--compact .payment-progress__label {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-secondary);
  white-space: normal;
}

.payment-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.badge-blocked {
  background: #ffebee;
  color: #c62828;
}

.confidence-high {
  background: #dcfce7;
  color: #15803d;
}

.confidence-medium {
  background: #fff3e0;
  color: #e65100;
}

.payment-receipt {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
  padding: 0.5rem 0.75rem;
}

.payment-receipt summary {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  cursor: pointer;
  font-size: 0.875rem;
}

.payment-receipt summary strong {
  margin-left: auto;
}

.payment-receipt .data-table {
  margin-top: 0.75rem;
  font-size: 0.8125rem;
}

.payment-actions {
  margin-top: 1rem;
}

.modal--narrow {
  width: min(460px, 100%);
}

/* Detail header meta, source markers, fee tracker (Phase 6) */
.detail-header-left h2 {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.detail-header-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: var(--color-text-secondary);
}

.detail-header-right {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.source-marker {
  align-self: flex-start;
  margin-top: 0.125rem;
  padding: 0 0.4rem;
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
  font-weight: 600;
  background: #f1f5f9;
  color: #475569;
}

.source-marker--billOfLading {
  background: #e0f2fe;
  color: #0369a1;
}

.source-marker--liquidacion {
  background: #dcfce7;
  color: #15803d;
}

.fee-chip {
  padding: 0.0625rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.fee-chip--safe { background: #dcfce7; color: #15803d; }
.fee-chip--warning { background: #fef3c7; color: #b45309; }
.fee-chip--critical { background: #fee2e2; color: #b91c1c; }
.fee-chip--overdue { background: #ffedd5; color: #c2410c; }

.fee-alert {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1rem;
  padding: 0.625rem 0.875rem;
  margin-bottom: 1rem;
  border-left: 4px solid var(--color-success);
  border-radius: var(--radius-sm);
  background: #f0fdf4;
  font-size: 0.875rem;
}

.fee-alert--warning { border-left-color: var(--color-warning); background: #fffbeb; }
.fee-alert--critical { border-left-color: var(--color-danger); background: #fef2f2; }
.fee-alert--overdue { border-left-color: #ea580c; background: #fff7ed; }

.doc-item__title {
  font-weight: 500;
}

.doc-item__actions {
  display: flex;
  gap: 0.5rem;
}

/* In-app PDF viewer */
.modal--viewer {
  width: min(1100px, 100%);
  height: 92vh;
  max-height: none;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  overflow: hidden;
}

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.viewer-header h3 {
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.viewer-frame {
  flex: 1;
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: #525659;
}

.modal-message {
  margin: 0.5rem 0 0;
}

.change-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  font-size: 0.875rem;
}

.change-list li {
  padding: 0.375rem 0;
  border-bottom: 1px solid var(--color-border);
  overflow-wrap: anywhere;
}

.change-list li:last-child {
  border-bottom: none;
}

@media (max-width: 1023px) {
  .detail-header {
    flex-direction: column;
    gap: 0.75rem;
  }

  .detail-header-right {
    justify-content: flex-start;
  }

  .detail-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }

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

.customs-release-form {
  width: min(560px, 100%);
  margin-top: 1rem;
  text-align: left;
}

.upload-placeholder__actions .customs-release-form {
  margin-top: 0;
}

/* Audit rows (PRD 7.8): warning and error rows tinted by severity; a row expands to its details. */
.audit-row {
  cursor: pointer;
}

.audit-row--warning > td {
  background-color: #fffbeb;
}

.audit-row--error > td {
  background-color: #fef2f2;
}

.audit-row--warning > td:first-child {
  box-shadow: inset 3px 0 0 var(--color-warning);
}

.audit-row--error > td:first-child {
  box-shadow: inset 3px 0 0 var(--color-danger);
}

.audit-toggle {
  display: inline-flex;
  align-items: baseline;
  gap: 0.375rem;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.audit-toggle__icon {
  color: var(--color-text-muted);
  transition: transform 0.15s ease;
}

.audit-row--open .audit-toggle__icon {
  transform: rotate(90deg);
}

.audit-details > td {
  padding-top: 0;
}

.audit-details__list {
  display: grid;
  grid-template-columns: minmax(140px, max-content) 1fr;
  gap: 0.25rem 1rem;
  margin: 0;
  padding: 0.5rem 0 0.75rem 1.25rem;
  font-size: 0.8125rem;
}

.audit-details__list dt {
  color: var(--color-text-secondary);
}

.audit-details__list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* "Revisar liquidación" preview modal (Phase 12) */
.lq-preview__text {
  margin: 4px 0 0;
}

.lq-preview__confirm {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-weight: 600;
  cursor: pointer;
}

.lq-preview__confirm input {
  width: 16px;
  height: 16px;
  accent-color: var(--color-danger);
}

.lq-preview__version {
  margin: 0 0 0.5rem;
}

/* Shared row picker (Phase 13, PRD §7.2): whole-row selection, confidence tints, pinned footer */
.modal.row-picker {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
  width: min(860px, 100%);
}

.row-picker__head {
  padding: 1.25rem 1.5rem 0.5rem;
}

.row-picker__head h3 {
  margin: 0 0 0.25rem;
}

.row-picker__search {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--color-border, #cbd5e1);
  border-radius: 6px;
  font: inherit;
}

.row-picker__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 1.5rem 0.5rem;
}

.row-picker__footer {
  flex: 0 0 auto;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

.row-picker__actions {
  display: flex;
  gap: 0.5rem;
}

.row-picker__table thead th {
  position: sticky;
  top: 0;
  background: var(--color-surface);
  z-index: 1;
}

.row-picker__section th {
  background: var(--color-bg);
  color: var(--color-text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  text-align: left;
}

.row-picker__row {
  cursor: pointer;
}

.row-picker__row:hover td {
  background: var(--color-bg);
}

.row-picker__row--high td {
  background: #f0fdf4;
}

.row-picker__row--high:hover td {
  background: #dcfce7;
}

.row-picker__row--medium td {
  background: #fffbeb;
}

.row-picker__row--medium:hover td {
  background: #fef3c7;
}

.row-picker__row--selected td {
  font-weight: 600;
  box-shadow: inset 0 2px 0 var(--color-primary), inset 0 -2px 0 var(--color-primary);
}

/* A selected suggestion keeps its confidence tint; plain rows turn light blue. */
.row-picker__row--selected:not(.row-picker__row--high):not(.row-picker__row--medium) td {
  background: #e0ecff;
}

.row-picker__row--selected td:first-child {
  box-shadow: inset 2px 2px 0 var(--color-primary), inset 0 -2px 0 var(--color-primary);
}

.row-picker__row--selected td:last-child {
  box-shadow: inset -2px 2px 0 var(--color-primary), inset 0 -2px 0 var(--color-primary);
}

.row-picker__mark {
  width: 28px;
}

.row-picker__dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--color-border);
  border-radius: 50%;
  vertical-align: middle;
}

.row-picker__row--selected .row-picker__dot {
  border-color: var(--color-primary);
  background: radial-gradient(circle, var(--color-primary) 45%, transparent 50%);
}

/* PY-07: receipt with parser problems ("Con errores") */
.bpd-problems-row td {
  padding-top: 0;
  border-top: none;
}

.bpd-problems-row .bl-alert {
  margin-bottom: 4px;
}

.bpd-row--problems td {
  border-bottom: none;
}

/* "Sacado de aduanas" (Phase 15, PRD §6.3) */
.pickup-block {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border, #e2e8f0);
}

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

.pickup-row .checkbox-label,
.pickup-row .pickup-date {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}
