/* Upbit Dashboard Styles */

/* [FIX] Force Hide Inactive Tab (Leakage Prevention) */
#upbit:not(.active) {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    overflow: hidden !important;
}

/* Table Compactness */
.upbit-table th,
.upbit-table td {
    font-size: 0.75rem;
    padding: 8px 8px;
    vertical-align: middle;
}

.tps-fire {
    color: #ef4444;
    font-weight: bold;
    animation: pulse 1s infinite;
}

.tps-hot {
    color: #f97316;
    font-weight: bold;
}

.tps-normal {
    color: #94a3b8;
}

@keyframes pulse {
    0% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.8;
        transform: scale(1.05);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Narrative Toast Notification (Antigravity Style) */
#narrative-toast-container {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    /* Allow clicks to pass through container */
}

#system-toast-container {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    pointer-events: none;
}

.narrative-toast {
    width: 320px;
    background: rgba(15, 23, 42, 0.98);
    /* Slate 900 with high opacity */
    border: 1px solid rgba(56, 189, 248, 0.3);
    /* Light Blue border */
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    color: #e2e8f0;
    font-family: 'Inter', sans-serif;
    pointer-events: auto;
    /* Enable clicks on toast */
    transition: all 0.3s ease-out;
    animation: slideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
}

/* Glassmorphism Shine Effect */
.narrative-toast::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg,
            transparent,
            rgba(255, 255, 255, 0.05),
            transparent);
    transition: 0.5s;
}

.narrative-toast:hover::before {
    left: 100%;
}

.narrative-toast.success {
    border-left: 4px solid #10b981;
}

/* Emerald */
.narrative-toast.warning {
    border-left: 4px solid #f59e0b;
}

/* Amber */
.narrative-toast.info {
    border-left: 4px solid #3b82f6;
}

/* Blue */

.toast-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 8px;
}

.toast-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: #38bdf8;
    /* Sky 400 */
    display: flex;
    align-items: center;
    gap: 6px;
}

.toast-body {
    font-size: 0.85rem;
    line-height: 1.5;
    color: #cbd5e1;
    /* Slate 300 */
}

.narrative-toast button {
    background: none;
    border: none;
    color: #64748b;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

.narrative-toast button:hover {
    color: #fff;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* [NEW] Scrollable Market List Container */
.market-list-container {
    max-height: 600px;
    /* Adjust height as needed (~15-20 rows) */
    overflow-y: auto;
    position: relative;
    border: 1px solid #334155;
    border-radius: 8px;
    /* Custom Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: #475569 #1e293b;
}

.market-list-container::-webkit-scrollbar {
    width: 6px;
}

.market-list-container::-webkit-scrollbar-track {
    background: #1e293b;
    border-radius: 0 8px 8px 0;
}

.market-list-container::-webkit-scrollbar-thumb {
    background-color: #475569;
    border-radius: 3px;
}

/* Sticky Header for Market List */
.market-list-container thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #0f172a;
    /* Match container background for opacity */
    box-shadow: 0 1px 0 #334155;
    /* Bottom border effect */
}

/* [FINAL FIX] Chart Modal - Absolute Stacking & Visibility (v7.8) */
#chartModal {
    display: none;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background-color: #0f172a !important;
    /* Fully opaque slate */
    z-index: 2147483646 !important;
    /* MaxInt - 1 */
}

#chartModalContent {
    position: absolute !important;
    top: 2% !important;
    left: 1% !important;
    width: 98% !important;
    height: 96vh !important;
    background-color: #1e293b !important;
    border: 1px solid #334155 !important;
    border-radius: 12px !important;
    display: flex !important;
    flex-direction: column !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7) !important;
    z-index: 2147483647 !important;
    /* MaxInt */
    overflow: hidden !important;
}

#chartHeaderOuter {
    flex: 0 0 auto !important;
    background: #1e293b !important;
    border-bottom: 1px solid #475569 !important;
    padding: 6px 12px !important;
    z-index: 100 !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background-color: #0f172a;
    border-bottom: 1px solid #334155;
    border-radius: 8px 8px 0 0;
    cursor: move;
    /* Indicate draggable */
}

.tv-chart-container {
    flex: 1;
    position: relative;
    width: 100%;
    height: 100%;
}

