﻿/*
 * Charts.css
 * ----------
 * Estilos exclusivos de la página Razor Pages /Charts.
 * La página utiliza Layout = null para ocupar todo el viewport.
 */

:root {
    --tv-blue: #2962ff;
    --tv-text: #131722;
    --tv-muted: #787b86;
    --tv-border: #e0e3eb;
    --tv-grid: #f0f3fa;
    --tv-up: #089981;
    --tv-down: #f23645;
    --tv-background: #ffffff;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--tv-background);
    color: var(--tv-text);
    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        Arial,
        sans-serif;
}

/* Estructura principal: toolbar, gráfico y barra inferior. */
#app {
    display: grid;
    grid-template-rows: 48px minmax(0, 1fr);
    width: 100%;
    height: 100%;
}

/* Barra superior del gráfico. */
#toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
    overflow-x: auto;
    border-bottom: 1px solid var(--tv-border);
    background: var(--tv-background);
    user-select: none;
}

.symbol-block {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 8px;
    min-width: 145px;
    padding-right: 10px;
    border-right: 1px solid var(--tv-border);
}

.symbol-logo {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #76b900;
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
}

.symbol-name {
    font-size: 14px;
    font-weight: 600;
}

.symbol-exchange {
    margin-top: 3px;
    color: var(--tv-muted);
    font-size: 11px;
}

.toolbar-group {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 3px;
    padding-right: 7px;
    border-right: 1px solid var(--tv-border);
}

.toolbar-button,
.interval-button {
    min-width: 32px;
    height: 30px;
    padding: 0 9px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--tv-text);
    font-size: 13px;
    cursor: pointer;
}

.toolbar-button:hover,
.interval-button:hover {
    background: var(--tv-grid);
}

.interval-button.active {
    background: #e8edff;
    color: var(--tv-blue);
    font-weight: 600;
}

.toolbar-spacer {
    flex: 1 1 auto;
    min-width: 10px;
}

.primary-button {
    flex: 0 0 auto;
    height: 30px;
    padding: 0 12px;
    border: 0;
    border-radius: 6px;
    background: var(--tv-blue);
    color: #ffffff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

/* Área donde Lightweight Charts crea el canvas. */
#chart-wrapper {
    position: relative;
    min-height: 0;
    background: var(--tv-background);
}

#chart {
    position: absolute;
    inset: 0;
}

/* Mensaje central para estados de carga, ausencia de datos o errores. */
.chart-message {
    position: absolute;
    z-index: 20;
    top: 50%;
    left: 50%;
    max-width: min(90%, 520px);
    padding: 12px 18px;
    transform: translate(-50%, -50%);
    border: 1px solid var(--tv-border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    color: var(--tv-muted);
    font-size: 13px;
    text-align: center;
    box-shadow: 0 4px 18px rgba(19, 23, 34, 0.08);
}

.chart-message.error {
    border-color: rgba(242, 54, 69, 0.35);
    color: var(--tv-down);
}

/* Leyenda OHLC e indicadores. */
#legend {
    position: absolute;
    z-index: 10;
    top: 10px;
    left: 12px;
    max-width: calc(100% - 80px);
    pointer-events: none;
    font-size: 12px;
    line-height: 18px;
    white-space: nowrap;
}

#legend-title {
    font-weight: 600;
}

#ohlc {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-left: 8px;
    color: var(--tv-muted);
}

#indicator-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 2px;
    color: var(--tv-muted);
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.legend-dot {
    width: 8px;
    height: 2px;
    border-radius: 2px;
}



/* Marca de agua central del ticker. */
#watermark {
    position: absolute;
    z-index: 2;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(19, 23, 34, 0.06);
    font-size: clamp(48px, 9vw, 110px);
    font-weight: 700;
    pointer-events: none;
    user-select: none;
}


/* Ajustes para pantallas pequeñas. */
@media (max-width: 700px) {
    #app {
        grid-template-rows: 48px minmax(0, 1fr);
    }

    .symbol-block {
        min-width: 115px;
    }

    #legend {
        max-width: calc(100% - 24px);
        white-space: normal;
    }

    #ohlc {
        margin-left: 0;
    }

    #statusbar {
        font-size: 10px;
    }
}


/* Precio y variación del ticker mostrados en la barra superior. */
.ticker-quote {
    display: flex;
    flex: 0 0 auto;
    align-items: baseline;
    gap: 8px;
    padding: 0 8px;
    white-space: nowrap;
}

.ticker-last-price {
    color: var(--tv-text);
    font-size: 15px;
    font-weight: 700;
}

.ticker-change {
    font-size: 12px;
    font-weight: 600;
}

.ticker-change.positive {
    color: var(--tv-up);
}

.ticker-change.negative {
    color: var(--tv-down);
}



/*
 * Botones de acciones del gráfico.
 * Los SVG usan currentColor para respetar el color del botón.
 */
.chart-actions {
    gap: 4px;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

.button-icon {
    width: 17px;
    height: 17px;
    flex: 0 0 auto;
}

@media (max-width: 560px) {
    .icon-button span {
        display: none;
    }

    .icon-button {
        width: 32px;
        padding: 0;
    }
}


/*
 * Imagen temporal usada únicamente durante la captura completa.
 * Se coloca debajo de las leyendas, pero encima del fondo del gráfico.
 */
.capture-chart-overlay {
    position: absolute;
    z-index: 1;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    pointer-events: none;
    user-select: none;
}


/*
 * Leyenda dinámica de medias móviles.
 * El color de cada línea se asigna desde Charts.js.
 */
.indicator-value {
    font-weight: 600;
}


/*
 * Checkbox para controlar la visibilidad de cada media móvil.
 */
#indicator-legend {
    pointer-events: auto;
}

