/* SAYWA Constat — feuille de style.
   Batie sur les tokens EMPIRE (tokens.css) : seuls --accent et --font-display
   sont surcharges ici, tout le reste reste constant entre les produits SAYWA.
   Mobile first : la mise en page de base est celle du telephone, l'ecran large
   est un elargissement, pas une refonte. */

:root {
  --accent: #2F6BFF;
  --accent-hover: #1E55E0;
  --accent-subtle: #EEF3FF;
  --accent-on: #FFFFFF;
  --alerte: #B42318;
  --alerte-fond: #FEF3F2;
  --attente: #B54708;
  --attente-fond: #FFFAEB;
  --calme: #067647;
  --calme-fond: #ECFDF3;
  --entete-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent-subtle: #16203A;
    --alerte-fond: #2A1413;
    --attente-fond: #2A1E0C;
    --calme-fond: #0C2018;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans, system-ui, -apple-system, "Segoe UI", sans-serif);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

h1, h2, h3 { font-family: var(--font-display, inherit); letter-spacing: -0.015em; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }

/* Accessibilite : cible clavier visible partout, jamais supprimee. */
:focus-visible {
  outline: 2px solid var(--focus, var(--accent));
  outline-offset: 2px;
  border-radius: 6px;
}

.saut {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: var(--accent-on);
  padding: var(--space-1, 8px) 12px; border-radius: 0 0 8px 0;
}
.saut:focus { left: 0; }

/* --- Structure ---------------------------------------------------------- */
.vue { padding: 16px; max-width: 760px; margin: 0 auto; }
.vue--centree {
  min-height: 100dvh; display: grid; place-items: center; padding: 20px;
}
main { padding-top: var(--entete-h); padding-bottom: env(safe-area-inset-bottom, 12px); }

.entete {
  position: fixed; inset: 0 0 auto 0; height: var(--entete-h); z-index: 20;
  display: flex; align-items: center; gap: 8px; padding: 0 8px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.entete__titre {
  flex: 1; display: flex; align-items: center; gap: 8px; justify-content: center;
  font-weight: 600; font-size: 0.95rem;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}

/* --- Cartes et piles ---------------------------------------------------- */
.carte {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px; box-shadow: var(--shadow-xs);
}
.carte--auth { width: min(400px, 100%); padding: 28px 24px; box-shadow: var(--shadow-lg); }
.marque { display: block; margin-bottom: 14px; }
.accroche { color: var(--text-muted); font-size: 0.9rem; margin: 6px 0 22px; }

.pile { display: flex; flex-direction: column; gap: 10px; }

.carte-constat {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px 16px; color: inherit; font: inherit;
  transition: transform var(--dur-fast, 140ms) var(--ease-out, ease),
              border-color var(--dur-fast, 140ms) var(--ease-out, ease),
              box-shadow var(--dur-fast, 140ms) var(--ease-out, ease);
}
.carte-constat:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.carte-constat:active { transform: scale(0.988); }
.carte-constat__ligne {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.carte-constat__titre { font-weight: 600; }
.meta { color: var(--text-muted); font-size: 0.8rem; margin: 3px 0 0; }

/* --- Formulaires -------------------------------------------------------- */
.champ { display: block; margin-bottom: 14px; }
.champ > span {
  display: block; font-size: 0.8rem; font-weight: 550;
  color: var(--text-muted); margin-bottom: 5px;
}
.champ em { font-style: normal; font-weight: 400; opacity: 0.7; }

input[type=text], input[type=email], input[type=password], input[type=date], select {
  width: 100%; padding: 11px 12px; font: inherit; font-size: 16px; /* 16px = pas de zoom iOS */
  color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px;
  transition: border-color var(--dur-fast, 140ms) var(--ease-out, ease),
              box-shadow var(--dur-fast, 140ms) var(--ease-out, ease);
}
input:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.bascule-case { display: flex; align-items: center; gap: 9px; margin-bottom: 16px; font-size: 0.9rem; }
.bascule-case input { width: 18px; height: 18px; accent-color: var(--accent); }

/* --- Boutons ------------------------------------------------------------ */
.bouton {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  width: 100%; padding: 12px 16px; min-height: 44px; /* cible tactile confortable */
  font: inherit; font-weight: 600; font-size: 0.93rem;
  border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  text-decoration: none;
  transition: background var(--dur-fast, 140ms) var(--ease-out, ease),
              transform var(--dur-fast, 140ms) var(--ease-out, ease);
}
.bouton:active { transform: scale(0.985); }
.bouton[disabled] { opacity: 0.55; cursor: not-allowed; transform: none; }
.bouton--primaire { background: var(--accent); color: var(--accent-on); }
.bouton--primaire:hover:not([disabled]) { background: var(--accent-hover); }
.bouton--secondaire {
  background: var(--surface); color: var(--text); border-color: var(--border);
}
.bouton--secondaire:hover { border-color: var(--border-strong); }
.bouton--compact { width: auto; padding: 8px 14px; font-size: 0.85rem; min-height: 38px; }

.bouton-icone {
  display: grid; place-items: center; width: 38px; height: 38px; flex: none;
  background: none; border: none; border-radius: 9px; cursor: pointer; color: var(--text-muted);
}
.bouton-icone:hover { background: var(--bg-muted); color: var(--text); }
.bouton-icone svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.lien {
  background: none; border: none; padding: 0; font: inherit; font-weight: 600;
  color: var(--accent); cursor: pointer; text-decoration: underline;
  text-underline-offset: 2px;
}
.bascule { margin: 18px 0 0; font-size: 0.85rem; color: var(--text-muted); text-align: center; }

.barre-action, .entete-constat {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.actions-constat { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

/* --- Etiquettes --------------------------------------------------------- */
.etiquette {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 650; letter-spacing: 0.01em;
  background: var(--bg-muted); color: var(--text-muted); white-space: nowrap;
}
.etiquette--entree { background: var(--accent-subtle); color: var(--accent); }
.etiquette--sortie { background: var(--attente-fond); color: var(--attente); }
.etiquette--degradation { background: var(--alerte-fond); color: var(--alerte); }
.etiquette--usure { background: var(--calme-fond); color: var(--calme); }
.etiquette--verifier { background: var(--attente-fond); color: var(--attente); }
/* Pièce en attente de capture : elle doit se repérer d'un coup d'œil, on la
   cherche en marchant, le téléphone rangé. */
.etiquette--capture {
  background: var(--accent-subtle); color: var(--accent);
  animation: pulse 2.4s var(--ease-in-out, ease-in-out) infinite;
}
@keyframes pulse { 50% { opacity: 0.45; } }

/* --- Pieces et observations --------------------------------------------- */
.piece { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.piece__entete {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 15px; border-bottom: 1px solid var(--border);
}
.piece__nom { font-weight: 600; }
.piece__corps { padding: 6px 15px 13px; }

.observation {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px;
  align-items: start; padding: 10px 0; border-bottom: 1px solid var(--border);
}
.observation:last-child { border-bottom: none; }
.observation__pastille {
  width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; flex: none;
  background: var(--text-subtle);
}
.observation__pastille[data-gravite="1"] { background: var(--calme); }
.observation__pastille[data-gravite="2"] { background: var(--attente); }
.observation__pastille[data-gravite="3"] { background: var(--alerte); }
.observation__element { font-weight: 550; font-size: 0.9rem; }
.observation__texte { grid-column: 2; color: var(--text-muted); font-size: 0.82rem; }
.observation__etat { font-size: 0.75rem; color: var(--text-subtle); white-space: nowrap; }

/* --- Synthese d'arbitrage ------------------------------------------------ */
.synthese {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px; margin-bottom: 16px;
}
.synthese__chiffres { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 14px; }
@media (min-width: 560px) { .synthese__chiffres { grid-template-columns: repeat(4, 1fr); } }
.chiffre__valeur { font-size: 1.35rem; font-weight: 700; font-family: var(--font-display, inherit); }
.chiffre__libelle { font-size: 0.74rem; color: var(--text-muted); }
.ligne-arbitrage { padding: 11px 0; border-top: 1px solid var(--border); }
.ligne-arbitrage__tete { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ligne-arbitrage__motif { font-size: 0.79rem; color: var(--text-muted); margin: 4px 0 0; }
.montant { font-weight: 650; font-variant-numeric: tabular-nums; }

/* --- Etats et retours --------------------------------------------------- */
.vide { color: var(--text-muted); font-size: 0.9rem; text-align: center; padding: 30px 16px; }
.erreur {
  background: var(--alerte-fond); color: var(--alerte); border-radius: 9px;
  padding: 9px 12px; font-size: 0.84rem; margin: 0 0 14px;
}

.bandeau {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%); z-index: 60;
  display: flex; align-items: center; gap: 9px;
  max-width: calc(100vw - 32px);
  padding: 11px 16px; border-radius: 11px;
  background: var(--surface-raised, var(--surface));
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  font-size: 0.86rem;
  animation: monte 200ms var(--ease-out, ease);
}
.bandeau--erreur { border-color: var(--alerte); color: var(--alerte); }
@keyframes monte { from { opacity: 0; transform: translate(-50%, 10px); } }

.rondelle {
  width: 15px; height: 15px; flex: none; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: tourne 640ms linear infinite;
}
@keyframes tourne { to { transform: rotate(360deg); } }

/* Une animation ne doit jamais etre un obstacle. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
