/* =============================================================================
   base.css — dirección visual compartida por index.html / historial.html / trades.html
   (Fase E2: dashboard SaaS moderno — sidebar + cards + badges pastilla).

   BLOQUE 1  — <style> del mockup aprobado (design_preview_v3_tradezella_style.html),
               copiado tal cual. No reinterpretar: si algo hay que ajustar, va en el
               BLOQUE 2, no acá.
   BLOQUE 2  — adaptaciones a los ids/clases reales del HTML y a lo que generan las
               funciones de render JS de cada página (renderPending, renderRows,
               renderTotals, renderPositions, renderChart, renderLotsSubTable, …).
   ============================================================================= */

/* --------------------------------------------------------------------------
   BLOQUE 1 — mockup aprobado (verbatim)
   -------------------------------------------------------------------------- */
:root {
  --bg: #F5F6FA; --card: #FFFFFF; --border: #E7E9F0;
  --ink: #14162B; --ink-soft: #565A78; --ink-mute: #8B8FA8;
  --primary: #6C5CE7; --primary-soft: #EFECFD;
  --green: #16A34A; --green-soft: #E8F8EE;
  --red: #E11D48; --red-soft: #FDEBEF;
  --amber: #D97706; --amber-soft: #FDF1DF;
  --shadow: 0 1px 2px rgba(20,22,43,0.04), 0 4px 16px rgba(20,22,43,0.06);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: 'Plus Jakarta Sans', sans-serif; font-size: 14px; line-height: 1.5;
  display: flex; min-height: 100vh;
}
.sidebar {
  width: 220px; background: var(--card); border-right: 1px solid var(--border);
  padding: 24px 16px; flex-shrink: 0; position: sticky; top: 0; height: 100vh;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 24px; }
.side-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px; }
.side-brand-text { font-weight: 700; font-size: 14.5px; }
.side-brand-sub { font-size: 10px; color: var(--ink-mute); }
.side-nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px;
  color: var(--ink-soft); text-decoration: none; font-size: 13.5px; font-weight: 500; margin-bottom: 2px;
}
.side-nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.side-nav .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.5; }

