/* ==========================================================================
   Legacy Glueware — PDF to Excel Automation Dashboard Styles (v2.0)
   Clean B2B operations aesthetic, accessible native [switch] + fallback,
   responsive container table, and native <dialog> scroll containment.
   ========================================================================== */

:root {
  --bg-page: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-subtle: #f8fafc;
  --border-subtle: #e2e8f0;
  --border-input: #cbd5e1;
  --border-strong: #94a3b8;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff6ff;

  --accent: #0f766e;
  --accent-hover: #115e59;
  --accent-soft: #f0fdfa;

  --success: #059669;
  --success-hover: #047857;
  --success-soft: #ecfdf5;
  --success-text: #065f46;

  --warn-border: #d97706;
  --warn-soft: #fffbeb;
  --warn-text: #92400e;

  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: #fef2f2;
  --danger-text: #991b1b;

  --purple-soft: #f5f3ff;
  --purple-text: #5b21b6;
  --purple-border: #c4b5fd;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.08);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  scroll-padding-top: 88px;
}

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-page);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Accessibility utilities */
.visually-hidden {
  position: absolute;
  clip-path: inset(50%);
  overflow: hidden;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  inset-block-start: -48px;
  inset-inline-start: 16px;
  background: var(--primary);
  color: #ffffff;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
  z-index: 100;
}

.skip-link:focus {
  inset-block-start: 12px;
}

:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}

.container {
  width: 100%;
  max-width: 1380px;
  margin-inline: auto;
  padding-inline: clamp(1rem, 2.5vw, 2rem);
}

/* ==========================================================================
   Accessible Native HTML Switch (<input type="checkbox" switch>) + Fallback
   ========================================================================== */

input[type="checkbox"][switch] {
  accent-color: var(--primary);
  margin: 0;
  cursor: pointer;
  flex-shrink: 0;
}

input[type="checkbox"][switch]:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 3px;
}

/* Zero-dependency progressive-enhancement fallback for browsers without native switch */
input[type="checkbox"][switch].switch-fallback {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background-color: #94a3b8;
  border: 2px solid #64748b;
  transition: background-color 0.16s ease, border-color 0.16s ease;
  vertical-align: middle;
}

input[type="checkbox"][switch].switch-fallback::before {
  content: "";
  position: absolute;
  inset-block-start: 2px;
  inset-inline-start: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
  transition: transform 0.16s ease;
}

input[type="checkbox"][switch].switch-fallback:checked {
  background-color: var(--primary);
  border-color: var(--primary);
}

input[type="checkbox"][switch].switch-fallback:checked::before {
  transform: translateX(20px);
}

input[type="checkbox"][switch].switch-fallback.switch-sm {
  width: 36px;
  height: 20px;
}

input[type="checkbox"][switch].switch-fallback.switch-sm::before {
  width: 12px;
  height: 12px;
}

input[type="checkbox"][switch].switch-fallback.switch-sm:checked::before {
  transform: translateX(16px);
}

/* Header */
.topbar {
  background: var(--bg-surface);
  border-block-end: 1px solid var(--border-subtle);
  position: sticky;
  inset-block-start: 0;
  z-index: 20;
  box-shadow: var(--shadow-sm);
}

.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 0.8rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.16);
}

.brand-logo-img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.brand-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-subtitle {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.local-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--success-text);
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid #a7f3d0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