.close-chart-btn {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.5rem;
    cursor: pointer;
}

.close-chart-btn:hover {
    color: #ef4444;
}

/* [NEW] Prevent Auto-Zoom on Mobile Inputs */
@media screen and (max-width: 768px) {

    input,
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* [NEW] Chart Info Bar */
.chart-info-bar,
.chart-account-info-bar {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 5px 15px;
    background-color: #0f172a;
    border-bottom: 1px solid #334155;
    font-size: 0.85rem;
    color: #94a3b8;
    overflow-x: auto;
    white-space: nowrap;
}

.chart-account-info-bar {
    background-color: #1e293b;
    border-top: 1px solid #334155;
    padding: 6px 15px;
    font-size: 0.85rem;
    color: #cbd5e1;
    /* [FIX] Fill Width Layout */
    display: flex;
    justify-content: space-between;
    width: 100%;
    box-sizing: border-box;
}

/* [NEW] Power Bar Container */
.chart-power-bar-container {
    padding: 2px 15px;
    background-color: #0f172a;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-bottom: 1px solid #334155;
}

/* Common Bar Track */
.bar-track {
    position: relative;
    width: 100%;
    height: 8px;
    /* Slim bar */
    background: #334155;
    border-radius: 4px;
    overflow: hidden;
    display: flex;
}

/* Bar Segments */
.bar-fill-left {
    height: 100%;
    transition: width 0.3s;
}

.bar-fill-right {
    height: 100%;
    transition: width 0.3s;
}

/* Tug of War Cursor */
.tug-cursor {
    position: absolute;
    top: -2px;
    width: 4px;
    height: 12px;
    background: #fff;
    border-radius: 2px;
    box-shadow: 0 0 4px rgba(255, 255, 255, 0.8);
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateX(-50%);
    z-index: 10;
}

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

.info-label {
    color: #64748b;
    font-size: 0.8em;
}

.info-val {
    font-weight: 600;
    color: #cbd5e1;
}

.info-val.up {
    color: #f87171;
}

.info-val.down {
    color: #3b82f6;
}

.info-val.fire {
    color: #f59e0b;
}

/* Timeframe Button Active State */
.tf-btn.active {
    background-color: #22c55e !important;
    color: white !important;
    border-color: #22c55e !important;
}

/* Background Candidate Indicator */
tr.bg-candi .market-code::after {
    content: " 📡";
    color: #22c55e;
    font-size: 0.7rem;
    animation: blink 2s infinite;
}

@keyframes blink {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }

    100% {
        opacity: 1;
    }
}

/* [v8.4] Header Scanner List Scrolling */
#headerScannerList::-webkit-scrollbar {
    display: none;
}

#headerScannerList {
    -ms-overflow-style: none;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

/* Responsive Fixes */
.tf-btn {
    padding: 3px 6px;
    font-size: 0.75rem;
    min-width: 30px;
}

/* Mobile Adjustments */
@media screen and (max-width: 768px) {
    .chart-modal-content {
        width: 98% !important;
        left: 1% !important;
        top: 2% !important;
        height: 85vh !important;
        max-width: 100vw !important;
    }

    .chart-header {
        flex-direction: column;
        align-items: flex-start !important;
    }

    .chart-header .chart-title-group {
        margin-bottom: 5px;
    }

    .tf-btn {
        padding: 4px 8px;
        font-size: 0.8rem;
    }

    .chart-controls-row {
        gap: 5px !important;
    }
}

/* [FIX] Upbit Tab Container Padding - REVERTED due to layout issues */
/* #upbit {
    padding: 0 16px 20px 16px;
    box-sizing: border-box;
} */

/* Redundant blocks removed to prevent conflicts */

/* [FIX] Scoping for Chart Bars - REVERTED strict positioning to fix layout mess */
.chart-power-bar-container,
.chart-info-bar {
    /* position: relative; */
    /* z-index: 10; */
    background: #0f172a;
    /* Keep background opaque */
    width: 100%;
    margin-top: 5px;
    /* Ensure spacing */
}

/* #chartPowerBarContainer { margin-top: 5px; } */

/* Candidate List Dropdown Items */
.bg-list-item {
    padding: 6px 10px;
    font-size: 0.8rem;
    color: #e2e8f0;
    cursor: pointer;
    border-bottom: 1px solid #334155;
}

