/*
  Theme tokens + Bootstrap overrides
  Goal: keep the exact same final rendering while removing duplicates.
*/

@font-face {
  font-family: 'Montserrat';
  src: url('../fonts/Montserrat-SemiBold.ttf') format('truetype');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Raleway';
  src: url('../fonts/Raleway-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Brand — COMPARABLES.fr charte graphique
     Primary: Indigo vibrant #240DAB
     Ink:     Noir obsidienne #111111
     Surrounding tints are derived for UI states (50→700). */
  --brand-50:  #f1eefb;
  --brand-100: #e0d9f6;
  --brand-200: #b9a9e9;
  --brand-300: #8e75d8;
  --brand-400: #5d3fc4;
  --brand-500: #240dab;
  --brand-500-rgb: 36, 13, 171;
  --brand-600: #1d0a8a;
  --brand-700: #160878;

  /* Ink — text + neutrals */
  --ink-900: #111111;
  --ink-700: #2a2a2a;
  --ink-500: #6b7280;
  --ink-300: #94a3b8;
  --ink-100: #e2e8f0;
  --ink-50:  #f4f6f8;

  /* Type scale (web translation of the poster scale on charte p.21) */
  --fs-display: clamp(2.5rem, 5vw + 1rem, 5rem);
  --fs-h1:      clamp(1.75rem, 2.5vw + 1rem, 2.75rem);
  --fs-h2:      clamp(1.375rem, 1.5vw + 0.75rem, 2rem);
  --fs-body:    1.0625rem;
  --fs-btn:     1rem;

  /* Radii / shadows */
  --radius-xl: 1.25rem;
  --shadow-soft: 0 14px 40px rgba(16, 24, 40, 0.08);
  --card-radius: 1.25rem;
  --card-shadow: 0 14px 40px rgba(16, 24, 40, 0.08);

  /* Bootstrap 5.3 CSS variable overrides */
  --bs-primary: var(--brand-500);
  --bs-primary-rgb: var(--brand-500-rgb);
  --bs-body-font-family: 'Raleway', sans-serif;
  --bs-heading-font-family: 'Montserrat', sans-serif;
  --bs-body-color: var(--ink-900);
  --bs-body-bg: #fff;
  --bs-border-radius: 1rem;
  --bs-border-radius-lg: 1.25rem;
}

/* Base page background */
body {
  font-family: 'Raleway', sans-serif;
  background: radial-gradient(
      900px 500px at 20% 0%,
      rgba(var(--brand-500-rgb), 0.18),
      transparent 60%
    ),
    radial-gradient(
      700px 450px at 90% 15%,
      rgba(var(--brand-500-rgb), 0.18),
      transparent 55%
    ),
    linear-gradient(180deg, #ffffff 0%, #fbfbff 55%, #ffffff 100%);
  color: var(--ink-900);
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Montserrat', sans-serif;
  font-weight: 600;
}

/* Buttons — rectangular with subtle rounding (not pill) */
.btn {
  border-radius: 0.5rem;
  padding: 0.75rem 1.25rem;
}

/* Override Bootstrap primary buttons (works for BS 5.2+ and wins cascade) */
.btn-primary {
  /* Bootstrap token mapping */
  --bs-btn-color: #fff;
  --bs-btn-bg: var(--brand-500);
  --bs-btn-border-color: var(--brand-500);

  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--brand-600);
  --bs-btn-hover-border-color: var(--brand-600);

  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: var(--brand-600);
  --bs-btn-active-border-color: var(--brand-600);

  /* Hard override for older/variant rules (and for load-order issues) */
  background-color: var(--brand-500) !important;
  border-color: var(--brand-500) !important;
  color: #fff !important;
}

.btn-primary:hover,
.btn-primary:focus {
  background-color: var(--brand-600) !important;
  border-color: var(--brand-600) !important;
  color: #fff !important;
}

.btn-primary:active,
.btn-primary.active,
.show > .btn-primary.dropdown-toggle {
  background-color: var(--brand-600) !important;
  border-color: var(--brand-600) !important;
  color: #fff !important;
}

.btn-primary:disabled,
.btn-primary.disabled {
  background-color: var(--brand-500) !important;
  border-color: var(--brand-500) !important;
  color: #fff !important;
  opacity: 0.65;
}

/* File inputs — replace the native "Choose file" selector button with
   the same look as the app's primary buttons */
input[type="file"].form-control::file-selector-button {
  background-color: var(--brand-500);
  border: 0;
  border-radius: 0.375rem;
  color: #fff;
  transition: background-color 0.15s ease-in-out;
}

input[type="file"].form-control:hover:not(:disabled):not([readonly])::file-selector-button {
  background-color: var(--brand-600);
  color: #fff;
}

.btn-outline-primary {
  border-color: rgba(var(--brand-500-rgb), 0.35);
  color: var(--brand-600);
}

.btn-outline-primary:hover {
  background: rgba(var(--brand-500-rgb), 0.08);
  border-color: rgba(var(--brand-500-rgb), 0.45);
  color: var(--brand-600);
}

/* ── Button loading state ───────────────────────────────────────── */
/* .is-loading is applied by static/js/loaders.js on the control that
   triggered server-side work; htmx forms are covered directly through
   the .htmx-request class htmx sets during a request. */
@keyframes btn-loading-spin {
  to { transform: rotate(360deg); }
}

.btn.is-loading,
form.htmx-request .btn,
.btn.htmx-request {
  pointer-events: none;
  opacity: 0.75;
}

.btn.is-loading::after,
form.htmx-request .btn::after,
.btn.htmx-request::after {
  content: "";
  display: inline-block;
  width: 1em;
  height: 1em;
  margin-left: 0.5em;
  vertical-align: -0.15em;
  border: 0.16em solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-loading-spin 0.6s linear infinite;
}

/* ── Cards (unified) ────────────────────────────────────────────── */
.card {
  border: 1px solid rgba(16, 24, 40, 0.06);
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
}

/* Same metrics as .btn (padding 0.75/1.25rem, 1rem/1.5 type): a card
   header is exactly as tall as a primary button, e.g. the pack cards'
   header matches their "Acheter" button. */
.card > .card-header {
  background: rgba(var(--brand-500-rgb), 0.04);
  border-bottom: 1px solid rgba(16, 24, 40, 0.06);
  border-radius: var(--card-radius) var(--card-radius) 0 0;
  /* extra top pixel: .btn carries a 2px border (top+bottom) while the
     header only has its 1px bottom border */
  padding: calc(0.75rem + 1px) 1.25rem 0.75rem;
  font-family: 'Montserrat', sans-serif;
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.5;
}

/* Headers render identically whatever heading tag templates put inside */
.card > .card-header :is(h1, h2, h3, h4, h5, h6) {
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
  margin: 0;
}

.card > .card-header.card-header--muted {
  background: rgba(var(--brand-500-rgb), 0.04);
  color: var(--ink-900);
}

.card > .card-header.card-header--accent {
  background: var(--brand-500);
  color: #fff;
}

.card > .card-body {
  padding: 1.5rem;
}

.card > .table-responsive:first-child table {
  border-radius: var(--card-radius);
}

.card > .card-header + .table-responsive table {
  border-radius: 0;
}

/* Hero */
.hero {
  padding: 5.5rem 0 3.5rem;
  background: radial-gradient(
      900px 500px at 15% 0%,
      rgba(var(--brand-500-rgb), 0.22),
      transparent 60%
    ),
    radial-gradient(
      700px 450px at 85% 20%,
      rgba(200, 164, 255, 0.22),
      transparent 55%
    ),
    linear-gradient(
      180deg,
      rgba(246, 243, 255, 0.85) 0%,
      rgba(255, 255, 255, 0.92) 55%,
      rgba(255, 255, 255, 1) 100%
    );
}

.hero .eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  color: var(--brand-600);
  background: rgba(var(--brand-500-rgb), 0.1);
  border: 1px solid rgba(var(--brand-500-rgb), 0.18);
}

