/* ════════════════════════════════════════════════════════
   components.css — Composants réutilisables
   bus-card, leaderboard, badges, empty, toast, whatsapp-btn,
   modal signalement, autocomplete
   ════════════════════════════════════════════════════════ */

/* ── Bus Card ── */
.bus-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  animation: slideInRight 0.3s ease;
  flex-shrink: 0;
}

.bus-card:hover {
  border-color: var(--border-hover);
  transform: translateX(-2px);
}

.bus-card.selected {
  border-color: var(--orange);
  background: var(--orange-dim);
}

.bus-card-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.bus-badge {
  background: var(--orange);
  color: white;
  font-family: var(--font-head);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.bus-name {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.3;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bus-age {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  flex-shrink: 0;
}

/* Âge avec texte ET couleur (accessibilité) */
.age-fresh  { background: var(--green-dim);  color: var(--green);  }
.age-ok     { background: var(--yellow-dim); color: var(--yellow); }
.age-old    { background: var(--red-dim);    color: var(--red);    }

.bus-position {
  font-size: 12px;
  color: var(--text);
  margin-bottom: var(--space-xs);
}

.bus-reporter {
  font-size: 11px;
  color: var(--muted);
}

/* ── Leaderboard ── */
.lb-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  animation: slideInUp 0.3s ease;
  flex-shrink: 0;
}

.lb-rank {
  font-family: var(--font-head);
  font-size: 16px;
  font-weight: 800;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.lb-rank.gold   { color: #FFD700; }
.lb-rank.silver { color: #C0C0C0; }
.lb-rank.bronze { color: #CD7F32; }
.lb-rank.other  { color: var(--muted); }

.lb-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  background: var(--surface3);
}

.lb-info { flex: 1; min-width: 0; }

.lb-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-zone {
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
}

.lb-score { text-align: right; flex-shrink: 0; }

.lb-count {
  font-family: var(--font-head);
  font-size: 16px;
  font-weight: 700;
  color: var(--orange);
  line-height: 1;
}

.lb-unit { font-size: 10px; color: var(--muted); }

/* ── Badges ── */
.badge-row {
  display: flex;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
  flex-wrap: wrap;
}

.badge {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-weight: 600;
}

.badge-orange { background: var(--orange-dim); color: var(--orange); }
.badge-green  { background: var(--green-dim);  color: var(--green); }
.badge-yellow { background: var(--yellow-dim); color: var(--yellow); }

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl) var(--space-lg);
  color: var(--muted);
  text-align: center;
  gap: var(--space-sm);
}

.empty-icon { font-size: 32px; }
.empty-text { font-size: 13px; line-height: 1.6; }

.empty-action {
  margin-top: var(--space-sm);
  padding: 8px 16px;
  background: var(--orange-dim);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-full);
  color: var(--orange);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.empty-action:hover {
  background: rgba(255, 107, 53, 0.25);
}

/* ── Boutons d'action sidebar / sheet ── */
.whatsapp-btn,
.btn-signaler {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: var(--radius-lg);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  transition: all var(--transition-fast);
  min-height: 44px;
}

.whatsapp-btn {
  background: #25D366;
  color: white;
  box-shadow: var(--shadow-green);
}

.whatsapp-btn:hover {
  background: #20bd5a;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(37, 211, 102, 0.4);
}

.whatsapp-btn:active { transform: translateY(0); }

.btn-signaler {
  background: var(--orange);
  color: white;
  box-shadow: 0 4px 14px rgba(255, 107, 53, 0.3);
}

.btn-signaler:hover {
  background: #e85d20;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(255, 107, 53, 0.45);
}

.btn-signaler:active { transform: translateY(0); }

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  z-index: var(--z-toast);
  pointer-events: none;
  width: 100%;
  max-width: 340px;
  padding: 0 var(--space-lg);
}

@media (min-width: 769px) {
  #toast-container {
    left: auto;
    right: var(--space-lg);
    bottom: var(--space-lg);
    transform: none;
    align-items: flex-end;
  }
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 12px var(--space-lg);
  border-radius: var(--radius-lg);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: all;
  animation: slideInUp 0.3s var(--transition-spring);
  max-width: 100%;
  border: 1px solid;
  backdrop-filter: blur(8px);
}

.toast.success {
  background: rgba(0, 214, 127, 0.15);
  border-color: rgba(0, 214, 127, 0.3);
  color: var(--green);
}

