/* ==========================================================================
   ONESHOT — Design system
   Direction : "carnet de route au crépuscule". Un journal de voyage feuilleté
   le soir au coin du feu : fond bordeaux presque noir, pages crème, lueur
   de braise pour les actions. Grain de pellicule en fond, cartes façon
   polaroid punaisées, barre de nav comme un onglet de cuir tanné.
   ========================================================================== */

:root {
    /* --- Palette --- */
    --ink:            #180a0c;   /* fond, presque noir, nuance bordeaux */
    --wine:           #5c1420;   /* bordeaux profond — surfaces, gradients */
    --wine-deep:      #3a0c14;   /* bordeaux le plus sombre — ombres, profondeur */
    --wine-soft:      #7a2230;   /* bordeaux plus clair — bordures, hover */
    --cream:          #f3e8d6;   /* crème — texte clair, cartes */
    --cream-dim:      #d9c6a8;   /* crème atténué — texte secondaire sur fond sombre */
    --ember:          #e2632f;   /* braise — accent principal, CTA */
    --ember-dim:      #b8481f;   /* braise foncée — hover/active */
    --gold:           #c79a4b;   /* or fumé — petites touches, badges */
    --ok:             #7ea87a;   /* vert doux pour les soldes positifs (dépenses, futur module) */
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    height: 100%;
    overscroll-behavior: none;
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, sans-serif;
    background: var(--ink);
    color: var(--cream);
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    position: relative;
}

/* Grain de pellicule + vignette ambiante sur toute l'app, discret et constant */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 999;
    pointer-events: none;
    opacity: 0.05;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 998;
    pointer-events: none;
    background: radial-gradient(ellipse at 50% 0%, transparent 40%, rgba(10, 4, 5, 0.55) 100%);
}

button, input { font-family: inherit; }
button { border: none; background: none; cursor: pointer; color: inherit; }
a { text-decoration: none; color: inherit; }
img { display: block; max-width: 100%; }

::selection { background: var(--ember); color: var(--cream); }

/* ==========================================================================
   AUTHENTIFICATION (login / register)
   ========================================================================== */

.login-wrapper {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    padding-top: calc(24px + env(safe-area-inset-top));
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    background:
        radial-gradient(ellipse 900px 600px at 50% -10%, var(--wine-soft) 0%, transparent 60%),
        linear-gradient(185deg, var(--wine-deep) 0%, var(--ink) 55%);
}

.login-box {
    width: 100%;
    max-width: 400px;
    background: var(--cream);
    color: var(--wine-deep);
    border-radius: 28px;
    padding: 44px 32px 36px;
    position: relative;
    box-shadow:
        0 30px 60px -20px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.04);
}

/* petit détail "carnet" : un fil de reliure en haut de la carte */
.login-box::before {
    content: "";
    position: absolute;
    top: 0; left: 50%;
    transform: translateX(-50%);
    width: 46px; height: 5px;
    border-radius: 0 0 6px 6px;
    background: var(--ember);
}

.snap-badge {
    display: inline-block;
    font-family: 'Syne', sans-serif;
    font-weight: 800;
    font-size: 13px;
    letter-spacing: 0.16em;
    color: var(--cream);
    background: var(--wine);
    padding: 6px 14px;
    border-radius: 100px;
    margin-bottom: 20px;
}

.login-box h1 {
    font-family: 'Syne', sans-serif;
    font-weight: 800;
    font-size: 34px;
    line-height: 1.05;
    letter-spacing: -0.01em;
    color: var(--wine-deep);
    margin-bottom: 8px;
}

.auth-desc {
    font-size: 15px;
    color: #8a6a5c;
    margin-bottom: 28px;
}

.error-msg {
    background: rgba(226, 99, 47, 0.12);
    border: 1px solid rgba(226, 99, 47, 0.35);
    color: var(--ember-dim);
    font-size: 14px;
    font-weight: 600;
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 20px;
}

form { display: flex; flex-direction: column; gap: 12px; }

