:root {
  --lodging: #e8553e;
  --activity: #2e9e5b;
  --restaurant: #f0a830;
  --primary: #e76f3c;
  --primary-dark: #c9542a;
  --accent: #0e7c86;
  --bg: #f6f3ee;
  --card: #ffffff;
  --text: #2b2b2b;
  --muted: #8a8a8a;
  --border: #ece7df;
  --shadow: 0 6px 24px rgba(40,30,20,.10);
  --shadow-sm: 0 2px 8px rgba(40,30,20,.08);
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text); background: var(--bg); overscroll-behavior: none;
}
.hidden { display: none !important; }
button { font-family: inherit; }
img { display: block; }

/* ----------------------------------------------------------------- Login */
.login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #f0a830 0%, #e76f3c 55%, #c9542a 100%); padding: 24px;
}
.login-card {
  background: var(--card); padding: 34px 28px; border-radius: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
  width: 100%; max-width: 360px; text-align: center; display: flex; flex-direction: column; gap: 12px;
}
.login-flag { font-size: 3rem; line-height: 1; }
.login-card h1 { margin: 0; font-size: 1.5rem; }
.login-card p { margin: 0 0 10px; color: var(--muted); font-size: .9rem; }
.login-card input, .login-card button { padding: 13px 15px; border-radius: 12px; font-size: 1rem; }
.login-card input { border: 1px solid var(--border); background: #faf8f5; }
.login-card button { border: none; background: var(--primary); color: #fff; font-weight: 700; cursor: pointer; }
.login-error { color: var(--lodging); font-size: .85rem; min-height: 1em; }

/* ------------------------------------------------------------------ Layout */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.content { flex: 1; position: relative; overflow: hidden; }

.topbar {
  display: flex; align-items: center; gap: 14px; padding: 12px 20px;
  background: var(--card); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm); z-index: 20;
}
.brand { font-weight: 800; font-size: 1.1rem; letter-spacing: -.2px; }
.top-tabs { display: flex; gap: 6px; margin-left: auto; }
.top-tabs .nav-item {
  border: none; background: transparent; padding: 9px 16px; border-radius: 999px;
  cursor: pointer; font-size: .92rem; color: var(--muted); font-weight: 600;
}
.top-tabs .nav-item.active { background: var(--primary); color: #fff; }
.ghost-btn { border: 1px solid var(--border); background: transparent; color: var(--muted);
  padding: 8px 13px; border-radius: 10px; cursor: pointer; }

.tab-panel { display: none; position: absolute; inset: 0; overflow: auto; -webkit-overflow-scrolling: touch; }
.tab-panel.active { display: block; }
#tab-map.tab-panel { overflow: hidden; }

/* Navigation mobile (bottom) */
.bottom-nav { display: none; }
@media (max-width: 760px) {
  .topbar .top-tabs { display: none; }
  .topbar { padding: 10px 16px; }
  .bottom-nav {
    display: flex; background: var(--card); border-top: 1px solid var(--border);
    padding-bottom: var(--safe-bottom); box-shadow: 0 -4px 16px rgba(0,0,0,.06); z-index: 30;
  }
  .bottom-nav .nav-item {
    flex: 1; border: none; background: none; padding: 9px 4px 7px; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: .7rem; color: var(--muted); font-weight: 600;
  }
  .bottom-nav .nav-item .ic { font-size: 1.3rem; }
  .bottom-nav .nav-item.active { color: var(--primary); }
}

/* -------------------------------------------------------------------- Map */
#map { position: absolute; inset: 0; z-index: 1; }
.map-overlay-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 600;
  padding: 12px; display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.map-overlay-top > * { pointer-events: auto; }

.search-wrap { position: relative; max-width: 460px; width: 100%; margin: 0 auto; }
#search-input {
  width: 100%; padding: 13px 16px; border: none; border-radius: 14px; font-size: .95rem;
  box-shadow: var(--shadow); background: var(--card);
}
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow);
  max-height: 60vh; overflow: auto;
}
.search-results .item { display: flex; gap: 10px; padding: 10px; cursor: pointer; align-items: center;
  border-bottom: 1px solid var(--border); }
