@import url("https://fonts.googleapis.com/css2?family=Archivo+Black&family=Space+Grotesk:wght@400;500;600;700&display=swap");

:root {
  --background: #f4f5f2;
  --foreground: #0b0b0b;
  --slam-black: #0b0b0b;
  --slam-red: #da0016;
  --slam-lime: #80ff00;
  --slam-green: #1b4d20;
  --font-sans: "Space Grotesk", system-ui, sans-serif;
  --font-display: "Archivo Black", Impact, sans-serif;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --red-50: #fef2f2;
  --red-200: #fecaca;
  --red-700: #b91c1c;
}

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

html, body {
  min-height: 100%;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  background: var(--slam-black);
  padding: 16px;
  border-bottom: 4px solid var(--slam-lime);
}
.app-header-inner {
  max-width: 48rem;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.app-header img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}
.app-header h1 {
  font-family: var(--font-display);
  font-size: 1.125rem;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  color: #fff;
  line-height: 1.25;
}
.app-header p {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.5);
}

/* Step bar */
.step-bar {
  background: #fff;
  padding: 20px 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.step-bar-inner {
  max-width: 48rem;
  margin: 0 auto;
  display: flex;
  align-items: center;
}
.step-node-wrap {
  display: flex;
  flex: 1;
  align-items: center;
}
.step-node-wrap:last-child { flex: none; }
.step-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.step-circle {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  transition: all 0.15s ease;
}
.step-circle.pending { background: var(--gray-100); color: var(--gray-400); }
.step-circle.active {
  background: var(--slam-red);
  color: #fff;
  box-shadow: 0 0 0 4px rgba(218, 0, 22, 0.2);
  animation: soft-pulse 1.6s ease-in-out infinite;
}
.step-circle.done { background: var(--slam-green); color: #fff; }
.step-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.step-label.pending { color: var(--gray-400); }
.step-label.active { color: var(--slam-red); }
.step-label.done { color: var(--slam-green); }
.step-line {
  flex: 1;
  height: 2px;
  margin: 0 8px;
  border-radius: 999px;
  background: var(--gray-200);
  transition: background 0.15s ease;
}
.step-line.done { background: var(--slam-green); }

@keyframes soft-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
@keyframes bull-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.bull-spinner { animation: bull-spin 1.6s linear infinite; }

/* Main */
.app-main {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
}
.app-main-inner {
  width: 100%;
  max-width: 48rem;
}

.screen { display: none; }
.screen-visible { display: block; }

/* Cards */
.card {
  background: #fff;
  border-radius: 1rem;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.card-title {
  font-family: var(--font-display);
  font-size: 1.125rem;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  color: var(--slam-black);
}
.card-sub {
  font-size: 0.75rem;
  color: var(--gray-400);
  margin-top: 4px;
  margin-bottom: 20px;
}

/* Upload zone */
.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 2px dashed var(--gray-300);
  border-radius: 1rem;
  background: #fff;
  padding: 80px 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.upload-zone:hover {
  border-color: var(--slam-red);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.08);
}
.upload-icon {
  width: 48px;
  height: 48px;
  color: var(--gray-300);
  margin-bottom: 16px;
}
.upload-title {
  font-family: var(--font-display);
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  color: var(--slam-black);
}
.upload-sub {
  font-size: 0.75rem;
  color: var(--gray-400);
  margin-top: 4px;
}

/* Fields */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--gray-600);
  margin-bottom: 4px;
}
.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--gray-300);
  border-radius: 0.5rem;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--foreground);
  background: #fff;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--slam-red);
  box-shadow: 0 0 0 1px var(--slam-red);
}
.field input.from-ocr {
  border-color: var(--slam-green);
  background: #f0fdf4;
}
.field-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 640px) {
  .field-grid { grid-template-columns: 1fr 1fr; }
}

.composite-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.composite-prefix {
  font-family: var(--font-display);
  font-size: 0.875rem;
  color: var(--slam-black);
  flex: none;
}
.field-hint {
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-top: 6px;
}
.field-hint strong { color: var(--slam-green); font-weight: 600; }

