/* =========================================================================
   TravelHub — stile mobile-first, tema outdoor/montagna, dark + light
   ========================================================================= */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #14202e;
  --text-soft: #5b6b7d;
  --border: #e2e7ee;
  --primary: #2f7d5b;      /* verde bosco */
  --primary-ink: #ffffff;
  --accent: #c2703d;       /* terra/roccia */
  --sky: #3b82c4;
  --danger: #c0392b;
  --warn: #d99a1c;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 10px rgba(20, 32, 46, 0.08);
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f172a;
    --surface: #16202f;
    --surface-2: #1d2a3c;
    --text: #e8eef5;
    --text-soft: #97a6ba;
    --border: #263447;
    --primary: #46a173;
    --accent: #d98a54;
    --sky: #58a5df;
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  --bg: #0f172a; --surface: #16202f; --surface-2: #1d2a3c; --text: #e8eef5;
  --text-soft: #97a6ba; --border: #263447; --primary: #46a173; --accent: #d98a54;
  --sky: #58a5df; --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.2; }
.hidden { display: none !important; }
.muted { color: var(--text-soft); }
.small { font-size: .82rem; }
.center { text-align: center; }

/* ---------- Layout app ---------- */
#app { min-height: 100vh; }
.layout { display: flex; min-height: 100vh; }

/* Sidebar (desktop) */
.sidebar { display: none; }

/* Contenuto */
.content {
  flex: 1;
  padding: 14px 14px calc(var(--nav-h) + var(--safe-b) + 20px);
  max-width: 920px;
  margin: 0 auto;
  width: 100%;
}

/* Header pagina */
.page-header {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 2px 14px;
}
.page-header h1 { font-size: 1.35rem; margin: 0; }
.page-header .sub { font-size: .82rem; color: var(--text-soft); }
.header-actions { margin-left: auto; display: flex; gap: 8px; }

/* ---------- Card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card-tight { padding: 12px; }
.card h2 { font-size: 1.05rem; }
.card h3 { font-size: .95rem; }

.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-soft); margin: 18px 4px 8px; font-weight: 700; }

/* ---------- Bottoni ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 11px 16px; border-radius: var(--radius-sm); font-size: .92rem; font-weight: 600;
  cursor: pointer; min-height: 44px; transition: transform .05s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn-accent { background: var(--accent); color: #fff; border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn-sm { min-height: 36px; padding: 7px 12px; font-size: .84rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 120px; }

/* ---------- Home "Oggi" ---------- */
.today-hero {
  background: linear-gradient(160deg, var(--primary), #1f5540);
  color: #fff; border-radius: var(--radius); padding: 20px 18px;
  box-shadow: var(--shadow); margin-bottom: 16px;
}
.today-hero .trip-name { font-size: .8rem; letter-spacing: .12em; text-transform: uppercase; opacity: .85; }
.today-hero .day-count { font-size: .9rem; opacity: .9; margin-top: 6px; }
.today-hero .day-title { font-size: 1.7rem; font-weight: 800; margin: 4px 0 2px; }
.today-hero .day-date { font-size: .92rem; opacity: .9; }

.pill-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.pill {
  background: rgba(255,255,255,.16); color: #fff; border-radius: 999px;
  padding: 6px 12px; font-size: .82rem; font-weight: 600; display: inline-flex; gap: 6px; align-items: center;
}
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.info-tile { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; }
.info-tile .label { font-size: .72rem; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; }
.info-tile .value { font-size: 1.05rem; font-weight: 700; margin-top: 2px; }

/* Reminder box */
.reminder-box { background: color-mix(in srgb, var(--warn) 16%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--border)); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.reminder-box h3 { color: var(--accent); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.reminder-item { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; }
.reminder-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); margin-top: 7px; flex: none; }

/* Weather */
.weather-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.weather-temp { font-size: 1.6rem; font-weight: 800; }
.weather-meta { font-size: .85rem; color: var(--text-soft); }
.weather-updated { font-size: .72rem; color: var(--text-soft); margin-top: 4px; }

/* ---------- Timeline programma ---------- */
.timeline { position: relative; margin: 6px 0 0; padding-left: 4px; }
.tl-item { display: flex; gap: 12px; padding: 8px 0; align-items: flex-start; }
.tl-time { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 52px; color: var(--primary); font-size: .9rem; }
.tl-body { flex: 1; }
.tl-type { font-size: .72rem; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; }
.tl-icon { font-size: 1.1rem; }

