/* ===========================================================================
   APP SHELL - topbar + sidebar + content
   =========================================================================== */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
}

/* ─── TOPBAR ─────────────────────────────────────────────────────────────── */
.topbar {
    position: relative;
    z-index: 50;
    display: flex;
    align-items: center;
    height: var(--topbar-h);
    padding: 0 20px 0 0;
    background: var(--glass);
    backdrop-filter: blur(28px) saturate(1.9);
    -webkit-backdrop-filter: blur(28px) saturate(1.9);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 0;
    box-shadow:
        0 1px 0 rgba(124,110,248,0.08),
        0 6px 40px rgba(0,0,0,0.5),
        inset 0 1px 0 rgba(255,255,255,0.04);
}

/* Subtle animated topbar accent line */
.topbar::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg,
        transparent 0%,
        rgba(124,110,248,0.5) 20%,
        rgba(34,211,238,0.4) 50%,
        rgba(124,110,248,0.3) 80%,
        transparent 100%
    );
    animation: topbar-shimmer 6s ease-in-out infinite;
    pointer-events: none;
}
@keyframes topbar-shimmer {
    0%, 100% { opacity: 0.5; }
    50%       { opacity: 1; }
}

/* Hamburger / menu toggle for mobile */
.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    border-radius: var(--r-sm);
    margin-left: 8px;
    transition: color var(--t), background var(--t);
    flex-shrink: 0;
}
.menu-toggle:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.menu-toggle i { width: 18px; height: 18px; }

/* Hidden by default on desktop */
.mobile-profile, .mobile-only-menu { display: none; }

/* Brand sits inside topbar, aligned to sidebar width */
.topbar-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    width: var(--sidebar-w);
    flex-shrink: 0;
    padding: 0 18px;
    border-right: 1px solid var(--border);
    height: 100%;
    position: relative;
}

.brand-mark {
    width: 34px;
    height: 34px;
    min-width: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 4px 20px var(--accent-glow),
        0 0 0 1px rgba(124,110,248,0.2),
        0 0 0 4px rgba(124,110,248,0.05);
    border-radius: 10px;
    flex-shrink: 0;
    animation: brand-breathe 4.5s ease-in-out infinite;
    transition: transform var(--t-spring);
}
.brand-mark:hover { transform: scale(1.08) rotate(-3deg); }

@keyframes brand-breathe {
    0%, 100% {
        box-shadow: 0 4px 20px var(--accent-glow), 0 0 0 1px rgba(124,110,248,0.2), 0 0 0 4px rgba(124,110,248,0.05);
        filter: brightness(1);
    }
    50% {
        box-shadow: 0 6px 35px rgba(124,110,248,0.6), 0 0 0 1px rgba(124,110,248,0.38), 0 0 0 8px rgba(124,110,248,0.07);
        filter: brightness(1.18);
    }
}

.brand-mark svg {
    width: 34px;
    height: 34px;
    display: block;
}

.brand-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    overflow: hidden;
}

.brand-name {
    font-size: 11px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: 2.2px;
    text-transform: uppercase;
    line-height: 1;
    white-space: nowrap;
}
.brand-name em {
    color: var(--accent-3);
    font-style: normal;
    text-shadow: 0 0 16px rgba(124,110,248,0.6);
}

.brand-sub {
    font-size: 9px;
    font-weight: 600;
    color: var(--dim);
    letter-spacing: 0.8px;
    text-transform: uppercase;
    white-space: nowrap;
}

/* Market status indicator */
.market-status-light {
    width: 7px; height: 7px;
    border-radius: 50%;
    margin-left: 4px;
    flex-shrink: 0;
}
.market-status-light.market-open {
    background: var(--profit);
    box-shadow: 0 0 0 3px rgba(15,218,140,0.18);
    animation: market-pulse 2.8s ease-in-out infinite;
}
.market-status-light.market-closed {
    background: var(--muted);
    box-shadow: none;
}
@keyframes market-pulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(15,218,140,0.18); }
    50%       { box-shadow: 0 0 0 6px rgba(15,218,140,0.05); }
}

/* Topbar right controls */
.topbar-controls {
    display: flex;
    align-items: center;
    gap: 18px;
    margin-left: auto;
    flex-shrink: 1;
    min-width: 0;
}

/* ── WS Status Pill: 3 states ────────────────────────────────────────────── */
.live-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 9.5px;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    transition: color 0.3s ease;
    color: var(--profit);
    background: var(--profit-dim);
    border: 1px solid rgba(15,218,140,0.18);
    padding: 4px 10px;
    border-radius: 20px;
}

