/* wwwroot/css/iframe-responsive.css
 * Responsive styles for iframe embedding
 * This file handles the UI adaptation when the app is displayed in an iframe
 * with reduced dimensions or on smaller viewports.
 */

/* =====================================================
   ROOT VARIABLES FOR IFRAME MODE
   ===================================================== */
:root {
    --menu-panel-width: 350px;
    --menu-panel-collapsed-width: 0px;
    --toolbar-height: 56px;
    --toolbar-compact-height: 44px;
    --transition-speed: 0.3s;
}

/* =====================================================
   CHART HEADER BADGE ROWS
   Two-row layout: main badges (asset, timeframe, charttype)
   and indicators row below
   ===================================================== */

.chart-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chart-badges-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.chart-badges-main {
    /* First row: asset name, timeframe, chart type */
}

.chart-badges-indicators {
    /* Second row: indicators */
    gap: 6px;
}

/* Ensure indicator tags in second row are always visible */
.chart-badges-indicators .indicator-tag {
    display: inline-flex !important;
}

/* =====================================================
   TOOLBAR BUTTON GROUPS - Visual grouping when separators are hidden
   ===================================================== */

/* Base group styling - subtle visual separation */
.timeframe-group,
.charttype-group,
.indicators-template-group,
.view-controls-group {
    display: flex !important;
    flex-wrap: nowrap;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 6px;
    padding: 2px;
    gap: 2px;
}

.timeframe-group .toolbar-btn,
.charttype-group .toolbar-btn,
.indicators-template-group .toolbar-btn,
.view-controls-group .toolbar-btn {
    display: inline-flex !important;
    flex-shrink: 0;
    border-radius: 4px;
}

/* Ensure dropdown containers inside groups align properly */
.indicators-template-group .indicator-dropdown,
.indicators-template-group .template-dropdown {
    display: flex;
    align-items: center;
}

/* Toolbar right group styling */
.toolbar-right-group {
    background: rgba(0, 0, 0, 0.04);
    border-radius: 6px;
    padding: 2px 4px;
}

/* =====================================================
   RESPONSIVE TOOLBAR GROUPS - Enhanced visual grouping on small screens
   ===================================================== */
@media (max-width: 900px) {
    /* More visible group backgrounds when separators are hidden */
    .timeframe-group,
    .charttype-group,
    .indicators-template-group,
    .view-controls-group {
        background: rgba(0, 0, 0, 0.06);
        padding: 3px;
        margin: 0 2px;
    }

    .toolbar-right-group {
        background: rgba(0, 0, 0, 0.06);
        padding: 3px 6px;
    }
}

@media (max-width: 768px) {
    .timeframe-group,
    .charttype-group,
    .indicators-template-group,
    .view-controls-group {
        background: rgba(0, 0, 0, 0.08);
        border: 1px solid rgba(0, 0, 0, 0.08);
    }

    .toolbar-right-group {
        background: rgba(0, 0, 0, 0.08);
        border: 1px solid rgba(0, 0, 0, 0.08);
    }
}

/* Iframe mode - always show group styling */
body.iframe-mode .timeframe-group,
body.iframe-mode .charttype-group,
body.iframe-mode .indicators-template-group,
body.iframe-mode .view-controls-group {
    background: rgba(0, 0, 0, 0.06);
    border-radius: 6px;
    padding: 3px;
    margin: 0 2px;
}

body.iframe-mode .toolbar-right-group {
    background: rgba(0, 0, 0, 0.06);
    border-radius: 6px;
    padding: 3px 6px;
}

/* =====================================================
   TIMEFRAME AND CHART TYPE BUTTONS (Font Awesome based)
   ===================================================== */

/* Timeframe icon text styling */
.timeframe-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    width: 20px;
    height: 20px;
    line-height: 1;
}

/* Timeframe buttons with colored backgrounds when active */
.timeframe-btn.active .timeframe-icon {
    color: inherit;
}

/* Specific colors for each timeframe when active */
.timeframe-btn[title="Timeframe daily"].active {
    background: #F2C53E !important;
    border-color: #F2C53E !important;
    color: #333 !important;
}

