/* ============================================================
   Comparateur fournisseurs — Design v3 "Chantier Pro"
   Space Grotesk + JetBrains Mono · Anthracite · Orange vif
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@500;700&family=DM+Sans:wght@400;500;600&display=swap');

:root {
  --bg:           #F5F4F0;
  --surface:      #FFFFFF;
  --surface-2:    #F9F8F5;
  --ink:          #18181B;
  --ink-soft:     #71717A;
  --ink-faint:    #A1A1AA;
  --line:         #E4E4E7;
  --line-strong:  #D4D4D8;

  /* Brand anthracite */
  --brand:        #1C1917;
  --brand-mid:    #292524;
  --brand-light:  #44403C;

  /* Orange chantier */
  --orange:       #EA580C;
  --orange-light: #FFF7ED;
  --orange-mid:   #FFEDD5;
  --orange-dark:  #C2410C;

  /* Vert économie */
  --green:        #16A34A;
  --green-bg:     #F0FDF4;
  --green-dark:   #15803D;

  /* Alertes */
  --warn:         #D97706;
  --warn-bg:      #FFFBEB;
  --danger:       #DC2626;
  --danger-bg:    #FEF2F2;
  --info:         #2563EB;
  --info-bg:      #EFF6FF;

  --sidebar-w:    260px;
  --radius:       10px;
  --radius-sm:    6px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow:       0 4px 6px rgba(0,0,0,.05), 0 10px 25px rgba(0,0,0,.08);
  --shadow-lg:    0 10px 20px rgba(0,0,0,.1), 0 30px 60px rgba(0,0,0,.12);

  --font-display: 'Space Grotesk', 'Segoe UI', sans-serif;
  --font-body:    'DM Sans', 'Segoe UI', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', 'Cascadia Mono', ui-monospace, monospace;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .display {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.15;
}
h1 { font-size: clamp(1.55rem, 2.5vw, 2rem); margin-bottom: .3rem; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 .75rem; color: var(--ink); }
h3 { font-size: 1rem; font-weight: 600; }

a { color: var(--orange); text-decoration: none; transition: color .15s; }
a:hover { color: var(--orange-dark); }
::selection { background: var(--orange); color: #fff; }
:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; border-radius: 4px; }

/* ============================================================
   LAYOUT
   ============================================================ */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}
.main {
  padding: clamp(1.5rem, 3vw, 2.5rem) clamp(1rem, 4vw, 3rem);
  max-width: 1280px;
  width: 100%;
  min-width: 0;
}

/* ============================================================
   SIDEBAR — anthracite profond
   ============================================================ */
.sidebar {
  background: var(--brand);
  color: #A8A29E;
  padding: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  border-right: 1px solid rgba(0,0,0,.3);
}

.sidebar .logo {
  padding: 1.6rem 1.25rem 1.4rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
  margin-bottom: .5rem;
}
.sidebar .logo .logo-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: #FFF;
  letter-spacing: -.02em;
  line-height: 1.2;
}
.sidebar .logo .logo-sub {
  font-size: .73rem;
  color: #78716C;
  margin-top: .2rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 500;
}

/* Groupes nav */
.sidebar .nav-group {
  padding: .25rem 0;
  margin-bottom: .25rem;
}
.sidebar .nav-label {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: 700;
  color: #57534E;
  padding: .5rem 1.25rem .25rem;
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: .6rem;
  color: #A8A29E;
  padding: .6rem 1.25rem;
  font-size: .88rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background .12s, color .12s, border-color .12s;
  position: relative;
}
.sidebar a:hover {
  background: rgba(255,255,255,.05);
  color: #E7E5E4;
  text-decoration: none;
}
.sidebar a.active {
  background: rgba(234,88,12,.12);
  color: #FFF;
  font-weight: 600;
  border-left-color: var(--orange);
}
.sidebar a .nav-icon { font-size: 1rem; opacity: .75; width: 1.15rem; text-align: center; }
.sidebar a.active .nav-icon { opacity: 1; }

.sidebar .user {
  margin-top: auto;
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.07);
  font-size: .78rem;
  color: #57534E;
  line-height: 1.7;
  word-break: break-all;
}
.sidebar .user a {
  color: #78716C;
  border-left: none;
  padding: 0;
  display: inline;
  font-size: .75rem;
}
.sidebar .user a:hover { color: #E7E5E4; background: none; }

/* ============================================================
   TOPBAR MOBILE
   ============================================================ */
.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 60;
  background: var(--brand);
  padding: 0 1rem;
  height: 52px;
  align-items: center;
  gap: .75rem;
  box-shadow: 0 1px 0 rgba(255,255,255,.07), var(--shadow-sm);
}
.topbar .burger {
  background: none;
  border: none;
  color: #A8A29E;
  font-size: 1.4rem;
  cursor: pointer;
  padding: .3rem;
  border-radius: 6px;
  line-height: 1;
  transition: color .15s, background .15s;
}
.topbar .burger:active { background: rgba(255,255,255,.1); color: #fff; }
.topbar .topbar-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: .95rem;
  color: #fff;
  letter-spacing: -.01em;
}
.topbar .topbar-dot {
  margin-left: auto;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--orange);
}

