*{box-sizing:border-box;margin:0;padding:0;}
html{height:100%;overflow:hidden;}
body{font-family:'IBM Plex Sans','Segoe UI',Arial,sans-serif;background:#f8fafc;height:100%;overflow:hidden;font-size:13px;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;}
input,textarea,select,[contenteditable="true"]{-webkit-user-select:text;user-select:text;-webkit-touch-callout:default;}
button,input,select{font-family:inherit;font-size:13px;}
button{cursor:pointer;}
input:focus,select:focus{outline:2px solid #2563eb;outline-offset:1px;}
::-webkit-scrollbar{width:6px;height:6px;}
::-webkit-scrollbar-track{background:#f1f5f9;}
::-webkit-scrollbar-thumb{background:#cbd5e1;border-radius:3px;}
table{border-collapse:collapse;width:100%;}
th{background:#f1f5f9;padding:8px 10px;text-align:left;color:#475569;font-weight:600;font-size:11px;border-bottom:2px solid #e2e8f0;white-space:nowrap;user-select:none;}
th.sortable{cursor:pointer;}
th.sortable:hover{background:#e2e8f0;}
td{padding:7px 10px;border-bottom:1px solid #f1f5f9;}
tr:nth-child(even) td{background:#f8fafc;}
tr:hover td{background:#eff6ff!important;cursor:pointer;}
.btn{background:#1e3a5f;color:#fff;border:1px solid #1e3a5f;border-radius:5px;padding:7px 14px;font-weight:600;letter-spacing:0.2px;}
.btn:hover{background:#15293f;border-color:#15293f;}
.btn:disabled{background:#94a3b8;border-color:#94a3b8;cursor:not-allowed;}
.btn-sm{background:#1e3a5f;color:#fff;border:1px solid #1e3a5f;border-radius:4px;padding:3px 9px;font-weight:600;font-size:11px;letter-spacing:0.2px;}
.btn-gray{background:transparent;color:#1e3a5f;border:1px solid #1e3a5f;border-radius:5px;padding:7px 14px;font-weight:600;letter-spacing:0.2px;}
.btn-gray:hover{background:#1e3a5f;color:#fff;}
.btn-danger{background:#7f1d1d;color:#fff;border:1px solid #7f1d1d;border-radius:5px;padding:7px 14px;font-weight:600;letter-spacing:0.2px;}
.btn-danger:hover{background:#601616;border-color:#601616;}
.btn-danger-sm{background:#7f1d1d;color:#fff;border:1px solid #7f1d1d;border-radius:4px;padding:3px 9px;font-weight:600;font-size:11px;letter-spacing:0.2px;}
.btn-edit-sm{background:#1e3a5f;color:#fff;border:1px solid #1e3a5f;border-radius:4px;padding:3px 9px;font-weight:600;font-size:11px;margin-right:4px;letter-spacing:0.2px;}
.btn-green{background:#1e3a5f;color:#fff;border:1px solid #1e3a5f;border-radius:5px;padding:7px 14px;font-weight:600;letter-spacing:0.2px;}
.inp{width:100%;border:1px solid #cbd5e1;border-radius:6px;padding:6px 10px;}
.inp-sm{border:1px solid #cbd5e1;border-radius:6px;padding:5px 8px;}
.card{background:#fff;border-radius:12px;border:1px solid #e2e8f0;padding:16px;min-width:0;overflow-wrap:break-word;}
.badge{display:inline-block;font-size:11px;font-weight:700;padding:2px 8px;border-radius:6px;}
.overlay{position:fixed;inset:0;background:rgba(0,0,0,0.45);z-index:1000;display:flex;align-items:center;justify-content:center;padding:16px;}
.modal{background:#fff;border-radius:16px;padding:24px;width:480px;max-width:95%;max-height:85vh;overflow-y:auto;box-shadow:0 24px 60px rgba(0,0,0,0.18);}
.modal h3{font-size:15px;color:#1d4ed8;margin-bottom:18px;}
.field{margin-bottom:12px;}
.field label{display:block;font-size:12px;font-weight:600;color:#475569;margin-bottom:4px;}
.grid2{display:grid;grid-template-columns:1fr 1fr;gap:10px;}
.metric-card{background:#fff;border-radius:12px;border:1px solid #e2e8f0;padding:10px 14px;min-width:0;}
.metric-card[onclick]:hover{box-shadow:0 2px 8px rgba(0,0,0,0.08);border-color:#cbd5e1;}
.metric-label{color:#64748b;font-size:10px;font-weight:600;letter-spacing:1px;text-transform:uppercase;margin-bottom:4px;min-height:2.5em;display:flex;align-items:flex-end;}
.metric-value{font-size:18px;font-weight:700;line-height:1.2;}
#app{display:flex;flex-direction:column;height:100vh;height:100dvh;overflow:hidden;background:#e2e8f0;}
#header{background:#fff;border-bottom:1px solid #e2e8f0;padding:10px 16px;flex-shrink:0;width:100%;max-width:1400px;margin:0 auto;box-sizing:border-box;}
#header-top{display:flex;align-items:center;gap:12px;margin-bottom:10px;flex-wrap:wrap;}
#metrics-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(120px,1fr));gap:8px;}
#tabs-bar{display:flex;background:#fff;border-bottom:1px solid #e2e8f0;overflow-x:auto;flex-shrink:0;width:100%;max-width:1400px;margin:0 auto;box-sizing:border-box;}
.tab-btn{padding:10px 16px;background:none;border:none;border-bottom:2px solid transparent;color:#64748b;white-space:nowrap;font-weight:400;}
.tab-btn.active{color:#2563eb;border-bottom-color:#2563eb;font-weight:700;}
.tab-btn:hover{color:#2563eb;}
#content{flex:1;overflow:auto;-webkit-overflow-scrolling:touch;background:#fff;width:100%;max-width:1400px;margin:0 auto;box-sizing:border-box;}
#div-ticker-wrap{width:100%;max-width:1400px;margin:0 auto;box-sizing:border-box;}
#alert-banner{margin-top:8px;background:#fef9c3;border:1px solid #fde68a;border-radius:8px;padding:6px 12px;font-size:12px;color:#b45309;font-weight:600;display:none;}
.toolbar{display:flex;gap:8px;flex-wrap:wrap;padding:10px 14px;border-bottom:1px solid #e2e8f0;background:#f8fafc;align-items:center;}
.progress-bar-wrap{background:#e2e8f0;border-radius:18px;height:36px;position:relative;overflow:hidden;}
.progress-bar-fill{height:36px;border-radius:18px;transition:width 0.5s;}
.progress-bar-label{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;color:#fff;font-weight:700;font-size:14px;}
#div-ticker-wrap{overflow:hidden;background:#fff;border-top:1px solid #e2e8f0;border-bottom:1px solid #e2e8f0;height:26px;display:none;position:relative;flex-shrink:0;}
#div-ticker-inner{display:flex;align-items:center;height:26px;white-space:nowrap;will-change:transform;}
#div-ticker-inner span{color:#475569;font-size:11px;font-weight:600;padding:0 20px;}
#div-ticker-inner span b{color:#1d4ed8;}
#div-ticker-inner span em{color:#059669;font-style:normal;}
#div-ticker-inner span s{color:#94a3b8;text-decoration:none;font-weight:400;}
@keyframes ticker-slide{0%{transform:translateX(0)}100%{transform:translateX(-50%)}}
.ac-wrap{position:relative;}
.ac-list{position:absolute;top:100%;left:0;right:0;background:#fff;border:1px solid #cbd5e1;border-radius:6px;box-shadow:0 8px 24px rgba(0,0,0,0.12);z-index:500;max-height:220px;overflow-y:auto;margin-top:2px;}
.ac-item{padding:8px 12px;cursor:pointer;font-size:12px;border-bottom:1px solid #f1f5f9;}
.ac-item:hover,.ac-item.selected{background:#eff6ff;}
.ac-item .ac-ticker{font-weight:700;color:#1d4ed8;margin-right:6px;}
.ac-item .ac-name{color:#475569;}
.ac-item .ac-exch{color:#94a3b8;font-size:11px;float:right;}
.price-tag{display:inline-flex;align-items:center;gap:5px;font-size:11px;padding:3px 8px;border-radius:20px;font-weight:600;}
.price-live{background:#d1fae5;color:#065f46;}
.price-sim{background:#fef3c7;color:#92400e;}
.spinner{display:inline-block;width:14px;height:14px;border:2px solid #e2e8f0;border-top-color:#2563eb;border-radius:50%;animation:spin 0.7s linear infinite;vertical-align:middle;}
@keyframes spin{to{transform:rotate(360deg)}}
.table-collapsible .table-header{cursor:pointer;user-select:none;display:flex;justify-content:space-between;align-items:center;padding:6px 0;}
.table-collapsible .table-header:hover{background:#f1f5f9;border-radius:6px;}
.table-collapsible .table-content{overflow:auto;}
.table-collapsible.collapsed .table-content{display:none;}

/* Estilos para pestañas de gráficos de dividendos */
.div-chart-tabs {
    display: flex;
    gap: 6px;
    margin: 10px 0 14px 0;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 6px;
    flex-wrap: wrap;
}
.div-chart-tab {
    padding: 6px 16px;
    border: none;
    background: transparent;
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    border-radius: 20px;
    transition: all 0.2s;
}
.div-chart-tab:hover {
    background: #f1f5f9;
    color: #1d4ed8;
}
.div-chart-tab.active {
    background: #1e3a5f;
    color: white;
}
.div-chart-container {
    background: #f8fafc;
    border-radius: 10px;
    padding: 12px;
    border: 1px solid #e2e8f0;
    min-height: 200px;
}
.div-chart-container svg {
    width: 100% !important;
    height: auto !important;
    max-height: 320px;
}
/* Gráficos "Total por empresa" / "Crecimiento anual": necesitan una tarjeta que SÍ pueda
   crecer más de 320px internamente y recortarse con scroll propio (con muchas posiciones
   no caben todas a la vez). Deliberadamente NO reutiliza .div-chart-container, cuya regla
   ".div-chart-container svg { max-height:320px }" forzaría a encoger el SVG entero (todas
   las filas aplastadas) en vez de dejar que el contenedor recorte y haga scroll. */
.div-chart-card {
    background: #f8fafc;
    border-radius: 10px;
    padding: 12px;
    border: 1px solid #e2e8f0;
    min-height: 200px;
}
.div-chart-scroll {
    max-height: 340px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}
.div-chart-scroll svg {
    width: 100% !important;
    height: auto !important;
    display: block;
}

/* Estilos para gráficos de la pestaña "Gráficos" */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 14px;
    padding: 14px;
}
/* Fila de roscos (Por Sector / Por Divisa / Por Empresa): 3 columnas en escritorio, apiladas en móvil */
.charts-donut-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 14px;
}
/* Gráficos principales ampliados: 2 columnas en escritorio ancho, 1 en tablet/móvil */
.charts-grid-main {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}
@media (max-width: 900px) {
  .charts-donut-row { grid-template-columns: repeat(2, 1fr); }
  .charts-grid-main { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .charts-donut-row { grid-template-columns: 1fr; }
}
.chart-card {
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    padding: 14px 16px 16px 16px;
    transition: box-shadow 0.15s;
}
.chart-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.05);
}
.chart-card h4 {
    font-size: 13px;
    font-weight: 700;
    color: #1e3a5f;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.chart-card .chart-sub {
    font-size: 10px;
    color: #94a3b8;
    font-weight: 400;
    margin-left: auto;
}
.chart-card svg {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 6px;
}
.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 6px;
    font-size: 10px;
    color: #475569;
}
.chart-legend span {
    display: flex;
    align-items: center;
    gap: 4px;
}
.chart-legend .dot {
    width: 12px;
    height: 3px;
    border-radius: 2px;
    display: inline-block;
}
.no-data-msg {
    padding: 30px 10px;
    text-align: center;
    color: #94a3b8;
    font-size: 12px;
    background: #f8fafc;
    border-radius: 8px;
}
@media (max-width: 480px) {
  .chart-card { padding: 10px 10px 12px 10px; }
  .chart-card h4 { font-size: 12px; }
  #metrics-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .metric-card { padding: 8px 10px; }
  .metric-label { font-size: 9px; letter-spacing: 0.5px; margin-bottom: 2px; min-height: 2.3em; }
  .metric-value { font-size: 15px; }
}

/* ── Modo oscuro ──
   Cubre los elementos estructurales (fondo, tarjetas, tablas, inputs,
   modales, pestañas), que es donde vive la gran mayoría de la superficie
   visual de la app. Como muchos textos y fondos puntuales están en estilos
   en línea (no en clases), la última regla de este bloque actúa como red de
   seguridad: oscurece automáticamente cualquier fondo blanco/gris claro en
   línea que se haya escapado de las reglas anteriores, sin tener que tocar
   cada uno de ellos a mano uno por uno. */
body.dark-mode { background:#0f172a; color:#e2e8f0; }
body.dark-mode #app { background:#0f172a; }
body.dark-mode #header, body.dark-mode #tabs-bar { background:#1e293b; border-color:#334155; }
body.dark-mode .tab-btn { color:#94a3b8; }
body.dark-mode .tab-btn.active { color:#60a5fa; border-bottom-color:#60a5fa; }
body.dark-mode .card, body.dark-mode .metric-card, body.dark-mode .modal, body.dark-mode .chart-card, body.dark-mode .ac-list { background:#1e293b; border-color:#334155; color:#e2e8f0; }
body.dark-mode .chart-card h4 { color:#93c5fd; }
body.dark-mode .chart-card .chart-sub, body.dark-mode .chart-legend { color:#94a3b8; }
body.dark-mode .toolbar { background:#15202f; border-color:#334155; }
body.dark-mode .no-data-msg { background:#0f172a; color:#94a3b8; }
body.dark-mode .div-chart-scroll, body.dark-mode svg { background:transparent; }
body.dark-mode .div-chart-container, body.dark-mode .div-chart-card { background:#0f172a; border-color:#334155; }
body.dark-mode .div-chart-tabs { border-color:#334155; }
body.dark-mode .div-chart-tab { color:#94a3b8; }
body.dark-mode .price-sim { background:#452c05; color:#fcd34d; }
body.dark-mode .div-chart-tab:hover { background:#334155; color:#93c5fd; }
body.dark-mode .metric-label { color:#94a3b8; }
body.dark-mode table { color:#e2e8f0; }
body.dark-mode th { background:#334155; color:#cbd5e1; border-color:#475569; }
body.dark-mode th.sortable:hover { background:#3f4f66; }
body.dark-mode td { border-color:#334155; }
body.dark-mode td { background:#1e293b; }
body.dark-mode tr:nth-child(even) td { background:#25344a; }
body.dark-mode tr:hover td { background:#25324580!important; }
body.dark-mode .inp, body.dark-mode .inp-sm { background:#0f172a; border-color:#475569; color:#e2e8f0; }
body.dark-mode .btn-gray { color:#93c5fd; border-color:#475569; }
body.dark-mode .btn-gray:hover { background:#334155; color:#e2e8f0; }
body.dark-mode .field label { color:#94a3b8; }
body.dark-mode .overlay { background:rgba(0,0,0,0.65); }
body.dark-mode ::-webkit-scrollbar-track { background:#1e293b; }
body.dark-mode ::-webkit-scrollbar-thumb { background:#475569; }
/* Fondos neutros (tarjetas, filas, separadores) → gris azulado oscuro */
body.dark-mode [style*="background:#fff"],
body.dark-mode [style*="background: #fff"],
body.dark-mode [style*="background:#ffffff"],
body.dark-mode [style*="background:#f8fafc"],
body.dark-mode [style*="background:#f1f5f9"],
body.dark-mode [style*="background:#fafafa"],
body.dark-mode [style*="background:#e2e8f0"],
body.dark-mode [style*="background:#cbd5e1"] { background:#1e293b!important; }

/* Avisos azules (info) → azul oscuro, conservando el tono */
body.dark-mode [style*="background:#eff6ff"],
body.dark-mode [style*="background:#dbeafe"],
body.dark-mode [style*="background:#f0f7ff"] { background:#1e3a5f!important; }
body.dark-mode [style*="color:#1e40af"],
body.dark-mode [style*="color:#1d4ed8"],
body.dark-mode [style*="color:#2563eb"] { color:#93c5fd!important; }

/* Avisos verdes (éxito) → verde oscuro */
body.dark-mode [style*="background:#f0fdf4"],
body.dark-mode [style*="background:#dcfce7"],
body.dark-mode [style*="background:#d1fae5"] { background:#14532d!important; }
body.dark-mode [style*="color:#166534"],
body.dark-mode [style*="color:#15803d"] { color:#86efac!important; }

/* Avisos ámbar (advertencia) → ámbar oscuro */
body.dark-mode [style*="background:#fef9c3"],
body.dark-mode [style*="background:#fffbeb"],
body.dark-mode [style*="background:#fef3c7"],
body.dark-mode [style*="background:#fefce8"] { background:#452c05!important; }
body.dark-mode [style*="color:#92400e"],
body.dark-mode [style*="color:#b45309"] { color:#fcd34d!important; }

/* Avisos rojos (error) → rojo oscuro */
body.dark-mode [style*="background:#fee2e2"],
body.dark-mode [style*="background:#fef2f2"] { background:#450a0a!important; }
body.dark-mode [style*="color:#991b1b"] { color:#fca5a5!important; }

/* Textos oscuros sobre fondo ahora oscuro → claros */
body.dark-mode [style*="color:#1e293b"],
body.dark-mode [style*="color:#0f172a"],
body.dark-mode [style*="color:#334155"] { color:#e2e8f0!important; }
body.dark-mode [style*="color:#64748b"],
body.dark-mode [style*="color:#475569"] { color:#94a3b8!important; }
body.dark-mode [style*="border:1px solid #e2e8f0"],
body.dark-mode [style*="border: 1px solid #e2e8f0"],
body.dark-mode [style*="border:1px solid #cbd5e1"],
body.dark-mode [style*="border:1px dashed #cbd5e1"] { border-color:#334155!important; }

/* ── Informe PDF de Análisis 360 (vía impresión del navegador) ──
   Se oculta todo salvo el propio informe, para que "Guardar como PDF" desde
   el diálogo de impresión del navegador genere un documento limpio, sin
   cabecera de la app, pestañas ni botones. */
@media print {
  body * { visibility: hidden; }
  #a360-report, #a360-report * { visibility: visible; }
  #a360-report { position: absolute; top: 0; left: 0; width: 100%; padding: 0; }
  #a360-report .a360-print-header { display: block !important; }
  .card { break-inside: avoid; border: 1px solid #cbd5e1 !important; }
}
