/**
 * Pro Chart Styles
 * Dark/Cosmic mode compatible
 */

/* ========================================
   CHART CONTAINER
   ======================================== */

#pro-chart-container {
    width: 100%;
    height: 450px;
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg-secondary, #1a1d2e);
}

.chart-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 15px;
    color: #ef4444;
}

.chart-error button {
    padding: 8px 20px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

/* ========================================
   AI ANALYSIS PANEL
   ======================================== */

#ai-analysis-panel {
    margin-top: 15px;
    padding: 20px;
    background: linear-gradient(145deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.05));
    border-radius: 16px;
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.ai-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.ai-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.ai-title {
    font-size: 1.1em;
    font-weight: 700;
    color: #a78bfa;
}

.ai-symbol {
    font-size: 0.9em;
    color: #9ca3af;
    background: rgba(99, 102, 241, 0.2);
    padding: 4px 12px;
    border-radius: 20px;
}

/* Meta Indicator */
.meta-indicator {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
}

.meta-score {
    display: flex;
    align-items: baseline;
    padding: 15px 25px;
    border-radius: 12px;
    color: white;
}

.score-value {
    font-size: 2.5em;
    font-weight: 800;
}

.score-label {
    font-size: 1em;
    opacity: 0.8;
    margin-left: 2px;
}

.meta-signal {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.signal-icon {
    font-size: 2em;
}

.signal-text {
    font-size: 1.1em;
    font-weight: 700;
    text-transform: uppercase;
}

.meta-confidence {
    margin-left: auto;
    padding: 8px 15px;
    background: rgba(99, 102, 241, 0.2);
    border-radius: 8px;
    font-size: 0.9em;
    color: #a78bfa;
}

/* AI Explanation */
.ai-explanation {
    padding: 15px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 10px;
    border-left: 4px solid #8b5cf6;
    line-height: 1.6;
    color: #e5e7eb;
}

/* Entry/SL/TP */
.entry-sl-tp {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
}

.est-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
}

.est-row.sl {
    background: rgba(239, 68, 68, 0.1);
    border-left: 3px solid #ef4444;
}

.est-row.tp {
    background: rgba(16, 185, 129, 0.1);
    border-left: 3px solid #10b981;
}

.est-label {
    color: #9ca3af;
    font-size: 0.9em;
}

.est-value {
    font-weight: 700;
    color: #f3f4f6;
}

.no-entry {
    padding: 15px;
    text-align: center;
    color: #9ca3af;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
    font-style: italic;
}

/* Signal Strength */
.signal-strength {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9em;
    color: #9ca3af;
}

.strength-bar {
    flex: 1;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.strength-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* Loading */
.ai-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 30px;
    color: #9ca3af;
}

.spinner-small {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(139, 92, 246, 0.3);
    border-top-color: #8b5cf6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.ai-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 20px;
    color: #ef4444;
}

.ai-error button {
    padding: 6px 15px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

/* ========================================
   TRADINGVIEW-STYLE TOOLBAR
   ======================================== */

.chart-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 15px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid rgba(99, 102, 241, 0.2);
    flex-wrap: wrap;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 10px;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.toolbar-group:last-child {
    border-right: none;
    margin-left: auto;
}

.toolbar-btn {
    padding: 6px 12px;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 6px;
    color: #a78bfa;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.toolbar-btn:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: rgba(99, 102, 241, 0.5);
    transform: translateY(-1px);
}

.toolbar-btn.active {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-color: #8b5cf6;
    color: white;
}

.toolbar-btn svg {
    width: 16px;
    height: 16px;
}

/* Timeframe selector */
.timeframe-selector {
    display: flex;
    gap: 3px;
    background: rgba(0, 0, 0, 0.2);
    padding: 3px;
    border-radius: 8px;
}

.tf-btn {
    padding: 5px 10px;
    background: transparent;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    font-size: 0.8em;
    font-weight: 600;
    border-radius: 5px;
    transition: all 0.2s;
}

.tf-btn:hover {
    color: #a78bfa;
    background: rgba(99, 102, 241, 0.1);
}

.tf-btn.active {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
}

/* Chart type selector */
.chart-type-selector {
    position: relative;
}

.chart-type-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 5px;
    background: #1a1d2e;
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 8px;
    padding: 8px;
    display: none;
    z-index: 1000;
    min-width: 150px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.chart-type-dropdown.show {
    display: block;
}

.chart-type-option {
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 5px;
    color: #d1d5db;
    font-size: 0.85em;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.chart-type-option:hover {
    background: rgba(99, 102, 241, 0.2);
    color: #a78bfa;
}

.chart-type-option.active {
    background: rgba(99, 102, 241, 0.3);
    color: #8b5cf6;
    font-weight: 600;
}

/* Drawing tools panel */
.drawing-tools-panel {
    position: absolute;
    top: 60px;
    left: 15px;
    background: rgba(26, 29, 46, 0.95);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 10px;
    padding: 10px;
    display: none;
    z-index: 999;
    backdrop-filter: blur(10px);
}

.drawing-tools-panel.show {
    display: block;
}

.drawing-tool-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    background: transparent;
    border: none;
    color: #d1d5db;
    cursor: pointer;
    width: 100%;
    border-radius: 6px;
    font-size: 0.85em;
    transition: all 0.2s;
}

.drawing-tool-btn:hover {
    background: rgba(99, 102, 241, 0.2);
    color: #a78bfa;
}

.drawing-tool-btn.active {
    background: rgba(99, 102, 241, 0.3);
    color: #8b5cf6;
}

/* Crosshair info panel */
.crosshair-info {
    position: absolute;
    top: 50px;
    left: 10px;
    background: rgba(26, 29, 46, 0.95);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 8px;
    padding: 10px 15px;
    display: none;
    z-index: 998;
    backdrop-filter: blur(10px);
    font-size: 0.85em;
}

.crosshair-info.show {
    display: block;
}

.crosshair-row {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    margin: 3px 0;
}

.crosshair-label {
    color: #9ca3af;
    font-weight: 600;
}

.crosshair-value {
    color: #f3f4f6;
    font-weight: 700;
}

.crosshair-value.up {
    color: #10b981;
}

.crosshair-value.down {
    color: #ef4444;
}

/* Fullscreen mode */
.chart-wrapper.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    background: #0f1117;
}

