/* Devite — feuille de style unique.
 *
 * Mobile-first, CSS natif, aucune dépendance. Les variables sont en tête :
 * changer l'identité de l'app ne doit demander que de toucher ce bloc.
 *
 * L'app est un formulaire du début à la fin : la densité et la lisibilité des
 * chiffres priment sur tout le reste. D'où les chiffres à chasse fixe partout
 * où un montant s'affiche, et des champs de saisie à 44 px minimum.
 */

:root {
  --bg: #0b1018;
  --surface: #151c28;
  --surface-2: #1e2837;
  --line: #ffffff14;
  --text: #e8eef7;
  --text-dim: #8a97ab;
  --text-faint: #5d6b80;

  --accent: #2dd4bf;
  --on-accent: #06211d;
  --danger: #f43f5e;
  --warn: #f0b429;
  --ok: #7fd8a0;

  --radius: 18px;
  --radius-sm: 12px;
  --gap: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* 100dvh : sur mobile la barre d'URL fausse 100vh (CLAUDE.md, pièges). */
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
}

/* --------------------------------------------------------------- entête */

#app-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(14px + var(--safe-top)) 16px 8px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
}
#app-header h1 {
  margin: 0;
  flex: 1;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
}
.header-actions { display: flex; gap: 4px; }

.icon-btn {
  background: transparent;
  color: var(--text-dim);
  border-radius: 12px;
  padding: 8px 12px;
  min-height: 44px;
  min-width: 44px;
  font-size: 1.1rem;
  line-height: 1;
}
.icon-btn:hover { color: var(--text); }
#btn-back { font-size: 1.9rem; padding: 0 10px; }

#app-main {
  flex: 1;
  padding: 0 16px 32px;
  max-width: 620px;
  width: 100%;
  margin: 0 auto;
}

/* --------------------------------------------------------------- écrans */

.screen { display: none; }
.screen.is-active { display: block; }

.section-title {
  margin: 22px 0 10px;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 600;
}

.placeholder {
  color: var(--text-dim);
  border: 1px dashed var(--surface-2);
  border-radius: var(--radius);
  padding: 22px;
  text-align: center;
  line-height: 1.5;
}

/* -------------------------------------------------------------- boutons */

button {
  font: inherit;
  color: inherit;
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  background: var(--surface-2);
  cursor: pointer;
  /* Cible tactile confortable : jamais moins de 44 px de haut. */
  min-height: 44px;
}
button:active { transform: scale(0.98); }
button.primary { background: var(--accent); color: var(--on-accent); font-weight: 600; }
button.big { font-size: 1.05rem; padding: 15px 26px; border-radius: 16px; }
button.block { display: block; width: 100%; }
button.ghost { background: transparent; color: var(--text-dim); }
button.danger-ghost { background: transparent; color: var(--danger); }
button.danger { background: var(--danger); color: #fff; font-weight: 600; }

button.ghost-box {
  background: transparent;
  border: 1px dashed var(--surface-2);
  color: var(--text-dim);
  margin-bottom: var(--gap);
}
button.ghost-box:hover { color: var(--text); border-color: var(--text-faint); }

.link-btn {
  background: transparent;
  color: var(--accent);
  padding: 4px 0;
  min-height: 0;
  font-size: 0.82rem;
}
.link-btn[hidden] { display: none; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 18px 0 8px;
}
.actions.tight { margin: 12px 0 0; }
.actions button { flex: 1 1 auto; }

/* --------------------------------------------------------------- cartes */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: var(--gap);
}
.card h2 {
  margin: 0 0 12px;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 600;
}
.note {
  margin: 8px 0 0;
  color: var(--text-faint);
  font-size: 0.82rem;
  line-height: 1.4;
}
.opt { color: var(--text-faint); font-weight: 400; }

/* --------------------------------------------------------- liste devis */

#btn-new-quote { margin-bottom: 18px; }

