/* EMPEROR TRADING TERMINAL - PROFESSIONAL UI UPGRADE
   
   Transforms layout into TradingView-style dashboard for desktop
   and swipeable tabs for mobile.
   
   BREAKING CHANGES: None - additive CSS using media queries
*/

/* ============================================
   DESKTOP LAYOUT (>1024px)
   Trading View style: Chart left, panels right
   ============================================ */

@media (min-width: 99999px) {
    /* Neutralized — desktop now uses the same single-column flow as mobile/PWA.
       All layout grids removed to prevent 2-column dashboard behaviour. */

    /* Hide mobile tabs */
    .mobile-tab-nav {
        display: none !important;
    }
}

/* ============================================
   TABLET & MOBILE (<1024px)
   Swipeable tab interface
   ============================================ */

@media (max-width: 99999px) {
    body {
        display: grid;
        grid-template-rows: auto auto 1fr auto;
        overflow: hidden;
    }

    /* Swipeable tab container */
    .tab-container {
        grid-row: 3;
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        scroll-behavior: smooth;
        scroll-snap-type: x mandatory;
        height: 100%;
        -webkit-overflow-scrolling: touch;
    }

    .tab-panel {
        flex: 0 0 100%;
        scroll-snap-align: start;
        overflow-y: auto;
        padding: 12px;
    }

    /* Tab navigation */
    .mobile-tab-nav {
        grid-row: 4;
        display: flex;
        gap: 0;
        border-top: 1px solid var(--border);
        background: var(--bg-secondary);
        padding: 0;
    }

    .mobile-tab-btn {
        flex: 1;
        padding: 12px 8px;
        border: none;
        background: transparent;
        color: var(--muted);
        font-size: 12px;
        font-weight: 600;
        cursor: pointer;
        border-bottom: 3px solid transparent;
        transition: all 0.2s ease;
        text-align: center;
    }

    .mobile-tab-btn.active {
        color: var(--accent);
        border-bottom-color: var(--accent);
    }

    .mobile-tab-btn:active {
        background: var(--bg-tertiary);
    }

    /* Show mobile tabs */
    .mobile-tab-nav {
        display: flex;
    }

    /* Keep trade/analysis cards visible in the current section-based layout */
    [data-section="chart"] .trade-scroll {
        display: block !important;
    }
    [data-section="chart"] #tradePrimaryGrid {
        display: grid !important;
        grid-template-columns: 1fr !important;
    }
    [data-section="chart"] #tradePrimaryGrid > .trade-card,
    [data-section="chart"] #emperorBrainAcc,
    [data-section="chart"] #botStatusCard,
    [data-section="levels"] #analysisAuxCards .trade-card,
    [data-section="levels"] #analysisAuxCards .acc-full {
        display: block !important;
    }

    /* Chart takes full width */
    .chart-area {
        width: 100%;
    }
}

/* ============================================
   TAB PANELS (Mobile)
   ============================================ */

.tab-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tab-panel.hidden {
    display: none;
}

/* AI Strategy Tab */
.tab-panel-ai {
    gap: 12px;
}

.tab-panel-ai .trade-card {
    display: flex;
    flex-direction: column;
}

/* Bot Status Tab */
.tab-panel-bot {
    gap: 12px;
}

.tab-panel-bot .trade-card {
    display: flex;
}

/* Timeline Tab */
.tab-panel-timeline {
    gap: 12px;
}

/* ============================================
   RESPONSIVE CARD IMPROVEMENTS
   ============================================ */

.trade-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-tertiary);
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.tc-hdr {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
}

.tc-hdr:hover {
    background: var(--bg-tertiary);
}

.tc-icon {
    font-size: 18px;
    flex: 0 0 auto;
}

.tc-title {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.tc-time, .tc-note {
    font-size: 11px;
    color: var(--muted);
    flex: 0 0 auto;
}

.tc-body {
    padding: 12px;
    font-size: 12px;
    color: var(--text-secondary);
    overflow-y: auto;
    max-height: 200px;
}

/* ============================================
   IMPROVED SPACING & ALIGNMENT
   ============================================ */

.acc-full {
    margin: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-tertiary);
    overflow: hidden;
}

.acc-full-hdr {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: var(--bg-secondary);
    border: none;
    cursor: pointer;
    width: 100%;
    text-align: left;
}

.acc-full-hdr:hover {
    background: var(--bg-tertiary);
}

.acc-icon {
    font-size: 16px;
    flex: 0 0 auto;
}

.acc-title {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.acc-note {
    font-size: 11px;
    color: var(--muted);
    padding: 2px 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.acc-chev {
    font-size: 12px;
    color: var(--muted);
    transition: transform 0.2s ease;
}

.acc-full-hdr.open .acc-chev {
    transform: rotate(-180deg);
}

.acc-body {
    padding: 12px;
    border-top: 1px solid var(--border);
    background: var(--bg-tertiary);
    max-height: 300px;
    overflow-y: auto;
}

.acc-body.hidden {
    display: none;
}

/* ============================================
   MOBILE IMPROVEMENTS
   ============================================ */

@media (max-width: 768px) {
    .v2-hero {
        padding: 12px;
        gap: 12px;
    }

    .mtf-align-bar {
        padding: 12px;
    }

    .mtf-align-pill {
        flex: 1;
        font-size: 11px;
        padding: 6px 4px;
    }

    .tc-hdr {
        padding: 10px;
        gap: 6px;
    }

    .tc-icon {
        font-size: 16px;
    }

    .tc-title {
        font-size: 12px;
    }

    .tc-body {
        font-size: 11px;
        padding: 10px;
    }

    /* Larger touch targets */
    .mobile-tab-btn {
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ============================================
   SMOOTH TRANSITIONS
   ============================================ */

* {
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

/* Disable transitions on scroll */
.scrolling * {
    transition: none !important;
}

/* ============================================
    DARK MODE (default) — variables from style.css
    ============================================ */

/* NOTE: Do NOT redefine :root here. style.css already defines all
   variables for both dark and light modes. Redefining them here
   breaks theme switching because these rules have equal specificity
   and load order becomes unpredictable. */

/* Ensure body uses theme variables */
body {
    background: var(--bg);
    color: var(--text);
}

/* Mobile-safe bottom padding for scrollable areas */
@media (max-width: 99999px) {
    .scroll-area,
    .trade-scroll,
    .chat-wrap,
    .school-panel,
    .news-scroll {
        padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 20px) !important;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

/* NOTE: .hidden is defined in style.css as .modal-bg.hidden { display: none; }
   Do NOT add a global .hidden here with !important — it overrides modal
   visibility logic and breaks the coin/settings modals. */

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.w-full {
    width: 100%;
}

.h-full {
    height: 100%;
}

.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }

.p-2 { padding: 8px; }
.p-3 { padding: 12px; }
.p-4 { padding: 16px; }

.rounded-sm { border-radius: 4px; }
.rounded { border-radius: 8px; }
.rounded-lg { border-radius: 12px; }