.chart-wrapper.fullscreen #pro-chart-container {
    height: calc(100vh - 60px);
    border-radius: 0;
}

/* Volume panel */
#volume-chart {
    height: 100px;
    border-top: 1px solid rgba(99, 102, 241, 0.2);
}

/* ========================================
   CUSTOM INDICATORS MENU
   ======================================== */

#custom-indicators-menu {
    /* Scrollbar styling */
    scrollbar-width: thin;
    scrollbar-color: rgba(99, 102, 241, 0.5) rgba(31, 41, 55, 0.5);
}

#custom-indicators-menu::-webkit-scrollbar {
    width: 6px;
}

#custom-indicators-menu::-webkit-scrollbar-track {
    background: rgba(31, 41, 55, 0.5);
    border-radius: 3px;
}

#custom-indicators-menu::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.5);
    border-radius: 3px;
}

#custom-indicators-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.7);
}

/* Custom indicators button hover */
#custom-indicators-btn:hover {
    background: #374151 !important;
    border-color: #6366f1 !important;
}

/* Responsive */
@media (max-width: 768px) {
    .chart-toolbar {
        padding: 8px 10px;
        gap: 5px;
    }
    
    .toolbar-btn {
        padding: 5px 8px;
        font-size: 0.75em;
    }
    
    .toolbar-group {
        padding: 0 5px;
    }
    
    .tf-btn {
        padding: 4px 6px;
        font-size: 0.7em;
    }
}


@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

/* Custom Active State for Drawing Control Button */
.finai-tool-active {
    background: #3b82f6 !important;
    border-radius: 4px;
}
.finai-tool-active svg {
    opacity: 1 !important;
    fill: #ffffff !important;
}

/* AmCharts 5 Drawing Tool Active State Styling (Native amCharts 5 active classes) */
.am5stock-control .am5-active,
.am5stock-control .am5stock-active,
.am5stock-control .active,
.am5stock-control-button.am5-active,
.am5stock-control-button.am5stock-active,
.am5stock-control-button.active,
.am5stock-link.am5-active,
.am5stock-link.am5stock-active,
.am5stock-link.active,
.am5stock-list-item.am5-active,
.am5stock-list-item.am5stock-active,
.am5stock-list-item.active {
    background: #3b82f6 !important;
    border-radius: 4px;
}

/* Hover effects cho amCharts 5 tools để đồng bộ với custom toolbar */
.am5stock-control a:hover,
.am5stock-control button:hover,
.am5stock-control .am5stock-control-button:hover,
.am5stock-control .am5stock-list-item:hover,
.am5stock-control .am5stock-link:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    border-radius: 4px;
}
/* Không áp dụng hover effect khi nó đang được active (để giữ màu xanh blue) */
.am5stock-control .am5-active:hover,
.am5stock-control .am5stock-active:hover,
.am5stock-control .active:hover,
.finai-tool-active:hover {
    background: #3b82f6 !important;
}

.am5stock-control .am5-active svg,
.am5stock-control .am5stock-active svg,
.am5stock-control .active svg,
.am5stock-control-button.am5-active svg,
.am5stock-control-button.am5stock-active svg,
.am5stock-control-button.active svg,
.am5stock-link.am5-active svg,
.am5stock-link.am5stock-active svg,
.am5stock-link.active svg {
    opacity: 1 !important;
    fill: #ffffff !important;
}

