/* style.css */

:root {
    --bg-app: #0d1117;
    --bg-sidebar: #161b22;
    --bg-card: #21262d;
    --border: #30363d;
    --text-main: #c9d1d9;
    --text-muted: #8b949e;
    --accent: #58a6ff;
    --accent-dim: rgba(88, 166, 255, 0.15);
    --success: #2ea043;
    --danger: #da3633;
    --warning: #d29922;
    --font-ui: 'Inter', sans-serif;
    --font-data: 'JetBrains Mono', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; scrollbar-width: thin; scrollbar-color: var(--border) var(--bg-app); }

body {
    font-family: var(--font-ui);
    background: var(--bg-app);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
}

/* LAYOUT */
.app-wrapper { display: flex; min-height: 100vh; position: relative; }

/* SIDEBAR */
.sidebar {
    width: 300px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: margin-left 0.3s ease-in-out, transform 0.3s ease-in-out; 
    z-index: 110;
    position: relative;
}

.sidebar.collapsed { margin-left: -300px; }

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 17, 23, 0.65);
    backdrop-filter: blur(2px);
    z-index: 100;
    display: none;
}
body.sidebar-open .sidebar-overlay { display: block; }

.brand {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}
.brand h1 { font-size: 1.2rem; color: #fff; }
.badge-version { background: var(--accent); color: #000; font-size: 0.6rem; padding: 2px 6px; border-radius: 4px; font-weight: 700; vertical-align: super; }

.scrollable-content { flex: 1; overflow-y: auto; padding: 1.5rem; }

.control-section { margin-bottom: 1.5rem; }
.control-section label { display: block; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.5rem; letter-spacing: 0.5px; }

.input-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.input-wrapper { position: relative; display: flex; align-items: center; background: var(--bg-app); border: 1px solid var(--border); border-radius: 4px; padding: 0 8px; }
.input-wrapper span { color: var(--text-muted); font-size: 0.8rem; margin-right: 5px; }
input, select { background: transparent; border: none; color: #fff; width: 100%; padding: 8px 0; font-family: var(--font-data); font-size: 0.9rem; outline: none; }
select:disabled { opacity: 0.5; cursor: not-allowed; }

.ticker-select-wrapper {
    position: relative;
    width: 100%;
}
.ticker-select-wrapper .choices {
    width: 100%;
}
.ticker-select-wrapper .choices__inner {
    padding-right: 48px !important;
}
.ticker-search-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 34px;
    height: 34px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}
.ticker-search-btn:hover:not(:disabled) {
    background: var(--accent-dim);
    color: var(--accent);
}
.ticker-search-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.inline-loader {
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.inline-loader i { font-size: 0.9rem; }
.inline-loader.error { color: var(--danger); }

/* --- CHOICES.JS MEJORADO --- */
.choices { margin-bottom: 0; }
.choices__inner { 
    background-color: var(--bg-app) !important; 
    border: 1px solid var(--border) !important; 
    border-radius: 4px !important;
    color: #fff !important; 
    min-height: 40px !important; 
    padding: 5px 8px !important; 
}
.choices__list--dropdown { 
    background-color: var(--bg-sidebar) !important; 
    border: 1px solid var(--border) !important; 
    margin-top: 5px !important;
    border-radius: 4px !important;
}
.choices__item--choice { 
    color: var(--text-main) !important; 
    font-size: 0.85rem !important;
    padding: 8px 10px !important;
}
.choices__item--choice.is-highlighted { 
    background-color: var(--bg-card) !important; 
    color: var(--accent) !important;
}
.choices__item--selectable.is-highlighted { background-color: rgba(88, 166, 255, 0.1) !important; }
.choices__list--multiple .choices__item {
    background-color: var(--accent-dim) !important;
    border: 1px solid var(--accent) !important;
    color: var(--accent) !important;
    border-radius: 3px !important;
}
.choices__button { border-left: 1px solid var(--accent) !important; margin: 0 -4px 0 8px !important; filter: brightness(1.5); }
.choices__input { background-color: transparent !important; color: #fff !important; margin-bottom: 0 !important; }

/* Advanced Panel */
.advanced-toggle { cursor: pointer; font-size: 0.85rem; color: var(--accent); margin-bottom: 10px; display: flex; justify-content: space-between; }
.advanced-panel { display: none; background: rgba(0,0,0,0.2); padding: 10px; border-radius: 4px; }
.advanced-panel.open { display: block; }
.range-control { margin-bottom: 10px; }
.range-control label { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 4px; }
input[type=range] { width: 100%; accent-color: var(--accent); }

/* BOTONES */
.btn-primary {
    width: 100%; background: var(--accent); color: #fff; border: none; padding: 12px; border-radius: 4px;
    font-weight: 600; cursor: pointer; margin-top: 1rem; display: flex; justify-content: center; gap: 10px; transition: 0.2s;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:disabled { background: var(--border); cursor: not-allowed; }

.btn-secondary {
    width: 100%; background: var(--bg-card); color: var(--text-main); border: 1px solid var(--border); 
    padding: 10px; border-radius: 4px; font-weight: 500; cursor: pointer; 
    display: flex; justify-content: center; align-items: center; gap: 8px; transition: 0.2s; font-size: 0.85rem;
}
.btn-secondary:hover { background: var(--border); color: #fff; }
.btn-secondary.success { color: var(--success); border-color: var(--success); background: rgba(46, 160, 67, 0.05); }
.btn-secondary.success:hover { background: var(--success); color: #fff; }
.mb-2 { margin-bottom: 0.5rem; }

.mobile-export-bar {
    display: none;
    gap: 0.75rem;
    margin: 1.5rem 0;
    padding: 1rem;
    background: rgba(22, 27, 34, 0.8);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.mobile-export-bar .btn-secondary {
    flex: 1;
    width: 100%;
}

/* --- SIDEBAR FOOTER & SOCIALS & FIRMA --- */
.sidebar-footer { padding: 1rem; border-top: 1px solid var(--border); text-align: center; }

.social-links { display: flex; justify-content: center; gap: 15px; margin-bottom: 1rem; }
.social-links a { color: var(--text-muted); font-size: 1.2rem; transition: color 0.2s; }
.social-links a:hover { color: var(--accent); }

/* Firma Invisible Estilos */
.firma-invisible-container { margin-bottom: 0.5rem; }
.firma-invisible {
    color: white;
    text-align: center;
    font-size: 0.7rem;
    cursor: text;
    user-select: none;
    padding: 5px 0;
}
.firma-invisible::selection { color: black; background-color: #f1c40f; }
.firma-invisible-container:hover .firma-invisible { user-select: text; }

.server-status { font-size: 0.65rem; color: var(--text-muted); opacity: 0.7; }


/* MAIN AREA */
.main-area { flex: 1; background: var(--bg-app); overflow-y: auto; position: relative; width: 100%; min-height: 100vh; }
.dashboard-content { padding: 2rem; max-width: 1600px; margin: 0 auto; }

/* TOGGLE BUTTON STYLES */
.sidebar-toggle-btn {
    position: absolute; top: 1rem; left: 1rem; z-index: 140;
    background: var(--bg-card); border: 1px solid var(--border);
    color: var(--text-main); width: 40px; height: 40px; border-radius: 6px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; transition: all 0.2s; box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.sidebar-toggle-btn:hover { background: var(--border); color: #fff; }

/* --- LOADER PRO --- */
.hidden { display: none !important; }
.loader-container { 
    position: absolute; inset: 0; background: rgba(13, 17, 23, 0.98); z-index: 100; 
    display: flex; flex-direction: column; justify-content: center; align-items: center; 
    text-align: center; 
}
.spinner { width: 50px; height: 50px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 1.5rem; }
#loader h2 { font-size: 1.2rem; color: var(--text-main); margin-bottom: 1rem; }
#loader p { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.5rem; }

.progress-bar-container {
    width: 300px; height: 6px; background: var(--border);
    border-radius: 3px; overflow: hidden; margin-bottom: 0.5rem;
}
.progress-bar-fill {
    height: 100%; width: 0%; background: var(--accent);
    transition: width 0.3s ease;
    box-shadow: 0 0 10px var(--accent);
}

.empty-state { height: 100%; display: flex; align-items: center; justify-content: center; color: var(--text-muted); opacity: 0.5; }
.empty-content { text-align: center; }
.empty-content i { font-size: 4rem; margin-bottom: 1rem; }

@keyframes spin { to { transform: rotate(360deg); } }

/* DASHBOARD CARDS & GRID */
.section-header { font-size: 1.1rem; font-weight: 600; color: #fff; margin: 2rem 0 1rem 0; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; display: flex; justify-content: space-between; align-items: center; }
.section-header i { margin-right: 8px; color: var(--accent); }
.timestamp-badge { font-size: 0.75rem; color: var(--text-muted); font-family: var(--font-data); background: rgba(0,0,0,0.2); padding: 4px 8px; border-radius: 4px; border: 1px solid var(--border); }

/* GRID SYSTEMS */
.grid-col-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; min-width: 0; }
.grid-col-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1.5rem; min-width: 0; }

.mt-2 { margin-top: 1.5rem; }
.mt-4 { margin-top: 3rem; }

.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; display: flex; flex-direction: column; position: relative; min-width: 0; }
.card-title { background: rgba(255,255,255,0.02); padding: 10px 15px; font-size: 0.85rem; font-weight: 600; border-bottom: 1px solid var(--border); color: var(--text-main); }

.chart-box { width: 100%; height: 300px; position: relative; }
.chart-box.large { height: 400px; }
.chart-box.x-large { height: 520px; }

/* Interpretation Box */
.interpretation-box {
    padding: 12px 15px; background: rgba(13, 17, 23, 0.5); border-top: 1px solid var(--border);
    font-size: 0.8rem; color: var(--text-muted); line-height: 1.4;
}
.interpretation-box strong { color: var(--text-main); }

/* TABLES */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; font-family: var(--font-data); }
th { text-align: left; padding: 10px 15px; color: var(--text-muted); font-weight: 500; border-bottom: 1px solid var(--border); background: rgba(0,0,0,0.2); }
td { padding: 8px 15px; border-bottom: 1px solid var(--border); color: #fff; }
tr:last-child td { border-bottom: none; }
.val-pos { color: var(--success); }
.val-neg { color: var(--danger); }
.row-header { font-weight: 600; color: var(--accent); font-family: var(--font-ui); }

/* ACCORDION */
.accordion-item { border: 1px solid var(--border); border-radius: 6px; margin-bottom: 1rem; background: var(--bg-card); overflow: hidden; }
.accordion-header { padding: 1rem; background: rgba(255,255,255,0.03); cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.accordion-header h3 { font-size: 1rem; font-weight: 600; margin: 0; }
.accordion-header span { color: var(--accent); font-family: var(--font-data); font-size: 0.9rem; }
.accordion-body { display: none; padding: 1.5rem; border-top: 1px solid var(--border); }
.accordion-body.active { display: block; animation: slideDown 0.3s ease; }

@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* RESPONSIVE */
@media (max-width: 1200px) {
    .grid-col-3, .grid-col-2 { grid-template-columns: 1fr; }
}

@media (max-width: 1024px) {
    .app-wrapper { flex-direction: column; }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 280px;
        max-width: 85vw;
        margin-left: 0;
        transform: translateX(-100%);
        box-shadow: 0 25px 60px rgba(0, 0, 0, 0.65);
    }
    .sidebar:not(.collapsed) { transform: translateX(0); }
    .sidebar.collapsed { transform: translateX(-100%); }
    body.sidebar-open { overflow: hidden; }
    .scrollable-content { padding: 1.25rem; }
    .main-area { padding-top: 4.5rem; }
    .sidebar-toggle-btn {
        position: fixed;
        top: 1rem;
        left: 1rem;
    }
}

@media (max-width: 768px) {
    .dashboard-content { padding: 1.5rem 1rem 3rem; }
    .grid-col-3, .grid-col-2 { gap: 1rem; }
    .section-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; font-size: 1rem; }
    .card-title { font-size: 0.8rem; }
    .chart-box { height: 260px; }
    .chart-box.large { height: 320px; }
    .chart-box.x-large { height: 380px; }
    .input-grid { grid-template-columns: 1fr; }
    .btn-primary, .btn-secondary { font-size: 0.9rem; }
    .mobile-export-bar {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }
    .mobile-export-bar .btn-secondary {
        font-size: 0.95rem;
        min-height: 48px;
    }
    .ticker-search-btn {
        width: 38px;
        height: 38px;
        top: 10px;
        right: 10px;
    }
}

@media (max-width: 520px) {
    .scrollable-content { padding: 1rem; }
    .sidebar { width: 90vw; }
    .sidebar-toggle-btn { width: 44px; height: 44px; font-size: 1.4rem; }
    .dashboard-content { padding: 1.25rem 0.75rem 3rem; }
    .section-header { font-size: 0.95rem; }
}