.quote-card, .svc-card { cursor: pointer; }
.quote-card:active, .svc-card:active { border-color: var(--accent); }

.quote-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.quote-head strong { font-size: 1.02rem; }
.quote-total {
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.quote-client {
  margin: 5px 0 0;
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 500;
}
.svc-description {
  margin: 6px 0 0;
  color: var(--text-dim);
  font-size: 0.86rem;
  line-height: 1.4;
  /* Deux lignes suffisent à reconnaître une prestation dans la liste ; la
     description complète se lit dans sa fiche. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-line;
}
.quote-meta {
  margin: 4px 0 0;
  color: var(--text-faint);
  font-size: 0.8rem;
}

/* --------------------------------------------------------------- champs */

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}

input[type="text"], textarea, select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  min-height: 44px;
}
input[type="text"]:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
input[inputmode="decimal"] { font-variant-numeric: tabular-nums; }
textarea {
  resize: vertical;
  line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.86rem;
}

/* Une description se rédige, elle ne se relit pas comme du code : police du
   texte, et hauteur pilotée par autoGrow() — d'où `resize: none` et
   `overflow: hidden`, qui empêchent la barre de défilement de s'installer dans
   un champ de deux lignes. */
.line-description {
  margin-top: 8px;
  padding: 9px 12px;
  min-height: 0;
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.45;
  resize: none;
  overflow: hidden;
}
select {
  /* La flèche native disparaît sur certains thèmes sombres : on la redessine. */
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
                    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 18px) 20px, calc(100% - 13px) 20px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

/* Champ avec son unité collée à droite. */
.input-unit { position: relative; }
.input-unit input { padding-right: 42px; }
.input-unit .unit {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  font-size: 0.85rem;
  pointer-events: none;
}

/* Sélecteur d'unité posé dans le champ, à la place du suffixe fixe. Il doit
   rester cliquable (donc pas de pointer-events: none comme sur .unit) et tenir
   dans une colonne de 110 px sur mobile : deux caractères, pas de flèche. */
.unit-select {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: auto;
  min-height: 34px;
  padding: 4px 15px 4px 7px;
  font-size: 0.82rem;
  color: var(--text);
  background-color: var(--surface-2);
  /* Un chevron minuscule : sans lui, le sélecteur passe pour un simple suffixe
     « h » et personne ne découvre qu'on peut saisir en jours. */
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
                    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 9px) 50%, calc(100% - 5px) 50%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  border: 1px solid var(--line);
  border-radius: 9px;
}
.input-unit:has(.unit-select) input { padding-right: 46px; }
/* Repli pour les navigateurs sans :has() — la règle ci-dessus est ignorée en
   bloc chez eux, et le texte passerait sous le sélecteur. */
@supports not selector(:has(*)) {
  .input-unit input { padding-right: 46px; }
}

.row { display: flex; gap: 10px; }
.row > .field { flex: 1; min-width: 0; }

.is-disabled { opacity: 0.45; }

/* Cases à cocher natives : `accent-color` suffit, et l'accessibilité clavier
   comme le mode lecteur d'écran restent ceux du navigateur. */
.check {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 0;
  font-size: 0.9rem;
  cursor: pointer;
}
.check input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex: none;
  accent-color: var(--accent);
  margin: 0;
}
.check .hint { color: var(--text-faint); font-size: 0.76rem; }
.checks { display: grid; grid-template-columns: 1fr; gap: 0; }
@media (min-width: 460px) {
  .checks { grid-template-columns: 1fr 1fr; column-gap: 14px; }
}

.switch-field {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  margin-top: 12px;
}
.switch-field > div { flex: 1; }
.switch-field label { margin-bottom: 2px; }

.switch {
  flex: none;
  width: 52px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 16px;
  background: var(--surface-2);
  position: relative;
  transition: background 0.18s ease;
}
.switch span {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: transform 0.18s ease, background 0.18s ease;
}
.switch.is-on { background: var(--accent); }
.switch.is-on span { transform: translateX(20px); background: var(--on-accent); }