/* ========================================
   FINAI CUSTOM CONTEXT MENU (CHUỘT PHẢI)
   ======================================== */

.finai-context-menu {
    position: fixed;
    z-index: 99999;
    min-width: 220px;
    background: rgba(18, 20, 36, 0.97);
    border: 1px solid rgba(99, 102, 241, 0.35);
    border-radius: 10px;
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.55),
        0 2px 8px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 5px 0;
    display: none;
    opacity: 0;
    transform: scale(0.94) translateY(-4px);
    transform-origin: top left;
    transition: opacity 0.15s ease, transform 0.15s ease;
    font-family: 'Inter', 'Segoe UI', sans-serif;
    user-select: none;
}

.finai-context-menu.visible {
    display: block;
    opacity: 1;
    transform: scale(1) translateY(0);
}

.finai-context-menu-separator {
    height: 1px;
    background: rgba(255, 255, 255, 0.07);
    margin: 4px 0;
}

.finai-context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    cursor: pointer;
    color: #cbd5e1;
    font-size: 13px;
    font-weight: 450;
    letter-spacing: 0.01em;
    transition: background 0.12s ease, color 0.12s ease;
    position: relative;
}

.finai-context-menu-item:hover {
    background: rgba(99, 102, 241, 0.18);
    color: #e2e8f0;
}

.finai-context-menu-item:active {
    background: rgba(99, 102, 241, 0.32);
}

.finai-context-menu-item .ctx-icon {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #818cf8;
    flex-shrink: 0;
    font-size: 13px;
}

.finai-context-menu-item .ctx-label {
    flex: 1;
}

.finai-context-menu-item .ctx-shortcut {
    font-size: 11px;
    color: #475569;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    padding: 1px 5px;
    letter-spacing: 0.05em;
    flex-shrink: 0;
    font-family: 'Consolas', 'Monaco', monospace;
}
/* ================================================================
   IMAGE OVERLAY TOOL — Chèn ảnh lên biểu đồ (anchor theo giá/thời gian)
   ================================================================ */

.finai-img-overlay {
    border: 1px solid rgba(168, 85, 247, 0.5);
    border-radius: 4px;
    overflow: hidden;
    transition: border-color 0.15s;
    pointer-events: all;
}
.finai-img-overlay:hover {
    border-color: rgba(168, 85, 247, 0.9);
    box-shadow: 0 0 0 1px rgba(168, 85, 247, 0.3);
}

/* Nút xóa ❌ */
.finai-img-delete-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background: rgba(239, 68, 68, 0.85);
    color: white;
    border-radius: 50%;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 10;
    line-height: 1;
}
.finai-img-overlay:hover .finai-img-delete-btn {
    opacity: 1;
}
.finai-img-delete-btn:hover {
    background: rgba(239, 68, 68, 1);
}

/* Resize handles — 4 góc */
.finai-img-resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: rgba(168, 85, 247, 0.8);
    border: 1px solid white;
    border-radius: 2px;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 10;
}
.finai-img-overlay:hover .finai-img-resize-handle {
    opacity: 1;
}
.finai-img-nw { top: -5px;    left: -5px;   cursor: nw-resize; }
.finai-img-ne { top: -5px;    right: -5px;  cursor: ne-resize; }
.finai-img-sw { bottom: -5px; left: -5px;   cursor: sw-resize; }
.finai-img-se { bottom: -5px; right: -5px;  cursor: se-resize; }