/* Main workspace */
.main-content {
  flex: 1;
  padding-block: 1.35rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

/* Workflow Step Tracker */
.workflow-bar {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 0.8rem 1.1rem;
  box-shadow: var(--shadow-sm);
}

.workflow-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.workflow-step {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  background: var(--bg-subtle);
  border: 1px solid transparent;
  transition: background-color 0.18s ease, border-color 0.18s ease;
}

.workflow-step strong {
  display: block;
  font-size: 0.9rem;
  color: var(--text-primary);
  line-height: 1.25;
}

.workflow-step span:not(.step-num) {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e2e8f0;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.workflow-step.is-active {
  background: var(--primary-soft);
  border-color: #bfdbfe;
}

.workflow-step.is-active .step-num {
  background: var(--primary);
  color: #ffffff;
}

.workflow-step.is-complete {
  background: var(--success-soft);
  border-color: #a7f3d0;
}

.workflow-step.is-complete .step-num {
  background: var(--success);
  color: #ffffff;
}

@media (max-width: 720px) {
  .workflow-steps {
    grid-template-columns: 1fr;
  }
}

/* Status Banner */
.status-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
}

.status-banner[hidden] {
  display: none;
}

.status-banner.is-info {
  background: var(--primary-soft);
  border-color: #93c5fd;
  color: #1e3a8a;
}

.status-banner.is-success {
  background: var(--success-soft);
  border-color: #6ee7b7;
  color: var(--success-text);
}

.status-banner.is-warning {
  background: var(--warn-soft);
  border-color: #fcd34d;
  color: var(--warn-text);
}

.status-banner.is-error {
  background: var(--danger-soft);
  border-color: #fca5a5;
  color: var(--danger-text);
}

.status-banner-content {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.status-banner-content p {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 500;
}

.status-banner-icon {
  font-size: 1.05rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* Cards */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: clamp(1.1rem, 2vw, 1.5rem);
  box-shadow: var(--shadow-sm);
}

.card[hidden] {
  display: none;
}

.section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-block-end: 1.1rem;
}

.section-header.compact {
  margin-block-end: 0.9rem;
}

.section-header h2 {
  margin: 0 0 0.25rem;
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.section-desc {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-secondary);
  max-width: 68ch;
}

/* Processing Controls Strip (OCR, Duplicate Detection, Currency) */
.controls-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
  margin-block-end: 1rem;
}

@media (max-width: 920px) {
  .controls-strip {
    grid-template-columns: 1fr;
  }
}

.control-tile {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
}

.control-tile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.control-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
}

.control-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

.control-inline-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.compact-select {
  font: inherit;
  font-size: 0.84rem;
  font-weight: 500;
  padding: 0.38rem 0.6rem;
  min-height: 36px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  cursor: pointer;
}

.compact-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.compact-select.full-width {
  width: 100%;
}

.link-btn {
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary);
  background: transparent;
  border: none;
  padding: 0.25rem 0.4rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}

.link-btn:hover {
  background: var(--primary-soft);
  text-decoration: underline;
}

.mini-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.14rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid #bfdbfe;
  white-space: nowrap;
}

.mini-badge[hidden] {
  display: none;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.55rem 0.95rem;
  min-height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}

.btn-sm {
  min-height: 36px;
  padding: 0.38rem 0.75rem;
  font-size: 0.82rem;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-accent {
  background: var(--accent);
  color: #ffffff;
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-success {
  background: var(--success);
  color: #ffffff;
}

.btn-success:hover:not(:disabled) {
  background: var(--success-hover);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-input);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--primary);
  border-color: #bfdbfe;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--primary-soft);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger-text);
  border-color: #fecaca;
}

.btn-danger-ghost:hover:not(:disabled) {
  background: var(--danger-soft);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.icon-btn:hover {
  background: rgba(15, 23, 42, 0.06);
  color: var(--text-primary);
}

/* Upload Dropzone */
.sample-cta-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.dropzone {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.3rem 1.45rem;
  border: 2px dashed #94a3b8;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  transition: border-color 0.18s ease, background-color 0.18s ease;
}

.dropzone.is-dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.dropzone-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: #e0e7ff;
  color: var(--primary);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.dropzone-copy {
  flex: 1 1 280px;
}

.dropzone-title {
  margin: 0 0 0.2rem;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text-primary);
}

.dropzone-sub {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-secondary);
}

.upload-label-btn {
  cursor: pointer;
}

input#pdf-file-input:focus-visible ~ .upload-label-btn {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}

.upload-progress {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-block-start: 0.85rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: #1e3a8a;
  font-size: 0.9rem;
  font-weight: 500;
}

.upload-progress[hidden] {
  display: none;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid #93c5fd;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Sample PDFs Drawer */
.sample-drawer {
  margin-block-start: 1rem;
  padding-block-start: 1rem;
  border-block-start: 1px solid var(--border-subtle);
}

.sample-drawer[hidden] {
  display: none;
}

.sample-drawer-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-block-end: 0.8rem;
}

