/* ============================================================
   Commission Plan — stili dedicati (§2.4: <appkey>-style.css)
   ------------------------------------------------------------
   Prima non esisteva: tutte le classi .cf-* vivevano in app/style.css, e alcune sezioni usavano
   classi mai definite (.cf-card in testa) rendendo card senza bordo, senza fondo e con tipografia
   di default — da cui il disallineamento visivo rispetto agli altri prodotti.

   ATTENZIONE — collisione di prefisso. Il prefisso .cf-* in app/style.css e' condiviso con il
   wizard "Cerca contatto" di SDRflow (dove cf sta per "contact finder"). Queste 18 classi sono
   usate da ENTRAMBI e NON vengono ridefinite qui, per non alterare il wizard:
     cf-badge, cf-badge-new, cf-bar, cf-btn, cf-btn-ghost, cf-btn-primary, cf-btn-sm,
     cf-btn-success, cf-chips, cf-empty, cf-empty-desc, cf-empty-state, cf-empty-title, cf-err,
     cf-hint, cf-input, cf-note-danger, cf-note-warn, cf-success, cf-table, cf-table-wrap
   Tutto cio' che segue e' o una classe NUOVA, o una regola SCOPED dentro un contenitore nuovo.
   Verifica automatica: `node scripts/css-prefix-owners.js cf` (FAIL se una regola di questo file
   colpisce markup di un'altra app).

   Riferimento tipografico e di componente: Strategy & Growth (app/strategy-style.css) — card,
   KPI, tabelle e spaziature sono allineate 1:1 a .stg-* per avere la stessa resa fra i prodotti.
   ============================================================ */

/* ── Palette per-app (§1.2: palette nel file dedicato, non colori sparsi) ── */
:root {
  --cf-primary: #4f6ef7;
  --cf-primary-light: #eef1fe;
  --cf-accent: #10b981;
  --cf-warn: #f59e0b;
  --cf-danger: #ef4444;
  /* Griglia dei grafici: letta dal JS via cfColor() perche' Chart.js non accetta var() (§1.2). */
  --cf-grid: #e2e8f0;
}

/* ── Testata di sezione (allineata a .stg-head) ── */
.cf-section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.cf-section-head h1 { margin: 0 0 .25rem; }
.cf-section-head-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

/* ── Card (allineata a .stg-card) ──
   .cf-card era usata nel markup ma NON esisteva nel CSS: i contenitori risultavano trasparenti,
   senza bordo e con il testo alla dimensione di default del browser. */
.cf-card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.cf-card-head { display: flex; justify-content: space-between; align-items: center; gap: .7rem; flex-wrap: wrap; margin-bottom: .7rem; }
.cf-card-title { font-size: .95rem; font-weight: 700; color: var(--text); margin: 0; display: flex; align-items: center; gap: .5rem; }
.cf-card-desc { font-size: .78rem; color: var(--muted); margin: -.4rem 0 .8rem; }

/* Titolo di blocco dentro una sezione: sostituisce gli <h3> nudi, che ereditavano una scala
   tipografica diversa da quella degli altri prodotti. */
.cf-section-title { font-size: .95rem; font-weight: 700; color: var(--text); margin: 1.4rem 0 .6rem; }
.cf-section-title:first-child { margin-top: 0; }

/* ── KPI strip (allineata a .stg-kpi*) ──
   Classi NUOVE: la .kpi-grid globale e' a `repeat(5,1fr)` fisso (resta a 5 colonne anche su
   mobile) e .kpi-value colora SEMPRE il valore di blu, mentre lo standard degli altri prodotti
   e' auto-fit con valore in colore testo e varianti semantiche. */