.section-label {
  margin-top: 24px;
  margin-bottom: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--slam-green);
}

/* Table */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--gray-200);
  border-radius: 0.5rem;
}
.items-table {
  width: 100%;
  font-size: 0.75rem;
  border-collapse: collapse;
}
.items-table thead tr {
  border-bottom: 1px solid var(--gray-200);
  background: var(--gray-50);
  color: var(--gray-500);
  text-align: left;
}
.items-table th,
.items-table td {
  padding: 8px;
}
.items-table th:last-child,
.items-table td:last-child { text-align: right; }
.items-table th:nth-child(3),
.items-table td:nth-child(3) { text-align: center; }
.items-table tbody tr { border-bottom: 1px solid var(--gray-100); }
.items-table input {
  width: 100%;
  border: 1px solid var(--gray-200);
  border-radius: 0.25rem;
  padding: 4px 6px;
  font-size: 0.75rem;
  font-family: inherit;
}
.items-table input[data-key="qty"] { width: 56px; text-align: center; }
.items-table input[data-key="amount"] { width: 88px; text-align: right; }

.totals-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  margin-top: 16px;
  font-size: 0.875rem;
}
.totals-row {
  display: flex;
  align-items: center;
  gap: 16px;
}
.totals-row label { font-size: 0.75rem; color: var(--gray-600); min-width: 120px; text-align: right; }
.totals-row input { width: 100px; text-align: right; }
.totals-value { font-weight: 700; color: var(--slam-green); font-size: 1rem; }

.ocr-banner {
  margin-bottom: 16px;
  padding: 10px 12px;
  border-radius: 0.5rem;
  border: 1px solid #bbf7d0;
  background: #f0fdf4;
  font-size: 0.75rem;
  color: var(--slam-green);
}

.preview {
  margin-top: 16px;
  border-radius: 0.5rem;
  overflow: hidden;
  border: 1px solid var(--gray-200);
}
.preview img { width: 100%; display: block; }

.ocr-status {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 0.5rem;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  font-size: 0.8125rem;
  color: var(--gray-600);
  display: none;
  align-items: center;
  gap: 10px;
}
.ocr-status.err {
  background: var(--red-50);
  border-color: var(--red-200);
  color: var(--red-700);
}
.ocr-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex: none;
  border: 2px solid var(--gray-200);
  border-top-color: var(--slam-red);
  animation: bull-spin 0.8s linear infinite;
}

/* Buttons */
.actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
  padding-top: 16px;
}
.btn {
  border: none;
  border-radius: 999px;
  padding: 8px 24px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  cursor: pointer;
  transition: filter 0.15s ease, background 0.15s ease;
}
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary {
  background: var(--slam-red);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn-ghost {
  background: transparent;
  color: var(--gray-500);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}
.btn-ghost:hover:not(:disabled) { background: var(--gray-100); }
.btn-outline {
  background: transparent;
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}
.btn-outline:hover:not(:disabled) { background: var(--gray-50); }

.error-banner {
  margin-bottom: 16px;
  padding: 12px 16px;
  border-radius: 0.5rem;
  border: 1px solid var(--red-200);
  background: var(--red-50);
  font-size: 0.875rem;
  color: var(--red-700);
}

.done-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 999px;
  background: rgba(128, 255, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.done-icon svg {
  width: 32px;
  height: 32px;
  color: var(--slam-green);
}
.done-card { text-align: center; }

.sig-wrap {
  border: 1px solid var(--gray-300);
  border-radius: 0.75rem;
  background: #fff;
  overflow: hidden;
  touch-action: none;
}
.sig-canvas {
  display: block;
  width: 100%;
  height: 160px;
  cursor: crosshair;
  background: #fff;
}
.sig-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  gap: 12px;
}
.sig-hint { font-size: 0.75rem; color: var(--gray-500); }
.vendor-field {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--gray-200);
}

.upload-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
}

@media (max-width: 640px) {
  .app-main { padding: 24px 12px; }
  .upload-zone { padding: 48px 16px; }
  .actions { flex-direction: column-reverse; }
  .btn { width: 100%; text-align: center; }
}
