:root {
  --bg: #0e1116; --panel: #151a22; --panel-2: #1b212b; --border: #262d38;
  --text: #e6eaf0; --muted: #8b95a5;
  --green: #2ecc71; --green-dim: #1c5c3a;
  --red: #e74c3c; --red-dim: #5e2420;
  --blue: #4f8cff;
  --amber: #f0b430;
  --purple: #a78bfa;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
header {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 12px 22px; border-bottom: 1px solid var(--border); background: #10141b;
  flex-wrap: wrap;
}
.brand { display: flex; gap: 12px; align-items: center; }
.logo {
  width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center;
  font-weight: 800; background: linear-gradient(135deg, var(--blue), #2b5fd9); color: #fff;
}
h1 { margin: 0; font-size: 20px; }
h1 .tag { font-size: 11px; color: var(--blue); border: 1px solid rgba(79,140,255,.4); background: rgba(79,140,255,.1); padding: 1px 7px; border-radius: 20px; vertical-align: middle; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.statusbar { display: flex; align-items: center; gap: 12px; }
.clock { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 78px; text-align: right; }
.sub { color: var(--muted); font-size: 12px; }
.data-chip {
  display: inline-block; min-width: 96px; text-align: center; font-size: 12px;
  padding: 7px 11px; border-radius: 8px; border: 1px solid var(--border);
  color: var(--muted); background: rgba(38,45,56,.35); white-space: nowrap;
}

/* Barra Regime Macro nell'header */
.regime-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.reg-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; padding: 5px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  white-space: nowrap;
}
.reg-pill.bull { border-color: rgba(46,204,113,.4); background: rgba(46,204,113,.08); }
.reg-pill.bear { border-color: rgba(231,76,60,.45); background: rgba(231,76,60,.10); }
.reg-pill.range { border-color: rgba(240,180,48,.35); background: rgba(240,180,48,.07); }

.btn {
  background: var(--blue); color: #fff; border: 0; border-radius: 8px; padding: 9px 16px;
  font-weight: 600; cursor: pointer;
}
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.small { padding: 6px 12px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

.tabs { display: flex; gap: 8px; padding: 10px 22px 0; flex-wrap: wrap; }
.tab {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: 9px; padding: 8px 18px; cursor: pointer; font-weight: 600; font-size: 13px;
}
.tab.active { color: #fff; border-color: var(--blue); background: rgba(79,140,255,.12); }

main { padding: 14px 22px 30px; width: 100%; }
.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px;
  min-width: 0;
}
.col-4 { grid-column: span 4; } .col-5 { grid-column: span 5; }
.col-6 { grid-column: span 6; }
.col-7 { grid-column: span 7; } .col-8 { grid-column: span 8; }
.col-12 { grid-column: span 12; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 10px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 15px; }
.muted { color: var(--muted); font-weight: 400; font-size: 12px; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.dot.buy { background: var(--green); } .dot.sell { background: var(--red); } .dot.neutral { background: var(--amber); }

.chart-legend {
  display: flex; gap: 12px; font-size: 11px; color: var(--muted); margin-bottom: 6px; flex-wrap: wrap; align-items: center;
}
.line-dot {
  display: inline-block; width: 10px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 4px;
}
.line-dot.sma20 { background: #4f8cff; }
.line-dot.sma50 { background: #f0b430; }
.line-dot.sma200 { background: #a78bfa; }
.line-dot.vwap { background: #f0b430; }
.line-dot.tp { background: #2ecc71; }
.line-dot.sl { background: #e74c3c; }
.line-dot.cone {
  background: repeating-linear-gradient(90deg, #a78bfa 0 3px, transparent 3px 6px);
  height: 2px; width: 14px;
}
.candle-est-box {
  display: inline-block; width: 9px; height: 9px; border-radius: 2px;
  vertical-align: middle; margin-right: 4px;
}
.candle-est-box.up {
  background: rgba(56, 189, 248, 0.25); border: 1.5px solid #38bdf8;
}
.candle-est-box.dn {
  background: rgba(192, 132, 252, 0.25); border: 1.5px solid #c084fc;
}

.forecast-banner {
  margin-top: 8px; padding: 9px 12px; border-radius: 10px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.08), rgba(167, 139, 250, 0.08));
  border: 1px dashed rgba(56, 189, 248, 0.45);
  font-size: 12px; line-height: 1.45; color: var(--text);
}
.forecast-banner .fc-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
}
.forecast-banner .fc-tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-weight: 700; font-size: 11.5px; color: #38bdf8;
}
.forecast-banner .fc-drivers {
  margin-top: 4px; font-size: 11.5px; color: var(--muted);
}

/* Pannello doppio: Target Price in caso di acquisto (Swing) + Quick-Selling (Poche ore) */
.targets-panel {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px;
}
.tp-card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 12px; line-height: 1.45;
}
.tp-card.qs-good {
  border-color: rgba(56, 189, 248, 0.5);
  background: linear-gradient(145deg, rgba(56, 189, 248, 0.09), rgba(27, 33, 43, 0.95));
}
.tp-card-head {
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
  margin-bottom: 6px; font-weight: 700; font-size: 12px; color: var(--text);
}
.tp-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 6px;
  padding: 2px 0; font-variant-numeric: tabular-nums;
}
.tp-row .lbl { color: var(--muted); font-size: 11.5px; }
.tp-foot {
  margin-top: 6px; padding-top: 5px; border-top: 1px dashed rgba(139, 149, 165, 0.22);
  font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 6px; flex-wrap: wrap;
}

.qs-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 12px;
  white-space: nowrap;
}
.qs-badge.ottimo {
  background: rgba(46, 204, 113, 0.22); color: #6ee7b7; border: 1px solid rgba(46, 204, 113, 0.45);
}
.qs-badge.buono {
  background: rgba(56, 189, 248, 0.20); color: #38bdf8; border: 1px solid rgba(56, 189, 248, 0.45);
}
.qs-badge.moderato {
  background: rgba(240, 180, 48, 0.15); color: var(--amber);
}
.qs-badge.sconsigliato {
  background: rgba(139, 149, 165, 0.14); color: var(--muted);
}

.qs-window-pill {
  display: inline-block; font-size: 11px; font-weight: 600; color: #38bdf8;
  background: rgba(56, 189, 248, 0.12); padding: 1px 6px; border-radius: 5px;
}
.line-dot.qs-tp {
  background: #38bdf8;
}
.btn-xs {
  background: rgba(56, 189, 248, 0.16); color: #38bdf8; border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: 6px; padding: 2px 7px; font-size: 11px; font-weight: 600; cursor: pointer;
}
.btn-xs:hover { background: rgba(56, 189, 248, 0.28); color: #fff; }
@media (max-width: 680px) {
  .targets-panel { grid-template-columns: 1fr; }
}

.table-wrap { overflow-x: auto; max-height: 480px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
td { padding: 8px; border-bottom: 1px solid rgba(38,45,56,.55); white-space: nowrap; }
tr.row { cursor: pointer; }
tr.row:hover { background: var(--panel-2); }
tr.selected { background: rgba(79,140,255,.10); }
.chg-pos { color: var(--green); font-weight: 600; }
.chg-neg { color: var(--red); font-weight: 600; }

.score-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 50px; padding: 3px 8px; border-radius: 7px; font-weight: 700; }
.score.pos { background: rgba(46,204,113,.15); color: var(--green); }
.score.neg { background: rgba(231,76,60,.15); color: var(--red); }
.score.neu { background: rgba(240,180,48,.13); color: var(--amber); }

/* Action tags (sia nomi italiani generati da app.js sia alias inglesi) */
.action-tag { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px; display: inline-block; }
.action-compra, .action-buy { background: rgba(46,204,113,.16); color: var(--green); }
.action-compra-forte, .action-buy-forte { background: rgba(46,204,113,.32); color: #73e69b; border: 1px solid rgba(46,204,113,.45); }
.action-vendi, .action-sell { background: rgba(231,76,60,.16); color: #ff8a75; }
.action-vendi-forte, .action-sell-forte { background: rgba(231,76,60,.34); color: #ffb0a1; border: 1px solid rgba(231,76,60,.45); }
.action-osta, .action-Osta { background: rgba(139,149,165,.15); color: var(--muted); }

.setup-pill {
  display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 6px;
  background: var(--panel-2); border: 1px solid var(--border); color: #c4cbd6;
}
.earn-warn {
  display: inline-block; font-size: 10.5px; padding: 1px 6px; border-radius: 5px;
  background: rgba(231,76,60,.2); color: #ff8a75; font-weight: 600; margin-left: 4px;
}
.trail-badge {
  display: inline-block; font-size: 10px; padding: 1px 5px; border-radius: 4px;
  background: rgba(46,204,113,.2); color: var(--green); font-weight: 700;
}

.conf-bar { display: inline-block; vertical-align: middle; position: relative; background: var(--panel-2); border-radius: 4px; height: 7px; width: 54px; overflow: hidden; }
.conf-fill { position: absolute; inset: 0 auto 0 0; background: var(--blue); }
.rumor { color: var(--amber); font-size: 13px; font-weight: 600; }

.quote { font-size: 15px; font-variant-numeric: tabular-nums; }
.chart { height: 300px; }
.chart.small { height: 240px; }
.figures { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 8px; margin-top: 10px; }
.fig { background: var(--panel-2); border-radius: 9px; padding: 8px 10px; }
.fig .k { color: var(--muted); font-size: 11px; }
.fig .v { font-weight: 700; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.fig .v.pos { color: var(--green); } .fig .v.neg { color: var(--red); } .fig .v.neu { color: var(--amber); }

#detail-reasons { margin-top: 10px; }
.reason { display: flex; gap: 8px; padding: 4px 0; font-size: 12.5px; color: #c4cbd6; border-bottom: 1px dashed rgba(38,45,56,.6); }
.reason b { color: var(--text); }
.news-line { font-size: 12.5px; color: var(--muted); padding: 6px 0; border-bottom: 1px solid rgba(38,45,56,.6); }
.news-line a { color: var(--text); text-decoration: none; }
.news-line a:hover { text-decoration: underline; }
.news-line .s { font-weight: 700; }

.subhead { margin: 12px 0 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.trades { max-height: 260px; }
.pf-panel .big { font-size: 20px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #223; border: 1px solid var(--border); color: var(--text);
  padding: 10px 18px; border-radius: 10px; font-size: 13px; z-index: 30;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.hidden { display: none; }

/* ---- portafogli ---- */
.pf-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.pf-cards { display: flex; gap: 10px; flex: 1; overflow-x: auto; padding-bottom: 2px; }
.pf-card {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 12px; padding: 10px 14px; min-width: 230px; cursor: pointer; text-align: left;
  font-size: 13px;
}
.pf-card:hover { background: var(--panel-2); }
.pf-card.active { border-color: var(--blue); background: rgba(79,140,255,.10); }
.pf-card .rgt { text-align: right; }
.pf-card .eq { font-weight: 700; font-size: 15px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.form-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form-row.inline { display: flex; }
.form-row input, .form-row select {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; min-width: 130px;
}
#add-form input {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 10px; width: 150px; font-size: 13px;
}
.risk-desc { margin-top: 8px; }
.sug {
  display: flex; align-items: center; gap: 8px; padding: 8px 4px;
  border-bottom: 1px solid rgba(38,45,56,.6); font-size: 13px; flex-wrap: wrap;
}
.sug .sp { flex: 1; }
.activity { max-height: 300px; overflow-y: auto; font-size: 12.5px; }
.act { padding: 5px 2px; border-bottom: 1px solid rgba(38,45,56,.6); color: #c4cbd6; }
.act .t { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 8px; }
.note-line {
  font-size: 11.5px; color: var(--amber); margin-top: 2px;
  max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.grow { flex: 1; min-width: 200px !important; }
.grow input { width: 100% !important; }

/* ---- sfondo rumor attivo e barra LLM ---- */
.llm-bar { display: flex; align-items: center; gap: 8px; }
.llm-bar select, #rumor-filter {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 13px;
}
#rumor-filter { width: 240px; }
.llm-bar select { max-width: 260px; }

/* ---- registro rumor (vista leggibile a due colonne) ---- */
.rumor-card {
  display: flex; gap: 16px; padding: 12px 10px;
  border-bottom: 1px solid rgba(38,45,56,.7); align-items: flex-start;
}
.rumor-card.is-active { background: rgba(240,180,48,.06); }
.rumor-sym {
  min-width: 128px; max-width: 128px; display: flex; flex-direction: column; gap: 2px;
}
.rumor-sym b { font-size: 15px; color: var(--text); }
.rumor-sym .nm { font-size: 11px; color: var(--muted); }
.rumor-sym button {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 7px 10px; cursor: pointer; text-align: left; font-size: 13px;
}
.rumor-sym button:hover { border-color: var(--blue); }
.rumor-body { flex: 1; min-width: 0; }
.rumor-titleline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rumor-title {
  font-size: 14.5px; line-height: 1.45; color: var(--text);
  overflow-wrap: anywhere; white-space: normal;
}
.rumor-title:hover { text-decoration: underline; }
.rumor-meta { color: var(--muted); font-size: 12px; margin-top: 4px; line-height: 1.5; }
.rumor-pills { margin-top: 7px; display: flex; flex-wrap: wrap; gap: 6px; }
.kpill {
  display: inline-block; font-size: 11px; padding: 3px 9px; border-radius: 12px;
  background: rgba(79,140,255,.15); color: #9db9ff; text-transform: lowercase; font-weight: 600;
}
.spill.on { background: rgba(240,180,48,.2); color: var(--amber); }
.spill.off { background: rgba(139,149,165,.12); color: var(--muted); }
.spill { display: inline-block; font-size: 10.5px; padding: 2px 8px; border-radius: 12px; font-weight: 600; }
.good { color: var(--green); } .bad { color: var(--red); }

/* selettore di frequenza del grafico dettaglio */
.range-tabs { display: inline-flex; gap: 2px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.range-tabs button {
  background: transparent; border: 0; color: var(--muted); font-size: 12px; font-weight: 600;
  padding: 6px 10px; cursor: pointer;
}
.range-tabs button:hover { color: var(--text); background: var(--panel-2); }
.range-tabs button.active { background: rgba(79,140,255,.18); color: #fff; }

.spacer { flex: 1; }

footer { padding: 10px 22px 26px; color: var(--muted); font-size: 12px; width: 100%; }

/* ---- Verifica Previsioni a Posteriori & Auto-Raffinamento ---- */
.tab-badge {
  display: inline-block; font-size: 10.5px; font-weight: 700; padding: 1px 6px;
  border-radius: 10px; background: rgba(46, 204, 113, 0.22); color: #6ee7b7;
  margin-left: 4px; vertical-align: middle;
}
.pred-ctl-label {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted);
}
.pred-ctl-label select, #pred-search {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 6px 10px; font-size: 12.5px;
}
.pred-ctl-toggle {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  padding: 5px 10px; border-radius: 8px; border: 1px solid rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.09); color: #e6eaf0; cursor: pointer;
}
.pred-kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 10px; margin-top: 10px;
}
.pred-kpi {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 11px;
  padding: 10px 13px; display: flex; flex-direction: column; gap: 3px;
}
.pred-kpi .k-lbl { font-size: 11.5px; color: var(--muted); }
.pred-kpi .k-val { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.pred-kpi .k-sub { font-size: 11.5px; color: var(--muted); }
.pred-insights {
  display: flex; flex-direction: column; gap: 7px;
}
.insight-item {
  background: rgba(56, 189, 248, 0.07); border-left: 3px solid #38bdf8;
  border-radius: 6px; padding: 8px 11px; font-size: 12.5px; line-height: 1.45; color: var(--text);
}
.cal-params-bar {
  display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px;
}
.cal-pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; padding: 3px 9px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--border); color: #c4cbd6;
}
.pred-filters {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.verdict-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 700; padding: 4px 10px; border-radius: 20px;
  white-space: nowrap;
}
.verdict-badge.right {
  background: rgba(46, 204, 113, 0.20); color: #6ee7b7; border: 1px solid rgba(46, 204, 113, 0.45);
}
.verdict-badge.wrong {
  background: rgba(231, 76, 60, 0.20); color: #fca5a5; border: 1px solid rgba(231, 76, 60, 0.45);
}
.verdict-badge.pending {
  background: rgba(240, 180, 48, 0.16); color: var(--amber); border: 1px solid rgba(240, 180, 48, 0.40);
}
.pred-note {
  font-size: 11.5px; color: #c4cbd6; white-space: normal; max-width: 340px; line-height: 1.4;
}
.pred-lesson {
  font-size: 11px; color: var(--muted); white-space: normal; max-width: 340px; margin-top: 2px; font-style: italic;
}
.origin-tag {
  display: inline-block; font-size: 10px; padding: 1px 5px; border-radius: 4px;
  font-weight: 600; text-transform: uppercase;
}
.origin-tag.live { background: rgba(79, 140, 255, 0.2); color: #93c5fd; }
.origin-tag.storico { background: rgba(167, 139, 250, 0.16); color: #c4b5fd; }
.prog-bar {
  display: inline-block; width: 64px; height: 6px; background: #0e1116;
  border-radius: 4px; overflow: hidden; vertical-align: middle; margin-right: 5px;
  border: 1px solid var(--border);
}
.prog-fill { height: 100%; background: var(--green); }
.prog-fill.warn { background: var(--amber); }

@media (max-width: 1100px) {
  .col-4, .col-5, .col-6, .col-7, .col-8, .col-12 { grid-column: span 12; }
  .chart { height: 260px; }
}
