/* =========================================================
   ANTARES CONTROLLO — Design System
   Tema scuro · Playfair Display + DM Sans
   ========================================================= */

:root,
[data-theme="light"] {
  /* superfici — light (default) */
  --bg:        #f5f3ed;
  --surface-1: #ffffff;
  --surface-2: #f0ede4;
  --surface-3: #e6e2d6;
  --border:    #e0dccf;
  --border-strong: #c7c1b2;

  /* testo */
  --text:      #1a1d24;
  --muted:     #6b6960;
  --dim:       #a8a499;

  /* accenti — primario azzurro */
  --teal:      #1d6fe0;
  --teal-on:   #ffffff;
  --teal-dim:  rgba(29,111,224,0.10);
  --coral:     #d63838;
  --coral-on:  #ffffff;
  --coral-dim: rgba(214,56,56,0.10);
  --yellow:    #a8780a;
  --yellow-on: #ffffff;
  --yellow-dim:rgba(168,120,10,0.12);
  --blue:      #4f46e5;
  --blue-on:   #ffffff;
  --blue-dim:  rgba(79,70,229,0.10);

  /* type */
  --serif: "Playfair Display", "Times New Roman", serif;
  --sans:  "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono:  "DM Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* radii / shadow */
  --r-sm: 6px;
  --r:    10px;
  --r-lg: 14px;
  --shadow-card: 0 1px 2px rgba(20,20,20,0.04), 0 6px 18px rgba(20,20,20,0.05);

  /* row backgrounds — per warn/danger rows e cell tesoreria */
  --row-warn-bg:   rgba(168,120,10,0.08);
  --row-danger-bg: rgba(214,56,56,0.08);
  --cell-warn-bg:  rgba(168,120,10,0.14);
  --cell-danger-bg:rgba(214,56,56,0.14);
}

[data-theme="dark"] {
  --bg:        #0e1117;
  --surface-1: #171b22;
  --surface-2: #1e2330;
  --surface-3: #252b3a;
  --border:    #2a2f3a;
  --border-strong: #353c4d;

  --text:      #e8eaed;
  --muted:     #8b919a;
  --dim:       #5d636e;

  --teal:      #6ba8ff;
  --teal-on:   #0a0d12;
  --teal-dim:  rgba(107,168,255,0.14);
  --coral:     #ff6b6b;
  --coral-on:  #2a0c0c;
  --coral-dim: rgba(255,107,107,0.13);
  --yellow:    #ffe66d;
  --yellow-on: #2a2300;
  --yellow-dim:rgba(255,230,109,0.13);
  --blue:      #a78bfa;
  --blue-on:   #0a0d12;
  --blue-dim:  rgba(167,139,250,0.14);

  --shadow-card: 0 1px 0 rgba(255,255,255,0.02) inset, 0 8px 24px rgba(0,0,0,0.25);

  --row-warn-bg:   rgba(255,230,109,0.05);
  --row-danger-bg: rgba(255,107,107,0.06);
  --cell-warn-bg:  rgba(255,230,109,0.10);
  --cell-danger-bg:rgba(255,107,107,0.15);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  min-height: 100vh;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea, button { font-family: inherit; font-size: 14px; color: var(--text); }
table { border-collapse: collapse; }

/* ---------- Tipografia ---------- */
.serif { font-family: var(--serif); font-weight: 500; letter-spacing: -0.01em; }
.h1 { font-family: var(--serif); font-weight: 600; font-size: 28px; line-height: 1.15; letter-spacing: -0.015em; margin: 0; }
.h2 { font-family: var(--serif); font-weight: 500; font-size: 20px; line-height: 1.2; margin: 0; }
.h3 { font-family: var(--serif); font-weight: 500; font-size: 16px; margin: 0; }
.eyebrow {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal);
  font-weight: 600;
}
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.pos { color: var(--teal); }
.neg { color: var(--coral); }
.warn { color: var(--yellow); }

