/* ───────────────────────────────────────────────────────────────────
   style.css – Premium dark-mode UI for Invoice Extraction Tool
   ─────────────────────────────────────────────────────────────────── */

/* ── Reset & Tokens ──────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #ffffff;
  --bg2: #f8fafc;
  --bg3: #f1f5f9;
  --bg4: #f1f5f9;
  --border: rgba(0, 0, 0, .06);
  --border2: rgba(0, 0, 0, .1);
  --primary: #4f46e5;
  --primary-h: #4338ca;
  --accent: #7c3aed;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --text: #0f172a;
  --text2: #475569;
  --text3: #94a3b8;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 10px 40px rgba(0, 0, 0, .08);
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, .04);
  --font: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
  --transition: .2s cubic-bezier(.4, 0, .2, 1);
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background:
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.05) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(139, 92, 246, 0.05) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(99, 102, 241, 0.05) 0px, transparent 50%),
    radial-gradient(at 0% 100%, rgba(139, 92, 246, 0.05) 0px, transparent 50%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────────────────────────────── */
.header {
  background: rgba(255, 255, 255, 0.7);
  border-bottom: 1px solid var(--border);
  padding: 16px 32px;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px) saturate(180%);
  transition: padding var(--transition);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 24px;
  filter: drop-shadow(0 0 8px rgba(79, 70, 229, 0.4));
}

.logo-text {
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -.3px;
}

.logo-text strong {
  color: var(--primary);
  font-weight: 700;
}

.header-sub {
  color: var(--text3);
  font-size: 13px;
}

/* ── Layout ──────────────────────────────────────────────────────── */
.app-container {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: rgba(255, 255, 255, 0.8);
  border-right: 1px solid var(--border);
  padding: 32px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 0;
  height: 100vh;
  backdrop-filter: blur(12px);
  z-index: 101;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  color: var(--text2);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  transition: all var(--transition);
  cursor: pointer;
  border: 1px solid transparent;
}

.nav-item:hover {
  background: var(--bg3);
  color: var(--primary);
}

.nav-item.active {
  background: rgba(79, 70, 229, 0.08);
  color: var(--primary);
  border-color: rgba(79, 70, 229, 0.15);
}

.nav-icon {
  font-size: 18px;
}

.main {
  flex: 1;
  max-width: 1200px;
  margin: 0;
  padding: 40px 48px 80px;
  position: relative;
}

.app-view {
  display: none;
  animation: fadeIn 0.4s ease both;
}

.app-view.active {
  display: block;
}

/* ── Upload card ─────────────────────────────────────────────────── */
.upload-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.upload-card {
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--border2);
  backdrop-filter: blur(8px);
  border-radius: 24px;
  padding: 56px 48px 48px;
  text-align: center;
  width: 100%;
  max-width: 560px;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  cursor: default;
  box-shadow: var(--shadow);
}

.upload-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.12);
  border-color: var(--primary);
}

.upload-card.drag-over {
  border-color: var(--primary);
  background: rgba(79, 70, 229, 0.08);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
  transform: scale(1.02);
}

.upload-icon-wrap {
  margin-bottom: 24px;
}

.upload-icon {
  width: 72px;
  height: 72px;
  filter: drop-shadow(0 4px 20px rgba(79, 70, 229, 0.25));
  transition: transform var(--transition);
}

.upload-card:hover .upload-icon {
  transform: translateY(-4px) scale(1.1) rotate(5deg);
}

.upload-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}

.upload-sub {
  color: var(--text2);
  font-size: 14px;
  margin-bottom: 32px;
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 28px;
  border-radius: 50px;
  cursor: pointer;
  border: none;
  outline: none;
  transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition);
  box-shadow: 0 4px 20px rgba(99, 102, 241, .35);
  font-family: var(--font);
}

.upload-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px rgba(99, 102, 241, .5);
}

.upload-btn:active {
  transform: translateY(0);
}

/* File badge */
.file-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 10px 16px;
  margin-top: 20px;
  animation: slideIn .25s ease;
}

.file-badge-icon {
  font-size: 20px;
}

