/* Reach: stile dell'app. Chiaro e scuro automatici, margini sicuri dell'iPhone, niente librerie. */
:root {
  --bg: #f4f6fb; --card: #ffffff; --ink: #0d1530; --ink2: #3b4560; --muted: #6b7591; --line: #e5e9f2; --soft: #eef2fb;
  --accent: #2f6bff; --accent2: #1f4fd6; --accent-soft: #e8efff; --on-accent: #ffffff;
  --red: #e5484d; --orange: #f76b15; --violet: #8e4ec6; --blue: #0090ff; --green: #2f9e6b; --gray: #8b8fa3; --yellow: #f5b300;
  --shadow: 0 1px 2px rgba(13, 21, 48, .05), 0 6px 20px rgba(13, 21, 48, .06);
  --r: 16px; --top: env(safe-area-inset-top, 0px); --bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0f1f; --card: #131a2e; --ink: #edf1fb; --ink2: #c3cbe0; --muted: #8b95b3; --line: #232c45; --soft: #1a2238;
    --accent: #5b8cff; --accent2: #7aa2ff; --accent-soft: #1c2a52; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; -webkit-font-smoothing: antialiased; }
body { overscroll-behavior-y: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--ink); }
a { color: var(--accent); text-decoration: none; }
svg { width: 22px; height: 22px; display: block; flex: none; }
.hidden { display: none !important; }

/* ---------- impalcatura */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.page { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.page.push { z-index: 20; animation: entra .22s ease-out; box-shadow: -8px 0 24px rgba(0, 0, 0, .08); }
@keyframes entra { from { transform: translateX(30%); opacity: .4; } to { transform: none; opacity: 1; } }
.head { padding: calc(var(--top) + 10px) 18px 10px; display: flex; align-items: center; gap: 10px; background: var(--bg); position: relative; z-index: 2; }
.head h1 { font-size: 30px; line-height: 1.1; margin: 0; letter-spacing: -.02em; font-weight: 800; flex: 1; min-width: 0; }
.head h2 { font-size: 17px; margin: 0; font-weight: 700; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; font-weight: 500; }
.ibtn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--ink2); flex: none; }
.ibtn:active { background: var(--soft); }
.ibtn.solid { background: var(--card); box-shadow: var(--shadow); }
.avatar-btn { width: 40px; height: 40px; border-radius: 50%; flex: none; }
.body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px calc(var(--bottom) + 96px); }
.page.push .body { padding-bottom: calc(var(--bottom) + 28px); }

/* ---------- barra delle schede */
.tabs { position: absolute; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: space-around;
  padding: 8px 6px calc(var(--bottom) + 6px); background: color-mix(in srgb, var(--card) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(18px); backdrop-filter: saturate(180%) blur(18px); border-top: 1px solid var(--line); }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--muted); padding: 4px 0; position: relative; }
.tab.on { color: var(--accent); }
.tab .badge { position: absolute; top: 0; left: 50%; margin-left: 6px; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }

/* ---------- elementi */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); margin: 0 0 12px; overflow: hidden; }
.card.pad { padding: 14px 16px; }
.sect { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 20px 4px 8px; display: flex; align-items: center; gap: 8px; }
.sect .n { background: var(--soft); color: var(--ink2); border-radius: 8px; padding: 1px 7px; font-size: 12px; letter-spacing: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); min-height: 60px; width: 100%; text-align: left; }
.row:first-child { border-top: 0; }
.row:active { background: var(--soft); }
.row .main { flex: 1; min-width: 0; }
.row .t1 { font-weight: 650; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .t2 { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.row .side { text-align: right; flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 12.5px; color: var(--muted); }
.row.unread .t1 { font-weight: 800; }
.row.unread::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; margin-left: -6px; }
.av { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 15px; color: #fff; flex: none; letter-spacing: .02em; }
.av.l { width: 64px; height: 64px; font-size: 22px; }
.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-da_rispondere { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
.st-interessato { color: var(--orange); background: color-mix(in srgb, var(--orange) 12%, transparent); }
.st-call { color: var(--violet); background: color-mix(in srgb, var(--violet) 12%, transparent); }
.st-preventivo { color: var(--blue); background: color-mix(in srgb, var(--blue) 12%, transparent); }
.st-trattativa { color: var(--green); background: color-mix(in srgb, var(--green) 13%, transparent); }
.st-attesa, .st-contattato { color: var(--gray); background: color-mix(in srgb, var(--gray) 13%, transparent); }
.st-chiusa { color: var(--gray); background: var(--soft); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 48px; padding: 0 20px; border-radius: 14px; font-weight: 700; font-size: 16px;
  background: var(--accent); color: var(--on-accent); width: 100%; }
.btn:active { background: var(--accent2); }
.btn.sec { background: var(--soft); color: var(--ink); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.sm { height: 36px; padding: 0 14px; font-size: 14px; border-radius: 11px; width: auto; }
.btn.danger { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); }
.btn[disabled] { opacity: .5; }
.field { display: block; width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 14px; padding: 13px 14px; font-size: 16px; outline: none; }
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.field { min-height: 110px; resize: vertical; line-height: 1.45; }
.label { font-size: 13px; color: var(--muted); font-weight: 600; margin: 14px 2px 6px; display: block; }
.search { display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 14px; padding: 0 12px; box-shadow: var(--shadow); margin: 4px 0 12px; }
.search svg { color: var(--muted); width: 19px; height: 19px; }
.search input { flex: 1; border: 0; background: transparent; height: 46px; outline: none; font-size: 16px; min-width: 0; }
.seg { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 12px; padding: 0 16px; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 34px; padding: 0 14px; border-radius: 17px; background: var(--card); color: var(--ink2); font-weight: 650; font-size: 14px; box-shadow: var(--shadow); display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--ink); color: var(--bg); }
.chip .n { font-size: 12px; opacity: .7; }
.empty { text-align: center; color: var(--muted); padding: 50px 24px; font-size: 15px; line-height: 1.5; }
.empty svg { width: 44px; height: 44px; margin: 0 auto 12px; opacity: .5; }
.spin { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: gira .8s linear infinite; margin: 40px auto; }
.spin.sm { width: 18px; height: 18px; border-width: 2.5px; margin: 0; }
@keyframes gira { to { transform: rotate(360deg); } }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- oggi */
.hero { padding: 6px 4px 4px; }
.hero .count { font-size: 15px; color: var(--muted); font-weight: 600; margin-top: 4px; }
.todo { padding: 14px 16px 12px; border-top: 1px solid var(--line); position: relative; }
.todo:first-child { border-top: 0; }
.todo .top { display: flex; align-items: flex-start; gap: 10px; }
.todo .az { font-weight: 750; font-size: 16.5px; flex: 1; min-width: 0; }
.todo .when { font-size: 12.5px; color: var(--muted); font-weight: 600; flex: none; margin-top: 2px; }
.todo .when.late { color: var(--red); }
.todo .desc { color: var(--ink2); font-size: 14px; margin-top: 4px; line-height: 1.4; }
.todo .quote { margin-top: 8px; font-size: 14px; color: var(--ink2); background: var(--soft); border-radius: 12px; padding: 9px 11px; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.sus { display: flex; gap: 9px; align-items: flex-start; margin-top: 9px; font-size: 14px; line-height: 1.4; color: var(--ink); }
.sus svg { width: 18px; height: 18px; color: var(--violet); margin-top: 1px; }
.sus b { color: var(--violet); font-weight: 700; }
.acts { display: flex; gap: 8px; margin-top: 11px; flex-wrap: wrap; }
.act { height: 34px; padding: 0 12px; border-radius: 10px; background: var(--soft); color: var(--ink); font-size: 13.5px; font-weight: 650; display: inline-flex; align-items: center; gap: 6px; }
.act svg { width: 17px; height: 17px; }
.act.pri { background: var(--accent); color: var(--on-accent); }
.act.ok { background: color-mix(in srgb, var(--green) 14%, transparent); color: var(--green); }
.ph { width: 4px; position: absolute; left: 0; top: 14px; bottom: 14px; border-radius: 0 4px 4px 0; }
.ph-1 { background: var(--red); } .ph-2 { background: var(--orange); } .ph-3 { background: var(--blue); } .ph-4 { background: var(--green); } .ph-0 { background: var(--gray); }
.appt { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }
.appt:first-child { border-top: 0; }
.appt .hour { font-weight: 800; font-size: 17px; width: 52px; color: var(--violet); }

/* ---------- pipeline */
.board { display: flex; gap: 12px; overflow-x: auto; margin: 0 -16px; padding: 0 16px 10px; scroll-snap-type: x mandatory; }
.col { flex: 0 0 82%; max-width: 340px; scroll-snap-align: start; }
.col h3 { font-size: 14px; margin: 4px 4px 8px; display: flex; align-items: center; gap: 8px; }
.mini { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 9px; width: 100%; text-align: left; display: block; }
.mini .t1 { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini .t2 { color: var(--muted); font-size: 13px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- scheda lead */
.lhero { display: flex; gap: 14px; align-items: center; padding: 6px 4px 14px; }
.lhero .nm { font-size: 23px; font-weight: 800; letter-spacing: -.01em; line-height: 1.15; }
.lhero .ml { color: var(--muted); font-size: 14px; margin-top: 3px; word-break: break-all; }
.quick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 14px; }
.qa { background: var(--card); box-shadow: var(--shadow); border-radius: 14px; padding: 11px 2px 9px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; font-weight: 650; color: var(--ink2); }
.qa svg { color: var(--accent); }
.qa[disabled] { opacity: .4; }
.tl { padding: 4px 0; }
.tli { display: flex; gap: 12px; padding: 11px 16px; border-top: 1px solid var(--line); }
.tli:first-child { border-top: 0; }
.tli .ic { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--soft); color: var(--ink2); }
.tli .ic svg { width: 17px; height: 17px; }
.tli .k { font-size: 13px; font-weight: 700; }
.tli .x { font-size: 14px; color: var(--ink2); margin-top: 2px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.tli .q { font-size: 12px; color: var(--muted); margin-left: auto; flex: none; padding-left: 8px; }
.kv { display: flex; padding: 11px 16px; border-top: 1px solid var(--line); gap: 12px; font-size: 15px; }
.kv:first-child { border-top: 0; }
.kv .k { color: var(--muted); width: 110px; flex: none; font-size: 14px; }
.kv .v { flex: 1; min-width: 0; word-break: break-word; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; padding: 12px 6px; }
.stats3 b { display: block; font-size: 20px; }
.stats3 span { font-size: 12px; color: var(--muted); }
.bub { max-width: 88%; border-radius: 16px; padding: 10px 13px; margin: 8px 0; font-size: 14.5px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.bub.loro { background: var(--card); box-shadow: var(--shadow); border-top-left-radius: 5px; }
.bub.noi { background: var(--accent); color: var(--on-accent); margin-left: auto; border-top-right-radius: 5px; }
.bub .m { font-size: 11.5px; opacity: .7; margin-bottom: 4px; font-weight: 600; }

/* ---------- posta */
.mailhead { padding: 4px 4px 12px; }
.mailhead .ogg { font-size: 21px; font-weight: 800; line-height: 1.25; margin-bottom: 10px; }
.mailhead .who { display: flex; gap: 11px; align-items: center; }
.mailhead .meta { font-size: 13px; color: var(--muted); margin-top: 2px; word-break: break-word; }
.mailbody { background: #fff; color: #111; border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.mailbody iframe { width: 100%; border: 0; display: block; min-height: 120px; background: #fff; }
.mailbody pre { white-space: pre-wrap; word-break: break-word; font: 15px/1.5 var(--font); margin: 0; padding: 14px 16px; }
.att { display: flex; gap: 10px; align-items: center; padding: 11px 14px; border-top: 1px solid var(--line); width: 100%; text-align: left; }
.mailbar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; padding: 10px 16px calc(var(--bottom) + 10px); background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); border-top: 1px solid var(--line); }
.mailbar .btn { height: 44px; font-size: 15px; }
.comp .rowf { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); padding: 0 2px; }
.comp .rowf label { color: var(--muted); font-size: 15px; width: 58px; flex: none; }
.comp .rowf input { flex: 1; border: 0; background: transparent; height: 48px; outline: none; font-size: 16px; min-width: 0; }
.comp textarea { width: 100%; border: 0; background: transparent; outline: none; min-height: 260px; padding: 14px 2px; font-size: 16px; line-height: 1.5; resize: none; }
.attlist { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.attlist .chip { box-shadow: none; background: var(--soft); }
.fab { position: absolute; right: 18px; bottom: calc(var(--bottom) + 82px); width: 58px; height: 58px; border-radius: 20px; background: var(--accent); color: #fff; display: grid; place-items: center;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 45%, transparent); z-index: 9; }
.fab svg { width: 26px; height: 26px; }

/* ---------- numeri */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; }
.kpi b { font-size: 28px; font-weight: 800; letter-spacing: -.02em; display: block; }
.kpi span { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi small { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.chartw { padding: 14px 12px 8px; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin: 0 4px 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chat { display: flex; flex-direction: column; gap: 8px; padding: 10px 0; }
.msg { border-radius: 16px; padding: 11px 13px; font-size: 14.5px; line-height: 1.45; max-width: 92%; word-break: break-word; }
.msg.io { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 5px; }
.msg.lei { background: var(--card); box-shadow: var(--shadow); align-self: flex-start; border-bottom-left-radius: 5px; overflow-x: auto; }
.msg.lei table { border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.msg.lei td, .msg.lei th { border-bottom: 1px solid var(--line); padding: 5px 7px; text-align: left; white-space: nowrap; }
.msg.lei ul, .msg.lei ol { padding-left: 18px; margin: 6px 0; }
.ex { display: block; width: 100%; text-align: left; background: var(--card); box-shadow: var(--shadow); border-radius: 12px; padding: 11px 13px; font-size: 14px; margin-bottom: 8px; color: var(--ink2); }
.askbar { display: flex; gap: 8px; align-items: flex-end; }
.askbar textarea { flex: 1; min-height: 46px; max-height: 120px; border-radius: 14px; }
.askbar .ibtn { background: var(--accent); color: #fff; width: 46px; height: 46px; border-radius: 14px; }

/* ---------- foglio dal basso, avvisi */
.veil { position: fixed; inset: 0; background: rgba(5, 10, 25, .42); z-index: 50; animation: sfuma .18s ease-out; }
@keyframes sfuma { from { opacity: 0; } }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; background: var(--bg); border-radius: 22px 22px 0 0; max-height: 92%; display: flex; flex-direction: column;
  animation: sale .24s cubic-bezier(.2, .9, .3, 1); padding-bottom: var(--bottom); }
@keyframes sale { from { transform: translateY(100%); } }
.sheet .grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 2px; flex: none; }
.sheet .sh { display: flex; align-items: center; padding: 8px 16px 6px; gap: 8px; }
.sheet .sh h3 { flex: 1; margin: 0; font-size: 18px; font-weight: 800; }
.sheet .sb { overflow-y: auto; padding: 4px 16px 18px; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0 4px; }
.opt { background: var(--card); box-shadow: var(--shadow); border-radius: 13px; padding: 13px 12px; font-weight: 650; font-size: 14.5px; text-align: left; }
.opt::first-letter { text-transform: uppercase; }
.opt.on { outline: 2px solid var(--accent); color: var(--accent); }
.toast { position: fixed; left: 50%; bottom: calc(var(--bottom) + 92px); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 14px;
  font-weight: 650; font-size: 14.5px; z-index: 80; box-shadow: var(--shadow); animation: sale .2s ease-out; max-width: 90%; text-align: center; }

/* ---------- accesso */
.login { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: calc(var(--top) + 30px) 26px calc(var(--bottom) + 30px); max-width: 460px; margin: 0 auto; width: 100%; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 34px; }
.brand .mark { width: 52px; height: 52px; border-radius: 15px; background: linear-gradient(135deg, #2f6bff, #6e46ff); display: grid; place-items: center; color: #fff;
  box-shadow: 0 10px 26px rgba(47, 107, 255, .35); }
.brand .mark svg { width: 30px; height: 30px; stroke-width: 2.2; }
.brand .w { font-size: 30px; font-weight: 850; letter-spacing: -.02em; }
.brand .w small { display: block; font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: 0; }
.login h1 { font-size: 26px; margin: 0 0 6px; letter-spacing: -.01em; }
.login p { color: var(--muted); margin: 0 0 22px; line-height: 1.45; }
.login .field { margin-bottom: 12px; }
.code { letter-spacing: .5em; text-align: center; font-size: 26px; font-weight: 800; }
.err { color: var(--red); font-size: 14px; font-weight: 600; min-height: 20px; margin: 4px 2px 8px; }
.splash { flex: 1; display: grid; place-items: center; }
@media (min-width: 760px) { .body { max-width: 760px; margin: 0 auto; width: 100%; } .col { flex-basis: 300px; } }
