/* Font proprietario di Banca Generali ("generali"/"generali-black", visto su
   bancageneraliprivate.it) non e' redistribuibile - fallback dichiarato dal sito
   stesso per i titoli e' Montserrat, un geometric sans-serif molto simile per
   struttura/carattere. Vendorizzato in locale (stesso principio delle librerie JS:
   niente dipendenza da Google Fonts a runtime) - unico file variabile, pesi 100-900,
   sottoinsieme Latin (sufficiente per l'italiano, include accenti ed €). */
@font-face {
  font-family: "Montserrat";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/static/fonts/Montserrat-Variable.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
    U+FEFF, U+FFFD;
}

:root {
  /* Palette Banca Generali (estratta dal tema ufficiale RED_Percorso_Operativo.pptx
     e da BG Home): rosso/bianco/nero/grigio come base, blu/arancione/oro solo come
     accenti secondari nei grafici multi-serie - mai per la UI di navigazione. */
  --bg: #f7f7f7;
  --panel: #ffffff;
  --panel-border: #e2e2e2;
  --sidebar-bg: #111111;
  --sidebar-fg: #b3b3b3;
  --sidebar-fg-active: #ffffff;
  --sidebar-accent: #c21b17;
  --text: #2b2b2b;
  --text-muted: #828282;
  --accent: #c21b17;
  --accent-dark: #8e1230;
  --ok: #1f9d55;
  --ok-bg: #e5f7ec;
  --warn: #a9720b;
  --warn-bg: #fdf1dc;
  --danger: #c21b17;
  --danger-bg: #fbe8e7;
  --font: "Montserrat", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* Palette qualitativa per grafici a piu' serie/categorie - solo tinte di brand */
  --chart-1: #c21b17;
  --chart-2: #2b2b2b;
  --chart-3: #828282;
  --chart-4: #e9573d;
  --chart-5: #ffc000;
  --chart-6: #8e1230;
  --chart-7: #002060;
  --chart-8: #bdbdbd;
}

/* Garantisce che l'attributo hidden vinca sempre, anche contro regole con
   la stessa classe che impostano display (es. .mappa-overlay) - senza
   questo, un elemento nascosto via hidden puo' comunque comparire se una
   regola CSS successiva/piu' specifica sulla stessa classe forza display. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
}

a { color: inherit; text-decoration: none; }

.layout {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.sidebar-user {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 14px;
}
.sidebar-user-email { color: #9a9a9a; margin-bottom: 6px; word-break: break-all; }
.sidebar-user a { color: var(--sidebar-accent); font-weight: 600; }

.sidebar .brand {
  color: #fff;
  font-weight: 700;
  font-size: 21px;
  letter-spacing: 0.03em;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-mark {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}
.sidebar .brand .brand-thin { color: #9a9a9a; font-weight: 400; }

.sidebar .brand-sub {
  color: #7a7a7a;
  font-size: 13px;
  margin-bottom: 28px;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 16px;
  margin-bottom: 2px;
  color: var(--sidebar-fg);
  border-left: 3px solid transparent;
}

.sidebar nav a:hover { background: rgba(255,255,255,0.06); }
.sidebar nav a.active {
  background: rgba(194,27,23,0.16);
  border-left-color: var(--sidebar-accent);
  color: #fff;
  font-weight: 600;
}
.sidebar nav a.disabled { color: #5c5c5c; cursor: default; pointer-events: none; }

.nav-badge {
  margin-left: auto;
  background: var(--sidebar-accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
}

.content { padding: 28px 36px 60px; max-width: 1320px; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 22px;
}

.page-header h1 { font-size: 25px; margin: 0 0 4px; }
.page-header .subtitle { color: var(--text-muted); font-size: 15.5px; }

.search-box {
  display: flex;
  gap: 8px;
}

.search-box input[type=text] {
  padding: 9px 14px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  min-width: 320px;
  font-size: 16px;
}

.search-box button {
  padding: 9px 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 20px;
}

.card + .card { margin-top: 18px; }

.card h2 {
  font-size: 18px;
  margin: 0 0 14px;
  color: var(--text);
}
.card h2 .muted { color: var(--text-muted); font-weight: 400; font-size: 15px; }

.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }

.kpi-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 16px 18px;
}
.kpi-card .kpi-label { font-size: 14.5px; color: var(--text-muted); margin-bottom: 6px; }
.kpi-card .kpi-value { font-size: 27px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.kpi-card .kpi-sub { font-size: 14.5px; color: var(--text-muted); margin-top: 4px; }

.compbar {
  display: flex;
  height: 20px;
  border-radius: 8px;
  overflow: hidden;
  margin: 8px 0 10px;
  background: #eef1f4;
}
.compbar .seg { height: 100%; }
.compbar-legend { display: flex; gap: 16px; font-size: 14.5px; color: var(--text-muted); flex-wrap: wrap; }
.compbar-legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

table.data { width: 100%; border-collapse: collapse; font-size: 16px; }
table.data th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--panel-border);
}
table.data td { padding: 9px 10px; border-bottom: 1px solid #f0f2f4; }

/* Numerazione automatica delle righe, richiesta esplicitamente dall'utente
   per tutti gli elenchi (piattaforma E pdf, stesso foglio di stile) - un
   contatore CSS invece di toccare ogni singolo template: se la prima
   colonna e' l'icona tipologia immobile (.col-icona), il numero va sulla
   colonna successiva per non sporcare l'icona. Le righe di totale/riepilogo
   ("Altri...") restano escluse, non sono una "riga" dell'elenco. */