.file-badge-name {
  font-size: 14px;
  font-weight: 500;
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-badge-size {
  font-size: 12px;
  color: var(--text3);
  white-space: nowrap;
}

.file-badge-clear {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color var(--transition);
}

.file-badge-clear:hover {
  color: var(--danger);
}

/* Extract button */
.extract-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin-top: -5px;
  padding: 15px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  font-family: var(--font);
  border: none;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(79, 70, 229, 0.3);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.extract-btn::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: 0.5s;
}

.extract-btn:hover::after {
  left: 100%;
}

.extract-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.extract-btn:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(99, 102, 241, .45);
}

.extract-btn:not(:disabled):active {
  transform: translateY(0);
}

/* Spinner */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, .3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

/* ── Results section ─────────────────────────────────────────────── */
.results-section {
  animation: fadeUp 0.6s cubic-bezier(0.23, 1, 0.32, 1) both;
}

/* Top bar */
.results-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 16px;
}

.results-filename {
  font-size: 17px;
  font-weight: 700;
  display: block;
  margin-bottom: 6px;
}

.results-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--text2);
}

.meta-chip .chip-val {
  color: var(--text);
  font-weight: 600;
}

.results-topbar-right {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* Pill buttons */
.pill-btn {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
  transition: opacity var(--transition), transform var(--transition);
  box-shadow: 0 2px 12px rgba(99, 102, 241, .3);
}

.pill-btn.secondary {
  background: #fff;
  border: 1px solid var(--border2);
  box-shadow: var(--shadow-sm);
  color: var(--text2);
}

.pill-btn.small {
  padding: 6px 14px;
  font-size: 12px;
}

.pill-btn:hover {
  opacity: .85;
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
}

.pill-btn.email-primary {
  background: linear-gradient(135deg, #6366f1, #8b5cf6, #d946ef);
  background-size: 200% 200%;
  animation: gradientShift 4s ease infinite;
  color: #fff;
  padding: 12px 28px;
  font-size: 14px;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}

.automation-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 10px;
  border-radius: 20px;
  margin-bottom: 12px;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.email-fetch-hero {
  text-align: center;
  margin-bottom: 24px;
  padding: 32px;
  border: 2px solid rgba(99, 102, 241, 0.2) !important;
  background: rgba(99, 102, 241, 0.02) !important;
}

.email-fetch-hero p {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text2);
}

.separator-text {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 24px;
  color: var(--text3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  width: 100%;
  max-width: 560px;
}

.separator-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Validation errors */
.validation-errors {
  background: rgba(245, 158, 11, .07);
  border: 1px solid rgba(245, 158, 11, .3);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
  animation: fadeUp .3s ease both;
}

.ve-header {
  font-size: 14px;
  font-weight: 700;
  color: var(--warning);
  margin-bottom: 8px;
}

.ve-list {
  padding-left: 16px;
}

.ve-list li {
  font-size: 13px;
  color: #92400e;
  margin-bottom: 4px;
}

/* ── Tabs ────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 5px;
  margin-bottom: 16px;
  overflow-x: auto;
}

.tab {
  flex: 1;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text2);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}

.tab:hover {
  color: var(--text);
  background: var(--bg3);
}

.tab.active {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  box-shadow: 0 2px 12px rgba(99, 102, 241, .3);
}

/* Tab content */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeUp .25s ease both;
  position: relative;
  z-index: 500;
  width: 100%;
}

/* Split View Layout */
.split-layout {
  display: flex;
  gap: 32px;
  margin-top: 24px;
  align-items: flex-start;
  min-height: 80vh;
}

.extraction-fields {
  flex: 1;
  /* Takes remaining space (Left side) */
  max-width: 480px;
  /* Increased slightly for better fit */
  max-height: calc(100vh - 250px);
  overflow-y: auto;
  padding-right: 20px;
  padding-bottom: 8px;
}

.fields-line-items:not(:empty) {
  margin-top: 32px;
}

/* Custom scrollbar for extraction fields */
.extraction-fields::-webkit-scrollbar {
  width: 5px;
}

.extraction-fields::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 10px;
}