.snap-input {
    width: 100%;
    padding: 16px 18px;
    border-radius: 14px;
    border: 1.5px solid rgba(58, 12, 20, 0.12);
    background: rgba(58, 12, 20, 0.03);
    color: var(--wine-deep);
    font-size: 15.5px;
    font-weight: 500;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.snap-input::placeholder { color: #a98d7d; }

.snap-input:focus {
    outline: none;
    border-color: var(--ember);
    background: #fff;
}

.snap-btn {
    margin-top: 8px;
    padding: 17px;
    border-radius: 14px;
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    font-size: 14.5px;
    letter-spacing: 0.06em;
    text-align: center;
}

.snap-btn.primary {
    background: linear-gradient(180deg, var(--ember) 0%, var(--ember-dim) 100%);
    color: var(--cream);
    box-shadow: 0 12px 24px -8px rgba(226, 99, 47, 0.55);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.snap-btn.primary:active {
    transform: translateY(1px) scale(0.99);
    box-shadow: 0 6px 14px -6px rgba(226, 99, 47, 0.5);
}

.toggle-auth {
    display: block;
    text-align: center;
    margin-top: 24px;
    font-size: 14px;
    color: #9a7c6c;
}

.toggle-auth strong { color: var(--wine); font-weight: 700; }

/* ==========================================================================
   APP SHELL
   ========================================================================== */

.app-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 50;
    height: 56px;
    padding-top: env(safe-area-inset-top);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 18px;
    padding-right: 14px;
    background: linear-gradient(180deg, rgba(24, 10, 12, 0.92) 0%, rgba(24, 10, 12, 0.65) 70%, transparent 100%);
}

.logo {
    position: absolute;
    left: 50%;
    top: calc(env(safe-area-inset-top) + 28px);
    transform: translate(-50%, -50%);
    font-family: 'Syne', sans-serif;
    font-weight: 800;
    font-size: 15px;
    letter-spacing: 0.12em;
    color: var(--cream);
}

.logo .dot { color: var(--ember); }

.user-badge {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--cream-dim);
    background: rgba(255, 255, 255, 0.06);
    padding: 7px 12px 7px 10px;
    border-radius: 100px;
    backdrop-filter: blur(6px);
}

.user-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--ember);
    box-shadow: 0 0 0 3px rgba(226, 99, 47, 0.2);
}

.btn-logout {
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    color: var(--cream-dim);
    background: rgba(255, 255, 255, 0.06);
    transition: background 0.2s ease, color 0.2s ease;
}
.btn-logout:active { background: rgba(226, 99, 47, 0.25); color: var(--cream); }

.views-wrapper {
    position: relative;
    height: 100vh;
    height: 100dvh;
}

.view {
    position: absolute;
    inset: 0;
    z-index: 1; /* contient les z-index internes de Leaflet (700+) dans ce contexte */
    display: none;
    opacity: 0;
}

.view.active {
    display: block;
    opacity: 1;
    animation: viewIn 0.35s ease;
}

@keyframes viewIn {
    from { opacity: 0; transform: scale(1.01); }
    to   { opacity: 1; transform: scale(1); }
}

/* ==========================================================================
   CARTE
   ========================================================================== */

#mapView { background: var(--ink); }
#map { width: 100%; height: 100%; }

.map-hint {
    position: absolute;
    bottom: calc(100px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    z-index: 401;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--cream-dim);
    background: rgba(24, 10, 12, 0.75);
    backdrop-filter: blur(8px);
    padding: 9px 16px;
    border-radius: 100px;
    white-space: nowrap;
    pointer-events: none;
}

.custom-snap-marker { filter: drop-shadow(0 4px 10px rgba(0,0,0,0.5)); }

.snap-marker-pin {
    width: 44px; height: 44px;
    border-radius: 50% 50% 50% 4px;
    transform: rotate(45deg);
    border: 3px solid var(--cream);
    background: var(--wine);
    overflow: hidden;
}
.snap-marker-pin img {
    width: 100%; height: 100%;
    object-fit: cover;
    transform: rotate(-45deg) scale(1.55);
}

.leaflet-popup-content-wrapper {
    background: var(--cream);
    color: var(--wine-deep);
    border-radius: 16px;
}
.leaflet-popup-tip { background: var(--cream); }