/* ---------- App shell ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 8px;
  background: var(--teal);
  color: var(--teal-on);
  display: grid; place-items: center;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 17px;
  flex-shrink: 0;
  letter-spacing: -0.02em;
}
.brand-sub { color: var(--muted); font-family: var(--sans); font-weight: 400; font-size: 12px; letter-spacing: 0.04em; }

.year-selector {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}
.year-selector button {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 500;
  font-size: 13px;
  transition: all .15s;
}
.year-selector button:hover { color: var(--text); }
.year-selector button.active {
  background: var(--teal);
  color: var(--teal-on);
}
.user-chip {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.user-chip .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-3);
  display: grid; place-items: center;
  color: var(--text); font-size: 12px; font-weight: 600;
}
.theme-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 36px; height: 36px;
  display: inline-grid; place-items: center;
  color: var(--muted);
  transition: all .15s;
}
.theme-toggle:hover { color: var(--text); background: var(--surface-3); }
.menu-btn {
  display: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 36px; height: 36px;
  align-items: center; justify-content: center;
  color: var(--text);
}

/* ---------- Nav tabs ---------- */
.nav {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 53px; z-index: 25;
}
.nav-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: thin;
  /* fade gradient sulla destra per indicare contenuto oltre */
  mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 28px), transparent 100%);
  -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 28px), transparent 100%);
}
.nav-inner::-webkit-scrollbar { height: 4px; }
.nav-inner::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.nav-tab {
  background: transparent;
  border: none;
  padding: 12px 10px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
  display: flex; align-items: center; gap: 6px;
}
.nav-tab:hover { color: var(--text); }
.nav-tab.active {
  color: var(--teal);
  border-bottom-color: var(--teal);
}
.nav-tab .tab-badge {
  background: var(--coral);
  color: #1a0808;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
}

/* ---------- Main content ---------- */
.main {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px 64px;
}
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-title-block .eyebrow { margin-bottom: 6px; display: block; }
.page-title-block .h1 { font-size: 32px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r);
  position: relative;
  overflow: hidden;
}
.card-bar {
  height: 3px;
  background: var(--teal);
}
.card-bar.coral { background: var(--coral); }
.card-bar.yellow { background: var(--yellow); }
.card-bar.blue { background: var(--blue); }
.card-bar.muted { background: var(--border-strong); }
.card-body { padding: 18px 20px; }
.card-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}

/* ---------- KPI ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--teal);
}
.kpi.coral::before { background: var(--coral); }
.kpi.yellow::before { background: var(--yellow); }
.kpi.blue::before { background: var(--blue); }
.kpi-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 10px;
}
.kpi-value {
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin-bottom: 6px;
}
.kpi-sub {
  font-size: 12px;
  color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.delta { font-weight: 600; }

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 600px;
}
.table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal);
  font-weight: 700;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.table tr:last-child td { border-bottom: none; }
.table tr.row-active td:first-child { box-shadow: inset 3px 0 0 var(--teal); }
.table tr.row-passive td:first-child { box-shadow: inset 3px 0 0 var(--coral); }
.table tr.row-warn td { background: var(--row-warn-bg); }
.table tr.row-warn td:first-child { box-shadow: inset 3px 0 0 var(--yellow); }
.table tr.row-danger td { background: var(--row-danger-bg); }
.table tr.row-danger td:first-child { box-shadow: inset 3px 0 0 var(--coral); }
.table tr:hover td { background: var(--surface-2); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .row-total td {
  background: var(--surface-2);
  font-weight: 600;
  border-top: 1px solid var(--border-strong);
}

/* ---------- Pills / badges ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.pill.teal { background: var(--teal-dim); color: var(--teal); }
.pill.coral { background: var(--coral-dim); color: var(--coral); }
.pill.yellow { background: var(--yellow-dim); color: var(--yellow); }
.pill.blue { background: var(--blue-dim); color: var(--blue); }
.pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}

/* ---------- Buttons ---------- */
.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex; align-items: center; gap: 8px;
  transition: all .15s;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn.primary {
  background: var(--teal);
  color: var(--teal-on);
  border-color: var(--teal);
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--coral); border-color: var(--coral); background: transparent; }
.btn-icon {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  padding: 0;
}