.extraction-preview {
  flex: 1.5;
  /* Takes more space for the PDF (Right side) */
  position: sticky;
  top: 40px;
  height: calc(100vh - 200px);
  background: var(--bg2);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

.preview-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
}

.expand-preview-btn {
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text2);
  transition: all var(--transition);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.expand-preview-btn:hover {
  background: #fff;
  color: var(--primary);
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.inline-preview-frame {
  width: 100%;
  flex: 1;
  border: none;
}

/* ── Fields tab ──────────────────────────────────────────────────── */
.fields-search-wrap {
  margin-bottom: 16px;
}

.fields-search {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 11px 16px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition);
}

.fields-search:focus {
  border-color: var(--primary);
}

.fields-search::placeholder {
  color: var(--text3);
}

.fields-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.category-heading {
  grid-column: 1 / -1;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text2);
  margin-top: 24px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  width: 100%;
}
.category-heading::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 14px;
  background: linear-gradient(to bottom, var(--primary), var(--accent));
  border-radius: 2px;
}
/* Ensure the first category heading does not have redundant top margin */
.category-heading:first-of-type {
  margin-top: 8px;
}

.field-card {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  transition: all 0.3s var(--transition);
  animation: fadeIn .4s ease both;
  box-shadow: var(--shadow-sm);
  position: relative;
  /* Ensure stacking context */
  z-index: 1;
}

.field-card:focus-within,
.field-card:hover {
  z-index: 99998;
  /* Bring active card to the absolute front */
}

.field-card.active-dropdown {
  z-index: 99999 !important;
  /* Keep active dropdown on top of everything */
}

.field-card:hover {
  border-color: var(--primary);
  border-left-color: var(--primary);
  transform: translateY(-4px);
  box-shadow: var(--shadow);
}

.field-label {
  font-size: 11px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .7px;
  margin-bottom: 4px;
}

.field-input {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  transition: all var(--transition);
  margin-top: 8px;
}

.field-input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}

/* Custom Select & Datalist Styling */
select.field-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
  cursor: pointer;
}

.custom-dropdown-input {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px !important;
}

input.field-input[list] {
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 15l5 5 5-5M7 9l5-5 5 5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

select.field-input:hover,
input.field-input:hover {
  border-color: var(--text3);
}

/* Custom Dropdown UI */
.custom-dropdown-wrap {
  position: relative;
  width: 100%;
}

.dropdown-list {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  width: 100%;
  max-height: 280px;
  overflow-y: auto;
  background: #ffffff;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  z-index: 999999;
  display: none;
  animation: fadeUp 0.2s ease;
}

.dropdown-search-wrap {
  position: sticky;
  top: 0;
  background: #ffffff;
  padding: 10px;
  border-bottom: 1px solid var(--bg3);
  z-index: 100;
}

.dropdown-search {
  width: 100%;
  padding: 10px 14px 10px 36px;
  /* Space for search icon */
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  background: var(--bg2);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
  font-family: var(--font);
  transition: all var(--transition);
}

.dropdown-search:focus {
  border-color: var(--primary);
  background-color: #fff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.dropdown-list.open-up {
  top: auto;
  bottom: calc(100% + 5px);
  animation: fadeDown 0.2s ease;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.15);
}

@keyframes fadeDown {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.dropdown-list.show {
  display: block;
}

.dropdown-list::-webkit-scrollbar {
  width: 6px;
}

.dropdown-list::-webkit-scrollbar-track {
  background: transparent;
}

.dropdown-list::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 10px;
}

.dropdown-list::-webkit-scrollbar-thumb:hover {
  background: var(--text3);
}

.dropdown-item {
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text2);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dropdown-item:hover {
  background: var(--bg3);
  color: var(--primary);
}

.dropdown-item.selected {
  background: rgba(79, 70, 229, 0.04);
  color: var(--primary);
  font-weight: 600;
}

