:root {
  --ink: #16202b;
  --ink-soft: #3c4a5a;
  --muted: #71808f;
  --line: #e3e8ef;
  --line-soft: #edf1f6;
  --accent: #2563eb;
  --accent-deep: #1d4fd7;
  --accent-ink: #16306e;
  --bg: #eef2f7;
  --card: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(22, 32, 43, 0.05), 0 8px 24px -12px rgba(22, 32, 43, 0.18);
  --shadow-soft: 0 1px 3px rgba(22, 32, 43, 0.07);
  --lower-bg: #fdecec;  --lower-ink: #a3262b;  /* competitor undercuts Ancira */
  --higher-bg: #e6f6ea; --higher-ink: #1d7a36; /* competitor priced higher */
  --same-bg: #fdf6dd;   --same-ink: #8a6d1a;   /* same price */
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 500px at 85% -10%, #dde7f8 0%, transparent 60%),
    var(--bg);
  min-height: 100vh;
}
main { padding: 1.6rem 2rem 3rem; max-width: 1560px; margin: 0 auto; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; font-weight: 700; letter-spacing: -0.015em; }
h2 { font-size: 1.05rem; font-weight: 650; margin-top: 2.2rem; letter-spacing: -0.01em; }
.muted { color: var(--muted); font-size: 0.85em; }
.empty { color: var(--muted); padding: 2.5rem 0; text-align: center; }
.error { color: #b00020; }
.flash {
  background: var(--higher-bg); color: var(--higher-ink);
  padding: 0.6rem 0.9rem; border-radius: 8px; border: 1px solid #cdead5;
}
.flash-warn { background: var(--same-bg); color: var(--same-ink); border-color: #efe2b0; }

/* ---------------------------------------------------------------- top nav */
.topnav {
  display: flex; align-items: center; gap: 1.35rem;
  background: linear-gradient(135deg, #101a30 0%, #1b2c52 60%, #21386b 100%);
  color: #fff; padding: 0.8rem 2rem;
  box-shadow: 0 2px 14px rgba(11, 19, 38, 0.35);
  position: sticky; top: 0; z-index: 50;
}
.topnav a {
  color: #b9c7e2; font-weight: 500; font-size: 0.93rem;
  padding: 0.3rem 0.65rem; border-radius: 7px; transition: background 0.15s, color 0.15s;
}
.topnav a:hover { color: #fff; background: rgba(255, 255, 255, 0.09); text-decoration: none; }
.topnav .brand {
  font-weight: 750; margin-right: 0.8rem; letter-spacing: -0.01em; font-size: 1.02rem;
}
.topnav .brand::before {
  content: ""; display: inline-block; width: 0.55em; height: 0.55em;
  border-radius: 50%; background: linear-gradient(135deg, #5b8cff, #8fd0ff);
  margin-right: 0.5em; vertical-align: 0.05em;
}
.topnav .logout { margin-left: auto; display: flex; gap: 0.8rem; align-items: center; }
.topnav .who { color: #7e93bd; font-size: 0.82em; }
a.who:hover { color: #fff; }

/* passkeys */
.passkey-btn { width: 100%; }
.or-divider {
  display: flex; align-items: center; gap: 0.7rem; color: var(--muted);
  font-size: 0.8em; margin: 1rem 0;
}
.or-divider::before, .or-divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
button.link { background: none; border: none; color: #b9c7e2; cursor: pointer; padding: 0; font: inherit; }
button.link:hover { color: #fff; }

/* ------------------------------------------------------------------ login */
.login-box {
  max-width: 380px; margin: 14vh auto; background: var(--card);
  padding: 2.4rem 2.2rem; border-radius: 16px; border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.login-box h1 { margin: 0 0 1.2rem; font-size: 1.2rem; text-align: center; }
.login-box button { width: 100%; margin-top: 0.9rem; }
.login-box input { width: 100%; }

/* -------------------------------------------------------- forms & buttons */
label { display: block; margin: 0.7rem 0; font-weight: 500; font-size: 0.92rem; color: var(--ink-soft); }
input[type=text], input[type=password], input[type=url], select {
  padding: 0.5rem 0.7rem; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; min-width: 220px; background: #fff; color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}
button, .btn {
  display: inline-block; padding: 0.48rem 1rem; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink); cursor: pointer;
  font: inherit; font-weight: 550;
  transition: transform 0.1s, box-shadow 0.15s, background 0.15s, border-color 0.15s;
  box-shadow: var(--shadow-soft);
}
button:hover, .btn:hover { border-color: #c8d2de; background: #fafbfd; text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button.primary, .btn.primary {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-deep) 100%);
  border-color: var(--accent-deep); color: #fff;
}
button.primary:hover, .btn.primary:hover { filter: brightness(1.07); background: linear-gradient(180deg, var(--accent) 0%, var(--accent-deep) 100%); }
button.danger { color: #b00020; }
button.danger:hover { border-color: #e4b6bc; background: #fdf4f5; }
button:disabled { opacity: 0.5; cursor: default; transform: none; }
form.inline { display: inline; }
form.stacked {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.2rem 1.5rem 1.4rem; max-width: 500px; box-shadow: var(--shadow-soft);
}

/* --------------------------------------------------------- toolbar / tabs */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.store-tabs { display: flex; gap: 0.45rem; flex-wrap: wrap; }
.tab {
  padding: 0.45rem 1rem; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); font-weight: 550; font-size: 0.92rem; color: var(--ink-soft);
  box-shadow: var(--shadow-soft); transition: all 0.15s;
}
.tab:hover { border-color: #c8d2de; text-decoration: none; }
.tab.active {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-deep) 100%);
  border-color: var(--accent-deep); color: #fff;
}
.actions { display: flex; gap: 0.5rem; }

/* export dropdown */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 4px); z-index: 40;
  min-width: 160px; background: #fff; border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow); padding: 0.3rem; overflow: hidden;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a {
  display: block; padding: 0.45rem 0.7rem; border-radius: 6px;
  color: var(--ink); font-size: 0.92rem;
}
.dropdown-menu a:hover { background: var(--bg); text-decoration: none; }

/* ----------------------------------------------------------- scrape status */
.scrape-status { margin: 1rem 0; min-height: 1.5rem; font-size: 0.92rem; }
.scrape-status.running {
  color: var(--accent-ink); background: #e8effc; border: 1px solid #cfdcf7;
  border-radius: 9px; padding: 0.55rem 0.9rem; display: inline-block;
}
.spinner {
  display: inline-block; width: 0.85em; height: 0.85em; margin-right: 0.45em;
  border: 2px solid var(--accent); border-top-color: transparent; border-radius: 50%;
  animation: spin 0.8s linear infinite; vertical-align: -0.1em;
}
@keyframes spin { to { transform: rotate(360deg); } }
.errors pre { font-size: 0.8em; white-space: pre-wrap; }
.btn-stop {
  margin-left: 0.7rem; padding: 0.15rem 0.7rem; font-size: 0.85em;
  border: 1px solid #e4b6bc; border-radius: 6px; background: #fff;
  color: #b00020; cursor: pointer;
}
.btn-stop:hover { background: #fdf4f5; }

/* last-refresh report panel */
.run-report { margin: 0.4rem 0 1rem; }
.run-report summary { cursor: pointer; color: var(--accent); font-weight: 550; font-size: 0.9rem; }
.run-report .run-fail { color: #b00020; font-weight: 650; }
.run-table { margin-top: 0.6rem; width: 100%; max-width: 1100px; }
.run-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.run-table code { background: #f0f3f8; padding: 0.08rem 0.4rem; border-radius: 5px; font-size: 0.85em; }
.run-error {
  margin: 0.3rem 0 0; font-size: 0.78rem; line-height: 1.45; white-space: pre-wrap;
  word-break: break-word; color: #7a2030; background: #fdf2f3;
  border: 1px solid #f3d4d8; border-radius: 6px; padding: 0.45rem 0.6rem; max-width: 760px;
}

/* --------------------------------------------------------- legend & badges */
.legend { display: flex; gap: 0.5rem; margin: 0.9rem 0 1rem; flex-wrap: wrap; }
.chip {
  padding: 0.22rem 0.75rem; border-radius: 999px; font-size: 0.8em;
  font-weight: 550; border: 1px solid transparent;
}
.chip.px-worse  { background: var(--lower-bg);  color: var(--lower-ink);  border-color: #f3cdcd; }
.chip.px-better { background: var(--higher-bg); color: var(--higher-ink); border-color: #cdead5; }
.chip.px-same   { background: var(--same-bg);   color: var(--same-ink);   border-color: #efe2b0; }
.badge { padding: 0.13rem 0.55rem; border-radius: 999px; font-size: 0.74em; font-weight: 600; }
.badge.fail { background: #b00020; color: #fff; }
.badge.ok { background: #1d7a36; color: #fff; }

/* --------------------------------------------------------- comparison grid */
.table-wrap {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: auto; max-height: calc(100vh - 230px);
}
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 0.92rem; }
table.grid th, table.grid td {
  border-bottom: 1px solid var(--line-soft); border-right: 1px solid var(--line-soft);
  padding: 0.5rem 0.75rem; text-align: left;
}
table.grid thead th {
  background: #f7f9fc; vertical-align: top; position: sticky; top: 0; z-index: 2;
  font-weight: 650; border-bottom: 1px solid var(--line);
}
table.grid .subhead th {
  top: unset; font-size: 0.74em; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); background: #fbfcfe; padding: 0.3rem 0.75rem;
}
table.grid tbody tr:nth-child(even) td { background: #fbfcfe; }
table.grid tbody tr:hover td { background: #f1f5fb; }
table.grid td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.grid td.veh { white-space: nowrap; font-weight: 520; }
.dealer-meta { font-weight: 400; margin-top: 0.2rem; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
td.px-worse  { background: var(--lower-bg)  !important; color: var(--lower-ink); }
td.px-better { background: var(--higher-bg) !important; color: var(--higher-ink); }
td.px-same   { background: var(--same-bg)   !important; color: var(--same-ink); }
td.px-worse a, td.px-better a, td.px-same a { color: inherit; font-weight: 600; }
.nomatch { color: #aab6c2; text-align: center !important; font-size: 0.84em; font-style: italic; }
.vin { font-size: 0.72rem; color: var(--muted); font-family: ui-monospace, monospace; margin-top: 0.1rem; }

/* ------------------------------------------------- admin tables & cards */
table.admin {
  border-collapse: separate; border-spacing: 0; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow-soft); font-size: 0.93rem;
}
table.admin th, table.admin td { border-bottom: 1px solid var(--line-soft); padding: 0.55rem 0.85rem; }
table.admin thead th {
  background: #f7f9fc; font-weight: 650; font-size: 0.8em;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
}
table.admin tbody tr:last-child td { border-bottom: none; }

.store-block { margin: 1.4rem 0; }
.dealer-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 0.7rem 0.95rem; margin: 0.45rem 0;
  display: flex; gap: 0.55rem; align-items: center; flex-wrap: wrap;
  box-shadow: var(--shadow-soft); transition: box-shadow 0.15s;
}
.dealer-card:hover { box-shadow: var(--shadow); }
.dealer-card.ancira { border-left: 4px solid var(--accent); }
.dealer-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.dealer-form .stk-excl { min-width: 90px; }
.competitors { margin-left: 2.2rem; }
.creds { font-size: 0.84em; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.creds code {
  background: #f0f3f8; padding: 0.12rem 0.45rem; border-radius: 5px;
  font-size: 0.92em; color: var(--ink-soft);
}
.manual-creds { width: 100%; margin-top: 0.3rem; }
.manual-creds summary { cursor: pointer; color: var(--accent); font-weight: 550; font-size: 0.86rem; }
.manual-creds .muted { margin: 0.4rem 0; max-width: 640px; }
.creds-form { display: flex; flex-direction: column; gap: 0.5rem; max-width: 640px; }
.creds-form textarea {
  width: 100%; font: 0.82rem/1.4 ui-monospace, monospace; padding: 0.5rem 0.6rem;
  border: 1px solid var(--line); border-radius: 8px; resize: vertical;
}
.creds-fields { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.creds-fields input { min-width: 150px; flex: 1; }
.add-comp { margin: 0.6rem 0; }
.add-comp summary { cursor: pointer; color: var(--accent); font-weight: 550; font-size: 0.92rem; }
.settings h2 { margin-top: 1.6rem; }

@media (max-width: 760px) {
  main { padding: 1rem; }
  .topnav { padding: 0.7rem 1rem; gap: 0.7rem; flex-wrap: wrap; }
  .competitors { margin-left: 0.8rem; }
}
