/* =====================================================================
   AERO Visites — Design System v4
   Eco Drones SASU · mobile-first · terrain
   Palette v2 alignée sur eco-drones.fr + typographie Barlow
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@700;800&family=Barlow:wght@400;500;600;700&display=swap');

:root {
  /* Couleurs marque — palette v2 (site eco-drones.fr) */
  --green: #1A5C08;
  --green-dark: #145A05;
  --green-hover: #1f7009;
  --green-light: #e6f4e1;
  --green-soft: #f4f7f3;
  --ink: #111612;
  --ink-soft: #4a5549;
  --muted: #7d8a7b;
  --line: #d9e0d3;
  --bg: #f4f7f3;
  --card: #ffffff;
  --white: #ffffff;

  /* États */
  --danger: #c81e1e;
  --danger-bg: #fde8e8;
  --warn: #d97706;
  --warn-bg: #fff7e6;
  --info: #0369a1;
  --ok: #1A5C08;

  /* Statuts fiches */
  --st-brouillon: #7d8a7b;
  --st-cadree: #0369a1;
  --st-chiffree: #7c3aed;
  --st-envoyee: #d97706;
  --st-signee: #1A5C08;
  --st-refusee: #c81e1e;
  --st-annulee: #9ca3af;

  /* Typo */
  --font: 'Barlow', -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, sans-serif;
  --font-display: 'Barlow Condensed', 'Barlow', -apple-system, sans-serif;
  --mono: "SF Mono", "Consolas", "Monaco", monospace;

  /* Rayons & ombres */
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --shadow: 0 2px 12px rgba(26,92,8,.07);
  --shadow-lg: 0 8px 32px rgba(26,92,8,.12);

  /* Tailles tactiles */
  --tap: 52px; /* hauteur min boutons/champs (gants, doigts) */
  --tap-lg: 60px;

  /* Espacements */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Palette sombre — variables réutilisées par le mode auto ET le mode forcé */
:root[data-theme="dark"] {
  --bg: #11160f;
  --card: #1a2116;
  --ink: #eef2ea;
  --ink-soft: #c2ccba;
  --muted: #8a948a;
  --line: #2c3626;
  --green-soft: #1d2718;
  --green-light:#23381a;
  --white: #1a2116;
  --shadow: 0 2px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.5);
}

/* Mode auto : applique le sombre si le système est en sombre ET qu'aucun
   choix explicite (data-theme="light") n'a été fait par l'utilisateur. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11160f;
    --card: #1a2116;
    --ink: #eef2ea;
    --ink-soft: #c2ccba;
    --muted: #8a948a;
    --line: #2c3626;
    --green-soft: #1d2718;
    --green-light:#23381a;
    --white: #1a2116;
    --shadow: 0 2px 12px rgba(0,0,0,.4);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  font-size: 16px; /* >=16px = pas de zoom auto iOS sur focus champ */
  overscroll-behavior-y: contain;
  padding-bottom: var(--safe-bottom);
}

/* Empêche le zoom sur double-tap iOS sur les éléments interactifs */
button, a, input, select, textarea { touch-action: manipulation; }

/* Icônes SVG inline */
.ico { width: 1.25em; height: 1.25em; flex-shrink: 0; display: inline-block; vertical-align: -0.22em; }
.ico svg { width: 100%; height: 100%; display: block; }

/* ============================ Layout ============================ */

.app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  padding: var(--sp-4);
  padding-top: calc(var(--sp-4) + var(--safe-top));
}

