/* Agendo: brand e poche regole proprie. Solo token del design system Otix. */
:root { --brand: #0F7C6E; --on-brand: #fff; --tabbar-h: 64px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px) }

/* Reset minimo (prima veniva dal preflight di Tailwind): nel layer base, sotto i componenti del DS. */
@layer base {
  ul, ol, menu { list-style: none; margin: 0; padding: 0 }
  dl, dd, figure, blockquote { margin: 0 }
  hr { height: 0; border: 0; border-top: 1px solid var(--line); margin: 0 }
  img, video, canvas, audio, iframe, svg { display: block; vertical-align: middle }
  img, video { max-width: 100%; height: auto }
  textarea { resize: vertical }
  table { border-collapse: collapse }
  [hidden]:not([hidden="until-found"]) { display: none !important }
}

/* Utility di layout usate nelle viste (sostituiscono Tailwind) */
.flex { display: flex }
.flex-wrap { flex-wrap: wrap }
.grid { display: grid; grid-template-columns: minmax(0, 1fr) }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)) }
.items-center { align-items: center }
.items-start { align-items: start }
.gap-2 { gap: 8px } .gap-3 { gap: 12px } .gap-4 { gap: 16px } .gap-6 { gap: 24px }
.mt-2 { margin-top: 8px } .mt-4 { margin-top: 16px } .mt-6 { margin-top: 24px }
.mb-4 { margin-bottom: 16px } .mb-6 { margin-bottom: 24px }
@media (min-width: 640px) { .sm\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)) } }
@media (min-width: 1024px) {
  .lg\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)) }
  .grid-main-340 { grid-template-columns: minmax(0, 1fr) 340px }
  .grid-main-360 { grid-template-columns: minmax(0, 1fr) 360px }
}
@media (min-width: 1280px) { .xl\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)) } }

/* Logo (views/partials/logo.php, stesso disegno di favicon.svg e icone PWA) */
.brand-logo { display: block; flex: none; width: 32px; height: 32px }
.app-brand { display: flex; align-items: center; gap: var(--space-10); padding: var(--space-4) var(--space-10) var(--space-20); font-size: var(--text-19); font-weight: var(--weight-bold); color: var(--ink); text-decoration: none; letter-spacing: var(--tracking-heading) }
.logout-btn { width: 100%; border: 0; background: none; cursor: pointer; font: inherit; text-align: left }

/* Blocchi del dettaglio in .split-pane (rubrica, utenti): titolo + righe in un riquadro */
.pane-block { margin-top: var(--space-32) }
.pane-block > h3 { display: flex; align-items: center; gap: var(--space-8); margin-bottom: var(--space-12); font-size: var(--text-16); font-weight: var(--weight-semibold); color: var(--ink) }
.pane-block > .row-list { border: 1px solid var(--line); border-radius: var(--radius-13); overflow: hidden }
.pane-block > .row-list > li:last-child .row { border-bottom: 0 }
.pane-block .row.dense { padding-inline: var(--space-16) }
.split-actions form { display: contents }
.split-pane .split-facts dd.muted { color: var(--muted) }
.split-facts .text-btn { padding: 0 }

.page-stack { display: flex; flex-direction: column; gap: var(--space-24) }
.text-wrap { white-space: pre-line; overflow-wrap: anywhere }
.props dd { overflow-wrap: anywhere }
.inline-form { display: inline }
.list-swatch { display: inline-flex; width: 10px; height: 10px; border-radius: var(--radius-round); background: var(--swatch, var(--brand)); flex-shrink: 0 }

/* Calendario mensile */
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line-soft) }
.cal-head { padding: var(--space-8) var(--space-10); font-size: var(--text-12); color: var(--muted); font-weight: var(--weight-semibold); border-bottom: 1px solid var(--line-soft) }
.cal-day { min-height: 118px; padding: var(--space-6); border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); display: flex; flex-direction: column; gap: var(--space-4); min-width: 0 }
.cal-day:nth-child(7n) { border-right: 0 }
.cal-day.outside { background: var(--slate-50) }
.cal-day.outside .cal-num { color: var(--muted) }
.cal-num { font-size: var(--text-12); font-weight: var(--weight-semibold); color: var(--ink-2); padding: 2px var(--space-4) }
.cal-day.today .cal-num { background: var(--brand); color: var(--on-brand); border-radius: var(--radius-pill); align-self: flex-start; padding: 2px var(--space-8) }
.cal-event { display: flex; align-items: center; gap: var(--space-6); min-width: 0; padding: 3px var(--space-6); border-radius: var(--radius-5); font-size: var(--text-12); color: var(--ink); text-decoration: none; background: var(--slate-100) }
.cal-event:hover { background: var(--slate-200) }
.cal-event span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.cal-event.cancelled span:last-child { text-decoration: line-through; color: var(--muted) }
.cal-event .tag-dot { flex-shrink: 0 }
.cal-more { font-size: var(--text-12); color: var(--muted); padding: 0 var(--space-6) }
.cal-nav { display: flex; align-items: center; gap: var(--space-8); flex-wrap: wrap }

