:root {
  --bg: #f6f8fb;
  --ink: #101828;
  --text: #1d2939;
  --muted: #667085;
  --faint: #98a2b3;
  --line: #d6dee7;
  --surface: #ffffff;
  --surface-2: #f9fbfd;
  --nav: #07141c;
  --nav-2: #0b222b;
  --teal: #069693;
  --teal-dark: #007978;
  --teal-soft: #dbf6f2;
  --blue: #1f6feb;
  --blue-soft: #e8f1ff;
  --green: #16803c;
  --green-soft: #def7e7;
  --amber: #b76e00;
  --amber-soft: #fff2cf;
  --red: #b42318;
  --red-soft: #fee4e2;
  --shadow: 0 18px 54px rgba(31, 46, 70, 0.09);
  --soft-shadow: 0 10px 26px rgba(31, 46, 70, 0.06);
  --radius: 8px;
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(6, 150, 147, 0.04), transparent 260px),
    var(--bg);
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 246px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 24px 16px 18px;
  color: #d7e4ea;
  background:
    linear-gradient(180deg, rgba(9, 43, 50, 0.92), rgba(4, 15, 23, 0.98)),
    var(--nav);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  font-size: 23px;
  font-weight: 790;
  text-decoration: none;
}

.brand-mark {
  width: 34px;
  height: 34px;
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: #13c9bd;
  box-shadow: 0 12px 28px rgba(19, 201, 189, 0.24);
}

.brand-mark span {
  position: absolute;
  background: #06333a;
  border-radius: 2px;
}

.brand-mark span:first-child {
  left: 9px;
  top: 8px;
  width: 7px;
  height: 18px;
}

.brand-mark span:last-child {
  left: 9px;
  bottom: 8px;
  width: 17px;
  height: 7px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: #d7e4ea;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 610;
  text-align: left;
}

.nav-item svg {
  width: 19px;
  height: 19px;
}

.nav-item.active {
  color: #fff;
  background: linear-gradient(90deg, rgba(8, 192, 181, 0.82), rgba(8, 192, 181, 0.36));
  box-shadow: inset 4px 0 0 #5af4e7;
}

.sidebar-card {
  margin-top: auto;
  display: grid;
  gap: 8px;
  border: 1px solid rgba(214, 222, 231, 0.2);
  border-radius: var(--radius);
  padding: 16px;
  background: rgba(255, 255, 255, 0.06);
}

.sidebar-card strong {
  color: #fff;
  font-size: 14px;
}

.sidebar-card span:not(.pulse-dot) {
  color: #c7d5dc;
  font-size: 12px;
  line-height: 1.45;
}

.sidebar-card button {
  height: 38px;
  margin-top: 4px;
  border: 1px solid #12d4c8;
  border-radius: var(--radius);
  background: rgba(18, 212, 200, 0.08);
  color: #7ff8ee;
  font-size: 13px;
  font-weight: 760;
}

.pulse-dot {
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(22, 128, 60, 0.2);
}

.pulse-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: inherit;
  background: #2bd071;
}

.account-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(214, 222, 231, 0.16);
  border-radius: var(--radius);
}

.avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--blue-soft);
  color: #175cd3;
  font-size: 13px;
  font-weight: 800;
}

.account-card strong {
  display: block;
  color: #fff;
  font-size: 13px;
}

.account-card span {
  display: block;
  margin-top: 2px;
  color: #b7c7d0;
  font-size: 12px;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  margin-bottom: 22px;
}

.topbar h1 {
  margin: 0 0 5px;
  color: var(--ink);
  font-size: 28px;
  line-height: 1.1;
}

.topbar p,
.panel-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon-button {
  position: relative;
  width: 43px;
  height: 43px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: #344054;
  box-shadow: var(--soft-shadow);
}

.notification-dot {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border: 2px solid var(--surface);
  border-radius: 999px;
  background: #12b9ae;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border-radius: var(--radius);
  padding: 0 17px;
  font-size: 14px;
  font-weight: 760;
  white-space: nowrap;
}

.primary-button {
  border: 0;
  color: #fff;
  background: linear-gradient(180deg, #079f9b, #007978);
  box-shadow: 0 14px 28px rgba(0, 121, 120, 0.18);
}

.secondary-button,
.ghost-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: #344054;
  box-shadow: var(--soft-shadow);
}

.ghost-button {
  box-shadow: none;
}

.compact {
  min-height: 36px;
  padding-inline: 12px;
  font-size: 13px;
}

.button-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 999px;
  animation: spin 800ms linear infinite;
}

body[data-stage="extracting"] .button-spinner {
  display: block;
}

