/* ============================================================
   App prototype — mobile-first. Loaded after tokens.css.
   The whole app is a single 430px column; screens toggle via JS.
   ============================================================ */

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

/* On wide screens (standalone view) center the column in a phone shell.
   In embed mode the host iframe is already phone-sized, so we fill it. */
body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
body:not(.embed) {
  min-height: 100%;
  padding: 32px;
  background:
    radial-gradient(120% 80% at 50% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
}

.app {
  position: relative;
  width: 100%;
  max-width: 430px;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}
body:not(.embed) .app {
  height: 880px;
  max-height: calc(100vh - 64px);
  border-radius: 44px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow), 0 0 0 11px color-mix(in oklch, var(--bg-2), #000 12%), 0 0 0 12px var(--border);
}

/* ---------- status bar ---------- */
.statusbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 26px 6px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text);
}
.statusbar .dots { display: flex; gap: 5px; align-items: center; }
.statusbar .dots i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-2);
}
.statusbar .batt {
  width: 22px; height: 11px; border-radius: 3px;
  border: 1.5px solid var(--text-2); position: relative;
}
.statusbar .batt::after {
  content: ""; position: absolute; inset: 1.5px; right: 40%;
  background: var(--text-2); border-radius: 1px;
}

/* ---------- screens ---------- */
.screens { position: relative; flex: 1 1 auto; min-height: 0; }
.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
}
.screen.is-active { display: flex; }

.scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 18px 120px;
  scrollbar-width: none;
}
.scroll::-webkit-scrollbar { display: none; }

/* ---------- app bar ---------- */
.appbar { padding: 8px 4px 14px; }
.appbar .kick {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
  display: flex; align-items: center; gap: 7px;
}
.appbar .kick::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.appbar h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 26px;
  letter-spacing: -.02em;
  margin-top: 8px;
  line-height: 1.05;
}
.appbar .sub { color: var(--text-2); font-size: 13.5px; margin-top: 6px; }

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  padding: 16px;
}
.card + .card, .stack > * + * { margin-top: 12px; }
.stack { display: block; }

.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }

.muted { color: var(--text-2); }
.tiny { font-size: 12px; }
.mono-label {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--text-3);
}

/* ---------- tags (semantic, palette-independent) ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase;
  padding: 4px 9px; border-radius: 999px;
  border: 1px solid currentColor;
}
.tag i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag.interesse { color: var(--accent); }
.tag.obiezione { color: var(--danger); }
.tag.accordo   { color: var(--ok); }
.tag.scadenza  { color: var(--warn); }
.tag.solid {
  border-color: transparent; color: var(--accent-ink);
  background: var(--accent);
}

/* avatar */
.avatar {
  width: 42px; height: 42px; border-radius: 13px; flex: 0 0 auto;
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 600; font-size: 16px;
  color: var(--accent-ink);
  background: linear-gradient(150deg, var(--accent-bright), var(--accent));
}
.avatar.lg { width: 56px; height: 56px; border-radius: 17px; font-size: 20px; }
.avatar.ghost { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border-2); }

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer;
  font-family: var(--font-body); font-weight: 600; font-size: 14px;
  padding: 11px 16px; border-radius: 12px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-2);
  transition: transform .12s var(--ease), background .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 8px 12px; font-size: 12.5px; border-radius: 10px; }
.btn.block { width: 100%; justify-content: center; display: flex; align-items: center; gap: 8px; }
.btn-ico { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }

/* ---------- record screen ---------- */
.rec {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column;
  padding: 6px 22px 28px;
  background:
    radial-gradient(120% 60% at 50% 12%, var(--accent-soft), transparent 62%);
}
.rec-ctx { text-align: center; margin: 6px 0 4px; }
.rec-ctx .who { font-family: var(--font-display); font-weight: 600; font-size: 19px; }
.rec-time {
  text-align: center; font-family: var(--font-mono); font-size: 34px;
  font-weight: 500; letter-spacing: .02em; margin: 2px 0 14px;
}
.rec-time .live {
  display: inline-flex; align-items: center; gap: 7px; font-size: 11px;
  letter-spacing: .14em; color: var(--danger); vertical-align: middle;
  margin-left: 10px; text-transform: uppercase;
}
.rec-time .live i {
  width: 8px; height: 8px; border-radius: 50%; background: var(--danger);
  animation: pulse 1.4s var(--ease) infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.7); } }