.sample-drawer-head h3 {
  margin: 0 0 0.2rem;
  font-size: 0.96rem;
}

.sample-drawer-head p {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-secondary);
}

.sample-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: 0.65rem;
}

.sample-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.sample-item-name {
  display: block;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow-wrap: break-word;
}

.sample-item-desc {
  display: block;
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-block-start: 0.15rem;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.95rem;
}

@media (max-width: 900px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 500px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.kpi-label {
  font-size: 0.79rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 1.62rem;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.kpi-card-warn .kpi-value.has-warnings {
  color: var(--warn-border);
}

.kpi-card-total .kpi-value {
  color: var(--success-text);
}

.kpi-sub {
  font-size: 0.79rem;
  color: var(--text-secondary);
}

/* File Reports Grid */
.file-reports-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  gap: 0.85rem;
}

.file-report-card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.95rem 1rem;
  background: var(--bg-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.file-report-card.status-warning {
  border-color: #fcd34d;
  background: #fffdf5;
}

.file-report-card.status-error {
  border-color: #fca5a5;
  background: var(--danger-soft);
}

.file-report-card.status-duplicate_skipped {
  border-color: var(--purple-border);
  background: var(--purple-soft);
}

.file-report-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem;
}

.file-report-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow-wrap: break-word;
  word-break: normal;
}

.file-report-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.pill-success {
  background: var(--success-soft);
  color: var(--success-text);
  border: 1px solid #a7f3d0;
}

.pill-warning {
  background: var(--warn-soft);
  color: var(--warn-text);
  border: 1px solid #fcd34d;
}

.pill-error {
  background: var(--danger-soft);
  color: var(--danger-text);
  border: 1px solid #fca5a5;
}

.pill-ocr {
  background: var(--primary-soft);
  color: #1e40af;
  border: 1px solid #93c5fd;
}

.pill-format {
  background: #f1f5f9;
  color: #334155;
  border: 1px solid #cbd5e1;
}

.pill-duplicate {
  background: var(--purple-soft);
  color: var(--purple-text);
  border: 1px solid var(--purple-border);
}

.report-messages {
  margin: 0;
  padding-inline-start: 1.15rem;
  font-size: 0.81rem;
  line-height: 1.45;
}

.report-messages.is-warning {
  color: var(--warn-text);
}

.report-messages.is-error {
  color: var(--danger-text);
}

.report-messages.is-duplicate {
  color: var(--purple-text);
}

.file-report-actions {
  margin-block-start: auto;
  padding-block-start: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

/* Export Controls & Format Switches */
.export-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.format-switches {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.format-switch-item {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
}

.export-option {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.83rem;
  color: var(--text-secondary);
}

.export-option input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--primary);
  cursor: pointer;
}

.export-option label {
  cursor: pointer;
}

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-block-end: 1rem;
}

.search-box {
  position: relative;
  flex: 1 1 250px;
  max-width: 400px;
}

.search-icon {
  position: absolute;
  inset-inline-start: 0.75rem;
  inset-block-start: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem 0.5rem 2.2rem;
  min-height: 38px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.filter-group {
  display: inline-flex;
  padding: 3px;
  background: var(--bg-page);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.filter-pill {
  font: inherit;
  font-size: 0.81rem;
  font-weight: 600;
  padding: 0.34rem 0.72rem;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.filter-pill.is-active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 2.75rem 1.25rem;
  border: 1px dashed var(--border-input);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
}

.empty-state[hidden] {
  display: none;
}

.empty-icon {
  color: var(--text-muted);
  margin-block-end: 0.75rem;
}

.empty-state h3 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}

.empty-state p {
  margin: 0 auto;
  max-width: 52ch;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Responsive Editable Data Table */
.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(620px, 70vh);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  container-type: inline-size;
  background: var(--bg-surface);
}

.table-wrapper[hidden] {
  display: none;
}

.po-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.88rem;
  --label-1: "Row";
  --label-2: "Customer Name";
  --label-3: "Order Number";
  --label-4: "Order Date";
  --label-5: "Product Name";
  --label-6: "Quantity";
  --label-7: "Unit Price";
  --label-8: "Total Amount";
  --label-9: "Review Status";
  --label-10: "Action";
}

