/* ============================================
   LAYOUT STYLES
   ICT Analyzer Pro V29.24
============================================ */

/* Header */
.top-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0.4rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
    min-height: 45px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.logo {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-yellow);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.logo i {
    font-size: 1rem;
}

.market-time {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.live-indicator {
    width: 8px;
    height: 8px;
    background: var(--buy-green);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.perf-indicator {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    background: var(--bg-tertiary);
    border-radius: 4px;
    color: var(--text-muted);
    margin-left: 0.5rem;
    cursor: help;
}

.perf-indicator.good { color: var(--buy-green); }
.perf-indicator.warn { color: var(--accent-yellow); }
.perf-indicator.bad { color: var(--sell-red); }

.header-right {
    display: flex;
    gap: 0.3rem;
}

/* Stats Bar */
.stats-bar {
    display: none;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    grid-template-columns: repeat(6, 1fr);
    gap: 1rem;
    flex-shrink: 0;
}

.stats-bar.visible {
    display: grid;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.stat-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.stat-value.buy { color: var(--buy-green); }
.stat-value.sell { color: var(--sell-red); }

/* Main Layout V29.20: Panel on RIGHT, pushes chart */
.main-container {
    display: flex;
    flex-direction: row;
    direction: ltr !important;  /* Force LTR layout */
    height: calc(100vh - 44px); /* toolbar height; stats-bar is display:none by default */
    background: var(--bg-primary);
    overflow: hidden;
}

/* Center Panel - Chart on LEFT (shrinks when panel opens) */
.center-panel {
    flex: 1;
    min-width: 0;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    position: relative;
    overflow: hidden;
    order: 1;  /* First = LEFT */
    /* Smooth transition when panel opens/closes */
    transition: width 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
}

/* Right Panel Container - on RIGHT (pushes chart) */
.right-panel-container {
    display: flex;
    height: 100%;
    flex-shrink: 0;
    order: 2;  /* Second = RIGHT */
}

/* Right Panel - V29.20: Wider panel (340px) for better content visibility */
.right-panel {
    width: 340px;
    min-width: 340px;
    height: 100%;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    direction: rtl;  /* Keep RTL for Arabic text inside panel */
    /* Smooth width animation */
    transition: width 0.3s cubic-bezier(0.25, 0.1, 0.25, 1),
                min-width 0.3s cubic-bezier(0.25, 0.1, 0.25, 1),
                opacity 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
    opacity: 1;
}

.right-panel.collapsed {
    width: 0;
    min-width: 0;
    border-left: none;
    opacity: 0;
    overflow: hidden;
}

/* Panel Header */
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    min-height: 36px;
}

.panel-header-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-header-title i {
    color: var(--accent-yellow);
}

.panel-header-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    font-size: 0.9rem;
    transition: color 0.15s;
}

.panel-header-close:hover {
    color: var(--text-primary);
}

.panel-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.panel-title i {
    font-size: 0.75rem;
    color: var(--accent-yellow);
}

/* Panel Tab Content */
.panel-tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
}

.panel-tab-content.active {
    display: flex;
    flex-direction: column;
}

/* Legacy support */
.panel-tabs {
    display: none;
}

.panel-tab {
    display: none;
}

.panel-toggle.left {
    left: 0;
    border-radius: 0 6px 6px 0;
    border-left: none;
}

.panel-toggle.right {
    right: 0;
    border-radius: 6px 0 0 6px;
    border-right: none;
}

/* ============================================
   RESPONSIVE DESIGN V2.1
   Mobile-first approach with progressive enhancement
============================================ */

/* Mobile Menu Toggle Button */
.mobile-menu-toggle {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    line-height: 1;
}

/* Loading States */
.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-yellow);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* @keyframes spin defined in base.css */

/* Skeleton Loading */
.skeleton {
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-secondary) 50%, var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Error State */
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
}

.error-state i {
    font-size: 2rem;
    color: var(--sell-red);
    margin-bottom: 1rem;
}

.retry-button {
    margin-top: 1rem;
    padding: 0.5rem 1rem;
    background: var(--accent-yellow);
    color: var(--bg-primary);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: opacity 0.2s;
}

.retry-button:hover {
    opacity: 0.9;
}

/* V31.0: Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(var(--bg-primary-rgb, 19, 23, 34), 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    z-index: 50;
    backdrop-filter: blur(2px);
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-yellow);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* V31.0: Error Content Styling */
.error-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.error-content p {
    margin: 0;
    font-size: 0.9rem;
}

/* V31.0: Skeleton Rows for Tables/Lists */
.skeleton-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.skeleton-cell {
    height: 16px;
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-secondary) 50%, var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

/* V31.0: Button Loading State */
button.loading {
    opacity: 0.7;
    pointer-events: none;
}

button.loading::after {
    content: none;
}

button.loading .fa-spinner {
    animation: spin 0.8s linear infinite;
}

/* Desktop Large (1400px+) */
@media (min-width: 1400px) {
    .right-panel {
        width: 380px;
        min-width: 380px;
    }
}