.dropdown-item.selected::after {
  content: '';
  width: 12px;
  height: 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%234f46e5' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

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

.dropdown-item:hover {
  background: var(--bg3);
  color: var(--primary);
  padding-left: 18px;
}

.dropdown-item.selected {
  background: rgba(79, 70, 229, 0.05);
  color: var(--primary);
  font-weight: 600;
}

.no-results {
  color: var(--text3);
  font-size: 14px;
  text-align: center;
  padding: 32px;
  grid-column: 1/-1;
}

/* ── Tables tab ──────────────────────────────────────────────────── */
.table-block {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
  animation: fadeUp .25s ease both;
}

.table-block-header {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
}

.table-block-name {
  font-size: 14px;
  font-weight: 700;
}

.table-block-meta {
  font-size: 12px;
  color: var(--text3);
}

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

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data-table th {
  background: var(--bg4);
  color: var(--text2);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  font-size: 11px;
  padding: 10px 14px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

table.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  word-break: break-word;
}

table.data-table tbody tr:last-child td {
  border-bottom: none;
}

table.data-table tbody tr:hover td {
  background: rgba(0, 0, 0, .02);
}

.no-tables {
  color: var(--text3);
  font-size: 14px;
  text-align: center;
  padding: 48px;
}

/* ── Raw text tab ────────────────────────────────────────────────── */
.raw-text-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 600px;
  overflow-y: auto;
  color: var(--text);
}

/* ── JSON tab ────────────────────────────────────────────────────── */
.json-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.json-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 600px;
  overflow-y: auto;
  color: var(--text);
}

/* JSON syntax colouring */
.j-key {
  color: #4f46e5;
}

.j-str {
  color: #059669;
}

.j-num {
  color: #d97706;
}

.j-bool {
  color: #db2777;
}

.j-null {
  color: #64748b;
}

/* ── Confirm Footer ──────────────────────────────────────────────── */
.results-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 24px;
  padding-bottom: 24px;
  border-top: 1px dashed var(--border2);
}

.confirm-btn {
  background: linear-gradient(135deg, var(--success), #059669);
  width: auto;
  padding: 14px 32px;
  box-shadow: 0 4px 20px rgba(16, 185, 129, 0.3);
}

.confirm-btn:not(:disabled):hover {
  box-shadow: 0 8px 32px rgba(16, 185, 129, 0.45);
}

/* ── Modal ───────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(8px);
  z-index: 9999999;
  /* Absolute top-level */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-content {
  background: #fff;
  width: 100%;
  max-width: 900px;
  max-height: 90vh;
  border-radius: 24px;
  padding: 40px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  animation: fadeUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  display: flex;
  flex-direction: column;
}

.modal-content.large {
  max-width: 1200px;
  height: 90vh;
  padding: 20px;
}

.preview-frame {
  width: 100%;
  flex: 1;
  border: none;
  border-radius: 12px;
  background: var(--bg2);
}

/* ── Toast ───────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  top: 32px;
  right: 32px;
  transform: translateX(120%) translateY(0);
  background: rgba(30, 41, 59, 0.95);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 16px 24px;
  font-size: 14px;
  font-weight: 500;
  color: #f1f5f9;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  opacity: 0;
  transition: opacity .3s, transform .3s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: normal;
  max-width: 400px;
  word-wrap: break-word;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 10000001; /* Always above modals (modal is 9999999) */
}

.toast.show {
  opacity: 1;
  transform: translateX(0) translateY(0);
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(254, 242, 242, 0.95);
  color: #b91c1c;
  box-shadow: 0 10px 25px -5px rgba(220, 38, 38, 0.1), 0 8px 10px -6px rgba(220, 38, 38, 0.1);
}

.toast.success {
  border-color: rgba(34, 197, 94, 0.3);
  background: rgba(240, 253, 250, 0.95);
  color: #0d9488;
  box-shadow: 0 10px 25px -5px rgba(13, 148, 136, 0.1), 0 8px 10px -6px rgba(13, 148, 136, 0.1);
}

/* ── Button saving/loading state ─────────────────────────────────── */
@keyframes savingPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.btn-saving {
  animation: savingPulse 1s ease-in-out infinite;
  cursor: not-allowed !important;
  pointer-events: none;
  position: relative;
  opacity: 0.85;
}

