:root {
  --page: #E9E9EB;
  --panel: #F7F7F8;
  --card: #FFFFFF;
  --soft: #F5F5F7;
  --line: #EFEFF1;
  --ink: #111111;
  --ink-2: #4B4B52;
  --muted: #6B6B73;
  --black: #1A1A1A;
  --accent: #7FA6D6;
  --accent-ink: #0E2238;
  --accent-soft: #C9DBF0;
  --accent-text: #2B5689;
  --accent-stripe: #C9DBF0;
  --good-soft: #E8F6EE;
  --good: #1E7A46;
  --violet-soft: #EEEBFF;
  --violet: #4B3BB8;
  --danger: #B42318;
  color-scheme: light;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  font-size: 14px;
}
a { color: var(--accent-text); }
a:hover { color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; left: -9999px; }

.shell { padding: 24px; min-height: 100vh; }
.panel {
  background: var(--panel);
  border-radius: 32px;
  padding: 20px 24px 28px;
  max-width: 1360px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Barra in alto */
.topbar { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; color: var(--ink); text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center; font-size: 15px;
}
.tabs { background: var(--card); border-radius: 999px; padding: 5px; display: flex; flex-wrap: wrap; gap: 2px; }
.tabs a {
  padding: 10px 18px; border-radius: 999px; color: var(--ink-2); text-decoration: none;
  font-weight: 500; min-height: 40px; display: inline-flex; align-items: center;
}
.tabs a[aria-current="page"] { background: var(--black); color: #FFFFFF; }
.profile { background: var(--card); border-radius: 999px; padding: 5px 14px 5px 5px; display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--black); color: #FFFFFF;
  font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
.profile small { color: var(--muted); }

.body { display: flex; flex-wrap: wrap; gap: 20px; }
main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }

/* Blocchi */
h1 { margin: 0; font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.lead { margin: 6px 0 0; color: var(--muted); }
.head-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: end; justify-content: space-between; }
.card { background: var(--card); border-radius: 22px; padding: 20px; }
.soft { background: var(--soft); border-radius: 18px; }
.card h2 { margin: 0; font-size: 17px; font-weight: 700; }
.card .sub { font-size: 12px; color: var(--muted); }
.grid-12 { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; } .span-7 { grid-column: span 7; } .span-12 { grid-column: span 12; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.spread { justify-content: space-between; }
.big { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }
.label { font-size: 13px; color: var(--ink-2); }
.tile { padding: 16px; min-height: 120px; display: flex; flex-direction: column; justify-content: space-between; gap: 8px; }
.tile.accent { background: var(--accent); color: var(--accent-ink); border-radius: 18px; }
.tile.accent .label { color: var(--accent-ink); }
.tile.dark { background: var(--black); color: #FFFFFF; border-radius: 18px; }
.tile.dark .label { color: #BDBDC4; }

.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; border-radius: 999px; padding: 3px 9px; white-space: nowrap; }
.chip.blue { background: var(--accent-soft); color: var(--accent-text); }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.violet { background: var(--violet-soft); color: var(--violet); }
.chip.grey { background: #F1F1F3; color: var(--ink-2); }
.chip.on-accent { background: rgba(14, 34, 56, .12); color: var(--accent-ink); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }

.btn {
  border: 0; border-radius: 999px; min-height: 40px; padding: 0 16px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; text-decoration: none;
}
.btn.lg { min-height: 46px; padding: 0 20px; }
.btn.dark { background: var(--black); color: #FFFFFF; }
.btn.light { background: #F1F1F3; color: var(--ink); }
.btn.white { background: var(--card); color: var(--ink); }
.btn.ghost { background: transparent; color: var(--danger); }
.btn.outline { background: var(--card); border: 1px solid #E4E4E7; color: var(--ink); }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent-text); outline-offset: 2px;
}
.btn[disabled] { opacity: .45; cursor: default; }

.search { display: flex; align-items: center; gap: 8px; border: 1px solid #E4E4E7; border-radius: 999px; padding: 0 14px; min-height: 40px; color: var(--muted); background: var(--card); }
.search input { border: 0; outline: none; background: transparent; width: 160px; color: var(--ink); }

.table-box { overflow-x: auto; border: 1px solid var(--line); border-radius: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead tr { text-align: left; color: var(--muted); background: #FAFAFB; }
th { padding: 12px 8px; font-weight: 500; }
td { padding: 13px 8px; border-top: 1px solid var(--line); vertical-align: middle; }
th:first-child, td:first-child { padding-left: 14px; }
th:last-child, td:last-child { padding-right: 14px; }
tr.selected td { background: #FAFAFB; }
.msg-cell { max-width: 280px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* Grafici */
.bars { display: flex; align-items: end; gap: 22px; height: 170px; padding: 0 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; gap: 4px; height: 100%; justify-content: end; }
.bar-left { border-radius: 8px; background: repeating-linear-gradient(135deg, var(--accent) 0 4px, var(--accent-stripe) 4px 7px); }
.bar-stay { border-radius: 8px; background: var(--black); }
.legend { display: flex; justify-content: end; gap: 12px; font-size: 11px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.meter { height: 10px; background: #FFFFFF; border-radius: 6px; margin-top: 6px; overflow: hidden; }
.meter > div { height: 10px; border-radius: 6px; }

textarea.email {
  width: 100%; font-size: 15px; line-height: 1.6; background: var(--soft); padding: 16px;
  border: 1px solid var(--line); border-radius: 18px; resize: vertical; min-height: 150px;
}
/* Spiegazioni al passaggio del mouse */
[data-tip] { cursor: help; }
.tip {
  position: fixed; z-index: 1000; max-width: 260px; pointer-events: none;
  background: rgba(26, 26, 26, .82); color: #FFFFFF; font-size: 12px; font-weight: 500; line-height: 1.45;
  padding: 9px 12px; border-radius: 12px; box-shadow: 0 8px 24px rgba(17, 17, 17, .2);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.tip[hidden] { display: none; }

/* Scheda cliente in popup */
dialog.detail {
  border: 0; padding: 0; border-radius: 28px; background: var(--panel); color: var(--ink);
  width: min(1180px, 94vw); max-height: 92vh; overflow: auto;
  box-shadow: 0 24px 80px rgba(17, 17, 17, .25);
}
dialog.detail::backdrop { background: rgba(17, 17, 17, .45); }
.detail-body { padding: 24px; display: flex; flex-direction: column; gap: 20px; }
.detail-body h1 { font-size: 28px; }
button.link {
  border: 0; background: none; padding: 0; cursor: pointer; color: var(--ink); font-weight: 600;
  text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px;
}
button.link:hover { color: var(--accent-text); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--black); color: #FFFFFF; padding: 12px 18px; border-radius: 999px; font-weight: 600;
}

/* Barra filtri Customers */
.filter-bar { display: flex; flex-direction: column; gap: 12px; padding: 12px; }
.seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; background: var(--soft); border-radius: 18px; padding: 4px; }
.seg.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.seg-btn { border: 0; background: transparent; border-radius: 14px; padding: 14px 18px; cursor: pointer; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 12px; min-width: 0; font-weight: 600; color: var(--ink-2); text-align: left; transition: background .2s, color .2s; }
.seg-btn strong { font-size: 28px; letter-spacing: -0.02em; }
.seg-btn[aria-pressed="true"] { background: var(--black); color: #FFFFFF; }
.seg-btn[aria-pressed="true"].risk { background: var(--accent); color: var(--accent-ink); }
.seg-btn:not([aria-pressed="true"]):hover { background: #ECECEF; }
.seg-btn:focus-visible, .chip-f:focus-visible, .chip-menu button:focus-visible, .chip-clear:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 0 4px; }
.chip-f { border: 1px solid #E4E4E7; background: var(--card); color: var(--ink); border-radius: 999px; padding: 7px 13px; font-size: 13px; font-weight: 600; cursor: pointer; }
.chip-f[aria-expanded="true"] { border-color: var(--black); }
.chip-f.on { background: var(--black); color: #FFFFFF; border-color: var(--black); }
.chip-clear { border: 0; background: none; color: var(--accent-text); font-weight: 600; font-size: 13px; cursor: pointer; padding: 7px 6px; }
.chip-menu { display: flex; flex-wrap: wrap; gap: 6px; background: var(--soft); border-radius: 14px; padding: 10px; margin: 0 4px; }
.chip-menu button { border: 0; background: var(--card); color: var(--ink); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; }
.chip-menu button:hover { background: var(--accent-soft); }
.bar-hint { margin: 0; padding: 0 6px 4px; color: var(--muted); font-size: 13px; }
@media (max-width: 900px) { .seg.four { grid-template-columns: repeat(2, minmax(0, 1fr)); } .seg-btn strong { font-size: 22px; } }
@media (prefers-reduced-motion: reduce) { .seg-btn { transition: none; } }

@media (max-width: 900px) {
  .shell { padding: 12px; }
  .panel { padding: 16px; border-radius: 24px; }
  .span-3, .span-4, .span-5, .span-6, .span-7 { grid-column: span 12; }
  h1 { font-size: 26px; }
}
