/* ============================================ */
/* CIV Map — Styles globaux                     */
/* Architecture : reset → tokens → layout →     */
/*                composants → utilitaires      */
/* ============================================ */

/* ------------------------------------------ */
/* 1. RESET MODERNE                           */
/* ------------------------------------------ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
    overflow: hidden; /* La carte occupe tout l'écran */
    transition: background-color 0.3s ease, color 0.3s ease;
}

img, svg {
    display: block;
    max-width: 100%;
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
}

input {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    outline: none;
}

/* ------------------------------------------ */
/* 2. DESIGN TOKENS (variables CSS)           */
/* ------------------------------------------ */
:root {
    /* Couleurs — thème clair (défaut) */
    --color-bg: #ffffff;
    --color-bg-elevated: #ffffff;
    --color-bg-sunken: #f5f5f7;
    --color-surface: rgba(255, 255, 255, 0.72);
    --color-surface-solid: #ffffff;
    --color-border: rgba(0, 0, 0, 0.08);
    --color-border-strong: rgba(0, 0, 0, 0.14);

    --color-text: #1d1d1f;
    --color-text-secondary: #6e6e73;
    --color-text-tertiary: #86868b;

    --color-primary: #0071e3;       /* Bleu Apple-like */
    --color-primary-hover: #0077ed;
    --color-primary-active: #006edb;
    --color-primary-contrast: #ffffff;

    --color-accent: #34c759;        /* Vert CIV (subtil) */
    --color-danger: #ff3b30;
    --color-warning: #ff9500;

    /* Ombres */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.16);

    /* Rayons */
    --radius-xs: 6px;
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --radius-full: 9999px;

    /* Espacements */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
    --duration-fast: 150ms;
    --duration-normal: 250ms;
    --duration-slow: 400ms;

    /* Z-index */
    --z-map: 1;
    --z-controls: 10;
    --z-header: 100;
    --z-panel: 200;
    --z-modal: 300;
    --z-toast: 400;

    /* Safe areas (iPhone notch) */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

/* Thème sombre */
[data-theme="dark"] {
    --color-bg: #000000;
    --color-bg-elevated: #1c1c1e;
    --color-bg-sunken: #0a0a0a;
    --color-surface: rgba(28, 28, 30, 0.72);
    --color-surface-solid: #1c1c1e;
    --color-border: rgba(255, 255, 255, 0.08);
    --color-border-strong: rgba(255, 255, 255, 0.16);

    --color-text: #f5f5f7;
    --color-text-secondary: #a1a1a6;
    --color-text-tertiary: #6e6e73;

    --color-primary: #0a84ff;
    --color-primary-hover: #409cff;
    --color-primary-active: #0071e3;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
}

/* ------------------------------------------ */
/* 3. LAYOUT APPLICATION                      */
/* ------------------------------------------ */
.app {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ------------------------------------------ */
/* 4. HEADER & BARRE DE RECHERCHE             */
/* ------------------------------------------ */
.app-header {
    position: absolute;
    top: calc(var(--safe-top) + var(--space-3));
    left: var(--space-3);
    right: var(--space-3);
    z-index: var(--z-header);
    pointer-events: none; /* laisse passer les clics vers la carte */
}

.search-bar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    background: var(--color-surface);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-md);
    pointer-events: auto;
    transition: box-shadow var(--duration-normal) var(--ease-out),
                border-color var(--duration-normal) var(--ease-out);
}

.search-bar:focus-within {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-lg), 0 0 0 3px rgba(0, 113, 227, 0.15);
}

.search-icon {
    color: var(--color-text-secondary);
    font-size: 20px;
    flex-shrink: 0;
}

.search-input {
    flex: 1;
    font-size: 15px;
    color: var(--color-text);
}

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

.search-clear {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: var(--radius-full);
    background: var(--color-bg-sunken);
    color: var(--color-text-secondary);
    transition: background var(--duration-fast) var(--ease-out);
}

.search-clear:hover {
    background: var(--color-border-strong);
}

.search-clear .material-symbols-rounded {
    font-size: 14px;
}

/* ------------------------------------------ */
/* 5. CARTE                                   */
/* ------------------------------------------ */
.map {
    position: absolute;
    inset: 0;
    z-index: var(--z-map);
    background: var(--color-bg-sunken);
}

/* ------------------------------------------ */
/* 6. CONTRÔLES FLOTTANTS                     */
/* ------------------------------------------ */
.map-controls {
    position: absolute;
    right: var(--space-3);
    bottom: calc(var(--safe-bottom) + 140px);
    z-index: var(--z-controls);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.control-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-surface-solid);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    color: var(--color-text);
    transition: transform var(--duration-fast) var(--ease-out),
                background var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out);
}

.control-btn:hover {
    background: var(--color-bg-elevated);
    box-shadow: var(--shadow-md);
}

.control-btn:active {
    transform: scale(0.94);
}

.control-btn .material-symbols-rounded {
    font-size: 22px;
}