.cf-kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1.1rem; }
.cf-kpi { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: .9rem 1.1rem; }
.cf-kpi-val { font-size: 1.7rem; font-weight: 700; color: var(--text); letter-spacing: -.02em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.cf-kpi-val.good { color: var(--cf-accent); }
.cf-kpi-val.warn { color: var(--cf-warn); }
.cf-kpi-val.bad { color: var(--cf-danger); }
.cf-kpi-val.brand { color: var(--cf-primary); }
.cf-kpi-label { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-top: .3rem; }
.cf-kpi-hint { font-size: .72rem; color: var(--muted); margin-top: .2rem; min-height: 1rem; }

/* ── Tabelle (allineate a .stg-table) ──
   .cf-table e' CONDIVISA col wizard SDRflow: le regole sono quindi SCOPED dentro .cf-tbl,
   contenitore nuovo usato solo dalle sezioni di Commission Plan. Il wizard non ha .cf-tbl,
   quindi non viene toccato. */
.cf-tbl { background: #fff; border: 1px solid var(--border); border-radius: 12px; overflow-x: auto; margin-bottom: 1rem; }
.cf-tbl .cf-table { width: 100%; border-collapse: collapse; font-size: .85rem; table-layout: auto; }
.cf-tbl .cf-table thead th {
  text-align: left; padding: .7rem .9rem; font-size: .7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  border-bottom: 1px solid var(--border); white-space: nowrap; background: #fafbfc;
}
.cf-tbl .cf-table thead th.cf-th-num { text-align: right; font-variant-numeric: tabular-nums; }
/* Header ordinabile (§1.4): indicatore a destra, nessuna selezione del testo al click. */
.cf-tbl .cf-table thead th.cf-th-sort { cursor: pointer; user-select: none; }
.cf-tbl .cf-table thead th.cf-th-sort:hover { color: var(--text); }
.cf-tbl .cf-table thead th .cf-sort-ind { margin-left: .25rem; opacity: .45; font-size: .8em; }
.cf-tbl .cf-table thead th.cf-th-sort.active .cf-sort-ind { opacity: 1; color: var(--cf-primary); }
/* §1.4.2: nessuno spill dalle celle — ellissi e tooltip sul testo pieno. */
/* font-size esplicito: la regola globale `.cf-table tbody td` in app/style.css impone .83rem, che
   qui va riportata a .85rem per combaciare con .stg-table del riferimento. */
.cf-tbl .cf-table tbody td {
  padding: .65rem .9rem; border-bottom: 1px solid #f0f2f5; vertical-align: middle;
  font-size: .85rem; color: var(--text); max-width: 420px; overflow: hidden; text-overflow: ellipsis;
  white-space: normal;
}
/* Variante compatta (usata nelle modali e nel breakdown per trimestre) */
.cf-tbl .cf-table.cf-table-sm tbody td { font-size: .82rem; padding: .5rem .8rem; }
.cf-tbl .cf-table.cf-table-sm thead th { font-size: .68rem; padding: .55rem .8rem; }
.cf-tbl .cf-table tbody td.cf-num { text-align: right; font-variant-numeric: tabular-nums; }
.cf-tbl .cf-table tbody tr:hover { background: var(--cf-primary-light); }
.cf-tbl .cf-table tbody tr:last-child td { border-bottom: none; }
.cf-tbl .cf-table tfoot td { padding: .65rem .9rem; font-weight: 700; border-top: 1px solid var(--border); background: #fafbfc; }
.cf-cellsub { display: block; font-size: .72rem; color: var(--muted); margin-top: .15rem; }

/* ── Toolbar di sezione: filtri di contenuto + filtri temporali (§1.4.3) ── */
/* Nomi esclusivi: .cf-bar e .cf-chips esistono nel CSS globale e le usa il wizard "Cerca contatto"
   di SDRflow. Ridichiararle qui (questo file carica dopo style.css) cambiava la resa di quell'altra
   app. §2.4: un prefisso ha un solo proprietario, e in caso di omonimia si rinomina la propria. */
.cf-filterbar { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .7rem; }
.cf-filterbar-end { margin-left: auto; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.cf-search { position: relative; display: inline-flex; align-items: center; }
.cf-search input { padding: .45rem .6rem .45rem 2rem; border: 1px solid var(--border); border-radius: 8px; font-size: .82rem; min-width: 220px; background: #fff; color: var(--text); }
.cf-search svg { position: absolute; left: .55rem; width: 15px; height: 15px; color: var(--muted); pointer-events: none; }
/* Preset temporali (§1.4.3): background esplicito anche sullo stato inattivo (§1.2 vieta i
   bottoni trasparenti). */
.cf-seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.cf-seg button { padding: .4rem .7rem; font-size: .78rem; font-weight: 600; border: none; background: #f8fafc; color: var(--text-secondary); cursor: pointer; }
.cf-seg button + button { border-left: 1px solid var(--border); }
.cf-seg button.active { background: var(--cf-primary); color: #fff; }
/* Chip dei filtri attivi, rimovibili (§1.4.3) */
.cf-filterchips { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-bottom: .7rem; }
.cf-chip-active { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .5rem .2rem .6rem; border-radius: 999px; background: var(--cf-primary-light); color: var(--cf-primary); border: 1px solid #d8def9; font-size: .74rem; font-weight: 600; }
.cf-chip-active button { border: none; background: #dbe1fb; color: var(--cf-primary); cursor: pointer; border-radius: 50%; width: 16px; height: 16px; line-height: 1; font-size: .8rem; display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.cf-chip-clear { background: #f1f5f9; color: var(--text-secondary); border: 1px solid var(--border); border-radius: 999px; padding: .2rem .6rem; font-size: .74rem; font-weight: 600; cursor: pointer; }

/* ── Paginazione (§1.4: oltre 50 righe) ── */
.cf-pager { display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; font-size: .8rem; color: var(--muted); }
.cf-pager-btns { display: flex; align-items: center; gap: .35rem; }
.cf-pager button { padding: .3rem .6rem; border: 1px solid var(--border); border-radius: 6px; background: #f8fafc; color: var(--text-secondary); cursor: pointer; font-size: .78rem; font-weight: 600; }
.cf-pager button:disabled { opacity: .5; cursor: not-allowed; }
.cf-pager button.active { background: var(--cf-primary); color: #fff; border-color: var(--cf-primary); }

/* ── Skeleton al primo caricamento (§1.6), come .stg-skel ── */
.cf-skel { background: linear-gradient(90deg, #f1f5f9 25%, #e8edf3 50%, #f1f5f9 75%); background-size: 200% 100%; animation: cf-shimmer 1.2s infinite; border-radius: 12px; min-height: 90px; margin-bottom: .8rem; }
.cf-skel-row { min-height: 44px; border-radius: 8px; }
@keyframes cf-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .cf-skel { animation: none; } }

/* ── Bottone distruttivo: era usato nel markup ma mai definito ── */
.cf-btn-danger { background: var(--cf-danger); color: #fff; }
.cf-btn-danger:hover { background: #dc2626; }

/* ── Grafici: altezza riservata per evitare layout shift (§1.6) ── */
.cf-chart-card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.1rem; margin-bottom: 1rem; }
.cf-chart-card canvas { max-height: 280px; }

/* ── Segmenti di stato in Qualità dati: il segmento attivo deve distinguersi da un filtro spento,
      altrimenti non si capisce quale elenco si sta guardando ── */
.cf-chip-clear.active {
  background: var(--cf-primary);
  color: #fff;
  border-color: var(--cf-primary);
}

/* ── Storico contatti SDR sotto la riga del deal: spiega perché il deal è attribuito a quella
      persona (regola: ultimo contatto prima dell'apertura della trattativa) ── */
.cf-sdr-history td { background: #f8fafc; padding: 0 !important; }
.cf-sdr-history-box { padding: .7rem .9rem; border-left: 3px solid var(--cf-primary); }
.cf-sdr-history-title { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: .45rem; }
.cf-sdr-history-box ul { margin: 0; padding-left: 1.1rem; font-size: .8rem; line-height: 1.5; }
.cf-sdr-history-box li.vincente { font-weight: 600; }
.cf-sdr-date { font-variant-numeric: tabular-nums; color: var(--muted); margin-right: .35rem; }

/* ── Drill-down: note che dichiarano lo scostamento fra dato live e motore (FE-15) ── */
.cf-detail-calc-notes {
  margin: .6rem 0 0;
  padding-left: 1.1rem;
  font-size: .78rem;
  line-height: 1.45;
  color: var(--muted);
}
.cf-detail-calc-notes li { margin-bottom: .25rem; }

/* ── KPI combinati: riga di riepilogo del gruppo e badge sui membri (CALC-10) ── */
.cf-badge-group { background: #e0e7ff; color: #3730a3; }
.cf-track-group-row { background: #f8fafc; }
.cf-track-group-row td { border-top: 1px dashed var(--border); }

/* ── Badge di collegamento assegnazione-utente e conferma di salvataggio ──
   Erano stili inline nel JS con colori hardcoded: §1.2 li vuole qui. */
.cf-link-badge {
  font-size: .72rem; font-weight: 600; padding: .15rem .4rem; border-radius: 10px;
  background: var(--bg-secondary, #f1f5f9); color: var(--muted);
}
.cf-link-badge.on { background: #dcfce7; color: #166534; }
.cf-saved-hint {
  font-size: .75rem; color: var(--cf-accent); margin: .6rem 0 0;
  opacity: 0; transition: opacity .3s;
}

/* ── Errore su input di tabella (§1.1: inline con role="alert", non in toast) ── */
.cf-cell-err {
  display: block;
  color: var(--danger);
  font-size: .72rem;
  font-weight: 500;
  line-height: 1.25;
  margin-top: .25rem;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Responsive (§1.4): sotto 768px le tabelle scorrono e la KPI strip va a una colonna ── */
@media (max-width: 768px) {
  .cf-kpi-grid { grid-template-columns: 1fr 1fr; }
  .cf-search input { min-width: 0; width: 100%; }
  .cf-filterbar-end { margin-left: 0; width: 100%; }
}
@media (max-width: 480px) {
  .cf-kpi-grid { grid-template-columns: 1fr; }
}
