/* ============================================================
   GenBox — reset, éléments de base, utilitaires partagés
   ============================================================ */

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

html, body {
  height: 100%;
  font-family: var(--ui);
  font-size: var(--fs);
  line-height: 1.5;
  color: var(--tx);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* CRITIQUE — la coquille est une colonne flex de la hauteur de la fenêtre :
   barre du haut (fixe) + bandeau budget (fixe) + page (tout le reste).
   Sans ça, `.page { flex: 1 }` n'a aucun conteneur de référence : les pages
   n'ont plus de hauteur bornée, plus rien ne défile et la barre de saisie
   ne tient plus en bas. `min-height: 0` autorise les enfants à rétrécir
   sous leur contenu — sinon un flex item refuse de défiler. */
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}
body > main.page { min-height: 0; }

a { color: var(--violet); text-decoration: none; }
a:hover { color: var(--violet-hi); }

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

h1, h2, h3, h4 { font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }

code, .mono { font-family: var(--mono); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-soft); border-radius: var(--r-full); }
::-webkit-scrollbar-thumb:hover { background: var(--line); }
* { scrollbar-width: thin; scrollbar-color: var(--line-soft) transparent; }

:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; }

/* ---------- utilitaires ---------- */
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.spacer { flex: 1; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- champs ---------- */
.field, input[type="text"], input[type="password"], input[type="number"],
input[type="date"], select, textarea {
  background: var(--void);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  color: var(--tx);
  width: 100%;
  transition: border-color var(--speed);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--violet-dim); }
input::placeholder, textarea::placeholder { color: var(--tx3); }
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--tx3) 50%),
                    linear-gradient(135deg, var(--tx3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
  cursor: pointer;
}
input[type="color"] { padding: 3px; height: 38px; cursor: pointer; }
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.6); cursor: pointer; }

.label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--tx2);
  margin-bottom: 6px;
}
.hint-txt { font-size: var(--fs-sm); color: var(--tx3); line-height: 1.55; }

/* ---------- boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  transition: background var(--speed), color var(--speed), border-color var(--speed);
  white-space: nowrap;
}
.btn-primary { background: var(--violet); color: var(--void); }
.btn-primary:hover:not(:disabled) { background: var(--violet-hi); }
.btn-quiet { background: var(--raised); color: var(--tx2); }
.btn-quiet:hover:not(:disabled) { background: var(--hover); color: var(--tx); }
.btn-ghost { border-color: var(--line); color: var(--tx2); }
.btn-ghost:hover:not(:disabled) { background: var(--raised); color: var(--tx); }
.btn-danger { border-color: var(--danger-tint); color: var(--danger-txt); }
.btn-danger:hover:not(:disabled) { background: var(--danger-tint); }
.btn-sm { font-size: var(--fs-sm); padding: 6px 11px; }
.btn-icon {
  width: 30px; height: 30px; padding: 0;
  border-radius: var(--r-sm);
  background: var(--raised); color: var(--tx2);
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon:hover { background: var(--violet); color: var(--void); }

/* ---------- pastilles de réglage ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--tx2);
  background: transparent;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-full);
  padding: 6px 12px;
  transition: background var(--speed), color var(--speed), border-color var(--speed);
}
.pill:hover { background: var(--raised); color: var(--tx); }
.pill.on { background: var(--violet-tint); border-color: var(--violet-dim); color: var(--violet-txt); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }

/* ---------- étiquettes ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--mono);
  font-size: var(--fs-xs);
  font-weight: 500;
  padding: 3px 8px;
  border-radius: var(--r-xs);
  background: var(--raised);
  color: var(--tx2);
  white-space: nowrap;
}
.badge-cost, .badge-cost-estimate { background: var(--terra-tint); color: var(--terra-txt); }
.badge-cost-estimate { opacity: 0.82; }
.badge-ok { background: var(--ok-tint); color: var(--ok-txt); }
.badge-warn { background: var(--warn-tint); color: var(--warn-txt); }
.badge-owner { background: var(--violet-tint); color: var(--violet-txt); }
.badge-quality-low { background: var(--raised); }
.badge-quality-medium { background: var(--warn-tint); color: var(--warn-txt); }
.badge-quality-high { background: var(--violet-tint); color: var(--violet-txt); }

/* ---------- interrupteurs ---------- */
.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  font-size: 13px;
  color: var(--tx2);
  cursor: pointer;
  user-select: none;
}
.toggle-label input[type="checkbox"] {
  appearance: none;
  width: 36px; height: 20px;
  border-radius: var(--r-full);
  background: var(--raised);
  border: none;
  position: relative;
  flex: none;
  cursor: pointer;
  transition: background var(--speed);
}
.toggle-label input[type="checkbox"]::after {
  content: "";
  position: absolute; top: 3px; left: 3px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--tx3);
  transition: left var(--speed), background var(--speed);
}
.toggle-label input[type="checkbox"]:checked { background: var(--violet); }
.toggle-label input[type="checkbox"]:checked::after { left: 19px; background: var(--void); }

/* ---------- curseurs ---------- */
input[type="range"] {
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: var(--r-full);
  background: var(--raised);
  padding: 0;
  border: none;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--violet);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px; border: none;
  border-radius: 50%; background: var(--violet); cursor: pointer;
}

/* ---------- cartes ---------- */
.card {
  background: var(--base);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  padding: var(--s5);
}

/* ---------- indicateur d'activité ---------- */
.spinner {
  width: 15px; height: 15px;
  border: 2px solid var(--line);
  border-top-color: var(--violet);
  border-radius: 50%;
  flex: none;
}
@media (prefers-reduced-motion: no-preference) {
  .spinner { animation: spin 0.7s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }
}

/* ---------- états vides ---------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  padding: 60px 20px;
  color: var(--tx3);
  text-align: center;
}
.empty-title { font-size: var(--fs-md); font-weight: 600; color: var(--tx2); }
.empty-sub { font-size: 13px; max-width: 44ch; line-height: 1.6; text-wrap: pretty; }