/* ---------- Form ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.span-2 { grid-column: span 2; }
.field.span-full { grid-column: 1 / -1; }
.label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.input, .select, .textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-dim);
}
.input.num { text-align: right; font-variant-numeric: tabular-nums; }
.help { font-size: 11px; color: var(--muted); }

/* Segmented control */
.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.segmented button {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
}
.segmented button.active {
  background: var(--surface-3);
  color: var(--text);
}
.segmented.teal button.active { background: var(--teal); color: var(--teal-on); }
.segmented.coral button.active { background: var(--coral); color: var(--coral-on); }
.segmented.compact button { padding: 5px 10px; font-size: 12px; }

/* ---------- Alert / banner ---------- */
.alert {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px;
  border-radius: var(--r);
  background: var(--yellow-dim);
  border: 1px solid rgba(255,230,109,0.25);
  color: var(--text);
  font-size: 13px;
}
.alert {
  border-color: var(--yellow);
}
.alert .alert-icon {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--yellow);
  color: var(--yellow-on);
  flex-shrink: 0;
  font-weight: 700;
}
.alert.coral { background: var(--coral-dim); border-color: var(--coral); }
.alert.coral .alert-icon { background: var(--coral); color: var(--coral-on); }
.alert .alert-action { margin-left: auto; }

/* ---------- Two-column layout ---------- */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.two-col-asym {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
}

/* ---------- Tesoreria specific ---------- */
.tesoreria-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tesoreria {
  width: 100%;
  min-width: 1000px;
  border-collapse: collapse;
  font-size: 12.5px;
}
.tesoreria th, .tesoreria td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.tesoreria th {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--teal);
  font-weight: 700;
  background: var(--surface-2);
  position: sticky; top: 0;
}
.tesoreria th:first-child, .tesoreria td:first-child {
  text-align: left;
  position: sticky; left: 0;
  background: var(--surface-1);
  z-index: 2;
  min-width: 180px;
}
.tesoreria th:first-child { z-index: 3; background: var(--surface-2); }
.tesoreria tr.group-head td {
  background: var(--surface-2);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  padding: 8px 10px;
}
.tesoreria tr.group-head td:first-child { background: var(--surface-2); }
.tesoreria tr.row-saldo td {
  background: var(--surface-2);
  font-weight: 700;
  border-top: 1px solid var(--border-strong);
}
.tesoreria tr.row-saldo td:first-child { background: var(--surface-2); }
.tesoreria .cell-warn { background: var(--cell-warn-bg); color: var(--yellow); font-weight: 600; }
.tesoreria .cell-danger { background: var(--cell-danger-bg); color: var(--coral); font-weight: 700; }
.tesoreria .cell-ok { color: var(--teal); }

/* ---------- Cashflow legend ---------- */
.legend {
  display: flex; gap: 16px; flex-wrap: wrap;
  font-size: 12px; color: var(--muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--border); }
.legend-swatch.ok { background: var(--surface-2); }
.legend-swatch.warn { background: rgba(255,230,109,0.18); }
.legend-swatch.danger { background: rgba(255,107,107,0.22); }

/* ---------- Riclassificato cascade ---------- */
.cascade { display: flex; flex-direction: column; }
.cascade-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.cascade-row.indent-1 { padding-left: 32px; color: var(--muted); }
.cascade-row.indent-2 { padding-left: 48px; color: var(--muted); font-size: 12px; }
.cascade-row.total {
  background: var(--surface-2);
  font-weight: 600;
  border-top: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border-strong);
}
.cascade-row.final { background: var(--teal-dim); }
.cascade-row .label-cell { font-weight: 500; }
.cascade-row .val { font-variant-numeric: tabular-nums; padding-right: 16px; min-width: 100px; text-align: right; }
.cascade-row .pct {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
  min-width: 60px;
  text-align: right;
}

/* ---------- Bar chart simple ---------- */
.minibar {
  height: 6px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
  width: 100%;
  max-width: 220px;
}
.minibar-fill { height: 100%; background: var(--teal); border-radius: 999px; }
.minibar-fill.coral { background: var(--coral); }
.minibar-fill.yellow { background: var(--yellow); }
.minibar-fill.blue { background: var(--blue); }

