/*
 * Console LiftBro. Colori dell'app (mobile/src/theme/tokens.ts).
 * Regola di impaginazione: lo spazio tra i blocchi lo danno SOLO i contenitori (gap di .page, .grid, .stack),
 * mai i margini tra fratelli: così i riquadri di una riga restano allineati e alti uguali.
 * Nessuno stile inline: la CSP lo vieta.
 */
:root {
  color-scheme: dark;
  --bg: #08080a;
  --panel: #0f0f12;
  --card: #131317;
  --card-hover: #17171c;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.12);
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --faint: #71717a;
  --accent: #d4ff3a;
  --accent-soft: rgba(212, 255, 58, 0.1);
  --accent-line: rgba(212, 255, 58, 0.28);
  --on-accent: #0b0b0c;
  --orange: #ffa94d;
  --orange-soft: rgba(255, 169, 77, 0.12);
  --red: #ff6b6b;
  --red-soft: rgba(255, 107, 107, 0.12);
  --blue: #6cb6ff;
  --blue-soft: rgba(108, 182, 255, 0.12);
  --radius: 16px;
  --radius-sm: 10px;
  --gap: 16px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 8px 24px rgba(0, 0, 0, 0.25);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--text); min-height: 100vh;
  font: 14px/1.5 var(--font); font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.2; }
h2 { font-size: 14px; font-weight: 600; letter-spacing: -0.005em; }
strong { font-weight: 600; }
small, .muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--mono); font-size: 12px; }
.nowrap { white-space: nowrap; }
.icon { flex: none; display: block; }
::selection { background: var(--accent); color: var(--on-accent); }