/* Registratore audio */
.recorder { display: flex; align-items: center; gap: var(--space-10); flex-wrap: wrap; padding: var(--space-12); border: 1px dashed var(--line-strong); border-radius: var(--radius-12); background: var(--slate-50) }
.recorder audio { width: 100%; max-width: 360px; height: 40px }
.recorder[hidden] { display: none }
.att-audio { display: flex; flex-direction: column; gap: var(--space-6); padding: var(--space-8) 0; border-bottom: 1px solid var(--line-soft) }
.att-audio audio { width: 100%; height: 40px }
.att-row { display: flex; align-items: center; gap: var(--space-10); padding: var(--space-10) 0; border-bottom: 1px solid var(--line-soft); min-width: 0 }
.att-row .att-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); text-decoration: none; font-weight: var(--weight-medium) }
.att-row .att-name:hover { color: var(--brand-text); text-decoration: underline }
.att-meta { font-size: var(--text-12); color: var(--muted); white-space: nowrap }
/* Telefono: data e peso sotto il nome, così il nome non si riduce a «P…». */
@media (max-width: 720px) {
  .att-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; column-gap: var(--space-10); row-gap: 2px }
  .att-row > svg { grid-area: 1 / 1 / 3 / 2 }
  .att-row .att-name { grid-area: 1 / 2 }
  .att-row .att-meta { grid-area: 2 / 2 }
  .att-row > .icon-btn, .att-row > .inline-form { grid-row: 1 / 3; align-self: center }
}

@media (max-width: 720px) {
  .cal-grid.month { display: none }
}
@media (min-width: 721px) {
  .cal-agenda.mobile-only { display: none }
}

.panel-body { padding: var(--space-4) var(--space-24) var(--space-24) }
.form-panel { padding: var(--space-24) }
.form-actions { display: flex; justify-content: flex-end; gap: var(--space-10); flex-wrap: wrap }
.field-error { color: var(--status-danger-fg); font-weight: var(--weight-medium) }
.row-link { color: inherit; text-decoration: none }
a.row-link:hover strong, a.cell-main.row-link:hover { color: var(--brand-text); text-decoration: underline }
.toolbar-select { height: var(--control-h-sm); width: auto; min-width: 160px }
.plain-fieldset { border: 0; padding: 0; margin: 0; min-width: 0 }
.plain-fieldset legend { font-size: var(--text-14); font-weight: var(--weight-semibold); color: var(--ink-2); margin-bottom: var(--space-8); padding: 0 }
.empty-state.compact { padding: var(--space-24) }
.page-btn.disabled { pointer-events: none; opacity: .5 }
.form-section-title { font-size: var(--text-16); margin: 0 0 var(--space-12) }
.form-hint { margin: 0 0 var(--space-10) }
.day-check { padding-right: var(--space-10); border: 1px solid var(--line-strong); border-radius: var(--radius-8) }
.stat-link { display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; width: 100%; text-align: left; text-decoration: none; color: inherit; cursor: pointer; transition: border-color var(--dur-fast), box-shadow var(--dur-fast) }
@media (hover: hover) {
  .stat-link:hover { border-color: var(--brand-line); box-shadow: var(--shadow-card-hover) }
}
dialog.stat-dialog { width: min(640px, calc(100% - 32px)); max-height: calc(100dvh - 40px); padding: 0; display: flex; flex-direction: column; overflow: hidden }
dialog.stat-dialog:not([open]) { display: none }
.stat-dialog .dialog-header > div { flex: 1; min-width: 0 }
.stat-dialog .dialog-body { padding: 0; gap: 0; overscroll-behavior: contain }
.stat-dialog .dialog-body > :first-child,
.stat-dialog .dialog-body > :first-child > .row:first-child { border-top: 0 }
.stat-dialog .dialog-footer .text-btn { font-size: var(--text-13) }
.stat-dialog .dialog-footer .text-btn .icon { width: 14px }
.stat-dialog .dialog-footer .btn[data-close] { margin-left: auto }
@media (max-width: 720px) {
  dialog.stat-dialog { width: calc(100% - 24px); max-height: calc(100dvh - 24px) }
}
.cal-num { text-decoration: none; align-self: flex-start }
.cal-num:hover { color: var(--brand-text) }
.row-group-title.today { color: var(--brand-text) }
.cal-empty-day { padding-top: var(--space-10); padding-bottom: var(--space-10) }
.help-details summary { cursor: pointer; font-weight: var(--weight-semibold); color: var(--brand-text); margin-bottom: var(--space-8) }
.help-steps { margin: 0 0 var(--space-16); padding-left: var(--space-20); line-height: var(--leading) }
.help-steps li { margin-bottom: var(--space-8) }
.check-list.is-empty { display: none }

