/**
 * Multi-Chart Layout Styles
 *
 * Defines layouts for 1, 2, and 4 chart configurations
 * Responsive behavior for mobile/tablet devices
 */

/* Hide old singleton oscillator panel when using LayoutManager */
.layout-single .indicators-container,
.layout-dual-horizontal .indicators-container,
.layout-dual-vertical .indicators-container,
.layout-quad .indicators-container {
    display: none !important;
}

/* Chart Wrapper - Base Container */
.chart-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    gap: 2px;
    background-color: #0d0d0d;
    position: relative;
}

/* Chart Pane - Individual Chart Container */
.chart-pane {
    display: flex;
    flex-direction: column;
    background-color: #1e222d;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    min-height: 0; /* Important for flex children */
    border: 2px solid transparent;
    transition: border-color 0.2s ease;
    cursor: pointer;
}

/* Active chart indicator */
.chart-pane.active-chart {
    border-color: #2962ff;
}

/* Symbol Label - Top Left Corner */
.chart-symbol-label {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 10;
    background-color: rgba(30, 34, 45, 0.8);
    backdrop-filter: blur(4px);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    color: #d1d4dc;
    border: 1px solid rgba(43, 43, 67, 0.5);
    pointer-events: none;
    user-select: none;
}

.chart-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.chart-main {
    flex: 1;
    min-height: 0;
    position: relative;
}

/* Oscillator Panel Styling */
.indicator-panel {
    display: flex;
    flex-direction: column;
    background-color: #1e222d;
    border-top: 1px solid #2b2b43;
}

.indicator-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px;
    background-color: #252935;
    border-bottom: 1px solid #2b2b43;
}

.indicator-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #d1d4dc;
}

.oscillator-tabs {
    display: flex;
    gap: 2px;
}

.oscillator-tab {
    background: transparent;
    border: none;
    padding: 4px 8px;
    color: #787b86;
    cursor: pointer;
    border-radius: 3px;
    font-size: 11px;
    transition: all 0.2s ease;
}

.oscillator-tab:hover {
    background-color: #2a2e39;
    color: #d1d4dc;
}

.oscillator-tab.active {
    background-color: #2962ff;
    color: #ffffff;
}

/* Oscillator Controls (Gear & Eye icons) */
.oscillator-controls {
    display: flex;
    align-items: center;
    gap: 8px; /* Reduced gap between buttons */
}

.indicator-control-btn {
    background: #1e222d;
    border: 1px solid #2a2e39;
    color: #787b86;
    padding: 6px 8px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 28px;
}

.indicator-control-btn:hover {
    background-color: #2a2e39;
    border-color: #363a45;
    color: #d1d4dc;
    transform: translateY(-1px);
}

.indicator-control-btn:active {
    transform: translateY(0);
    background-color: #252930;
}

.indicator-control-btn svg {
    width: 14px;
    height: 14px;
}

/* Minimized state for oscillator panel */
.indicator-panel.minimized .indicator-chart-wrapper {
    display: none;
}

.indicator-panel.minimized {
    height: auto !important;
    min-height: auto !important;
}

/* Change eye icon to "eye-off" when minimized */
.indicator-panel.minimized .indicator-toggle-btn svg {
    opacity: 0.5;
}

.indicator-chart-wrapper {
    flex: 1;
    min-height: 0;
    position: relative;
    transition: all 0.3s ease;
}

.chart-oscillator {
    width: 100%;
    height: 100%;
    position: relative;
}

/* ===================
   SINGLE CHART LAYOUT
   =================== */
.layout-single {
    flex-direction: column;
}

.layout-single .chart-pane {
    width: 100%;
    height: 100%;
}

/* ===================
   DUAL HORIZONTAL LAYOUT (2 charts side-by-side)
   =================== */
.layout-dual-horizontal {
    flex-direction: row;
}

.layout-dual-horizontal .chart-pane {
    width: 50%;
    height: 100%;
}

/* ===================
   DUAL VERTICAL LAYOUT (2 charts stacked)
   =================== */
.layout-dual-vertical {
    flex-direction: column;
}

.layout-dual-vertical .chart-pane {
    width: 100%;
    height: 50%;
}

