* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f0f23;
    color: #d1d4dc;
    height: 100vh;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.6rem 1rem;
    background: #16213e;
    border-bottom: 1px solid #2B2B43;
    flex-wrap: wrap;
}

header h1 {
    font-size: 1.1rem;
    font-weight: 600;
    white-space: nowrap;
}

header h1 a {
    color: inherit;
    text-decoration: none;
}

header h1 a:hover {
    color: #26a69a;
}

.controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

select {
    background: #1a1a2e;
    color: #d1d4dc;
    border: 1px solid #485c7b;
    padding: 0.35rem 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
}

.asset-picker {
    background: #1a1a2e;
    color: #d1d4dc;
    border: 1px solid #485c7b;
    border-radius: 4px;
    padding: 0.35rem 0.5rem;
    font-size: 0.85rem;
    min-width: 160px;
    width: 160px;
}

.asset-picker::placeholder {
    color: #7f8796;
}

.asset-picker-wrap {
    position: relative;
}

.asset-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    width: 260px;
    max-height: min(48vh, 360px);
    overflow-y: auto;
    background: rgba(26, 16, 16, 0.98);
    border: 1px solid #3e3a4c;
    border-radius: 8px;
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.45);
    z-index: 1200;
}

.asset-menu-item {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 12px;
    cursor: pointer;
    color: #d6d2cd;
    font-size: 0.9rem;
}

.asset-menu-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.asset-menu-item.active {
    background: rgba(255, 255, 255, 0.12);
}

.asset-menu-header {
    padding: 6px 12px 4px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #7f8796;
    border-top: 1px solid #2a2a3e;
    margin-top: 2px;
    pointer-events: none;
    user-select: none;
}

.asset-menu-header:first-child {
    border-top: none;
    margin-top: 0;
}

.asset-menu-ticker {
    color: #6b7280;
    white-space: nowrap;
    font-size: 0.78rem;
}

.asset-menu-empty {
    padding: 10px 12px;
    color: #a7a7b6;
    font-size: 0.82rem;
}

.tf-buttons,
.preset-buttons,
.zoom-buttons {
    display: flex;
    gap: 2px;
}

.tf-buttons button,
.preset-buttons button,
.zoom-buttons button {
    background: #1a1a2e;
    color: #d1d4dc;
    border: 1px solid #485c7b;
    padding: 0.35rem 0.7rem;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.15s;
}

.tf-buttons button:first-child,
.preset-buttons button:first-child,
.zoom-buttons button:first-child { border-radius: 4px 0 0 4px; }
.tf-buttons button:last-child,
.preset-buttons button:last-child,
.zoom-buttons button:last-child { border-radius: 0 4px 4px 0; }

.tf-buttons button.active {
    background: #26a69a;
    color: #fff;
    border-color: #26a69a;
}

.preset-buttons button.active {
    background: #7c4dff;
    color: #fff;
    border-color: #7c4dff;
}

.zoom-buttons button {
    padding: 0.35rem 0.55rem;
    font-weight: 600;
}

.zoom-buttons button:hover {
    background: #2B2B43;
}

.tf-buttons button:hover:not(.active),
.preset-buttons button:hover:not(.active) {
    background: #2B2B43;
}