/* Mappa (MapLibre) */
.map-panel { overflow: hidden }
.map-toolbar { flex-wrap: wrap; gap: var(--space-10); justify-content: flex-start; align-items: center }
.map-field { display: flex; align-items: center; gap: var(--space-8); font-size: var(--text-13); color: var(--ink-2) }
.map-field input { height: var(--control-h-sm); width: auto }
.map-canvas { position: relative; height: 300px; border: 1px solid var(--line); border-radius: var(--radius-12); overflow: hidden; background: var(--slate-100) }
.map-canvas[data-theme="scuro"] { background: var(--slate-900) }
.map-canvas-lg { height: clamp(420px, calc(100vh - 290px), 860px); border: 0; border-radius: 0; border-top: 1px solid var(--line-soft) }
.map-legend { display: flex; flex-wrap: wrap; gap: var(--space-8) var(--space-16); padding: var(--space-10) var(--space-16); font-size: var(--text-12); border-top: 1px solid var(--line-soft) }
.map-legend span { display: inline-flex; align-items: center; gap: var(--space-6) }
.legend-dot { width: 11px; height: 11px; border-radius: var(--radius-round); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line-strong) }
.legend-dot.appt { width: 12px; height: 15px; border: 0; box-shadow: none; background: var(--brand); border-radius: 50% 50% 50% 0; transform: rotate(-45deg) scale(.85) }
.legend-dot.item { background: #fff; border-color: var(--brand); box-shadow: none }
.legend-dot.plan { background: var(--priority-high) }
.legend-line { width: 18px; border-top: 3px dotted var(--brand) }
.map-side [data-plan-form][hidden] { display: none }
.plan-target { margin: 0; font-size: var(--text-13); color: var(--ink-2) }
.geo-picker { display: flex; flex-direction: column; gap: var(--space-6) }
.sugg-title { font-size: var(--text-13); font-weight: var(--weight-semibold); color: var(--ink-2); margin: var(--space-16) 0 var(--space-6) }
.sugg-list { border: 1px solid var(--line); border-radius: var(--radius-12); overflow: hidden }
.sugg-list > li:last-child .row, .sugg-list > li:last-child.sugg-item { border-bottom: 0 }
.sugg-item { display: flex; flex-direction: column; gap: var(--space-6); padding: var(--space-10) var(--space-16); border-bottom: 1px solid var(--line-soft) }
.sugg-focus { display: flex; flex-direction: column; gap: 2px; border: 0; background: none; padding: 0; text-align: left; cursor: pointer; font: inherit; color: inherit; min-width: 0 }
.sugg-focus strong { color: var(--ink); font-size: var(--text-14) }
.sugg-focus small { color: var(--muted); font-size: var(--text-12) }
.sugg-focus:hover strong { color: var(--brand-text); text-decoration: underline }
.sugg-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--space-8); flex-wrap: wrap }
.sugg-foot .text-btn { margin-left: auto; font-size: var(--text-13); font-weight: var(--weight-semibold); color: var(--brand-text); text-decoration: none }
.sugg-foot .text-btn:hover { text-decoration: underline }
.map-pop { display: flex; flex-direction: column; gap: var(--space-4); font-family: var(--font-sans); font-size: var(--text-13) }
.map-pop-title { font-weight: var(--weight-semibold); color: var(--ink); text-decoration: none }
.map-pop-title:hover { color: var(--brand-text); text-decoration: underline }
.map-pop .btn { margin-top: var(--space-6); align-self: flex-start }

/* Mappa: controlli in stile Google Maps con i token Otix */
/* Il CSS di MapLibre arriva dopo (caricato quando serve): :root alza la specificità per tenere Inter */
:root .maplibregl-map { font-family: var(--font-sans) }
.maplibregl-ctrl-group { border-radius: var(--radius-8); box-shadow: var(--shadow-raised), 0 0 0 1px var(--line); overflow: hidden }
.maplibregl-ctrl-group:not(:empty) { box-shadow: 0 1px 4px rgb(27 39 56 / .18) }
.maplibregl-ctrl-group button { width: 36px; height: 36px }
.maplibregl-ctrl-group button + button { border-top-color: var(--line-soft) }
.maplibregl-ctrl-group button:not(:disabled):hover { background: var(--slate-100) }
.maplibregl-ctrl-bottom-right .maplibregl-ctrl, .maplibregl-ctrl-top-right .maplibregl-ctrl { margin: 0 var(--space-12) var(--space-12) 0 }
.maplibregl-ctrl-top-right .maplibregl-ctrl { margin-top: var(--space-12) }
.maplibregl-ctrl-attrib { font-size: var(--text-12) }
.maplibregl-ctrl-attrib a { color: var(--ink-2) }
.map-popup .maplibregl-popup-content { padding: var(--space-12) var(--space-14); border-radius: var(--radius-12); box-shadow: 0 2px 10px rgb(27 39 56 / .22); color: var(--ink) }
.map-popup .maplibregl-popup-close-button { width: 28px; height: 28px; font-size: var(--text-19); color: var(--slate-600); border-radius: var(--radius-8) }
.map-popup .maplibregl-popup-close-button:hover { background: var(--slate-100) }
.map-pop { padding-right: var(--space-20) }