/* ---------- Liste giornate ---------- */
.day-card { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.day-badge { width: 46px; height: 46px; border-radius: 12px; background: var(--surface-2); display: flex; flex-direction: column; align-items: center; justify-content: center; flex: none; }
.day-badge .d { font-size: 1.1rem; font-weight: 800; line-height: 1; }
.day-badge .m { font-size: .62rem; text-transform: uppercase; color: var(--text-soft); }
.day-card .grow { flex: 1; min-width: 0; }
.day-card .title { font-weight: 700; }
.day-card .meta { font-size: .8rem; color: var(--text-soft); display: flex; gap: 8px; flex-wrap: wrap; }
.chip { font-size: .7rem; background: var(--surface-2); padding: 2px 8px; border-radius: 999px; color: var(--text-soft); }
.chip.today { background: var(--primary); color: #fff; }

/* ---------- Box Tyson (cane) ---------- */
.dog-box { border-left: 4px solid var(--accent); background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; }
.dog-box h3 { color: var(--accent); }

/* ---------- Galleria ---------- */
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.gallery.cols-2 { grid-template-columns: repeat(2, 1fr); }
.g-item { position: relative; aspect-ratio: 1; background: var(--surface-2); border-radius: 8px; overflow: hidden; cursor: pointer; }
.g-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.g-item .vbadge { position: absolute; bottom: 4px; right: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: .65rem; padding: 1px 6px; border-radius: 6px; }
.g-item .fav { position: absolute; top: 4px; right: 4px; color: #ffd23f; font-size: .9rem; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.g-item.sel { outline: 3px solid var(--primary); outline-offset: -3px; }

.filter-row { display: flex; gap: 8px; margin-bottom: 12px; overflow-x: auto; padding-bottom: 4px; }
.filter-row .btn { flex: none; }
.filter-row .btn.active { background: var(--primary); color: #fff; border-color: transparent; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.94); z-index: 200; display: flex; flex-direction: column; }
.lightbox .lb-media { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.lightbox img, .lightbox video { max-width: 100%; max-height: 100%; }
.lightbox .lb-bar { display: flex; align-items: center; gap: 10px; padding: 12px calc(12px + env(safe-area-inset-right)) calc(12px + var(--safe-b)) 12px; color: #fff; }
.lightbox .lb-bar .btn { background: rgba(255,255,255,.14); color: #fff; border-color: transparent; }
.lightbox .lb-caption { color: #ddd; font-size: .85rem; flex: 1; }

/* ---------- Upload queue ---------- */
.upload-summary { display: flex; gap: 14px; flex-wrap: wrap; font-weight: 700; margin: 8px 0; }
.upload-summary .ok { color: var(--primary); }
.upload-summary .err { color: var(--danger); }
.upload-list { max-height: 240px; overflow-y: auto; margin-top: 8px; }
.up-item { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: .82rem; border-bottom: 1px solid var(--border); }
.up-item .st { margin-left: auto; font-weight: 700; }
.st-created { color: var(--primary); }
.st-duplicate { color: var(--sky); }
.st-error { color: var(--danger); }
.st-pending { color: var(--text-soft); }
.st-uploading { color: var(--warn); }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 10px 0; }
.progress > div { height: 100%; background: var(--primary); width: 0; transition: width .2s ease; }

/* Dropzone (desktop) */
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 26px; text-align: center; color: var(--text-soft); }
.dropzone.drag { border-color: var(--primary); background: var(--surface-2); }

/* ---------- Mappa ---------- */
/* Altezza reale: viewport dinamica meno topbar+pageheader e bottom-nav+safe-area,
   così la mappa resta interamente visibile e MAI sotto la bottom navigation. */
#map { width: 100%; height: calc(100dvh - var(--nav-h) - var(--safe-b) - env(safe-area-inset-top) - 128px); min-height: 220px; border-radius: var(--radius); overflow: hidden; }
.leaflet-container { background: var(--surface-2); font-family: var(--font); }
.map-num { background: var(--primary); color: #fff; width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.5); }
/* Marker COMPOSITO (stesso punto usato più volte, es. "1/8"): pillola più larga */
.map-num.multi { width: 40px; border-radius: 14px; font-size: .8rem; }
.map-popup .mp-title { font-weight: 700; font-size: .95rem; }
.map-popup .mp-desc { font-size: .82rem; color: var(--text-soft); margin: 4px 0; }
.map-popup .mp-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
/* Map Hub: selettore modalità + cambio giornata */
.map-hub-bar { display: flex; gap: 8px; align-items: center; padding: 8px 2px 10px; flex-wrap: wrap; }
.map-hub-bar .btn.active { background: var(--primary); color: #fff; border-color: transparent; }
.map-hub-bar .day-switch { display: flex; gap: 4px; margin-left: auto; }
.map-hub-bar .day-switch .btn[disabled] { opacity: .4; }
/* Mappa panoramica esperienza (STEP 5.6): legenda minima + toggle discreti (default puliti) */
.map-legend { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-top: 10px; font-size: .82rem; color: var(--text-soft); }
.map-legend .lg-item { display: inline-flex; align-items: center; gap: 6px; }
.map-legend .lg-line { display: inline-block; width: 18px; height: 3px; border-radius: 2px; }
.map-hub-toggles { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.map-hub-toggles .btn.active { border-color: var(--primary); color: var(--primary); font-weight: 600; }
/* Selettore luogo (place picker) */
.place-field { position: relative; }
.place-field .pf-status { margin-top: 6px; color: var(--text-soft); }
.place-field .pf-status.ok { color: var(--primary); }
.place-field .pf-results { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-top: 6px; max-height: 220px; overflow-y: auto; }
.place-field .pf-results:empty { display: none; }
.place-field .pf-item { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--border); }
.place-field .pf-item:last-child { border-bottom: none; }
.place-field .pf-item:active { background: var(--surface-2); }

/* PlacePicker (STEP 4.4): barra modalità + selettore mappa full-screen */
.pp-modes { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.pp-modes .btn { flex: 1 1 auto; }
/* Overlay full-screen: colonna hint · mappa · azioni. I controlli (azioni) NON stanno
   dentro i layer trasformati di Leaflet — restano sempre raggiungibili (come il viewer). */
.pp-overlay { position: fixed; inset: 0; z-index: 3000; display: flex; flex-direction: column; background: var(--bg, #0d0f0e); }
body.pp-open { overflow: hidden; }
.pp-overlay .pp-hint {
  flex: 0 0 auto; padding: calc(10px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 10px calc(12px + env(safe-area-inset-left));
  background: var(--surface, #16302a); color: var(--text, #fff); font-size: .92rem; line-height: 1.35; text-align: center;
}
.pp-overlay .pp-map { flex: 1 1 auto; min-height: 0; width: 100%; }
.pp-overlay .pp-actions {
  flex: 0 0 auto; display: flex; gap: 10px;
  padding: 12px calc(12px + env(safe-area-inset-right)) calc(12px + var(--safe-b)) calc(12px + env(safe-area-inset-left));
  background: var(--surface, #16302a); border-top: 1px solid var(--border);
}
.pp-overlay .pp-actions .btn { flex: 1 1 0; padding: 13px 12px; font-size: 1rem; }
.pp-overlay .pp-actions .btn:disabled { opacity: .5; }

/* Profilo altimetrico */
.elevation { width: 100%; height: 90px; }

/* =========================================================================
   STEP 5 — Programma evoluto + Import da ChatGPT
   ========================================================================= */
.program-actions { display: flex; gap: 8px; align-items: center; margin: 4px 0 14px; flex-wrap: wrap; }
.program-actions .btn-import { flex: 1 1 auto; }
.import-steps { margin: 0 0 12px 1.1rem; padding: 0; color: var(--text-soft); font-size: .9rem; }
.import-steps li { margin: 2px 0; }
.import-area { width: 100%; min-height: 140px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .82rem; }
.import-summary { font-size: .85rem; color: var(--text-soft); background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 10px; margin-bottom: 10px; }
.import-preview { max-height: 46vh; overflow-y: auto; }
.ip-day { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; margin-bottom: 8px; }
.ip-day-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; font-size: .92rem; }
.ip-act { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: .9rem; }
.ip-act .ip-num { color: var(--text-soft); min-width: 1.4em; }
.ip-act .grow, .unpl-row .grow { flex: 1; min-width: 0; }
.ip-upd { display: inline-flex; align-items: center; gap: 4px; font-size: .8rem; color: var(--text-soft); }
.import-result { text-align: center; padding: 10px 0; }
.import-result .ir-check { width: 54px; height: 54px; line-height: 54px; margin: 0 auto 8px; border-radius: 50%; background: color-mix(in srgb, var(--primary) 18%, var(--surface)); color: var(--primary); font-size: 1.7rem; font-weight: 800; }
.import-result .ir-list { list-style: none; padding: 0; margin: 8px 0; color: var(--text-soft); }
.import-result .ir-list .warn { color: #b06a1f; }

/* Tag di stato leggibili (non diff Git) */
.tag { font-size: .68rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.tag-ok { background: color-mix(in srgb, #2f7d5b 18%, var(--surface)); color: #2f7d5b; }
.tag-muted { background: var(--surface-2); color: var(--text-soft); }
.tag-warn { background: color-mix(in srgb, #d1901f 22%, var(--surface)); color: #a9701a; }
.tag-info { background: color-mix(in srgb, #2b7fb3 18%, var(--surface)); color: #2b7fb3; }

/* Da programmare */
.unpl-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.unpl-row:last-child { border-bottom: none; }

/* Import 5.1: warning, localizzazione, modalità */
.ip-warn { font-size: .84rem; background: color-mix(in srgb, #d1901f 16%, var(--surface)); color: #8a5a12; border-radius: var(--radius-sm); padding: 8px 10px; margin-bottom: 6px; }
.ip-warn-strong { background: color-mix(in srgb, #c0392b 14%, var(--surface)); color: #a02a20; }
.ip-localize { background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 10px; margin: 8px 0; }
.ip-mode { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 8px; }
.ip-mode-opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; }
.ip-mode-opt.sel { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 7%, transparent); }
.ip-mode-opt input { margin-top: 3px; }
.ip-rebuild { background: color-mix(in srgb, #c0392b 8%, var(--surface)); border: 1px solid color-mix(in srgb, #c0392b 25%, var(--border)); border-radius: var(--radius-sm); padding: 10px; margin-bottom: 8px; }

/* Nuova esperienza (STEP 5.3) — chooser import/manuale */
.newexp-choice { display: block; text-align: left; padding: 14px 16px; height: auto; min-height: 60px; }
.newexp-choice .ne-t { font-weight: 700; font-size: 1rem; }
.newexp-choice .ne-s { font-size: .82rem; opacity: .85; margin-top: 2px; font-weight: 400; }
.ne-summary { padding: 12px 14px; }
.ne-title { font-weight: 800; font-size: 1.15rem; line-height: 1.15; }

/* Suggerimenti "Da vedere / Da fare" (STEP 5.5) */
.suggestions .sugg-row { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.suggestions .sugg-row:last-child { border-bottom: none; }
.suggestions .sugg-ico { font-size: 1.4rem; line-height: 1.2; flex: none; }
.sugg-toggle { margin-top: 10px; opacity: .75; }
.sugg-toggle.on { opacity: 1; border-color: var(--primary); color: var(--primary); }
.promote-opts { display: flex; flex-direction: column; gap: 6px; }
.promote-opt { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; }

/* STEP 6.1 — Informazioni utili della giornata (card semplici, mai tabella) */
.day-info .info-group-title { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--text-soft); margin: 12px 0 6px; }
.info-card { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 8px; background: var(--surface); }
.info-card .ic-title { display: flex; align-items: baseline; gap: 8px; font-weight: 600; }
.info-card .ic-ico { font-size: 1.1rem; flex: none; }
.info-card .ic-text { margin-top: 3px; font-size: .92rem; }
.info-card .ic-action { margin-top: 6px; font-size: .88rem; background: color-mix(in srgb, #d99a1c 14%, transparent); border-radius: var(--radius-sm); padding: 6px 8px; }
.info-card .ic-meta { margin-top: 6px; font-size: .76rem; color: var(--text-soft); }
.info-card .ic-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
/* action_required: bordo/accento ambra ben visibile ma non allarmistico */
.info-card.info-action { border-color: #d99a1c; border-left-width: 4px; }
.info-card.info-important { border-left: 4px solid var(--primary); }
.info-card.info-critical { border-color: #c0563e; border-left-width: 4px; background: color-mix(in srgb, #c0563e 6%, var(--surface)); }

/* Percorso pianificato (STEP 5.2) — riepilogo tratte sotto la mappa */
.route-panel { margin-top: 12px; }
.route-panel .rp-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.route-panel .rp-from { font-weight: 700; padding: 4px 0; }
.route-panel .rp-leg { border-left: 2px dashed var(--border); margin-left: 6px; padding: 2px 0 2px 12px; }
.route-panel .rp-leg.tappable { cursor: pointer; }
.route-panel .rp-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 2px 0 6px; }
.route-panel .rp-mode { background: var(--surface-2); border: none; border-radius: 999px; padding: 3px 10px; font-size: .8rem; font-weight: 600; color: var(--text); cursor: pointer; }
.route-panel .rp-totals { border-top: 1px solid var(--border); margin-top: 6px; }

/* Editor attività */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.adv-fields { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 6px; }
.prog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tl-admin { display: flex; gap: 6px; margin-top: 8px; }
.btn-xs { font-size: .74rem; padding: 4px 9px; min-height: 0; }

/* ---------- Stat grid ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; text-align: center; }
.stat .n { font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.stat .l { font-size: .74rem; color: var(--text-soft); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + var(--safe-b));
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; padding-bottom: var(--safe-b); z-index: 100;
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--text-soft); font-size: .66rem; font-weight: 600; padding-top: 6px;
  position: relative; text-decoration: none;
}
.bottom-nav a.active { color: var(--primary); }
/* Selezione discreta: piccola barra-accent in cima (niente rettangolo pieno) */
.bottom-nav a.active::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 20px; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary);
}
.bottom-nav .ico svg { width: 24px; height: 24px; }

/* Tab orizzontali giornata: visibili solo su desktop (mobile usa la bottom-nav) */
.day-tabs { display: none; }

/* FAB */
.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + var(--safe-b) + 14px);
  width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: #fff;
  border: none; font-size: 1.7rem; box-shadow: 0 6px 18px rgba(0,0,0,.28); z-index: 101; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* Sheet / modale bottom */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 150; display: flex; align-items: flex-end; }
.sheet { background: var(--surface); width: 100%; border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); max-height: 85vh; overflow-y: auto; }
.sheet h2 { font-size: 1.1rem; }
.sheet .grip { width: 40px; height: 4px; background: var(--border); border-radius: 999px; margin: 0 auto 14px; }
.form-field { margin-bottom: 12px; }
.form-field label { display: block; font-size: .78rem; color: var(--text-soft); margin-bottom: 4px; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: 1rem; font-family: var(--font);
}
textarea { min-height: 80px; resize: vertical; }
/* FIX globale (STEP 5.5.1): radio e checkbox NON devono ereditare width:100%/padding (venivano
   stirati e centrati). Dimensione naturale, allineati a sinistra, con accent del tema. */
input[type="radio"], input[type="checkbox"] {
  width: auto; height: auto; padding: 0; margin: 0; flex: 0 0 auto; accent-color: var(--primary);
}
/* Componente standard di scelta: controllo a sinistra, contenuto a destra, intera riga cliccabile. */
.choice-row { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; min-height: 48px; }
.choice-row input[type="radio"], .choice-row input[type="checkbox"] { width: 18px; height: 18px; }
.choice-row .choice-content { flex: 1; min-width: 0; }
.choice-row .choice-content .ch-sub { font-size: .82rem; color: var(--text-soft); margin-top: 2px; }
.choice-row.sel { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 7%, transparent); }
.choice-row:focus-within { outline: 2px solid var(--primary); outline-offset: 2px; }
.role-selector { display: flex; flex-direction: column; gap: 8px; }

/* STEP 6 — Home → Impostazioni: Utenti, Accessi, Archiviate */
.settings-list { display: flex; flex-direction: column; gap: 10px; }
.settings-row { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; min-height: 64px; }
.settings-row .sr-ico { font-size: 26px; flex: 0 0 auto; }
.settings-row .sr-body { flex: 1; min-width: 0; }
.settings-row .sr-title { font-weight: 700; }
.settings-row .sr-desc { font-size: .84rem; color: var(--text-soft); margin-top: 2px; }
.settings-row .sr-chev { color: var(--text-soft); font-size: 1.2rem; }
.user-list { display: flex; flex-direction: column; gap: 8px; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); text-decoration: none; color: inherit; min-height: 56px; }
.user-row .ur-body { flex: 1; min-width: 0; }
.user-row .ur-name { font-weight: 600; }
.user-row .ur-sub { font-size: .82rem; color: var(--text-soft); margin-top: 2px; }
.user-row .ur-status { font-size: .74rem; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.user-row .ur-status.on { background: color-mix(in srgb, var(--primary) 16%, transparent); color: var(--primary); }
.user-row .ur-status.off { background: color-mix(in srgb, #b0453a 16%, transparent); color: #b0453a; }
.user-row .ur-chev { color: var(--text-soft); }
.access-row .ar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.access-row .ar-title { font-weight: 600; }
.archived-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.archived-row .ar-info { flex: 1; min-width: 0; }
.archived-row .ar-title { font-weight: 600; }
.field { margin-bottom: 10px; }
.field .field-label { display: block; font-size: .82rem; color: var(--text-soft); margin-bottom: 4px; }
/* HOTFIX F — Il mio account / dettaglio utente compatto */
.acc-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.acc-line:last-child { border-bottom: none; }
.acc-line.switch-row { cursor: pointer; min-height: 44px; }
.acc-line.switch-row input[type="checkbox"] { width: 20px; height: 20px; }
.access-compact { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.access-compact:last-child { border-bottom: none; }
.access-compact .ac-title { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.access-compact .ac-actions { display: flex; gap: 6px; flex: none; }
.wikiloc-btn { border-color: #d3722a; color: #d3722a; }

/* Login */
.login-screen { position: fixed; inset: 0; background: linear-gradient(160deg, #1f5540, #0f172a); display: flex; align-items: center; justify-content: center; z-index: 300; padding: 20px; }
.login-card { background: var(--surface); border-radius: var(--radius); padding: 28px 22px; width: 100%; max-width: 360px; box-shadow: 0 10px 40px rgba(0,0,0,.4); }
.login-logo { font-size: 1.6rem; font-weight: 800; text-align: center; }
.login-sub { text-align: center; color: var(--text-soft); margin: 4px 0 20px; }
.login-card input { margin-bottom: 12px; }
.login-error { color: var(--danger); font-size: .85rem; text-align: center; margin-top: 10px; min-height: 20px; }

/* Toast */
.toast { position: fixed; bottom: calc(var(--nav-h) + var(--safe-b) + 80px); left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: .85rem; z-index: 250; box-shadow: var(--shadow); opacity: 0; transition: opacity .2s; }
.toast.show { opacity: 1; }

.empty { text-align: center; color: var(--text-soft); padding: 40px 20px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.offline-banner { background: var(--warn); color: #241a02; text-align: center; font-size: .8rem; padding: 6px; font-weight: 600; }

/* =========================================================================
   HOME GENERALE (Esperienze) + topbar esperienza  [STEP 2]
   Nota: il layout FUNZIONALE interno all'esperienza non cambia; qui si
   aggiunge solo il livello superiore (Home) e una topbar per uscire.
   ========================================================================= */
/* Contesto Home: niente bottom-nav / sidebar / topbar esperienza */
#app[data-context="home"] .bottom-nav,
#app[data-context="home"] .sidebar { display: none; }
.exp-topbar { display: none; }
/* Livello ESPERIENZA: topbar compatta a riga singola */
#app[data-context="exp"] .exp-topbar {
  display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 90;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 10px 14px; min-height: 52px;
}
.exp-topbar .back { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; color: var(--primary); background: none; border: none; font-size: .95rem; cursor: pointer; padding: 6px 4px; flex: none; }
.exp-topbar .tb-head { margin-left: 8px; min-width: 0; flex: 1; }
.exp-topbar .tb-title { font-weight: 700; font-size: .98rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exp-topbar .tb-sub { font-size: .74rem; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exp-topbar .tb-status { flex: none; font-size: .72rem; font-weight: 700; color: var(--primary); background: color-mix(in srgb, var(--primary) 14%, var(--surface)); border-radius: 999px; padding: 4px 10px; }

/* Livello GIORNATA: header a due righe (‹ Programma · titolo+badge · data).
   Un solo comando di ritorno. Titolo lungo su max 2 righe, badge sempre leggibile. */
#app[data-context="day"] .exp-topbar {
  display: grid; grid-template-columns: 1fr auto; column-gap: 12px; row-gap: 2px;
  grid-template-areas: "back back" "head status";
  align-items: start; background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 10px 14px 12px;
}
#app[data-context="day"] .exp-topbar .back { grid-area: back; padding: 2px 2px 4px; }
#app[data-context="day"] .exp-topbar .tb-head { grid-area: head; margin-left: 0; min-width: 0; }
#app[data-context="day"] .exp-topbar .tb-title {
  font-weight: 800; font-size: 1.18rem; line-height: 1.2; white-space: normal;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
#app[data-context="day"] .exp-topbar .tb-sub { font-size: .82rem; white-space: normal; margin-top: 2px; }
#app[data-context="day"] .exp-topbar .tb-status { grid-area: status; align-self: start; margin-top: 3px; white-space: nowrap; }

/* Icona coerente nella shell */
.ico { display: inline-flex; align-items: center; justify-content: center; }
.ico svg { display: block; width: 22px; height: 22px; }
/* Focus visibile per accessibilità */
.bottom-nav a:focus-visible, .day-tabs a:focus-visible, .sidebar a:focus-visible, .exp-topbar .back:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 8px;
}
/* Popup mappa: righe compatte */
.map-popup .mp-line { font-size: .82rem; margin-top: 3px; }

/* Home */
.home { padding-bottom: 40px; }
/* HOTFIX UX D — header Home: titolo a sinistra, azioni utility (Impostazioni/Esci) a destra */
.home-header { padding: 18px 4px 8px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.home-header .hh-title { min-width: 0; }
.home-header h1 { font-size: 1.7rem; font-weight: 800; letter-spacing: -.01em; }
.home-header .sub { color: var(--text-soft); font-size: .9rem; }
.home-actions { display: flex; gap: 6px; flex: none; }
.home-actions .btn { white-space: nowrap; }
.home-newexp { margin: 4px 4px 14px; }
.home-section { margin-top: 22px; }
.home-section > .st { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-soft); font-weight: 700; margin: 0 4px 10px; }

/* Hero esperienza in corso / prossima */
.exp-hero {
  position: relative; border-radius: var(--radius); overflow: hidden; cursor: pointer;
  min-height: 200px; display: flex; flex-direction: column; justify-content: flex-end;
  color: #fff; box-shadow: var(--shadow); background-size: cover; background-position: center;
}
.exp-hero .veil { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,.05) 30%, rgba(0,0,0,.72) 100%); }
.exp-hero .content { position: relative; padding: 18px; }
.exp-hero .kicker { font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; opacity: .95; font-weight: 700; }
.exp-hero .title { font-size: 1.7rem; font-weight: 800; margin: 4px 0 2px; line-height: 1.1; }
.exp-hero .meta { font-size: .9rem; opacity: .95; }
.exp-hero .cta { display: inline-flex; margin-top: 12px; background: rgba(255,255,255,.92); color: #14202e; font-weight: 700; padding: 9px 16px; border-radius: 999px; font-size: .9rem; }
.exp-hero.small { min-height: 130px; }
.exp-hero.small .title { font-size: 1.25rem; }

/* Griglia card esperienze (in programma / ricordi) */
.exp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.exp-card { border-radius: var(--radius-sm); overflow: hidden; cursor: pointer; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.exp-card .cover { height: 96px; background-size: cover; background-position: center; position: relative; }
.exp-card .cover .veil { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,0) 40%, rgba(0,0,0,.5)); }
.exp-card .cover .badge { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,.55); color: #fff; font-size: .68rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; display: inline-flex; gap: 4px; align-items: center; }
.exp-card .body { padding: 10px 12px; }
.exp-card .body .t { font-weight: 700; font-size: .95rem; line-height: 1.15; }
.exp-card .body .d { font-size: .78rem; color: var(--text-soft); margin-top: 2px; }
.exp-card .body .x { font-size: .74rem; color: var(--text-soft); margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; }

/* Bottone nuova esperienza (Home) */
.newexp-row { margin-top: 22px; }
.btn-newexp { width: 100%; border-style: dashed; color: var(--text-soft); font-weight: 700; }

@media (min-width: 860px) {
  .exp-hero { min-height: 260px; }
  .home-header h1 { font-size: 2rem; }
}

/* =========================================================================
   STEP 3 — Upload media (3 azioni + coda) · Viewer full-screen · Galleria
   ========================================================================= */
/* Azioni upload */
.up-actions { display: grid; gap: 8px; margin-bottom: 14px; }
.up-act { justify-content: flex-start; gap: 10px; font-weight: 600; min-height: 48px; }
.up-act .i { font-size: 1.2rem; }
.upload-list { max-height: 46vh; overflow-y: auto; }
.up-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.up-thumb { width: 46px; height: 46px; border-radius: 8px; overflow: hidden; background: var(--surface-2); flex: none; display: flex; align-items: center; justify-content: center; }
.up-thumb img { width: 100%; height: 100%; object-fit: cover; }
.up-thumb .ph { font-size: 1.3rem; }
.up-meta { flex: 1; min-width: 0; }
.up-meta .nm { font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-meta .sz { font-size: .72rem; color: var(--text-soft); }
.up-bar { height: 5px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 5px; }
.up-bar > div { height: 100%; background: var(--primary); width: 0; transition: width .15s ease; }
.st-done { color: var(--primary); font-weight: 700; }
.st-duplicate { color: var(--sky); font-weight: 700; }
.st-error { color: var(--danger); font-weight: 700; }
.st-queued, .st-uploading { color: var(--text-soft); }
/* Indicatore flottante upload in corso */
.upload-indicator { position: fixed; right: 16px; bottom: calc(var(--nav-h) + var(--safe-b) + 78px); z-index: 140; background: var(--primary); color: #fff; border: none; border-radius: 999px; padding: 9px 15px; font-weight: 700; font-size: .82rem; box-shadow: 0 6px 18px rgba(0,0,0,.28); display: flex; align-items: center; gap: 8px; cursor: pointer; }
.upload-indicator .spin { width: 12px; height: 12px; border: 2px solid rgba(255,255,255,.45); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }

/* Galleria (thumbnail grandi, video con play, niente filename) */
.gal-day { font-size: .8rem; font-weight: 700; color: var(--text-soft); margin: 16px 4px 8px; }
.gallery { gap: 3px; }
.g-item .vthumb { width: 100%; height: 100%; background: #121a26; display: flex; align-items: center; justify-content: center; }
.g-item .vthumb .play { color: #fff; font-size: 1rem; background: rgba(0,0,0,.4); width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; padding-left: 3px; }
.g-item .gdoc { display: flex; align-items: center; justify-content: center; height: 100%; font-size: 2rem; }
.g-item .fav { color: #ff5a7a; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
@media (min-width: 860px) { .gallery { gap: 6px; } }

/* Viewer full-screen (stile app Foto) — MEDIA layer separato dai CONTROLLI [STEP 4.2] */
html.viewer-lock, html.viewer-lock body { overflow: hidden; }
.viewer { position: fixed; inset: 0; background: #000; z-index: 300; height: 100vh; height: 100dvh; overflow: hidden; touch-action: none; user-select: none; }
/* Unico layer trasformato (swipe track + zoom img) */
.viewer-track { position: absolute; inset: 0; display: flex; height: 100%; width: 300%; will-change: transform; }
.vslide { width: 33.3333%; height: 100%; flex: none; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.vslide img, .vslide video { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; display: block; will-change: transform; }
.vslide img { -webkit-user-drag: none; }
.vdoc { color: #fff; text-align: center; padding: 20px; }
/* Controlli overlay: SEMPRE ancorati alla viewport (position:fixed), MAI dentro il layer trasformato */
.viewer-back { position: fixed; top: calc(8px + env(safe-area-inset-top)); left: calc(10px + env(safe-area-inset-left)); z-index: 12;
  background: rgba(0,0,0,.45); color: #fff; border: none; border-radius: 999px; padding: 9px 15px; font-size: .95rem; font-weight: 700; cursor: pointer;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.viewer-counter { position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 11; color: #fff; font-size: .92rem; font-weight: 600; text-shadow: 0 1px 3px rgba(0,0,0,.8); pointer-events: none; }
.viewer-actions { position: fixed; top: calc(8px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); z-index: 11; display: flex; gap: 8px; align-items: center; transition: opacity .2s ease; }
.viewer.hide-controls .viewer-actions { opacity: 0; pointer-events: none; }
.viewer-btn { background: rgba(0,0,0,.45); color: #fff; border: none; width: 42px; height: 42px; border-radius: 999px; font-size: 1.35rem; cursor: pointer; display: flex; align-items: center; justify-content: center; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.viewer-btn.fav.on { color: #ff5a7a; }
.viewer-btn.danger { color: #ff8a8a; font-size: 1.5rem; }

/* STEP 4 — azione "Naviga" (contestuale, non una sezione) */
.nav-btn { background: var(--accent); color: #fff; border-color: transparent; }
.nav-opt { justify-content: flex-start; font-weight: 600; }
.nav-always { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: .88rem; color: var(--text-soft); }
.nav-always input { width: auto; }

/* =========================================================================
   DESKTOP (>= 860px): sidebar + dashboard, niente bottom nav
   ========================================================================= */
@media (min-width: 860px) {
  .bottom-nav, .fab { display: none; }
  /* Sidebar ESPERIENZA — alleggerita (non un gestionale): più stretta, highlight discreto */
  .sidebar {
    display: flex; flex-direction: column; width: 212px; flex: none;
    background: var(--surface); border-right: 1px solid var(--border); padding: 16px 10px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
  }
  .sidebar .brand { font-size: 1.05rem; font-weight: 800; letter-spacing: .02em; padding: 4px 10px 16px; color: var(--text); }
  .sidebar a.nav-link { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 9px; color: var(--text-soft); font-weight: 600; margin-bottom: 1px; position: relative; text-decoration: none; }
  .sidebar a.nav-link:hover { background: color-mix(in srgb, var(--primary) 6%, transparent); }
  /* Attivo discreto: accent bar a sinistra, niente rettangolo pieno pesante */
  .sidebar a.nav-link.active { background: transparent; color: var(--primary); }
  .sidebar a.nav-link.active::before { content: ''; position: absolute; left: 0; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0; background: var(--primary); }
  .sidebar a.nav-link .ico svg { width: 20px; height: 20px; }
  .sidebar .spacer { flex: 1; }
  .content { padding: 26px 30px 40px; max-width: 1100px; }
  .info-grid { grid-template-columns: repeat(4, 1fr); }
  .gallery { grid-template-columns: repeat(5, 1fr); gap: 8px; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  #map { height: calc(100dvh - 150px); }
  .day-list-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .day-list-grid .card { margin-bottom: 0; }

  /* Livello GIORNATA su desktop: NIENTE sidebar esperienza. Header + tab orizzontali. */
  #app[data-context="day"] .sidebar { display: none; }
  #app[data-context="day"] .exp-topbar { padding: 16px 30px 0; }
  #app[data-context="day"] .exp-topbar .tb-title { font-size: 1.5rem; }
  #app[data-context="day"] .day-tabs {
    display: flex; gap: 2px; background: var(--surface); border-bottom: 1px solid var(--border);
    padding: 4px 30px 0;
  }
  #app[data-context="day"] .day-tabs a.tab {
    display: inline-flex; align-items: center; gap: 8px; padding: 12px 18px; position: relative;
    color: var(--text-soft); font-weight: 600; text-decoration: none;
  }
  #app[data-context="day"] .day-tabs a.tab .ico svg { width: 19px; height: 19px; }
  #app[data-context="day"] .day-tabs a.tab .lbl { font-size: .95rem; }
  #app[data-context="day"] .day-tabs a.tab.active { color: var(--primary); }
  /* Selezione elegante: underline accent sotto la tab attiva */
  #app[data-context="day"] .day-tabs a.tab.active::after {
    content: ''; position: absolute; left: 14px; right: 14px; bottom: -1px; height: 2.5px; border-radius: 2px; background: var(--primary);
  }
  /* Contenuto giornata proporzionato e centrato (niente vuoti enormi su monitor larghi) */
  #app[data-context="day"] .content { max-width: 1120px; margin: 0 auto; }
  #app[data-context="day"] .map-view { max-width: 1400px; margin: 0 auto; }
}
