:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #22261f;
  --muted: #6b6f64;
  --border: #ddd8cc;
  --primary: #2f4a3a;
  --primary-text: #ffffff;
  --accent: #8a6d3b;
  --good: #2e7d4f;
  --warn: #b7791f;
  --bad: #b23b3b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161915;
    --surface: #1f231e;
    --surface-2: #2a2f28;
    --text: #e9e7df;
    --muted: #a3a79a;
    --border: #353a32;
    --primary: #7fae8f;
    --primary-text: #10140f;
    --accent: #d2b07a;
    --good: #6cc391;
    --warn: #e0b04f;
    --bad: #e07a7a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(72px + var(--safe-bottom));
}
a { color: var(--primary); }
h2 { font-size: 1.25rem; margin: 1.2rem 0 .6rem; }
h3 { font-size: 1.05rem; margin: 1rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.loading { text-align: center; color: var(--muted); padding: 3rem 0; }

/* barra superiore e tab */
.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; gap: .5rem;
  padding: calc(.7rem + var(--safe-top)) 16px .7rem;
  background: var(--primary); color: var(--primary-text);
}
.topbar h1 { font-size: 1.1rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { background: none; border: 0; color: inherit; font-size: 2rem; line-height: 1; padding: 0 .4rem 0 0; cursor: pointer; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: .5rem 0 .55rem; text-decoration: none; color: var(--muted); font-size: .72rem;
}
.tabbar a span { font-size: 1.3rem; line-height: 1; }
.tabbar a.active { color: var(--primary); font-weight: 600; }

main { max-width: 720px; margin: 0 auto; padding: 0 16px 1.5rem; }

/* componenti */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem; margin: .8rem 0;
}
.list { display: flex; flex-direction: column; gap: .6rem; margin: .6rem 0; }
.item {
  display: flex; gap: .8rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .7rem; text-decoration: none; color: inherit; box-shadow: var(--shadow);
}
.item .thumb {
  width: 64px; height: 64px; flex: 0 0 64px; border-radius: 10px; object-fit: cover;
  background: var(--surface-2); display: grid; place-items: center; color: var(--muted); font-size: 1.6rem;
}
.item .body { flex: 1; min-width: 0; }
.item .name { font-weight: 600; }
.item .meta { color: var(--muted); font-size: .85rem; }
.item .side { color: var(--muted); font-size: .85rem; text-align: right; white-space: nowrap; }
.badge {
  display: inline-block; font-size: .72rem; padding: .1rem .5rem; border-radius: 99px;
  background: var(--surface-2); color: var(--muted); margin-right: .3rem;
}
.badge.rel { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 1.5rem 1rem; border: 1px dashed var(--border); border-radius: var(--radius); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: .7rem 1rem; border-radius: 12px; font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--bad); }
.btn.block { display: flex; width: 100%; }
.btn.big { padding: 1rem; font-size: 1.05rem; }
.btn:disabled { opacity: .55; cursor: default; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; }
.row > * { flex: 1; }
.linkbtn { background: none; border: 0; color: var(--primary); font: inherit; padding: 0; cursor: pointer; text-decoration: underline; }

form .field { margin: .8rem 0; }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=date], input[type=search], textarea, select {
  width: 100%; font: inherit; padding: .65rem .75rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }
.check { display: flex; gap: .5rem; align-items: flex-start; font-weight: 400; }
.check input { margin-top: .25rem; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.error { color: var(--bad); font-weight: 600; margin: .5rem 0; }

/* foto */
.photo-pick {
  display: grid; place-items: center; text-align: center; gap: .3rem;
  min-height: 180px; border: 2px dashed var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--muted); cursor: pointer; overflow: hidden; position: relative;
}
.photo-pick img { width: 100%; max-height: 340px; object-fit: cover; display: block; }
.photo-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.hero-photo { width: 100%; max-height: 420px; object-fit: cover; border-radius: var(--radius); display: block; margin-top: 1rem; }

/* mappe */
.map { height: 240px; border-radius: var(--radius); border: 1px solid var(--border); z-index: 0; }
.map.tall { height: 340px; }