.timeframe-btn[title="Timeframe weekly"].active {
    background: #73AD59 !important;
    border-color: #73AD59 !important;
    color: white !important;
}

.timeframe-btn[title="Timeframe monthly"].active {
    background: #CF1212 !important;
    border-color: #CF1212 !important;
    color: white !important;
}

.timeframe-btn[title="Timeframe quarterly"].active {
    background: #4A8ECA !important;
    border-color: #4A8ECA !important;
    color: white !important;
}

/* Chart type buttons */
.charttype-btn i {
    font-size: 14px;
}

.charttype-btn.active {
    background: linear-gradient(135deg, #0891b2 0%, #0e7490 100%) !important;
    border-color: #0891b2 !important;
    color: white !important;
}

/* Ensure button groups don't disappear - override any display:none rules */
.timeframe-group,
.charttype-group {
    display: flex !important;
    flex-wrap: nowrap;
}

.timeframe-group .toolbar-btn,
.charttype-group .toolbar-btn {
    display: inline-flex !important;
    flex-shrink: 0;
}

/* =====================================================
   IFRAME MODE DETECTION (via body class)
   When running in an iframe, JS adds 'iframe-mode' class to body
   ===================================================== */

/* =====================================================
   MENU PANEL TOGGLE BUTTON - ALWAYS VISIBLE
   Toggle mode is always active, sidebar pushes content
   ===================================================== */
.menu-toggle-btn {
    display: flex; /* Always visible */
    align-items: center;
    justify-content: center;
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1000;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 0 8px 8px 0;
    padding: 12px 8px;
    cursor: pointer;
    box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.2);
    transition: all var(--transition-speed) ease;
}

/* When sidebar is visible, hide toggle button (use close button inside sidebar instead) */
.trading-layout.sidebar-visible .menu-toggle-btn {
    display: none;
}

.menu-toggle-btn:hover {
    padding-right: 12px;
    box-shadow: 4px 2px 12px rgba(0, 0, 0, 0.3);
}

.menu-toggle-btn i {
    font-size: 16px;
    transition: transform var(--transition-speed) ease;
}

/* Arrow rotation is handled by Blazor class binding in the icon */

/* Close button inside menu panel - always visible */
.menu-close-btn {
    display: flex; /* Always visible */
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 1001;
    background: rgba(0, 0, 0, 0.1);
    color: #666;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    transition: all 0.2s ease;
    align-items: center;
    justify-content: center;
}

.menu-close-btn:hover {
    background: rgba(0, 0, 0, 0.2);
    color: #333;
}

/* =====================================================
   SIDEBAR PUSH MODE - Always Active
   Menu sidebar pushes content instead of overlaying
   ===================================================== */

/* Menu panel - part of flex layout, not fixed */
.menu-panel {
    position: relative;
    width: 0;
    min-width: 0;
    flex-shrink: 0;
    overflow: hidden;
    transition: width var(--transition-speed) ease, min-width var(--transition-speed) ease;
    border-right: none;
}

.menu-panel.visible {
    width: var(--menu-panel-width);
    min-width: var(--menu-panel-width);
    border-right: 1px solid #e0e0e0;
}

/* Menu body needs proper sizing when visible */
.menu-panel.visible .menu-body {
    width: var(--menu-panel-width);
}

/* Overlay is no longer needed - hide it completely */
.menu-overlay {
    display: none !important;
}

/* Content wrapper - flexible layout */
.content-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
    width: 100%;
}

/* Chart panel - takes remaining space */
.chart-panel {
    flex: 1;
    min-width: 0;
    transition: none;
}

/* Toolbar also shifts with content */
.trading-layout {
    position: relative;
}

/* =====================================================
   RESPONSIVE BREAKPOINTS - MEDIUM SCREENS (< 1200px)
   Smaller sidebar width
   ===================================================== */
@media (max-width: 1200px) {
    :root {
        --menu-panel-width: 320px;
    }
}

/* =====================================================
   RESPONSIVE BREAKPOINTS - SMALL SCREENS (< 900px)
   Compact toolbar and smaller elements
   ===================================================== */