.hero h1 {
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: var(--ink-900);
}

.hero .lead {
  color: var(--ink-700);
}

.hero-mockup {
  border-radius: var(--card-radius);
  box-shadow: var(--card-shadow);
  background: #fff;
  border: 1px solid rgba(16, 24, 40, 0.06);
  overflow: hidden;
  transform: translateY(6px);
}

.hero-mockup img {
  width: 100%;
  height: auto;
  display: block;
}

/* Content sections (frosted variant) */
.card.card--frosted {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
}

/* Card left-accent variants (status indicators) */
.card.card--accent-left-primary {
  border-left: 4px solid var(--brand-500);
}

.card.card--accent-left-warning {
  border-left: 4px solid var(--bs-warning);
}

.card.card--accent-left-success {
  border-left: 4px solid var(--bs-success);
}

/* Comparables feature cards (home) */
.comparables-card {
  transition: transform 220ms ease, box-shadow 220ms ease;
}

.comparables-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 18px 44px rgba(16, 24, 40, 0.12);
}

.section-title {
  letter-spacing: -0.02em;
  color: var(--ink-900);
}

.kicker {
  color: var(--brand-600);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.feature-list li {
  margin-bottom: 0.35rem;
}

/* Pricing tiles */
.price-tile {
  border: 1px solid rgba(16, 24, 40, 0.08);
  border-radius: 1rem;
  background: linear-gradient(
    180deg,
    rgba(246, 243, 255, 0.7),
    rgba(255, 255, 255, 1)
  );
  box-shadow: 0 10px 24px rgba(16, 24, 40, 0.06);
}

/* FAQ accordion refinement */
.accordion-item {
  border: 1px solid rgba(16, 24, 40, 0.08);
  border-radius: 1rem;
  overflow: hidden;
}

.accordion-button {
  font-weight: 600;
}

.accordion-button:not(.collapsed) {
  color: var(--brand-600);
  background: rgba(var(--brand-500-rgb), 0.08);
}

.sidebar-note {
  position: sticky;
  top: 5rem;
}

/* Navbar dropdown above page panels (map-panel is z-index:1000) */
.navbar .dropdown-menu {
  z-index: 1050;
}

/* Open navbar dropdown on hover */
.navbar .dropdown:hover .dropdown-menu {
  display: block;
}

/* Footer links */
footer a.text-muted:hover {
  color: var(--brand-500) !important;
  text-decoration: underline !important;
}

/* ── Toaster (Sonner-inspired) ───────────────────────────────────
   Fixed bottom-right stack. At rest, only the top toast is fully
   visible; older ones peek behind it. On hover/focus the stack
   expands vertically. Each toast is a white card with a leading
   variant-coloured icon.

   Sizing assumes toasts of similar height; --toast-h tweaks the
   expanded gap. Override via inline style if a specific toast is
   taller than usual.
*/
.toaster {
  position: fixed;
  inset: auto 1rem 1rem auto;
  z-index: 1080;
  width: 356px;
  max-width: calc(100vw - 2rem);
  margin: 0;
  padding: 0;
  list-style: none;
  pointer-events: none;
  --toast-h: 64px;
  --stack-gap: 10px;
}

.toaster .snk-toast {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 100%;
  display: grid;
  grid-template-columns: 20px 1fr auto;
  gap: 0.75rem;
  align-items: start;
  padding: 0.875rem 1rem;
  background: #fff;
  color: var(--ink-900);
  border: 1px solid rgba(16, 24, 40, 0.08);
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.10),
              0 1px 2px rgba(16, 24, 40, 0.06);
  font-family: 'Raleway', sans-serif;
  font-size: 13px;
  line-height: 1.45;
  pointer-events: auto;
  opacity: 1;
  --y: 0px;
  --scale: 1;
  transform: translateY(var(--y)) scale(var(--scale));
  transform-origin: 50% 0;
  transition:
    transform 400ms cubic-bezier(0.21, 1.02, 0.73, 1),
    opacity 400ms cubic-bezier(0.21, 1.02, 0.73, 1);
}