.main { flex: 1; padding: 28px 32px 60px; max-width: 1180px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 22px; }
.page-title { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.page-sub { font-size: 13px; color: var(--ink-mute); margin-top: 2px; }

.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.kpi-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow); }
.kpi-label { font-size: 11.5px; color: var(--ink-mute); font-weight: 600; margin-bottom: 8px; display:flex; align-items:center; gap:6px; }
.kpi-value { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.kpi-value.up { color: var(--green); } .kpi-value.down { color: var(--red); }
.kpi-icon { width: 22px; height: 22px; border-radius: 6px; display:flex; align-items:center; justify-content:center; font-size:11px; font-weight:800; }

.notice { display: flex; gap: 10px; align-items: center; background: var(--primary-soft); border-radius: 12px; padding: 12px 16px; margin-bottom: 22px; font-size: 12.5px; color: #4C3FB8; }
.notice b { font-weight: 700; }

.sec-label { font-size: 15px; font-weight: 700; margin: 0 0 12px; display:flex; align-items:center; justify-content:space-between; }
.sec-label span.count { font-size: 12px; font-weight: 600; color: var(--ink-mute); background: var(--bg); padding: 2px 9px; border-radius: 20px; }
.ficha-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 30px; }
.ficha { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
.ficha-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.ficha-ticker { font-weight: 800; font-size: 16px; }
.badge { font-size: 10.5px; font-weight: 700; padding: 4px 10px; border-radius: 20px; }
.badge.aprobado { background: var(--green-soft); color: var(--green); }
.badge.watchlist { background: var(--amber-soft); color: var(--amber); }
.badge.rechazado { background: var(--red-soft); color: var(--red); }
.badge.pending { background: var(--bg); color: var(--ink-mute); }
.badge.target_hit { background: var(--green-soft); color: var(--green); }
.badge.stop_hit { background: var(--red-soft); color: var(--red); }
.ficha-data { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; margin-bottom: 14px; font-family: 'IBM Plex Mono', monospace; }
.ficha-field .fl { font-size: 9.5px; color: var(--ink-mute); text-transform: uppercase; letter-spacing: 0.05em; }
.ficha-field .fv { font-size: 13px; font-weight: 600; }
.ficha-actions { display: flex; gap: 8px; }
.btn { border: none; border-radius: 9px; padding: 8px 13px; font-family: 'Plus Jakarta Sans', sans-serif; font-size: 12px; font-weight: 700; cursor: pointer; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.ghost { background: var(--bg); color: var(--ink-soft); }

.card-panel { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 6px 18px; box-shadow: var(--shadow); margin-bottom: 30px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11px; color: var(--ink-mute); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 12px 10px; border-bottom: 1px solid var(--border); }
td { padding: 13px 10px; border-bottom: 1px solid var(--border); }
td.mono { font-family: 'IBM Plex Mono', monospace; }
tr:last-child td { border-bottom: none; }

.chart-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); }
.bar-row { display: grid; grid-template-columns: 70px 1fr 80px; gap: 10px; align-items: center; margin-bottom: 10px; font-size: 12px; }
.bar-label { font-weight: 700; font-size: 12px; }
.bar-track { background: var(--bg); border-radius: 8px; height: 10px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 8px; }
.bar-fill.inv { background: #C7C4F5; }
.bar-fill.up { background: var(--green); }
.bar-fill.down { background: var(--red); }
.bar-val { font-family: 'IBM Plex Mono', monospace; text-align: right; font-size: 12px; font-weight: 600; }

/* --------------------------------------------------------------------------
   BLOQUE 2 — adaptaciones al HTML/JS real de las 3 páginas
   -------------------------------------------------------------------------- */

/* El JS togglea visibilidad con el atributo [hidden] (els.x.hidden = true/false).
   Cualquier regla que setee `display` acá abajo lo pisaría — este guard lo evita. */
[hidden] { display: none !important; }

a { color: var(--primary); }

/* La última sección de cada página no necesita el margen inferior del mockup. */
.main > :last-child { margin-bottom: 0; }

/* --- badges: journal_status que el mockup no listaba (enum de _shared/constants.js) --- */
.badge.ambiguous { background: var(--amber-soft); color: var(--amber); }
.badge.expired   { background: var(--bg); color: var(--ink-mute); }

/* --- botones --- */
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost { border: 1px solid var(--border); }

/* --- helpers de signo (celdas de tabla generadas por renderPositions) --- */
.up { color: var(--green); }
.down { color: var(--red); }
td.up, td.down { font-weight: 700; }

/* --- formularios: #filters (historial) y #form-register / #form-sell (trades) --- */
.form-grid { display: flex; flex-wrap: wrap; gap: 14px 16px; align-items: flex-end; padding: 14px 0; margin: 0; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 10.5px; font-weight: 700; color: var(--ink-mute); text-transform: uppercase; letter-spacing: 0.04em; }
.form-grid input,
.form-grid select {
  font-family: 'Plus Jakarta Sans', sans-serif; font-size: 13px; font-weight: 500;
  color: var(--ink); background: var(--card);
  border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px;
  text-transform: none; letter-spacing: normal; min-width: 150px;
}
.form-grid input:focus,
.form-grid select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-grid .btn { margin-bottom: 1px; }

.form-hint { font-size: 12px; color: var(--ink-mute); min-height: 1.1rem; margin: 4px 0 0; }
.form-warning { font-size: 12px; color: var(--amber); margin: 6px 0 0; }
.form-error { font-size: 12.5px; color: var(--red); margin: 6px 0 0; }

/* --- pills de mensaje/estado: #banner-message (index), #message (historial+trades),
       #quote-banner (trades) --- */
#message,
#quote-banner { border-radius: 12px; padding: 11px 16px; font-size: 12.5px; margin: 0 0 18px; }
#message { background: var(--primary-soft); color: #4C3FB8; }
#message.error { background: var(--red-soft); color: var(--red); }
#quote-banner { background: var(--amber-soft); color: var(--amber); }
#banner-message { font-size: 12px; color: var(--red); margin: 8px 0 0; }

/* --- historial --- */
#pagination { display: flex; align-items: center; gap: 14px; margin: 0 0 30px; }
#page-info { font-size: 12px; color: var(--ink-mute); }
#results tbody tr { cursor: pointer; }
#results tbody tr:hover { background: var(--primary-soft); }
#detail { max-width: 760px; }
#detail-close { margin-bottom: 14px; }
#detail-content h2 { font-size: 18px; font-weight: 800; margin: 4px 0; }
#detail-content h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-mute); font-weight: 700; margin: 18px 0 6px; }
#detail-content p { margin: 6px 0; color: var(--ink-soft); }
#detail-content ul { margin: 6px 0; padding-left: 18px; }
#detail-content li { margin: 3px 0; color: var(--ink-soft); }
#detail-content pre {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; overflow-x: auto; white-space: pre-wrap;
  font-family: 'IBM Plex Mono', monospace; font-size: 12px;
}

/* --- trades --- */
.card-panel.pad { padding: 4px 18px 18px; }
#totals { margin-bottom: 24px; }
#positions-empty { padding: 16px 4px; color: var(--ink-mute); }
#positions-table { margin: 0; }

/* fila "Ver lotes" expandida: fondo --bg para diferenciarla del resto de la tabla */
tr.lots-row > td { background: var(--bg); padding: 6px 12px 12px; }
.lots-subtable { width: auto; font-size: 12px; margin: 4px 0 0; box-shadow: none; }
.lots-subtable th { padding: 8px 10px; }
.lots-subtable td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.lots-subtable tr:last-child td { border-bottom: none; }

/* gráfico: grupos por ticker dentro de .chart-card (renderChart) */
.chart-group { margin-bottom: 16px; }
.chart-group:last-child { margin-bottom: 0; }
.chart-title { font-weight: 800; font-size: 13px; margin-bottom: 8px; }

/* --- watchlist --- */
/* Variantes del .notice del mockup para el aviso de límite de tickers: warn
   reusa el amber de los badges, danger el rojo (más notorio pasando 50). */
.notice.warn   { background: var(--amber-soft); color: var(--amber); }
.notice.danger { background: var(--red-soft); color: var(--red); font-weight: 600; }

.chip-list { display: flex; flex-wrap: wrap; gap: 10px; padding: 14px 0; }
.ticker-chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 20px;
  padding: 5px 6px 5px 14px;
  font-family: 'IBM Plex Mono', monospace; font-weight: 600; font-size: 13px;
}
.ticker-chip button {
  border: none; background: var(--card); color: var(--ink-soft);
  border-radius: 14px; padding: 3px 10px;
  font-family: 'Plus Jakarta Sans', sans-serif; font-size: 11px; font-weight: 700; cursor: pointer;
}
.ticker-chip button:hover { background: var(--red-soft); color: var(--red); }
.ticker-chip button:disabled { opacity: 0.5; cursor: not-allowed; }