table.data tbody tr:not(.total-row):not(.altri) { counter-increment: riga; }
table.data tbody { counter-reset: riga; }
table.data tbody tr:not(.total-row):not(.altri) td:first-child:not(.col-icona)::before,
table.data tbody tr:not(.total-row):not(.altri) td.col-icona + td::before {
  content: counter(riga) ".  ";
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
table.data tr:last-child td { border-bottom: none; }
table.data tr.total-row td { font-weight: 700; border-top: 1px solid var(--panel-border); }
table.data tr.highlight td { background: #fbe8e7; font-weight: 600; }
table.data tr.altri td { color: var(--text-muted); font-style: italic; }

/* Micro-visualizzazione "sparkbar": una barra proporzionale al valore max
   della colonna, dietro al testo - tocco originale non presente nel
   riferimento Banca Generali (le sue tabelle sono a testo puro), pensato per
   leggere a colpo d'occhio le grandezze relative in liste lunghe. */
table.data td.bar-cell { position: relative; text-align: right; font-variant-numeric: tabular-nums; }
table.data td.bar-cell .bar-cell-fill {
  position: absolute;
  left: 0; top: 3px; bottom: 3px;
  background: linear-gradient(90deg, rgba(194,27,23,0.16), rgba(194,27,23,0.08));
  border-radius: 3px;
  z-index: 0;
}
table.data td.bar-cell .bar-cell-text { position: relative; z-index: 1; padding-right: 4px; }

/* Ordinamento e filtro "stile Excel" (vedi static/js/tabella.js) - applicato
   automaticamente a ogni tabella, nessuna marcatura richiesta nei template. */
table.data th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
table.data th.sortable:hover { color: var(--text); }
table.data th.sortable::after { content: "\2195"; margin-left: 5px; opacity: 0.35; font-size: 10px; }
table.data th.sortable.sort-asc::after { content: "\2191"; opacity: 1; color: var(--sidebar-accent, #c21b17); }
table.data th.sortable.sort-desc::after { content: "\2193"; opacity: 1; color: var(--sidebar-accent, #c21b17); }

.tabella-filtro { margin-bottom: 10px; }
.tabella-filtro input {
  width: 100%;
  max-width: 280px;
  padding: 7px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font-size: 15.5px;
  font-family: inherit;
}
.tabella-filtro input:focus { outline: none; border-color: #c21b17; }

/* Intestazione bloccata per le tabelle operative lunghe (es. Soggetti
   richiesti) - richiesto esplicitamente dall'utente per non perdere di
   vista i nomi delle colonne scorrendo un elenco di decine di soggetti.
   Serve un contenitore con altezza limitata: senza, "position:sticky" sul
   thead non avrebbe nulla rispetto a cui restare fisso durante lo scroll. */
.table-scroll-sticky { max-height: 72vh; overflow-y: auto; }
.table-scroll-sticky table.data thead th {
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 2;
  box-shadow: 0 1px 0 var(--panel-border);
}

/* Icona tipologia immobile (vedi webapp/icone.py) - colonna stretta, senza
   intestazione ne' freccia di ordinamento (::after si applica solo con
   testo, qui l'header resta vuoto apposta). */
table.data td.col-icona { width: 1%; white-space: nowrap; text-align: center; padding-right: 2px; }
table.data td.col-icona a { text-decoration: none; }
.icona-immobile { display: inline-flex; vertical-align: middle; }
.icona-immobile svg { display: block; }

/* Pallino rosso/verde stato travaso anagrafiche RED_2 -> RED_1 */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.dot-ok { background: var(--ok, #2e7d32); }
.dot-off { background: #c21b17; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.neutral { background: #eef1f4; color: var(--text-muted); }

.identity-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.identity-card .name { font-size: 23px; font-weight: 700; }
.identity-card .cf { color: var(--text-muted); font-size: 15.5px; margin-top: 2px; }
.identity-card .badges { display: flex; gap: 8px; }

.download-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--panel-border);
}
.download-row .download-label { font-size: 16px; color: var(--text); letter-spacing: 0.02em; }
.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.btn-download:hover { border-color: var(--accent); color: var(--accent); }
.btn-download::before { content: "\2193"; color: var(--accent); font-weight: 700; }

.soggetti-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  margin-bottom: 8px;
}
.soggetti-list-item:hover { border-color: var(--accent); }
.soggetti-list-item .name { font-weight: 600; }
.soggetti-list-item .cf { color: var(--text-muted); font-size: 15px; }
.soggetti-list-patrimonio {
  font-size: 14.5px;
  color: var(--text);
  text-align: right;
  line-height: 1.5;
  margin: 0 20px;
  white-space: nowrap;
}
.soggetti-list-patrimonio .muted { color: var(--text-muted); }

.alert-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 22px; }
.alert-summary-card {
  border-radius: 12px;
  padding: 18px;
  border: 1px solid var(--panel-border);
}
.alert-summary-card .n { font-size: 31px; font-weight: 800; font-variant-numeric: tabular-nums; }
.alert-summary-card .n .n-tot { font-size: 20px; font-weight: 600; color: var(--text-muted); }
.alert-summary-card .lbl { font-size: 15px; color: var(--text-muted); margin-top: 2px; }
.alert-summary-card .lbl .muted { display: block; font-size: 13px; margin-top: 2px; }
.alert-summary-card.danger { background: var(--danger-bg); }
.alert-summary-card.warn { background: var(--warn-bg); }

.chart-box { width: 100%; height: 260px; }
.chart-box.small { height: 180px; }

.empty-state { color: var(--text-muted); font-size: 15.5px; padding: 20px 0; text-align: center; }

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.auth-card {
  width: 360px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 32px;
}
.auth-label { display: block; font-size: 15px; color: var(--text-muted); margin: 14px 0 6px; }
.auth-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  font-size: 15.5px;
  font-family: var(--font);
}
.auth-submit {
  width: 100%;
  margin-top: 22px;
  padding: 11px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15.5px;
  cursor: pointer;
}
.auth-error {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 15.5px;
  margin-bottom: 4px;
}

.admin-msg {
  background: #eef4ff;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 15.5px;
  margin-bottom: 16px;
}

.mappa-box { margin-top: 14px; }
.mappa-iframe { width: 100%; height: 180px; border: 1px solid var(--panel-border); border-radius: 8px; cursor: pointer; }
.mappa-links { display: flex; gap: 14px; margin-top: 8px; font-size: 15px; }
.mappa-links a { color: var(--accent); font-weight: 600; }
.mappa-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.mappa-overlay[hidden] { display: none; }
.mappa-overlay-inner { background: var(--panel); border-radius: 12px; padding: 16px; width: min(900px, 92vw); }
.mappa-iframe-grande { width: 100%; height: 70vh; border: none; border-radius: 8px; }
.mappa-overlay-close { display: block; margin: 0 0 10px auto; background: none; border: none; font-size: 14px; font-weight: 700; color: var(--text); cursor: pointer; }

/* Aggregazione ad albero Manager -> Consulente (sezione Consulenti) -
   <details>/<summary> nativi, zero JS: espandi/comprimi gratis. */
.albero-riga {
  display: grid;
  grid-template-columns: 1fr 110px 140px 140px 140px 150px;
  gap: 10px;
  align-items: center;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.albero-header {
  display: grid;
  grid-template-columns: 1fr 110px 140px 140px 140px 150px;
  gap: 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 0 0 8px;
  border-bottom: 1px solid var(--panel-border);
  margin-bottom: 10px;
}
.albero-nome { font-weight: 600; }
details.albero-dettaglio { margin-bottom: 4px; }
details.albero-dettaglio summary {
  cursor: pointer;
  padding: 9px 10px;
  border-radius: 8px;
  list-style: none;
}
details.albero-dettaglio summary::-webkit-details-marker { display: none; }
details.albero-dettaglio summary::before { content: "\25B8"; display: inline-block; width: 14px; color: var(--text-muted); }
details.albero-dettaglio[open] > summary::before { content: "\25BE"; }
details.albero-dettaglio summary:hover { background: #f7f7f7; }
.albero-figli { margin-left: 22px; padding-left: 14px; border-left: 2px solid var(--panel-border); margin-top: 2px; }
.albero-figli .albero-riga { padding: 7px 10px; }

.toggle-group { display: flex; gap: 8px; }
.toggle-btn {
  padding: 8px 16px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text-muted);
  font-size: 15.5px;
  font-weight: 600;
  cursor: pointer;
}
.toggle-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