/* Livelli: anteprima del tema come la miniatura di Google Maps */
.map-layers.maplibregl-ctrl { position: relative; margin: 0 0 var(--space-28) var(--space-12) }
.map-layers-toggle { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; width: 64px; height: 64px; padding: 0 0 var(--space-4); border: 2px solid #fff; border-radius: var(--radius-10); background: var(--slate-200); box-shadow: 0 1px 4px rgb(27 39 56 / .3); cursor: pointer; overflow: hidden; position: relative }
.map-layers-toggle .map-layers-preview { position: absolute; inset: 0; border-radius: 0 }
.map-layers-label { position: relative; font-size: var(--text-12); font-weight: var(--weight-semibold); color: #fff; text-shadow: 0 1px 2px rgb(0 0 0 / .6) }
.map-layers-menu { position: absolute; left: 0; bottom: calc(100% + var(--space-8)); display: flex; gap: var(--space-8); padding: var(--space-8); background: var(--surface); border-radius: var(--radius-12); box-shadow: 0 2px 10px rgb(27 39 56 / .22) }
.map-layers-menu[hidden] { display: none }
.map-layers-option { display: flex; flex-direction: column; align-items: center; gap: var(--space-6); width: 76px; padding: var(--space-4); border: 0; border-radius: var(--radius-8); background: none; font: inherit; font-size: var(--text-12); color: var(--ink-2); cursor: pointer; text-align: center }
.map-layers-option:hover { background: var(--slate-100) }
.map-layers-option .map-layers-preview { width: 56px; height: 56px; border-radius: var(--radius-8); border: 2px solid transparent }
.map-layers-option[aria-pressed="true"] { color: var(--brand-text); font-weight: var(--weight-semibold) }
.map-layers-option[aria-pressed="true"] .map-layers-preview { border-color: var(--brand) }
.map-layers-preview { display: block; background-size: cover }
/* Miniature disegnate con gradienti: terra, parco, acqua, strada principale */
.map-layers-preview[data-preview="chiaro"] { background: linear-gradient(135deg, transparent 46%, #f6cf6a 46% 52%, transparent 52%), radial-gradient(circle at 78% 22%, #aecfee 0 26%, transparent 27%), radial-gradient(circle at 20% 80%, #d4ead6 0 24%, transparent 25%), linear-gradient(45deg, transparent 47%, #fff 47% 51%, transparent 51%), #f4f5f7 }
.map-layers-preview[data-preview="scuro"] { background: linear-gradient(135deg, transparent 46%, #8a7442 46% 52%, transparent 52%), radial-gradient(circle at 78% 22%, #0f2740 0 26%, transparent 27%), radial-gradient(circle at 20% 80%, #1f3530 0 24%, transparent 25%), linear-gradient(45deg, transparent 47%, #3a4a62 47% 51%, transparent 51%), #1c2533 }
.map-layers-preview[data-preview="rilievo"] { background: linear-gradient(135deg, transparent 46%, #f6cf6a 46% 52%, transparent 52%), radial-gradient(ellipse at 30% 35%, #8b98ab 0 10%, #c3cad4 18%, transparent 40%), radial-gradient(ellipse at 70% 70%, #9ca5b1 0 8%, #cfe5c8 22%, transparent 42%), #f1f0e9 }

/* Ricerca sulla mappa */
.map-search { position: absolute; top: var(--space-12); left: var(--space-12); z-index: 2; display: flex; align-items: center; width: min(360px, calc(100% - 80px)); height: 44px; background: var(--surface); border-radius: var(--radius-pill); box-shadow: 0 1px 4px rgb(27 39 56 / .3) }
.map-search input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; padding: 0 var(--space-6) 0 var(--space-18); font: inherit; font-size: var(--text-14); color: var(--ink); box-shadow: none; outline: none }
.map-search:focus-within { box-shadow: 0 1px 4px rgb(27 39 56 / .3), 0 0 0 2px var(--focus-ring) }
.map-search-btn { display: grid; place-items: center; width: 40px; height: 40px; margin-right: var(--space-2); border: 0; border-radius: var(--radius-round); background: none; color: var(--slate-600); cursor: pointer }
.map-search-btn:hover { background: var(--slate-100); color: var(--brand-text) }
@media (max-width: 720px) {
  .map-layers.maplibregl-ctrl { margin-bottom: var(--space-48) }
  .map-layers-toggle { width: 56px; height: 56px }
}

/* =====================================================================
   Telefono (≤720px): barra in alto compatta, barra in basso con «+», aree sicure (notch, home bar)
   ===================================================================== */
.tabbar, .tab-fab { display: none }
.app-shell { min-height: 100vh; min-height: 100dvh }
@media (max-width: 720px) {
  .sidebar, .app-footer { display: none }
  .mobile-topbar { padding-top: var(--safe-t); height: calc(56px + var(--safe-t)); padding-left: max(var(--space-12), env(safe-area-inset-left)); padding-right: max(var(--space-8), env(safe-area-inset-right)) }
  .mobile-brand { display: grid; place-items: center; width: 44px; height: 44px }
  .mobile-brand .brand-logo { width: 30px; height: 30px }
  .mobile-avatar { display: grid; place-items: center; width: 44px; height: 44px }
  .mobile-avatar .avatar { width: 32px; height: 32px; font-size: var(--text-12) }
  .main-shell main { min-height: 0; padding-left: max(var(--space-16), env(safe-area-inset-left)); padding-right: max(var(--space-16), env(safe-area-inset-right)); padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + var(--space-32)) }

  .tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; height: calc(var(--tabbar-h) + var(--safe-b)); padding: 0 env(safe-area-inset-right) var(--safe-b) env(safe-area-inset-left); background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -2px 12px rgb(27 39 56 / .06) }
  .tabbar .tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: var(--tabbar-h); color: var(--muted); font-size: var(--text-12); font-weight: var(--weight-medium); list-style: none; cursor: pointer; text-decoration: none }
  .tabbar .tab::-webkit-details-marker { display: none }
  .tabbar .tab .icon { width: 22px; height: 22px }
  .tabbar .tab.active { color: var(--brand-text); font-weight: var(--weight-semibold) }
  .tabbar .tab.active .icon { stroke-width: 2 }
  .tab-fab { display: grid; place-items: center; justify-self: center; width: 56px; height: 56px; margin-top: -18px; border-radius: var(--radius-round); background: var(--brand); color: var(--on-brand); box-shadow: 0 4px 14px color-mix(in srgb, var(--brand) 45%, transparent) }
  .tab-fab .icon { width: 26px; height: 26px; stroke-width: 2.2 }
  .tab-fab:active { transform: scale(.94) }
  .tab-more { position: static }
  .tab-sheet { position: fixed; left: var(--space-12); right: var(--space-12); bottom: calc(var(--tabbar-h) + var(--safe-b) + var(--space-8)); display: flex; flex-direction: column; padding: var(--space-6); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-16); box-shadow: var(--shadow-dialog); max-height: 70dvh; overflow-y: auto }
  .tab-sheet .menu-item { min-height: 48px; font-size: var(--text-16) }
  .tab-sheet .menu-item.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: var(--weight-semibold) }
  .tab-sheet form { display: contents }

  /* Toast e fogli del DS sopra la barra in basso */
  .toast { bottom: calc(var(--tabbar-h) + var(--safe-b) + var(--space-12)) }
  .dropdown > .menu, .dropdown > .popover, .dropdown:is(.start, .end, .up) > :is(.menu, .popover) { bottom: calc(var(--tabbar-h) + var(--safe-b) + var(--space-8)) }

  /* Niente zoom automatico di iOS: campi ≥16px anche dove il DS li rimpicciolisce */
  .search-box input, .map-search input, .map-field input { font-size: var(--text-16) }

  /* Form lunghi: «Salva» sempre a portata di pollice */
  .form-actions.sticky-actions { position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b)); z-index: 5; margin: 0 calc(var(--space-16) * -1); padding: var(--space-12) var(--space-16); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-top: 1px solid var(--line) }
  .form-actions.sticky-actions .btn { flex: 1 }

  .map-canvas-lg { height: calc(100dvh - 56px - var(--safe-t) - var(--tabbar-h) - var(--safe-b) - 160px); min-height: 360px }
}

