/* =============================================
   Modo claro (original)
   ============================================= */
:root {
  --blue-primary:   #1F4E79;
  --blue-secondary: #2E75B6;
  --blue-light:     #5B9BD5;

  --success:   #70AD47;
  --warning:   #ED7D31;
  --highlight: #FFC000;
  --neutral:   #A5A5A5;
  --danger:    #E53E3E;

  --bg-light:   #D9E2F3;
  --card:       #FFFFFF;
  --card-soft:  #F5F7FB;
  --card-dark:  #E2E8F0;
  --text:       #1F2937;
  --text-muted: #A0AEC0;
  --border:     #E2E8F0;
}

/* =============================================
   Tokyo Night (modo oscuro)
   ============================================= */
:root.dark, body.dark {
  --blue-primary:   #7aa2f7;  /* blue */
  --blue-secondary: #7dcfff;  /* cyan */
  --blue-light:     #2ac3de;  /* teal */

  --success:   #9ece6a;  /* green */
  --warning:   #ff9e64;  /* orange */
  --highlight: #e0af68;  /* yellow */
  --neutral:   #565f89;  /* comment */
  --danger:    #f7768e;  /* red */

  --bg-light:   #1a1b26;  /* editor background */
  --card:       #24283b;  /* terminal black */
  --card-soft:  #32344a;  /* selection bg */
  --card-dark:  #1f2335;  /* darker bg */
  --text:       #a9b1d6;  /* foreground */
  --text-muted: #565f89;  /* comment */
  --border:     #32344a;  /* border */
}

body {
  margin: 0;
  padding: 30px;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg-light);
  color: var(--text);
}

body.dark {
  background: var(--bg-light);
  color: var(--text);
}

h1 {
  margin: 0 0 6px 0;
  color: var(--blue-primary);
}
.subtitle {
  color: var(--text-muted);
  margin: 0 0 18px 0;
}

/* Status box */
#statusBox{
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 6px solid var(--blue-primary);
  padding: 10px 16px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 8px;
  margin: 16px 0 26px 0;
}
.tab-btn {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
}
.tab-btn.active {
  background: var(--blue-primary);
  color: #FFFFFF;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Sections */
section {
  background: var(--card);
  padding: 22px 26px;
  border-radius: 10px;
  margin-bottom: 28px;
  border: 1px solid var(--border);
  color: var(--text);
}
section h2 {
  margin: 0 0 16px 0;
  color: var(--blue-primary);
  font-size: 22px;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.section-title-row h2 {
  margin: 0;
}

/* Dark mode styles - sober pastel */
body.dark section {
  background: var(--card);
  border: 1px solid var(--border);
}

body.dark #kpis {
  background: transparent;
  border: none;
}

body.dark #statusBox {
  background: var(--card-dark);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue-primary);
  color: var(--text);
}

body.dark .tab-btn {
  background: var(--card-soft);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

body.dark .tab-btn.active {
  background: var(--blue-primary);
  color: var(--bg-light);
  border-color: var(--blue-primary);
}

body.dark table {
  background: var(--card);
  border: 1px solid var(--border);
}

body.dark th, body.dark td {
  color: var(--text);
  border-color: var(--border);
}

body.dark tr:hover td {
  background: var(--card-soft);
}

/* Total row styling */
.total-row {
  background: var(--bg-light);
  border-top: 2px solid var(--blue-primary);
  font-weight: bold;
}

body.dark .total-row {
  background: var(--card-dark);
  border-top-color: var(--blue-light);
}

/* KPIs */
.kpi-toolbar-section {
  padding: 14px 26px;
}

.kpi-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.kpi-toolbar label {
  font-size: 14px;
  font-weight: 600;
  color: var(--blue-primary);
}

.kpi-toolbar select {
  min-width: 110px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-soft);
  color: var(--text);
  font-size: 14px;
}

.kpi-periodo-info {
  font-size: 13px;
  color: var(--text-muted);
}

/* Separación cuando kpi-toolbar aparece dentro de secciones de detalle */
.kpi-toolbar--inline {
  margin-bottom: 0;
  padding: 10px 14px;
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: inline-flex;
}

@media (max-width: 900px) {
  .section-title-row {
    flex-direction: column;
    align-items: flex-start;
  }
}

body.dark .kpi-toolbar select {
  background: var(--card-soft);
  color: var(--text);
  border-color: var(--border);
}

#kpis {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
  margin-bottom: 26px;
  background: transparent;
  padding: 0;
  box-shadow: none;
  border: none;
}
.kpi {
  background: var(--card);
  color: var(--text);
  padding: 16px 14px;
  border-radius: 8px;
  text-align: center;
}
.kpi span {
  display: block;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.kpi strong {
  font-size: 22px;
  font-weight: 600;
  color: #4a5168;
}

/* Layout */
.grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 26px;
  align-items: start;
  overflow-x: auto;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-soft);
  border: 1px solid var(--border);
  table-layout: fixed;
  word-wrap: break-word;
}
th {
  text-align: left;
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  padding: 10px 8px;
  background: var(--card);
}
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--text);
}
td:last-child, th:last-child { text-align: right; }
tr:hover { background: var(--card-soft); }

