/* ============================================================
   IPO Performance Analysis — overlay full-screen
   Prefisso: ipo-  | layout coerente con la seasonality dashboard
   Usa SEMPRE i design token di global.css, mai valori hardcoded.
   ============================================================ */

.ipo-overlay {
  position: fixed; inset: 0;
  z-index: 4000;
  display: none;
  background: var(--bg, #0a0b0f);
}
.ipo-overlay.open { display: block; }

.ipo-modal {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  font-family: var(--font-ui);
  color: var(--text);
}

/* ── Header ────────────────────────────────────────────── */
.ipo-header {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--divider-soft, rgba(255,255,255,.07));
  flex: 0 0 auto;
}
.ipo-header-title { font-size: 1.05rem; font-weight: 600; letter-spacing: .2px; }
.ipo-header-sub { font-size: .9rem; color: var(--text-dim); font-weight: 500; }
.ipo-header-spacer { flex: 1; }
.ipo-close {
  width: 26px; height: 26px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; line-height: 1; cursor: pointer;
  background: transparent; border: none; color: var(--text-dim);
  transition: var(--ease, .15s ease);
}
.ipo-close:hover { background: rgba(255,255,255,var(--hover-medium, .08)); color: var(--text); }

/* ── 2-column layout ──────────────────────────────────── */
.ipo-cols { flex: 1; display: flex; min-height: 0; }

.ipo-left {
  flex: 0 0 320px; min-width: 0;
  border-right: 1px solid var(--divider-soft, rgba(255,255,255,.07));
  display: flex; flex-direction: column; overflow: hidden;
}
.ipo-main {
  flex: 1; min-width: 0; min-height: 0;
  display: flex; flex-direction: column; overflow: hidden;
  padding: 14px 16px; gap: 12px;
}
.ipo-main-scroll {
  flex: 1; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; gap: 12px;
}
.ipo-right {
  flex: 0 0 330px; min-width: 0;
  border-left: 1px solid var(--divider-soft, rgba(255,255,255,.07));
  overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column;
}

/* ── Left sidebar ─────────────────────────────────────── */
.ipo-left-scroll { flex: 1; overflow-y: auto; padding: 12px; }
.ipo-section-label {
  font-size: .82rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .8px; margin: 14px 4px 8px;
}
.ipo-section-label:first-child { margin-top: 4px; }