/* ── Pagination ──────────────────────────────────────────────────── */
.pagination-wrap {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.pagination-info {
  font-size: 13px;
  color: var(--text3);
}

.pagination-controls {
  display: flex;
  gap: 8px;
}

.pagination-btn {
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border2);
  border-radius: 8px;
  background: #fff;
  color: var(--text2);
  cursor: pointer;
  transition: all var(--transition);
}

.pagination-btn:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--bg2);
}

.pagination-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

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

/* ── Animations ──────────────────────────────────────────────────── */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes pulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.4);
  }

  70% {
    transform: scale(1.05);
    box-shadow: 0 0 0 10px rgba(79, 70, 229, 0);
  }

  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(79, 70, 229, 0);
  }
}

/* ── Scrollbars ──────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg4);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text3);
}

/* ── Badges ──────────────────────────────────────────────────────── */
.badge {
  padding: 4px 10px;
  border-radius: 50px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: inline-block;
  white-space: nowrap;
  /* Prevent text wrapping inside the badge */
}

.source-email {
  background: rgba(79, 70, 229, 0.1);
  color: var(--primary);
  border: 1px solid rgba(79, 70, 229, 0.2);
}

.source-manual {
  background: rgba(124, 58, 237, 0.1);
  color: var(--accent);
  border: 1px solid rgba(124, 58, 237, 0.2);
}

.status-extracted {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-pending {
  background: rgba(245, 158, 11, 0.1);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

/* ── Statistics Dashboard ────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.stats-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  transition: all var(--transition);
  box-shadow: var(--shadow-sm);
}

.stats-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow);
  border-color: var(--primary);
}

.stats-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.stats-info {
  display: flex;
  flex-direction: column;
}

.stats-label {
  font-size: 13px;
  color: var(--text3);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stats-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  margin-top: 2px;
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .main {
    padding: 20px 14px 60px;
  }

  .upload-card {
    padding: 36px 20px 28px;
  }

  .results-topbar {
    flex-direction: column;
  }

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

  .tabs {
    gap: 2px;
  }

  .tab {
    flex: none;
    font-size: 11px;
    padding: 8px 12px;
  }
}

/* ── Compact UI Overrides (QB View) ──────────────────────────────── */
#quickbooks-view .stats-card {
  padding: 10px 14px;
}

#quickbooks-view .stats-icon {
  width: 32px;
  height: 32px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

#quickbooks-view .stats-label {
  font-size: 10px;
  margin-bottom: 2px;
}

#quickbooks-view .stats-value {
  font-size: 15px;
  font-weight: 700;
}

#quickbooks-view .results-topbar {
  padding: 8px 14px;
  margin-bottom: 12px;
}

#quickbooks-view .pill-btn.small {
  padding: 5px 12px;
  font-size: 11px;
}

.pill-btn.qb-connect {
  background: var(--success);
  color: #fff !important;
  padding: 10px 24px !important;
  font-size: 14px !important;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.pill-btn.qb-disconnect {
  background: var(--danger);
  color: #fff !important;
  padding: 10px 24px !important;
  font-size: 14px !important;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* ── 3-Dot Action Menu Dropdown ──────────────────────────────────── */
.action-menu-container {
  position: relative;
  display: inline-block;
}

.action-menu-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text3);
  padding: 4px 8px;
  border-radius: 50%;
  line-height: 1;
  transition: background-color 0.2s, color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.action-menu-btn:hover {
  background-color: var(--bg3);
  color: var(--text);
}

.action-menu-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  z-index: 100;
  min-width: 120px;
  overflow: hidden;
  animation: fadeUp 0.15s ease;
}

.action-menu-dropdown.show {
  display: block;
}

.action-menu-item {
  width: 100%;
  padding: 10px 16px;
  font-size: 13px;
  text-align: left;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font);
  font-weight: 500;
  transition: background-color 0.15s;
}

.action-menu-item:hover {
  background-color: var(--bg2);
}

.action-menu-item.delete {
  color: var(--danger);
}

.action-menu-item.delete:hover {
  background-color: rgba(239, 68, 68, 0.05);
}