@media (max-width: 900px) {
    /* More compact toolbar */
    .main-toolbar.e-toolbar {
        padding: 6px 10px;
        min-height: var(--toolbar-compact-height);
    }

    .toolbar-btn {
        padding: 4px 8px;
        font-size: 12px;
        min-height: 28px;
    }

    .timeframe-group .toolbar-btn,
    .charttype-group .toolbar-btn {
        min-width: 32px;
        padding: 4px 6px;
    }

    .timeframe-icon {
        font-size: 12px;
        width: 16px;
        height: 16px;
    }

    .charttype-btn i {
        font-size: 12px;
    }

    /* Hide some toolbar elements */
    .main-toolbar .e-separator {
        display: none;
    }

    /* Compact chart header */
    .chart-header {
        padding: 10px 12px;
    }

    .chart-info {
        gap: 4px;
    }

    .chart-badges-row {
        gap: 6px;
    }

    .setting-badge {
        padding: 4px 8px;
        font-size: 11px;
    }

    .setting-badge.asset-name {
        padding: 6px 10px;
        font-size: 13px;
    }

    /* Compact indicators */
    .chart-badges-indicators .indicator-tag {
        padding: 3px 6px;
        font-size: 10px;
    }

    /* Smaller menu panel width when visible */
    :root {
        --menu-panel-width: 300px;
    }
}

/* =====================================================
   RESPONSIVE BREAKPOINTS - EXTRA SMALL (< 768px)
   Mobile-first layout
   ===================================================== */
@media (max-width: 768px) {
    .main-toolbar.e-toolbar {
        padding: 4px 8px;
        min-height: 40px;
    }

    /* Hide text labels, show only icons */
    .user-info-badge .user-name {
        display: none;
    }

    .user-info-badge {
        padding: 4px 8px;
    }

    .login-btn {
        padding: 4px 8px !important;
    }

    /* Toolbar button groups become more compact */
    .btn-group {
        gap: 2px;
    }

    .toolbar-btn {
        padding: 4px 6px;
        min-height: 26px;
    }

    .toolbar-btn i {
        font-size: 12px;
    }

    /* Timeframe and chart type buttons - more compact */
    .timeframe-group .toolbar-btn,
    .charttype-group .toolbar-btn {
        min-width: 28px;
        padding: 3px 5px;
    }

    .timeframe-icon {
        font-size: 11px;
        width: 14px;
        height: 14px;
    }

    .charttype-btn i {
        font-size: 11px;
    }

    /* Hide less important toolbar items */
    .toolbar-btn .toolbar-badge {
        display: none;
    }

    /* Chart header compact */
    .chart-info {
        gap: 3px;
    }

    .chart-badges-row {
        gap: 4px;
    }

    .chart-badges-main .setting-badge {
        padding: 3px 6px;
        font-size: 10px;
        white-space: nowrap;
    }

    .chart-badges-main .setting-badge.asset-name {
        padding: 4px 8px;
        font-size: 11px;
    }

    /* Compact indicators on small screens */
    .chart-badges-indicators .indicator-tag {
        padding: 2px 5px;
        font-size: 9px;
    }

    .chart-badges-indicators .indicator-tag .indicator-params {
        display: none;
    }

    /* Smaller menu panel on mobile */
    :root {
        --menu-panel-width: min(85vw, 300px);
    }

    /* Toggle button smaller */
    .menu-toggle-btn {
        padding: 10px 6px;
    }

    .menu-toggle-btn i {
        font-size: 14px;
    }
}

/* =====================================================
   RESPONSIVE BREAKPOINTS - TINY SCREENS (< 576px)
   Ultra-compact mode for very small iframes
   ===================================================== */