.ipo-group-select {
  width: 100%;
  font-family: var(--font-ui); font-size: .92rem; font-weight: 500;
  padding: 8px 10px; border-radius: var(--radius-sm);
  background: rgba(255,255,255,.04); color: var(--text);
  border: 1px solid var(--surface-border, rgba(255,255,255,.12));
  cursor: pointer; transition: var(--ease, .15s ease); outline: none;
}
.ipo-group-select:hover { border-color: var(--surface-border-hi, rgba(255,255,255,.24)); }
.ipo-group-select:focus { border-color: var(--green, #26d97f); }
.ipo-group-select option { background: var(--panel, #101219); color: var(--text); }

/* Header lista titoli: label + bottone filtro coorti (stile seasonality) */
.ipo-tickers-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ipo-tickers-head .ipo-section-label { flex: 1; min-width: 0; }
.ipo-tickers-head .sn-dash-filters-btn.ipo-filt-on {
  background: var(--pill-active-bg); color: var(--pill-active-color); border-color: transparent;
}

.ipo-ticker-list { margin-top: 6px; display: flex; flex-direction: column; gap: 2px; }
.ipo-ticker {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 8px; border-radius: var(--radius-sm);
  cursor: pointer; transition: var(--ease, .15s ease);
}
.ipo-ticker:hover { background: rgba(255,255,255,var(--hover-subtle, .05)); }
.ipo-ticker.off { opacity: .4; }
.ipo-tk-check {
  width: 16px; height: 16px; flex: 0 0 auto; border-radius: 4px;
  border: 1.5px solid var(--surface-border-hi, rgba(255,255,255,.28));
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; color: var(--pill-active-color, #0c0e12);
}
.ipo-ticker:not(.off) .ipo-tk-check { background: var(--green, #26d97f); border-color: transparent; }
.ipo-tk-logo { width: 24px; height: 24px; flex: 0 0 auto; border-radius: 6px; object-fit: contain; background: #fff; }
.ipo-tk-logo-fb {
  width: 24px; height: 24px; flex: 0 0 auto; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: .78rem; font-weight: 700; color: #fff;
}
.ipo-tk-meta { flex: 1; min-width: 0; }
.ipo-tk-sym { font-size: .92rem; font-weight: 600; }
.ipo-tk-name { font-size: .82rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ipo-tk-warn { color: var(--amber, #f0b429); font-size: .9rem; cursor: help; }
/* Occhio show/hide linea sul grafico (riusa .sn-yl-eye della seasonality) */
.ipo-tk-eye { flex: 0 0 auto; }
.ipo-tk-eye.on { opacity: 1; color: var(--green, #26d97f); }
.ipo-tk-rm { color: var(--text-dim); font-size: 1rem; cursor: pointer; padding: 0 4px; opacity: 0; transition: var(--ease, .15s ease); }
.ipo-ticker:hover .ipo-tk-rm { opacity: 1; }
.ipo-tk-rm:hover { color: var(--red, #f0506e); }
.ipo-add-btn {
  margin-top: 8px; width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-dim);
  border: 1px dashed var(--surface-border-hi, rgba(255,255,255,.24));
  font-family: var(--font-ui); font-size: .88rem; font-weight: 500;
  cursor: pointer; transition: var(--ease, .15s ease);
}
.ipo-add-btn:hover { color: var(--text); border-color: var(--green, #26d97f); }

/* ── Center: controls ─────────────────────────────────── */
.ipo-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; flex: 0 0 auto; }
.ipo-controls-spacer { flex: 1; }
.ipo-ctrl-label { font-size: .82rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }
.ipo-seg {
  display: inline-flex; background: rgba(0,0,0,.25);
  border: 1px solid var(--divider-soft, rgba(255,255,255,.07));
  border-radius: var(--radius-sm); padding: 3px;
}
.ipo-seg button {
  font-family: var(--font-ui); font-size: .86rem; font-weight: 500;
  padding: 4px 12px; border: none; background: transparent;
  color: var(--text-dim); cursor: pointer; border-radius: 4px;
  transition: var(--ease, .15s ease);
}
.ipo-seg button.active { background: var(--surface-border-hi, rgba(255,255,255,.16)); color: var(--text); }
.ipo-reset-sel {
  font-family: var(--font-ui); font-size: .84rem; font-weight: 500;
  padding: 5px 12px; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-dim);
  border: 1px solid var(--surface-border, rgba(255,255,255,.12));
  cursor: pointer; transition: var(--ease, .15s ease);
}
.ipo-reset-sel:hover { color: var(--text); border-color: var(--surface-border-hi, rgba(255,255,255,.24)); }

/* ── Chart ────────────────────────────────────────────── */
.ipo-chart-wrap {
  flex: 0 0 auto; position: relative; height: 50vh; min-height: 300px;
  border: 1px solid var(--divider-soft, rgba(255,255,255,.07));
  border-radius: var(--radius-md); padding: 8px;
}
.ipo-chart-hint {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  font-size: .82rem; color: var(--text-dim); pointer-events: none; opacity: .7;
}
/* Reset zoom: dentro la chart, in alto a destra, solo quando zoommato */
.ipo-zoom-reset {
  display: none; position: absolute; top: 10px; right: 12px; z-index: 3;
  font-family: var(--font-ui); font-size: .82rem; font-weight: 500;
  padding: 5px 12px; border-radius: var(--radius-sm);
  background: var(--overlay-bg, rgba(20,22,28,.85)); backdrop-filter: blur(4px);
  color: var(--text-dim); border: 1px solid var(--surface-border, rgba(255,255,255,.14));
  cursor: pointer; transition: var(--ease, .15s ease);
}
.ipo-zoom-reset:hover { color: var(--text); border-color: var(--surface-border-hi, rgba(255,255,255,.24)); }
.ipo-readout {
  position: absolute; top: 12px; left: 14px;
  pointer-events: none; z-index: 2;
  background: var(--divider-soft); backdrop-filter: blur(4px);
  border: 1px solid var(--border-hi); border-radius: var(--radius-md);
  padding: 9px 12px; font-size: .84rem; color: var(--text); line-height: 1.5;
}
.ipo-ro-head {
  font-size: .82rem; color: var(--text-muted); margin-bottom: 5px;
  padding-bottom: 4px; border-bottom: 1px solid var(--surface-raised);
  text-transform: uppercase; letter-spacing: .4px; white-space: nowrap;
}
.ipo-ro-row { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.ipo-ro-row b { margin-left: auto; font-weight: 700; padding-left: 14px; font-family: var(--font-ui); }
.ipo-ro-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.ipo-ro-mean { background: var(--text-dim); }
.ipo-spinner {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center; flex-direction: column; gap: 12px;
  font-size: .9rem; color: var(--text-dim); background: rgba(0,0,0,.2);
}
.ipo-spinner.on { display: flex; }
.ipo-spin-ring {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.12); border-top-color: var(--green, #26d97f);
  animation: ipo-spin .8s linear infinite;
}
@keyframes ipo-spin { to { transform: rotate(360deg); } }

/* ── Scrollbar orizzontale sotto l'asse X (solo quando zoommato) ── */
.ipo-scroll {
  display: none; position: relative; height: 10px; flex: 0 0 auto;
  margin: 2px 8px 0; border-radius: 999px;
  background: rgba(255,255,255,.05);
}
.ipo-scroll.on { display: block; }
.ipo-scroll-thumb {
  position: absolute; top: 0; height: 100%; min-width: 24px;
  border-radius: 999px; cursor: grab;
  background: rgba(255,255,255,.22); transition: background var(--ease, .15s ease);
}
.ipo-scroll-thumb:hover { background: rgba(255,255,255,.34); }
.ipo-scroll-thumb:active { cursor: grabbing; background: var(--green, #26d97f); }

/* ── Leggenda a pallini (sotto la chart) ──────────────── */
.ipo-legend {
  display: flex; flex-wrap: wrap; gap: 8px 16px;
  padding: 2px 4px; flex: 0 0 auto;
}
.ipo-leg-item { display: flex; align-items: center; gap: 7px; font-size: .85rem; color: var(--text-dim); }
.ipo-leg-dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
/* Voci per-titolo cliccabili: toggle visibilita' dal grafico/aggregato */
.ipo-leg-item.ipo-leg-tog { cursor: pointer; user-select: none; border-radius: var(--radius-sm); padding: 1px 6px; transition: var(--ease, .15s ease); }
.ipo-leg-item.ipo-leg-tog:hover { background: rgba(255,255,255,var(--hover-subtle, .05)); color: var(--text); }
.ipo-leg-item.ipo-leg-tog.off { opacity: .4; text-decoration: line-through; }

/* ── Tabella rendimenti per orizzonte (stile year-list seasonality) ── */
/* La tabella scrolla per conto suo (Y + X), il grafico resta fisso */
.ipo-matrix { flex: 1 1 auto; min-height: 80px; overflow: auto; }
.ipo-mx { width: 100%; border-collapse: collapse; font-family: var(--font-ui); font-size: 1.07rem; white-space: nowrap; }
.ipo-mx th {
  text-align: right; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .4px;
  padding: 4px 10px 6px; position: sticky; top: 0; background: var(--bg);
  border-bottom: 1px solid var(--surface-raised);
}
.ipo-mx th:first-child, .ipo-mx td:first-child {
  text-align: left; position: sticky; left: 0; background: var(--bg); z-index: 1; font-weight: 600;
}
/* Header sopra le righe quando si scrolla in verticale (il tbody segue nel DOM) */
.ipo-mx thead th { z-index: 3; background: var(--bg); }
.ipo-mx thead th:first-child { z-index: 4; }
.ipo-mx td {
  padding: 5px 10px; text-align: right; color: var(--text);
  border-bottom: 1px solid var(--hover-subtle);
}
.ipo-mx tbody tr { transition: background var(--ease); }
.ipo-mx tbody tr:hover td { background: var(--divider-soft); }
.ipo-mx tbody tr:hover td:first-child { background: var(--divider-soft); }
.ipo-mx-avg td { font-weight: 700; color: #c3a05f; background: var(--divider-soft); border-bottom: 1px solid var(--surface-raised); }
.ipo-mx-avg td:first-child { background: var(--divider-soft); }
/* Righe dei singoli titoli: font ridotto di 2px rispetto alle aggregate */
.ipo-mx tbody tr:not(.ipo-mx-avg) td { font-size: .94rem; }
.ipo-mx-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; vertical-align: middle; }

.ipo-pos { color: var(--green); }
.ipo-neg { color: var(--red); }

/* ── Matrice di correlazione (modalita' H1) ───────────── */
.ipo-corr-sec { flex: 0 0 auto; }
.ipo-corr { overflow-x: auto; }
.ipo-corr-empty { padding: 16px 2px; font-size: .86rem; color: var(--text-dim); }
.ipo-corr-tbl { border-collapse: collapse; font-family: var(--font-ui); font-size: .8rem; }
.ipo-corr-tbl th {
  color: var(--text-muted); font-weight: 600; padding: 5px 8px; white-space: nowrap;
  position: sticky; background: var(--bg);
}
.ipo-corr-tbl thead th { top: 0; border-bottom: 1px solid var(--surface-raised); }
.ipo-corr-tbl tbody th { left: 0; text-align: left; border-right: 1px solid var(--surface-raised); z-index: 1; }
.ipo-corr-cell {
  text-align: center; padding: 5px 9px; min-width: 46px;
  color: var(--text); font-weight: 600;
  border-bottom: 1px solid var(--hover-subtle);
}

/* ── Right panel: statistiche di periodo ──────────────── */
.ipo-stats-empty { padding: 26px; text-align: center; font-size: .9rem; color: var(--text-dim); line-height: 1.5; }
/* Rendimento per titolo: barre orizzontali (stile year-list seasonality) */
.ipo-dist { display: flex; flex-direction: column; gap: 2px; }
.ipo-dist-row { display: flex; align-items: center; gap: 9px; padding: 2px 0; }
.ipo-dist-sym { flex: 0 0 50px; font-size: .82rem; font-weight: 600; color: var(--text); }
.ipo-dist-row .sn-yl-bar-track { flex: 1; }
.ipo-dist-val { flex: 0 0 50px; text-align: right; font-size: .82rem; font-weight: 600; font-family: var(--font-ui); }