/* Mobile UI Fixes */
@media (max-width: 768px) {
    div[id^="stock-toolbar-container"] {
        padding: 2px !important;
        gap: 2px !important;
        justify-content: flex-start !important;
        flex-wrap: wrap !important;
    }
    div[id^="stock-toolbar-container"] button, 
    div[id^="stock-toolbar-container"] select,
    div[id^="stock-toolbar-container"] .toolbar-btn,
    div[id^="stock-toolbar-container"] .tf-btn {
        padding: 2px 4px !important;
        font-size: 11px !important;
        height: 26px !important;
        min-height: 26px !important;
        line-height: 22px !important;
    }
    div[id^="finai-fav-toolbar"] {
        padding: 0 !important;
        margin: 0 !important;
        gap: 2px !important;
        border: none !important;
        background: transparent !important;
    }
    div[id^="finai-fav-toolbar"] button {
        padding: 2px !important;
        width: 26px !important;
        height: 26px !important;
    }
    div[id^="finai-fav-toolbar"] svg {
        width: 14px !important;
        height: 14px !important;
    }
    div[id^="htf-bias-container"] {
        transform: scale(0.65) !important;
        transform-origin: bottom left !important;
        left: 5px !important;
        bottom: 50px !important; 
    }
}
/* Page light mode chart chrome */
body:not(.dark-mode):not(.cosmic-mode) div[id^="stock-toolbar-container"],
body:not(.dark-mode):not(.cosmic-mode) .light-chart-theme div[id^="stock-toolbar-container"]{
  background:#f1f5f9!important;
  border-bottom:1px solid #cbd5e1!important;
}
body:not(.dark-mode):not(.cosmic-mode) div[id^="stock-toolbar-container"] .am5stock-control,
body:not(.dark-mode):not(.cosmic-mode) div[id^="stock-toolbar-container"] button,
body:not(.dark-mode):not(.cosmic-mode) div[id^="stock-toolbar-container"] select{
  background:#fff!important;
  color:#0f172a!important;
  border-color:#cbd5e1!important;
}
body:not(.dark-mode):not(.cosmic-mode) div[id^="htf-bias-container"]{
  background:rgba(248,250,252,.96)!important;
  border:1px solid #cbd5e1!important;
  color:#0f172a!important;
}
body:not(.dark-mode):not(.cosmic-mode) div[id^="htf-bias-container"] table th,
body:not(.dark-mode):not(.cosmic-mode) div[id^="htf-bias-container"] table td,
body:not(.dark-mode):not(.cosmic-mode) div[id^="htf-bias-container"] > div{color:#334155!important}
/* ===== Dark/Cosmic chart chrome sync ===== */
body.dark-mode div[id^="stock-toolbar-container"],
body.cosmic-mode div[id^="stock-toolbar-container"]{
  background:#050505!important;
  border-bottom:1px solid rgba(148,163,184,.35)!important;
}
body.dark-mode div[id^="stock-toolbar-container"] .am5stock-control,
body.cosmic-mode div[id^="stock-toolbar-container"] .am5stock-control,
body.dark-mode div[id^="stock-toolbar-container"] button,
body.cosmic-mode div[id^="stock-toolbar-container"] button,
body.dark-mode div[id^="stock-toolbar-container"] select,
body.cosmic-mode div[id^="stock-toolbar-container"] select{
  background:#1f2937!important;
  color:#e2e8f0!important;
  border-color:#374151!important;
}
body.dark-mode [id^="ai-analyze-btn-"],
body.cosmic-mode [id^="ai-analyze-btn-"]{
  background:linear-gradient(135deg,#8b5cf6,#6366f1)!important;
  color:#fff!important;
  border:none!important;
}
body.dark-mode div[id^="stock-toolbar-container"] svg,
body.cosmic-mode div[id^="stock-toolbar-container"] svg{
  filter:none!important;
}
body.dark-mode div[id^="htf-bias-container"],
body.cosmic-mode div[id^="htf-bias-container"]{
  background:rgba(15,23,42,.92)!important;
  color:#e2e8f0!important;
  border-color:rgba(148,163,184,.35)!important;
}
body.dark-mode .light-chart-theme .am5stock-control-button,
body.cosmic-mode .light-chart-theme .am5stock-control-button,
body.dark-mode .light-chart-theme [id^="custom-indicators-btn-"],
body.cosmic-mode .light-chart-theme [id^="custom-indicators-btn-"]{
  background:#1f2937!important;
  color:#e2e8f0!important;
  border-color:#374151!important;
}
body.dark-mode .light-chart-theme .am5stock-control-button svg,
body.cosmic-mode .light-chart-theme .am5stock-control-button svg{
  filter:none!important;
}

/* ===================================================
   PRO CHART TOOLBAR STYLING & PROPORTIONS
   =================================================== */

/* Container chuẩn: 1 hàng ngang, wrap mượt mà nếu màn hình hẹp, padding gọn gàng */
div[id^="stock-toolbar-container"] {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 6px !important;
    padding: 6px 10px !important;
    min-height: 42px !important;
    max-height: none !important;
    overflow: visible !important;
    box-sizing: border-box !important;
    position: relative !important;
    z-index: 1000 !important;
}

#th-chart.th-chart,
#th-chart,
.th-chart,
.th-chart-wrap,
#pro-chart-container,
.chart-wrapper {
    position: relative !important;
    overflow: visible !important;
}

/* Chuẩn hóa toàn bộ StockControl button trong amCharts 5 */
.am5stock-control-button {
    display: inline-flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    height: 30px !important;
    min-height: 30px !important;
    padding: 0 10px !important;
    box-sizing: border-box !important;
    line-height: 1 !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    border-radius: 4px !important;
    white-space: nowrap !important;
    overflow: visible !important;
}

/* Label text không bị cắt xén đáy */
.am5stock-control-button .am5stock-control-label {
    display: inline-block !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    line-height: 1 !important;
    margin: 0 !important;
    padding: 0 !important;
    white-space: nowrap !important;
}

/* Icon / SVG bên trong button */
.am5stock-control-button .am5stock-control-icon,
.am5stock-control-button svg {
    width: 16px !important;
    height: 16px !important;
    max-width: 16px !important;
    max-height: 16px !important;
    flex-shrink: 0 !important;
    margin: 0 !important;
}

/* Dropdown list và Modal của amCharts 5 & Custom */
.am5stock-dropdown-list,
.am5stock-control-list,
.am5stock-control-dropdown,
.am5stock-control-drawing-tools,
.am5modal,
.am5-modal,
div[id^="custom-indicators-menu-"],
#symbol-search-dropdown,
div[id^="symbol-search-dropdown-"],
.symbol-search-dropdown {
    z-index: 999999 !important;
    border-radius: 8px !important;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.75) !important;
}

/* amCharts indicator settings modal (thường gắn trên body, ngoài #chart-tab) */
.am5-modal .am5-modal-content {
    color: var(--str-text-main, #f8fafc) !important;
    background: var(--str-bg-card, #141414) !important;
    border: 1px solid var(--str-border-subtle, rgba(255, 255, 255, 0.14)) !important;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55) !important;
}

.am5-modal-content h1,
.am5-modal-content .am5-modal-table-heading {
    color: inherit !important;
}

/* Ô Period/Offset/Field: nền sáng + chữ tối (tránh chữ trắng trên nền trắng) */
.am5-modal-content input[type="text"],
.am5-modal-content input[type="number"],
.am5-modal-content select,
.am5-modal-content .am5-modal-input {
    color: #0f172a !important;
    -webkit-text-fill-color: #0f172a !important;
    background: #ffffff !important;
    border-color: #94a3b8 !important;
}

.am5-modal-content select option {
    color: #0f172a !important;
    background: #ffffff !important;
}

.am5-modal-content .am5-modal-link-reset {
    color: var(--str-accent, #3b82f6) !important;
}

body:not(.dark-mode):not(.cosmic-mode) .am5-modal .am5-modal-content,
body.str-pure-white .am5-modal .am5-modal-content {
    color: #0f172a !important;
    background: #ffffff !important;
    border-color: #e2e8f0 !important;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18) !important;
}

#symbol-search-list::-webkit-scrollbar,
div[id^="symbol-search-list-"]::-webkit-scrollbar,
.symbol-search-list::-webkit-scrollbar {
    width: 6px !important;
}
#symbol-search-list::-webkit-scrollbar-track,
div[id^="symbol-search-list-"]::-webkit-scrollbar-track,
.symbol-search-list::-webkit-scrollbar-track {
    background: #0f172a !important;
}
#symbol-search-list::-webkit-scrollbar-thumb,
div[id^="symbol-search-list-"]::-webkit-scrollbar-thumb,
.symbol-search-list::-webkit-scrollbar-thumb {
    background: #475569 !important;
    border-radius: 3px !important;
}
#symbol-search-list::-webkit-scrollbar-thumb:hover,
div[id^="symbol-search-list-"]::-webkit-scrollbar-thumb:hover,
.symbol-search-list::-webkit-scrollbar-thumb:hover {
    background: #3b82f6 !important;
}

/* Custom buttons trên toolbar: AI, Custom, Bg, MTF Toggle */
[id^="ai-analyze-btn-"],
[id^="custom-indicators-btn-"],
[id^="bg-toggle-btn-"],
[id^="htf-bias-toggle-btn-"],
.custom-undo-redo button {
    height: 30px !important;
    min-height: 30px !important;
    box-sizing: border-box !important;
    font-size: 12px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: 1 !important;
    border-radius: 4px !important;
}

/* Symbol Selector Button trên toolbar: Căn giữa hoàn hảo, độ cao 30px đồng bộ, không icon mũi tên */
.symbol-search-wrapper {
    position: relative !important;
    display: inline-flex !important;
    align-items: center !important;
    height: 30px !important;
    margin-left: 6px !important;
    box-sizing: border-box !important;
    vertical-align: middle !important;
}

[id^="symbol-search-btn-"],
.symbol-search-btn {
    height: 30px !important;
    min-height: 30px !important;
    box-sizing: border-box !important;
    font-size: 12px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: normal !important;
    border-radius: 4px !important;
    width: auto !important;
    min-width: fit-content !important;
    max-width: none !important;
    padding: 0 12px !important;
    margin: 0 !important;
    vertical-align: middle !important;
}

[id^="symbol-search-btn-text-"],
.symbol-search-btn-text {
    white-space: nowrap !important;
    overflow: visible !important;
    text-overflow: clip !important;
    max-width: none !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    height: 100% !important;
    font-weight: 600 !important;
    font-size: 12px !important;
    letter-spacing: 0.2px !important;
    line-height: normal !important;
    margin: 0 !important;
    padding: 0 !important;
    transform: none !important;
    vertical-align: middle !important;
}

/* Toolbar Divider mỏng giữa các nhóm nút */
.toolbar-divider {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.15);
    margin: 0 4px;
    flex-shrink: 0;
}
body:not(.dark-mode):not(.cosmic-mode) .toolbar-divider {
    background: rgba(0, 0, 0, 0.15);
}

/* ===================================================
   MTF TREND BIAS OVERLAY & MINIMIZER
   =================================================== */

/* Container bảng MTF Bias (Thu nhỏ tỷ lệ Compact Size ~25%) */
div[id^="htf-bias-container"] {
    position: absolute;
    bottom: 25px;
    left: 15px;
    z-index: 9998;
    background: rgba(15, 23, 42, 0.94) !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    border-radius: 6px !important;
    padding: 6px 8px !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5) !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    font-size: 10px !important;
    user-select: none;
    transition: box-shadow 0.2s ease, opacity 0.2s ease;
    width: 225px !important;
    max-width: 230px !important;
    box-sizing: border-box !important;
}

/* Header kéo thả & điều khiển thu nhỏ */
.htf-bias-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 4px;
    margin-bottom: 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    cursor: grab;
    width: 100%;
    box-sizing: border-box;
}
.htf-bias-header:active {
    cursor: grabbing;
}
.htf-bias-title {
    font-size: 11.5px !important;
    font-weight: 700 !important;
    color: #ffffff !important;
    letter-spacing: 0.3px;
    flex: 1;
    text-align: center;
    padding-left: 18px; /* Cân giữa tiêu đề khi có nút thu nhỏ bên phải */
}

