/* ===== Hub — nero + blu elettrico. Compatto su computer, arioso su telefono. ===== */
:root {
  --bg: #0A0A0B; --side: #0F0F12; --card: #141417; --card-2: #1B1B20; --field: #0F0F12;
  --line: #222228; --line-2: #2A2A31; --row: #1C1C21;
  --ink: #F2F2F2; --soft: #D4D4DA; --muted: #A1A1AA;
  --accent: #2F6BFF; --accent-ink: #FFFFFF; --accent-soft: #172341; --accent-text: #9DBBFF;
  --link: #6B97FF; /* il blu pieno su nero non basta per il testo piccolo: i link usano questo */
  --good: #4ADE80; --bad: #F87171; --warn: #FBBF24;
  --good-soft: rgba(74, 222, 128, .12); --bad-soft: rgba(248, 113, 113, .12); --warn-soft: rgba(251, 191, 36, .12);
  --radius: 12px; --side-w: 232px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin: 0; }
h2 { font-size: 15px; font-weight: 700; margin: 0 0 10px; } h3 { font-size: 13.5px; font-weight: 600; margin: 0 0 6px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .err { color: var(--bad); min-height: 1em; }
a { color: var(--link); text-decoration: none; } a:hover { color: var(--accent-text); }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.eyebrow { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }

/* ===== Struttura: barra laterale + contenuto ===== */
.shell { min-height: 100vh; display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); }
.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--side); border-right: 1px solid var(--line);
  padding: 20px 12px; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; font-size: 15px; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; overflow: hidden; flex: none; }
