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

/* Mobile-first: Full screen chart with overlay controls */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #fff;
    height: 100vh;
    overflow: hidden;
}

.container {
    position: relative;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

/* Full screen chart container */
.chart-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: white;
    z-index: 1;
}

#mainChart {
    width: 100%;
    height: 100%;
    /* Ensure touch events work properly on mobile */
    touch-action: manipulation;
}

/* Overlay controls for mobile */
.mobile-overlay {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 15px;
    pointer-events: none;
    /* Ensure this doesn't interfere with tutorial overlay */
}

.mobile-overlay > * {
    pointer-events: auto;
}

/* Compact header overlay */
.header-overlay {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.header-overlay h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #f7931a;
    margin-bottom: 4px;
}

.header-overlay p {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 8px;
}

.loading-status {
    font-size: 0.85rem;
    color: #f7931a;
    font-weight: 500;
    background: rgba(247, 147, 26, 0.1);
    padding: 6px 12px;
    border-radius: 6px;
    margin-top: 8px;
}

.progress-container {
    margin-top: 8px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    height: 6px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: #f7931a;
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 4px;
}

/* Fade out animation */
.fade-out {
    opacity: 0;
    transition: opacity 0.8s ease-out;
}

/* Slide up animation */
.slide-up {
    transform: translateY(-100%);
    opacity: 0;
    transition: all 0.6s ease-in-out;
}

/* Axis management buttons */
.axis-button {
    position: absolute;
    top: 20px;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid #f7931a;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 14px;
    font-weight: bold;
    color: #f7931a;
    cursor: pointer;
    z-index: 10;
    transition: all 0.2s ease;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.axis-button:hover {
    background: #f7931a;
    color: white;
    transform: scale(1.1);
}

.axis-button-left {
    left: 20px;
}

.axis-button-right {
    right: 20px;
}

/* Metric management modal */
.metric-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.metric-modal-content {
    background: white;
    border-radius: 16px;
    padding: 30px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.metric-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    border-bottom: 2px solid #f5f5f5;
    padding-bottom: 15px;
}

.metric-modal-header h3 {
    color: #f7931a;
    margin: 0;
    font-size: 1.3rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #999;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    color: #f7931a;
}

.current-metrics-section, .add-metrics-section {
    margin-bottom: 25px;
}

.current-metrics-section h4, .add-metrics-section h4 {
    color: #333;
    margin: 0 0 15px 0;
    font-size: 1.1rem;
}

.current-metrics-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
    min-height: 60px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 2px dashed #ddd;
}

.current-metric-item {
    display: flex;
    align-items: center;
    background: white;
    border: 2px solid;
    border-radius: 20px;
    padding: 8px 12px;
    font-size: 0.9rem;
    font-weight: 500;
}

.current-metric-remove {
    background: none;
    border: none;
    color: inherit;
    margin-left: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    opacity: 0.7;
}

.current-metric-remove:hover {
    opacity: 1;
}

.ma-selector {
    margin-bottom: 20px;
}

.ma-selector label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #555;
}

.ma-selector select {
    width: 200px;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.available-metrics-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
}

