/* ==========================================================================
   Fresno-Madera Central Auto Sales — Design System

   TOKEN ARCHITECTURE
   - Semantic tokens (surfaces, ink, borders, brand, semantic colors) are
     defined three times, in this exact source order:
       1. :root                                  -> light (the default)
       2. :root[data-theme="dark"]               -> explicit user choice
       3. @media (prefers-color-scheme: dark)
          :root:not([data-theme="light"])        -> OS dark, unless the user
                                                    explicitly chose light
     The attribute always wins over the OS preference in BOTH directions.
   - ⚠ KEEP-IN-SYNC: blocks 2 and 3 must stay byte-identical. Any token edit
     in one must be mirrored in the other.
   - Legacy aliases (--bg-card, --primary, --text-muted, ...) map old names
     onto the semantic tokens so inline styles in markup retheme correctly.
     They resolve through var() indirection, so DO NOT redefine an alias in
     the dark blocks — it would shadow the indirection.
   - Elevation: light theme separates with shadows on white; dark theme
     separates with lighter surface steps. Never with hairlines alone.
   ========================================================================== */

@font-face {
  font-family: 'Manrope';
  src: url('/static/fonts/manrope-var.woff2') format('woff2');
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

/* ── Tokens: LIGHT (default) ────────────────────────────────────── */
:root {
  color-scheme: light;

  /* Surfaces (elevation 0 -> 3) */
  --surface-page:    #f2f5f8;
  --surface-1:       #ffffff;
  --surface-2:       #e9eef4;
  --surface-3:       #dde5ee;
  --surface-glass:   rgba(255, 255, 255, 0.86);
  --surface-overlay: rgba(15, 23, 36, 0.55);

  /* Ink */
  --ink:         #16202e;
  --ink-muted:   #49586c;
  --ink-inverse: #ffffff;

  /* Borders: --border is decorative only (pair with shadow or a surface
     step); --border-strong is for interactive boundaries, >=3:1 contrast. */
  --border:        #d4dce6;
  --border-strong: #8593a4;

  /* Brand (deep azure) + accent (amber) */
  --brand:        #0b5cad;
  --brand-strong: #094a8c;
  --brand-soft:   #e3eefb;
  --brand-ring:   rgba(11, 92, 173, 0.35);
  --accent:        #e08700;
  --accent-strong: #b96f00;
  --accent-soft:   #fdf0dc;
  --accent-ink:    #241a03;

  /* Semantic */
  --ok:   #0e7a4f;  --ok-soft:   #e0f3ea;
  --err:  #c62828;  --err-soft:  #fce9e9;
  --warn: var(--accent);
  --info: #4f46e5;  --info-soft: #e9e8fc;

  /* Shadows — blue-gray tinted, real depth on light surfaces */
  --shadow-sm: 0 1px 2px rgba(23,32,49,0.06), 0 1px 3px rgba(23,32,49,0.10);
  --shadow-md: 0 2px 4px rgba(23,32,49,0.05), 0 6px 16px rgba(23,32,49,0.12);
  --shadow-lg: 0 8px 24px rgba(23,32,49,0.14), 0 20px 48px rgba(23,32,49,0.18);

  /* Type */
  --font-body: 'Manrope', -apple-system, BlinkMacSystemFont, "Segoe UI",
               Roboto, Helvetica, Arial, sans-serif;
  --text-xs:   0.75rem;    /* legal / meta only */
  --text-sm:   0.875rem;   /* secondary UI, table cells, pills */
  --text-base: 1rem;
  --text-md:   1.125rem;   /* card titles, lead paragraphs */
  --text-lg:   clamp(1.25rem, 1.1rem + 0.6vw, 1.5rem);   /* h3, section titles */
  --text-xl:   clamp(1.5rem, 1.3rem + 1vw, 1.9rem);      /* h2 */
  --text-2xl:  clamp(1.9rem, 1.6rem + 1.6vw, 2.5rem);    /* h1, price hero */
  --text-3xl:  clamp(2.3rem, 1.9rem + 2.4vw, 3.2rem);    /* flagship hero */
  --leading-tight: 1.2;
  --leading-snug:  1.45;
  --leading-body:  1.6;

  /* Space — static rem scale */
  --space-2xs: 0.25rem;
  --space-xs:  0.5rem;
  --space-sm:  0.875rem;
  --space-md:  1.25rem;
  --space-lg:  2rem;
  --space-xl:  3rem;
  --page-gutter: clamp(1rem, 4vw, 2rem);
  --page-max:    1280px;

  /* Radius */
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   16px;
  --radius-pill: 999px;

  /* Motion */
  --dur:  0.18s;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --transition: color var(--dur) var(--ease),
                background-color var(--dur) var(--ease),
                border-color var(--dur) var(--ease),
                box-shadow var(--dur) var(--ease),
                transform var(--dur) var(--ease);

  /* Z-index scale */
  --z-nav:    100;
  --z-modal:  400;
  --z-gate:   600;
  --z-banner: 800;
  --z-toast:  900;

  /* Theme-toggle icon swap — rides the token cascade, zero JS */
  --icon-sun:  none;
  --icon-moon: inline-flex;

  /* ── LEGACY ALIASES — migrate markup, then delete ── */
  --bg-dark:       var(--surface-page);
  --bg-card:       var(--surface-1);
  --bg-glass:      var(--surface-glass);
  --primary:       var(--brand);
  --primary-hover: var(--brand-strong);
  --accent-hover:  var(--accent-strong);
  --success:       var(--ok);
  --danger:        var(--err);
  --warning:       var(--warn);
  --text-main:     var(--ink);
  --text-muted:    var(--ink-muted);
  --text-dark:     var(--ink-inverse);
}

/* ── Tokens: DARK, explicit choice ──────────────────────────────────
   ⚠ KEEP-IN-SYNC with the media block below — byte-identical. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-page:    #0c111c;
  --surface-1:       #151d2c;
  --surface-2:       #1e2839;
  --surface-3:       #283549;
  --surface-glass:   rgba(18, 25, 38, 0.85);
  --surface-overlay: rgba(4, 7, 12, 0.66);
  --ink:         #edf2f8;
  --ink-muted:   #9fadc0;
  --ink-inverse: #0e1520;
  --border:        #2a3750;
  --border-strong: #5d6d85;
  --brand:        #4dabf5;
  --brand-strong: #7cc4ff;
  --brand-soft:   #14283f;
  --brand-ring:   rgba(77, 171, 245, 0.45);
  --accent:        #f5a623;
  --accent-strong: #ffc04d;
  --accent-soft:   #33260e;
  --ok:   #34c98a;  --ok-soft:   #123324;
  --err:  #f26d6d;  --err-soft:  #3a1518;
  --info: #8f98f7;  --info-soft: #1d2044;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.40);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.45);
  --shadow-lg: 0 16px 40px rgba(0,0,0,0.55);
  --icon-sun:  inline-flex;
  --icon-moon: none;
}

/* ── Tokens: DARK, from the OS (unless user chose light) ────────────
   ⚠ KEEP-IN-SYNC with the attribute block above — byte-identical. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-page:    #0c111c;
    --surface-1:       #151d2c;
    --surface-2:       #1e2839;
    --surface-3:       #283549;
    --surface-glass:   rgba(18, 25, 38, 0.85);
    --surface-overlay: rgba(4, 7, 12, 0.66);
    --ink:         #edf2f8;
    --ink-muted:   #9fadc0;
    --ink-inverse: #0e1520;
    --border:        #2a3750;
    --border-strong: #5d6d85;
    --brand:        #4dabf5;
    --brand-strong: #7cc4ff;
    --brand-soft:   #14283f;
    --brand-ring:   rgba(77, 171, 245, 0.45);
    --accent:        #f5a623;
    --accent-strong: #ffc04d;
    --accent-soft:   #33260e;
    --ok:   #34c98a;  --ok-soft:   #123324;
    --err:  #f26d6d;  --err-soft:  #3a1518;
    --info: #8f98f7;  --info-soft: #1d2044;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.40);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.45);
    --shadow-lg: 0 16px 40px rgba(0,0,0,0.55);
    --icon-sun:  inline-flex;
    --icon-moon: none;
  }
}

/* ── Reset + base layer ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 100%; }
@media (min-width: 1024px) {
  html { font-size: 106.25%; }  /* 17px root on desktop */
}

