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

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-muted: #f9fafb;
  --ink: #111827;
  --ink-muted: #4b5563;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --success: #10b981;
  --error: #ef4444;
  --font-family: "Inter", system-ui, -apple-system, sans-serif;
  --radius: 8px;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-muted: #334155;
  --ink: #f8fafc;
  --ink-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --border: #334155;
  --border-strong: #475569;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-family);
  background-color: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s, color 0.3s;
}

.page-shell {
  max-width: 1024px;
  margin: 0 auto;
  padding: 40px 20px;
}

/* Theme Switcher */
.theme-switcher {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
}

.theme-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  font-size: 1.2rem;
  transition: transform 0.2s;
}

.theme-button:hover {
  transform: scale(1.1);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  margin: 0 0 16px;
  font-weight: 600;
  color: var(--ink);
}

h1 { font-size: 2.25rem; line-height: 1.2; }
h2 { font-size: 1.5rem; line-height: 1.3; }
h3 { font-size: 1.25rem; line-height: 1.4; }
p { margin: 0 0 16px; color: var(--ink-muted); }

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.2s, border-color 0.2s;
  border: 1px solid transparent;
}

.button-primary {
  background-color: var(--primary);
  color: #fff;
}

.button-primary:hover {
  background-color: var(--primary-hover);
}

.button-secondary {
  background-color: var(--surface-muted);
  border-color: var(--border);
  color: var(--ink);
}

.button-secondary:hover {
  background-color: var(--border);
  border-color: var(--border-strong);
}

.button-ghost {
  background-color: transparent;
  color: var(--ink-muted);
}

.button-ghost:hover {
  background-color: var(--surface-muted);
  color: var(--ink);
}

/* Stepper */
.stepper {
  display: flex;
  list-style: none;
  padding: 0;
  margin: 0 0 32px;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.stepper::-webkit-scrollbar { display: none; }

.stepper li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
  white-space: nowrap;
  color: var(--ink-muted);
}

.stepper li.is-active {
  background: var(--surface);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.stepper li.is-complete {
  background: rgba(16, 185, 129, 0.1);
  border-color: var(--success);
  color: var(--success);
}

.step-index {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: currentColor;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
}

.stepper li.is-active .step-index, .stepper li.is-complete .step-index {
  color: #fff;
}
.stepper li:not(.is-active):not(.is-complete) .step-index {
  background: var(--border-strong);
  color: #fff;
}


/* Panels */
.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  background: var(--surface);
  margin-bottom: 24px;
  transition: background-color 0.3s, border-color 0.3s;
}

.panel-head {
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
}
.panel-head h2 { margin: 0; }

.panel-actions {
  display: flex;
  gap: 12px;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

/* Forms */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field span, .review-field span {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink-muted);
}

input, textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--surface);
  transition: border-color 0.2s, background-color 0.3s;
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

/* Upload Grid */
.upload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.upload-grid-single {
  grid-template-columns: minmax(300px, 400px);
}

.upload-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  background: var(--surface-muted);
  height: 100%;
}

.upload-card.is-ready { border-color: var(--success); }
.upload-card.is-processing { border-color: var(--primary); }
.upload-card.is-error { border-color: var(--error); }
.upload-card.is-skipped { opacity: 0.7; }

.upload-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
  height: 90px; /* Fixed height so images align perfectly horizontally */
}

.upload-card-head > div {
  flex: 1;
}

.upload-card-head h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
  line-height: 1.2;
}

.upload-card-head p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--ink-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3; /* Limit description to 3 lines */
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.upload-state-badge {
  flex-shrink: 0;
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.upload-state-badge.is-muted { background: var(--border); color: var(--ink-muted); }
.upload-state-badge.is-info { background: rgba(37, 99, 235, 0.1); color: var(--primary); }
.upload-state-badge.is-success { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.upload-state-badge.is-error { background: rgba(239, 68, 68, 0.1); color: var(--error); }

.upload-preview {
  width: 100%;
  aspect-ratio: 16/10;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 16px;
}

.upload-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 20px;
  flex-grow: 1; /* Pushes buttons to the bottom of the card */
}
.upload-meta strong {
  font-size: 0.95rem;
  color: var(--ink);
}
.upload-meta span {
  font-size: 0.85rem;
  color: var(--ink-muted);
  line-height: 1.4;
}

.upload-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: auto;
}