.live-dot {
    width: 5px; height: 5px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
    transition: background 0.3s;
}

.live-pill.ws-live { color: var(--profit); background: var(--profit-dim); border-color: rgba(15,218,140,0.2); }
.live-pill.ws-live .live-dot { animation: live-pulse 2.4s ease-in-out infinite; }

.live-pill.ws-reconnecting { color: var(--warn); background: var(--warn-dim); border-color: rgba(245,158,11,0.2); }
.live-pill.ws-reconnecting .live-dot { animation: live-pulse-warn 1.6s ease-in-out infinite; }

.live-pill.ws-offline { color: var(--loss); background: var(--loss-dim); border-color: rgba(240,80,78,0.2); }
.live-pill.ws-offline .live-dot { animation: none; }

@keyframes live-pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 transparent; }
    50%       { opacity: 0.55; box-shadow: 0 0 0 5px var(--profit-dim); }
}
@keyframes live-pulse-warn {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 transparent; }
    50%       { opacity: 0.4; box-shadow: 0 0 0 5px var(--warn-dim); }
}

.utc-clock {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    letter-spacing: 1px;
    white-space: nowrap;
    font-feature-settings: "tnum";
    text-shadow: 0 0 14px rgba(124,110,248,0.18);
}

/* Profile wrap */
.profile-wrap { position: relative; }

.profile-btn {
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    background: var(--elevated);
    border: 1px solid var(--border-md);
    border-radius: 50%;
    color: var(--muted);
    cursor: pointer;
    transition: all var(--t);
}
.profile-btn:hover {
    color: var(--accent-text);
    border-color: var(--accent);
    background: var(--accent-dim);
    box-shadow: 0 0 16px rgba(124,110,248,0.2);
}

.profile-dropdown {
    display: none;
    position: absolute;
    right: 0; top: calc(100% + 8px);
    background: var(--elevated-2);
    border: 1px solid var(--border-md);
    border-radius: var(--r-lg);
    min-width: 210px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04);
    z-index: 100;
    animation: dropIn 0.2s var(--ease-out-back);
    overflow: hidden;
}
.profile-dropdown.open { display: block; }
@keyframes dropIn {
    from { opacity: 0; transform: translateY(-8px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.profile-header {
    display: flex; align-items: center; gap: 12px;
    padding: 16px;
    background: linear-gradient(135deg, rgba(124,110,248,0.08) 0%, transparent 100%);
    border-bottom: 1px solid var(--border);
}
.profile-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--accent-dim);
    border: 1px solid rgba(124,110,248,0.3);
    display: flex; align-items: center; justify-content: center;
    color: var(--accent-text);
    flex-shrink: 0;
}
.profile-name { font-size: 14px; font-weight: 700; color: var(--text); display: block; }
.profile-role { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; display: block; margin-top: 2px; }


/* ===========================================================================
   BODY AREA (sidebar + main content)
   =========================================================================== */
.body-area {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}


/* ─── SIDEBAR ─────────────────────────────────────────────────────────────── */
.sidebar {
    white-space: nowrap;
    will-change: width, transform;
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform var(--t-slow), width var(--t-slow);
    z-index: 40;
    box-shadow: 2px 0 24px rgba(0,0,0,0.3);
}

.sidebar-nav {
    flex: 1;
    padding: 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 13px;
    border-radius: var(--r-md);
    background: none;
    border: none;
    color: var(--muted);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.22s ease, color 0.22s ease, transform 0.18s var(--ease-out-back), box-shadow 0.22s ease;
    width: 100%;
    text-align: left;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

/* Hover shimmer sweep */
.nav-item::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(124,110,248,0.1) 50%, transparent 100%);
    transform: translateX(-100%);
    transition: transform 0.55s ease;
    pointer-events: none;
    border-radius: inherit;
}
.nav-item:hover::after { transform: translateX(100%); }

.nav-item i {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
    transition: color 0.22s ease, transform 0.25s var(--ease-out-back), filter 0.22s;
}

.nav-item .nav-label {
    flex: 1;
    transition: opacity var(--t-slow), transform 0.2s ease;
}

.nav-item:hover {
    background: rgba(124,110,248,0.08);
    color: var(--text-2);
    transform: translateX(3px);
}
.nav-item:hover i { transform: scale(1.18); color: var(--accent-3); }

.nav-item:active {
    transform: translateX(1px) scale(0.98);
    transition-duration: 0.08s;
}

.nav-item.active {
    background: linear-gradient(135deg, rgba(124,110,248,0.22) 0%, rgba(124,110,248,0.09) 100%);
    color: var(--accent-text);
    box-shadow: inset 0 0 0 1px rgba(124,110,248,0.25), 0 2px 18px rgba(124,110,248,0.14);
}