body {
  background-color: var(--surface-page);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  /* No flex on body — it was collapsing grid container widths */
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 800;
  line-height: var(--leading-tight);
  letter-spacing: -0.01em;
  margin-bottom: 0.5em;
  text-wrap: balance;
}
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4, h5, h6 { font-size: var(--text-md); }

p { margin-bottom: 0.75em; }
p:last-child { margin-bottom: 0; }

a { color: var(--brand); }

img { max-width: 100%; }

table { border-collapse: collapse; width: 100%; }
th { text-align: left; }

input, select, textarea, button { font: inherit; color: inherit; }
textarea { resize: vertical; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--brand); }

code {
  background: var(--surface-2);
  padding: 0.1em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
}

::selection { background: var(--brand); color: var(--ink-inverse); }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 2px;
}

.vehicle-price, .spec-val, .stat-value, .data-table td {
  font-variant-numeric: tabular-nums;
}

/* ── Navbar ─────────────────────────────────────────────────────── */
.navbar {
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: var(--z-nav);
  padding-block: 0.8rem;
  padding-inline: var(--page-gutter);
}

.nav-container {
  max-width: var(--page-max);
  margin-inline: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--ink);
  font-weight: 800;
  font-size: clamp(1.05rem, 3vw, 1.35rem);
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: clamp(0.6rem, 2vw, 1.5rem);
  list-style: none;
  flex-wrap: wrap;
}