.po-table thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
}

.po-table thead th {
  background: #1e293b;
  color: #ffffff;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  text-align: left;
  padding: 0.72rem 0.5rem;
  border-block-end: 1px solid #334155;
  white-space: nowrap;
}

.po-table thead th.col-num {
  text-align: right;
}

.po-table tbody tr {
  background: var(--bg-surface);
}

.po-table tbody tr:nth-child(even) {
  background: #f8fafc;
}

.po-table tbody tr.row-has-warning {
  background: #fffdf4;
}

.po-table tbody tr.row-has-error {
  background: #fef6f6;
}

.po-table tbody th,
.po-table tbody td {
  padding: 0.42rem 0.35rem;
  border-block-end: 1px solid var(--border-subtle);
  vertical-align: top;
}

.po-table tbody th {
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  width: 34px;
  padding-block-start: 0.82rem;
  background: inherit;
}

.col-customer {
  min-width: 155px;
  width: 16%;
}

.col-order-no {
  min-width: 118px;
  width: 11%;
}

.col-date {
  min-width: 122px;
  width: 11%;
}

.col-product {
  min-width: 195px;
  width: 22%;
}

.col-num {
  min-width: 86px;
  width: 8.5%;
}

.col-qty {
  min-width: 68px;
  width: 6.5%;
}

.col-status {
  min-width: 126px;
  width: 12%;
}

.col-actions {
  width: 44px;
  text-align: center;
}

/* Inline Cell Inputs */
.cell-input {
  width: 100%;
  font: inherit;
  font-size: 0.83rem;
  padding: 0.42rem 0.48rem;
  min-height: 36px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  transition: border-color 0.14s ease, background-color 0.14s ease;
}

.cell-input:hover {
  border-color: var(--border-strong);
}

.cell-input.is-numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cell-input.is-missing {
  background: var(--warn-soft);
  border-color: var(--warn-border);
}

.cell-input.is-missing::placeholder {
  color: #b45309;
  font-weight: 500;
}

.cell-input.is-invalid {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.cell-error-msg {
  display: block;
  margin-block-start: 0.2rem;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--danger-text);
}

.status-cell-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding-block-start: 0.15rem;
}

.source-tag {
  font-size: 0.73rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
}

.row-hint-text {
  font-size: 0.74rem;
  color: var(--warn-text);
  line-height: 1.3;
}

.inline-fix-btn {
  align-self: flex-start;
  font: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid #bfdbfe;
  border-radius: 4px;
  padding: 0.18rem 0.45rem;
  cursor: pointer;
}

.inline-fix-btn:hover {
  background: #dbeafe;
}

.delete-row-btn {
  margin-block-start: 0.15rem;
  color: var(--text-muted);
}

.delete-row-btn:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

/* Container Query: Stacked Cards Layout on Narrow Screens */
@container (width < 820px) {
  .po-table,
  .po-table thead,
  .po-table tbody,
  .po-table tr,
  .po-table th,
  .po-table td {
    display: block;
    width: 100%;
  }

  .po-table thead {
    display: none;
  }

  .po-table tbody {
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .po-table tbody tr {
    border: 1px solid var(--border-input);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
  }

  .po-table tbody th {
    position: sticky;
    inset-block-start: 0;
    z-index: 1;
    text-align: left;
    padding: 0.55rem 0.85rem;
    background: #1e293b;
    color: #ffffff;
    font-size: 0.82rem;
  }

  .po-table tbody th::before {
    content: "Purchase Order Line ";
  }

  .po-table tbody td {
    padding: 0.55rem 0.85rem;
    border-block-end: 1px solid var(--border-subtle);
  }

  .po-table tbody td::before {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    margin-block-end: 0.25rem;
  }

  .po-table tbody td:nth-child(2)::before { content: var(--label-2); }
  .po-table tbody td:nth-child(3)::before { content: var(--label-3); }
  .po-table tbody td:nth-child(4)::before { content: var(--label-4); }
  .po-table tbody td:nth-child(5)::before { content: var(--label-5); }
  .po-table tbody td:nth-child(6)::before { content: var(--label-6); }
  .po-table tbody td:nth-child(7)::before { content: var(--label-7); }
  .po-table tbody td:nth-child(8)::before { content: var(--label-8); }
  .po-table tbody td:nth-child(9)::before { content: var(--label-9); }
  .po-table tbody td:nth-child(10)::before { content: var(--label-10); }

  .cell-input.is-numeric {
    text-align: left;
  }

  .col-actions {
    text-align: left;
  }
}

/* Table Footer & Legend */
.table-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-block-start: 0.85rem;
  font-size: 0.83rem;
  color: var(--text-secondary);
}

