/* =============================================================
   Vigie — composants (boutons pill, badges, champs, dialogues…)
   ============================================================= */

/* ── Boutons : forme pill, 3 variantes (design system) ───────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 10px 22px;
  border: 2px solid transparent;
  border-radius: var(--radius-full);
  font-family: var(--font-web);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  line-height: 1.15;
  text-align: center;
  text-decoration: none;
  /* Un libellé long passe à la ligne plutôt que de déborder sur petit écran. */
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}

.btn:hover {
  text-decoration: none;
}

.btn--sm {
  min-height: 40px;
  padding: 7px 16px;
  font-size: var(--text-sm);
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn--secondary {
  background: transparent;
  border-color: var(--accent);
  color: var(--brand-text);
}

.btn--secondary:hover {
  background: var(--accent-subtle);
}

.btn--ghost {
  background: transparent;
  color: var(--brand-text);
}

.btn--ghost:hover {
  background: var(--accent-subtle);
}

.btn--danger-ghost {
  background: transparent;
  color: var(--danger-text);
}

.btn--danger-ghost:hover,
.btn--danger-ghost.is-confirm {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.btn--icon {
  padding: 8px;
  min-width: 40px;
}

.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.is-busy svg:first-child {
  animation: spin 0.9s linear infinite;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-2);
  transition: background var(--transition-fast), color var(--transition-fast);
}

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

/* ── Badges : capitales espacées (design system) ─────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 4px 10px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  line-height: 1.2;
  text-transform: uppercase;
  white-space: normal;
  overflow-wrap: anywhere;
}

.badge--neutral {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-2);
}

.badge--success {
  background: var(--success-soft);
  border-color: transparent;
  color: var(--success-text);
}

.badge--danger {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--danger-text);
}

.badge--warning {
  background: var(--warning-soft);
  color: var(--warning-text);
}

.badge--info {
  background: var(--info-soft);
  border-color: transparent;
  color: var(--info-text);
}

.badge--new {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.badge--region {
  background: var(--info-soft);
  border-color: transparent;
  color: var(--info-text);
}

.badge--cat {
  background: var(--cat-soft);
  border-color: var(--cat);
  color: var(--cat-text);
}

/* ── Puces de filtre ─────────────────────────────────────────────── */

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

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 38px;
  max-width: 100%;
  padding: 6px 8px 6px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  text-align: left;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.chip:hover {
  border-color: var(--cat, var(--accent));
}

.chip.is-active {
  border-color: var(--cat, var(--accent));
  background: color-mix(in srgb, var(--cat, var(--accent)) 14%, var(--surface));
  color: var(--text-strong);
}

.chip-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--cat);
  flex-shrink: 0;
}

.chip-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

.chip-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 24px;
  padding: 0 7px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
}

.chip.is-active .chip-count {
  background: var(--surface);
  color: var(--text-strong);
}

.chip.is-empty {
  color: var(--text-2);
  border-style: dashed;
}

.chips--compact .chip {
  min-height: 34px;
  padding: 4px 6px 4px 12px;
  font-size: 13px;
}

.chips--compact .chip-count {
  min-width: 24px;
  height: 22px;
}

@media (max-width: 639px) {
  .chip {
    min-height: 36px;
    padding: 5px 6px 5px 12px;
    font-size: 13px;
  }
}

/* ── Champs ──────────────────────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-strong);
}

.field-required {
  color: var(--danger-text);
}

.field-optional {
  font-weight: var(--weight-regular);
  color: var(--text-2);
}

.field-hint {
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
  color: var(--text-2);
}

.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 1.5px solid var(--color-gray-500);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text-strong);
  font-size: var(--text-base);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input::placeholder {
  color: var(--text-2);
  opacity: 0.85;
}

.input:hover {
  border-color: var(--text-2);
}

.input:focus,
.input:focus-visible {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 28%, transparent);
  outline: none;
}

.textarea {
  min-height: 120px;
  resize: vertical;
  line-height: var(--leading-normal);
}

.select-wrap {
  position: relative;
  min-width: 0;
}

.select {
  appearance: none;
  padding-right: 40px;
  cursor: pointer;
  text-overflow: ellipsis;
}

.select-chevron {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-2);
  pointer-events: none;
}

.search {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-2);
  pointer-events: none;
}

.search-input {
  padding-left: 42px;
}

.search-input::-webkit-search-cancel-button {
  cursor: pointer;
}

/* ── Interrupteur ────────────────────────────────────────────────── */

