/* BE RACE TAX MANAGER — tema scuro: nero, antracite, bianco, rosso BE RACE */
:root {
  --bg: #0b0b0c;
  --panel: #151517;
  --panel-2: #1c1c1f;
  --line: #2a2a2e;
  --line-2: #36363b;
  --text: #f2f2f3;
  --muted: #9a9aa2;
  --faint: #6c6c74;
  --red: #e1061b;
  --red-2: #ff2a3d;
  --red-bg: rgba(225, 6, 27, .12);
  --amber: #f0a020;
  --amber-bg: rgba(240, 160, 32, .12);
  --green: #2fbf71;
  --green-bg: rgba(47, 191, 113, .12);
  --blue: #5aa9ff;
  --blue-bg: rgba(90, 169, 255, .12);
  --radius: 10px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, ui-monospace, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 14px; }
.hidden { display: none !important; }

/* ---------- layout */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: #070708; border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--red); display: grid; place-items: center; font-weight: 800; font-size: 13px; letter-spacing: -.02em; }
.brand-name { font-weight: 800; letter-spacing: .04em; font-size: 13px; line-height: 1.15; }
.brand-name span { display: block; color: var(--muted); font-weight: 600; font-size: 11px; letter-spacing: .12em; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--panel); color: var(--text); }
.nav a.active { background: var(--panel-2); color: var(--text); box-shadow: inset 3px 0 0 var(--red); }
.nav .sep { height: 1px; background: var(--line); margin: 10px 6px; }
.nav .badge { margin-left: auto; }
.nav svg { width: 17px; height: 17px; flex: none; }
.main { min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: rgba(11, 11, 12, .92); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20; }
.content { padding: 22px 24px 60px; max-width: 1400px; }
.top .menu-btn { display: none; }
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* ---------- componenti */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card.link { cursor: pointer; transition: border-color .15s; }
.card.link:hover { border-color: var(--line-2); }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.card-head a { margin-left: auto; color: var(--muted); font-size: 12.5px; text-decoration: none; }
.card-head a:hover { color: var(--text); }
.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)); }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.kpi .sub { color: var(--faint); font-size: 12px; margin-top: 2px; }
.kpi.red .value { color: var(--red-2); }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-2); background: var(--panel-2); padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 550; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #4a4a50; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-2); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.ok { border-color: rgba(47,191,113,.5); color: var(--green); }
.btn.danger { border-color: rgba(225,6,27,.55); color: var(--red-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search], input[type=url], select, textarea {
  background: #0f0f11; border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 10px; outline: none; min-width: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--red); }
label.f { display: grid; gap: 5px; font-size: 12.5px; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { color: var(--text); font-size: 14px; }
.form { display: grid; gap: 12px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line-2); white-space: nowrap; }
.chip.red { background: var(--red-bg); color: var(--red-2); border-color: rgba(225,6,27,.35); }
.chip.amber { background: var(--amber-bg); color: var(--amber); border-color: rgba(240,160,32,.3); }
.chip.green { background: var(--green-bg); color: var(--green); border-color: rgba(47,191,113,.3); }
.chip.blue { background: var(--blue-bg); color: var(--blue); border-color: rgba(90,169,255,.3); }
.badge { background: var(--red); color: #fff; border-radius: 99px; padding: 0 7px; font-size: 11px; font-weight: 700; line-height: 18px; min-width: 18px; text-align: center; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: rgba(255,255,255,.02); }
tr.warn td { background: rgba(240,160,32,.05); }
.list { display: grid; }
.li { display: flex; gap: 12px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.li:last-child { border-bottom: 0; }
.li .grow { flex: 1; min-width: 0; }
.li .t { font-weight: 550; overflow: hidden; text-overflow: ellipsis; }
.li .s { color: var(--muted); font-size: 12.5px; }
.li.click { cursor: pointer; }
.li.click:hover .t { color: #fff; text-decoration: underline; text-decoration-color: var(--red); text-underline-offset: 3px; }
.date-box { width: 46px; text-align: center; flex: none; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 3px 0; }
.date-box b { display: block; font-size: 17px; line-height: 1.1; }
.date-box span { font-size: 10.5px; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; }
.date-box.over { border-color: var(--red); }
.date-box.over b { color: var(--red-2); }
.empty { color: var(--faint); padding: 18px 4px; text-align: center; font-size: 13px; }
.alert { display: flex; gap: 10px; padding: 10px 12px; border-radius: 8px; border: 1px solid; font-size: 13.5px; align-items: flex-start; }
.alert.critico { background: var(--red-bg); border-color: rgba(225,6,27,.4); }
.alert.attenzione { background: var(--amber-bg); border-color: rgba(240,160,32,.35); }
.alert.info { background: var(--blue-bg); border-color: rgba(90,169,255,.3); }
.alert.ok { background: var(--green-bg); border-color: rgba(47,191,113,.3); }
.alert a { font-weight: 600; }
.conf { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.conf i { display: inline-block; width: 44px; height: 5px; background: var(--line-2); border-radius: 9px; overflow: hidden; position: relative; }
.conf i::after { content: ""; position: absolute; inset: 0; width: var(--w); background: var(--c, var(--green)); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 9px 12px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; font-weight: 550; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--red); }
.drop { border: 1.5px dashed var(--line-2); border-radius: var(--radius); padding: 26px; text-align: center; color: var(--muted); cursor: pointer; transition: .15s; }
.drop.over, .drop:hover { border-color: var(--red); background: var(--red-bg); color: var(--text); }
.drop b { color: var(--text); }
.steps { display: grid; gap: 4px; }
.step { display: grid; grid-template-columns: 24px 170px 1fr; gap: 8px; font-size: 13px; align-items: baseline; }
.step .n { color: var(--faint); font-family: var(--mono); font-size: 11.5px; }
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.bar-chart .b { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; min-width: 0; height: 100%; }
.bar-chart .b i { width: 100%; max-width: 38px; background: var(--red); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar-chart .b span { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.hbar { display: grid; grid-template-columns: minmax(120px, 230px) 1fr auto; gap: 10px; align-items: center; padding: 6px 0; font-size: 13px; }
.hbar i { height: 8px; background: var(--red); border-radius: 9px; display: block; }

/* ---------- calendario */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cal .dow { padding: 6px 8px; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--panel-2); }
.cal .day { min-height: 104px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); min-width: 0; }
.cal .day.other { background: #0e0e10; }
.cal .day.other .dn { color: var(--faint); }
.cal .day.today { box-shadow: inset 0 0 0 1px var(--red); }
.cal .day.hol .dn { color: var(--red-2); }
.cal .dn { font-size: 12px; font-weight: 600; margin-bottom: 4px; display: flex; gap: 4px; }
.cal .dn small { color: var(--faint); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev { display: block; font-size: 11.5px; padding: 2px 6px; border-radius: 5px; margin-bottom: 3px; background: var(--panel-2); border-left: 3px solid var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.ev.alta, .ev.critica { border-left-color: var(--red); }
.ev.media { border-left-color: var(--amber); }
.ev.bassa { border-left-color: var(--blue); }
.ev.chiusa { opacity: .5; text-decoration: line-through; }
.ev.in_verifica { border-left-color: var(--green); }

/* ---------- modale / pannello */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50; display: flex; justify-content: flex-end; }
.overlay.center { justify-content: center; align-items: center; padding: 16px; }
.drawer { width: min(560px, 100%); height: 100%; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 20px; }
.modal { width: min(520px, 100%); max-height: 92vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; padding: 20px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.toast-wrap { position: fixed; bottom: 18px; right: 18px; z-index: 80; display: grid; gap: 8px; }
.toast { background: var(--panel-2); border: 1px solid var(--line-2); border-left: 3px solid var(--green); padding: 10px 14px; border-radius: 8px; max-width: 360px; box-shadow: 0 8px 30px rgba(0,0,0,.4); }
.toast.err { border-left-color: var(--red); }

/* ---------- accesso */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 500px at 10% -10%, rgba(225,6,27,.18), transparent 60%), var(--bg); }
.auth .box { width: min(400px, 100%); }
.auth .brand { justify-content: center; padding-bottom: 26px; }

/* ---------- chat */
.chat { display: grid; gap: 12px; }
.msg { padding: 12px 14px; border-radius: 10px; max-width: 760px; white-space: pre-wrap; }
.msg.q { background: var(--panel-2); margin-left: auto; border: 1px solid var(--line-2); }
.msg.a { background: var(--panel); border: 1px solid var(--line); }
.msg .src { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }

iframe.preview { width: 100%; height: 620px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 60; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.5); }
  .top .menu-btn { display: inline-flex; }
  .top { padding: 10px 16px; }
  .content { padding: 16px 16px 60px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .cal .day { min-height: 64px; padding: 3px; }
  .ev { font-size: 0; padding: 0; height: 6px; border-left-width: 0; background: var(--red); }
  .step { grid-template-columns: 22px 1fr; }
  .step .d { grid-column: 2; }
  .hide-sm { display: none; }
  .hbar { grid-template-columns: 1fr auto; }
  .hbar i { grid-column: 1 / -1; }
}

td .row { flex-wrap: nowrap; }
.step { grid-template-columns: 24px 200px 1fr; }

/* Selezione multipla delle rate */
th.check, td.check { width: 34px; text-align: center; }
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--red); cursor: pointer; vertical-align: middle; }
tr.sel td { background: var(--red-bg); }
.bulk-bar { position: sticky; top: 64px; z-index: 5; padding: 10px 14px; margin-bottom: 10px; border-color: rgba(225,6,27,.45); }

/* ---------- versione mobile (telefono e app installata) */
.tabbar, .scrim { display: none; }
.only-touch { display: none; }
@media (hover: none) and (pointer: coarse) { .only-touch { display: inline-flex; } }
@media (max-width: 820px) {
  body { font-size: 15px; -webkit-tap-highlight-color: transparent; }
  .app { min-height: 100dvh; }
  .top { padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); gap: 8px; }
  .top select { max-width: 46vw; min-width: 0; }
  .content { padding: 14px max(14px, env(safe-area-inset-right)) calc(84px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); }
  .side { height: 100dvh; padding-top: calc(18px + env(safe-area-inset-top)); padding-bottom: calc(18px + env(safe-area-inset-bottom)); width: min(300px, 86vw); }
  .side.open { box-shadow: none; }
  .scrim { position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.55); }
  .side.open + .scrim { display: block; }
  .nav a { padding: 11px 12px; font-size: 15px; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: rgba(7,7,8,.96); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
    padding: 4px max(4px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left)); }
  .tabbar a, .tabbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; min-height: 52px; justify-content: center;
    color: var(--muted); text-decoration: none; background: none; border: 0; font-size: 11px; font-weight: 600; cursor: pointer; border-radius: 10px; }
  .tabbar svg { width: 22px; height: 22px; }
  .tabbar a.active { color: var(--text); }
  .tabbar a.active svg { color: var(--red-2); }
  .btn { min-height: 40px; padding: 8px 14px; }
  .btn.sm { min-height: 36px; }
  input, select, textarea { font-size: 16px !important; }
  input[type=checkbox] { width: 22px; height: 22px; }
  h1 { font-size: 20px; }
  .page-head { margin-bottom: 14px; }
  .page-head .row, .page-head > .btn { flex-wrap: wrap; }
  .card { padding: 14px; }
  .card > table, .stack > table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap { margin: 0 -14px; padding: 0 14px; }
  th, td { padding: 9px 8px; }
  .kpi .value { font-size: 22px; }
  .overlay { align-items: flex-end; }
  .overlay.center { padding: 0; align-items: flex-end; }
  .modal { width: 100%; max-height: 90dvh; border-radius: 16px 16px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
  .drawer { width: 100%; padding: calc(16px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); }
  .toast-wrap { left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }
  .bulk-bar { top: calc(56px + env(safe-area-inset-top)); }
  .drop { padding: 18px; }
  iframe.preview { height: 70dvh; }
}
@media (display-mode: standalone) { .auth { padding-top: calc(16px + env(safe-area-inset-top)); } }
@media (max-width: 820px) {
  .top .menu-btn { display: none; }
  .grid.g4:has(> .kpi) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .label { font-size: 12px; }
  .kpi .value { font-size: 19px !important; overflow-wrap: anywhere; }
}
@media (max-width: 820px) { .grid.g2 { grid-template-columns: 1fr !important; } }