.nav-link {
  color: var(--ink-muted);
  text-decoration: none;
  font-weight: 700;
  font-size: var(--text-sm);
  transition: var(--transition);
  white-space: nowrap;
}

.nav-link:hover, .nav-link.active { color: var(--brand); }

/* Nav dropdown (e.g. Dealers). Opens on hover and on keyboard focus.
   The menu is attached flush to the trigger (top:100%) so the pointer
   never crosses a dead gap that would close it. */
.nav-dropdown { position: relative; }
.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.4rem;
  min-width: 260px;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  flex-direction: column;
}
.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu { display: flex; }
.nav-dropdown-menu a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: var(--text-sm);
  white-space: nowrap;
}
.nav-dropdown-menu a:hover { background: var(--brand-soft); color: var(--brand); }
.nav-dropdown-menu .count { color: var(--ink-muted); font-size: var(--text-xs); }
.nav-dropdown-menu .menu-all {
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
  color: var(--brand);
}

/* ── User avatar menu (signed-in header) ── */
.user-avatar-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.6rem 0.3rem 0.35rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
  font-size: var(--text-sm);
}
.user-avatar-btn:hover { border-color: var(--border-strong); }
.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: var(--brand);
  color: var(--ink-inverse);
  font-weight: 800;
  font-size: var(--text-sm);
}
.user-menu .nav-dropdown-menu {
  left: auto;
  right: 0;
  transform: none;
  min-width: 220px;
}
.user-menu-role {
  padding: 0.25rem 0.75rem 0.5rem;
  margin-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
  color: var(--ink-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: capitalize;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--ink-muted);
  cursor: pointer;
  transition: var(--transition);
}
.theme-toggle:hover {
  color: var(--brand);
  border-color: var(--brand);
  background: var(--brand-soft);
}
.theme-toggle .tt-sun  { display: var(--icon-sun); }
.theme-toggle .tt-moon { display: var(--icon-moon); }

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.25rem;
  min-height: 44px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: var(--text-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn:disabled, .btn-loading {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary { background: var(--brand); color: var(--ink-inverse); }
.btn-primary:hover { background: var(--brand-strong); }

.btn-accent { background: var(--accent); color: var(--accent-ink); }
.btn-accent:hover { background: var(--accent-strong); }

.btn-outline {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--ink);
}
.btn-outline:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
}

.btn-danger { background: var(--err); color: var(--ink-inverse); }

