/* ================================================================
   components.css — Composants réutilisables : boutons, inputs,
                    champs de formulaire, spinner
   ================================================================ */

/* ── Boutons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;          /* WCAG 2.5.5 / iOS HIG : cible tactile 44×44 minimum */
  padding: 9px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), opacity var(--transition);
  text-decoration: none;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-ghost {
  background: transparent;
  color: rgba(255,255,255,.9);
  border-color: rgba(255,255,255,.35);
}
.btn-ghost:hover:not(:disabled) {
  background: rgba(255,255,255,.1);
  color: #fff;
}

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-outline:hover:not(:disabled) { background: var(--bg); }

.btn-full { width: 100%; }

/* ── Champs ───────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  position: relative;
  min-width: 0;          /* shrink-friendly dans flex/grid parents */
}

.field label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.field .hint {
  font-size: .75rem;
  font-weight: 400;
  color: var(--text-disabled);
  text-transform: none;
  letter-spacing: 0;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="time"],
input[type="number"] {
  width: 100%;
  max-width: 100%;
  min-width: 0;            /* permet le shrink dans un flex/grid container */
  padding: 10px 13px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .95rem;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

/* iOS Safari : type="date" a une intrinsèque min-content basée sur le placeholder
   et ignore parfois width:100% dans un flex item. Force le sizing explicite. */
input[type="date"],
input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  box-sizing: border-box;
}

input:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(155,39,67,.12); }
input::placeholder { color: var(--text-disabled); }

/* ── Select personnalisé ──────────────────────────────────── */
.custom-select-wrapper {
  width: 100%;
}

.custom-select-trigger {
  width: 100%;
  padding: 10px 36px 10px 13px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .95rem;
  font-family: inherit;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
  overflow: hidden;
}
.custom-select-trigger:focus,
.custom-select-trigger.open {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(155,39,67,.12);
  outline: none;
}
.custom-select-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}
.custom-select-label.placeholder { color: var(--text-disabled); }
.select-chevron {
  flex-shrink: 0;
  color: var(--text-secondary);
  transition: transform var(--transition);
}
.custom-select-trigger.open .select-chevron { transform: rotate(180deg); }

/* ── Liste déroulante partagée (autocomplete + select) ────── */
/* Autocomplete gares : positionnement absolu dans .field */
.field .suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
}

.suggestions {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  list-style: none;
  overflow: hidden;
  max-height: 240px;
  overflow-y: auto;
}

.suggestion-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: .9rem;
  display: flex;
  flex-direction: column;
  gap: 1px;
  border-bottom: 1px solid var(--border);
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover,
.suggestion-item[aria-selected="true"] { background: var(--primary-light); }
.suggestion-item .name { font-weight: 500; color: var(--text-primary); }
.suggestion-item .name mark { background: none; color: var(--primary); font-weight: 700; }

/* ── Champ en rangée ──────────────────────────────────────── */
.field-row {
  display: flex;
  gap: 12px;
}
.field-row .field { flex: 1; }

/* ── Bouton danger ────────────────────────────────────────── */
.btn-danger {
  background: #b91c1c;
  color: #fff;
  border-color: #b91c1c;
}
.btn-danger:hover:not(:disabled) { background: #991b1b; border-color: #991b1b; }

/* ── Skip link (A11y) ─────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -48px;
  left: 8px;
  z-index: 1000;
  background: var(--primary);
  color: #fff;
  padding: 9px 14px;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 600;
  text-decoration: none;
  transition: top .2s;
}
.skip-link:focus,
.skip-link:focus-visible { top: 8px; outline: 2px solid #fff; outline-offset: 2px; }

/* ── Visually hidden (lecteurs d'écran) ───────────────────── */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Toast ────────────────────────────────────────────────── */
.toast-stack {
  position: fixed;
  top: calc(var(--header-h) + 12px);
  right: 16px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  max-width: min(380px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow-lg);
  font-size: .9rem;
  color: var(--text-primary);
  pointer-events: auto;
  opacity: 0;
  transform: translateX(20px);
  transition: opacity .25s ease, transform .25s ease;
}
.toast-visible { opacity: 1; transform: translateX(0); }

.toast-body  { flex: 1; line-height: 1.4; }
.toast-body a { color: var(--primary); font-weight: 600; text-decoration: underline; }

.toast-close {
  background: none;
  border: 0;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-secondary);
  min-width: 32px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.toast-close:hover { color: var(--text-primary); }
.toast-close:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.toast-success { border-left-color: #16a34a; }
.toast-error   { border-left-color: #b91c1c; }
.toast-warning { border-left-color: #ca8a04; }
.toast-info    { border-left-color: #2563eb; }

/* ── Modal (générique : confirm + autres) ─────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1050;
  padding: 16px;
}
.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 22px 24px;
  width: 100%;
  max-width: 460px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

.confirm-modal { max-width: 420px; }
.confirm-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}
.confirm-msg {
  color: var(--text-secondary);
  margin-bottom: 18px;
  font-size: .95rem;
}
.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ── Skeleton loaders ─────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, #eef0f3 25%, #e3e5ea 50%, #eef0f3 75%);
  background-size: 200% 100%;
  animation: skel-shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius);
}
.skeleton-row  { height: 16px; margin: 8px 0; }
.skeleton-card { height: 96px; margin-bottom: 12px; }
.skeleton-card--train { height: 148px; }
.skeleton-card--ref   { height: 112px; }
@keyframes skel-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Spinner ──────────────────────────────────────────────── */
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .65s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