.legend-panel-toggle.icon-btn {
    background: #1a1a2e;
    color: #d1d4dc;
    border: 1px solid #485c7b;
    border-radius: 4px;
    padding: 4px 5px;
    cursor: pointer;
    line-height: 0;
    transition: background 0.15s, color 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.legend-panel-toggle.icon-btn:hover {
    background: #2B2B43;
}

.legend-panel-toggle.icon-btn.active {
    color: #26a69a;
    border-color: #26a69a;
}

.help-toggle.icon-btn {
    background: #1a1a2e;
    color: #d1d4dc;
    border: 1px solid #485c7b;
    border-radius: 4px;
    padding: 4px 5px;
    cursor: pointer;
    line-height: 0;
    transition: background 0.15s, color 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.help-toggle.icon-btn:hover {
    background: #2B2B43;
    color: #26a69a;
}

.health-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid #485c7b;
    background: #1a1a2e;
}

.health-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

.health-live { color: #9de3b4; }
.health-live .health-dot { background: #26a69a; }

.health-delayed { color: #ffd18a; }
.health-delayed .health-dot { background: #ffa726; }

.health-reconnecting { color: #ffb0b0; }
.health-reconnecting .health-dot { background: #ef5350; }

.health-replay { color: #fbbf24; }
.health-replay .health-dot { background: #f59e0b; }

/* --- Replay controls --- */
.history-control { display: inline-flex; align-items: center; }

.history-step-btn { padding: 2px 4px; }
.history-step-btn:hover { color: #fbbf24; }

.back-to-live-btn {
    background: #26a69a;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 3px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    font-weight: 600;
    margin-left: 4px;
}
.back-to-live-btn:hover { background: #2bbbad; }

.replay-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    padding: 2px 10px;
    border-radius: 999px;
    border: 1px solid #92400e;
    background: rgba(245, 158, 11, 0.15);
    color: #fbbf24;
    font-weight: 600;
}

.loading-indicator {
    color: #ffa726;
    font-size: 0.8rem;
}

.error-message {
    color: #ef5350;
    font-size: 0.8rem;
}

main {
    flex: 1;
    overflow: hidden;
    position: relative;
}

#chart-container {
    width: 100%;
    height: 100%;
}

/* Chart legend overlay */
.chart-legend {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(22, 33, 62, 0.88);
    border: 1px solid #2B2B43;
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 0.72rem;
    z-index: 10;
    max-width: 200px;
    backdrop-filter: blur(4px);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 4px;
    cursor: pointer;
    border-radius: 3px;
    transition: opacity 0.15s, background 0.15s;
    user-select: none;
}

.legend-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.legend-item.legend-disabled {
    opacity: 0.35;
}

.legend-item.legend-disabled .legend-label {
    text-decoration: line-through;
}

.legend-swatch {
    width: 12px;
    height: 3px;
    border-radius: 1px;
    flex-shrink: 0;
}

.legend-label {
    color: #c0c4cc;
    white-space: nowrap;
}

.legend-crosshair {
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid #2B2B43;
}

.legend-price {
    color: #ffa726;
    font-weight: 600;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.7rem;
}

/* Insight panel */
.insight-panel {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.5rem 1rem;
    background: #16213e;
    border-top: 1px solid #2B2B43;
    font-size: 0.8rem;
    min-height: 36px;
    flex-shrink: 0;
}

.insight-bias {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
}

.insight-levels {
    display: flex;
    gap: 1rem;
    white-space: nowrap;
}

.level-support { color: #26a69a; }
.level-resistance { color: #ef5350; }

.insight-summary {
    color: #8892a0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

/* Debug panel */
.debug-panel {
    background: #111827;
    border-top: 1px solid #2B2B43;
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    flex-shrink: 0;
    max-height: 150px;
    overflow-y: auto;
}

.debug-section h3 {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #7c4dff;
    margin-bottom: 0.3rem;
    letter-spacing: 0.05em;
}

.indicator-grid {
    display: grid;
    grid-template-columns: repeat(4, auto);
    gap: 0.15rem 0.8rem;
}

.indicator-cell {
    display: flex;
    gap: 0.3rem;
    align-items: center;
}

.indicator-label {
    color: #6b7280;
}

.indicator-value {
    font-weight: 600;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.ind-buy { color: #26a69a; }
.ind-sell { color: #ef5350; }
.ind-wait { color: #ffa726; }

.group-scores-grid {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.score-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.score-label {
    color: #6b7280;
    min-width: 80px;
}

.score-buy { color: #26a69a; font-weight: 600; }
.score-sell { color: #ef5350; font-weight: 600; }
.score-wait { color: #ffa726; }

.trend-summary-text {
    color: #8892a0;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.7rem;
    white-space: pre-wrap;
    max-width: 600px;
}

/* Pattern Analysis panel */
/* Pattern Analysis — chart overlay (bottom-left) */
.chart-pattern-overlay {
    position: absolute;
    bottom: 30px;
    left: 8px;
    background: rgba(22, 33, 62, 0.88);
    border: 1px solid #2B2B43;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.68rem;
    z-index: 10;
    backdrop-filter: blur(4px);
    font-family: 'SF Mono', 'Fira Code', monospace;
    max-width: 520px;
}

.pattern-overlay-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 3px;
    white-space: nowrap;
}

.pattern-overlay-title {
    font-size: 0.62rem;
    text-transform: uppercase;
    color: #ffb74d;
    letter-spacing: 0.05em;
    font-weight: 700;
}

.pattern-overlay-summary {
    color: #d1d4dc;
    font-weight: 600;
}

.pattern-overlay-vol {
    color: #6b7280;
    margin-left: auto;
}

.pattern-overlay-rows {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.pattern-overlay-row {
    display: flex;
    gap: 0.6rem;
    align-items: center;
}

.pattern-overlay-label {
    color: #6b7280;
    min-width: 80px;
}

.pattern-overlay-dir {
    font-weight: 600;
    min-width: 50px;
    text-transform: capitalize;
}

.pattern-overlay-conf {
    color: #9ca3af;
    min-width: 35px;
    text-align: right;
}

.pattern-overlay-range {
    color: #d1d4dc;
    min-width: 130px;
}

.pattern-overlay-counts {
    color: #6b7280;
}

.pat-up { color: #26a69a; }
.pat-down { color: #ef5350; }
.pat-neutral { color: #ffa726; }

.pattern-conf {
    color: #9ca3af;
    min-width: 35px;
    text-align: right;
}

.pattern-range {
    color: #d1d4dc;
    min-width: 200px;
}

.pattern-counts {
    color: #6b7280;
}

.help-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(6, 10, 24, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 16px;
}

.help-modal {
    width: min(860px, 96vw);
    max-height: 90vh;
    overflow: auto;
    background: #101b38;
    border: 1px solid #2B2B43;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.help-modal-header {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    border-bottom: 1px solid #2B2B43;
    background: #16213e;
}

.help-modal-header h2 {
    font-size: 1rem;
    color: #d7deea;
}

.help-close {
    background: transparent;
    color: #d1d4dc;
    border: 1px solid #485c7b;
    border-radius: 4px;
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
}

.help-modal-body {
    padding: 14px;
    color: #c7cfdf;
    font-size: 0.9rem;
    line-height: 1.45;
}

.help-lead {
    margin-bottom: 10px;
    color: #d8e0ef;
}

.help-section {
    margin-bottom: 10px;
}

.help-section h3 {
    color: #8f67ff;
    font-size: 0.9rem;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.help-section p {
    margin: 3px 0;
}

.help-disclaimer {
    margin-top: 10px;
    color: #9fb0cd;
    border-top: 1px solid #2B2B43;
    padding-top: 8px;
}

.help-actions {
    margin-top: 10px;
    display: flex;
    gap: 8px;
}

.help-action-btn {
    background: #1a1a2e;
    color: #d1d4dc;
    border: 1px solid #485c7b;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 0.82rem;
}

.help-action-btn:hover {
    background: #2B2B43;
}

.help-action-btn.secondary {
    border-color: #7c4dff;
    color: #cdb7ff;
}

.help-action-btn.reset {
    border-color: #ef5350;
    color: #ef9a9a;
    margin-left: auto;
}

.help-action-btn.reset:hover {
    background: rgba(239, 83, 80, 0.15);
}

/* Chart tooltip */
.chart-tooltip {
    position: absolute;
    pointer-events: none;
    z-index: 20;
    background: rgba(22, 33, 62, 0.94);
    border: 1px solid #485c7b;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.72rem;
    color: #e0e3ea;
    white-space: pre-line;
    max-width: 360px;
    backdrop-filter: blur(4px);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    transition: opacity 0.1s;
}

[x-cloak] { display: none !important; }

@media (max-width: 600px) {
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.4rem;
    }
    .controls {
        flex-wrap: wrap;
    }
    .chart-legend {
        font-size: 0.65rem;
        max-width: 160px;
    }
    .insight-panel {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .insight-summary {
        width: 100%;
        white-space: normal;
    }
    .debug-panel {
        flex-direction: column;
        gap: 0.5rem;
    }
    .indicator-grid {
        grid-template-columns: repeat(2, auto);
    }
    .chart-pattern-overlay {
        font-size: 0.6rem;
        max-width: 300px;
        bottom: 24px;
    }
    .pattern-overlay-range { display: none; }
}