/* ==========================================================================
   CAMÉRA
   ========================================================================== */

#cameraView {
    background: #000;
    overflow: hidden;
}

#webcam {
    width: 100%; height: 100%;
    object-fit: cover;
}

/* Mode PWA standalone : pas de flux live (voir app.js), on affiche
   une invitation chaleureuse à ouvrir l'appareil photo natif à la place */
#cameraView.standalone-mode {
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse 700px 500px at 50% 30%, var(--wine-soft) 0%, transparent 65%),
        linear-gradient(190deg, var(--wine-deep), var(--ink) 60%);
}

#cameraView.standalone-mode::before {
    content: "Prêt quand tu l'es";
    position: absolute;
    top: 42%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Syne', sans-serif;
    font-weight: 800;
    font-size: 22px;
    color: var(--cream);
    text-align: center;
    width: 80%;
}

#cameraView.standalone-mode::after {
    content: "Appuie sur le déclencheur pour ouvrir l'appareil photo";
    position: absolute;
    top: 42%;
    margin-top: 34px;
    left: 50%;
    transform: translate(-50%, 0);
    font-size: 13.5px;
    color: var(--cream-dim);
    text-align: center;
    width: 70%;
}

.camera-controls {
    position: absolute;
    bottom: calc(112px + env(safe-area-inset-bottom));
    left: 0; right: 0;
    display: flex;
    justify-content: center;
    z-index: 20;
}

.snap-trigger {
    width: 78px; height: 78px;
    border-radius: 50%;
    background: rgba(243, 232, 214, 0.14);
    backdrop-filter: blur(4px);
    border: 2.5px solid rgba(243, 232, 214, 0.55);
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.12s ease;
}
.snap-trigger:active { transform: scale(0.92); }

.snap-ring {
    width: 60px; height: 60px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, var(--ember) 0%, var(--ember-dim) 75%);
    box-shadow: 0 4px 16px rgba(226, 99, 47, 0.5);
}

.post-overlay {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    background: var(--ink);
}

/* Plein écran pendant la review d'une photo : le header et la nav du bas
   passeraient au-dessus de la barre de légende sinon (contexte d'empilement
   propre à chaque vue), donc on les retire complètement le temps de la review */
body.is-previewing .app-header,
body.is-previewing .bottom-nav {
    display: none;
}

.post-overlay img {
    flex: 1;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.caption-bar {
    position: absolute;
    left: 16px; right: 16px;
    bottom: calc(28px + env(safe-area-inset-bottom));
    display: flex;
    gap: 10px;
    align-items: center;
}

.caption-input {
    flex: 1;
    padding: 15px 18px;
    border-radius: 100px;
    border: 1px solid rgba(243, 232, 214, 0.25);
    background: rgba(24, 10, 12, 0.65);
    backdrop-filter: blur(10px);
    color: var(--cream);
    font-size: 15px;
    font-weight: 500;
}
.caption-input::placeholder { color: rgba(243, 232, 214, 0.45); }
.caption-input:focus { outline: none; border-color: var(--ember); }

.send-btn {
    width: 50px; height: 50px;
    flex-shrink: 0;
    border-radius: 50%;
    background: linear-gradient(180deg, var(--ember), var(--ember-dim));
    display: flex; align-items: center; justify-content: center;
    color: var(--cream);
    box-shadow: 0 8px 18px -6px rgba(226, 99, 47, 0.65);
}
.send-btn:active { transform: scale(0.93); }

.cancel-btn {
    position: absolute;
    top: calc(18px + env(safe-area-inset-top));
    left: 18px;
    z-index: 31;
    font-size: 13.5px;
    font-weight: 700;
    letter-spacing: 0.03em;
    color: var(--cream);
    background: rgba(24, 10, 12, 0.55);
    backdrop-filter: blur(8px);
    padding: 10px 18px;
    border-radius: 100px;
}

/* ==========================================================================
   GALERIE
   ========================================================================== */

#galleryView {
    background: var(--ink);
    height: 100%;
    overflow-y: auto;
    padding: calc(72px + env(safe-area-inset-top)) 18px calc(120px + env(safe-area-inset-bottom));
}

