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

:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-light: #eff6ff;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --amber-bg: #fef3c7;
  --amber: #92400e;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-400: #94a3b8;
  --gray-600: #475569;
  --gray-800: #1e293b;
  --red: #991b1b;
  --red-bg: #fef2f2;
  --red-border: #fecaca;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.1);
  --radius: 0.5rem;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--gray-800);
}

header p {
  color: var(--gray-600);
  margin-top: 0.375rem;
}

.card {
  background: white;
  border-radius: 0.75rem;
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

/* ─── Email form ─────────────────────────────────────────────────────────── */

#email-form label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 0.5rem;
}

.input-row {
  display: flex;
  gap: 0.75rem;
}

.input-row input[type="email"] {
  flex: 1;
  padding: 0.625rem 1rem;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: white;
  color: var(--gray-800);
}

.input-row input[type="email"]:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

/* ─── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  white-space: nowrap;
  line-height: 1;
}

.btn:active:not(:disabled) { transform: translateY(1px); }

.btn-primary {
  background: var(--blue);
  color: white;
}

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

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

.btn-confirm {
  background: var(--green);
  color: white;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.btn-confirm:hover:not(:disabled) { background: #15803d; }

.btn-confirm:disabled {
  background: var(--gray-200);
  color: var(--gray-400);
  cursor: not-allowed;
}

/* ─── Stats ───────────────────────────────────────────────────────────────── */

.stats-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat-badge {
  padding: 0.3rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.stat-badge.unmapped { background: var(--amber-bg); color: var(--amber); }
.stat-badge.mapped   { background: var(--green-bg); color: var(--green); }

.stat-total {
  margin-left: auto;
  font-size: 0.8125rem;
  color: var(--gray-400);
}

/* ─── Section headers ─────────────────────────────────────────────────────── */

.section-header {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--gray-600);
  background: var(--gray-100);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  margin-top: 1.25rem;
}

.section-header:first-child { margin-top: 0; }

/* ─── Company rows ────────────────────────────────────────────────────────── */

.company-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: white;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.company-row:focus-within {
  border-color: #a5b4fc;
  box-shadow: 0 0 0 3px rgba(99,102,241,0.08);
}

.company-row.mapped {
  background: var(--gray-50);
  border-color: var(--gray-100);
}

.company-name {
  flex: 0 0 280px;
  font-weight: 500;
  font-size: 0.9375rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.company-row.mapped .company-name {
  color: var(--gray-600);
}

.company-mapping {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

/* ─── Autocomplete ────────────────────────────────────────────────────────── */

.autocomplete-wrapper {
  flex: 1;
  position: relative;
  min-width: 0;
}

.autocomplete-wrapper input {
  width: 100%;
  padding: 0.5rem 0.875rem;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 0.9375rem;
  outline: none;
  background: white;
  color: var(--gray-800);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.autocomplete-wrapper input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.autocomplete-wrapper input::placeholder { color: var(--gray-400); }

.dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  background: white;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 200;
  max-height: 220px;
  overflow-y: auto;
}

.dropdown.visible { display: block; }

.dropdown ul { list-style: none; }

.dropdown li {
  padding: 0.5rem 0.875rem;
  cursor: pointer;
  font-size: 0.9375rem;
  transition: background 0.1s;
  border-bottom: 1px solid var(--gray-100);
}

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

.dropdown li:hover,
.dropdown li.active {
  background: var(--blue-light);
  color: var(--blue-dark);
}

.dropdown li.no-results {
  color: var(--gray-400);
  cursor: default;
  font-style: italic;
}

.dropdown li.loading {
  color: var(--gray-400);
  font-style: italic;
}

/* ─── Mapped badge ────────────────────────────────────────────────────────── */

.mapped-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.3rem 0.75rem;
  background: var(--green-bg);
  color: var(--green);
  border-radius: 9999px;
  font-size: 0.875rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.mapped-badge::before { content: '✓'; }

/* ─── Error banner ────────────────────────────────────────────────────────── */

.error-banner {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid var(--red-border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

/* ─── All done ────────────────────────────────────────────────────────────── */

.all-done {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--green);
}

.all-done-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
}

/* ─── Toast ───────────────────────────────────────────────────────────────── */

#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 1000;
}

.toast {
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease;
  max-width: 380px;
}

.toast.error {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid var(--red-border);
}

.toast.success {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid #bbf7d0;
}

@keyframes slideIn {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ─── Utility ─────────────────────────────────────────────────────────────── */

.hidden { display: none !important; }

/* ─── Loading spinner ─────────────────────────────────────────────────────── */

.spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

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

/* ─── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .company-name { flex: 0 0 160px; }
  .input-row { flex-direction: column; }
}