/* ===================
   QUAD LAYOUT (4 charts in 2x2 grid)
   =================== */
.layout-quad {
    flex-direction: row;
    flex-wrap: wrap;
}

.layout-quad .chart-pane {
    width: calc(50% - 1px);
    height: calc(50% - 1px);
}

/* Adjust oscillator panel height in multi-chart layouts */
.layout-single .indicator-panel {
    height: 150px;
    min-height: 150px;
}

.layout-dual-horizontal .indicator-panel,
.layout-dual-vertical .indicator-panel {
    height: 120px;
    min-height: 120px;
}

.layout-quad .indicator-panel {
    height: 100px;
    min-height: 100px;
}

/* ===================
   LAYOUT SWITCHER BUTTONS
   =================== */
.layout-switcher {
    display: flex;
    gap: 4px;
    padding: 4px;
    background-color: #2a2e39;
    border-radius: 6px;
}

.layout-btn {
    background: transparent;
    border: none;
    padding: 6px 8px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #d1d4dc;
}

.layout-btn:hover {
    background-color: #363a45;
}

.layout-btn.active {
    background-color: #2962ff;
    color: #ffffff;
}

.layout-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* ===================
   RESPONSIVE BEHAVIOR
   =================== */

/* Tablet (768px - 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
    /* Dual horizontal becomes vertical on tablet */
    .layout-dual-horizontal {
        flex-direction: column;
    }

    .layout-dual-horizontal .chart-pane {
        width: 100%;
        height: 50%;
    }

    /* Quad becomes 2 vertical on tablet */
    .layout-quad {
        flex-direction: column;
    }

    .layout-quad .chart-pane {
        width: 100%;
        height: 50%;
    }

    .layout-quad .chart-pane:nth-child(3),
    .layout-quad .chart-pane:nth-child(4) {
        display: none; /* Hide 3rd and 4th charts */
    }
}

/* Mobile Portrait (up to 768px) */
@media (max-width: 768px) {
    /* All dual layouts become stacked vertically */
    .layout-dual-horizontal,
    .layout-dual-vertical {
        flex-direction: column;
    }

    .layout-dual-horizontal .chart-pane,
    .layout-dual-vertical .chart-pane {
        width: 100%;
        height: 50%;
    }

    /* Quad becomes 2 stacked charts */
    .layout-quad {
        flex-direction: column;
    }

    .layout-quad .chart-pane {
        width: 100%;
        height: 50%;
    }

    .layout-quad .chart-pane:nth-child(3),
    .layout-quad .chart-pane:nth-child(4) {
        display: none; /* Hide 3rd and 4th charts */
    }

    /* Oscillator height on mobile - increased for better visibility */
    .indicator-panel {
        height: 120px !important;
        min-height: 120px !important;
    }

    /* Simplify oscillator tabs on mobile */
    .oscillator-tab span {
        font-size: 10px;
    }

    .indicator-title {
        font-size: 10px;
    }

    /* Hide layout switcher on very small screens */
    @media (max-width: 480px) {
        .layout-switcher {
            display: none;
        }
    }
}

/* Mobile Landscape */
@media (max-width: 768px) and (orientation: landscape) {
    /* 2 charts side-by-side in landscape */
    .layout-dual-horizontal,
    .layout-dual-vertical,
    .layout-quad {
        flex-direction: row;
    }

    .layout-dual-horizontal .chart-pane,
    .layout-dual-vertical .chart-pane,
    .layout-quad .chart-pane {
        width: 50%;
        height: 100%;
    }

    .layout-quad .chart-pane:nth-child(3),
    .layout-quad .chart-pane:nth-child(4) {
        display: none;
    }

    /* Smaller oscillator in landscape */
    .indicator-panel {
        height: 60px !important;
        min-height: 60px !important;
    }

    /* Hide oscillator title text on small landscape */
    .indicator-title > span {
        display: none;
    }
}

