/* ==========================================================================
   Composants communs
   ========================================================================== */

/* --- Icônes -------------------------------------------------------------- */

.icon {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

.icon--sm {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}

/* --- Barre du haut ------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: var(--s-2);
  min-height: 56px;
  padding: var(--safe-top) calc(var(--gutter) - 12px) 0;
  background: var(--bg);
}

.topbar--bordered {
  border-bottom: 1px solid var(--line);
}

.topbar__title {
  overflow: hidden;
  font-size: var(--fs-md);
  font-weight: 500;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Boutons ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 48px;
  padding: 0 var(--s-5);
  border: 1px solid transparent;
  border-radius: var(--r-btn);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 500;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  user-select: none;
  transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
    transform var(--t-fast) var(--ease);
}

.btn:active {
  transform: scale(0.985);
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
}

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

.btn--primary:active {
  background: #d9d6cf;
}

.btn--accent {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn--accent:active {
  background: color-mix(in srgb, var(--accent) 85%, black);
}

.btn--secondary:active {
  background: var(--surface-3);
}

.btn--ghost {
  border-color: var(--line-strong);
  background: transparent;
  color: var(--text);
}

.btn--ghost:active {
  background: var(--surface-1);
}

.btn--danger {
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  background: transparent;
  color: var(--danger);
}

.btn--sm {
  min-height: 36px;
  padding: 0 var(--s-3);
  font-size: var(--fs-base);
}

.btn--lg {
  min-height: 56px;
  font-size: var(--fs-lg);
}

.btn--block {
  width: 100%;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--r-btn);
  background: transparent;
  color: var(--text-2);
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.icon-btn:active {
  background: var(--surface-2);
  color: var(--text);
}

/* --- Titres de section --------------------------------------------------- */

.section {
  margin-top: var(--s-8);
}

.section-label {
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
  margin-bottom: var(--s-2);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.section-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
  transform: translateY(-3px);
}

.section-label__count {
  order: 2;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

/* --- Lignes de liste ----------------------------------------------------- */

.row {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  width: 100%;
  min-height: 56px;
  padding: var(--s-3) 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  color: var(--text);
  text-align: left;
  text-decoration: none;
}

.row:last-child {
  border-bottom: 0;
}

button.row:active,
a.row:active {
  background: linear-gradient(var(--surface-1), var(--surface-1)) no-repeat center / calc(100% + 2 * var(--gutter)) 100%;
}

.row__main {
  flex: 1;
  min-width: 0;
}

.row__title,
.row__hint {
  display: block;
}

.row__title {
  font-size: var(--fs-md);
  font-weight: 500;
}

.row__hint {
  margin-top: 2px;
  color: var(--text-2);
  font-size: var(--fs-sm);
}

.row__value {
  color: var(--text-2);
  font-size: var(--fs-base);
  font-variant-numeric: tabular-nums;
}

.row--danger .row__title {
  color: var(--danger);
}

.row .icon {
  color: var(--text-3);
}

/* --- Interrupteur (volontairement carré) --------------------------------- */

.switch {
  position: relative;
  flex: none;
  width: 42px;
  height: 24px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: var(--surface-2);
  transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 2px;
  background: var(--text-2);
  transition: transform var(--t-med) var(--ease), background-color var(--t-fast) var(--ease);
}

[aria-checked="true"] > .switch {
  border-color: var(--accent);
  background: var(--accent);
}

[aria-checked="true"] > .switch::after {
  background: var(--accent-ink);
  transform: translateX(18px);
}

/* --- Sélecteur numérique ------------------------------------------------- */

.stepper {
  display: inline-flex;
  align-items: center;
  flex: none;
}

/* Valeur calculée alignée sur les sélecteurs (2 × 40 px de boutons + valeur) */
.stepper--static {
  justify-content: center;
  width: 124px;
}

.stepper__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-btn);
  background: transparent;
  color: var(--text);
}

.stepper__btn:active {
  background: var(--surface-2);
}