/* ---------- Schedule items ---------- */
.sched-item {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.sched-item:last-child { border-bottom: none; }
.sched-date {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 6px 8px;
  text-align: center;
}
.sched-date .d { font-family: var(--serif); font-size: 18px; line-height: 1; font-weight: 600; }
.sched-date .m { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-top: 2px; }
.sched-date.urgent { background: var(--coral-dim); border: 1px solid var(--coral); }
.sched-date.urgent .d { color: var(--coral); }
.sched-date.soon { background: var(--yellow-dim); border: 1px solid var(--yellow); }
.sched-date.soon .d { color: var(--yellow); }
.sched-title { font-weight: 500; font-size: 13px; }
.sched-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.sched-amount { font-family: var(--serif); font-size: 16px; font-weight: 600; text-align: right; }

/* ---------- Linea di business cards ---------- */
.line-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px 20px;
  position: relative;
}
.line-card .line-name { font-family: var(--serif); font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.line-card .line-sub { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.line-card .line-value { font-family: var(--serif); font-size: 26px; font-weight: 600; }
.line-card .line-bar {
  height: 4px; border-radius: 999px;
  background: var(--surface-3);
  margin-top: 14px;
  overflow: hidden;
}
.line-card .line-bar-fill { height: 100%; background: var(--teal); }

/* ---------- Drawer (mobile) ---------- */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 50;
  display: none;
}
.drawer-backdrop.open { display: block; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: 280px;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  z-index: 51;
  transform: translateX(-100%);
  transition: transform .25s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.drawer-list { padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.drawer-item {
  background: transparent;
  border: none;
  color: var(--muted);
  text-align: left;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 14px;
  display: flex; align-items: center; gap: 12px;
}
.drawer-item.active { background: var(--teal-dim); color: var(--teal); }
.drawer-item:hover { background: var(--surface-2); color: var(--text); }
.drawer-item.active:hover { background: var(--teal-dim); color: var(--teal); }

/* ---------- Misc ---------- */
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.spacer { flex: 1; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.scroll-hint {
  font-size: 11px; color: var(--dim);
  display: flex; align-items: center; gap: 6px;
  padding: 6px 0;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface-1);
  border: 1px solid var(--teal);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 100;
  box-shadow: var(--shadow-card);
  display: flex; align-items: center; gap: 10px;
  animation: toast-in .25s ease;
}
.toast .toast-icon {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--teal); color: var(--teal-on);
  display: grid; place-items: center;
  font-weight: 700; font-size: 12px;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .two-col, .two-col-asym { grid-template-columns: 1fr; }
  .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: span 1; }
  .page-title-block .h1 { font-size: 26px; }
}
@media (max-width: 640px) {
  .topbar-inner { padding: 10px 14px; gap: 10px; }
  .menu-btn { display: inline-flex; }
  .nav { display: none; }
  .brand-sub { display: none; }
  .user-chip span:not(.avatar) { display: none; }
  .main { padding: 18px 14px 64px; }
  .page-title-block .h1 { font-size: 24px; }
  .kpi { padding: 14px 16px; }
  .kpi-value { font-size: 24px; }
  .card-body { padding: 14px 16px; }
  .card-head { padding: 12px 16px; }
}

/* =========================================================
   LOGIN
   ========================================================= */
.login-screen {
  min-height: 100vh;
  background: var(--bg);
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
}
.login-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 50% 30%, var(--teal-dim), transparent 70%),
    radial-gradient(ellipse 50% 40% at 80% 80%, var(--blue-dim), transparent 70%);
  pointer-events: none;
}
.login-theme-toggle {
  position: absolute;
  top: 20px; right: 20px;
  z-index: 2;
}
.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 440px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 36px 28px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.login-logo-frame {
  display: grid; place-items: center;
  padding: 22px 0 10px;
}
.login-logo-bg {
  width: 200px; height: 200px;
  background: #0e1117;
  border-radius: 20px;
  display: grid; place-items: center;
  position: relative;
  overflow: hidden;
  box-shadow:
    0 8px 32px rgba(14,17,23,0.18),
    inset 0 1px 0 rgba(255,255,255,0.04);
}
.login-logo-bg::before {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 30%, rgba(255,255,255,0.06), transparent 60%);
  pointer-events: none;
}
.login-logo-bg img {
  width: 92%; height: 92%;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.4));
}
.login-title {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  text-align: center;
  letter-spacing: -0.015em;
  margin: 8px 0 0;
}
.login-sub {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 22px;
}
.login-form {
  display: flex; flex-direction: column; gap: 14px;
  margin-top: 6px;
}
.login-input-wrap { position: relative; }
.login-input-wrap .lock {
  position: absolute;
  left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.login-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 14px 14px 42px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.login-input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-dim);
}
.login-btn {
  width: 100%;
  background: var(--teal);
  color: var(--teal-on);
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: filter .15s, transform .04s;
}
.login-btn:hover { filter: brightness(1.06); }
.login-btn:active { transform: translateY(1px); }
.login-meta {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}
.login-meta .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--teal);
  display: inline-block;
  margin-right: 6px;
  vertical-align: middle;
}
.login-error {
  background: var(--coral-dim);
  border: 1px solid var(--coral);
  color: var(--coral);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  text-align: center;
}
.login-hint {
  text-align: center;
  font-size: 11.5px;
  color: var(--dim);
  margin-top: 14px;
}
.login-hint code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: var(--mono);
  color: var(--muted);
  font-size: 11px;
}