.btn-sm { min-height: 36px; padding: 0.4rem 0.8rem; font-size: var(--text-xs); }
.btn-lg { min-height: 52px; font-size: var(--text-base); }
.btn-block { width: 100%; }
.btn-confirm-ok { min-width: 110px; }

/* ── Hero Section ───────────────────────────────────────────────── */
.hero-section {
  background: radial-gradient(circle at 50% 0%, var(--brand-soft), transparent 65%);
  padding-block: var(--space-lg);
  padding-inline: var(--page-gutter);
  border-bottom: 1px solid var(--border);
}

.hero-container {
  max-width: var(--page-max);
  margin-inline: auto;
}

.featured-flagship-card {
  background: var(--surface-1);
  border: 2px solid var(--brand);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
  gap: var(--space-md);
  align-items: center;
  box-shadow: var(--shadow-lg);
  margin-bottom: var(--space-md);
}

.flagship-title {
  font-size: var(--text-3xl);
  font-weight: 800;
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
  color: var(--ink);
}

.flagship-location {
  color: var(--ink-muted);
  font-size: var(--text-md);
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.flagship-img {
  width: 100%;
  height: clamp(180px, 30vw, 320px);
  object-fit: cover;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
}

/* ── Sponsored Ad Banner ────────────────────────────────────────── */
.ad-banner-header {
  background: var(--info-soft);
  border: 1px solid var(--info);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.ad-banner-content {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

/* ── Panels & filter bar ────────────────────────────────────────── */
/* .panel is the generic surface for any block of content. .filter-card is
   the horizontal filter BAR specifically — don't use it as a panel. */
.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  box-shadow: var(--shadow-md);
}

.search-filter-section {
  max-width: var(--page-max);
  margin-inline: auto;
  margin-bottom: var(--space-lg);
  padding-inline: var(--page-gutter);
}

.filter-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-items: flex-end;
  box-shadow: var(--shadow-md);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1 1 30%;
  min-width: 0;
}

.filter-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.filter-select, .form-input {
  background: var(--surface-page);
  border: 1px solid var(--border-strong);
  color: var(--ink);
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  outline: none;
  transition: var(--transition);
  width: 100%;
  min-width: 0;
}

.filter-select:focus, .form-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}

/* ── Sections & inventory grid ──────────────────────────────────── */
.main-container {
  max-width: var(--page-max);
  margin-inline: auto;
  margin-bottom: var(--space-xl);
  padding-inline: var(--page-gutter);
  width: 100%;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-bottom: var(--space-md);
}

.section-title { font-size: var(--text-xl); font-weight: 800; margin-bottom: 0; }

.section-h {
  font-size: var(--text-lg);
  font-weight: 800;
  margin: var(--space-lg) 0 var(--space-sm);
}

.vehicle-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: clamp(0.75rem, 2vw, 1.5rem);
}
@media (min-width: 800px) {
  .vehicle-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1200px) {
  .vehicle-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 420px) {
  .vehicle-grid { grid-template-columns: 1fr; }
}

/* ── Vehicle card ───────────────────────────────────────────────── */
.vehicle-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: var(--shadow-sm);
}

a.vehicle-card { color: inherit; text-decoration: none; display: block; }

.vehicle-card:hover {
  transform: translateY(-3px);
  border-color: var(--brand);
  box-shadow: var(--shadow-md);
}

.card-img-wrapper {
  position: relative;
  height: clamp(140px, 22vw, 220px);
  overflow: hidden;
  background: var(--surface-2);
}

.card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}

.vehicle-card:hover .card-img { transform: scale(1.04); }

.card-body {
  padding: var(--space-sm) var(--space-md) var(--space-md);
  display: flex;
  flex-direction: column;
  flex: 1;
}

.vehicle-title {
  font-size: var(--text-md);
  font-weight: 800;
  line-height: var(--leading-snug);
  margin-bottom: 0.25rem;
}

.vehicle-price {
  font-size: var(--text-lg);
  font-weight: 800;
  color: var(--brand);
  margin-bottom: 0.6rem;
}

.specs-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  color: var(--ink-muted);
  font-size: var(--text-sm);
  margin-bottom: 0.75rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}