.gallery-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 18px;
}

.gallery-header h2 {
    font-family: 'Syne', sans-serif;
    font-weight: 800;
    font-size: 22px;
    letter-spacing: 0.02em;
    color: var(--cream);
}

.count-badge {
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--cream-dim);
}

.storage-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 18px;
    padding: 16px 18px;
    margin-bottom: 24px;
}

.storage-info {
    display: flex;
    justify-content: space-between;
    font-size: 12.5px;
    color: var(--cream-dim);
    margin-bottom: 10px;
}

.storage-val { color: var(--cream); font-weight: 700; }

.storage-bar-bg {
    height: 7px;
    border-radius: 100px;
    background: rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

.storage-bar-fill {
    height: 100%;
    border-radius: 100px;
    background: linear-gradient(90deg, var(--gold) 0%, var(--ember) 55%, var(--wine-soft) 100%);
    transition: width 0.5s ease;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

.grid-card {
    background: var(--cream);
    border-radius: 14px;
    padding: 8px 8px 12px;
    box-shadow: 0 10px 22px -10px rgba(0, 0, 0, 0.6);
    transition: transform 0.15s ease;
}
.grid-card:nth-child(odd)  { transform: rotate(-1.2deg); }
.grid-card:nth-child(even) { transform: rotate(1deg); }
.grid-card:active { transform: scale(0.97) rotate(0deg); }

.img-wrap {
    aspect-ratio: 1 / 1.05;
    border-radius: 9px;
    overflow: hidden;
    margin-bottom: 9px;
    background: var(--wine-deep);
}
.img-wrap img { width: 100%; height: 100%; object-fit: cover; }

.grid-card .info { padding: 0 3px; }

.grid-card .author {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ember-dim);
    margin-bottom: 2px;
}

.grid-card .caption {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--wine-deep);
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ==========================================================================
   NAVIGATION BASSE
   ========================================================================== */

.bottom-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 40;
    padding: 0 18px calc(14px + env(safe-area-inset-bottom));
    padding-top: 14px;
    background: linear-gradient(0deg, rgba(24, 10, 12, 0.95) 0%, rgba(24, 10, 12, 0.7) 75%, transparent 100%);
}

.nav-container {
    display: flex;
    justify-content: space-around;
    background: rgba(243, 232, 214, 0.08);
    border: 1px solid rgba(243, 232, 214, 0.1);
    backdrop-filter: blur(14px);
    border-radius: 100px;
    padding: 7px;
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 9px 0 8px;
    border-radius: 100px;
    color: var(--cream-dim);
    transition: background 0.2s ease, color 0.2s ease;
}

.nav-btn span {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.03em;
}

.nav-btn.active {
    color: var(--ink);
    background: linear-gradient(180deg, var(--cream), #e8d9bf);
}

/* ==========================================================================
   MODALE PLEIN ÉCRAN
   ========================================================================== */

.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(10, 4, 5, 0.9);
    backdrop-filter: blur(6px);
}

.modal.active { display: flex; }

.preview-box {
    position: relative;
    max-width: 480px;
    width: 100%;
    background: var(--cream);
    border-radius: 20px;
    overflow: hidden;
}

.preview-box img { width: 100%; max-height: 70vh; object-fit: contain; background: #000; }

.preview-close {
    position: absolute;
    top: 12px; right: 12px;
    width: 32px; height: 32px;
    border-radius: 50%;
    background: rgba(24, 10, 12, 0.55);
    color: var(--cream);
    font-size: 20px;
    line-height: 1;
    display: flex; align-items: center; justify-content: center;
}

.preview-meta { padding: 16px 18px 20px; color: var(--wine-deep); }
.preview-meta .author {
    display: block;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ember-dim);
    margin-bottom: 4px;
}
.preview-meta .caption { font-size: 14.5px; line-height: 1.45; }

/* ==========================================================================
   ACCESSIBILITÉ / CONFORT
   ========================================================================== */

button:focus-visible, input:focus-visible, a:focus-visible {
    outline: 2px solid var(--ember);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .view.active { animation: none; }
    * { transition-duration: 0.01ms !important; }
}