/* Nút thu nhỏ / mở rộng */
.mtf-minimize-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    color: #cbd5e1 !important;
    cursor: pointer;
    font-size: 13px !important;
    font-weight: 700 !important;
    line-height: 1;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.15s ease;
    flex-shrink: 0;
}
.mtf-minimize-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff !important;
}

/* Trạng thái thu nhỏ widget */
div[id^="htf-bias-container"].minimized {
    padding-bottom: 6px !important;
}
div[id^="htf-bias-container"].minimized .htf-bias-table {
    display: none !important;
}
div[id^="htf-bias-container"].minimized .htf-bias-header {
    border-bottom: none !important;
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
}

/* Table styling nhỏ gọn */
.htf-bias-table {
    border-collapse: separate;
    border-spacing: 3px 2px !important;
    width: 100%;
    text-align: center;
    font-size: 10px;
}
.htf-bias-table th {
    padding: 2px 1px !important;
    font-size: 10px !important;
    font-weight: 700 !important;
    color: #94a3b8 !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center !important;
}
.htf-bias-table th:first-child {
    text-align: left !important;
    padding-left: 2px !important;
}
.htf-bias-table td {
    padding: 0 !important;
}
.htf-bias-table td:first-child {
    padding-left: 2px !important;
    color: #94a3b8;
    font-weight: 700;
    font-size: 10px !important;
}