.wave { display: flex; align-items: center; justify-content: center; gap: 4px; height: 78px; margin: 4px 0 10px; }
.wave i {
  width: 5px; border-radius: 999px;
  background: linear-gradient(var(--accent-bright), var(--accent));
  animation: wv 1.1s var(--ease) infinite;
}
@keyframes wv { 0%,100% { height: 14%; opacity: .55; } 50% { height: 100%; opacity: 1; } }

.transcript {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--r-md); padding: 16px; margin-top: 6px;
  scrollbar-width: none;
}
.transcript::-webkit-scrollbar { display: none; }
.tx-line { display: flex; gap: 10px; padding: 7px 0; font-size: 14px; line-height: 1.45; }
.tx-line .t { font-family: var(--font-mono); font-size: 10px; color: var(--text-3); padding-top: 4px; flex: 0 0 38px; }
.tx-line .x { color: var(--text); }
.tx-line.detect .x { color: var(--text-2); }
.tx-chip {
  display: inline-block; vertical-align: baseline; margin-left: 6px;
}
.rec-bottom { display: flex; align-items: center; justify-content: center; gap: 22px; margin-top: 16px; }
.rec-stop {
  width: 66px; height: 66px; border-radius: 50%; cursor: pointer;
  border: 3px solid var(--border); background: var(--surface);
  display: grid; place-items: center;
}
.rec-stop i { width: 22px; height: 22px; border-radius: 5px; background: var(--danger); }
.rec-side { color: var(--text-2); font-size: 12px; text-align: center; width: 64px; }

/* note created banner */
.note-built {
  margin-top: 12px; border: 1px solid var(--accent-soft); background: var(--accent-soft);
  border-radius: 14px; padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start;
}

/* ---------- activity cards ---------- */
.act { position: relative; overflow: hidden; }
.act .type {
  display: flex; align-items: center; gap: 9px; margin-bottom: 10px;
}
.act .type .ico {
  width: 30px; height: 30px; border-radius: 9px; flex: 0 0 auto;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent);
}
.act .type .ico svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }
.act h3 { font-family: var(--font-display); font-weight: 600; font-size: 16px; letter-spacing: -.01em; }
.act .why {
  font-size: 13px; color: var(--text-2); line-height: 1.5; margin: 2px 0 12px;
}
.act .why b { color: var(--text); font-weight: 600; }
.act .src { font-family: var(--font-mono); font-size: 10px; color: var(--text-3); letter-spacing: .04em; }
.act .acts { display: flex; gap: 8px; margin-top: 13px; }
.act .acts .btn { flex: 1; justify-content: center; }
.act.done { opacity: .55; }
.act .stamp {
  position: absolute; top: 14px; right: 14px;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ok); display: none; align-items: center; gap: 5px;
}
.act.done .stamp { display: flex; }
.act.done .acts { display: none; }

/* progress header */
.prog { display: flex; align-items: center; gap: 10px; margin: 2px 0 14px; }
.prog .bar { flex: 1; height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.prog .bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s var(--ease); width: 0; }

/* promo banner */
.banner {
  display: flex; gap: 12px; align-items: center; cursor: pointer;
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  color: var(--accent-ink); border-radius: var(--r-md); padding: 14px 16px;
}
.banner .b-ico { width: 34px; height: 34px; border-radius: 10px; background: rgba(255,255,255,.22); display: grid; place-items: center; }
.banner svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }
.banner .arr { margin-left: auto; font-size: 20px; }

/* ---------- client scheda ---------- */
.client-head { display: flex; gap: 14px; align-items: flex-start; }
.client-head h2 { font-family: var(--font-display); font-weight: 600; font-size: 21px; letter-spacing: -.02em; }
.trend {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600;
  padding: 5px 10px; border-radius: 999px; margin-top: 8px;
  color: var(--danger); background: color-mix(in oklch, var(--danger), transparent 88%);
}
.segbar { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin: 16px 0 14px; }
.segbar button {
  flex: 1; appearance: none; border: 0; cursor: pointer; background: transparent;
  color: var(--text-2); font-family: var(--font-body); font-weight: 600; font-size: 12.5px;
  padding: 8px 4px; border-radius: 9px;
}
.segbar button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.18); }