.logo img { width: 100%; height: 100%; object-fit: cover; }
.logo.big { width: 64px; height: 64px; border-radius: 14px; font-size: 26px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #B4B4BD; font-weight: 500; }
.nav a:hover { background: var(--card); color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: #FFFFFF; font-weight: 600; }
.nav a.active svg { color: var(--link); }
.count { margin-left: auto; font-size: 11px; background: #1E1E24; color: var(--soft); padding: 1px 7px; border-radius: 99px; }
.count:empty { display: none; }
.me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; border: 1px solid var(--line); color: var(--ink); }
.me:hover, .me.active { border-color: var(--line-2); background: var(--card); color: var(--ink); }
.me span { display: flex; flex-direction: column; line-height: 1.3; } .me small { color: var(--muted); font-size: 11px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; background: #26324D; color: var(--accent-text); overflow: hidden; flex: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.big { width: 96px; height: 96px; font-size: 34px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 28px; border-bottom: 1px solid var(--line); }
.ask { flex: 1; max-width: 520px; }
.ask input { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.iconbtn { width: 44px; height: 44px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); color: var(--ink); display: none; place-items: center; cursor: pointer; flex: none; }
.iconbtn svg { width: 20px; height: 20px; }
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 30; }
.view { padding: 24px 28px 48px; min-width: 0; width: 100%; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }

/* Telefono: menu a scomparsa, tutto più grande e arioso */
@media (max-width: 860px) {
  body { font-size: 15px; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; left: 0; top: 0; bottom: 0; height: auto; width: min(300px, 86vw); z-index: 40; transform: translateX(-100%); transition: transform .2s ease; }
  .shell.open .side { transform: none; }
  .iconbtn { display: grid; }
  .topbar { padding: 12px 16px; }
  .view { padding: 18px 16px 40px; }
  h1 { font-size: 21px; }
  .nav a { padding: 12px 10px; }
  .btn { min-height: 44px; }
  .btn.sm { min-height: 38px; }
  .item { flex-wrap: wrap; }
  .item > .row { width: 100%; }
}

/* ===== Componenti ===== */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) { .g2, .g3 { grid-template-columns: 1fr; } .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.cols { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.cols > .wide { flex: 999 1 520px; min-width: 0; } .cols > .narrow { flex: 1 1 300px; min-width: 0; }

.btn {
  font: inherit; font-size: 13.5px; font-weight: 600; border: 1px solid var(--line-2); background: var(--card); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { background: var(--card-2); color: var(--ink); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { background: #2559E0; color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: wait; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--field); border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 11px; width: 100%; }
textarea { min-height: 90px; resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Schede sottolineate, come le code di Meta Ads */
.tabs { display: flex; gap: 4px; margin-bottom: 18px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tabs button { font: inherit; font-weight: 600; background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: 10px 12px; color: #B4B4BD; cursor: pointer; white-space: nowrap; }
.tabs button.active { color: #FFFFFF; border-bottom-color: var(--accent); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 500; background: #1E1E24; color: var(--soft); white-space: nowrap; }
.pill.good { background: var(--accent-soft); color: var(--accent-text); } /* "buono" per il lavoro = blu, non verde */
.pill.bad { background: var(--bad-soft); color: var(--bad); } .pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.accent { background: var(--accent-soft); color: var(--accent-text); }
.need { display: inline-block; min-width: 46px; text-align: center; font-size: 11px; font-weight: 700; padding: 3px 0; border-radius: 6px; background: #1E1E24; color: var(--soft); }
.need.n4, .need.n3 { background: var(--accent); color: #FFFFFF; } .need.n2 { background: var(--accent-soft); color: var(--accent-text); }

.list { display: flex; flex-direction: column; }
.item { display: flex; gap: 12px; align-items: flex-start; padding: 11px 0; border-bottom: 1px solid var(--row); }
.item:last-child { border-bottom: 0; }
.item .time { font-variant-numeric: tabular-nums; color: var(--accent-text); min-width: 48px; font-weight: 600; }
/* Barra in alto: su computer nota veloce; sul telefono ☰ + titolo + foto */
.top-title, .top-me, .lbl-m { display: none; }
.calls { padding: 0; overflow: hidden; }
.calls-head { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.calls-body { padding: 0 16px; }
.calls-more { padding: 10px 16px; border-top: 1px solid var(--line); }
.cr-act { display: flex; align-items: center; gap: 8px; }

/* Riga "Chiama adesso": in linea su computer; sul telefono nome sopra, dettagli sotto, pulsante largo */
.callrow { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--row); }
.callrow:last-child { border-bottom: 0; }
.cr-who { flex: 1; min-width: 0; } .cr-who a { color: var(--ink); } .cr-who a:hover { color: var(--accent-text); }
@media (max-width: 860px) {
  .ask { display: none; }
  .top-title { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.2; }
  .top-title .tt { font-size: 21px; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .top-me { display: block; } .top-me .avatar { width: 40px; height: 40px; }
  /* il titolo è già nella barra: nella pagina restano solo i pulsanti (se ci sono) */
  .view > .head > div:first-child { display: none; }
  .view > .head:not(:has(> :nth-child(2))), .view > .head:not(:has(> :not(:first-child):not(.desk-only))) { display: none; }
  .lbl-d { display: none; } .lbl-m { display: inline; }
  .desk-only { display: none !important; }
  /* 3 numeri su una riga: prima il numero, poi l'etichetta */
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px !important; }
  .stats > div:nth-child(4), .stats .note { display: none; }
  .stats > div { display: flex; flex-direction: column; padding: 10px 12px !important; }
  .stats .stat { order: -1; font-size: 20px; }
  /* "Chiama adesso": una scheda per lead, come l'anteprima */
  .calls { background: none; border: 0; overflow: visible; }
  .calls-head { padding: 4px 0 10px; border: 0; }
  .calls-head h2 { font-size: 16px; }
  .calls-body { padding: 0; }
  .calls-more { border: 0; padding: 2px 0 6px; }
  .callrow { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px 10px; align-items: center;
    background: var(--card); border: 1px solid var(--line) !important; border-radius: 14px; padding: 14px; margin-bottom: 10px; }
  .cr-who b { font-size: 15px; }
  .cr-act { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .cr-act .btn { min-height: 44px; font-size: 15px; }
  .cr-act .primary { order: -1; }
  .cr-act .btn:only-child { grid-column: 1 / -1; }
}
.clickable { cursor: pointer; border-radius: 8px; } .clickable:hover { background: var(--card-2); }
details > summary { cursor: pointer; padding: 6px 0; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 8px; border-bottom: 1px solid var(--line); }
td { padding: 10px 8px; border-bottom: 1px solid var(--row); vertical-align: top; }
tr.clickable:hover td { background: var(--card-2); }
.table-wrap { overflow-x: auto; }

.stat { font-size: 22px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.grid > div:has(> .stat) { padding: 12px 14px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); }
.card .grid > div:has(> .stat) { background: var(--field); }
.bar { height: 6px; background: #1E1E24; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

.banner { border-radius: var(--radius); padding: 12px 16px; background: var(--accent-soft); border: 1px solid #22345E; }
.banner.warn { background: var(--warn-soft); border-color: rgba(251, 191, 36, .3); }
.commit { display: flex; gap: 10px; } .commit b { color: var(--accent-text); }

.score { font-weight: 700; font-variant-numeric: tabular-nums; }
.score.lo { color: var(--bad); } .score.mid { color: var(--warn); } .score.hi { color: var(--good); }

.phase-chart { display: flex; flex-direction: column; gap: 8px; }
.phase-row { display: grid; grid-template-columns: 120px 1fr 1fr; gap: 8px; align-items: center; font-size: 13px; }
.phase-row .neg { display: flex; justify-content: flex-end; } .phase-row .neg i { background: var(--bad); }
.phase-row .pos i { background: var(--accent); }
.phase-row i { display: block; height: 12px; border-radius: 99px; min-width: 2px; }
.phase-row span.n { font-size: 12px; color: var(--muted); padding: 0 6px; }

.rec { width: 64px; height: 64px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 22px; cursor: pointer; }
.rec.on { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 12px rgba(47, 107, 255, .25); } }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(120px); background: var(--card-2); border: 1px solid var(--line-2); color: var(--ink); padding: 10px 16px; border-radius: 10px; transition: transform .2s; z-index: 50; max-width: 90vw; font-size: 14px; }
.toast.show { transform: translateX(-50%) translateY(0); }

dialog { background: var(--card); border: 1px solid var(--line-2); border-radius: 14px; padding: 0; color: var(--ink); width: min(780px, 94vw); max-height: 88vh; }
dialog::backdrop { background: rgba(0, 0, 0, .7); }
#modalBody { padding: 22px; overflow: auto; max-height: 88vh; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px 24px; }
.linkbtn { font: inherit; font-size: 13px; background: none; border: 0; color: var(--link); cursor: pointer; padding: 4px 0; align-self: flex-start; }
.linkbtn:hover { color: var(--accent-text); }

.prose p { margin: 0 0 8px; } .prose ul { margin: 4px 0 8px; padding-left: 18px; }
.qa { border-left: 3px solid var(--accent); padding-left: 12px; }
.empty { color: var(--muted); padding: 16px 0; text-align: center; }
.day-card { padding: 0; overflow: hidden; }
.day-head { display: flex; gap: 8px; align-items: baseline; padding: 11px 16px; border-bottom: 1px solid var(--line); }
.day-card .list { padding: 0 16px; }
.ev-bar { width: 3px; align-self: stretch; border-radius: 99px; background: #3A3A44; flex: none; }
.ev-bar.k-appuntamento { background: var(--accent); } .ev-bar.k-impegno { background: var(--warn); } .ev-bar.k-studio { background: var(--accent-text); }
.cal-day { margin-bottom: 18px; } .cal-day h3 { color: var(--muted); font-size: 13px; text-transform: capitalize; }
pre.msg { white-space: pre-wrap; font: inherit; margin: 0; }

@media (prefers-reduced-motion: reduce) {
  .side, .toast { transition: none; }
  .rec.on { animation: none; }
}

/* ===== Meta Ads: code, filtri, modalità chiamata e tabella ===== */
.qtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.qtabs button { font: inherit; font-weight: 600; background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: 10px 12px; color: #B4B4BD; cursor: pointer; white-space: nowrap; }
.qtabs button span { color: var(--muted); font-weight: 500; }
.qtabs button.on { color: #FFFFFF; border-bottom-color: var(--accent); }
.chip { font: inherit; font-size: 12px; font-weight: 600; background: var(--card); color: var(--soft); border: 1px solid var(--line-2); border-radius: 99px; padding: 5px 12px; cursor: pointer; }
.chip.on { background: var(--accent-soft); color: #FFFFFF; border-color: #22345E; }
.seg { display: flex; padding: 3px; gap: 2px; background: var(--card); border: 1px solid var(--line); border-radius: 9px; }
.seg button { font: inherit; font-size: 12.5px; font-weight: 600; background: none; border: 0; color: var(--muted); padding: 6px 12px; border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--accent-soft); color: #FFFFFF; }

.msplit { display: flex; gap: 16px; align-items: flex-start; }
.mlist { flex: 0 1 360px; min-width: 260px; padding: 0; overflow: hidden; max-height: calc(100vh - 230px); overflow-y: auto; }
.mcard { flex: 1 1 auto; min-width: 0; padding: 20px 22px; position: sticky; top: 16px; }
.qrow { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--row); color: var(--ink); }
.qrow:hover { background: var(--card-2); color: var(--ink); }
.qrow.on { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.qname { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.qname b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qname a { color: var(--ink); }
.inset { background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.inset.blue { background: var(--accent-soft); border-color: #22345E; color: #FFFFFF; }
.label { color: var(--muted); font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.inset.blue .label { color: var(--accent-text); }
.soft { color: var(--soft); }
.btn.big { font-size: 15px; padding: 12px 18px; }
.only-phone { display: none !important; }

.mtable { padding: 0; overflow-x: auto; }
.mt-inner { min-width: 900px; }
.mt-row { display: grid; gap: 12px; align-items: center; padding: 10px 16px; }
.mt-row > div { min-width: 0; }
.mt-head { color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); }
.mt-item { border-bottom: 1px solid var(--row); }
.mt-item:last-child { border-bottom: 0; }
.mt-item [data-open] { cursor: pointer; }
.mt-item [data-open]:hover, .mt-item.open { background: #17171B; }
.mt-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 20px; padding: 4px 16px 16px 98px; background: #17171B; align-items: start; }

@media (max-width: 860px) {
  /* Telefono: la coda a tutto schermo; toccando un lead si apre la scheda chiamata al suo posto */
  .calling > .head, .calling > .qtabs, .calling > .meta-filters, .calling > .stats, .calling > h2, .calling > .mtable { display: none !important; }
  .msplit { display: block; }
  .mlist { max-height: none; min-width: 0; }
  .mcard { display: none; position: static; padding: 16px; }
  .msplit.sel .mlist { display: none; }
  .msplit.sel .mcard { display: block; }
  .only-phone { display: flex !important; }
  .mcard .btn.big { width: 100%; min-height: 54px; font-size: 16px; }
  .mcard .row[data-ml] { display: grid; grid-template-columns: 1fr 1fr; }
  .mcard .row[data-ml] .spacer { display: none; }
  .mcard .row[data-ml] #mNext { grid-column: 1 / -1; text-align: center; padding: 10px; }
  .mt-detail { grid-template-columns: 1fr; padding-left: 16px; }
}

/* ===== Impostazioni ===== */
.subnav { flex: 0 0 200px; display: flex; flex-direction: column; gap: 2px; }
.subnav button { font: inherit; font-weight: 500; text-align: left; background: none; border: 0; color: #B4B4BD; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.subnav button:hover { background: var(--card); color: var(--ink); }
.subnav button.on { background: var(--accent-soft); color: #FFFFFF; font-weight: 600; }
.niche { border-bottom: 1px solid var(--row); }
.switch { position: relative; display: inline-flex; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span[aria-hidden] { width: 46px; height: 26px; border-radius: 99px; background: #2A2A31; position: relative; transition: background .15s; }
.switch span[aria-hidden]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #FFFFFF; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.chip-check { flex-direction: row; cursor: pointer; }
.chip-check input { position: absolute; opacity: 0; width: 1px; }
.chip-check span { font-size: 12.5px; font-weight: 600; padding: 7px 12px; border-radius: 99px; background: var(--card); border: 1px solid var(--line-2); color: var(--soft); }
.chip-check input:checked + span { background: var(--accent-soft); border-color: #22345E; color: #FFFFFF; }
.chip-check input:focus-visible + span { outline: 2px solid var(--accent); }
@media (max-width: 860px) {
  .subnav { flex: 1 1 100%; flex-direction: row; overflow-x: auto; }
  .subnav button { white-space: nowrap; }
  /* Nicchie sul telefono: nome + annunci + ✕ sopra, parola cercata sotto (le etichette diventano i segnaposto) */
  .mt-head:has(+ #mNiches) { display: none; }
  .niche { grid-template-columns: minmax(0, 1fr) 90px 44px !important; gap: 8px !important; }
  .niche [data-k="query"] { grid-column: 1 / -1; grid-row: 2; }
}