.toast.error {
  background: rgba(255, 71, 87, 0.15);
  border-color: rgba(255, 71, 87, 0.3);
  color: var(--red);
}

.toast.info {
  background: rgba(255, 107, 53, 0.12);
  border-color: rgba(255, 107, 53, 0.25);
  color: var(--orange);
}

.toast-icon    { font-size: 16px; flex-shrink: 0; }
.toast-message { flex: 1; }

.toast-retry {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid currentColor;
  background: none;
  color: inherit;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity var(--transition-fast);
  flex-shrink: 0;
}

.toast-retry:hover { opacity: 1; }

.toast-dismiss {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  opacity: 0.5;
  font-size: 18px;
  line-height: 1;
  transition: opacity var(--transition-fast);
  flex-shrink: 0;
  padding: 0;
}

.toast-dismiss:hover { opacity: 1; }

.toast.removing {
  animation: fadeOut 0.25s ease forwards;
}

@keyframes fadeOut {
  to { opacity: 0; transform: translateY(8px); }
}

/* ── Skeleton loader ── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface2) 0%,
    var(--surface3) 50%,
    var(--surface2) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}


/* ════════════════════════════════════════════════════════
   MODAL SIGNALEMENT
   ════════════════════════════════════════════════════════ */

/* ── Overlay ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(2px);
  z-index: var(--z-modal-overlay, 900);
}

/* ── Conteneur modal ── */
.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: var(--z-modal, 901);
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
  animation: modalSlideIn 0.22s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.modal[hidden] { display: none; }

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translate(-50%, -48%) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* ── Header modal ── */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 0;
}

.modal-title {
  font-family: var(--font-head);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: color var(--transition-fast), background var(--transition-fast);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: var(--text);
  background: var(--surface2);
}

/* ── Formulaire ── */
.modal-form {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.required {
  color: var(--red);
  margin-left: 2px;
}

.form-optional {
  color: var(--muted);
  font-weight: 400;
  text-transform: none;
  font-size: 0.78rem;
  opacity: 0.7;
}

.form-select,
.form-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font-body);
  padding: 11px 14px;
  width: 100%;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
}

/* Flèche select custom */
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='rgba(255,255,255,0.35)' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.form-select option {
  background: var(--surface1);
  color: var(--text);
}

.form-select:focus,
.form-input:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px var(--orange-dim);
}

.form-error {
  font-size: 0.78rem;
  color: var(--red);
  display: block;
  min-height: 1em;
}

/* ── Autocomplete arrêts ── */
.autocomplete-wrapper {
  position: relative;
}

.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 10;
  list-style: none;
  margin: 0;
  padding: 4px;
  background: var(--surface2);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-height: 220px;
  overflow-y: auto;
}

.autocomplete-list[hidden] { display: none; }

.autocomplete-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  font-size: 0.88rem;
  color: var(--text);
}

.autocomplete-item:hover,
.autocomplete-item.is-highlighted {
  background: var(--surface3);
}

.autocomplete-item mark {
  background: none;
  color: var(--orange);
  font-weight: 700;
}

.suggestion-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggestion-lines {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.suggestion-line-badge {
  font-size: 0.68rem;
  font-weight: 700;
  background: var(--orange-dim);
  color: var(--orange);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
}

/* ── Bouton submit modal ── */
.modal-submit-btn {
  background: var(--orange);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-head);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 13px 20px;
  cursor: pointer;
  width: 100%;
  min-height: 48px;
  transition: opacity var(--transition-fast), transform 0.1s;
  margin-top: 4px;
  box-shadow: 0 4px 14px rgba(255, 107, 53, 0.3);
}

.modal-submit-btn:hover:not(:disabled) {
  opacity: 0.9;
  transform: translateY(-1px);
}

.modal-submit-btn:active:not(:disabled) {
  transform: translateY(0);
}

.modal-submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ── Footer liens WA / TG ── */
.modal-footer-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 20px 20px;
  flex-wrap: wrap;
}

.modal-footer-text {
  font-size: 0.75rem;
  color: var(--muted);
  opacity: 0.6;
}

.modal-channel-link {
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color var(--transition-fast);
}

.modal-channel-link:hover { color: var(--text); }