/* Sezioni facoltative dei form, chiuse di default */
details.form-fold > summary { display: flex; align-items: center; justify-content: space-between; gap: var(--space-8); list-style: none; cursor: pointer; min-height: 44px; margin: calc(var(--space-12) * -1) 0 }
details.form-fold > summary::-webkit-details-marker { display: none }
details.form-fold > summary .form-section-title { margin: 0 }
details.form-fold > summary small { color: var(--muted); font-size: var(--text-13); font-weight: var(--weight-regular); margin-left: auto }
details.form-fold > summary .icon { width: 18px; height: 18px; color: var(--slate-500); transition: transform var(--dur) }
details.form-fold[open] > summary { margin-bottom: var(--space-12) }
details.form-fold[open] > summary .icon { transform: rotate(180deg) }

/* Touch: bersagli ≥44px, niente stati hover «appiccicati» dopo il tocco */
@media (pointer: coarse) {
  .icon-btn, .page-btn, .segment, .maplibregl-ctrl-group button { min-width: 44px; min-height: 44px }
  .toolbar-select, .map-field input { height: 44px }
  .map-popup .maplibregl-popup-close-button { width: 40px; height: 40px }
  .cal-num { min-width: 32px; min-height: 32px; display: inline-grid; place-items: center }
  .cal-event { min-height: 28px }
}
@media (hover: none) {
  .btn:hover, a.card:hover, button.card:hover { transform: none }
}
/* Azioni del form a tutta larghezza sotto le due colonne: su telefono restano agganciate in basso per tutto il form */
.form-actions-wide { grid-column: 1 / -1 }

/* Azioni rapide sotto una riga (Fatto, Domani, +1 settimana) */
.row-actions { display: flex; flex-wrap: wrap; gap: var(--space-8); padding: 0 var(--space-24) var(--space-14) calc(var(--space-24) + 52px) }
.row-actions form { display: contents }
form.row-actions { display: flex; align-items: center }
.row-actions input:not([type=hidden]) { flex: 1 1 180px; width: auto; min-height: var(--icon-btn) }
.row-actions select { width: auto; min-height: var(--icon-btn) }
@media (max-width: 720px) {
  .row-actions { padding: 0 19px var(--space-16) }
  .row-actions .btn { flex: 1; min-height: 44px }
}

/* «Prossimo»: l'appuntamento in arrivo con le azioni che servono in giro */
.next-card { padding: var(--space-24); margin-bottom: var(--space-24) }
.next-card .eyebrow { color: var(--brand-text) }
.next-card h2 { font-size: var(--text-24, 24px); margin: var(--space-4) 0 var(--space-6) }
.next-card h2 a { color: inherit; text-decoration: none }
.next-meta { color: var(--ink-2); margin: 0 0 var(--space-16) }
.next-actions { display: flex; flex-wrap: wrap; gap: var(--space-10) }
.next-actions form { display: contents }
@media (max-width: 720px) {
  .next-actions .btn { flex: 1 1 30%; min-height: 52px; flex-direction: column; gap: 4px; font-size: var(--text-13) }
  .next-actions .btn .icon { width: 22px; height: 22px }
}
.empty-state .inline-actions { justify-content: center; margin-top: var(--space-16) }
.inline-actions { display: flex; flex-wrap: wrap; gap: var(--space-8); margin-top: var(--space-10) }

.tours { margin-top: var(--space-24); padding-top: var(--space-20); border-top: 1px solid var(--line-soft) }
.tours [data-tours-out] { margin-top: var(--space-12) }

/* ---------- Mappa: filtri richiudibili, popup, «dove sono io» ---------- */
.map-filters-chip { display: none }
.map-filters-fold > summary::-webkit-details-marker { display: none }
.map-pop-actions { display: flex; gap: var(--space-8); flex-wrap: wrap; margin-top: var(--space-6) }
.map-pop-actions .btn { margin-top: 0 }
.map-pop > .btn.secondary { align-self: flex-start }
.form-hint .icon { display: inline-block; width: 14px; height: 14px; vertical-align: -2px }
.sheet-handle { display: none }