.specs-item { display: flex; align-items: center; gap: 0.25rem; }

.dealer-name {
  font-size: var(--text-sm);
  color: var(--ink-muted);
}

/* ── Detail-page price hero ─────────────────────────────────────── */
.price-hero {
  font-size: var(--text-2xl);
  font-weight: 800;
  color: var(--brand);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

/* ── Breadcrumbs ────────────────────────────────────────────────── */
.breadcrumbs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  font-size: var(--text-sm);
  margin-bottom: var(--space-md);
}
.breadcrumbs a {
  color: var(--ink-muted);
  text-decoration: none;
}
.breadcrumbs a:hover { color: var(--brand); text-decoration: underline; }
.breadcrumbs .current { color: var(--ink); font-weight: 700; }
.breadcrumbs .sep { color: var(--border-strong); }

/* ── Spec sheet (vehicle details rows) ──────────────────────────── */
.spec-sheet { display: block; }
.spec-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}
.spec-row:last-child { border-bottom: none; }
.spec-key { color: var(--ink-muted); font-size: var(--text-sm); }
.spec-val { font-weight: 700; text-align: right; }

/* ── Photo gallery ──────────────────────────────────────────────── */
.gallery-main {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  display: block;
}
.gallery-thumbs {
  display: flex;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
  flex-wrap: wrap;
}
.gallery-thumb {
  width: 6rem;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 2px solid transparent;
  transition: var(--transition);
}
.gallery-thumb:hover, .gallery-thumb.active { border-color: var(--brand); }
.gallery-count {
  font-size: var(--text-xs);
  color: var(--ink-muted);
  margin-top: 0.35rem;
}