.modal-footer-sep {
  font-size: 0.75rem;
  color: var(--muted);
  opacity: 0.3;
}

/* ════════════════════════════════════════════════════════
   CHAT — FAB, fenêtre, bulles, typing, suggestions
   ════════════════════════════════════════════════════════ */

/* ── FAB ── */
.chat-fab {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--orange);
  color: white;
  border: none;
  font-size: 22px;
  cursor: pointer;
  z-index: calc(var(--z-toast) - 1);
  box-shadow: 0 4px 16px rgba(255, 107, 53, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition-spring), background var(--transition-fast);
}

.chat-fab:hover { transform: scale(1.08); }
.chat-fab--active { background: var(--surface3); }

@media (max-width: 768px) {
  .chat-fab {
    bottom: calc(var(--sheet-peek) + 16px);
    left: 16px;
    width: 46px;
    height: 46px;
    font-size: 20px;
  }
}

/* ── Fenêtre chat ── */
.chat-window {
  position: fixed;
  bottom: 88px;
  left: 24px;
  right: auto;
  width: min(360px, calc(100vw - 48px));
  height: min(520px, calc(100dvh - 120px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  z-index: calc(var(--z-toast) - 2);
  overflow: hidden;
  transform: scale(0.95) translateY(8px);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 0.18s ease;
}

.chat-window--open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

@media (max-width: 768px) {
  .chat-window {
    bottom: calc(var(--sheet-peek) + 68px);
    right: 8px;
    left: 8px;
    width: auto;
    height: min(420px, calc(100dvh - 180px));
  }
}

/* ── Header ── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface2);
}

.chat-header-info  { display: flex; align-items: center; gap: 10px; }
.chat-header-avatar { font-size: 22px; line-height: 1; }

.chat-header-name {
  font-family: var(--font-head);
  font-size: 0.95rem;
  font-weight: 700;
}

.chat-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 1px;
}

.chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status--open       { background: var(--green); }
.status--connecting { background: var(--yellow); animation: pulse-yellow 1s infinite; }
.status--closed     { background: var(--muted); }

@keyframes pulse-yellow {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.chat-status-label { font-size: 0.72rem; color: var(--muted); }

.chat-close-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background var(--transition-fast);
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-close-btn:hover { color: var(--text); background: var(--surface3); }

/* ── Messages ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.chat-msg { display: flex; max-width: 88%; }
.chat-msg--user { align-self: flex-end; }
.chat-msg--bot  { align-self: flex-start; }

.chat-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 0.88rem;
  line-height: 1.55;
  word-break: break-word;
}

.chat-msg--user .chat-bubble {
  background: var(--orange);
  color: white;
  border-bottom-right-radius: var(--radius-sm);
}

.chat-msg--bot .chat-bubble {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: var(--radius-sm);
}

/* ── Typing ── */
.chat-bubble--typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%           { transform: translateY(-5px); opacity: 1; }
}

/* ── Suggestions ── */
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-md);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-suggestions:empty { display: none; }

.chat-suggestion-chip {
  font-size: 0.78rem;
  padding: 5px 11px;
  background: var(--surface2);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-full);
  color: var(--orange);
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--transition-fast), transform 0.1s;
}

.chat-suggestion-chip:hover {
  background: var(--orange-dim);
  transform: translateY(-1px);
}

/* ── Composer ── */
.chat-composer {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-top: 1px solid var(--border);
  background: var(--surface2);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.9rem;
  padding: 9px 16px;
  min-height: 40px;
  -webkit-appearance: none;
  transition: border-color var(--transition-fast);
}

.chat-input::placeholder { color: var(--muted); }
.chat-input:focus { outline: none; border-color: var(--orange); }

.chat-send-btn {
  background: var(--orange);
  border: none;
  border-radius: 50%;
  color: white;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity var(--transition-fast), transform 0.1s;
}

.chat-send-btn:hover:not(:disabled) { opacity: 0.88; transform: scale(1.05); }
.chat-send-btn:disabled { opacity: 0.3; cursor: not-allowed; }


/* ── Responsive mobile : modal → bottom sheet ── */
@media (max-width: 480px) {
  .modal {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 92dvh;
    animation: modalSlideUp 0.25s cubic-bezier(0.34, 1.2, 0.64, 1) both;
  }

  @keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(40px); }
    to   { opacity: 1; transform: translateY(0); }
  }
}