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

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #eef4ff;
  --line: #dbe5f3;
  --line-strong: #b8c8dc;
  --text: #0f172a;
  --muted: #475569;
  --primary: #1e40af;
  --primary-2: #2563eb;
  --primary-soft: #dbeafe;
  --amber: #f59e0b;
  --amber-soft: #fef3c7;
  --green: #137333;
  --green-soft: #dcfce7;
  --red: #b42318;
  --red-soft: #fee2e2;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.08);
  color: var(--text);
  font-family: "Fira Sans", Arial, Helvetica, sans-serif;
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
a { color: var(--primary); font-weight: 600; text-decoration: none; }
a:hover { color: var(--primary-2); text-decoration: underline; }

.topbar {
  align-items: center;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
  display: flex;
  gap: 18px;
  justify-content: space-between;
  min-height: 68px;
  padding: 12px clamp(16px, 3vw, 32px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  align-items: center;
  color: var(--text);
  display: inline-flex;
  font-size: 18px;
  font-weight: 700;
  gap: 10px;
  letter-spacing: 0;
  white-space: nowrap;
}
.brand img {
  display: block;
  height: 42px;
  object-fit: contain;
  width: 42px;
}

nav { align-items: center; display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
nav a, .link-button {
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 11px;
  transition: background 180ms ease, color 180ms ease;
}
nav a:hover, .link-button:hover { background: var(--primary-soft); color: var(--primary); text-decoration: none; }
nav form { margin: 0; }

.page {
  margin: 0 auto;
  max-width: 1280px;
  padding: 28px clamp(16px, 3vw, 32px) 56px;
}
.app-footer {
  color: var(--muted);
  font-size: 12px;
  padding: 0 clamp(16px, 3vw, 32px) 20px;
  text-align: center;
}

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(28px, 4vw, 40px); line-height: 1.08; margin-bottom: 10px; }
h2 { color: #172554; font-size: 18px; margin: 26px 0 12px; }
p { color: var(--muted); line-height: 1.55; }

.hero {
  background:
    linear-gradient(135deg, rgba(30, 64, 175, 0.96), rgba(37, 99, 235, 0.86)),
    radial-gradient(circle at 90% 20%, rgba(245, 158, 11, 0.35), transparent 34%);
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: #fff;
  margin-bottom: 18px;
  padding: clamp(24px, 4vw, 38px);
}
.hero p { color: #dbeafe; margin-bottom: 0; max-width: 720px; }

.panel, .login-card, .summary {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
  padding: 20px;
}

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.stack { display: grid; gap: 14px; }
.connection-form, .mapping-form {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.mapping-grid {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.filter-form {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 16px;
}
.metric-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 20px;
}
.metric-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
  padding: 18px;
}
.metric-card strong {
  color: #172554;
  display: block;
  font-family: "Fira Code", ui-monospace, monospace;
  font-size: 28px;
  line-height: 1.1;
  margin-top: 8px;
}
.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.chart-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  margin-bottom: 20px;
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
  display: grid;
  gap: 12px;
  padding: 18px;
}
.chart-heading {
  align-items: baseline;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}
.chart-heading h3 {
  color: #172554;
  font-size: 16px;
  margin: 0;
}
.chart-heading span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}
.bar-row {
  display: grid;
  gap: 7px;
}
.bar-label {
  align-items: baseline;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}
.bar-label strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-label span {
  color: var(--muted);
  flex: 0 0 auto;
  font-size: 12px;
}
.bar-track {
  background: #e5edf8;
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}
.bar-track span {
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  border-radius: inherit;
  display: block;
  height: 100%;
}
.bar-track.product-bar {
  background: #fef3c7;
}
.bar-track.product-bar span {
  background: linear-gradient(90deg, var(--amber), #2563eb);
}
.split-heading, .summary, .inline {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
}
.inline { justify-content: flex-start; }
.summary { margin: 14px 0 22px; }
.summary span {
  background: var(--surface-2);
  border: 1px solid #c7d7fe;
  border-radius: 999px;
  color: #1e3a8a;
  display: inline-flex;
  font-family: "Fira Code", ui-monospace, monospace;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 11px;
}
.summary strong {
  color: #172554;
}

label { color: var(--text); display: grid; font-weight: 600; gap: 6px; }
input, select, button, .button {
  border-radius: 7px;
  font: inherit;
  min-height: 40px;
  padding: 9px 11px;
}
input, select {
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, button:focus-visible, .button:focus-visible, a:focus-visible {
  outline: 3px solid rgba(245, 158, 11, 0.38);
  outline-offset: 2px;
}
button, .button {
  background: var(--primary);
  border: 1px solid var(--primary);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font-weight: 700;
  justify-content: center;
  text-decoration: none;
  transition: background 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}
button:hover, .button:hover {
  background: var(--primary-2);
  border-color: var(--primary-2);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.18);
  text-decoration: none;
}
button:disabled {
  background: #94a3b8;
  border-color: #94a3b8;
  box-shadow: none;
  cursor: not-allowed;
}
.danger {
  background: var(--red);
  border-color: var(--red);
}
.danger:hover {
  background: #8f1d14;
  border-color: #8f1d14;
  box-shadow: 0 8px 18px rgba(180, 35, 24, 0.16);
}
.button.secondary {
  background: #fff;
  border-color: var(--line-strong);
  color: var(--primary);
}
.link-button {
  background: transparent;
  border: 0;
  min-height: auto;
}

table {
  background: var(--surface);
  border: 1px solid var(--line);
  border-collapse: separate;
  border-radius: 8px;
  border-spacing: 0;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.04);
  display: block;
  margin-top: 14px;
  overflow-x: auto;
  width: 100%;
}
thead, tbody, tr { width: 100%; }
th, td {
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}
th {
  background: #eef4ff;
  color: #1e3a8a;
  font-size: 12px;
  letter-spacing: 0.04em;
  position: sticky;
  text-transform: uppercase;
  top: 0;
}
th.sticky-action, td.sticky-action {
  background: #fff;
  box-shadow: -10px 0 18px rgba(15, 23, 42, 0.06);
  position: sticky;
  right: 0;
  z-index: 2;
}
th.sticky-action {
  background: #eef4ff;
  z-index: 3;
}
td { color: #24324a; }
td input, td select { min-width: 120px; }
td input.account-name-input { min-width: 340px; }
td button { min-width: 72px; }
tbody tr:hover { background: #f8fbff; }
tbody tr:last-child td { border-bottom: 0; }

.empty, .muted { color: var(--muted); }
.alert {
  background: var(--amber-soft);
  border: 1px solid var(--amber);
  border-radius: 8px;
  color: #7c4a03;
  padding: 12px 14px;
}
.badge, .success, .error, .pending_pin, .pending_pin_error, .pending_product, .skipped_missing_contact, .skipped_duplicate, .skipped_unreadable_row {
  border-radius: 999px;
  display: inline-block;
  font-family: "Fira Code", ui-monospace, monospace;
  font-size: 12px;
  font-weight: 600;
  margin: 2px 4px 2px 0;
  padding: 4px 8px;
}
.badge, .pending_pin, .pending_pin_error, .pending_product, .skipped_missing_contact, .skipped_duplicate, .skipped_unreadable_row {
  background: var(--amber-soft);
  border: 1px solid #f8c35d;
  color: #7c4a03;
}
.success {
  background: var(--green-soft);
  border: 1px solid #86efac;
  color: var(--green);
}
.error {
  background: var(--red-soft);
  border: 1px solid #fecaca;
  color: var(--red);
}

.login-page {
  background:
    radial-gradient(circle at 12% 18%, rgba(37, 99, 235, 0.16), transparent 30%),
    radial-gradient(circle at 88% 82%, rgba(245, 158, 11, 0.18), transparent 28%),
    var(--bg);
  display: grid;
  min-height: 100vh;
  padding: 16px;
  place-items: center;
}
.login-card {
  border-color: rgba(30, 64, 175, 0.18);
  padding: 28px;
  width: min(440px, calc(100vw - 32px));
}
.login-card h1 { font-size: 30px; }

@media (max-width: 780px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  nav { justify-content: flex-start; }
  .page { padding-top: 20px; }
  .split-heading { align-items: flex-start; flex-direction: column; }
  .inline select, .inline button { width: 100%; }
  .filter-form { grid-template-columns: 1fr; }
  th, td { padding: 10px; }
}

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