@media (max-width: 576px) {
    .main-toolbar.e-toolbar {
        padding: 4px 6px;
        min-height: 36px;
        gap: 4px;
    }

    .main-toolbar .e-toolbar-items {
        gap: 4px;
    }

    /* Minimal toolbar buttons */
    .toolbar-btn {
        padding: 3px 5px;
        min-height: 24px;
        border-radius: 3px;
    }

    /* Timeframe and chart type buttons - ultra compact */
    .timeframe-group .toolbar-btn,
    .charttype-group .toolbar-btn {
        min-width: 24px;
        padding: 2px 4px;
    }

    .timeframe-icon {
        font-size: 10px;
        width: 12px;
        height: 12px;
        font-weight: 800;
    }

    .charttype-btn i {
        font-size: 10px;
    }

    /* Very compact chart header */
    .chart-header {
        padding: 6px 8px;
    }

    .chart-info {
        gap: 2px;
    }

    .chart-badges-row {
        gap: 3px;
    }

    /* Ultra-compact badges on tiny screens - keep visible but smaller */
    .chart-badges-main .setting-badge {
        padding: 2px 5px;
        font-size: 9px;
    }

    .chart-badges-main .setting-badge.asset-name {
        padding: 3px 6px;
        font-size: 10px;
    }

    /* Hide icons inside badges on tiny screens to save space */
    .chart-badges-main .setting-badge i {
        display: none;
    }

    /* Compact indicators row */
    .chart-badges-indicators {
        gap: 4px;
    }

    .chart-badges-indicators .indicator-tag {
        padding: 2px 5px;
        font-size: 9px;
    }

    /* Hide indicator icons and params on tiny screens */
    .chart-badges-indicators .indicator-tag i,
    .chart-badges-indicators .indicator-tag .indicator-params {
        display: none;
    }

    /* Smaller remove button */
    .chart-badges-indicators .indicator-tag .remove-indicator {
        width: 12px;
        height: 12px;
        margin-left: 3px;
    }

    .chart-badges-indicators .indicator-tag .remove-indicator i {
        display: inline; /* Keep the X icon visible */
        font-size: 8px;
    }

    /* Menu panel full-width on tiny screens */
    :root {
        --menu-panel-width: 100vw;
    }
}

/* =====================================================
   IFRAME-SPECIFIC STYLES
   Applied when body has 'iframe-mode' class
   ===================================================== */
body.iframe-mode {
    overflow: hidden;
    /* Force app to fit within visible viewport even if iframe is oversized */
    max-width: 100vw;
}

body.iframe-mode .trading-layout {
    height: 100vh;
    max-height: 100vh;
    max-width: 100vw;
    overflow: hidden;
}

body.iframe-mode .content-wrapper {
    height: calc(100vh - var(--toolbar-height));
    overflow: hidden;
    max-width: 100vw;
}

body.iframe-mode .main-toolbar.e-toolbar {
    max-width: 100vw;
    overflow-x: auto;
}

body.iframe-mode .chart-panel {
    max-width: 100vw;
    overflow: hidden;
}

/* Iframe mode inherits the same push sidebar behavior as normal mode */
/* No special overrides needed - sidebar push mode is always active */

body.iframe-mode .content-wrapper {
    flex-direction: row;
}

body.iframe-mode .chart-panel {
    flex: 1;
    min-width: 0;
}

/* Compact toolbar in iframe mode */
body.iframe-mode .main-toolbar.e-toolbar {
    padding: 6px 10px;
    min-height: 44px;
}

body.iframe-mode .main-toolbar .e-separator {
    display: none;
}

body.iframe-mode .toolbar-btn {
    padding: 4px 8px;
    font-size: 12px;
    min-height: 28px;
}

body.iframe-mode .timeframe-group .toolbar-btn,
body.iframe-mode .charttype-group .toolbar-btn {
    min-width: 32px;
    padding: 4px 6px;
}

body.iframe-mode .timeframe-icon {
    font-size: 12px;
    width: 16px;
    height: 16px;
}

body.iframe-mode .charttype-btn i {
    font-size: 12px;
}

/* Compact badges in iframe mode */
body.iframe-mode .chart-info {
    gap: 4px;
}

body.iframe-mode .chart-badges-row {
    gap: 6px;
}

body.iframe-mode .setting-badge {
    padding: 4px 8px;
    font-size: 11px;
}

body.iframe-mode .setting-badge.asset-name {
    padding: 6px 10px;
    font-size: 13px;
}