.upload-actions .button {
  padding: 8px 12px;
  font-size: 0.85rem;
  width: 100%;
}

.upload-actions .button-ghost {
  grid-column: span 1;
}
.upload-actions:has(.button-ghost:only-child) .button-ghost {
  grid-column: span 2;
}

/* Review Section */
.review-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
}
@media (max-width: 768px) {
  .review-layout { grid-template-columns: 1fr; }
}

.review-section-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.review-section-chip {
  padding: 8px 18px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink-muted);
  transition: all 0.2s;
}
.review-section-chip.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
  transform: translateY(-1px);
}

.review-subgroup {
  margin-bottom: 32px;
}
.review-subgroup h4 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 20px;
}

.review-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}

.review-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.review-field.is-multiline {
  grid-column: 1 / -1;
}

.review-field span {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.review-field input, .review-field textarea {
  width: 100%;
  border-color: var(--border-strong);
}

.review-field textarea {
  min-height: 60px;
  line-height: 1.4;
}

.checks-card, .draft-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  background: var(--surface-muted);
}

.checks-card h3, .draft-card h3 {
  font-size: 1.1rem;
  margin-bottom: 12px;
}

.check-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.875rem;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.check-item:last-child { border-bottom: none; }
.check-item[data-status="conflict"] strong { color: var(--error); }
.check-item[data-status="matched"] strong { color: var(--success); }

pre[data-draft-contract] {
  font-family: monospace;
  font-size: 0.8rem;
  white-space: pre-wrap;
  color: var(--ink-muted);
  margin: 0;
}

/* Utility / Status */
.status-banner, .success-banner, .status-toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 0.95rem;
  font-weight: 500;
}
.status-banner.is-error, .status-toast.is-error { background: rgba(239, 68, 68, 0.1); color: var(--error); border: 1px solid var(--error); }
.status-banner.is-success, .success-banner, .status-toast.is-success { background: rgba(16, 185, 129, 0.1); color: var(--success); border: 1px solid var(--success); }
.status-banner.is-warning { background: rgba(245, 158, 11, 0.1); color: #b45309; border: 1px solid #fcd34d; }

.status-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 50;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink);
}

.pdf-preview-shell {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 24px;
  height: 600px;
}
iframe[data-pdf-frame] {
  width: 100%;
  height: 100%;
  border: none;
}

/* Landing Page specific */
.landing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 40px;
}
.landing-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  background: var(--surface);
}
.landing-card h3 {
  font-size: 1.25rem;
  margin-bottom: 12px;
}
.hero {
  text-align: center;
  padding: 60px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 40px;
}
.hero h1 {
  font-size: 3rem;
  margin-bottom: 20px;
}
.hero p.hero-copy {
  font-size: 1.25rem;
  max-width: 600px;
  margin: 0 auto 32px;
}
.hero-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
}

.hero-process {
  margin-top: 60px;
  text-align: left;
}
.hero-flow {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  list-style: none;
  padding: 0;
  margin-top: 24px;
}
.hero-flow li {
  border: 1px solid var(--border);
  padding: 20px;
  border-radius: var(--radius);
}
.hero-flow strong {
  display: block;
  font-size: 1.1rem;
  margin: 12px 0 8px;
}
.flow-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  font-weight: 600;
  font-size: 0.9rem;
}
.landing-list {
  list-style: disc;
  padding-left: 20px;
  margin-bottom: 40px;
}
.landing-list li {
  margin-bottom: 8px;
}
