* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #0a0e27;
    color: #e0e0e0;
    line-height: 1.6;
    overflow-x: hidden;
    height: 100vh;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 0;
    max-width: 100%;
}

header {
    background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
    padding: 15px 25px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    flex-shrink: 0;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

header h1 {
    font-size: 1.5em;
    margin: 0;
    color: #fff;
}

.system-resources {
    display: flex;
    gap: 20px;
    background-color: rgba(0, 0, 0, 0.2);
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.resource-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.resource-label {
    font-weight: 600;
    color: #93c5fd;
    font-size: 0.85em;
}

.resource-value {
    font-family: 'Courier New', monospace;
    color: #fff;
    font-size: 0.85em;
    font-weight: bold;
}

.controls {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.controls label {
    font-weight: 600;
    color: #fff;
    font-size: 0.9em;
}

#expiry-select, #baseline-time-select {
    padding: 6px 12px;
    font-size: 0.9em;
    border: none;
    border-radius: 5px;
    background-color: #fff;
    color: #0a0e27;
    cursor: pointer;
    min-width: 120px;
}

#expiry-select:focus, #baseline-time-select:focus {
    outline: 2px solid #60a5fa;
}

.datetime-filters {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.datetime-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

#start-datetime, #end-datetime {
    padding: 6px 10px;
    font-size: 0.85em;
    border: none;
    border-radius: 5px;
    background-color: #fff;
    color: #0a0e27;
    cursor: pointer;
}

#start-datetime:focus, #end-datetime:focus {
    outline: 2px solid #60a5fa;
}

.btn-apply, .btn-reset {
    padding: 6px 16px;
    font-size: 0.85em;
    font-weight: 600;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-apply {
    background-color: #10b981;
    color: #fff;
}

.btn-apply:hover {
    background-color: #059669;
    transform: translateY(-1px);
}

.btn-reset {
    background-color: #6b7280;
    color: #fff;
}

.btn-reset:hover {
    background-color: #4b5563;
    transform: translateY(-1px);
}

.status-bar {
    display: flex;
    gap: 15px;
}

#last-update, #auto-refresh {
    color: #e0e0e0;
    font-size: 0.8em;
    padding: 4px 10px;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
}

.status {
    color: #4ade80;
    font-weight: bold;
}

/* Main Grid Layout - 2x2 Grid */
.charts-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 15px;
    padding: 15px;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - 160px);
}

.chart-wrapper {
    background-color: #1a1f3a;
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chart-wrapper h2 {
    margin: 0 0 10px 0;
    color: #60a5fa;
    font-size: 1.1em;
    border-bottom: 2px solid #3b82f6;
    padding-bottom: 8px;
    flex-shrink: 0;
}

.baseline-info {
    color: #9ca3af;
    font-size: 0.85em;
    margin-bottom: 8px;
    flex-shrink: 0;
}

/* Wrapper per grafici con loading overlay */
.chart-container-wrapper {
    position: relative;
    width: 100%;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#candles-chart, #ivsum-chart, #strikes-chart {
    width: 100%;
    flex: 1;
    min-height: 0;
}

/* Candles takes top-left */
.chart-wrapper:nth-child(1) {
    grid-column: 1;
    grid-row: 1;
}

/* IV_SUM takes bottom-left */
.chart-wrapper:nth-child(2) {
    grid-column: 1;
    grid-row: 2;
}

/* Strikes takes full right side (spans both rows) */
.chart-wrapper:nth-child(3) {
    grid-column: 2;
    grid-row: 1 / 3;
}

.info-panel {
    display: none; /* Hide info panel to save space */
}

/* Chart Loading Overlay - Non-blocking */
.chart-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(26, 31, 58, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(2px);
    border-radius: 8px;
    pointer-events: none; /* Permette di interagire con il grafico sotto */
}

.loading-spinner-small {
    text-align: center;
}

.spinner-small {
    width: 40px;
    height: 40px;
    margin: 0 auto;
    border: 3px solid rgba(59, 130, 246, 0.2);
    border-top: 3px solid #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #0a0e27;
}

::-webkit-scrollbar-thumb {
    background: #3b82f6;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #60a5fa;
}

/* Responsive for smaller screens */
@media (max-width: 1400px) {
    .charts-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        height: auto;
        overflow-y: auto;
    }
    
    .chart-wrapper:nth-child(1),
    .chart-wrapper:nth-child(2),
    .chart-wrapper:nth-child(3) {
        grid-column: 1;
        grid-row: auto;
    }
    
    #candles-chart, #ivsum-chart, #strikes-chart {
        height: 400px;
    }
}

@media (max-width: 768px) {
    header h1 {
        font-size: 1.2em;
    }

    .controls {
        flex-direction: column;
        align-items: flex-start;
    }

    #candles-chart, #ivsum-chart, #strikes-chart {
        height: 300px;
    }
}