.nav-item.active i {
    color: var(--accent);
    filter: drop-shadow(0 0 7px rgba(124,110,248,0.75));
}

/* Active indicator bar */
.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0; top: 20%; bottom: 20%;
    width: 3px;
    background: linear-gradient(180deg, var(--accent-3), var(--accent-2));
    border-radius: 0 3px 3px 0;
    box-shadow: 0 0 14px rgba(124,110,248,0.9);
    animation: active-bar-glow 2s ease-in-out infinite;
}

@keyframes active-bar-glow {
    0%, 100% { box-shadow: 0 0 8px rgba(124,110,248,0.65); opacity: 1; }
    50%      { box-shadow: 0 0 18px rgba(124,110,248,1); opacity: 0.85; }
}

/* Staggered nav entrance animation */
.sidebar-nav .nav-item { animation: navSlideIn 0.4s var(--ease-out-expo) both; }
.nav-item:nth-child(1) { animation-delay: 0.05s; }
.nav-item:nth-child(2) { animation-delay: 0.1s; }
.nav-item:nth-child(3) { animation-delay: 0.15s; }
.nav-item:nth-child(4) { animation-delay: 0.2s; }
.nav-item:nth-child(5) { animation-delay: 0.25s; }
.nav-item:nth-child(6) { animation-delay: 0.3s; }

@keyframes navSlideIn {
    from { opacity: 0; transform: translateX(-14px); }
    to   { opacity: 1; transform: translateX(0); }
}


.sidebar-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-md), transparent);
    margin: 10px 10px;
}

.sidebar-section-label {
    font-size: 9px;
    font-weight: 800;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 1.6px;
    padding: 8px 13px 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.sidebar-section-label::before {
    content: '';
    width: 14px; height: 1px;
    background: var(--border-md);
    flex-shrink: 0;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    z-index: 39;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}


/* ─── MAIN CONTENT ─────────────────────────────────────────────────────────── */
.main-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 26px 30px 60px;
}


/* ─── PANELS ─────────────────────────────────────────────────────────────── */
.panel { display: none; }
.panel.active {
    display: block;
    animation: panelReveal 0.45s var(--ease-out-expo);
}

@keyframes panelReveal {
    from { opacity: 0; transform: translateY(12px) scale(0.997); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Staggered children reveal inside panels */
.panel.active > .panel-header    { animation: childReveal 0.35s 0.05s var(--ease-out-expo) both; }
.panel.active > .cards-grid,
.panel.active > .exec-positions-layout,
.panel.active > .hist-filters,
.panel.active > .tbl-wrap,
.panel.active > .news-container   { animation: childReveal 0.4s 0.12s var(--ease-out-expo) both; }
.panel.active > .hist-summary     { animation: childReveal 0.4s 0.18s var(--ease-out-expo) both; }

@keyframes childReveal {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Panel header */
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 26px;
    gap: 12px;
    flex-wrap: wrap;
}

.panel-title-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.panel-title {
    font-size: 24px;
    font-weight: 900;
    color: var(--text);
    letter-spacing: -0.6px;
    line-height: 1.15;
    background: linear-gradient(130deg, var(--text) 20%, var(--accent-3) 75%, var(--cyan) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.panel-sub {
    font-size: 12.5px;
    color: var(--muted);
    letter-spacing: 0.1px;
}

/* ===========================================================================
   MOBILE OPTIMIZATIONS
   =========================================================================== */
@media (max-width: 768px) {
    #charts_panel .panel-header {
        flex-direction: column;
        align-items: stretch;
        margin-bottom: 12px;
    }
    #charts_panel .chart-controls {
        width: 100%;
        justify-content: space-between;
    }
    #charts_panel .chart-select {
        flex: 1;
        font-size: 16px; /* Prevents auto-zoom on mobile browsers */
        height: 48px; /* Touch-friendly target size */
    }
    #chart_legend {
        font-size: 11px !important;
        padding: 4px 6px !important;
        left: 8px !important;
        top: 8px !important;
    }
    
    /* Force exactly one screen height on mobile to prevent scrolling */
    .main-content:has(#charts_panel.active) {
        padding: 12px !important;
        overflow: hidden !important; 
    }
    #charts_panel.active {
        display: flex !important;
        flex-direction: column !important;
        height: calc(100dvh - var(--topbar-h) - 24px) !important;
    }
    #tv_chart_container {
        flex: 1 !important;
        min-height: 0 !important;
        height: auto !important;
    }
}