.table-footer[hidden] {
  display: none;
}

.table-count-label {
  margin: 0;
  font-weight: 500;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  border: 1px solid transparent;
}

.swatch-ok {
  background: var(--success-soft);
  border-color: var(--success);
}

.swatch-warn {
  background: var(--warn-soft);
  border-color: var(--warn-border);
}

.swatch-err {
  background: var(--danger-soft);
  border-color: var(--danger);
}

/* Native Modal Dialogs */
dialog.modal-dialog {
  padding: 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  color: var(--text-primary);
  background: var(--bg-surface);
  max-width: calc(100vw - 2rem);
  max-height: calc(100dvh - 2rem);
}

dialog.modal-dialog[open] {
  display: flex;
  flex-direction: column;
}

dialog.modal-sm {
  width: 440px;
}

dialog.modal-md {
  width: 640px;
}

dialog.modal-lg {
  width: 860px;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  overflow: hidden;
  overscroll-behavior: contain;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
  border-block-end: 1px solid var(--border-subtle);
}

.modal-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
}

.modal-subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.84rem;
  color: var(--text-secondary);
}

.modal-body {
  padding: 1.1rem 1.25rem;
  overflow-y: auto;
}

.modal-helper {
  margin: 0 0 0.75rem;
  font-size: 0.84rem;
  color: var(--text-secondary);
}

.raw-text-pre {
  margin: 0;
  padding: 1rem;
  border-radius: var(--radius-sm);
  background: #0f172a;
  color: #e2e8f0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  overflow: auto;
  max-height: 55vh;
  white-space: pre;
}

.modal-footer {
  padding: 0.9rem 1.25rem;
  border-block-start: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  background: var(--bg-subtle);
}

.modal-footer-between {
  justify-content: space-between;
  flex-wrap: wrap;
}

.modal-actions {
  display: flex;
  gap: 0.6rem;
}

/* Custom Column Mapping Modal Styles */
.mapping-modal-body {
  display: flex;
  flex-direction: column;
  gap: 1.35rem;
}

.mapping-section {
  padding-block-end: 1.15rem;
  border-block-end: 1px solid var(--border-subtle);
}

.mapping-section:last-child {
  padding-block-end: 0;
  border-block-end: none;
}

.mapping-subhead {
  margin: 0 0 0.25rem;
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text-primary);
}

.mapping-dropdown-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.7rem;
}

.mapping-field-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}

.mapping-field-card label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
}

.alias-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 0.85rem;
}

.alias-group-card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem 0.95rem;
  background: var(--bg-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.alias-group-card h3 {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-primary);
}

.alias-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.alias-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--border-input);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
}

.alias-chip.is-active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: #93c5fd;
}

.alias-add-row {
  display: flex;
  gap: 0.4rem;
}

.alias-add-row input {
  flex: 1;
  font: inherit;
  font-size: 0.82rem;
  padding: 0.36rem 0.55rem;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
}

.output-headers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 0.65rem;
}

.output-header-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.output-header-item label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.output-header-item input {
  font: inherit;
  font-size: 0.84rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
}

/* History List */
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 48vh;
  overflow-y: auto;
}

.history-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  font-size: 0.84rem;
}

.history-item strong {
  color: var(--text-primary);
}

.history-meta {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.guide-list {
  margin: 0;
  padding-inline-start: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  font-size: 0.92rem;
}

.guide-list code {
  background: var(--bg-page);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
}

/* Footer */
.footer {
  margin-block-start: auto;
  border-block-start: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.footer-inner {
  padding-block: 1rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.footer-inner p {
  margin: 0;
}