/* Alineación de columnas numéricas */
/* Col 1: Activo/Riesgo */
table th:nth-child(1), table td:nth-child(1) {
  text-align: left;
  width: 110px;
  min-width: 110px;
}
/* Col 2: ROI % */
table th:nth-child(2), table td:nth-child(2) {
  text-align: right;
  width: 55px;
  min-width: 55px;
}
/* Col 3: Actual */
table th:nth-child(3), table td:nth-child(3) {
  text-align: right;
  width: 100px;
  min-width: 100px;
}
/* Col 4: % Actual */
table th:nth-child(4), table td:nth-child(4) {
  text-align: right;
  width: 50px;
  min-width: 50px;
}
/* Col 5: P&G */
table th:nth-child(5), table td:nth-child(5) {
  text-align: right;
  width: 85px;
  min-width: 85px;
}
/* Col 6: Dep./Ret. */
table th:nth-child(6), table td:nth-child(6) {
  text-align: right;
  width: 85px;
  min-width: 85px;
}
/* Col 7: Anterior */
table th:nth-child(7), table td:nth-child(7) {
  text-align: right;
  width: 100px;
  min-width: 100px;
}
/* Col 8: % Anterior */
table th:nth-child(8), table td:nth-child(8) {
  text-align: right;
  width: 50px;
  min-width: 50px;
}

td:first-child, th:first-child {
  text-align: left;
}

.theme-toggle {
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.theme-toggle:hover {
  background: var(--blue-primary);
  color: var(--bg-light);
  border-color: var(--blue-primary);
}

body.dark .theme-toggle {
  background: var(--card-soft);
  border-color: var(--border);
  color: var(--text);
}

body.dark .theme-toggle:hover {
  background: var(--blue-secondary);
  color: var(--text);
}

/* Movimientos grid - separar tablas verticalmente */
.movimientos-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 28px;
}

.movimientos-grid > div {
  padding: 0;
  overflow-x: auto;
}

.movimientos-grid > div h3 {
  margin: 0 0 16px 0;
  color: var(--blue-primary);
  font-size: 18px;
  font-weight: 600;
}

/* Tablas de movimientos: layout automático para distribución uniforme */
#tablaMovimientos1,
#tablaMovimientos2 {
  table-layout: auto;
  width: 100%;
}

#tablaMovimientos1 th,
#tablaMovimientos2 th,
#tablaMovimientos1 td,
#tablaMovimientos2 td {
  width: auto;
  min-width: 0;
}

/* Primera columna (Concepto): ancho fijo para dar más espacio a los años */
#tablaMovimientos1 th:first-child,
#tablaMovimientos1 td:first-child,
#tablaMovimientos2 th:first-child,
#tablaMovimientos2 td:first-child {
  text-align: left;
  min-width: 200px;
  max-width: 260px;
  font-size: 13px;
}

/* Columnas de año y Total: alineadas a la derecha, uniformes */
#tablaMovimientos1 th:not(:first-child),
#tablaMovimientos1 td:not(:first-child),
#tablaMovimientos2 th:not(:first-child),
#tablaMovimientos2 td:not(:first-child) {
  text-align: right;
  min-width: 90px;
  font-size: 13px;
  white-space: nowrap;
}

/* Fila de total en tablas de movimientos */
#tablaMovimientos1 .total-row td,
#tablaMovimientos2 .total-row td,
#tablaMovimientos1 .subtotal-row td,
#tablaMovimientos2 .subtotal-row td {
  font-size: 13px;
}

/* Yield y porcentaje de impuestos */
#tablaMovimientos1 .yield-row td,
#tablaMovimientos1 .impuestos-fees-row td {
  font-size: 13px;
  font-style: italic;
}

body.dark .chart-box {
  background: var(--card);
}

body.dark .var-pos { color: var(--success); }
body.dark .var-neg { color: var(--danger); }

body.dark .kpi strong {
  color: #ffffff;
}

.header-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex-wrap: wrap;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85em;
  color: #555;
}

.dark .user-badge { color: #bbb; }
.dark .user-badge button { background: #333; color: #ccc; border-color: #555; }

/* Chart sizing (PPT-like) */
.chart-box {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 280px;
  background: var(--card);
  border-radius: 8px;
}
.chart-box canvas {
  max-width: 260px;
  max-height: 260px;
}

/* Variación positiva en verde, negativa en rojo - Bloomberg style */
.var-pos { color: var(--success); font-weight: bold; }
.var-neg { color: var(--danger); font-weight: bold; }