/* ---------- Mappa su telefono: tutto schermo + foglio dal basso ---------- */
@media (max-width: 720px) {
  .page-mappa .map-heading { display: none }
  .page-mappa .main-shell main { padding: 0; padding-bottom: 0 }
  .page-mappa [data-map-page] { display: block }
  .page-mappa .map-panel { border: 0; border-radius: 0; box-shadow: none; margin: 0 }
  .page-mappa .map-legend { display: none }
  .map-filters-chip { display: flex; align-items: center; gap: var(--space-8); min-height: 48px; padding: 0 var(--space-16); list-style: none; cursor: pointer; font-weight: var(--weight-semibold); border-bottom: 1px solid var(--line-soft); background: var(--surface) }
  .map-filters-chip .icon { width: 18px; height: 18px; color: var(--slate-500) }
  .map-filters-chip span { white-space: nowrap }
  .map-filters-chip small { margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: var(--weight-regular); font-size: var(--text-12) }
  .page-mappa .map-toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-10); padding: var(--space-12) var(--space-16) }
  .page-mappa .map-toolbar .map-field { flex-direction: column; align-items: stretch; gap: 4px }
  .page-mappa .map-toolbar .map-field input, .page-mappa .map-toolbar .toolbar-select { width: 100%; min-width: 0 }
  .page-mappa .map-canvas-lg { height: calc(100dvh - 56px - var(--safe-t) - 48px - var(--tabbar-h) - var(--safe-b)); min-height: 320px; border-top: 0 }

  /* Pannello «Pianifica» come foglio: chiuso (solo maniglia e titolo), metà, quasi pieno */
  .page-mappa .map-side { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-b)); z-index: 30; margin: 0; padding: 0 var(--space-16) var(--space-16);
    border-radius: var(--radius-16) var(--radius-16) 0 0; border: 1px solid var(--line); border-bottom: 0; box-shadow: 0 -6px 24px rgb(27 39 56 / .16);
    max-height: calc(100dvh - 56px - var(--safe-t) - var(--tabbar-h) - var(--safe-b) - 24px); overflow-y: auto; overscroll-behavior: contain;
    transition: height var(--dur-slow, .3s) var(--ease-out, ease-out) }
  .page-mappa .map-side[data-sheet="peek"] { height: 104px; overflow: hidden }
  .page-mappa .map-side[data-sheet="half"] { height: 46dvh }
  .page-mappa .map-side[data-sheet="full"] { height: calc(100dvh - 56px - var(--safe-t) - var(--tabbar-h) - var(--safe-b) - 24px) }
  .sheet-handle { display: grid; place-items: center; position: sticky; top: 0; z-index: 2; width: calc(100% + var(--space-32)); height: 32px; margin: 0 calc(var(--space-16) * -1) var(--space-4); background: var(--surface); border: 0; cursor: grab; touch-action: none }
  .sheet-handle span { width: 40px; height: 5px; border-radius: 3px; background: var(--slate-300) }
  .page-mappa .map-side .form-section-title { margin-top: 0 }
  .page-mappa .maplibregl-ctrl-bottom-right, .page-mappa .maplibregl-ctrl-bottom-left { bottom: 112px }
}
@media (prefers-reduced-motion: reduce) { .page-mappa .map-side { transition: none } }

/* ---------- Calendario su telefono: striscia dei giorni, swipe, menu «⋯» ---------- */
.week-strip { display: none }
.heading-more { padding-inline: var(--space-12) }
@media (max-width: 720px) {
  .cal-panel { overflow: clip }
  .week-strip { position: sticky; top: calc(56px + var(--safe-t)); z-index: 4; display: flex; gap: var(--space-6); padding: var(--space-8) var(--space-12); overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none; background: var(--surface); border-top: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); overscroll-behavior-x: contain }
  .week-strip::-webkit-scrollbar { display: none }
  .strip-day { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; width: 46px; min-height: 60px; border-radius: var(--radius-12); color: var(--ink-2); text-decoration: none; scroll-snap-align: center }
  .strip-wd { font-size: var(--text-12); color: var(--muted); text-transform: capitalize }
  .strip-num { font-size: var(--text-16); font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums }
  .strip-dot { width: 5px; height: 5px; border-radius: var(--radius-round); background: transparent }
  .strip-day.has .strip-dot { background: var(--brand) }
  .strip-day.today { background: var(--brand); color: var(--on-brand) }
  .strip-day.today .strip-wd { color: inherit }
  .strip-day.today.has .strip-dot { background: var(--on-brand) }
  .strip-day.current:not(.today) { background: var(--brand-soft); color: var(--brand-ink) }
  .cal-agenda .row-group-title { scroll-margin-top: calc(56px + var(--safe-t) + 80px) }
  .heading-actions .dropdown { flex: 0 0 auto }
  .heading-actions .heading-more { min-width: 49px }
}
.cal-panel.swipe-next, .cal-panel.swipe-prev { opacity: .5; transition: opacity var(--dur-fast) }

/* Tema scuro: ritocchi dove l'app usa colori fissi */
@media (prefers-color-scheme: dark) {
  .tooltip { background: var(--slate-300) }
  .legend-dot { border-color: var(--surface) }
  .legend-dot.item { background: var(--surface) }
  .map-search, .map-layers-menu { box-shadow: 0 1px 6px rgb(0 0 0 / .5) }
}

