/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #0d1117;
  --bg-surface:   #161b22;
  --bg-card:      #1c2230;
  --border:       #30363d;
  --accent:       #2563eb;
  --accent-hover: #1d4ed8;
  --green:        #16a34a;
  --red:          #dc2626;
  --yellow:       #ca8a04;
  --text:         #e6edf3;
  --text-muted:   #8b949e;
  --radius:       8px;
  --font:         'Inter', system-ui, -apple-system, sans-serif;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.5; }
.hidden { display: none !important; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 16px 0;
}

.sidebar-logo {
  padding: 0 16px 20px;
  font-size: 16px; font-weight: 700; color: var(--accent);
  border-bottom: 1px solid var(--border);
}

.sidebar-logo span { font-weight: 400; color: var(--text-muted); font-size: 12px; display: block; }

.sidebar-nav { flex: 1; padding: 16px 0; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px;
  color: var(--text-muted);
  cursor: pointer; border: none; background: none;
  width: 100%; text-align: left; font-size: 14px;
  border-left: 3px solid transparent;
  transition: color .15s, background .15s;
}
.nav-item:hover { color: var(--text); background: rgba(255,255,255,.04); }
.nav-item.active { color: var(--text); background: rgba(37,99,235,.1); border-left-color: var(--accent); }
.nav-item .icon { font-size: 16px; width: 18px; text-align: center; }

.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); }
.user-info { font-size: 12px; color: var(--text-muted); }
.user-info strong { display: block; color: var(--text); font-size: 13px; }
.btn-logout { margin-top: 8px; width: 100%; padding: 6px; background: none; border: 1px solid var(--border); color: var(--text-muted); border-radius: var(--radius); cursor: pointer; font-size: 12px; }
.btn-logout:hover { border-color: var(--red); color: var(--red); }

.main-content { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }

.topbar {
  height: 52px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
}
.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-meta { font-size: 12px; color: var(--text-muted); }

.page { padding: 24px; flex: 1; }
.page.hidden { display: none; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.card-title { font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 14px; }

/* ── Stat row ─────────────────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat-value.up { color: var(--green); }
.stat-value.down { color: var(--red); }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 8px 12px; color: var(--text-muted); font-weight: 500; font-size: 11px; text-transform: uppercase; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid rgba(48,54,61,.5); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.badge.up { background: rgba(22,163,74,.15); color: var(--green); }
.badge.down { background: rgba(220,38,38,.15); color: var(--red); }
.badge.neutral { background: rgba(139,148,158,.15); color: var(--text-muted); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn { padding: 8px 16px; border-radius: var(--radius); border: none; font-size: 13px; font-weight: 500; cursor: pointer; transition: background .15s; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: none; border: 1px solid var(--border); color: var(--text-muted); }
.btn-ghost:hover { border-color: var(--accent); color: var(--text); }
.btn-danger { background: rgba(220,38,38,.15); color: var(--red); border: 1px solid rgba(220,38,38,.3); }
.btn-danger:hover { background: rgba(220,38,38,.25); }
.ind-btn { padding: 3px 10px; border-radius: 12px; border: 1px solid var(--border); background: none; color: var(--text-muted); font-size: 11px; font-weight: 600; cursor: pointer; transition: all .15s; }
.ind-btn:hover { border-color: var(--accent); color: var(--text); }
.ind-btn.active { background: rgba(37,99,235,.15); border-color: var(--accent); color: var(--accent); }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 5px; }
input, select { width: 100%; padding: 9px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 14px; outline: none; }
input:focus, select:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-muted); }

/* ── Login page ──────────────────────────────────────────────────────────── */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.login-box { width: 100%; max-width: 380px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: 12px; padding: 36px 32px; }
.login-logo { font-size: 22px; font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.login-subtitle { font-size: 13px; color: var(--text-muted); margin-bottom: 28px; }
.login-tabs { display: flex; gap: 0; margin-bottom: 24px; border-bottom: 1px solid var(--border); }
.login-tab { padding: 8px 16px; background: none; border: none; color: var(--text-muted); font-size: 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.login-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.login-error { background: rgba(220,38,38,.1); border: 1px solid rgba(220,38,38,.3); color: var(--red); padding: 10px 12px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; display: none; }
.login-error.show { display: block; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 12px 18px; border-radius: var(--radius);
  font-size: 13px; color: var(--text);
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
  transform: translateY(80px); opacity: 0;
  transition: transform .25s, opacity .25s;
  z-index: 1000;
}
#toast.show { transform: translateY(0); opacity: 1; }
#toast.success { border-color: var(--green); }
#toast.error   { border-color: var(--red); }

/* ── Loading spinner ─────────────────────────────────────────────────────── */
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 500; padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 12px; width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 0;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 20px; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 16px 20px 20px; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; padding: 0 20px 20px; }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.page-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.page-tab {
  padding: 8px 16px; background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--text-muted); font-size: 13px; cursor: pointer; margin-bottom: -1px;
}
.page-tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ── Signals / Screening ─────────────────────────────────────────────────── */
.signals-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.signal-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; transition: border-color .15s, background .15s; }
.signal-card:hover { border-color: var(--accent); background: rgba(37,99,235,.07); }
.signal-card.active { border-color: var(--accent); background: rgba(37,99,235,.12); }
.signal-card-icon { font-size: 22px; margin-bottom: 6px; }
.signal-card-label { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 3px; }
.signal-card-desc { font-size: 11px; color: var(--text-muted); margin-bottom: 8px; }
.signal-card-count { font-size: 20px; font-weight: 700; color: var(--text-muted); }
.signal-card-count.has-matches { color: var(--accent); }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 13px; }