body.iframe-mode .chart-badges-indicators .indicator-tag {
    padding: 3px 6px;
    font-size: 10px;
}

/* =====================================================
   VIEWPORT HEIGHT FIX FOR IFRAMES
   Ensures content fits within iframe viewport
   ===================================================== */
html, body {
    height: 100%;
    overflow: hidden;
    /* Prevent horizontal overflow in all cases */
    max-width: 100%;
    overflow-x: hidden;
}

#app, .page, .main-content {
    height: 100%;
    overflow: hidden;
    max-width: 100%;
}

.trading-layout {
    height: 100%;
    max-height: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

/* Content wrapper should not exceed available width */
.content-wrapper {
    max-width: 100%;
    overflow-x: hidden;
}

/* Toolbar should scroll horizontally if needed */
.main-toolbar.e-toolbar {
    max-width: 100%;
}

.main-toolbar .e-toolbar-items {
    max-width: 100%;
}

/* =====================================================
   TOOLBAR RESPONSIVE OVERFLOW HANDLING
   ===================================================== */
.main-toolbar .e-toolbar-items {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

.main-toolbar .e-toolbar-items::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

/* Indicator tags responsive */
@media (max-width: 900px) {
    .indicator-tag {
        padding: 3px 6px;
        font-size: 10px;
    }

    .indicator-tag .indicator-params {
        display: none;
    }

    .indicator-tag .remove-indicator {
        width: 14px;
        height: 14px;
    }
}

@media (max-width: 576px) {
    /* Hide indicator tags on very small screens */
    .indicator-tag {
        display: none;
    }
}

/* =====================================================
   OHLC LEGEND RESPONSIVE
   ===================================================== */
@media (max-width: 900px) {
    .ohlc-legend {
        font-size: 11px;
    }

    .legend-row-price {
        flex-wrap: wrap;
    }

    .legend-asset-name {
        display: none;
    }
}

@media (max-width: 576px) {
    .ohlc-legend {
        font-size: 10px;
        padding: 4px 8px;
    }

    .ohlc-legend-label {
        display: none;
    }
}

/* =====================================================
   MENU PANEL CONTENT RESPONSIVE
   ===================================================== */
@media (max-width: 900px) {
    .menu-controls {
        padding: 4px;
        gap: 4px;
    }

    .menu-controls .e-input-group input {
        height: 26px;
        font-size: 11px;
    }

    .action-buttons .e-btn {
        min-width: 24px;
        height: 24px;
    }

    .accordion-header-content span {
        font-size: 12px;
    }

    .menu-item a {
        padding: 5px 10px;
        font-size: 12px;
    }
}

/* =====================================================
   WELCOME SCREEN RESPONSIVE
   ===================================================== */
@media (max-width: 768px) {
    .welcome-chart h3 {
        font-size: 16px;
    }

    .welcome-chart p {
        font-size: 13px;
    }

    .welcome-chart i.fa-5x {
        font-size: 3rem;
    }
}

@media (max-width: 576px) {
    .welcome-chart h3 {
        font-size: 14px;
    }

    .welcome-chart p {
        font-size: 12px;
        padding: 0 20px;
    }

    .welcome-chart i.fa-5x {
        font-size: 2rem;
    }
}

/* =====================================================
   SETTINGS DROPDOWN RESPONSIVE
   ===================================================== */
@media (max-width: 768px) {
    .settings-dropdown-menu {
        min-width: 160px;
        font-size: 13px;
    }

    .settings-dropdown-menu .dropdown-item {
        padding: 8px 12px;
        font-size: 13px;
    }
}

/* =====================================================
   ALERTS AND MODALS RESPONSIVE
   ===================================================== */
@media (max-width: 768px) {
    .alert-component {
        max-width: 90vw;
        font-size: 13px;
    }
}

/* =====================================================
   LOADING OVERLAY RESPONSIVE
   ===================================================== */
@media (max-width: 576px) {
    .chart-loading-overlay .loading-spinner {
        font-size: 12px;
    }

    .chart-loading-overlay .loading-spinner i {
        font-size: 2rem;
    }
}