.stepper__btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.stepper__value {
  min-width: 44px;
  font-size: var(--fs-lg);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

/* --- Contrôle segmenté --------------------------------------------------- */

.segmented {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-btn);
}

.segmented__option {
  flex: 1;
  min-height: 38px;
  padding: 0 var(--s-2);
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-base);
  font-weight: 500;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.segmented__option[aria-checked="true"] {
  background: var(--surface-3);
  color: var(--text);
}

/* --- Étiquettes sélectionnables (catégories) ----------------------------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.chip {
  min-height: 38px;
  padding: 0 var(--s-3);
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-base);
  transition: border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease),
    background-color var(--t-fast) var(--ease);
}

.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--text);
}

/* --- Champs -------------------------------------------------------------- */

.field {
  display: block;
}

.field__label {
  display: block;
  margin-bottom: var(--s-2);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
}

.input {
  width: 100%;
  min-height: 48px;
  padding: 0 var(--s-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-input);
  background: var(--surface-1);
  font-size: var(--fs-md); /* 16 px minimum : évite le zoom automatique sur iOS */
  transition: border-color var(--t-fast) var(--ease);
}

.input::placeholder {
  color: var(--text-3);
}

.input:focus {
  border-color: var(--accent);
  outline: none;
}

.input[aria-invalid="true"] {
  border-color: var(--danger);
}

select.input {
  padding-right: 40px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a09e98' stroke-width='1.75'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-position: right 12px center;
  background-repeat: no-repeat;
  background-size: 18px;
}

textarea.input {
  min-height: 96px;
  padding: var(--s-3);
  resize: vertical;
}

.field__error {
  margin-top: var(--s-2);
  color: var(--danger);
  font-size: var(--fs-sm);
}

/* --- Bandeau d'information ----------------------------------------------- */

.notice {
  display: flex;
  gap: var(--s-3);
  padding: var(--s-4);
  border-left: 2px solid var(--accent);
  border-radius: 0 var(--r-card) var(--r-card) 0;
  background: var(--surface-1);
}

.notice--warning {
  border-left-color: var(--danger);
}

.notice__body {
  flex: 1;
  min-width: 0;
}

.notice__title {
  font-weight: 500;
}

.notice__text {
  margin-top: 2px;
  color: var(--text-2);
  font-size: var(--fs-base);
}

.notice__actions {
  display: flex;
  gap: var(--s-2);
  margin-top: var(--s-3);
}

/* --- Feuille de dialogue (bas d'écran) ----------------------------------- */

.sheet {
  width: 100%;
  max-width: var(--app-width);
  max-height: 90dvh;
  margin: auto auto 0;
  padding: var(--s-6) var(--gutter) calc(var(--s-5) + var(--safe-bottom));
  border: 0;
  border-top: 1px solid var(--line-strong);
  border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  background: var(--surface-1);
  color: var(--text);
}

.sheet[open] {
  animation: sheet-in var(--t-med) var(--ease);
}

.sheet::backdrop {
  background: rgb(0 0 0 / 0.62);
}

@keyframes sheet-in {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}

.sheet__title {
  font-size: var(--fs-xl);
  font-weight: 500;
  line-height: 1.25;
}

.sheet__text {
  margin-top: var(--s-2);
  color: var(--text-2);
}

.sheet__content {
  display: grid;
  gap: var(--s-4);
  margin-top: var(--s-4);
}

.sheet__content:empty {
  display: none;
}

.sheet__actions {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  margin-top: var(--s-6);
}

/* --- Message temporaire -------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + var(--safe-bottom));
  z-index: 100;
  max-width: calc(100% - 2 * var(--gutter));
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-btn);
  background: var(--surface-3);
  font-size: var(--fs-base);
  transform: translateX(-50%);
  animation: toast-in var(--t-med) var(--ease);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

/* --- État vide ----------------------------------------------------------- */

.empty {
  padding: var(--s-10) 0;
  color: var(--text-2);
  text-align: center;
}

.empty__title {
  color: var(--text);
  font-weight: 500;
}