.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10,10,10,.65);
  backdrop-filter: blur(3px);
  z-index: 70;
  opacity: 0;
  transition: opacity .22s;
}
.drawer-overlay.open { opacity: 1; }

/* ============================================================
   CARTES
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow-sm);
}
.card--flush { padding: 0; overflow: hidden; }

/* ============================================================
   STATS — chiffres oversized en mono
   ============================================================ */
.grid-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .75rem;
  margin: 1.25rem 0;
}
.stat-card { padding: 1.1rem 1.25rem; }
.stat-card .k {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 700;
  color: var(--ink-faint);
  margin-bottom: .4rem;
}
.stat-card .v {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   BOUTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .6rem 1.15rem;
  border-radius: 8px;
  font-family: var(--font-display);
  font-size: .88rem;
  font-weight: 600;
  letter-spacing: -.01em;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: transform .1s, box-shadow .15s, background .15s;
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }

.btn-primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.btn-primary:hover { background: var(--brand-mid); box-shadow: 0 3px 8px rgba(0,0,0,.2); }

.btn-accent {
  background: var(--orange);
  color: #fff;
  border-color: var(--orange);
  box-shadow: 0 1px 3px rgba(234,88,12,.35);
}
.btn-accent:hover { background: var(--orange-dark); box-shadow: 0 3px 10px rgba(234,88,12,.4); }

.btn-ghost {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line-strong);
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--ink-soft); }

.btn-full { width: 100%; margin-top: .75rem; }

/* ============================================================
   BADGES — solides et lisibles
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .02em;
  padding: .22rem .6rem;
  border-radius: 4px;
  line-height: 1.4;
  text-transform: uppercase;
}
.badge-cheapest, .badge-certain {
  background: var(--green);
  color: #fff;
}
.badge-probable  { background: var(--info);   color: #fff; }
.badge-uncertain { background: var(--warn);   color: #fff; }
.badge-different { background: var(--danger); color: #fff; }
.badge-default   { background: var(--line); color: var(--ink-soft); }

/* ============================================================
   FORMULAIRES
   ============================================================ */
