/* General Resets */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Segoe UI', 'Roboto', Helvetica, Arial, sans-serif;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: #f0f2f5;
    overflow: hidden;
}

header {
    background: #1a5376;
    box-shadow: 0 4px 6px rgba(15, 14, 14, 0.1);
    padding: 10px 20px;
    font-weight: 600;
    font-size: 1.2rem;
    color: white;
    letter-spacing: 0.5px;
    flex: 0 0 auto;
    z-index: 100;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
}

.header-title {
    text-align: center;
    white-space: nowrap;
    /* Keeps it on one line */
}

/* Specific Button Variants */
#btnInstructions {
    background-color: #e74c3c;
    padding: 6px 15px;
    font-size: 0.85rem;
    justify-self: end;
    grid-column: 7;
}

#btnInstructions:hover {
    background-color: #c0392b;
}

.header-spacer {
    visibility: hidden;
}

.bottom-banner {
    background: #1a5376;
    color: white;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    flex-shrink: 0;
}

/* =========================================================
   8. MODALS & OVERLAYS
========================================================= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: transparent;
    display: none;
    justify-content: flex-end;
    align-items: flex-start;

    z-index: 1000;
}

.modal {
    background: white;
    padding: 25px;
    border-radius: 12px;
    max-width: 500px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(0, 0, 0, 0.05);
    margin-top: 70px;
    margin-right: 20px;

    animation: modalEntry 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.workspace {
    flex: 1;
    display: flex;
    padding: 10px;
    gap: 10px;
    overflow: hidden;
}

/* Sidebar column should not grow or shrink */
.sidebar-column {
    width: 250px;
    /* Static width */
    min-width: 250px;
    /* Prevents squishing */
    max-width: 250px;
    /* Prevents unwanted expansion */
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-shrink: 0;
    /* Ensures it won't compress when graph area expands */
    overflow-y: auto;
    padding-right: 5px;
    /* Space for scrollbar if needed */
}

/* Ensure cards inside take full width of the sidebar */
.panel-card {
    width: 100%;
    background: white;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    border: 1px solid #e1e4e8;
    flex-shrink: 0;
    /* Prevents individual panels from collapsing vertically */
}

.panel-header {
    background: #ffffff;
    padding: 10px 15px;
    font-size: 0.75rem;
    font-weight: 700;
    color: black;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #f0f2f5;
}

.panel-body {
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

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

select {
    width: 100%;
    padding: 6px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background-color: #fff;
    font-size: 0.85rem;
    outline: none;
}

button {
    width: 100%;
    padding: 8px;
    border: none;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
}

.btn-primary {
    background-color: #1a5376;
    color: white;
}

.btn-primary:hover {
    background-color: #2980b9;
}

.btn-secondary {
    background-color: #1a5376;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #7f8c8d;
}

.btn-action {
    background-color: #27ae60;
    color: white;
}

.btn-action:hover:not(:disabled) {
    background-color: #27ae60;
    color: white;
}

.btn-success {
    background-color: #2ecc71;
    color: white;
}

.btn-success:hover {
    background-color: #27ae60;
}

.btn-danger {
    background-color: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background-color: #c0392b;
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.label-small {
    font-size: 0.75rem;
    color: #666;
    display: flex;
    justify-content: space-between;
}

input[type="range"] {
    width: 100%;
    cursor: pointer;
}

.info-text {
    font-size: 0.91rem;
    color: black;
    margin: 0;
    line-height: 1.3;
}

.instruction-text {
    font-size: 0.85rem;
    font-weight: bold;
    color: #d35400;
    text-align: center;
    margin: 0;
}

.status-box {
    font-size: 0.75rem;
    color: #7f8c8d;
    text-align: center;
    margin-bottom: 5px;
    font-style: italic;
}

.graph-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: transparent;
    gap: 8px;
    position: relative;
    overflow: hidden;
}

.chart-wrapper {
    background: white;
    border-radius: 6px;
    padding: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    flex: 1;
    position: relative;
    min-height: 0;
    transition: flex 0.3s ease;
}

.chart-wrapper.full-height {
    flex: 100;
}

.scroll-wrapper {
    background: white;
    padding: 4px 12px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
}

.scroll-icon {
    color: #888;
    font-size: 1rem;
}

#emptyState {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #999;
}

.empty-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
    opacity: 0.5;
}