/* ── Detail-page layout grids ───────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr));
  gap: var(--space-md);
  align-items: start;
  margin-bottom: var(--space-md);
}

.lead-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
  gap: var(--space-xs) var(--space-sm);
}

/* ── Modals ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--surface-overlay);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: var(--page-gutter);
}

.modal-overlay.active { opacity: 1; pointer-events: auto; }

.modal-container {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: min(600px, 100%);
  max-height: 90dvh;
  overflow-y: auto;
  padding: clamp(1.25rem, 4vw, 2rem);
  box-shadow: var(--shadow-lg);
  position: relative;
}

.modal-container.modal-sm { max-width: min(420px, 100%); }
.modal-container.modal-lg { max-width: min(760px, 100%); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: var(--space-md);
}

.modal-title { font-size: var(--text-lg); font-weight: 800; margin-bottom: 0; }

.modal-close {
  background: transparent;
  border: none;
  color: var(--ink-muted);
  font-size: 1.5rem;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  padding: 0.1rem 0.3rem;
}
.modal-close:hover { color: var(--ink); }

/* ── Camera VIN Scanner ─────────────────────────────────────────── */
.camera-scanner-viewport {
  width: 100%;
  aspect-ratio: 16 / 6;
  min-height: 140px;
  max-height: 280px;
  background: #000;  /* live camera feed — always dark */
  border-radius: var(--radius-md);
  border: 2px dashed var(--brand);
  position: relative;
  overflow: hidden;
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.camera-video { width: 100%; height: 100%; object-fit: cover; }

.camera-overlay-target {
  position: absolute;
  width: 80%;
  height: 30%;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
  border-radius: var(--radius-sm);
  pointer-events: none;
}

/* ── Data tables ────────────────────────────────────────────────── */
.data-table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: var(--text-sm);
}
.data-table th {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  background: var(--surface-2);
  padding: 0.6rem 0.9rem;
  white-space: nowrap;
}
.data-table th:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.data-table th:last-child  { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.data-table td {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:hover { background: var(--surface-2); }

/* ── Stat cards (dashboard KPIs) ────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 1fr));
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}
.stat-card {
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
}
.stat-value { font-size: var(--text-xl); font-weight: 800; }
.stat-label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}

/* ── Pills & badges (one primitive, thin variants) ──────────────── */
.pill, .badge, .brand-badge, .ad-tag, .flagship-badge,
.city-pill, .status-pill, .auth-gate-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.3;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-pill);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.brand-badge {
  background: var(--brand);
  color: var(--ink-inverse);
  text-transform: uppercase;
}

.ad-tag { background: var(--info); color: #fff; text-transform: uppercase; }

.flagship-badge {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--ink);
  margin-bottom: var(--space-sm);
}

/* On-photo overlays: fixed dark scrim + white text, theme-invariant */
.city-pill {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  background: rgba(12, 17, 28, 0.78);
  backdrop-filter: blur(4px);
  color: #fff;
}

.status-pill {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.status-available { background: var(--ok);     color: var(--ink-inverse); }
.status-hold      { background: var(--accent); color: var(--accent-ink); }
.status-sold      { background: var(--err);    color: var(--ink-inverse); }

/* Standalone status pills for tables / new markup */
.pill-brand   { background: var(--brand-soft);  color: var(--brand); }
.pill-ok      { background: var(--ok-soft);     color: var(--ok); }
.pill-err     { background: var(--err-soft);    color: var(--err); }
.pill-warn    { background: var(--accent-soft); color: var(--accent-strong); }
.pill-neutral { background: var(--surface-2);   color: var(--ink-muted); }

/* ── Text & container utilities ─────────────────────────────────── */
.text-muted { color: var(--ink-muted); }
.text-small { font-size: var(--text-sm); }

/* A quiet inset container — tinted well inside a panel or modal */
.well {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
}

.divider-top {
  border-top: 1px solid var(--border);
  padding-top: var(--space-sm);
  margin-bottom: var(--space-sm);
}

/* ── Alerts ─────────────────────────────────────────────────────── */
.alert-box {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  font-size: var(--text-sm);
  background: var(--surface-2);
}

.alert-warning { background: var(--accent-soft); border: 1px solid var(--accent); color: var(--ink); }
.alert-success { background: var(--ok-soft);     border: 1px solid var(--ok);     color: var(--ink); }
.alert-info    { background: var(--brand-soft);  border: 1px solid var(--brand);  color: var(--ink); }
.alert-danger  { background: var(--err-soft);    border: 1px solid var(--err);    color: var(--ink); }

/* ── Empty & loading states ─────────────────────────────────────── */
.empty-state, .loading-state {
  text-align: center;
  padding: var(--space-xl) var(--space-md);
  color: var(--ink-muted);
  grid-column: 1 / -1;
}

/* ── Toast System ───────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: clamp(0.75rem, 3vw, 1.5rem);
  right: clamp(0.75rem, 3vw, 1.5rem);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(380px, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  display: flex; align-items: flex-start; gap: 0.65rem;
  padding: 0.85rem 0.95rem;
  border-radius: var(--radius-md);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink);
  pointer-events: auto;
  min-width: min(280px, calc(100vw - 3rem));
  transform: translateX(110%);
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}

.toast.toast-show { transform: translateX(0); opacity: 1; }
.toast-success { border-left-color: var(--ok); }
.toast-error   { border-left-color: var(--err); }
.toast-warning { border-left-color: var(--accent); }
.toast-info    { border-left-color: var(--info); }
.toast-message { flex: 1; line-height: var(--leading-snug); word-break: break-word; }
.toast-close {
  background: none; border: none; color: var(--ink-muted);
  font-size: 1.25rem; cursor: pointer; padding: 0;
  flex-shrink: 0; line-height: 1;
}
.toast-close:hover { color: var(--ink); }

/* ── Auth Gate Overlay ──────────────────────────────────────────── */
.auth-gate {
  position: fixed; inset: 0; z-index: var(--z-gate);
  display: none; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 20%, var(--brand-soft), transparent 60%),
              var(--surface-page);
  padding: var(--page-gutter);
}

.auth-gate-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(1.5rem, 5vw, 3rem) clamp(1.25rem, 4vw, 2.5rem);
  width: 100%; max-width: min(440px, 100%);
  box-shadow: var(--shadow-lg);
}