@media (max-width: 480px) {
  .login-card { padding: 24px 22px 22px; }
  .login-logo-bg { width: 160px; height: 160px; }
  .login-title { font-size: 24px; }
}

/* Logout button in drawer */
.drawer-footer {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.drawer-footer .logout {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  display: flex; align-items: center; gap: 10px;
  transition: all .15s;
}
.drawer-footer .logout:hover {
  color: var(--coral);
  border-color: var(--coral);
}

/* =========================================================
   PREVENTIVI · table tweaks
   ========================================================= */
.preventivo-table th:first-child,
.preventivo-table td:first-child { min-width: 240px; }

/* =========================================================
   STATISTICHE · chart bars
   ========================================================= */
.chart-bars {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  align-items: end;
  height: 320px;
  padding-top: 20px;
}
.chart-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  position: relative;
}
.chart-numbers {
  display: flex; flex-direction: column; align-items: center;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  margin-bottom: 8px;
  min-height: 32px;
}
.chart-num { font-weight: 600; }
.chart-bar-wrap {
  width: 64px;
  flex: 1;
  display: flex; align-items: flex-end;
  justify-content: center;
  position: relative;
}
.chart-bar {
  width: 100%;
  background: var(--teal-dim);
  border: 1px solid var(--teal);
  border-radius: 8px 8px 2px 2px;
  position: relative;
  overflow: hidden;
  min-height: 4px;
}
.chart-bar-margin {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: var(--teal);
}
.chart-label {
  margin-top: 10px;
  font-size: 13px;
  text-align: center;
}

/* =========================================================
   STATISTICHE · rank rows
   ========================================================= */
.rank-row {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.rank-row:last-child { border-bottom: none; }
.rank-num {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 600;
  color: var(--teal);
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--teal-dim);
  display: grid; place-items: center;
}
.rank-num.bad { color: var(--coral); background: var(--coral-dim); }
.rank-title { font-weight: 600; font-size: 14px; }
.rank-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.rank-value {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
}

/* =========================================================
   ANAGRAFICA · split layout
   ========================================================= */
.anagrafica-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  align-items: start;
}
.contact-list {
  max-height: 70vh;
  overflow-y: auto;
}
.contact-item {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 12px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  transition: background .15s;
}
.contact-item:hover { background: var(--surface-2); }
.contact-item.active { background: var(--teal-dim); }
.contact-item.active .contact-name { color: var(--teal); }
.contact-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--surface-3);
  display: grid; place-items: center;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.contact-avatar.teal { background: var(--teal-dim); color: var(--teal); }