/* Pre-mount state: sits just below the viewport, scaled down.
   The first paint uses this; JS flips data-mounted=true on the
   next frame, which transitions to the resting stacked position. */
.toaster .snk-toast:not([data-mounted="true"]) {
  --y: 100%;
  --scale: 0.9;
  opacity: 0;
  transition: none;
}

/* Stack at rest — most recent on top, two visible behind it. */
.toaster .snk-toast:nth-last-child(1) { --y: 0px;    --scale: 1;    z-index: 3; }
.toaster .snk-toast:nth-last-child(2) { --y: -12px;  --scale: 0.94; z-index: 2; }
.toaster .snk-toast:nth-last-child(3) { --y: -22px;  --scale: 0.88; z-index: 1; }
.toaster .snk-toast:nth-last-child(n+4) { opacity: 0; pointer-events: none; }

/* Expand stack on hover/focus — vertical layout. */
.toaster:hover .snk-toast,
.toaster:focus-within .snk-toast { --scale: 1; }

.toaster:hover .snk-toast:nth-last-child(1),
.toaster:focus-within .snk-toast:nth-last-child(1) { --y: 0px; }
.toaster:hover .snk-toast:nth-last-child(2),
.toaster:focus-within .snk-toast:nth-last-child(2) {
  --y: calc(-1 * (var(--toast-h) + var(--stack-gap)));
}
.toaster:hover .snk-toast:nth-last-child(3),
.toaster:focus-within .snk-toast:nth-last-child(3) {
  --y: calc(-2 * (var(--toast-h) + var(--stack-gap)));
}
.toaster:hover .snk-toast:nth-last-child(n+4),
.toaster:focus-within .snk-toast:nth-last-child(n+4) {
  --y: calc(-3 * (var(--toast-h) + var(--stack-gap)));
  opacity: 0;
}