.bg-list-item:hover {
    background-color: #334155;
    color: #22c55e;
}

.bg-list-item:last-child {
    border-bottom: none;
}

/* Sidebar Portfolio List Styles (v31) */
#chartRealPortfolioList {
    flex: 1;
    overflow-y: auto;
    background: #0f172a;
    border-top: 1px solid #334155;
    padding: 5px;
    scrollbar-width: thin;
    scrollbar-color: #334155 #0f172a;
}

#chartRealPortfolioList::-webkit-scrollbar {
    width: 6px;
}

#chartRealPortfolioList::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 3px;
}

#chartRealPortfolioList .upbit-table {
    width: 100%;
    border-collapse: collapse;
}

#chartRealPortfolioList .upbit-table th {
    position: sticky;
    top: 0;
    background: #1e293b;
    z-index: 1;
    font-size: 0.65rem !important;
}

#chartRealPortfolioList .text-up {
    color: #f87171 !important;
}

#chartRealPortfolioList .text-down {
    color: #60a5fa !important;
}

/* [FIX] Hide Global Footer when Upbit is Active */
/* [FIX] Hide Global Footer when Upbit is Active */
body.upbit-active .footer {
    display: none !important;
}

/* [NEW] Orderbook (Hoga) Styles */
.ob-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1.2fr;
    align-items: center;
    padding: 1px 4px;
    font-size: 0.7rem;
    height: 18px;
    /* Fixed height for consistency */
    border-bottom: 1px solid rgba(51, 65, 85, 0.3);
}

.ob-row:hover {
    background-color: rgba(255, 255, 255, 0.05) !important;
}

.ob-unit-btn {
    transition: all 0.2s;
}

.ob-unit-btn:hover {
    opacity: 0.9;
}

/* --- Mobile Upbit Enhancements --- */
@media screen and (max-width: 768px) {

    /* 1. Main wrapper for scrolling tables */
    .market-list-container,
    .table-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Force tables to have a minimum width to enable scrolling */
    .market-list-container .upbit-table,
    .table-container>.upbit-table,
    .algo-scanner-section .upbit-table,
    .vt-analysis-section .upbit-table {
        min-width: 850px !important;
    }

    /* But keep real portfolio table fitting the screen */
    #chartRealPortfolioList .upbit-table {
        min-width: 100% !important;
    }

    /* 2. Control Rows in virtual trading */
    .vt-controls-group .control-row {
        margin-left: 0 !important;
        border-left: none !important;
        padding-left: 0 !important;
        align-items: flex-start !important;
        flex-direction: column !important;
        background: #0f172a;
        padding: 10px !important;
        border-radius: 6px;
        margin-bottom: 8px;
        border: 1px solid #334155 !important;
        gap: 8px !important;
    }

    .control-row>div,
    .control-row label {
        display: flex;
        flex-wrap: wrap;
        gap: 5px;
        align-items: center;
    }

    /* Make inputs touch-friendly */
    .control-row input[type="number"],
    .control-row button {
        padding: 6px !important;
        height: auto !important;
        font-size: 16px !important;
        /* Prevent iOS zoom */
    }

    /* 3. Adjust chart modal layout for stacked view */
    #chartModalContent>div:nth-child(2) {
        flex-direction: column !important;
        overflow-y: auto !important;
        /* Allow smooth scrolling */
        -webkit-overflow-scrolling: touch;
    }

    #chartContentArea {
        min-height: 350px !important;
        flex: none !important;
    }

    #orderbookColumn {
        flex: none !important;
        max-width: 100% !important;
        border-left: none !important;
        border-top: 1px solid #334155;
        padding-top: 10px;
        min-height: 250px;
    }

    #chartSidebar {
        flex: none !important;
        max-width: 100% !important;
        width: 100% !important;
        border-left: none !important;
        border-top: 1px solid #334155;
        padding-left: 0 !important;
        margin-top: 10px;
        height: auto !important;
        overflow: visible !important;
    }

    /* Ensure Chart Header overflows gracefully */
    #chartHeaderOuter {
        padding: 4px 6px !important;
        overflow-x: auto;
    }

    #chartHeaderOuter>div {
        flex-wrap: wrap !important;
        height: auto !important;
        gap: 8px !important;
    }
}