/* ============================================
   Trader UI Layout Styles
   Chart-first responsive layout for indicator pages
   ============================================ */

/* ============================================
   Page Layout - Chart First
   ============================================ */

.indicator-page-layout {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 200px); /* Account for header/footer */
}

/* Indicator Header - Minimal */
.indicator-header {
    padding: 1.5rem 0 1rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.indicator-header h1 {
    margin: 0;
    font-size: 2rem;
    font-weight: 700;
}

.indicator-subtitle {
    color: var(--muted);
    margin: 0.5rem 0 0;
    font-size: 1rem;
    flex-basis: 100%;
}

.btn-info {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: transparent;
    border: 2px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-info:hover {
    background: var(--card);
    border-color: var(--muted);
    transform: translateY(-1px);
}

/* Main Workspace - Two Column on Desktop */
.workspace-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    flex: 1;
    position: relative;
}

@media (min-width: 1024px) {
    .workspace-container {
        grid-template-columns: 1fr 320px;
        gap: 1.5rem;
        align-items: start; /* Align both columns at the top */
    }
    
    .workspace-container.settings-collapsed {
        grid-template-columns: 1fr 0;
    }
    
    /* When there's no settings panel (non-optimizable indicators), make chart full width */
    .workspace-container.no-settings-panel {
        grid-template-columns: 1fr;
        gap: 0;
    }
    
    /* Hide settings panel for non-optimizable indicators */
    .workspace-container.no-settings-panel .settings-panel {
        display: none;
    }
}

/* Chart Workspace */
.chart-workspace {
    min-width: 0; /* Prevent grid blowout */
    position: relative;
}

.chart-container {
    border-radius: 8px;
    overflow: hidden;
    min-height: 500px;
    margin-bottom: 1rem;
}

/* Comparison Chips */
.comparison-chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    padding: 0.5rem 0;
}

.comparison-chips-container h4 {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-basis: 100%;
    margin-bottom: 0.5rem;
}

.comparison-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.9375rem;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px var(--shadow-color-soft, rgba(0, 0, 0, 0.1));
    animation: slideInScale 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.comparison-chip:hover {
    border-color: var(--brand);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(var(--brand-rgb), 0.2);
}

.comparison-color {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px var(--comparison-color-outline, rgba(255, 255, 255, 0.2));
}

[data-theme="light"] .comparison-color {
    --comparison-color-outline: rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] .comparison-color {
    --comparison-color-outline: rgba(255, 255, 255, 0.2);
}
.comparison-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text);
    line-height: 1.4;
}

.btn-remove-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--muted);
    cursor: pointer;
    padding: 0;
    margin-left: 0.25rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-remove-chip:hover {
    background: var(--down);
    color: white;
    transform: scale(1.1);
}

.btn-remove-chip:active {
    transform: scale(0.95);
}

/* Chart Actions */
.chart-actions {
    margin-top: 1.5rem;
    display: flex;
    justify-content: flex-end;
}