/* Badge trạng thái chuẩn FinAI (Solid Background, chữ trắng #ffffff đậm) */
.htf-bias-badge,
.mtf-badge {
    color: #ffffff !important;
    font-weight: 700 !important;
    border-radius: 4px !important;
    padding: 2px 0 !important;
    text-align: center !important;
    display: block !important;
    width: 100% !important;
    border: none !important;
    font-size: 9.5px !important;
    line-height: 1.2 !important;
    letter-spacing: 0.1px;
    box-sizing: border-box;
}

.htf-bias-badge.badge-strong-buy,
.mtf-badge.badge-strong-buy {
    background: #1e3a8a !important;
}

.htf-bias-badge.badge-buy,
.mtf-badge.badge-buy {
    background: #3b82f6 !important;
}

.htf-bias-badge.badge-neutral,
.mtf-badge.badge-neutral {
    background: #475569 !important;
}

.htf-bias-badge.badge-sell,
.mtf-badge.badge-sell {
    background: #f43f5e !important;
}

.htf-bias-badge.badge-strong-sell,
.mtf-badge.badge-strong-sell {
    background: #9f1239 !important;
}

/* Mini-pill Bar khi thu nhỏ */
div[id^="htf-bias-minibar"] {
    position: absolute;
    bottom: 35px;
    left: 15px;
    z-index: 9998;
    display: none;
    align-items: center;
    gap: 6px;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 20px;
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 600;
    color: #cbd5e1;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
    transition: all 0.2s ease;
}
div[id^="htf-bias-minibar"]:hover {
    background: rgba(30, 41, 59, 0.95);
    border-color: #38bdf8;
    transform: translateY(-1px);
}

/* ===================================================
   STR DYNAMIC THEME SYSTEM INTEGRATION (#chart-tab)
   =================================================== */