.indicator-toggle {
    cursor: pointer;
    user-select: none;
    pointer-events: auto;
}

.indicator-toggle input[type="checkbox"] {
    width: 13px;
    height: 13px;
    margin: 0 2px 0 0;
    accent-color: var(--tv-blue);
    cursor: pointer;
}

.indicator-toggle.disabled {
    opacity: 0.45;
}

.indicator-toggle.disabled .indicator-value {
    text-decoration: line-through;
}


/*
 * Indicador de color más visible en la leyenda.
 * El grosor visual de la leyenda es independiente del grosor real de la línea.
 */
#indicator-legend .legend-dot {
    width: 14px;
    height: 4px !important;
    border-radius: 3px;
    flex: 0 0 auto;
}


/*
 * Capa de separación entre sesiones en temporalidad 2m.
 */
.day-separator-canvas {
    position: absolute;
    inset: 0;
    z-index: 6;
    pointer-events: none;
}

/* Streaming en vivo */
.live-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #2962ff;
    border-color: rgba(41, 98, 255, .48);
}

.live-button .live-stream-icon {
    color: #2962ff;
}

.live-button:hover {
    background: rgba(41, 98, 255, .09);
    color: #1748c9;
}

.live-button.active {
    background: #089981;
    border-color: #089981;
    color: #ffffff;
    font-weight: 600;
}

.live-button.active .live-stream-icon {
    color: #ffffff;
}

.live-button[data-state="connecting"] {
    border-color: #f59f00;
    color: #b36b00;
}

.live-button[data-state="error"] {
    border-color: var(--tv-down);
    color: var(--tv-down);
}

.extended-hours-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #7b1fa2;
    border-color: rgba(123, 31, 162, .45);
}

.extended-hours-button.active {
    background: rgba(123, 31, 162, .14);
    border-color: #7b1fa2;
    color: #7b1fa2;
    font-weight: 600;
}

.live-dot,
.live-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #adb5bd;
}

.live-button[data-state="connecting"] .live-dot,
.live-status-dot[data-state="connecting"] {
    background: #f59f00;
    animation: live-pulse 1s infinite;
}

.live-button[data-state="connected"] .live-dot,
.live-status-dot[data-state="connected"] {
    background: var(--tv-up);
}

.live-button[data-state="warning"] .live-dot,
.live-status-dot[data-state="warning"] {
    background: #f59f00;
}

.live-button[data-state="error"] .live-dot,
.live-status-dot[data-state="error"] {
    background: var(--tv-down);
}

.stream-status-link {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 5px;
    color: var(--tv-muted);
    font-size: 11px;
    text-decoration: none;
    white-space: nowrap;
}

.live-mini-log {
    position: absolute;
    z-index: 30;
    right: 12px;
    bottom: 12px;
    width: min(560px, calc(100% - 24px));
    max-height: 240px;
    overflow: hidden;
    border: 1px solid #334155;
    border-radius: 7px;
    background: rgba(15, 23, 42, .96);
    color: #dbe7f3;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .2);
    font: 11px/1.45 Consolas, "Courier New", monospace;
}

.live-mini-log-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    border-bottom: 1px solid #334155;
}

.live-mini-log-header button {
    border: 0;
    background: transparent;
    color: inherit;
    font-size: 18px;
    cursor: pointer;
}

#live-mini-log-content {
    max-height: 195px;
    overflow: auto;
}

.live-mini-log-line {
    display: grid;
    grid-template-columns: 70px 42px minmax(0, 1fr);
    gap: 6px;
    padding: 3px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, .04);
}

.live-mini-log-line strong[data-level="ERROR"] {
    color: #ff8787;
}

.live-mini-log-line strong[data-level="INFO"] {
    color: #74c0fc;
}

@keyframes live-pulse {
    50% { opacity: .35; }
}


/*
 * En pantallas estrechas el texto de los botones puede ocultarse,
 * pero el icono Live conserva un color visible en todos sus estados.
 */
@media (max-width: 760px) {
    .live-button .button-icon,
    .extended-hours-button .button-icon {
        width: 20px;
        height: 20px;
    }

    .live-button:not(.active) .live-stream-icon {
        color: #2962ff;
    }

    .live-button.active .live-stream-icon {
        color: #ffffff;
    }
}


.stream-status-container {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.stream-status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    color: var(--tv-muted);
    font-size: 12px;
    white-space: nowrap;
}

.live-log-button {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: #2962ff;
    border-color: rgba(41, 98, 255, .42);
}

.live-log-button:hover,
.live-log-button.active {
    color: #1748c9;
    background: rgba(41, 98, 255, .10);
    border-color: #2962ff;
}

.live-mini-log[hidden] {
    display: none !important;
}

@media (max-width: 760px) {
    .live-log-button span {
        display: none;
    }

    .live-log-button .button-icon {
        width: 19px;
        height: 19px;
    }

    .stream-status-indicator {
        max-width: 150px;
    }

    #live-status-text {
        overflow: hidden;
        text-overflow: ellipsis;
    }
}


/* Bollinger Bands muestra superior, media e inferior en una sola entrada. */
.indicator-value {
    white-space: nowrap;
}

@media (max-width: 720px) {
    #indicator-legend {
        row-gap: 4px;
    }

    .indicator-value {
        font-size: 10px;
    }
}