/* ---------- Tabelle → card su telefono: <table class="table stack">, <td data-label="…"> ---------- */
@media (max-width: 720px) {
  .table.stack, .table.stack tbody, .table.stack tr, .table.stack td { display: block; width: 100% }
  .table.stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0) }
  .table.stack tr { position: relative; padding: var(--space-12) var(--space-16); border-top: 1px solid var(--line-soft) }
  .table.stack tr:first-child { border-top: 0 }
  .table.stack td { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-12); padding: var(--space-2) 0; border: 0; text-align: left; font-size: var(--text-14) }
  .table.stack td[data-label]::before { content: attr(data-label); flex-shrink: 0; color: var(--muted); font-size: var(--text-13) }
  .table.stack td > * { min-width: 0; text-align: right }
  .table.stack td.stack-title { display: block; padding-bottom: var(--space-4) }
  .table.stack td.stack-title > * { text-align: left }
  .table.stack td.stack-title .cell-main { font-size: var(--text-16); white-space: normal }
  .table.stack td.stack-empty { display: none }
  .table.stack td.stack-wrap { overflow-wrap: anywhere; text-align: right }
  .table.stack .stretch::after { content: ""; position: absolute; inset: 0 }
  .table.stack .stretch:active::after { background: var(--slate-100); opacity: .5 }
  .pagination { flex-wrap: wrap; justify-content: center }
}

/* ---------- Fase 6: select uniformi e bersagli touch emersi dall'audit su iPhone (WebKit) ---------- */
/* Safari su iPhone ignora altezza e padding dei <select> nativi (restano alti ~25px): freccia disegnata da noi. */
select:not([multiple]) { -webkit-appearance: none; appearance: none; padding-right: 38px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237b889a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 16px }
@media (pointer: coarse) {
  .btn.small, .tab, .text-btn, .check, .map-search-btn { min-height: 44px }
  .map-search-btn { min-width: 44px }
  .text-btn { padding-block: 0 }
  .search-box input:not([type=checkbox]):not([type=radio]) { min-height: 44px }
  .props dd > a:only-child { display: inline-flex; align-items: center; min-height: 44px; min-width: 44px }
  .sheet-handle { height: 44px }
}

/* Profilo: punti di partenza (casa, ufficio) uno sotto l'altro, separati. */
.place-remove { display: flex; justify-content: flex-end; margin-top: var(--space-8) }
.place-form + .place-form, .place-remove + .place-form { margin-top: var(--space-16); padding-top: var(--space-16); border-top: 1px solid var(--line) }

/* Mappa: partenza dei giri e «Salva come casa/ufficio». */
.tour-start { margin-bottom: var(--space-12) }
.plan-save-place { display: flex; flex-wrap: wrap; gap: 0 var(--space-16) }
.plan-save-place .text-btn, .tour-start .text-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; text-decoration: none }
.plan-save-place .text-btn svg, .tour-start .text-btn svg { width: 16px; height: 16px }

/* Mappa su schermo largo: il pannello «Pianifica / Giri consigliati» è alto quanto il riquadro della mappa e scorre
   al suo interno, così i risultati lunghi non allungano la pagina (su telefono è già un foglio dal basso).
   contain: size → l'altezza della riga la decide solo la mappa; align-self: stretch la riempie.
   Solo con le due colonne (≥1024px): sotto, il pannello sta sotto la mappa e cresce normalmente. */
@media (min-width: 1024px) {
  .page-mappa .map-side { align-self: stretch; contain: size; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable }
  /* La pagina della mappa sta tutta nella finestra: colonna alta quanto lo schermo, la mappa prende lo spazio rimasto
     (niente altezze calcolate a mano: vale per ogni altezza di finestra e per i filtri aperti o chiusi). */
  .page-mappa .main-shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh }
  .page-mappa .main-shell > main { flex: 1; min-height: 0; width: 100%; display: flex; flex-direction: column; padding-bottom: var(--space-24) }
  .page-mappa [data-map-page] { flex: 1; min-height: 0; grid-template-rows: minmax(0, 1fr) }
  .page-mappa .map-panel { align-self: stretch; display: flex; flex-direction: column; min-height: 0 }
  .page-mappa .map-canvas-lg { flex: 1; height: auto; min-height: 240px }
  .page-mappa .app-footer { display: none }
  /* Più spazio alla mappa: titolo e filtri compatti (l'etichetta «Mappa» ripete la barra in alto). */
  .page-mappa .main-shell > main { padding-top: var(--space-24) }
  .page-mappa .page-heading { margin-bottom: var(--space-16) }
  .page-mappa .page-heading .eyebrow { display: none }
  .page-mappa .map-toolbar { padding: var(--space-12) var(--space-16); gap: var(--space-8) var(--space-12) }
}
/* Filtri della mappa: da 1280px una riga quando c'è posto (la lista riempie lo spazio, va a capo da sola se non basta),
   griglia 2×2 tra 1024 e 1279px. Meno altezza tolta alla mappa. */
@media (min-width: 1280px) {
  .page-mappa .map-toolbar .toolbar-select { flex: 1 1 160px }
  .page-mappa .map-toolbar .check { flex: none }
}
@media (min-width: 1024px) and (max-width: 1279px) {
  .page-mappa .map-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) }
  .page-mappa .map-toolbar .map-field input { flex: 1; min-width: 0 }
  .page-mappa .map-toolbar .toolbar-select { width: 100%; min-width: 0 }
}

/* Tappe di un giro (pagina appuntamento) */
.stop-btn { min-height: 44px }
.stop-state { margin: 0; padding: 0 var(--space-24) var(--space-14) calc(var(--space-24) + 52px) }