/* GPS */
.gps { display: flex; flex-direction: column; gap: .6rem; }
.gps-status { display: flex; align-items: center; gap: .6rem; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); flex: 0 0 12px; }
.dot.good { background: var(--good); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.dot.live { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* navigazione */
.nav-panel { text-align: center; }
.nav-distance { font-size: 3.2rem; font-weight: 700; line-height: 1; margin: .6rem 0 .2rem; }
.arrow-wrap { width: 190px; height: 190px; margin: 1rem auto; position: relative; }
.arrow-wrap svg { width: 100%; height: 100%; transition: transform .25s ease-out; }
.arrived { background: color-mix(in srgb, var(--good) 15%, transparent); border-color: var(--good); }

/* messaggi */
.msg { border-left: 3px solid var(--accent); padding: .3rem 0 .3rem .8rem; margin: .8rem 0; }
.msg .text { white-space: pre-wrap; }
.msg .meta { font-size: .8rem; color: var(--muted); }

/* finestra modale e toast */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 2000;
  display: grid; place-items: end center;
}
.modal {
  background: var(--surface); color: var(--text); width: 100%; max-width: 520px;
  border-radius: 18px 18px 0 0; padding: 1.3rem 16px calc(1.3rem + var(--safe-bottom));
  /* finestre lunghe (es. imprese e fiorai): scorrono dentro lo schermo */
  max-height: 92vh; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
}
@media (min-width: 600px) { .modal-back { place-items: center; } .modal { border-radius: 18px; } }
.modal ul { padding-left: 1.2rem; }
#toast {
  position: fixed; left: 50%; bottom: calc(86px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px;
  font-size: .9rem; z-index: 3000; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw;
}
#toast.show { opacity: 1; }

.auth { max-width: 420px; margin: 2rem auto; }
.auth .logo { font-size: 3rem; text-align: center; }
.plan { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }

/* suggerimenti comuni */
.suggest { display: flex; flex-direction: column; margin-top: .3rem; border-radius: 10px; overflow: hidden; }
.suggest button {
  text-align: left; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-top: 0; padding: .65rem .75rem; cursor: pointer;
}
.suggest button:first-child { border-top: 1px solid var(--border); border-radius: 10px 10px 0 0; }
.suggest button:last-child { border-radius: 0 0 10px 10px; }
.suggest button:only-child { border-radius: 10px; }
button.item { width: 100%; font: inherit; text-align: left; cursor: pointer; }
.badge.other { background: color-mix(in srgb, var(--primary) 15%, transparent); color: var(--primary); }

/* messaggi ricevuti su un defunto seguito */
.msg-count { position: relative; flex: 0 0 auto; font-size: 1.9rem; line-height: 1; color: var(--accent); padding: 0 .35rem .1rem 0; }
.msg-count b {
  position: absolute; top: -.35rem; right: -.2rem; min-width: 1.25rem; height: 1.25rem; padding: 0 .3rem;
  border-radius: 99px; background: var(--bad); color: #fff; font-size: .75rem; line-height: 1.25rem; text-align: center;
}

/* area di amministrazione */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; margin: 1rem 0; }
.stats div { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .6rem .4rem; text-align: center; font-size: .75rem; color: var(--muted); }
.stats b { display: block; font-size: 1.3rem; color: var(--text); }
.tabs { display: flex; gap: .3rem; overflow-x: auto; margin-bottom: .8rem; border-bottom: 1px solid var(--border); }
.tabs a { padding: .5rem .45rem; font-size: .92rem; text-decoration: none; color: var(--muted); white-space: nowrap; border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--primary); border-color: var(--primary); font-weight: 600; }
.pill { background: var(--bad); color: #fff; border-radius: 99px; font-size: .7rem; padding: 0 .4rem; }
details.card summary { cursor: pointer; }

/* visita ottimizzata */
.num-pin { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; border: 2px solid #fff;
  display: grid; place-items: center; font-weight: 700; font-size: .85rem; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.num-pin.big { width: 40px; height: 40px; flex: 0 0 40px; font-size: 1.05rem; }
.item.check input { margin: 0 .2rem 0 0; width: 20px; height: 20px; flex: 0 0 20px; }
.visit-bar { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }

/* documenti dell'Area Comune */
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 1rem; text-align: center; background: var(--surface-2); }
.dropzone.over { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, var(--surface)); }
.dropzone label.btn { cursor: pointer; }
.stats.three { grid-template-columns: repeat(3, 1fr); }
.badge.ok { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg a { padding: .45rem .8rem; text-decoration: none; color: var(--muted); font-size: .9rem; }
.seg a.active { background: var(--primary); color: var(--primary-text); font-weight: 600; }

/* grafici mensili dell'Area Comune */
.hero-num { font-size: 2.6rem; font-weight: 700; line-height: 1.1; }
.seg.years { display: flex; flex-wrap: wrap; margin: .8rem 0 .4rem; }
.seg.years button { font: inherit; font-size: .85rem; border: 0; background: none; color: var(--muted); padding: .4rem .7rem; cursor: pointer; }
.seg.years button.active { background: var(--primary); color: var(--primary-text); font-weight: 600; }
.seg.years button.active .muted { color: inherit; opacity: .8; }
.chart-wrap { position: relative; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.chart-wrap .bar { fill: var(--primary); }
.chart-wrap .grid { stroke: var(--border); stroke-width: 1; }
.chart-wrap .tick { fill: var(--muted); font-size: 10px; }
.chart-wrap .tick.future { opacity: .45; }
.chart-wrap .val { fill: var(--text); font-size: 10px; font-weight: 600; }
.chart-wrap .hit { fill: transparent; cursor: pointer; }
.chart-tip { position: absolute; top: -4px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  font-size: .8rem; padding: .3rem .55rem; border-radius: 8px; white-space: nowrap; pointer-events: none; }
table.mini { width: 100%; border-collapse: collapse; margin-top: .4rem; font-size: .75rem; text-align: center; }
table.mini th { color: var(--muted); font-weight: 400; }
table.mini td, table.mini th { padding: .2rem 0; border-bottom: 1px solid var(--border); }

/* messaggi nuovi e risposte */
.msg.new { border-left-color: var(--bad); }
.badge.new-badge { background: var(--bad); color: #fff; margin-bottom: .2rem; }
.reply-box:not(:empty) { margin-top: .5rem; }

/* riquadro dell'impresa funebre */
.funeral-row { display: flex; align-items: center; gap: .8rem; margin: .4rem 0 .6rem; }
.funeral-row img { max-height: 56px; max-width: 140px; object-fit: contain; border-radius: 6px; background: #fff; }
.florist-box .florist { border-top: 1px solid var(--border); padding-top: .5rem; margin-top: .6rem; }
.florist-box .funeral-row { margin: .2rem 0 .4rem; }
.florist-box .row .btn { white-space: nowrap; padding-left: .5rem; padding-right: .5rem; }

/* Avviso ben visibile nella schermata "Controlla la tua email" */
.spam-note { margin: 1rem 0; padding: .75rem .9rem; border-radius: 10px; font-size: .9rem; line-height: 1.45;
  background: color-mix(in srgb, var(--warn) 14%, transparent); border-left: 4px solid var(--warn); }