/* ===== Pagina di accesso ===== */
body.landing {
  display: grid; place-items: center; padding: 32px 16px;
  background: radial-gradient(900px 500px at 50% -10%, rgba(212, 255, 58, 0.08), transparent 70%), var(--bg);
}
.landing main { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 24px; }
.landing .intro { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.landing .intro p { color: var(--muted); max-width: 320px; }
.landing .card { padding: 24px; }
.landing form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.landing .foot { text-align: center; color: var(--faint); font-size: 12px; }
.mark {
  width: 52px; height: 52px; border-radius: 15px; background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; font-weight: 800; font-size: 19px; letter-spacing: -0.04em;
  box-shadow: 0 10px 30px rgba(212, 255, 58, 0.18);
}

/* ===== Struttura ===== */
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 22px 14px;
  display: flex; flex-direction: column; gap: 22px; background: var(--panel); border-right: 1px solid var(--line);
}
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 8px; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand .mark { width: 34px; height: 34px; border-radius: 10px; font-size: 13px; box-shadow: none; }
.brand b { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; display: block; line-height: 1.2; }
.brand small { font-size: 11px; color: var(--faint); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); padding: 0 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 500; position: relative;
}
.nav a:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.nav a.on { color: var(--text); background: var(--accent-soft); }
.nav a.on .icon { color: var(--accent); }
.nav a.on::before { content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px 8px 0; border-top: 1px solid var(--line); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--card-hover); border: 1px solid var(--line-strong); font-size: 12px; font-weight: 700; color: var(--text);
}
.me .who { min-width: 0; flex: 1; line-height: 1.3; }
.me .who b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me .who span { display: block; font-size: 11px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn {
  width: 34px; height: 34px; border-radius: var(--radius-sm); display: grid; place-items: center; flex: none;
  background: transparent; border: 1px solid var(--line); color: var(--muted); cursor: pointer;
}
.iconbtn:hover { color: var(--text); border-color: var(--line-strong); background: rgba(255, 255, 255, 0.04); }

.content { min-width: 0; padding: 32px 36px 56px; }
.page { display: flex; flex-direction: column; gap: 20px; max-width: 1360px; margin: 0 auto; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.head p { color: var(--muted); margin-top: 6px; }
.head .back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.head .back:hover { color: var(--accent); }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== Griglie: gap e altezze uguali per riga ===== */
.grid { display: grid; gap: var(--gap); align-items: stretch; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); }
.cols-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.span-2 { grid-column: span 2; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-lg { display: flex; flex-direction: column; gap: 20px; }

/* ===== Card ===== */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px;
  min-width: 0; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 24px; }
.card-head h2 { display: flex; align-items: center; gap: 8px; }
.card-head h2 .icon { color: var(--faint); }
.card-head .aside { color: var(--faint); font-size: 12px; white-space: nowrap; }
.card-desc { color: var(--muted); font-size: 13px; margin-top: -8px; }
.card.flush { padding: 0; gap: 0; overflow: hidden; }
.card.flush > .card-head { padding: 18px 20px 14px; }
.card.flush > .card-foot { padding: 12px 20px; border-top: 1px solid var(--line); }
.divider { height: 1px; background: var(--line); }

/* ===== KPI ===== */
.kpi { gap: 6px; padding: 18px 20px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.kpi-icon { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: rgba(255, 255, 255, 0.05); color: var(--muted); }
.kpi-value { font-size: 30px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.15; font-variant-numeric: tabular-nums; margin-top: 4px; }
.kpi-hint { font-size: 12px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tone-accent .kpi-value { color: var(--accent); }
.tone-accent .kpi-icon { background: var(--accent-soft); color: var(--accent); }
.tone-warn .kpi-value { color: var(--orange); }
.tone-warn .kpi-icon { background: var(--orange-soft); color: var(--orange); }
.tone-danger .kpi-value { color: var(--red); }
.tone-danger .kpi-icon { background: var(--red-soft); color: var(--red); }
.tone-blue .kpi-icon { background: var(--blue-soft); color: var(--blue); }

/* ===== Grafici ===== */
.chart { display: flex; flex-direction: column; gap: 10px; }
.chart .plot { position: relative; height: 168px; padding-top: 18px; }
.chart .plot svg { position: absolute; left: 0; right: 0; bottom: 0; top: 18px; width: 100%; height: calc(100% - 18px); display: block; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart .bar { fill: var(--accent); opacity: 0.9; }
.chart .bar.orange { fill: var(--orange); }
.chart .bar.blue { fill: var(--blue); }
.chart .bar:hover { opacity: 1; filter: brightness(1.15); }
.chart .bar.today { opacity: 1; }
.chart .scale { position: absolute; right: 0; top: 0; font-size: 11px; line-height: 14px; color: var(--faint); }
.chart .axis { display: flex; justify-content: space-between; color: var(--faint); font-size: 11px; }
.big-number { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

.rows { display: flex; flex-direction: column; gap: 10px; }
.rows .row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: baseline; }
.rows .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.rows .num { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; text-align: right; white-space: nowrap; }
.rows .num b { color: var(--text); font-weight: 600; margin-right: 6px; }
.rows svg { grid-column: 1 / -1; width: 100%; height: 6px; display: block; }
.rows .track { fill: rgba(255, 255, 255, 0.06); }
.rows .fill { fill: var(--accent); }
.rows.blue .fill { fill: var(--blue); }
.rows.orange .fill { fill: var(--orange); }
.empty { color: var(--faint); font-size: 13px; padding: 8px 0; }

.metric-list { display: flex; flex-direction: column; }
.metric-list .item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.metric-list .item:first-child { padding-top: 0; }
.metric-list .item:last-child { border-bottom: 0; padding-bottom: 0; }
.metric-list .val { font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }

/* ===== Tabelle ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; color: var(--faint); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: rgba(255, 255, 255, 0.015);
}
td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(255, 255, 255, 0.025); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th:first-child, td:first-child { padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; }
.cell-user { display: flex; align-items: center; gap: 12px; min-width: 200px; }
.cell-user .avatar { width: 32px; height: 32px; font-size: 11px; }
.cell-user > span:not(.avatar) { display: block; min-width: 0; color: var(--text); }
.cell-user > span:not(.avatar) > b { display: block; font-weight: 600; }
.cell-user > span:not(.avatar) > span:not(.tag) { display: block; color: var(--faint); font-size: 12px; }
a.cell-user:hover b { color: var(--accent); }
.sub { display: block; color: var(--faint); font-size: 12px; margin-top: 2px; }
.empty-row td { text-align: center; color: var(--faint); padding: 32px 14px; }

/* ===== Etichette ===== */
.tag {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: rgba(255, 255, 255, 0.06); color: var(--muted); white-space: nowrap; line-height: 1.4; vertical-align: middle;
}
.tag.ok { background: var(--accent-soft); color: var(--accent); }
.tag.warn { background: var(--orange-soft); color: var(--orange); }
.tag.danger { background: var(--red-soft); color: var(--red); }
.tag.info { background: var(--blue-soft); color: var(--blue); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); flex: none; }
.dot.live { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(212, 255, 58, 0.04); } }
@media (prefers-reduced-motion: reduce) { .dot.live { animation: none; } }

/* ===== Messaggi ===== */
.flash, .banner { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 12px; border: 1px solid; font-size: 13.5px; }
.flash { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.flash.error { background: var(--red-soft); color: var(--red); border-color: rgba(255, 107, 107, 0.3); }
.banner.warn { background: var(--orange-soft); color: var(--orange); border-color: rgba(255, 169, 77, 0.3); }
.banner a { text-decoration: underline; margin-left: auto; white-space: nowrap; }

/* ===== Moduli ===== */
label { display: block; font-size: 12.5px; color: var(--muted); font-weight: 500; margin-bottom: 7px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=url], select, textarea {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 10px 12px; font: inherit; transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
textarea { min-height: 92px; resize: vertical; }
select { appearance: none; padding-right: 34px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.hint { color: var(--faint); font-size: 12px; }
.err { color: var(--red); font-size: 12.5px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; cursor: pointer;
  background: var(--accent); color: var(--on-accent); font: inherit; font-weight: 600; font-size: 13.5px;
  padding: 9px 16px; border-radius: var(--radius-sm); white-space: nowrap; transition: filter 0.15s, background 0.15s;
}
.btn:hover { filter: brightness(0.93); color: var(--on-accent); }
.btn.block { width: 100%; padding: 12px; }
.btn.ghost { background: rgba(255, 255, 255, 0.05); color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.09); color: var(--text); filter: none; }
.btn.danger { background: var(--red-soft); color: var(--red); border-color: rgba(255, 107, 107, 0.25); }
.btn.danger:hover { background: rgba(255, 107, 107, 0.2); color: var(--red); filter: none; }
.btn.small { padding: 6px 11px; font-size: 12.5px; }
.btn.disabled { opacity: 0.4; pointer-events: none; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions.end { justify-content: flex-end; }
.card .actions:last-child { margin-top: auto; }
.linkbtn { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 0; }
.linkbtn:hover { color: var(--accent); }

/* ===== Barra filtri e schede ===== */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar .search { position: relative; flex: 1 1 260px; max-width: 360px; }
.toolbar .search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.toolbar .search input { padding-left: 38px; }
.toolbar select { width: auto; min-width: 170px; }
.toolbar .count { margin-left: auto; color: var(--faint); font-size: 12.5px; }
.tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; flex-wrap: wrap; align-self: flex-start; }
.tabs a { display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 9px; color: var(--muted); font-weight: 500; font-size: 13px; }
.tabs a:hover { color: var(--text); }
.tabs a.on { background: rgba(255, 255, 255, 0.08); color: var(--text); }

/* ===== Paginazione ===== */
.pager { display: flex; gap: 12px; justify-content: space-between; align-items: center; color: var(--faint); font-size: 12.5px; padding: 12px 20px; border-top: 1px solid var(--line); }

/* ===== Varie ===== */
pre.log {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; overflow: auto; max-height: 560px;
  font: 11.5px/1.6 var(--mono); color: var(--muted); white-space: pre-wrap; word-break: break-word;
}
dl.info { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0; }
dl.info dt, dl.info dd { padding: 10px 0; border-bottom: 1px solid var(--line); }
dl.info dt { color: var(--muted); padding-right: 24px; }
dl.info dd { font-weight: 500; word-break: break-word; text-align: right; }
dl.info dt:last-of-type, dl.info dd:last-of-type { border-bottom: 0; }
.status-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.msg { padding: 12px 14px; border-radius: var(--radius-sm); background: rgba(255, 255, 255, 0.03); border: 1px solid var(--line); }
.msg b { display: block; }

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  .span-2 { grid-column: auto; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; z-index: 10; height: auto; padding: 12px 16px; gap: 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side .brand small, .nav-label { display: none; }
  .nav { flex-direction: row; overflow-x: auto; scrollbar-width: none; gap: 4px; }
  .nav a { white-space: nowrap; padding: 8px 10px; }
  .nav a.on::before { display: none; }
  .me { display: none; }
  .brand-row { padding: 0; }
  .content { padding: 20px 16px 40px; }
  h1 { font-size: 22px; }
}
.brand-row .mobile-out { display: none; }
@media (max-width: 900px) { .brand-row .mobile-out { display: block; } }

/* Campo di ricerca nella barra filtri: è un <label>, senza il margine delle etichette dei moduli. */
.toolbar label.search { margin: 0; display: block; }
.head .cell-user { gap: 14px; }
.head .cell-user .avatar { width: 48px; height: 48px; font-size: 15px; }
.head .cell-user h1 { margin-bottom: 6px; }
.head .cell-user .status-line { display: flex; }
/* Nelle card affiancate i pulsanti stanno tutti sul fondo, alla stessa altezza. */
.card > .form { flex: 1; }
.form > .actions:last-child { margin-top: auto; padding-top: 4px; }
/* Telefono: due numeri per riga, più compatti. */
@media (max-width: 600px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 23px; }
  .kpi-icon { display: none; }
  .kpi-hint { white-space: normal; }
  .card { padding: 16px; }
  .toolbar select, .toolbar .search { flex: 1 1 100%; max-width: none; }
}