/* ============================ Topbar ============================ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--green);
  color: #fff;
  padding: calc(var(--sp-4) + var(--safe-top)) var(--sp-4) var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  box-shadow: var(--shadow);
}
.topbar h1 {
  font-family: var(--font-display);
  font-size: 21px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase;
  color: #fff;
}
.topbar .sub { font-size: 13px; opacity: .85; font-weight: 500; color: #fff; }
.topbar .grow { flex: 1; }
.topbar button {
  background: rgba(255,255,255,.14);
  color: #fff;
  border: 0;
  border-radius: var(--r-sm);
  min-width: 44px; height: 44px;
  font-size: 15px; font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 0 var(--sp-3);
}
.topbar button:active { background: rgba(255,255,255,.28); }
.topbar button .ico { width: 20px; height: 20px; vertical-align: middle; }

/* Pastille logo dans la topbar (fond blanc fixe pour le logo couleur) */
.topbar-logo {
  width: 44px; height: 44px;
  background: #fff;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.topbar-logo img { width: 36px; height: 36px; object-fit: contain; display: block; }

/* ============================ Cards ============================ */

.card {
  background: var(--card);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: var(--sp-5);
  margin-bottom: var(--sp-4);
}
.card h2 {
  font-family: var(--font-display);
  font-size: 18px; color: var(--green);
  margin-bottom: var(--sp-3); font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  display: flex; align-items: center; gap: var(--sp-2);
}
.card h2 .ico { width: 20px; height: 20px; }

/* ============================ Forms ============================ */

.field { margin-bottom: var(--sp-4); }
.field label {
  display: block;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: var(--sp-2);
  color: var(--ink-soft);
}
.field .hint { font-size: 13px; color: var(--muted); margin-top: var(--sp-1); }

input[type=text], input[type=email], input[type=password],
input[type=tel], input[type=number], input[type=date], input[type=time],
select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: var(--sp-3) var(--sp-4);
  font-size: 16px;
  font-family: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(26,92,8,.12);
}
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }

/* Code 2FA : gros, espacé, centré */
input.code2fa {
  text-align: center;
  font-family: var(--mono);
  font-size: 28px;
  letter-spacing: .35em;
  font-weight: 600;
}

/* ============================ Buttons ============================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  width: 100%;
  min-height: var(--tap-lg);
  padding: 0 var(--sp-5);
  font-size: 17px;
  font-weight: 700;
  font-family: inherit;
  border: 0;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: transform .08s, background .15s, opacity .15s;
  text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn .ico { width: 20px; height: 20px; }

.btn-primary { background: var(--green); color: #fff; }
.btn-primary:active { background: var(--green-dark); }

.btn-ghost { background: var(--green-soft); color: var(--green); }
.btn-ghost:active { background: var(--green-light); }
:root[data-theme="dark"] .btn-ghost { color: #b9e8a6; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-ghost { color: #b9e8a6; }
}

.btn-danger { background: var(--danger-bg); color: var(--danger); }

.btn-sm { min-height: var(--tap); font-size: 15px; }

/* ============================ Alerts ============================ */