.switch-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding-block: var(--space-3);
}

.switch-row + .switch-row {
  border-top: 1px solid var(--border);
}

.switch-text {
  min-width: 0;
}

.switch-label {
  font-weight: var(--weight-semibold);
  color: var(--text-strong);
  cursor: pointer;
}

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

.switch {
  position: relative;
  flex-shrink: 0;
  width: 48px;
  height: 28px;
  margin-top: 2px;
}

.switch-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}

.switch-input:disabled {
  cursor: not-allowed;
}

.switch-track {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-full);
  background: var(--color-gray-500);
  transition: background var(--transition-fast);
}

.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast);
}

.switch-input:checked + .switch-track {
  background: var(--accent);
}

.switch-input:checked + .switch-track .switch-thumb {
  transform: translateX(20px);
}

.switch-input:focus-visible + .switch-track {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.switch-input:disabled + .switch-track {
  opacity: 0.5;
}

/* ── Choix segmenté ──────────────────────────────────────────────── */

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border: 0;
  border-radius: 14px;
  background: var(--surface-2);
}

.segmented-item {
  flex: 1 1 auto;
  display: flex;
}

.segmented-item input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-item label {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 12px;
  border-radius: 10px;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-2);
  text-align: center;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.segmented-item label:hover {
  color: var(--text-strong);
}

.segmented-item input:checked + label {
  background: var(--surface);
  color: var(--brand-text);
  box-shadow: var(--shadow-sm);
}

.segmented-item input:focus-visible + label {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

/* ── Encadrés ────────────────────────────────────────────────────── */

.callout {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}

.callout-icon {
  margin-top: 1px;
}

.callout-body {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.callout-title {
  font-weight: var(--weight-bold);
  color: var(--text-strong);
}

.callout-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: 4px;
}

.callout--info {
  background: var(--info-soft);
  border-color: color-mix(in srgb, var(--info-text) 22%, transparent);
}

.callout--info .callout-icon {
  color: var(--info-text);
}

.callout--success {
  background: var(--success-soft);
  border-color: color-mix(in srgb, var(--success-text) 22%, transparent);
}

.callout--success .callout-icon {
  color: var(--success-text);
}

.callout--warning {
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning-text) 25%, transparent);
}

.callout--warning .callout-icon {
  color: var(--warning-text);
}

.callout--danger {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger-text) 25%, transparent);
}

.callout--danger .callout-icon {
  color: var(--danger-text);
}

.tips {
  display: grid;
  gap: 4px;
  padding-left: 1.1em;
}

/* ── État vide ───────────────────────────────────────────────────── */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-12) var(--space-4);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-xl);
  text-align: center;
}

.empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-subtle);
  color: var(--brand-text);
}

.empty-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
}

.empty-text {
  max-width: 46ch;
  color: var(--text-2);
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

/* ── Notifications ───────────────────────────────────────────────── */

.toasts {
  position: fixed;
  z-index: 300;
  inset-inline: 16px;
  bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  display: grid;
  gap: var(--space-2);
  justify-items: center;
  pointer-events: none;
}

@media (min-width: 768px) {
  .toasts {
    inset-inline: auto 24px;
    bottom: 24px;
    width: min(420px, calc(100vw - 48px));
  }
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  width: 100%;
  max-width: 480px;
  padding: 12px 8px 12px 16px;
  border-radius: var(--radius-lg);
  background: var(--color-dark-2);
  color: #ffffff;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in 200ms ease-out;
}

:root[data-theme='dark'] .toast {
  background: #3a3a3a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .toast {
    background: #3a3a3a;
  }
}

.toast > svg:first-child {
  margin-top: 2px;
}

.toast--success > svg:first-child {
  color: var(--color-primary-light);
}

.toast--error > svg:first-child {
  color: #f19a9a;
}

.toast--info > svg:first-child {
  color: #9cc6e6;
}

.toast-text {
  flex: 1;
  min-width: 0;
  padding-top: 1px;
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}

.toast-action {
  align-self: center;
  flex-shrink: 0;
  min-height: 32px;
  padding: 4px 12px;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-primary-light);
  font-family: var(--font-web);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  cursor: pointer;
}

.toast-action:hover {
  background: rgba(255, 255, 255, 0.12);
}

.toast .icon-btn {
  width: 32px;
  height: 32px;
  color: #d0d4d8;
}

.toast .icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

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

/* ── Dialogue : fenêtre centrée, feuille sur mobile ──────────────── */