.auth-gate-title {
  font-size: var(--text-xl);
  font-weight: 800;
  text-align: center;
  margin-bottom: 0.35rem;
}
.auth-gate-subtitle {
  text-align: center;
  color: var(--ink-muted);
  font-size: var(--text-sm);
  margin-bottom: var(--space-md);
  line-height: var(--leading-snug);
}
.auth-gate-divider { height: 1px; background: var(--border); margin-bottom: var(--space-md); }

.gate-error {
  background: var(--err-soft);
  border: 1px solid var(--err);
  color: var(--err);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  font-size: var(--text-sm);
  font-weight: 600;
  margin-top: 0.75rem;
  display: none;
}
.gate-error:not(:empty) { display: block; }

.auth-gate-back {
  text-align: center;
  margin-top: var(--space-md);
  font-size: var(--text-sm);
  color: var(--ink-muted);
  border-top: 1px solid var(--border);
  padding-top: var(--space-sm);
}
.auth-gate-back a { color: var(--brand); text-decoration: none; font-weight: 700; }
.auth-gate-back a:hover { text-decoration: underline; }

.auth-gate-badge {
  background: var(--brand-soft);
  border: 1px solid var(--brand-ring);
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-sm);
}
.auth-gate-badge-wrap { text-align: center; }

/* ── Confirm Modal ──────────────────────────────────────────────── */
.confirm-body { text-align: center; padding: var(--space-2xs) 0 var(--space-md); }
.confirm-body p {
  color: var(--ink-muted);
  font-size: var(--text-sm);
  line-height: var(--leading-body);
  margin-bottom: var(--space-md);
}
.confirm-actions { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; }

/* ── Forms ──────────────────────────────────────────────────────── */
.form-group { margin-bottom: var(--space-sm); }
.form-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--ink-muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr));
  gap: var(--space-sm);
}
.form-input.is-error { border-color: var(--err); box-shadow: 0 0 0 3px var(--err-soft); }

/* ── Dashboard nav user badge ───────────────────────────────────── */
.user-badge-name { font-size: var(--text-sm); font-weight: 700; color: var(--brand); }

/* ── Square payment card box ────────────────────────────────────── */
.square-card-form-box { padding: var(--space-sm) 0; }
.square-trust-badge { margin-top: var(--space-sm); color: var(--ok); font-size: var(--text-xs); font-weight: 700; }

/* ── PWA update banner ──────────────────────────────────────────── */
.pwa-banner {
  display: none;  /* JS flips to flex when an update is waiting */
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-banner);
  background: var(--surface-1);
  border: 1px solid var(--brand);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.5rem;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-lg);
}

/* ── Add-vehicle wizard (dealer dashboard) ──────────────────────── */
.wizard-dots { display: flex; gap: 0.5rem; margin-bottom: var(--space-sm); }
.wiz-dot {
  flex: 1 1 0;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  transition: var(--transition);
}
.wiz-dot.active { background: var(--brand); }

/* ── Footer ─────────────────────────────────────────────────────── */
footer {
  background: var(--surface-page);
  border-top: 1px solid var(--border);
  padding-block: var(--space-lg);
  padding-inline: var(--page-gutter);
  color: var(--ink-muted);
  font-size: var(--text-sm);
  text-align: center;
  margin-top: auto;
}

.footer-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: clamp(0.75rem, 2vw, 1.5rem);
  margin-bottom: var(--space-sm);
}

.footer-links a { color: var(--ink-muted); text-decoration: none; font-weight: 600; }
.footer-links a:hover { color: var(--brand); }

/* ── Responsive overrides ───────────────────────────────────────── */
@media (max-width: 640px) {
  /* Keep only first link (Inventory) and last item (actions) visible.
     The theme toggle lives in the trailing .nav-links div, never as a
     middle <li>, so it survives this. */
  .nav-links li:not(:last-child):not(:first-child) { display: none; }
  .featured-flagship-card { grid-template-columns: 1fr; }
  .flagship-img { height: clamp(160px, 40vw, 240px); }
  .modal-container { border-radius: var(--radius-md); }
  .toast-container { right: 0.5rem; top: 0.5rem; }
}

@media (max-width: 400px) {
  .filter-group { flex-basis: 100%; }
}

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