.available-metric-item {
    padding: 0;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.available-metric-item:hover {
    background: #f7931a;
    color: white;
}

.available-metric-item:last-child {
    border-bottom: none;
}

.available-metric-item.disabled {
    color: #999;
    cursor: not-allowed;
    background: #f8f9fa;
}

.available-metric-item.disabled:hover {
    background: #f8f9fa;
    color: #999;
}


/* Simple tutorial overlay */
.tutorial-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.tutorial-content {
    background: white;
    border-radius: 20px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    text-align: center;
    cursor: pointer;
}

.tutorial-content h2 {
    color: #f7931a;
    margin-bottom: 25px;
    font-size: 1.5rem;
    font-weight: 700;
}

.tutorial-section {
    margin-bottom: 25px;
}

.tutorial-item {
    display: flex;
    align-items: flex-start;
    margin-bottom: 20px;
    text-align: left;
}

.tutorial-icon {
    font-size: 2rem;
    margin-right: 15px;
    flex-shrink: 0;
}

.tutorial-text h3 {
    color: #333;
    margin: 0 0 5px 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.tutorial-text p {
    color: #666;
    margin: 0;
    font-size: 0.9rem;
}

.tutorial-footer {
    margin-top: 20px;
}

.dismiss-hint {
    font-size: 0.8rem;
    color: #999;
    margin: 0 0 15px 0;
    font-style: italic;
}

.tutorial-dismiss {
    background: linear-gradient(135deg, #f7931a, #ffb74d);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.tutorial-dismiss:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(247, 147, 26, 0.4);
}

.tutorial-dismiss:active {
    transform: translateY(0);
}


/* Floating controls */
.controls-overlay {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

/* Collapsible control sections */
.control-section {
    margin-bottom: 16px;
}

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

.control-header {
    display: flex;
    justify-content: between;
    align-items: center;
    margin-bottom: 8px;
    cursor: pointer;
    font-weight: 600;
    color: #555;
    font-size: 0.9rem;
}

.control-header::after {
    content: '▼';
    font-size: 0.8rem;
    margin-left: auto;
    transition: transform 0.2s ease;
}

.control-section.collapsed .control-header::after {
    transform: rotate(-90deg);
}

.control-content {
    overflow: hidden;
    transition: max-height 0.3s ease;
    max-height: 200px;
}

.control-section.collapsed .control-content {
    max-height: 0;
}

/* Compact metric selector */
#metricSelect {
    width: 100%;
    max-height: 120px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    background: white;
}

/* Compact chart options */
.chart-options {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.chart-options label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    cursor: pointer;
}

.chart-options input[type="number"] {
    width: 60px;
    padding: 4px 6px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

/* Compact buttons */
.button-group {
    display: flex;
    gap: 8px;
}

button {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1;
}

button.primary {
    background: #f7931a;
    color: white;
}

button.primary:hover {
    background: #e8850e;
}

button:not(.primary) {
    background: rgba(233, 236, 239, 0.8);
    color: #495057;
}

/* Status overlay */
.status-overlay {
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: 20px;
    z-index: 10;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.status-overlay span {
    font-size: 0.85rem;
    color: #666;
    display: block;
    margin-bottom: 4px;
}

.status-overlay span:last-child {
    margin-bottom: 0;
}

/* Data info overlay */
.data-info {
    position: absolute;
    bottom: 80px;
    right: 20px;
    z-index: 10;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.8rem;
    display: none; /* Hide on mobile by default */
    color: #666;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* Desktop override: Traditional layout */
@media (min-width: 768px) {
    body {
        background-color: #f5f5f5;
        overflow: visible;
        height: auto;
    }

    .container {
        max-width: 1400px;
        margin: 0 auto;
        padding: 20px;
        height: auto;
        overflow: visible;
        position: relative;
    }

    .mobile-overlay {
        display: none;
    }

    .status-overlay {
        display: none;
    }

    .data-info {
        display: block; /* Show on desktop */
        position: relative;
        bottom: auto;
        right: auto;
        left: auto;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: white;
        margin-bottom: 20px;
    }

    /* Traditional desktop layout */
    header {
        text-align: center;
        margin-bottom: 30px;
        padding: 20px;
        background: linear-gradient(135deg, #f7931a, #ffb74d);
        border-radius: 10px;
        color: white;
        display: block;
    }

    header h1 {
        font-size: 2.5rem;
        margin-bottom: 10px;
        font-weight: 700;
    }

    header p {
        font-size: 1.1rem;
        opacity: 0.9;
        margin-bottom: 12px;
    }

    header .loading-status {
        font-size: 0.95rem;
        color: white;
        background: rgba(255, 255, 255, 0.2);
        padding: 8px 16px;
        border-radius: 8px;
        margin-top: 12px;
    }

    header .progress-container {
        background: rgba(255, 255, 255, 0.2);
        height: 8px;
        margin-top: 8px;
    }

    header .progress-bar {
        background: white;
    }

    .controls {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 20px;
        margin-bottom: 20px;
        padding: 20px;
        background: white;
        border-radius: 10px;
        box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    }

    .control-group {
        display: flex;
        flex-direction: column;
    }

    .control-group label {
        font-weight: 600;
        margin-bottom: 8px;
        color: #555;
    }

    .chart-container {
        position: relative;
        background: white;
        border-radius: 10px;
        box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        padding: 10px;
        margin-bottom: 30px;
    }

    #mainChart {
        height: 600px;
    }

    .status {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    footer {
        text-align: center;
        padding: 20px;
        color: #666;
        font-size: 14px;
        display: block;
    }

    /* Desktop metric selector */
    #metricSelect {
        min-height: 120px;
        max-height: none;
    }

    /* Desktop chart options */
    .chart-options {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .chart-options input[type="number"] {
        width: 100px;
        padding: 6px 8px;
    }

    /* Desktop buttons */
    button {
        padding: 12px 24px;
        font-size: 14px;
    }

    .button-group {
        gap: 12px;
    }
}

/* Hide desktop elements on mobile */
@media (max-width: 767px) {
    header,
    .controls,
    .status,
    footer {
        display: none !important;
    }

    /* Ensure mobile overlay is visible */
    .mobile-overlay {
        display: flex !important;
    }

    .status-overlay {
        display: block !important;
    }
}