.info-panel {
    width: 240px;
    background: white;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

/* Updated Legend Styles for Horizontal Layout under graph */
.legend-box {
    background: white;
    border: 1px solid #e1e4e8;
    border-radius: 6px;
    margin-top: 5px;
}

.legend-grid {
    padding: 10px 15px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    gap: 15px;
    font-size: 0.75rem;
    color: #555;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.swatch {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    display: inline-block;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.line-p {
    background-color: #e74c3c;
}

.line-qrs {
    background-color: #3498db;
}

.line-t {
    background-color: #2ecc71;
}

.bg-pq {
    background-color: rgba(241, 196, 15, 0.4);
}

.bg-qrs {
    background-color: rgba(52, 152, 219, 0.2);
}

.bg-st {
    background-color: rgba(155, 89, 182, 0.3);
}

.hidden {
    display: none !important;
}

/* Container for the label and its numerical value */
.label-wrapper {
    display: flex;
    align-items: baseline;
    justify-content: flex-start;
    /* Aligns items to the left, removing the gap */
    gap: 5px;
    /* Adds a clean, consistent space between text and value */
    margin-bottom: 2px;
}

/* Adjust the specific font styles for the sidebar scale */
.sidebar-column .label-small {
    font-size: 0.85rem;
    color: black;
    margin: 0;
}

.value-display {
    font-weight: 600;
    color: #3498db;
    /* Optional: adds a distinct color to the numerical value */
}

/* Ensure the slider itself looks consistent */
.sidebar-column input[type="range"] {
    width: 100%;
    margin-top: 2px;
}

/* =========================================================
   9. RESPONSIVE DESIGN (Add to end of file)
========================================================= */
@media screen and (max-width: 1024px) {

    /* 1. Unlock height to allow scrolling */
    body {
        height: auto;
        overflow-y: auto;
    }

    .workspace {
        flex-direction: column;
        /* Stack main sections vertically */
        overflow: visible;
        gap: 20px;
    }

    /* 2. Top Row: Input, Auto, & Manual Panels */
    .sidebar-column {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        flex-direction: row;
        /* Align panels in a row */
        overflow-x: auto;
        /* Scroll horizontally on small phones */
        padding-right: 0;
    }

    .panel-card {
        min-width: 300px;
        /* Ensure panels don't get too squashed */
        flex: 1;
    }

    /* 3. Middle: Graph Canvas */
    .graph-area {
        flex: none;
        /* Disable flex scaling */
        height: 500px;
        /* Fixed height for graph visibility */
    }

    /* Ensure legend wraps properly below graph */
    .legend-grid {
        justify-content: center;
    }

    /* 4. Bottom Row: Results & Wave Description */
    .info-panel {
        width: 100%;
        /* Use Grid to create two side-by-side columns from the flat HTML structure */
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
        /* Header Row, Body Row */
    }

    /* Force "Results" Header & Body to Column 1 */
    .info-panel> :nth-child(1) {
        grid-column: 1;
        grid-row: 1;
    }

    .info-panel> :nth-child(2) {
        grid-column: 1;
        grid-row: 2;
        height: 100%;
    }

    /* Force "Wave Description" Header & Body to Column 2 */
    .info-panel> :nth-child(3) {
        grid-column: 2;
        grid-row: 1;
        border-top: none !important;
        /* Remove existing top border */
        border-left: 1px solid #f0f2f5;
        /* Add separator */
    }

    .info-panel> :nth-child(4) {
        grid-column: 2;
        grid-row: 2;
        border-left: 1px solid #f0f2f5;
        height: 100%;
    }
}

/* Optional: Stack everything on very small mobile screens */
@media screen and (max-width: 600px) {
    .sidebar-column {
        flex-direction: column;
    }

    .info-panel {
        display: flex;
        flex-direction: column;
    }

    .info-panel> :nth-child(3) {
        border-left: none;
        border-top: 1px solid #f0f2f5 !important;
    }

    .info-panel> :nth-child(4) {
        border-left: none;
    }
}

/* =========================================================
   9. RESPONSIVE DESIGN (Add to end of file)
========================================================= */
@media screen and (max-width: 600px) {

    /* Essential Scroll Fixes */
    body {
        height: auto;
        overflow-y: auto;
    }

    .workspace {
        flex-direction: column;
        overflow: visible;
        gap: 20px;
    }

    .sidebar-column {
        flex-direction: column;
        width: 100%;
        max-width: 100%;
    }

    .info-panel {
        display: flex;
        flex-direction: column;
        width: 100%;
        height: auto;
        overflow: visible;
    }

    header {
        font-size: 0.9rem;
        /* Reduced by 25% from 1.2rem */
        padding: 8px 10px;
        /* Slightly reduced padding to save vertical space */
    }

    /* Optional: Ensure the title wraps nicely if still too long */
    .header-title {
        white-space: normal;
        /* Allow text to wrap on very small screens */
        line-height: 1.2;
    }

    .info-panel> :nth-child(3) {
        border-left: none;
        border-top: 1px solid #f0f2f5 !important;
    }

    .info-panel> :nth-child(4) {
        border-left: none;
    }
}