/* Desktop (1200px - 1400px) */
@media (max-width: 1400px) {
    .right-panel {
        width: 320px;
        min-width: 320px;
    }

    .stats-bar {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* Tablet Landscape (992px - 1200px) */
@media (max-width: 1200px) {
    .stats-bar {
        grid-template-columns: repeat(3, 1fr);
    }

    .right-panel {
        width: 300px;
        min-width: 300px;
    }

    .header-left {
        gap: 1rem;
    }

    .logo {
        font-size: 1rem;
    }
}

/* Tablet Portrait (768px - 992px) */
@media (max-width: 992px) {
    .mobile-menu-toggle {
        display: block;
    }

    .main-container {
        flex-direction: column;
    }

    .center-panel {
        order: 1;
        height: 50vh;
        min-height: 300px;
    }

    .right-panel-container {
        order: 2;
        width: 100%;
        height: 50vh;
    }

    .right-panel {
        width: 100%;
        min-width: 100%;
        border-left: none;
        border-top: 1px solid var(--border-color);
    }

    .right-panel.collapsed {
        height: 0;
        min-height: 0;
    }

    .stats-bar {
        grid-template-columns: repeat(3, 1fr);
        padding: 0.4rem 0.75rem;
    }

    .stat-value {
        font-size: 0.9rem;
    }

    .header-right .btn-icon span {
        display: none;
    }
}

/* Mobile (480px - 768px) */
@media (max-width: 768px) {
    .top-header {
        padding: 0.3rem 0.75rem;
        min-height: 40px;
    }

    .header-left {
        gap: 0.5rem;
    }

    .logo {
        font-size: 0.9rem;
    }

    .logo span:not(.logo-icon) {
        display: none;
    }

    .market-time {
        display: none;
    }

    .perf-indicator {
        display: none;
    }

    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .stat-label {
        font-size: 0.6rem;
    }

    .stat-value {
        font-size: 0.85rem;
    }

    .center-panel {
        height: 40vh;
        min-height: 250px;
    }

    .right-panel-container {
        height: 60vh;
    }

    .panel-header {
        padding: 0.4rem 0.5rem;
    }

    .panel-tab-content {
        padding: 0.5rem;
    }

    /* Touch-friendly buttons */
    .btn-icon {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Mobile Small (< 480px) */
@media (max-width: 480px) {
    .top-header {
        padding: 0.25rem 0.5rem;
    }

    .logo {
        font-size: 0.85rem;
    }

    .header-right {
        gap: 0.2rem;
    }

    .stats-bar {
        grid-template-columns: 1fr 1fr;
        gap: 0.4rem;
        padding: 0.3rem 0.5rem;
    }

    .stat-item {
        padding: 0.2rem;
    }

    .center-panel {
        height: 35vh;
        min-height: 200px;
    }

    .right-panel-container {
        height: 65vh;
    }

    .panel-header-title {
        font-size: 0.8rem;
    }
}

/* Landscape Mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .main-container {
        flex-direction: row;
    }

    .center-panel {
        height: 100%;
        width: 60%;
        order: 1;
    }

    .right-panel-container {
        height: 100%;
        width: 40%;
        order: 2;
    }

    .right-panel {
        width: 100%;
        border-left: 1px solid var(--border-color);
        border-top: none;
    }

    .stats-bar.visible {
        display: none;
    }
}

/* Print Styles */
@media print {
    .top-header,
    .stats-bar,
    .right-panel-container,
    .mobile-menu-toggle {
        display: none !important;
    }

    .main-container {
        height: auto;
    }

    .center-panel {
        height: auto;
        width: 100%;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn-icon,
    .panel-header-close,
    .retry-button {
        min-width: 44px;
        min-height: 44px;
    }

    /* Disable hover effects on touch devices */
    .btn-icon:hover,
    .panel-header-close:hover {
        background: transparent;
    }

    .btn-icon:active,
    .panel-header-close:active {
        background: var(--bg-tertiary);
    }
}

/* ============================================
   MOBILE MENU OVERLAY
============================================ */

/* Mobile Menu Overlay Background */
.mobile-menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-menu-overlay.active {
    display: block;
    opacity: 1;
}

/* Mobile Menu Button Active State */
.mobile-menu-toggle.active {
    background: var(--accent-yellow);
    color: var(--bg-primary);
}

.mobile-menu-toggle.active i {
    transform: rotate(90deg);
}

.mobile-menu-toggle i {
    transition: transform 0.3s ease;
}

/* Mobile Visible States */
@media (max-width: 992px) {
    /* Right panel visible on mobile when toggled */
    .right-panel:not(.collapsed) {
        position: fixed;
        right: 0;
        top: 44px;
        height: calc(100vh - 44px);
        width: 300px;
        max-width: 100vw;
        z-index: 998;
        animation: slideInRight 0.3s ease;
    }

    /* Body scroll lock when menu is open */
    body.mobile-menu-open {
        overflow: hidden;
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Ensure proper z-index stacking */
.chart-toolbar {
    z-index: 100;
}

/* Mobile menu toggle positioning */
@media (max-width: 992px) {
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        left: 10px;
        top: 50%;
        transform: translateY(-50%);
        z-index: 101;
    }

    .toolbar-drag-zone {
        padding-left: 50px; /* Make room for mobile menu button */
    }
}