body[data-stage="extracting"] .button-icon {
  display: none;
}

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

.workflow-strip {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--soft-shadow);
}

.workflow-step {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.workflow-step strong {
  display: block;
  color: var(--ink);
  font-size: 13px;
}

.workflow-step span:not(.step-icon) {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workflow-arrow {
  color: var(--faint);
  font-size: 18px;
}

.step-icon {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #eef2f6;
  color: #64748b;
}

.step-icon svg {
  width: 18px;
  height: 18px;
}

.step-icon.success {
  background: var(--green-soft);
  color: var(--green);
}

.step-icon.active {
  background: var(--blue-soft);
  color: var(--blue);
}

.step-icon.warning {
  background: var(--amber-soft);
  color: var(--amber);
}

.step-icon.cloud {
  background: var(--teal-soft);
  color: var(--teal-dark);
}

body[data-stage="error"] .workflow-step[data-step="review"] .step-icon {
  background: var(--red-soft);
  color: var(--red);
}

.command-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.05fr);
  gap: 16px;
  align-items: stretch;
}

.upload-panel,
.preview-panel,
.line-items-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.upload-panel,
.preview-panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-head h2 {
  margin: 0 0 5px;
  color: var(--ink);
  font-size: 17px;
  line-height: 1.2;
}

.provider-badge,
.confidence-chip,
.confidence-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 780;
}

.provider-badge {
  height: 28px;
  padding: 0 11px;
  background: var(--teal-soft);
  color: var(--teal-dark);
}

.provider-badge.warning {
  background: var(--amber-soft);
  color: var(--amber);
}

.drop-zone {
  min-height: 210px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 9px;
  padding: 22px;
  border: 1.5px dashed #22bbb3;
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(6, 150, 147, 0.045), transparent),
    #fbfefd;
  text-align: center;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.drop-zone.dragover {
  transform: translateY(-1px);
  border-color: var(--teal-dark);
  background: var(--teal-soft);
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.upload-icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border: 2px solid var(--teal);
  border-radius: 14px;
  background: #fff;
  color: var(--teal-dark);
  box-shadow: var(--soft-shadow);
}

.upload-icon svg {
  width: 28px;
  height: 28px;
}

.drop-zone strong {
  margin-top: 6px;
  color: var(--ink);
  font-size: 19px;
}

.drop-zone span,
.drop-zone small {
  color: var(--muted);
  font-size: 13px;
}

.upload-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
}

.sample-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 18px 0 11px;
}

.sample-head h3 {
  margin: 0;
  color: var(--ink);
  font-size: 15px;
}

.sample-head button {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-size: 13px;
  font-weight: 720;
}

.sample-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.sample-card {
  min-width: 0;
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 8px;
  text-align: left;
}

.sample-card.active {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(6, 150, 147, 0.14);
}

.sample-card img {
  width: 100%;
  aspect-ratio: 0.78;
  object-fit: cover;
  object-position: top;
  border-radius: 6px;
  background: #f0f4f8;
}

.sample-card span {
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sample-card small,
.sample-card em {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.confidence-chip {
  min-width: 92px;
  height: 32px;
  gap: 5px;
  background: var(--green-soft);
  color: var(--green);
}

.confidence-chip span {
  font-size: 14px;
}

.confidence-chip.empty {
  background: #eef2f6;
  color: var(--muted);
}

.confidence-chip.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.empty-state {
  min-height: 285px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  text-align: center;
  padding: 26px;
}

.empty-state svg {
  width: 42px;
  height: 42px;
  color: var(--teal-dark);
}

.empty-state strong {
  color: var(--ink);
  font-size: 16px;
}

.empty-state span {
  max-width: 280px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.field-list {
  display: grid;
  border-top: 1px solid var(--line);
}

.field-row {
  display: grid;
  grid-template-columns: 22px minmax(100px, 0.75fr) minmax(130px, 1fr) 56px;
  gap: 12px;
  align-items: center;
  min-height: 44px;
  border-bottom: 1px solid var(--line);
}

.field-row svg {
  width: 16px;
  height: 16px;
  color: #64748b;
}

.field-row span {
  color: #475467;
  font-size: 13px;
}

.field-row strong {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
}

.confidence-badge {
  min-width: 42px;
  height: 23px;
  padding: 0 8px;
  background: var(--green-soft);
  color: var(--green);
}

.confidence-badge.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.confidence-badge.empty {
  background: #eef2f6;
  color: var(--muted);
}

.review-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
}

.review-bar button {
  border: 0;
  background: transparent;
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 760;
}

.line-items-panel {
  margin-top: 16px;
  padding: 18px;
}

.line-head {
  align-items: center;
}

.line-head h2 span {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  margin-left: 6px;
  border-radius: 999px;
  background: #edf2f7;
  color: var(--muted);
  font-size: 12px;
}

.line-tools {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #344054;
  font-size: 13px;
  font-weight: 650;
}

.toggle input {
  position: absolute;
  opacity: 0;
}

.toggle span {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #d0d5dd;
}

.toggle span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #fff;
  transition: transform 160ms ease;
}

.toggle input:checked + span {
  background: var(--teal);
}

.toggle input:checked + span::after {
  transform: translateX(16px);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  height: 45px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  background: #f8fafc;
  color: #475467;
  font-size: 12px;
  font-weight: 790;
}

tr:last-child td {
  border-bottom: 0;
}

td:first-child,
th:first-child {
  width: 48px;
  color: var(--muted);
}

.mobile-line-items {
  display: none;
}

.totals-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
  margin-top: 16px;
}