.btn-export {
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.75rem 1.5rem;
    background: var(--brand);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.btn-export:hover {
    background: var(--link-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.btn-export:active {
    transform: translateY(0);
}

/* ============================================
   Settings Panel - Collapsible Sidebar
   ============================================ */

.settings-panel {
    position: relative;
    background: var(--card);
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (max-width: 1023px) {
    .settings-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 90%;
        max-width: 400px;
        z-index: 1000;
        transform: translateX(100%);
        border-radius: 0;
        margin: 0;
    }
    
    .settings-panel.open {
        transform: translateX(0);
    }
}

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

.settings-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.btn-toggle-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-toggle-panel:hover {
    background: var(--bg);
    border-color: var(--brand);
    color: var(--brand);
}

@media (max-width: 1023px) {
    .btn-toggle-panel {
        display: none; /* Hide on mobile, use backdrop instead */
    }
}

.settings-content {
    padding: 1rem;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

@media (max-width: 1023px) {
    .settings-content {
        max-height: calc(100vh - 120px);
    }
}

/* Settings Backdrop (Mobile) */
.settings-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.settings-backdrop.active {
    display: block;
    opacity: 1;
}

/* Mobile: Show settings toggle button */
@media (max-width: 1023px) {
    .btn-open-settings-mobile {
        position: fixed;
        bottom: 20px;
        right: 20px;
        display: flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.75rem 1.25rem;
        background: var(--brand);
        border: none;
        border-radius: 50px;
        color: white;
        font-size: 0.9375rem;
        font-weight: 600;
        cursor: pointer;
        z-index: 900;
        box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
        transition: all 0.2s ease;
    }
    
    .btn-open-settings-mobile:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 16px rgba(59, 130, 246, 0.5);
    }
}

/* Desktop: Hide mobile settings button */
@media (min-width: 1024px) {
    .btn-open-settings-mobile {
        display: none;
    }
}

/* ============================================
   Export Drawer - Bottom Sheet
   ============================================ */

.export-drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 2000;
    display: none;
}

.export-drawer.open {
    display: block;
}

.export-drawer-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.export-drawer-content {
    position: relative;
    background: var(--card);
    border-radius: 16px 16px 0 0;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (min-width: 768px) {
    .export-drawer-content {
        max-height: 70vh;
    }
}

.export-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 1.5rem 1rem;
    border-bottom: 1px solid var(--border);
}

.export-drawer-header h2 {
    margin: 0;
    font-size: 1.375rem;
    font-weight: 700;
    border: none;
    padding: 0;
}

.btn-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-close:hover {
    background: var(--bg);
    border-color: var(--down);
    color: var(--down);
}

.export-drawer-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

/* Language Selector */
.language-selector {
    margin-bottom: 1.5rem;
}

.language-selector label {
    display: block;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
}

.language-tabs {
    display: flex;
    gap: 0.5rem;
    padding: 0.25rem;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.language-tab {
    flex: 1;
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--muted);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.language-tab:hover {
    color: var(--text);
}

.language-tab.active {
    background: var(--card);
    color: var(--brand);
    font-weight: 600;
}

/* Export Code Container */
.export-code-container {
    background: var(--code-bg);
    border-radius: 8px;
    border: 1px solid var(--border);
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.export-code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid var(--border);
}

.export-code-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.btn-copy-code {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    background: var(--brand);
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-copy-code:hover {
    background: var(--link-hover);
    transform: translateY(-1px);
}

.btn-copy-code:active {
    transform: translateY(0);
}

.export-code-block {
    margin: 0;
    padding: 1.25rem;
    background: var(--code-bg);
    color: var(--code-fg);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8125rem;
    line-height: 1.6;
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
}

.export-code-block code {
    font-family: inherit;
}

/* Export Accordion */
.export-accordion {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.export-accordion-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: var(--bg);
    cursor: pointer;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text);
    user-select: none;
    transition: all 0.2s ease;
}

.export-accordion-header:hover {
    background: rgba(59, 130, 246, 0.05);
    color: var(--brand);
}

.export-accordion-header svg {
    transition: transform 0.2s ease;
}

.export-accordion[open] .export-accordion-header svg {
    transform: rotate(180deg);
}

.export-accordion-content {
    padding: 1.25rem;
    border-top: 1px solid var(--border);
}

.export-section {
    margin-bottom: 2rem;
}

.export-section:last-child {
    margin-bottom: 0;
}

.export-section h4 {
    margin-top: 0;
    margin-bottom: 0.75rem;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
}

.export-description {
    color: var(--muted);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

/* ============================================
   Info Modal - Quick Reference
   ============================================ */

.info-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 3000;
}

.info-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.info-modal-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--card);
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    max-width: 800px;
    width: 90%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    animation: scaleIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.info-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 1.5rem 1rem;
    border-bottom: 1px solid var(--border);
}

.info-modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    border: none;
    padding: 0;
}

.info-modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.info-section {
    margin-bottom: 2rem;
}

.info-section:last-child {
    margin-bottom: 0;
}

/* ============================================
   Animations
   ============================================ */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes scaleIn {
    from {
        transform: translate(-50%, -50%) scale(0.9);
        opacity: 0;
    }
    to {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

/* ============================================
   Utility Classes
   ============================================ */

.hidden {
    display: none !important;
}

.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid var(--border);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes slideInScale {
    0% {
        opacity: 0;
        transform: scale(0.9) translateY(-4px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .comparison-chip,
    .comparison-item {
        animation: none;
        transition: none;
    }
}

/* ============================================
   Responsive Adjustments
   ============================================ */

@media (max-width: 768px) {
    .indicator-header h1 {
        font-size: 1.5rem;
    }
    
    .export-drawer-content {
        border-radius: 12px 12px 0 0;
    }
    
    .info-modal-content {
        width: 95%;
        max-height: 90vh;
    }
    
    /* Responsive comparison chips for mobile */
    .comparison-chips-container {
        gap: 0.75rem;
    }
    
    .comparison-chip,
    .comparison-item {
        padding: 0.5rem 0.875rem;
        font-size: 0.875rem;
    }
    
    .comparison-label {
        font-size: 0.875rem;
    }
    
    .comparison-color {
        width: 14px;
        height: 14px;
    }
    
    /* Ensure remove button has accessible touch target on mobile */
    .comparison-item .btn-remove-comparison {
        width: 44px;
        height: 44px;
    }
}

/* Ensure comparison items from old layout are styled */
.comparison-item {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.9375rem;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px var(--shadow-color-soft, rgba(0, 0, 0, 0.1));
    animation: slideInScale 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.comparison-item:hover {
    border-color: var(--brand);
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(var(--brand-rgb), 0.2);
}

.comparison-item .comparison-color {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px var(--comparison-color-outline, rgba(255, 255, 255, 0.2));
}

.comparison-item .comparison-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text);
    line-height: 1.4;
}

.comparison-item .btn-remove-comparison {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--muted);
    cursor: pointer;
    padding: 0;
    margin-left: 0.25rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.comparison-item .btn-remove-comparison:hover {
    background: var(--down);
    color: white;
    transform: scale(1.1);
}

.comparison-item .btn-remove-comparison:active {
    transform: scale(0.95);
}