/* Exit: slide down and fade out, regardless of stack position. */
.toaster .snk-toast[data-removing="true"] {
  --y: 110% !important;
  --scale: 0.9 !important;
  opacity: 0;
}

.toaster .snk-toast-icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-500);
  flex: none;
  margin-top: 1px;
}
.toaster .snk-toast-icon svg { width: 20px; height: 20px; }

.toaster .snk-toast-content { min-width: 0; }
.toaster .snk-toast-title {
  font-weight: 600;
  color: var(--ink-900);
  font-size: 13px;
  line-height: 1.35;
}
.toaster .snk-toast-message {
  margin-top: 2px;
  color: var(--ink-500);
  font-size: 13px;
  line-height: 1.4;
}
.toaster .snk-toast-title:only-child { font-weight: 500; }

.toaster .snk-toast-close {
  appearance: none;
  background: transparent;
  border: 0;
  padding: 0;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-300);
  cursor: pointer;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 150ms, color 150ms, background 150ms;
}
.toaster .snk-toast:hover .snk-toast-close,
.toaster .snk-toast:focus-within .snk-toast-close { opacity: 1; }
.toaster .snk-toast-close:hover {
  color: var(--ink-700);
  background: rgba(16, 24, 40, 0.05);
}
.toaster .snk-toast-close svg { width: 14px; height: 14px; }

/* Variant accent — icon colour only, card stays neutral white. */
.toaster .snk-toast-success .snk-toast-icon { color: #16a34a; }
.toaster .snk-toast-error   .snk-toast-icon { color: #dc2626; }
.toaster .snk-toast-warning .snk-toast-icon { color: #d97706; }
.toaster .snk-toast-info    .snk-toast-icon { color: #2563eb; }
.toaster .snk-toast-default .snk-toast-icon { color: var(--brand-500); }

/* Reduced motion — keep entrance/exit but disable stack hover travel. */
@media (prefers-reduced-motion: reduce) {
  .toaster .snk-toast { transition-duration: 0ms; }
}

/* Basemap look (issue #312). The IGN Plan v2 tiles are busy and beige; fade
   them to a pale grey so the filter panel and the reference polygons stand
   out, like the CARTO Light basemap used before. Only the tile pane is
   filtered: polygons, markers and tooltips keep their colours. */
.leaflet-tile-pane {
  filter: grayscale(1) contrast(0.55) brightness(1.32);
}