/* ------------------------------------------ */
/* 7. PANNEAU DE COORDONNÉES                  */
/* ------------------------------------------ */
.coords-panel {
    position: absolute;
    left: var(--space-3);
    bottom: calc(var(--safe-bottom) + var(--space-3));
    z-index: var(--z-controls);
    padding: var(--space-2) var(--space-3);
    background: var(--color-surface);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    font-size: 12px;
    font-family: "SF Mono", Monaco, Consolas, monospace;
    color: var(--color-text-secondary);
    box-shadow: var(--shadow-sm);
    display: flex;
    gap: var(--space-2);
    align-items: center;
}

.coords-label {
    color: var(--color-text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 10px;
}

/* ------------------------------------------ */
/* 8. TOAST                                   */
/* ------------------------------------------ */
.toast-container {
    position: fixed;
    bottom: calc(var(--safe-bottom) + var(--space-5));
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    pointer-events: none;
}

/* ------------------------------------------ */
/* 9. UTILITAIRES & ACCESSIBILITÉ             */
/* ------------------------------------------ */
.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;
}

/* Focus visible accessible */
:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: var(--radius-xs);
}

/* Respect des préférences de mouvement réduit */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ------------------------------------------ */
/* 10. RESPONSIVE — Desktop                   */
/* ------------------------------------------ */
@media (min-width: 768px) {
    .app-header {
        top: calc(var(--safe-top) + var(--space-5));
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: min(520px, calc(100% - var(--space-6)));
    }

    .search-bar {
        padding: var(--space-4) var(--space-5);
    }

    .search-input {
        font-size: 16px;
    }

    .map-controls {
        bottom: var(--space-5);
    }

    .control-btn {
        width: 48px;
        height: 48px;
    }
}

/* ============================================ */
/* AJOUTS ÉTAPE 2                               */
/* Marqueur utilisateur, attribution, toasts,   */
/* animation boussole.                          */
/* ============================================ */

/* ------------------------------------------ */
/* MARQUEUR UTILISATEUR (pulsation)           */
/* ------------------------------------------ */
.user-location-marker {
  background: transparent !important;
  border: none !important;
}

.user-location-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  background: var(--color-primary);
  border: 3px solid #ffffff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 8px rgba(0, 113, 227, 0.4);
}

.user-location-pulse {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  background: var(--color-primary);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  opacity: 0.3;
  animation: pulse 2s ease-out infinite;
}

@keyframes pulse {
  0% {
      transform: translate(-50%, -50%) scale(0.3);
      opacity: 0.5;
  }
  100% {
      transform: translate(-50%, -50%) scale(1.2);
      opacity: 0;
  }
}

/* ------------------------------------------ */
/* ATTRIBUTION CUSTOM                         */
/* ------------------------------------------ */
.geonex-attribution {
  background: var(--color-surface);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: 4px 10px;
  font-size: 11px;
  color: var(--color-text-secondary);
  margin: 0 var(--space-3) calc(var(--safe-bottom) + var(--space-3)) 0;
  box-shadow: var(--shadow-xs);
  display: flex;
  gap: 6px;
  align-items: center;
}

.geonex-attribution a {
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out);
}

.geonex-attribution a:hover {
  color: var(--color-primary);
}

.geonex-attribution .sep {
  color: var(--color-border-strong);
}

.geonex-attribution .brand {
  font-weight: 600;
  color: var(--color-primary);
}

/* ------------------------------------------ */
/* TOASTS                                     */
/* ------------------------------------------ */
.toast {
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-solid);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  color: var(--color-text);
  min-width: 240px;
  max-width: 360px;
  text-align: center;
  animation: toast-in 0.3s var(--ease-out);
  pointer-events: auto;
}

.toast--success {
  border-left: 3px solid var(--color-accent);
}

.toast--error {
  border-left: 3px solid var(--color-danger);
}

.toast--info {
  border-left: 3px solid var(--color-primary);
}

.toast--exit {
  animation: toast-out 0.3s var(--ease-in-out) forwards;
}

@keyframes toast-in {
  from {
      opacity: 0;
      transform: translateY(20px) scale(0.95);
  }
  to {
      opacity: 1;
      transform: translateY(0) scale(1);
  }
}

@keyframes toast-out {
  to {
      opacity: 0;
      transform: translateY(-10px) scale(0.95);
  }
}

/* ------------------------------------------ */
/* ANIMATION BOUSSOLE                         */
/* ------------------------------------------ */
.compass-spin .material-symbols-rounded {
  animation: compass-rotate 0.6s var(--ease-out);
}

@keyframes compass-rotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ------------------------------------------ */
/* LEAFLET OVERRIDES                          */
/* ------------------------------------------ */

/* Supprime le zoom control par défaut (on utilise les nôtres) */
.leaflet-control-zoom {
  display: none !important;
}

/* Scale control */
.leaflet-control-scale-line {
  background: var(--color-surface) !important;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--color-border) !important;
  border-top: none !important;
  color: var(--color-text-secondary) !important;
  font-size: 10px !important;
  padding: 2px 6px !important;
  border-radius: 0 0 var(--radius-xs) var(--radius-xs);
}

/* Retire l'attribution Leaflet par défaut (on a la nôtre) */
.leaflet-control-attribution {
  display: none !important;
}