#chart-tab .card.chart-wrapper {
    background: var(--str-bg-base, #000000) !important;
    border-color: var(--str-border-subtle, rgba(255, 255, 255, 0.1)) !important;
    transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

body.str-themed-borders #chart-tab .card.chart-wrapper {
    border-color: var(--str-accent, #3b82f6) !important;
    box-shadow: 0 0 16px var(--str-accent-soft, rgba(59, 130, 246, 0.18)) !important;
}

#pro-chart-container {
    background: var(--str-bg-base, #000000) !important;
    transition: background 0.25s ease;
}

#global-toolbar-wrapper {
    background: var(--str-bg-surface, #0f141c) !important;
    border-bottom: 1px solid var(--str-border-subtle, rgba(255, 255, 255, 0.1)) !important;
    transition: background 0.25s ease, border-color 0.25s ease;
}

#charts-grid {
    background: var(--str-bg-base, #000000) !important;
}

.chart-cell {
    background: var(--str-bg-base, #000000) !important;
    transition: background 0.25s ease;
}

/* Layout Selector */
#layout-select {
    background: var(--str-bg-card, #1e293b) !important;
    color: var(--str-text-main, #f8fafc) !important;
    border: 1px solid var(--str-border-subtle, rgba(255, 255, 255, 0.15)) !important;
    transition: all 0.2s ease;
}

/* amCharts 5 StockToolbar Buttons & Controls */
div[id^="stock-toolbar-container"] {
    background: transparent !important;
}

div[id^="stock-toolbar-container"] .am5stock-control-button,
div[id^="stock-toolbar-container"] button,
div[id^="stock-toolbar-container"] select,
.symbol-search-btn,
[id^="symbol-search-btn-"],
[id^="ai-analyze-btn-"],
[id^="custom-indicators-btn-"],
[id^="bg-toggle-btn-"],
[id^="grid-toggle-btn-"],
[id^="recenter-chart-btn-"],
[id^="htf-bias-toggle-btn-"] {
    background: var(--str-bg-card, rgba(255, 255, 255, 0.06)) !important;
    color: var(--str-text-main, #f1f5f9) !important;
    border: 1px solid var(--str-border-subtle, rgba(255, 255, 255, 0.12)) !important;
    transition: all 0.2s ease;
}

div[id^="stock-toolbar-container"] .am5stock-control-button:hover,
div[id^="stock-toolbar-container"] button:hover,
div[id^="stock-toolbar-container"] select:hover,
.symbol-search-btn:hover,
[id^="symbol-search-btn-"]:hover,
[id^="ai-analyze-btn-"]:hover,
[id^="custom-indicators-btn-"]:hover,
[id^="bg-toggle-btn-"]:hover,
[id^="grid-toggle-btn-"]:hover,
[id^="recenter-chart-btn-"]:hover,
[id^="htf-bias-toggle-btn-"]:hover {
    background: var(--str-accent-soft, rgba(59, 130, 246, 0.15)) !important;
    border-color: var(--str-accent, #3b82f6) !important;
    color: var(--str-text-main, #ffffff) !important;
}

/* Active State for Buttons & Timeframes */
div[id^="stock-toolbar-container"] .am5stock-control-button.am5-active,
div[id^="stock-toolbar-container"] .am5stock-control-button[aria-pressed="true"],
.toolbar-btn.active,
.tf-btn.active {
    background: var(--str-accent, #3b82f6) !important;
    border-color: var(--str-accent, #3b82f6) !important;
    color: #ffffff !important;
}

/* Dropdowns & Menus */
.am5stock-dropdown-list,
.am5stock-control-list,
.am5stock-control-dropdown,
.am5stock-control-drawing-tools,
div[id^="custom-indicators-menu-"],
div[id^="symbol-search-dropdown-"],
.symbol-search-dropdown,
.chart-type-dropdown {
    background: var(--str-bg-card, #0f172a) !important;
    border: 1px solid var(--str-border-subtle, rgba(255, 255, 255, 0.15)) !important;
    color: var(--str-text-main, #f8fafc) !important;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6) !important;
}

/* Drawing tools panel */
.drawing-tools-panel,
.crosshair-info {
    background: var(--str-bg-card, rgba(15, 23, 42, 0.95)) !important;
    border: 1px solid var(--str-border-subtle, rgba(255, 255, 255, 0.15)) !important;
    color: var(--str-text-main, #f8fafc) !important;
}

/* MTF Bias Container */
div[id^="htf-bias-container"] {
    background: var(--str-bg-surface, rgba(15, 23, 42, 0.94)) !important;
    border-color: var(--str-border-subtle, rgba(255, 255, 255, 0.15)) !important;
}

body.str-themed-borders div[id^="htf-bias-container"] {
    border-color: var(--str-accent, #3b82f6) !important;
}

/* Light Mode Overrides for #chart-tab */
body:not(.dark-mode):not(.cosmic-mode) #chart-tab .card.chart-wrapper,
body.str-pure-white #chart-tab .card.chart-wrapper,
body:not(.dark-mode):not(.cosmic-mode) #pro-chart-container,
body.str-pure-white #pro-chart-container,
body:not(.dark-mode):not(.cosmic-mode) #charts-grid,
body.str-pure-white #charts-grid,
body:not(.dark-mode):not(.cosmic-mode) .chart-cell,
body.str-pure-white .chart-cell {
    background: #ffffff !important;
    border-color: #e2e8f0 !important;
}

body:not(.dark-mode):not(.cosmic-mode) #global-toolbar-wrapper,
body.str-pure-white #global-toolbar-wrapper {
    background: #f8fafc !important;
    border-bottom: 1px solid #e2e8f0 !important;
}

body:not(.dark-mode):not(.cosmic-mode) #layout-select,
body.str-pure-white #layout-select {
    background: #ffffff !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

body:not(.dark-mode):not(.cosmic-mode) div[id^="stock-toolbar-container"] .am5stock-control-button,
body.str-pure-white div[id^="stock-toolbar-container"] .am5stock-control-button,
body:not(.dark-mode):not(.cosmic-mode) div[id^="stock-toolbar-container"] button,
body.str-pure-white div[id^="stock-toolbar-container"] button,
body:not(.dark-mode):not(.cosmic-mode) div[id^="stock-toolbar-container"] select,
body.str-pure-white div[id^="stock-toolbar-container"] select,
body:not(.dark-mode):not(.cosmic-mode) .symbol-search-btn,
body.str-pure-white .symbol-search-btn,
body:not(.dark-mode):not(.cosmic-mode) [id^="symbol-search-btn-"],
body.str-pure-white [id^="symbol-search-btn-"],
body:not(.dark-mode):not(.cosmic-mode) [id^="ai-analyze-btn-"],
body.str-pure-white [id^="ai-analyze-btn-"],
body:not(.dark-mode):not(.cosmic-mode) [id^="custom-indicators-btn-"],
body.str-pure-white [id^="custom-indicators-btn-"],
body:not(.dark-mode):not(.cosmic-mode) [id^="bg-toggle-btn-"],
body.str-pure-white [id^="bg-toggle-btn-"],
body:not(.dark-mode):not(.cosmic-mode) [id^="grid-toggle-btn-"],
body.str-pure-white [id^="grid-toggle-btn-"],
body:not(.dark-mode):not(.cosmic-mode) [id^="recenter-chart-btn-"],
body.str-pure-white [id^="recenter-chart-btn-"],
body:not(.dark-mode):not(.cosmic-mode) [id^="htf-bias-toggle-btn-"],
body.str-pure-white [id^="htf-bias-toggle-btn-"] {
    background: #ffffff !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

body:not(.dark-mode):not(.cosmic-mode) div[id^="stock-toolbar-container"] .am5stock-control-button:hover,
body.str-pure-white div[id^="stock-toolbar-container"] .am5stock-control-button:hover,
body:not(.dark-mode):not(.cosmic-mode) div[id^="stock-toolbar-container"] button:hover,
body.str-pure-white div[id^="stock-toolbar-container"] button:hover,
body:not(.dark-mode):not(.cosmic-mode) .symbol-search-btn:hover,
body.str-pure-white .symbol-search-btn:hover {
    background: var(--str-accent-soft, rgba(59, 130, 246, 0.12)) !important;
    border-color: var(--str-accent, #3b82f6) !important;
    color: var(--str-accent, #2563eb) !important;
}

body:not(.dark-mode):not(.cosmic-mode) .am5stock-dropdown-list,
body.str-pure-white .am5stock-dropdown-list,
body:not(.dark-mode):not(.cosmic-mode) .am5stock-control-list,
body.str-pure-white .am5stock-control-list,
body:not(.dark-mode):not(.cosmic-mode) div[id^="custom-indicators-menu-"],
body.str-pure-white div[id^="custom-indicators-menu-"],
body:not(.dark-mode):not(.cosmic-mode) div[id^="symbol-search-dropdown-"],
body.str-pure-white div[id^="symbol-search-dropdown-"] {
    background: #ffffff !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15) !important;
}

body:not(.dark-mode):not(.cosmic-mode) div[id^="htf-bias-container"],
body.str-pure-white div[id^="htf-bias-container"] {
    background: rgba(255, 255, 255, 0.95) !important;
    border-color: #cbd5e1 !important;
    color: #0f172a !important;
}

/* Cosmic Mode Overrides */
body.cosmic-mode #global-toolbar-wrapper,
body.str-bg-cosmic #global-toolbar-wrapper {
    background: rgba(6, 9, 19, 0.85) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
}

body.cosmic-mode #charts-grid,
body.str-bg-cosmic #charts-grid,
body.cosmic-mode .chart-cell,
body.str-bg-cosmic .chart-cell,
body.cosmic-mode #pro-chart-container,
body.str-bg-cosmic #pro-chart-container {
    background: #060913 !important;
}