#list-empty { padding: 16px 4px; color: var(--ink-mute); }
.add-status { font-size: 12px; font-weight: 600; min-height: 1.1rem; margin: 6px 0 0; }
.add-status.ok      { color: var(--green); }
.add-status.err     { color: var(--red); }
.add-status.pending { color: var(--ink-mute); }

/* --- noticias --- */
/* Lista de titulares de GET /api/news (noticias.html). Cada .news-item es el
   headline como link a la nota + una línea de meta (fuente · hora relativa). */
.news-list { display: flex; flex-direction: column; }
.news-item { padding: 13px 0; border-bottom: 1px solid var(--border); }
.news-item:first-child { padding-top: 4px; }
.news-item:last-child  { padding-bottom: 4px; border-bottom: none; }
.news-item a { font-size: 14px; font-weight: 600; line-height: 1.45; text-decoration: none; }
.news-item a:hover { text-decoration: underline; }
.news-meta { font-size: 11.5px; font-weight: 600; color: var(--ink-mute); margin-top: 5px; }
#news-placeholder,
#news-loading,
#news-empty { padding: 16px 4px; color: var(--ink-mute); }

/* --- grafico --- */
/* Contenedor del candlestick (lightweight-charts inyecta su canvas adentro). */
#chart { width: 100%; height: 420px; }
#chart-placeholder,
#chart-loading,
#chart-empty { padding: 16px 4px; color: var(--ink-mute); }
/* Bloque obligatorio de fuente/timestamp bajo el gráfico. */
.chart-source {
  font-family: 'IBM Plex Mono', monospace; font-size: 11.5px; color: var(--ink-mute);
  padding: 12px 4px 4px; margin-top: 10px; border-top: 1px solid var(--border);
}
.chart-source-name { color: var(--ink-soft); font-weight: 600; }
.chart-source-ts { color: var(--ink-mute); }

/* --- responsive: sidebar arriba en pantallas angostas --- */
@media (max-width: 760px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); padding: 16px; }
  .main { padding: 20px 18px 40px; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .ficha-grid { grid-template-columns: 1fr; }
  .form-grid input, .form-grid select { min-width: 0; flex: 1; }
}