label {
  display: block;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-soft);
  margin: .85rem 0 .35rem;
}
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=file], select, textarea {
  width: 100%;
  padding: .65rem .8rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: .93rem;
  background: var(--surface);
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(234,88,12,.12);
}
/* Signature : inputs numériques en mono */
input[type=number] { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ============================================================
   TABLEAUX
   ============================================================ */
table { width: 100%; border-collapse: collapse; font-size: .88rem; }

th {
  text-align: left;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-soft);
  padding: .6rem .85rem;
  background: var(--surface-2);
  border-bottom: 2px solid var(--line);
  white-space: nowrap;
}
td {
  padding: .72rem .85rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover td { background: #FAFAF9; }

/* Signature : TOUS les montants en JetBrains Mono */
.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  letter-spacing: -.03em;
  white-space: nowrap;
  font-weight: 500;
}

/* Ligne moins chère — vert franc */
.tr-cheapest td { background: var(--green-bg) !important; }
.tr-cheapest td:first-child { border-left: 3px solid var(--green); }
.tr-cheapest .num { color: var(--green-dark); font-weight: 700; }

/* ============================================================
   ALERTES
   ============================================================ */
.alert {
  padding: .8rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  margin-bottom: 1rem;
  border-left: 3px solid transparent;
  line-height: 1.5;
}
.alert-danger  { background: var(--danger-bg); color: #991B1B; border-left-color: var(--danger); }
.alert-success { background: var(--green-bg);  color: var(--green-dark); border-left-color: var(--green); }
.alert-info    { background: var(--info-bg);   color: #1D4ED8; border-left-color: var(--info); }

/* ============================================================
   TOTAUX PANIER
   ============================================================ */
.totals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 1rem;
}
.total-block .k {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 700;
  color: var(--ink-faint);
  margin-bottom: .35rem;
}
.total-block .v {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.total-block.savings .v { color: var(--green); }
.total-block.savings .k { color: var(--green); }

/* ============================================================
   PAGES AUTH
   ============================================================ */
.auth-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: var(--bg);
}
.auth-box {
  width: 420px;
  max-width: 100%;
  padding: 2rem 1.75rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.auth-box h1 { margin-bottom: .2rem; }
.auth-box .sub { color: var(--ink-soft); margin-bottom: 1.5rem; font-size: .92rem; }

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }
::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 1100px) {
  :root { --sidebar-w: 220px; }
}

@media (max-width: 820px) {
  body { overflow-x: hidden; }
  .app-layout { grid-template-columns: 1fr; max-width: 100vw; }
  .topbar { display: flex; }
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: min(280px, 82vw);
    z-index: 80;
    transform: translateX(-105%);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
    box-shadow: var(--shadow-lg);
    height: 100dvh;
  }
  .sidebar.open { transform: translateX(0); }
  .drawer-overlay.show { display: block; }
  .main { padding: 1.15rem .95rem 3rem; }
  .card--flush { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .card--flush table { min-width: 520px; }
  .form-row { grid-template-columns: 1fr; }
  .grid-stats { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
  .stat-card .v { font-size: 1.65rem; }
  .totals-grid { grid-template-columns: repeat(2, 1fr); }
  .btn { min-height: 44px; }
  input, select, textarea { min-height: 44px; }
  h1 { font-size: 1.4rem; }
  /* Override inline grid styles sur mobile */
  [style*="grid-template-columns:1fr 340px"],
  [style*="grid-template-columns:1fr 300px"],
  [style*="grid-template-columns: 220px 1fr"],
  [style*="grid-template-columns:220px 1fr"] {
    grid-template-columns: 1fr !important;
  }
  #modal-overlay > .card { width: 95vw !important; max-height: 90dvh; overflow-y: auto; }
}

@media (max-width: 420px) {
  .grid-stats, .totals-grid { grid-template-columns: 1fr 1fr; }
  body { font-size: 14px; }
}

/* ============================================================
   IMPRESSION
   ============================================================ */
@media print {
  .sidebar, .topbar, .drawer-overlay, .btn, button { display: none !important; }
  .app-layout { display: block; }
  .main { padding: 0; max-width: 100%; }
  .card { box-shadow: none !important; break-inside: avoid; }
  body { background: #fff; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ============================================================
   AMÉLIORATIONS PRÉSENTATION
   ============================================================ */

/* Sous-titres de page */
.page-sub {
  color: var(--ink-soft);
  font-size: .93rem;
  margin-top: 0;
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

/* En-tête de page avec action principale */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.page-header h1 { margin: 0; }
.page-header .page-actions { display: flex; gap: .5rem; flex-wrap: wrap; flex-shrink: 0; }

/* Carte avec accent coloré gauche */
.card-accent {
  border-left: 3px solid var(--orange);
}
.card-accent-green {
  border-left: 3px solid var(--green);
}

/* Badge de statut inline */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .2rem .55rem;
  border-radius: 4px;
}

/* Numéro de ligne discret */
.line-num {
  font-family: var(--font-mono);
  font-size: .72rem;
  font-weight: 500;
  color: var(--ink-faint);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: .1rem .4rem;
  min-width: 1.8rem;
  text-align: center;
}

/* Tableau sans bordures extérieures dans une card--flush */
.card--flush table th:first-child,
.card--flush table td:first-child { padding-left: 1rem; }
.card--flush table th:last-child,
.card--flush table td:last-child  { padding-right: 1rem; }

/* Bouton icône seul */
.btn-icon {
  width: 34px; height: 34px;
  padding: 0;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

/* Compteur animé */
@keyframes countUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
.count-up { animation: countUp .45s ease both; }

/* Hover sur les lignes de tableau — indicateur visuel */
tbody tr { cursor: default; }
tbody tr[onclick], tbody tr a { cursor: pointer; }

/* Indicateur de chargement */
.loading-dots::after {
  content: '';
  animation: dots 1.2s infinite;
}
@keyframes dots {
  0%   { content: '.'; }
  33%  { content: '..'; }
  66%  { content: '...'; }
}

/* Kbd style */
kbd {
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: .1rem .4rem;
  font-family: var(--font-mono);
  font-size: .75rem;
  color: var(--ink-soft);
  box-shadow: 0 1px 0 var(--line-strong);
}

/* Tooltip simple via data-tip */
[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: .73rem;
  padding: .3rem .6rem;
  border-radius: 5px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
  font-family: var(--font-body);
}

/* ============================================================
   RESPONSIVE dashboard hero
   ============================================================ */
@media (max-width: 820px) {
  .dash-hero { grid-template-columns: 1fr; }
  .dash-hero .hero-actions { flex-direction: row; }
  .dash-grid, .dash-grid-3 { grid-template-columns: 1fr; }
}