.dialog {
  width: min(640px, calc(100vw - 32px));
  max-width: none;
  max-height: min(88vh, 900px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: var(--radius-2xl);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

.dialog--lg {
  width: min(760px, calc(100vw - 32px));
}

.dialog::backdrop {
  background: var(--overlay);
}

.dialog[open] {
  display: flex;
  animation: dialog-in 180ms ease-out;
}

.dialog-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: inherit;
  min-height: 0;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 20px 16px 12px 24px;
  border-bottom: 1px solid var(--border);
}

.dialog-head-text {
  min-width: 0;
  padding-top: 6px;
}

.dialog-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-extrabold);
  overflow-wrap: anywhere;
}

.dialog-description {
  margin-top: 4px;
  font-size: var(--text-sm);
  color: var(--text-2);
}

.dialog-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 24px;
}

.dialog-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.dialog-foot-start {
  margin-right: auto;
}

@media (max-width: 639px) {
  .dialog,
  .dialog--lg {
    width: 100vw;
    max-height: 92dvh;
    margin: auto 0 0;
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
  }

  .dialog[open] {
    animation: sheet-in 220ms ease-out;
  }

  .dialog-head {
    padding: 16px 12px 12px 16px;
  }

  .dialog-body {
    padding: 16px;
  }

  .dialog-foot {
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .dialog-foot .btn {
    flex: 1 1 auto;
  }

  .dialog-foot .dialog-foot-start {
    flex-basis: 100%;
    order: 3;
  }
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
}

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

/* ── Formulaires ─────────────────────────────────────────────────── */

.form,
.form-stack {
  display: grid;
  gap: var(--space-5);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: var(--space-4);
}

.form-note {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  font-size: var(--text-sm);
  color: var(--text-2);
}

.form-note svg {
  margin-top: 2px;
  color: var(--brand-text);
}

.type-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
  gap: var(--space-2);
}

.type-card {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.type-card:hover {
  border-color: var(--border-strong);
}

.type-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.type-card:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.type-card:has(input:focus-visible) {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.type-card-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--brand-text);
}

.type-card:has(input:checked) .type-card-icon {
  background: var(--surface);
}

.type-card-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.type-card-title {
  font-weight: var(--weight-semibold);
  color: var(--text-strong);
  font-size: var(--text-sm);
}

.type-card-hint {
  font-size: var(--text-xs);
  color: var(--text-2);
}

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

.check-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: 6px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  cursor: pointer;
}

.check-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.check-chip:has(input:checked) {
  border-color: var(--cat);
  background: color-mix(in srgb, var(--cat) 14%, var(--surface));
}

.check-chip:has(input:checked)::after {
  content: '';
  width: 10px;
  height: 6px;
  margin-left: 2px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg) translateY(-2px);
}

.check-chip:has(input:focus-visible) {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.swatch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.swatch label {
  display: block;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--cat);
  cursor: pointer;
  transition: box-shadow var(--transition-fast);
}

.swatch input:checked + label {
  box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--cat);
}

.swatch input:focus-visible + label {
  outline: 2px solid var(--focus);
  outline-offset: 6px;
}

.test-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.preview:empty,
.form-error:empty {
  display: none;
}

.preview-box {
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
}

.preview-title {
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  color: var(--text-strong);
}

.preview-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
  padding-left: 1.1em;
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

/* ── Écran de mot de passe (access.js) ───────────────────────────── */

.gate {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: grid;
  place-items: center;
  padding: var(--space-4);
  overflow-y: auto;
  background: var(--bg);
}

.gate-card {
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  width: min(100%, 27rem);
  padding: 32px 24px;
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  text-align: center;
}

@media (min-width: 640px) {
  .gate-card {
    padding: 40px 36px;
  }
}

.gate-brand {
  display: flex;
  align-items: center;
  margin-bottom: var(--space-3);
}

.gate-brand .header-divider {
  margin-inline: var(--space-4);
}

.gate-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-subtle);
  color: var(--brand-text);
}

.gate-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-extrabold);
  color: var(--text-strong);
}

.gate-text {
  color: var(--text-2);
  text-wrap: pretty;
}

.gate-form {
  display: grid;
  gap: 6px;
  width: 100%;
  margin-top: var(--space-2);
  text-align: left;
}

.gate-row {
  display: flex;
  gap: var(--space-2);
}

.gate-row .input {
  flex: 1;
  min-width: 0;
}

.gate-row .input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.gate-error {
  min-height: 1.5em;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-normal);
  color: var(--danger-text);
}