/* --------------------------------------------------------- ligne de devis */

.line { padding: 14px; }


.line-head { display: flex; gap: 6px; align-items: flex-start; }

/* ⚠️ `touch-action: none` n'est pas optionnel : sans lui, le navigateur mobile
   s'approprie le glissement pour faire défiler la page et aucun `pointermove`
   n'atteint la poignée. Le geste part d'ici, jamais de la carte entière. */
.drag-handle {
  flex: none;
  touch-action: none;
  cursor: grab;
  background: transparent;
  color: var(--text-faint);
  padding: 10px 6px;
  min-height: 44px;
  min-width: 30px;
  font-size: 1.05rem;
  line-height: 1;
}
.drag-handle:active { cursor: grabbing; color: var(--text); }

.line.is-dragging {
  border-color: var(--accent);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.55);
  opacity: 0.92;
}
.line-head .suggest-wrap { flex: 1; min-width: 0; }
.line-head .icon-btn { flex: none; color: var(--text-faint); font-size: 0.95rem; }

/* Le conteneur des suggestions est en position absolue DANS la carte : sans
   position: relative ici, il se placerait par rapport à la page et suivrait le
   défilement au lieu de rester sous le champ. */
.suggest-wrap { position: relative; }
.suggest {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 30;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.55);
}
.suggest[hidden] { display: none; }
.suggest-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border-radius: 0;
  padding: 11px 12px;
  min-height: 0;
}
.suggest-item + .suggest-item { border-top: 1px solid var(--line); }
.suggest-item:hover { background: var(--surface); }
.suggest-name { font-size: 0.92rem; }
.suggest-meta { color: var(--text-faint); font-size: 0.78rem; white-space: nowrap; }

.line-grid {
  display: grid;
  grid-template-columns: 0.8fr 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
/* ⚠️ `display: grid` (et `display: flex` plus bas) écrasent le `[hidden]` du
   navigateur : sans ces règles, masquer un bloc par `el.hidden = true` ne fait
   rien du tout. Voir le piège n°23 du CLAUDE.md. */
.row[hidden] { display: none; }
/* Mode forfait : deux colonnes au lieu de trois (quantité + prix). Les champs
   masqués sortent du flux, les deux restants occupent la grille. */
.line.is-flat .line-grid { grid-template-columns: 0.8fr 1fr; }
.line-grid .field { margin-bottom: 0; }
.line-grid .field > label { font-size: 0.74rem; }
.line-grid input { padding: 10px 8px; }
.line-grid .input-unit input { padding-right: 26px; }
.line-grid .input-unit:has(.unit-select) input { padding-right: 42px; }
.line-grid .input-unit .unit { right: 8px; font-size: 0.78rem; }
.line-grid .unit-select { right: 3px; min-height: 30px; padding: 2px 14px 2px 6px; font-size: 0.78rem; }

.line-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 12px;
}
.flat-check {
  flex: none;
  padding: 0;
  font-size: 0.82rem;
  color: var(--text-dim);
}
.flat-check input[type="checkbox"] { width: 18px; height: 18px; }
.line-foot .line-meta { flex: 1; text-align: right; }
.line-meta { color: var(--text-faint); font-size: 0.78rem; }
.line-total {
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.line .link-btn { display: block; margin-top: 10px; }
/* ⚠️ Même spécificité que `.link-btn[hidden]` plus haut : sans cette règle, la
   dernière déclarée l'emporte et le bouton reste visible malgré son attribut
   hidden. Symptôme : « + Ajouter au catalogue » proposé sur une prestation qui
   y est déjà. */
.line .link-btn[hidden] { display: none; }

/* --------------------------------------------------------- récapitulatif */

.tot-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  font-size: 0.92rem;
  color: var(--text-dim);
}
.tot-row strong {
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
}
.tot-row.is-main {
  border-top: 1px solid var(--line);
  margin-top: 4px;
  padding-top: 12px;
  font-size: 1rem;
  color: var(--text);
}
.tot-row.is-main strong { font-size: 1.25rem; font-weight: 600; color: var(--accent); }