/* Very Small Screens (320px - 480px) */
@media (max-width: 480px) {
    /* Allow 2-chart mode, but force single chart for quad layout only */

    /* Dual layouts: keep 2 charts stacked vertically */
    .layout-dual-horizontal,
    .layout-dual-vertical {
        flex-direction: column;
    }

    .layout-dual-horizontal .chart-pane,
    .layout-dual-vertical .chart-pane {
        width: 100%;
        height: 50%;
    }

    /* Quad layout: force single chart on very small screens */
    .layout-quad {
        flex-direction: column;
    }

    .layout-quad .chart-pane:not(:first-child) {
        display: none;
    }

    .layout-quad .chart-pane:first-child {
        width: 100%;
        height: 100%;
    }
}

/* ===================
   CHART PANE TOOLBAR (For future enhancements)
   =================== */
.chart-pane-toolbar {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.chart-pane:hover .chart-pane-toolbar {
    opacity: 1;
}

.chart-pane-btn {
    background-color: rgba(30, 34, 45, 0.9);
    border: 1px solid #2b2b43;
    color: #d1d4dc;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.chart-pane-btn:hover {
    background-color: #363a45;
    border-color: #2962ff;
}

/* ===================
   LOADING STATE
   =================== */
.chart-pane.loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(30, 34, 45, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.chart-pane.loading::after {
    content: 'Loading...';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #d1d4dc;
    font-size: 14px;
    z-index: 101;
}

/* ===================
   PRINT STYLES
   =================== */
@media print {
    .layout-switcher {
        display: none;
    }

    .chart-pane-toolbar {
        display: none;
    }

    .chart-wrapper {
        gap: 0;
    }

    .chart-pane {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}

/* ===================
   OSCILLATOR SETTINGS MODAL
   =================== */
.oscillator-settings-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10001;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.oscillator-settings-modal.active {
    display: flex;
}

.oscillator-settings-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: modalSlideIn 0.3s ease;
    display: flex;
    flex-direction: column;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.oscillator-settings-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    background: var(--bg-secondary);
}

.oscillator-settings-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.oscillator-modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.oscillator-modal-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

.oscillator-settings-body {
    padding: 1.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
}

.oscillator-setting-row {
    display: grid;
    grid-template-columns: 140px 1fr;
    align-items: center;
    margin-bottom: 1rem;
    gap: 1rem;
}

.oscillator-setting-row label {
    font-size: 0.813rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.oscillator-setting-row input[type="number"],
.oscillator-setting-row input[type="text"],
.oscillator-setting-row select {
    padding: 0.625rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: all 0.2s;
}

.oscillator-setting-row input[type="number"]:hover,
.oscillator-setting-row input[type="text"]:hover,
.oscillator-setting-row select:hover {
    border-color: var(--accent-primary);
}

.oscillator-setting-row input[type="number"]:focus,
.oscillator-setting-row input[type="text"]:focus,
.oscillator-setting-row select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(41, 98, 255, 0.1);
}

.oscillator-setting-row input[type="color"] {
    width: 100%;
    height: 40px;
    padding: 2px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.oscillator-setting-row input[type="color"]:hover {
    border-color: var(--accent-primary);
}

.oscillator-setting-divider {
    height: 1px;
    background: var(--border-color);
    margin: 1.25rem 0;
}

.oscillator-settings-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    background: var(--bg-secondary);
}

.oscillator-btn-primary,
.oscillator-btn-secondary {
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.oscillator-btn-primary {
    background: var(--accent-primary);
    color: white;
}

.oscillator-btn-primary:hover {
    background: var(--accent-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(41, 98, 255, 0.3);
}

.oscillator-btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.oscillator-btn-secondary:hover {
    background: var(--border-color);
    transform: translateY(-1px);
}

/* Mobile responsive */
@media (max-width: 768px) {
    /* Larger touch targets for mobile */
    .indicator-control-btn {
        padding: 8px 10px;
        min-width: 40px;
        height: 36px;
    }

    .indicator-control-btn svg {
        width: 16px;
        height: 16px;
    }

    .oscillator-controls {
        gap: 6px;
    }

    .oscillator-settings-modal {
        padding: 0;
        align-items: flex-start;
    }

    .oscillator-settings-content {
        max-height: 100vh;
        border-radius: 0;
        height: 100vh;
    }

    .oscillator-settings-body {
        padding: 1rem;
    }

    .oscillator-setting-row {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .oscillator-settings-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 1rem;
    }
}