.totals {
  display: flex;
  justify-content: end;
  gap: 28px;
  color: var(--muted);
  font-size: 12px;
}

.totals strong {
  display: block;
  margin-top: 2px;
  color: var(--ink);
  font-size: 15px;
}

.export-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 44px));
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  padding: 13px 15px;
  font-size: 13px;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast[data-tone="error"] {
  border-color: #fecdca;
  background: #fff8f7;
  color: var(--red);
}

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

.mobile-nav {
  display: none;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 14px;
  }

  .brand {
    flex: 0 0 auto;
    font-size: 20px;
  }

  .nav-list {
    display: flex;
    min-width: max-content;
  }

  .sidebar-card,
  .account-card {
    display: none;
  }

  .workflow-strip,
  .command-grid {
    grid-template-columns: 1fr;
  }

  .workflow-arrow {
    display: none;
  }

  .workflow-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  body {
    padding-bottom: 72px;
  }

  .workspace {
    padding: 18px 14px 22px;
  }

  .sidebar {
    padding: 12px 14px;
  }

  .nav-list {
    display: none;
  }

  .topbar,
  .top-actions,
  .upload-actions,
  .line-tools,
  .export-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar h1 {
    font-size: 23px;
  }

  .topbar {
    margin-bottom: 14px;
  }

  .secondary-button,
  .primary-button,
  .ghost-button {
    width: 100%;
  }

  .workflow-strip {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
  }

  .workflow-step {
    min-height: 48px;
  }

  .panel-head,
  .line-head {
    flex-direction: column;
    align-items: stretch;
  }

  .upload-panel,
  .preview-panel,
  .line-items-panel {
    padding: 14px;
  }

  .drop-zone {
    min-height: 205px;
    padding: 20px 14px;
  }

  .sample-grid {
    display: flex;
    overflow-x: auto;
    padding-bottom: 6px;
    scroll-snap-type: x mandatory;
  }

  .sample-card {
    flex: 0 0 132px;
    scroll-snap-align: start;
  }

  .field-row {
    grid-template-columns: 20px 1fr 50px;
    gap: 9px;
    padding: 9px 0;
  }

  .field-row strong {
    grid-column: 2 / 4;
  }

  .table-wrap {
    display: none;
  }

  .mobile-line-items {
    display: grid;
    gap: 10px;
  }

  .mobile-line-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    padding: 12px;
  }

  .mobile-line-card > div:first-child {
    display: flex;
    gap: 10px;
    align-items: start;
  }

  .mobile-line-card > div:first-child span {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 999px;
    background: #eef2f6;
    color: var(--muted);
    font-size: 12px;
    font-weight: 760;
  }

  .mobile-line-card strong {
    color: var(--ink);
    font-size: 13px;
  }

  .mobile-line-card dl {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px 14px;
    margin: 12px 0 0;
  }

  .mobile-line-card div {
    min-width: 0;
  }

  .mobile-line-card dt {
    color: var(--muted);
    font-size: 11px;
  }

  .mobile-line-card dd {
    margin: 2px 0 0;
    overflow-wrap: anywhere;
    color: var(--ink);
    font-size: 12px;
    font-weight: 700;
  }

  .totals-row {
    grid-template-columns: 1fr;
  }

  .totals {
    justify-content: space-between;
    gap: 12px;
  }

  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 15;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(18px);
  }

  .mobile-nav button {
    min-height: 62px;
    display: grid;
    place-items: center;
    gap: 3px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    font-weight: 690;
  }

  .mobile-nav button.active {
    color: var(--teal-dark);
  }

  .mobile-nav svg {
    width: 19px;
    height: 19px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