.memo-list > li {
  list-style: none; display: flex; gap: 12px; padding: 13px 0;
  border-bottom: 1px solid var(--border-2);
}
.memo-list > li:last-child { border-bottom: 0; }
.memo-list .dot { flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%; margin-top: 5px; }
.memo-list .txt { font-size: 14px; line-height: 1.5; }
.memo-list .meta { font-family: var(--font-mono); font-size: 10px; color: var(--text-3); margin-top: 4px; letter-spacing: .03em; }

.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline .ev { position: relative; padding: 8px 0 14px; }
.timeline .ev::before { content: ""; position: absolute; left: -21px; top: 11px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.timeline .ev .d { font-family: var(--font-mono); font-size: 10px; color: var(--text-3); letter-spacing: .05em; }
.timeline .ev .h { font-weight: 600; font-size: 14.5px; margin: 2px 0 3px; }
.timeline .ev p { font-size: 13px; color: var(--text-2); line-height: 1.5; }

/* ---------- route / map (Leaflet + OpenStreetMap) ---------- */
.map {
  position: relative; height: 280px; border-radius: var(--r-md); overflow: hidden;
  border: 1px solid var(--border-2); background: var(--surface-2);
  z-index: 0; /* contain Leaflet's internal z-index (controls use 1000) below the sheet */
}
#leafmap { position: absolute; inset: 0; width: 100%; height: 100%; }
.leaflet-container { background: var(--surface-2); font-family: var(--font-body); outline: none; }
.leaflet-div-icon { background: transparent; border: 0; }
.leaflet-control-attribution { font-size: 9px; background: color-mix(in oklch, var(--surface), transparent 15%) !important; color: var(--text-3); }
.leaflet-control-attribution a { color: var(--text-2); }
.leaflet-bar a { background: var(--surface); color: var(--text); border-color: var(--border-2); }
.leaflet-bar a:hover { background: var(--surface-2); }

.mk {
  width: 30px; height: 30px; border-radius: 50% 50% 50% 2px; rotate: 45deg;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; box-shadow: 0 5px 14px var(--glow);
  border: 2px solid color-mix(in oklch, var(--accent-bright), #fff 20%); cursor: pointer;
  transition: transform .12s var(--ease);
}
.mk:hover { transform: rotate(45deg) scale(1.12); }
.mk span { rotate: -45deg; font-family: var(--font-mono); font-weight: 700; font-size: 12px; }
.mk.ghost { background: var(--surface-hi); color: var(--text-2); box-shadow: none; border-color: var(--border); }
.mk.me { width: 16px; height: 16px; border-radius: 50%; rotate: 0deg; cursor: default;
  background: var(--accent-2); border: 3px solid var(--bg);
  box-shadow: 0 0 0 4px color-mix(in oklch, var(--accent-2), transparent 70%); }
.mk.me:hover { transform: none; }

.route-stats { display: flex; gap: 8px; margin: 12px 0; }
.route-stats .s { flex: 1; background: var(--surface); border: 1px solid var(--border-2); border-radius: 14px; padding: 12px; text-align: center; }
.route-stats .s b { font-family: var(--font-display); font-size: 20px; font-weight: 600; display: block; }
.route-stats .s span { font-size: 11px; color: var(--text-2); }

.stop { display: flex; gap: 13px; align-items: flex-start; padding: 14px 0; border-bottom: 1px solid var(--border-2); cursor: pointer; }
.stop:last-child { border-bottom: 0; }
.stop-go { margin-left: auto; align-self: center; flex: 0 0 auto; color: var(--text-3); font-size: 22px; line-height: 1; transition: color .12s, transform .12s var(--ease); }
.stop:hover .stop-go { color: var(--accent); transform: translateX(2px); }
.stop:active { opacity: .7; }
.stop .n {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 13px;
  background: var(--accent); color: var(--accent-ink);
}
.stop .n.ghost { background: var(--surface-2); color: var(--text-2); }
.stop .name { font-weight: 600; font-size: 15px; }
.stop .det { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* ---------- promo match ---------- */
.match { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--border-2); }
.match:last-child { border-bottom: 0; }
.score { flex: 0 0 auto; width: 44px; text-align: right; font-family: var(--font-display); font-weight: 600; font-size: 18px; color: var(--accent); }
.score small { display: block; font-family: var(--font-mono); font-size: 9px; color: var(--text-3); font-weight: 500; }
.listino { display: flex; gap: 14px; align-items: center; }
.listino .ph {
  flex: 0 0 auto; width: 60px; height: 78px; border-radius: 10px; overflow: hidden;
  background:
    repeating-linear-gradient(135deg, var(--surface-2), var(--surface-2) 7px, var(--surface-hi) 7px, var(--surface-hi) 14px);
  border: 1px solid var(--border-2); display: grid; place-items: center;
}
.listino .ph span { font-family: var(--font-mono); font-size: 8px; color: var(--text-3); text-align: center; rotate: -8deg; }

/* ---------- report ---------- */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--r-md); padding: 15px; }
.kpi .v { font-family: var(--font-display); font-weight: 600; font-size: 27px; letter-spacing: -.02em; }
.kpi .l { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.kpi .delta { font-family: var(--font-mono); font-size: 11px; font-weight: 600; margin-top: 8px; display: inline-flex; gap: 4px; }
.kpi .delta.up { color: var(--ok); }
.kpi .delta.down { color: var(--danger); }

.bars { display: flex; align-items: flex-end; gap: 10px; height: 130px; padding-top: 8px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 7px; height: 100%; justify-content: flex-end; }
.bars .col .bar { width: 100%; max-width: 26px; border-radius: 7px 7px 3px 3px; background: linear-gradient(var(--accent-bright), var(--accent)); }
.bars .col .bar.soft { background: var(--surface-2); }
.bars .col .lab { font-family: var(--font-mono); font-size: 10px; color: var(--text-3); }

/* ---------- bottom nav + fab ---------- */
.tabbar {
  flex: 0 0 auto; position: relative; z-index: 5;
  display: flex; align-items: center; justify-content: space-around;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in oklch, var(--bg), transparent 8%);
  border-top: 1px solid var(--border-2);
  backdrop-filter: blur(20px);
}
.tab {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  color: var(--text-3); font-family: var(--font-body); font-size: 10px; font-weight: 600;
  padding: 4px 6px; flex: 1;
}
.tab svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.9; }
.tab.on { color: var(--accent); }