/* --------------------------------------------------------------- chips */

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  flex: 1 1 auto;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 0.88rem;
}
.chip.is-on { background: var(--accent); color: var(--on-accent); font-weight: 600; }

/* --------------------------------------------------------------- toasts */

#toast-host {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(16px + var(--safe-bottom));
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  max-width: min(92vw, 440px);
  background: var(--surface-2);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  animation: rise 0.18s ease-out;
}
.toast button { padding: 6px 10px; min-height: 0; background: var(--accent); color: var(--on-accent); font-weight: 600; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* ------------------------------------------------------------- bannières */

#banner-host { position: fixed; left: 0; right: 0; bottom: calc(16px + var(--safe-bottom)); z-index: 50; padding: 0 12px; }
.banner {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
  animation: rise 0.2s ease-out;
}
.banner .banner-body { flex: 1; }
.banner strong { display: block; margin-bottom: 2px; }
.banner p { margin: 0; color: var(--text-dim); font-size: 0.9rem; }
.banner .banner-close { background: transparent; color: var(--text-dim); padding: 4px 8px; min-height: 0; }

/* --------------------------------------------------------------- modales */

#modal-host {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(4, 8, 14, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
#modal-host[hidden] { display: none; }
.sheet {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 18px 16px calc(18px + var(--safe-bottom));
  max-height: 85dvh;
  overflow-y: auto;
  animation: slide-up 0.2s ease-out;
}
.sheet h2 { margin: 0 0 14px; font-size: 1.05rem; }
@keyframes slide-up { from { transform: translateY(16px); opacity: 0; } }

/* ------------------------------------------------------- grands écrans */

@media (min-width: 520px) {
  .sheet { border-radius: var(--radius); margin-bottom: 24px; }
  #modal-host { align-items: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ------------------------------------------------------- synchronisation */
/* Panneau posé par js/sync-ui.js dans #sync-panel. Les couleurs sortent des
   variables du thème définies en tête de fichier : ne rien coder en dur ici,
   sinon le panneau jure dans chaque app qui change de teinte. */

.sync-status {
  margin: 0 0 4px;
  font-weight: 600;
}

/* L'état est porté par un attribut plutôt que par une classe : sync-ui.js
   écrit un seul dataset.state, et le CSS décide seul de la couleur. */
.sync-status[data-state='ready'] { color: var(--ok, #7fd8a0); }
.sync-status[data-state='syncing'] { opacity: .7; }
.sync-status[data-state='unverified'] { color: var(--warn, #f0b429); }
.sync-status[data-state='error'] { color: var(--error, #ff8a8a); }
.sync-status[data-state='offline'],
.sync-status[data-state='anonymous'] { color: var(--fg-dim, #98a0ad); }

.sync-detail {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--fg-dim, #98a0ad);
}

.sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.sync-btn {
  flex: 1 1 auto;
  min-width: 160px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  color: var(--on-accent);
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.sync-btn:disabled { opacity: .55; cursor: default; }
.sync-btn[hidden] { display: none; }

.sync-btn.ghost {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
}

/* Bouton en attente de confirmation (déconnexion en deux temps). Sans repère
   visuel, le premier clic passe pour un clic qui n'a rien fait. */
.sync-btn.is-armed {
  color: var(--warn);
  border-color: var(--warn);
}

/* L'iframe de connexion. Elle annonce sa hauteur par postMessage ; la
   transition évite le à-coup quand on passe d'un panneau à l'autre. */
.sync-frame {
  margin-top: 16px;
  padding: 14px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.sync-frame iframe {
  display: block;
  transition: height .15s ease-out;
}

.sync-frame[hidden] { display: none; }