.search-results .item:last-child { border-bottom: none; }
.search-results .item:active, .search-results .item:hover { background: #faf6f1; }
.search-results .item img { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; flex-shrink: 0; background: #eee; }
.search-results .item .noimg { width: 52px; height: 52px; border-radius: 10px; background: #f0ece5;
  display: flex; align-items: center; justify-content: center; font-size: 1.3rem; flex-shrink: 0; }
.search-results .item .txt { min-width: 0; }
.search-results .item b { display: block; font-size: .9rem; }
.search-results .item small { color: var(--muted); font-size: .76rem; display: block; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.search-results .empty { padding: 14px; color: var(--muted); font-size: .88rem; text-align: center; }

.filters { display: flex; gap: 7px; flex-wrap: wrap; justify-content: center; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: .8rem; font-weight: 600;
  padding: 7px 12px; border-radius: 999px; background: var(--card); cursor: pointer; user-select: none;
  box-shadow: var(--shadow-sm);
}
.chip input { accent-color: var(--primary); }
.chip.lodging    { color: var(--lodging); }
.chip.activity   { color: var(--activity); }
.chip.restaurant { color: var(--restaurant); }
.chip.route      { color: var(--accent); }

.fab {
  position: absolute; right: 18px; bottom: calc(20px + var(--safe-bottom)); z-index: 600;
  width: 58px; height: 58px; border-radius: 50%; border: none; background: var(--primary); color: #fff;
  font-size: 2rem; line-height: 1; cursor: pointer; box-shadow: 0 8px 22px rgba(231,111,60,.5);
  transition: transform .15s;
}
.fab:active { transform: scale(.92); }
.map-adding #map { cursor: crosshair; }
.map-adding .fab { background: var(--lodging); transform: rotate(45deg); }
.add-hint {
  position: absolute; bottom: calc(96px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  z-index: 600; background: var(--text); color: #fff; padding: 11px 18px; border-radius: 999px;
  font-size: .85rem; box-shadow: var(--shadow); max-width: 90%; text-align: center;
}
.route-info {
  position: absolute; bottom: calc(20px + var(--safe-bottom)); left: 50%; transform: translateX(-50%); z-index: 590;
  background: var(--accent); color: #fff; padding: 9px 16px; border-radius: 999px;
  font-size: .85rem; font-weight: 600; box-shadow: var(--shadow);
}

/* Marqueurs */
.pin {
  width: 36px; height: 36px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  border: 3px solid #fff; box-shadow: 0 3px 8px rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
}
.pin span { transform: rotate(45deg); font-size: 16px; }
.pin.lodging    { background: var(--lodging); }
.pin.activity   { background: var(--activity); }
.pin.restaurant { background: var(--restaurant); }
.pin.search     { background: var(--accent); animation: bounce .6s ease infinite alternate; }
@keyframes bounce { to { transform: rotate(-45deg) translateY(-5px); } }

/* Popup */
.leaflet-popup-content-wrapper { border-radius: 16px; }
.leaflet-popup-content { margin: 0; width: 250px !important; }
.popup { overflow: hidden; border-radius: 16px; }
.popup .gallery { display: flex; gap: 4px; overflow-x: auto; scroll-snap-type: x mandatory; }
.popup .gallery img { width: 100%; height: 150px; object-fit: cover; flex: 0 0 100%; scroll-snap-align: center; }
.popup .body { padding: 12px 14px 14px; }
.popup h3 { margin: 0 0 3px; font-size: 1.05rem; }
.popup .meta { color: var(--muted); font-size: .78rem; margin-bottom: 6px; }
.popup .pay-line { font-size: .82rem; margin: 4px 0; }
.popup .pay-line .ok { color: var(--activity); font-weight: 600; }
.popup .pay-line .todo { color: var(--lodging); font-weight: 600; }
.popup p { margin: 6px 0; font-size: .86rem; }
.popup .actions { display: flex; gap: 7px; margin-top: 10px; flex-wrap: wrap; }
.popup a.link-btn { text-decoration: none; background: var(--primary); color: #fff; padding: 7px 12px;
  border-radius: 9px; font-size: .8rem; font-weight: 600; }
.popup button { border: 1px solid var(--border); background: #fff; padding: 7px 10px; border-radius: 9px;
  cursor: pointer; font-size: .8rem; }
.popup button.danger { color: var(--lodging); border-color: #f3c8c0; }
.popup button.primary-pop { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.popup .gallery { position: relative; cursor: zoom-in; }
.popup .gallery-count { position: absolute; bottom: 6px; right: 8px; background: rgba(0,0,0,.6); color: #fff;
  font-size: .72rem; padding: 2px 8px; border-radius: 999px; }
.popup p.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Vue agrandie (détail) */
.modal.wide { max-width: 620px; }
.detail-main { width: 100%; height: 300px; object-fit: cover; border-radius: 14px; background: #f0ece5; }
.detail-main.noimg { display: flex; align-items: center; justify-content: center; font-size: 4rem; }
.detail-thumbs { display: flex; gap: 6px; overflow-x: auto; margin-top: 8px; }
.detail-thumbs img { width: 76px; height: 56px; object-fit: cover; border-radius: 8px; cursor: pointer;
  border: 2px solid transparent; flex-shrink: 0; }
.detail-thumbs img.active { border-color: var(--primary); }
.detail h2 { margin: 14px 0 4px; }
.detail-meta { color: var(--muted); font-size: .9rem; margin-bottom: 8px; }
.detail-price { background: var(--primary); color: #fff; padding: 2px 10px; border-radius: 999px;
  font-weight: 700; margin-left: 6px; }
.detail-desc { font-size: .95rem; line-height: 1.5; color: var(--text); }

/* ------------------------------------------------------------- Itineraire */
.panel-head { display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 4px; max-width: 760px; margin: 0 auto; }
.panel-head h2 { margin: 0; font-size: 1.3rem; }
.panel-hint { color: var(--muted); font-size: .8rem; padding: 0 18px 8px; max-width: 760px; margin: 0 auto; }
/* Grille itinéraire (colonnes Matin/Midi/Aprem/Soir/Nuit) */
#tab-itinerary { background: var(--bg); }
.itin-grid { padding: 4px 14px 90px; min-width: max-content; }
.itin-row { display: flex; align-items: stretch; gap: 0; margin-bottom: 8px; }
.itin-row.itin-header {
  position: sticky; top: 0; z-index: 5; margin-bottom: 6px;
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted);
}
.itin-header .icell { background: var(--bg); box-shadow: none; align-items: center; padding: 6px 10px; }
.itin-row .icell {
  width: 158px; flex: 0 0 158px; background: var(--card); box-shadow: var(--shadow-sm);
  padding: 10px; border-radius: 12px; margin-right: 6px; display: flex; flex-direction: column;
}
.itin-row .icell.slot { cursor: pointer; }
.itin-row .icell.slot:hover { background: #fbf7f1; }
.itin-row .day-cell {
  width: 120px; flex: 0 0 120px; position: sticky; left: 0; z-index: 4;
  border-left: 6px solid var(--bc, var(--accent)); gap: 2px;
}
.itin-header .day-cell { position: sticky; left: 0; z-index: 6; }
.dc-line { display: flex; align-items: center; justify-content: space-between; }
.day-num { background: var(--bc, var(--primary)); color: #fff; font-weight: 700; font-size: .72rem;
  padding: 2px 8px; border-radius: 999px; }
.dc-handle { cursor: grab; color: #bbb; font-size: 1.1rem; touch-action: none; }
.dc-date { font-weight: 700; font-size: .86rem; text-transform: capitalize; cursor: pointer; margin-top: 4px; color: var(--bc); }
.dc-loc { font-size: .78rem; color: var(--text); }
.dc-drive { font-size: .72rem; color: var(--muted); margin-top: 2px; }
.dc-edit { margin-top: auto; align-self: flex-start; border: none; background: #f3efe9; border-radius: 8px;
  padding: 3px 9px; cursor: pointer; font-size: .8rem; }
.chip-stack { display: flex; flex-direction: column; gap: 5px; }
.chip-act { background: #f6f2ec; border: 1px solid var(--border); border-radius: 9px; padding: 6px 8px;
  font-size: .8rem; line-height: 1.25; }
.chip-act.linked { cursor: pointer; background: #eaf6f4; border-color: #bfe3df; color: #0c5c64; font-weight: 600; }
.chip-act.linked:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.cell-empty { color: #cfc7bb; font-size: 1.1rem; margin: auto; }

/* Surbrillance des marqueurs (lieux du jour) */
.pin.hl { animation: pulse 1s ease infinite; box-shadow: 0 0 0 4px rgba(231,111,60,.5), 0 3px 8px rgba(0,0,0,.4); z-index: 1000; }
@keyframes pulse { 0%,100% { transform: rotate(-45deg) scale(1); } 50% { transform: rotate(-45deg) scale(1.25); } }
.day-toast {
  position: absolute; bottom: calc(20px + var(--safe-bottom)); left: 50%; transform: translate(-50%, 20px);
  z-index: 700; background: var(--text); color: #fff; padding: 11px 18px; border-radius: 999px;
  font-size: .88rem; font-weight: 600; box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; max-width: 90%; text-align: center;
}
.day-toast.show { opacity: 1; transform: translate(-50%, 0); }
.nuit-tag { display: flex; flex-direction: column; gap: 5px; font-size: .82rem; font-weight: 600; }
.nuit-tag img { width: 100%; height: 60px; object-fit: cover; border-radius: 8px; }
.nuit-cell { border-top: 3px solid var(--bc, var(--accent)); }

/* ----------------------------------------------------------------- Budget */
.budget-content { padding: 18px 16px 100px; max-width: 720px; margin: 0 auto; }
.budget-hero { background: linear-gradient(135deg, var(--accent), #0a5c64); color: #fff;
  border-radius: 20px; padding: 20px; box-shadow: var(--shadow); }
.budget-hero .total { font-size: 2.2rem; font-weight: 800; line-height: 1; }
.budget-hero .total small { font-size: .9rem; font-weight: 500; opacity: .85; }
.bar { height: 12px; background: rgba(255,255,255,.25); border-radius: 999px; margin: 14px 0 8px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: #ffd24a; border-radius: 999px; }
.budget-hero .bar-legend { display: flex; justify-content: space-between; font-size: .82rem; opacity: .95; }
.budget-cards { display: flex; gap: 10px; margin: 14px 0; }
.budget-cards .c { flex: 1; background: var(--card); border-radius: 14px; padding: 12px; text-align: center;
  box-shadow: var(--shadow-sm); }
.budget-cards .c .lbl { font-size: .74rem; color: var(--muted); }
.budget-cards .c .val { font-size: 1.25rem; font-weight: 800; margin-top: 2px; }
.budget-cards .c .val.paid { color: var(--activity); }
.budget-cards .c .val.todo { color: var(--lodging); }

.budget-section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); margin: 18px 4px 8px; font-weight: 700; }
.bline { display: grid; align-items: center; gap: 8px;
  grid-template-columns: 34px minmax(0,1fr) 58px 58px 64px 26px;
  background: var(--card); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow-sm); margin-bottom: 6px; }
.bline .bicon { width: 34px; height: 34px; border-radius: 9px; background: #f3efe9;
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem; }
.bline .binfo { min-width: 0; }
.bline .binfo b { font-size: .9rem; }
.bline .binfo small { display: block; color: var(--muted); font-size: .74rem; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.bline .bnum { text-align: right; white-space: nowrap; font-size: .85rem; font-variant-numeric: tabular-nums; }
.bline .bnum.paid { color: var(--activity); }
.bline .bnum.rest.ok { color: var(--activity); }
.bline .bnum.rest.todo { color: var(--lodging); font-weight: 700; }
.bline .bedit { border: none; background: none; cursor: pointer; font-size: .95rem; opacity: .5; padding: 2px; }
.bline .bedit:hover { opacity: 1; }
.bline.bhead { background: transparent; box-shadow: none; padding: 2px 12px; margin-bottom: 2px;
  font-size: .68rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 700; }
.bline.bhead .bnum { font-weight: 700; }
.add-expense-btn { width: 100%; margin-top: 12px; padding: 13px; border-radius: 14px; border: 2px dashed var(--border);
  background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; }

/* ------------------------------------------------------------- Boutons communs */
.primary-btn { border: none; background: var(--primary); color: #fff; padding: 11px 18px; border-radius: 12px;
  font-weight: 700; cursor: pointer; font-size: .92rem; box-shadow: var(--shadow-sm); }
.primary-btn.small { padding: 9px 14px; font-size: .85rem; }

/* ------------------------------------------------------------------ Modale */
.modal-overlay { position: fixed; inset: 0; background: rgba(20,15,10,.5); z-index: 2000;
  display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--card); border-radius: 20px; padding: 22px; width: 100%; max-width: 440px;
  max-height: 92vh; overflow: auto; box-shadow: 0 24px 60px rgba(0,0,0,.3); }
.modal h2 { margin: 0 0 16px; font-size: 1.25rem; }
.modal label { display: block; font-size: .8rem; color: var(--muted); margin: 12px 0 5px; font-weight: 600; }
.modal input, .modal textarea, .modal select {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 11px; font-size: .95rem;
  font-family: inherit; background: #faf8f5; }
.modal textarea { resize: vertical; min-height: 56px; }
.modal .row { display: flex; gap: 10px; }
.modal .row > div { flex: 1; }
.modal .field-hint { font-size: .74rem; color: var(--muted); margin-top: 4px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions button { flex: 1; padding: 13px; border-radius: 12px; border: none; cursor: pointer;
  font-weight: 700; font-size: .95rem; }
.modal-actions .save { background: var(--primary); color: #fff; }
.modal-actions .cancel { background: #f0ece5; color: var(--text); }
.modal-actions .del { background: #fde2dd; color: var(--lodging); flex: 0 0 auto; }

/* Gestion des photos dans le formulaire */
.photo-manager { margin-top: 6px; }
.photo-thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.photo-thumbs .pt { position: relative; width: 72px; height: 56px; border-radius: 9px; overflow: hidden; }
.photo-thumbs .pt img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumbs .pt .rm { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.6); color: #fff;
  border: none; border-radius: 50%; width: 20px; height: 20px; cursor: pointer; font-size: .8rem; line-height: 1; }
.photo-empty { font-size: .8rem; color: var(--muted); padding: 6px 0; }
.candidates { display: flex; gap: 6px; overflow-x: auto; margin-top: 8px; padding-bottom: 4px; }
.candidates .cand { width: 84px; height: 60px; border-radius: 9px; overflow: hidden; flex-shrink: 0;
  cursor: pointer; border: 2px solid transparent; position: relative; }
.candidates .cand img { width: 100%; height: 100%; object-fit: cover; }
.candidates .cand.added { border-color: var(--activity); }
.candidates .cand.added::after { content: "✓"; position: absolute; inset: 0; background: rgba(46,158,91,.55);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; font-weight: 800; }
.inline-btn { margin-top: 8px; padding: 9px 13px; border: 1px solid var(--border); background: #faf8f5;
  border-radius: 10px; cursor: pointer; font-size: .85rem; font-weight: 600; }

/* Éditeur d'activités (créneaux du jour) */
.act-list { display: flex; flex-direction: column; gap: 6px; }
.act-row { display: flex; gap: 6px; align-items: center; }
.act-row .act-input { flex: 1; }
.act-rm { flex: 0 0 auto; width: 36px; height: 38px; border: 1px solid var(--border); background: #fbeeeb;
  color: var(--lodging); border-radius: 10px; cursor: pointer; font-size: 1.2rem; line-height: 1; }
.act-add { margin: 6px 0 4px; padding: 7px 12px; border: 1px dashed var(--accent); background: #eaf6f4;
  color: var(--accent); border-radius: 10px; cursor: pointer; font-size: .82rem; font-weight: 700; }

@media (max-width: 760px) {
  .modal { border-radius: 20px 20px 0 0; max-width: 100%; align-self: flex-end; max-height: 94vh; }
  .modal-overlay { align-items: flex-end; padding: 0; }
}