.tab.mic {
  flex: 0 0 auto; width: 58px; height: 58px; border-radius: 50%;
  margin-top: -24px; padding: 0; gap: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(150deg, var(--accent-bright), var(--accent));
  color: var(--accent-ink);
  box-shadow: 0 12px 28px var(--glow), 0 0 0 6px var(--bg);
  transition: transform .14s var(--ease);
}
.tab.mic:active { transform: scale(.92); }
.tab.mic svg { width: 25px; height: 25px; }
.tab.mic.on { color: var(--accent-ink); }

/* embed mode tweaks: hide phone shell + status detail nuance handled by body class */
body.embed .app { border-radius: 0; box-shadow: none; border: 0; }

/* ---------- stop preview bottom sheet ---------- */
.sheet { position: absolute; inset: 0; z-index: 1000; display: flex; align-items: flex-end; }
.sheet[hidden] { display: none; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.5); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); animation: sh-fade .2s ease; }
.sheet-card {
  position: relative; width: 100%;
  background: var(--surface); border: 1px solid var(--border-2); border-bottom: 0;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -20px 50px rgba(0,0,0,.45); animation: sh-up .26s var(--ease);
}
@keyframes sh-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sh-fade { from { opacity: 0; } to { opacity: 1; } }
.sheet-grip { width: 42px; height: 4px; border-radius: 999px; background: var(--border); margin: 2px auto 16px; }
.sheet-name { font-family: var(--font-display); font-weight: 600; font-size: 18px; letter-spacing: -.01em; }
.sheet-x { appearance: none; border: 0; cursor: pointer; flex: 0 0 auto;
  width: 32px; height: 32px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); font-size: 13px; }
.sheet-why { margin-top: 14px; background: var(--surface-2); border-radius: 14px; padding: 14px; }
.sheet-why p { font-size: 14px; line-height: 1.55; color: var(--text); }