.alert {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-sm);
  font-size: 14px;
  margin-bottom: var(--sp-4);
  border-left: 4px solid;
  line-height: 1.45;
}
.alert-err  { background: var(--danger-bg); border-color: var(--danger); color: #7a0e0e; }
.alert-ok   { background: var(--green-light); border-color: var(--ok); color: var(--green-dark); }
.alert-warn { background: var(--warn-bg); border-color: var(--warn); color: #92500a; }
:root[data-theme="dark"] .alert-err  { color: #ffb4b4; }
:root[data-theme="dark"] .alert-ok   { color: #b9e8a6; }
:root[data-theme="dark"] .alert-warn { color: #ffd98a; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .alert-err  { color: #ffb4b4; }
  :root:not([data-theme="light"]) .alert-ok   { color: #b9e8a6; }
  :root:not([data-theme="light"]) .alert-warn { color: #ffd98a; }
}

/* ============================ Badges statut ============================ */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}
.badge.brouillon { background: var(--st-brouillon); }
.badge.cadree    { background: var(--st-cadree); }
.badge.chiffree  { background: var(--st-chiffree); }
.badge.envoyee   { background: var(--st-envoyee); }
.badge.signee    { background: var(--st-signee); }
.badge.refusee   { background: var(--st-refusee); }
.badge.annulee   { background: var(--st-annulee); }

/* ============================ Liste des fiches ============================ */

.filter-row { display: flex; gap: var(--sp-3); align-items: center; margin-bottom: var(--sp-4); }
.filter-row select { flex: 1; }

.fiche-item {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  padding: var(--sp-4);
  margin-bottom: var(--sp-3);
  cursor: pointer;
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  transition: border-color .15s, transform .08s;
}
.fiche-item:active { transform: scale(.99); border-color: var(--green); }
.fiche-item .fi-top {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-2); margin-bottom: var(--sp-2);
}
.fiche-item .fi-ref { font-family: var(--mono); font-size: 13px; font-weight: 700; color: var(--green); }
:root[data-theme="dark"] .fiche-item .fi-ref { color: #b9e8a6; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .fiche-item .fi-ref { color: #b9e8a6; }
}
.fiche-item .fi-nom { font-size: 16px; font-weight: 700; margin-bottom: 2px; }
.fiche-item .fi-meta { font-size: 13px; color: var(--muted); display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; }
.fiche-item .fi-meta .ico { width: 15px; height: 15px; }

/* ============================ Tuiles de sélection ============================ */

.pick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.pick {
  position: relative;
  min-height: 84px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--r);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px;
  padding: var(--sp-3);
  transition: border-color .15s, background .15s, transform .08s;
}
.pick .ico { width: 28px; height: 28px; color: var(--green); }
:root[data-theme="dark"] .pick .ico { color: #b9e8a6; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pick .ico { color: #b9e8a6; }
}
.pick:active { transform: scale(.98); }
.pick.selected { border-color: var(--green); background: var(--green-soft); font-weight: 700; }
.pick[disabled] { opacity: .45; cursor: not-allowed; }
.pick .soon { font-size: 11px; font-weight: 600; color: var(--muted); }
.pick .tick {
  position: absolute; top: 8px; right: 8px;
  width: 22px; height: 22px;
  background: var(--green); color: #fff;
  border-radius: 50%;
  display: none; align-items: center; justify-content: center;
}
.pick .tick .ico { width: 13px; height: 13px; color: #fff; }
.pick.selected .tick { display: flex; }

.steps {
  font-family: var(--font-display);
  font-size: 13px; font-weight: 700; color: var(--muted);
  letter-spacing: .08em; text-transform: uppercase;
  margin-bottom: var(--sp-2);
}

/* ============================ Détail fiche ============================ */

.detail-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-2); margin-bottom: var(--sp-3);
}
.detail-head .ref { font-family: var(--mono); font-weight: 700; color: var(--green); }
:root[data-theme="dark"] .detail-head .ref { color: #b9e8a6; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .detail-head .ref { color: #b9e8a6; }
}
.detail-row {
  display: flex; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-3) 0; border-bottom: 1px solid var(--line); font-size: 15px;
}
.detail-row:last-child { border-bottom: 0; }
.detail-row .k { color: var(--muted); font-weight: 600; flex-shrink: 0; }
.detail-row .v { text-align: right; word-break: break-word; }

/* ============================ Utilities ============================ */

.center { text-align: center; }
.muted  { color: var(--muted); }
.small  { font-size: 13px; }
.mt-2 { margin-top: var(--sp-2); }
.mt-4 { margin-top: var(--sp-4); }
.mt-6 { margin-top: var(--sp-6); }
.row { display: flex; gap: var(--sp-3); }
.row > * { flex: 1; }
.hidden { display: none !important; }

/* Spinner */
.spinner {
  width: 22px; height: 22px;
  border: 3px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spinner.dark { border-color: rgba(26,92,8,.25); border-top-color: var(--green); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Splash / centre vertical */
.splash {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: var(--sp-4);
  padding: var(--sp-6);
}

/* Logo bloc */
.brand {
  display: flex; flex-direction: column; align-items: center;
  gap: var(--sp-3); margin-bottom: var(--sp-6);
}
.brand .brand-logo {
  max-width: 240px; width: 70vw; height: auto; display: block;
}
:root[data-theme="dark"] .brand .brand-logo {
  background: #fff; border-radius: var(--r); padding: 14px 18px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand .brand-logo {
    background: #fff; border-radius: var(--r); padding: 14px 18px;
  }
}
.brand .name {
  font-family: var(--font-display);
  font-size: 26px; font-weight: 800; letter-spacing: .03em;
  text-transform: uppercase; color: var(--ink);
}
.brand .tag { font-size: 14px; color: var(--muted); font-weight: 500; }

/* Fade-in au chargement */
.fade-in { animation: fadeIn .35s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