/* Mappa: «Programma giro» (giorno, ora, tappe con durata, totale, sovrapposizioni) */
.tour-plan { display: flex; flex-direction: column; gap: var(--space-10) }
.tour-plan .tour-back { align-self: flex-start; min-height: 44px; font-size: var(--text-14) }
.tour-plan .form-section-title { margin: 0 }
.tour-plan input:not([type=checkbox]), .tour-plan select { font-size: var(--text-16) }
.tour-plan-when { margin: 0; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) }
.tour-plan-when input { min-width: 0 }
.tour-plan-from, .tour-plan-status, .tour-plan-total, .tour-plan-warn, .tour-plan-error { margin: 0 }
.tour-plan-stops { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column }
.tour-plan-stop { display: flex; flex-wrap: wrap; align-items: center; column-gap: var(--space-8); row-gap: var(--space-4); padding: var(--space-6) 0; border-top: 1px solid var(--line-soft) }
.tour-plan-name { flex: 1 1 10rem; min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; column-gap: var(--space-8); row-gap: 2px }
.tour-plan-acts { display: flex; align-items: center; gap: var(--space-4); margin-left: auto }
.tour-plan-name strong { color: var(--ink); font-size: var(--text-14); overflow-wrap: anywhere }
.tour-plan-time, .tour-plan-end { font-variant-numeric: tabular-nums; font-size: var(--text-13); color: var(--ink-2) }
.tour-plan-end { padding: var(--space-6) 0; font-weight: var(--weight-semibold) }
.tour-plan-leg { padding: 2px 0 2px var(--space-16); font-size: var(--text-12); color: var(--muted) }
.tour-plan-stop select { width: 7.5rem; flex: none; min-height: 44px; margin: 0 }
.tour-plan-btn { width: 44px; height: 44px; flex: none; color: var(--slate-600); background: none; cursor: pointer; font-size: var(--text-16) }
.tour-plan-btn:disabled { opacity: .3; cursor: default }
.tour-plan-from { margin: 0; grid-template-columns: minmax(0, 1fr); align-items: end }
.tour-plan-from.has-ret { grid-template-columns: minmax(0, 1fr) auto }
.tour-plan-from select { min-width: 0; width: 100% }
.tour-plan-from .check { min-height: 44px }
.tour-plan-add { display: flex; flex-direction: column; gap: var(--space-4); margin: 0 }
.tour-plan-add input { width: 100%; min-height: 44px }
.tour-plan-results { display: flex; flex-direction: column }
.tour-plan-results:empty { display: none }
.tour-plan-result { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; min-height: 44px; padding: var(--space-6) var(--space-8); border: 0; border-radius: var(--radius-8); background: none; color: var(--ink); text-align: left; font: inherit; cursor: pointer }
.tour-plan-result:hover, .tour-plan-result:focus-visible { background: var(--slate-100) }
.tour-plan-result strong { font-size: var(--text-14); overflow-wrap: anywhere }
.tour-plan-none, .tour-plan-hint { margin: 0; padding: var(--space-6) var(--space-8); font-size: var(--text-13) }
.tour-plan-tools { display: flex; flex-wrap: wrap; gap: var(--space-8) }
.tour-plan-tools .btn { flex: 1 1 9rem }
.tour-plan-total { font-weight: var(--weight-semibold); color: var(--ink); font-variant-numeric: tabular-nums }
.tour-plan-create { width: 100% }
.tour-plan [hidden] { display: none }
.tour-plan-warn p, .tour-plan-warn ul { margin: 0 }
.tour-plan-warn ul { padding-left: var(--space-20); font-variant-numeric: tabular-nums }

/* Setup di primo avvio (/setup): passi 1-2-3 */
.setup-steps { display: flex; gap: var(--space-8); margin: var(--space-12) 0 var(--space-20); padding: 0; list-style: none; font-size: var(--text-13); color: var(--muted) }
.setup-steps li { display: flex; flex: 1; align-items: center; gap: var(--space-8); min-width: 0; padding-top: var(--space-8); border-top: 3px solid var(--line) }
.setup-steps li.done, .setup-steps li.current { border-top-color: var(--brand); color: var(--ink) }
.setup-steps li.current { font-weight: var(--weight-semibold) }
.setup-step-no { display: inline-grid; flex: none; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--surface-alt); font-variant-numeric: tabular-nums }
.setup-steps .done .setup-step-no, .setup-steps .current .setup-step-no { background: var(--brand); color: #fff }
.setup-step-no svg { width: 14px; height: 14px }
.auth-body + .auth-body { margin-top: var(--space-12) }

/* Profilo: griglia di card. Telefono: una colonna (calendario, punti di partenza, password, dispositivi).
   Desktop: a sinistra calendario, password e dispositivi; a destra i punti di partenza (con le mappe) per tutta l'altezza. */
.profile-grid { display: grid; gap: var(--space-24); align-items: start }
.profile-grid > .panel { margin: 0; min-width: 0 }
@media (min-width: 1024px) {
  .profile-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: auto auto 1fr; grid-template-areas: "cal places" "pwd places" "dev places" }
  .profile-grid > #calendario { grid-area: cal }
  .profile-grid > #luoghi { grid-area: places }
  .profile-grid > #password { grid-area: pwd }
  .profile-grid > #dispositivi { grid-area: dev }
}
.profile-grid > #dispositivi .row { padding-left: 0; padding-right: 0 } /* già dentro il padding della card */