.contact-info { min-width: 0; }
.contact-name {
  font-weight: 600; font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.contact-meta { margin-top: 2px; }
.contact-amount {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 14px;
}

/* =========================================================
   TIMELINE (calendario attrezzatura / carico collaboratori)
   ========================================================= */
.timeline-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.timeline {
  min-width: 900px;
}
.timeline-row {
  display: grid;
  grid-template-columns: 200px 1fr 80px;
  border-bottom: 1px solid var(--border);
  align-items: stretch;
}
.timeline-row.timeline-head {
  background: var(--surface-2);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--teal);
  font-weight: 700;
}
.timeline-row.timeline-head .timeline-label,
.timeline-row.timeline-head .timeline-side { padding: 10px 14px; }
.timeline-label {
  padding: 12px 14px;
  border-right: 1px solid var(--border);
}
.timeline-side {
  padding: 12px 14px;
  border-left: 1px solid var(--border);
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.timeline-lane {
  position: relative;
  background-image: linear-gradient(to right,
    var(--border) 1px, transparent 1px);
  background-size: calc(100% / 12) 100%;
  min-height: 44px;
}
.timeline-lane.months {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  background: none;
  min-height: 32px;
}
.timeline-month-label {
  padding: 8px 0;
  text-align: center;
  border-right: 1px solid var(--border);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--teal);
  font-weight: 700;
}
.timeline-month-label:last-child { border-right: none; }
.timeline-bar {
  position: absolute;
  height: 26px;
  background: var(--teal-dim);
  border: 1px solid var(--teal);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  gap: 6px;
  font-size: 11px;
  color: var(--teal);
  overflow: hidden;
  margin-left: 2px;
}
.timeline-bar-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}
.timeline-bar-meta {
  font-family: var(--mono);
  font-size: 10px;
  opacity: 0.85;
  flex-shrink: 0;
}
.timeline-bar.overlap {
  background: var(--coral-dim);
  border-color: var(--coral);
  color: var(--coral);
}
.timeline-bar.ricorrente {
  background: var(--blue-dim);
  border-color: var(--blue);
  color: var(--blue);
}

/* =========================================================
   CALENDARIO mensile (Scadenze)
   ========================================================= */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-top: 1px solid var(--border);
}
.cal-dow {
  padding: 8px 0;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--teal);
  font-weight: 700;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
}
.cal-dow:last-child { border-right: none; }
.cal-cell {
  min-height: 96px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface-1);
}
.cal-cell:nth-child(7n+7) { border-right: none; }
.cal-cell.empty { background: var(--surface-2); opacity: 0.4; }
.cal-cell.urgent { background: var(--coral-dim); }
.cal-day {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  font-family: var(--mono);
}
.cal-events { display: flex; flex-direction: column; gap: 3px; }
.cal-event {
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 10px;
  display: flex;
  justify-content: space-between;
  gap: 4px;
  background: var(--surface-3);
  color: var(--muted);
  border-left: 2px solid var(--muted);
}
.cal-event.fisc  { background: var(--coral-dim); color: var(--coral); border-left-color: var(--coral); }
.cal-event.inps  { background: var(--blue-dim);  color: var(--blue);  border-left-color: var(--blue); }
.cal-event.ires  { background: var(--yellow-dim);color: var(--yellow);border-left-color: var(--yellow); }
.cal-event.rata  { background: var(--teal-dim); color: var(--teal); border-left-color: var(--teal); }
.cal-event.incasso { background: var(--teal-dim); color: var(--teal); border-left-color: var(--teal); }
.cal-event.more { background: transparent; border: none; font-style: italic; color: var(--dim); }
.cal-event-label {
  font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal-event-amt {
  font-family: var(--mono);
  flex-shrink: 0;
  opacity: 0.85;
}

@media (max-width: 900px) {
  .anagrafica-layout { grid-template-columns: 1fr; }
  .contact-list { max-height: 50vh; }
  .chart-bars { height: 240px; }
  .chart-bar-wrap { width: 44px; }
  .timeline-row { grid-template-columns: 140px 1fr 60px; }
  .timeline-label { padding: 10px; }
  .cal-cell { min-height: 78px; padding: 4px; }
}
@media (max-width: 640px) {
  .chart-bars { gap: 6px; height: 200px; }
  .chart-bar-wrap { width: 32px; }
  .chart-numbers { font-size: 10px; }
  .chart-label { font-size: 11px; }
  .cal-cell { min-height: 64px; }
  .cal-event { font-size: 9px; }
  .cal-event-amt { display: none; }
}