/* ── Inline actions ──────────────────────────────────────────────────────── */
.action-btn { background: none; border: none; cursor: pointer; padding: 4px 6px; border-radius: 4px; font-size: 14px; }
.action-btn:hover { background: rgba(255,255,255,.08); }

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-header h2 { font-size: 15px; font-weight: 600; }

/* ── Market tabs ─────────────────────────────────────────────────────────── */
.market-tab { color: var(--text-muted); transition: color .15s, background .15s; }
.market-tab.active { color: var(--text); background: rgba(37,99,235,.15); }
.market-tab:hover:not(.active) { color: var(--text); background: rgba(255,255,255,.04); }

/* ── Color helpers ───────────────────────────────────────────────────────── */
.text-up   { color: var(--green); }
.text-down { color: var(--red); }
.text-muted-sm { color: var(--text-muted); font-size: 12px; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 56px; }
  .sidebar-logo span, .nav-item span:not(.icon), .sidebar-footer .user-info strong, .sidebar-footer .user-info small { display: none; }
  .nav-item { justify-content: center; padding: 12px; }
}

/* ── Forecast Dashboard ──────────────────────────────────────────────────── */

/* Market Status Bar */
.forecast-market-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 0;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 16px;
  margin-bottom: 12px; font-size: 13px;
}
.fmb-item { display: flex; flex-direction: column; gap: 2px; padding: 0 14px; }
.fmb-label { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.fmb-value { font-weight: 600; font-size: 13px; }
.fmb-badge { font-weight: 700; font-size: 12px; padding: 2px 8px; border-radius: 4px; letter-spacing: .3px; }
.fmb-sep { color: var(--border); font-size: 16px; align-self: center; }

/* Summary Pills */
.forecast-summary-bar {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.fsb-item {
  display: flex; flex-direction: column; align-items: center;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 16px; min-width: 80px;
}
.fsb-item.clickable-pill { cursor: pointer; transition: border-color .15s; }
.fsb-item.clickable-pill:hover { border-color: rgba(255,255,255,.2); }
.fsb-count { font-size: 22px; font-weight: 700; line-height: 1; }
.fsb-label { font-size: 10px; color: var(--text-muted); margin-top: 3px; text-align: center; }

/* Filtres */
.forecast-filters {
  display: flex; align-items: flex-end; flex-wrap: wrap; gap: 12px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 12px;
}
.filter-group { display: flex; flex-direction: column; gap: 5px; }
.filter-group label { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.filter-btns { display: flex; gap: 4px; }
.fbtn {
  background: var(--bg-surface); border: 1px solid var(--border);
  color: var(--text-muted); padding: 4px 10px; border-radius: 5px;
  cursor: pointer; font-size: 12px; transition: all .15s;
}
.fbtn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.fbtn:hover:not(.active) { border-color: rgba(255,255,255,.2); color: var(--text); }
.filter-group select {
  background: var(--bg-surface); border: 1px solid var(--border);
  color: var(--text); padding: 5px 9px; border-radius: 6px; font-size: 13px; cursor: pointer;
}

/* Taula forecast */
.forecast-table { width: 100%; border-collapse: collapse; }
.forecast-table thead th {
  background: var(--bg-surface); padding: 10px 12px;
  text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-muted); font-weight: 600;
  position: sticky; top: 0; z-index: 1;
}
.symbol-row td { padding: 10px 12px; border-bottom: 1px solid rgba(48,54,61,.5); vertical-align: middle; }
.symbol-row:hover td { background: rgba(255,255,255,.02); }
.symbol-row.expanded td { background: rgba(37,99,235,.05); }

/* Símbol cel·la */
.sym-col { display: flex; flex-direction: column; gap: 1px; }
.sym-ticker { font-weight: 700; font-size: 14px; letter-spacing: .3px; }
.sym-company { font-size: 11px; color: var(--text); opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
.sym-market { font-size: 10px; color: var(--text-muted); }

/* Signal badge */
.signal-badge {
  display: inline-block; padding: 3px 9px; border-radius: 5px;
  font-size: 11px; font-weight: 700; letter-spacing: .4px; white-space: nowrap;
}

/* Confidence bar */
.conf-bar-wrap { display: flex; align-items: center; gap: 7px; min-width: 110px; }
.conf-bar-track { flex: 1; height: 5px; background: rgba(255,255,255,.08); border-radius: 3px; overflow: hidden; }
.conf-bar-fill { height: 100%; border-radius: 3px; transition: width .3s; }
.conf-pct { font-size: 12px; font-weight: 700; min-width: 30px; }

/* Quality badge */
.quality-badge { font-size: 14px; font-weight: 700; }

/* Stage chip */
.stage-chip { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

/* Risk chip */
.risk-chip { display: flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; }
.risk-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* Expand button */
.btn-expand {
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  padding: 3px 7px; border-radius: 4px; cursor: pointer; font-size: 10px;
  transition: all .15s;
}
.btn-expand:hover { border-color: var(--accent); color: var(--accent); }

/* Detail panel */
.detail-row td { padding: 0 !important; border-bottom: 1px solid var(--border) !important; }
.detail-panel {
  background: var(--bg-surface); border-top: 1px solid var(--border);
  padding: 16px 12px; animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.detail-cols { display: grid; grid-template-columns: repeat(4, 1fr); gap: 24px; }
@media (max-width: 900px) { .detail-cols { grid-template-columns: 1fr 1fr; } }
.detail-col-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted); margin-bottom: 8px; font-weight: 600;
}

/* Comment panel */
.comment-item {
  display: flex; align-items: baseline; gap: 8px;
  padding: 5px 0; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.comment-item:last-child { border-bottom: none; }
.comment-date  { flex-shrink: 0; font-size: 10px; color: var(--text-muted); min-width: 110px; }
.comment-text  { flex: 1; color: var(--text); word-break: break-word; }
.comment-delete {
  flex-shrink: 0; opacity: 0; font-size: 10px;
  color: var(--text-muted); transition: opacity .15s;
  padding: 0 4px; background: none; border: none; cursor: pointer;
}
.comment-item:hover .comment-delete { opacity: 1; }

/* Explainability */
.explain-list { list-style: none; display: flex; flex-direction: column; gap: 5px; }
.explain-item { font-size: 12px; line-height: 1.4; }
.explain-item.positive { color: #4caf72; }
.explain-item.negative { color: #f85149; }

/* Top features */
.top-feat-list { display: flex; flex-direction: column; gap: 6px; }
.top-feat-item { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.top-feat-rank {
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(37,99,235,.2); color: var(--accent);
  font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.top-feat-label { color: var(--text-muted); flex: 1; }
.top-feat-value { font-weight: 600; font-size: 12px; }

/* Timing */
.timing-stage { display: flex; align-items: center; gap: 10px; }
.timing-icon { font-size: 22px; }
.timing-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; }
.timing-value { font-size: 14px; font-weight: 700; margin-top: 2px; }

/* Risk detail */
.risk-detail-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.risk-detail-label { font-size: 12px; color: var(--text-muted); min-width: 80px; }
