* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    /* Lock the app to the exact height of the browser window */
    height: 100vh; 
    display: flex;
    flex-direction: column;
    
    background-color: #1e1e1e;
    color: #cccccc;
}

.top-bar {
    flex: 0 0 60px; 
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    background-color: #2d2d2d;
    border-bottom: 1px solid #444444;
}

.top-bar h1 {
    font-size: 1.2rem;
    color: #ffffff;
}

.file-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

#ecuStatus {
    font-size: 0.9rem;
    color: #4CAF50;
    font-weight: bold;
}

.app-container {
    flex: 1; 
    display: flex;
    
    /* Prevent the whole page from scrolling, force columns to scroll instead */
    overflow: hidden; 
}

.left-sidebar, .right-sidebar {
    background-color: #252526;
    padding: 15px;
    overflow-y: auto; /* Adds a scrollbar only if the content is too long */
}

.left-sidebar {
    flex: 0 0 250px;
    border-right: 1px solid #444444;
}

.right-sidebar {
    flex: 0 0 300px;
    border-left: 1px solid #444444;
}

aside h3 {
    color: #ffffff;
    font-size: 1rem;
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.center-workspace {
    flex: 1; /* Automatically fill all space between the two sidebars */
    padding: 20px;
    background-color: #1e1e1e;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.center-workspace h2 {
    color: #ffffff;
    border-bottom: 1px solid #444444;
    padding-bottom: 10px;
}

button, input[type="file"]::file-selector-button {
    background-color: #0e639c;
    color: white;
    border: none;
    padding: 8px 15px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.9rem;
    transition: background-color 0.2s;
}

button:hover, input[type="file"]::file-selector-button:hover {
    background-color: #1177bb;
}

button:disabled {
    background-color: #444444;
    color: #888888;
    cursor: not-allowed;
}

.table-container {
    overflow-x: auto; /* Allows horizontal scrolling if the map is massive */
    background-color: #2d2d2d;
    padding: 10px;
    border-radius: 5px;
    border: 1px solid #444444;
}

table {
    border-collapse: collapse;
    width: max-content; /* Keeps cells from squishing together */
}

th, td {
    border: 1px solid #555555;
    padding: 3px 4px;
    text-align: center;
    font-size: 0.85rem;
    min-width: 50px;
    color: #ffffff;
}

td {
    min-width: 45px;
    max-width: 55px;
    height: 24px;
    overflow: hidden;
    white-space: nowrap;
    -webkit-user-drag: none; 
    user-select: none;
}

th {
    background-color: #3e3e42;
    font-weight: bold;
}

td[contenteditable="true"]:focus {
    outline: 2px solid #0e639c;
    background-color: #333333;
}

.map-list-btn {
    display: block;
    width: 100%;
    text-align: left;
    margin-bottom: 8px;
    background-color: #333333;
    border: 1px solid #444444;
}

.map-list-btn:hover {
    background-color: #444444;
}

.top-dashboard {
    flex: 0 0 50px;
    background-color: #252526;
    border-bottom: 1px solid #444;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
}

.dash-info {
    color: #cccccc;
    font-size: 0.95rem;
}

.dash-buttons {
    display: flex;
    gap: 10px;
}

.center-workspace {
    flex: 1; 
    padding: 20px;
    background-color: #1e1e1e;
    overflow-y: auto;
    
    /* CRITICAL FIX: This stops massive tables from pushing sidebars off the screen */
    min-width: 0; 
}

.workspace-split {
    display: flex;
    flex-direction: column; /* FORCES stacking: Table on top, Graph below */
    gap: 20px;
    align-items: center;
    width: 100%;
}

.table-container {
    width: 100%;
    background-color: #2d2d2d;
    border-radius: 5px;
    border: 1px solid #444444;
    overflow-x: auto; 
}

.map-info {
    padding: 15px;
    border-bottom: 1px solid #444;
    background-color: #252526;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}

#mapDescText {
    margin-bottom: 8px;
    color: #cccccc;
    font-style: italic;
}

#mapUnitsText {
    font-size: 0.85rem;
    color: #4CAF50;
    font-weight: bold;
}

.graph-container {
    width: 100%;
    height: 600px; /* Massive, beautiful 3D view */
    background-color: #2d2d2d;
    border: 1px solid #444;
    border-radius: 5px;
}

/* Highlights cells when selected via dragging */
td.selected {
    outline: 2px solid #ffffff !important;
    filter: brightness(1.2); /* Brightens the heatmap slightly */
    font-weight: bold;
    color: #ffffff !important;
    /* Creates a dark shadow around the text so it's always readable */
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8), -1px -1px 2px rgba(0, 0, 0, 0.8);
}

td.delta-changed {
    color: #111111 !important;
    font-weight: 700;
    text-shadow: 1px 1px 0 #ffffff, -1px -1px 0 #ffffff, 1px -1px 0 #ffffff, -1px 1px 0 #ffffff;
}

#mapTable {
    user-select: none;
    -webkit-user-select: none; /* For Chrome/Safari compatibility */
}

.math-btn {
    padding: 5px 10px;
    background: #333;
    color: white;
    border: 1px solid #555;
    border-radius: 3px;
    cursor: pointer;
}

.math-btn:hover {
    background: #444;
}

/* Map card and badge enhancements for renderMapsToScreen */
.map-card {
    background: #2f2f35;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.map-card h3 {
    margin-bottom: 8px;
    font-size: 0.95rem;
    color: #e0e0e0;
}

.badge {
    margin-left: 10px;
    font-size: 0.7rem;
    background: #4caf50;
    color: #ffffff;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 700;
    text-transform: uppercase;
}

.map-card p,
.map-card label {
    margin: 4px 0;
    color: #cccccc;
}

.map-card input[type="text"],
.map-card input[type="checkbox"] {
    margin-top: 4px;
}

/* Manual Maps stay default */

/* Auto-Discovered (High Confidence) */
.map-auto-verified {
    border-left: 4px solid #4CAF50; /* Green accent */
    background-color: rgba(76, 175, 80, 0.05);
}

/* Auto-Discovered (Low Confidence / Flat) */
.map-auto-warning {
    border-left: 4px solid #FF9800; /* Orange accent */
    background-color: rgba(255, 152, 0, 0.1);
}

/* Curated hand-written map pack entries */
.map-curated-guaranteed {
    border-left: 4px solid #9AA0A6;
    background-color: rgba(154, 160, 166, 0.14);
}

/* Injection visualizer page (shared stylesheet target) */
body.injection-page {
    display: block;
    height: auto;
    margin: 0;
    padding: 16px;
    background: #1e1e1e;
    color: #fff;
}

.inj-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    gap: 14px;
    flex-wrap: wrap;
}

.inj-title {
    margin: 0;
    color: #63b3ed;
    font-size: 2rem;
}

.inj-conn {
    color: #aaa;
    font-size: 0.9rem;
}

.inj-conn-dot {
    color: #4CAF50;
    font-size: 0.6rem;
    vertical-align: middle;
}

.inj-controls {
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.inj-slider-row,
.inj-dropdown-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.inj-control-label {
    width: 130px;
    color: #ccc;
    font-weight: 700;
    font-size: 0.86rem;
    white-space: nowrap;
}

.inj-slider-row input[type="range"] {
    flex-grow: 1;
    cursor: pointer;
}

.inj-dropdown-row select {
    min-width: 280px;
    padding: 6px 8px;
    background: #333;
    color: #fff;
    border: 1px solid #555;
    border-radius: 4px;
    outline: none;
    font-size: 0.86rem;
}

.inj-value {
    width: 130px;
    text-align: right;
    color: #7ec8ff;
    font-size: 0.9rem;
    font-weight: 700;
}

.inj-viz-shell {
    border: 1px solid #444;
    border-radius: 8px;
    background: #252526;
    padding: 10px;
}

.inj-custom-legend {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    color: #ddd;
    font-size: 0.84rem;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.inj-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
}

.inj-legend-color {
    width: 10px;
    height: 10px;
    border-radius: 6px;
    display: inline-block;
}

.inj-soi {
    background: #4FC3F7;
}

.inj-doi {
    background: #66BB6A;
}

.inj-eoi {
    background: #FF8A65;
}

.inj-soft-zone {
    background: rgba(255, 184, 77, 0.55);
}

.inj-hard-zone {
    background: rgba(255, 82, 82, 0.62);
}

.inj-readout {
    display: grid;
    grid-template-columns: repeat(3, minmax(150px, 1fr));
    gap: 8px;
    margin-bottom: 8px;
}

.inj-read-cell {
    font-size: 0.82rem;
    color: #d8d8d8;
    background: #1f1f1f;
    border: 1px solid #3c3c3c;
    border-radius: 5px;
    padding: 6px 8px;
}

.inj-read-cell strong {
    color: #7fc8ff;
}

#warningBox {
    display: none;
    margin-bottom: 10px;
    border-radius: 6px;
    padding: 8px 10px;
    background: rgba(255, 82, 82, 0.1);
    border: 1px solid #ff5252;
    color: #ff9d9d;
    font-size: 0.84rem;
}

#warningBox.soft {
    background: rgba(255, 184, 77, 0.12);
    border-color: #ffb84d;
    color: #ffdca2;
}

#plot {
    width: 100%;
    height: calc(100vh - 275px);
    min-height: 400px;
    border: 1px solid #444;
    border-radius: 8px;
    background: #252526;
}

@media (max-width: 900px) {
    .inj-slider-row,
    .inj-dropdown-row {
        flex-direction: column;
        align-items: stretch;
    }

    .inj-control-label,
    .inj-value {
        width: auto;
        text-align: left;
    }

    .inj-dropdown-row select {
        min-width: 100%;
    }

    .inj-readout {
        grid-template-columns: 1fr;
    }

    #plot {
        height: calc(100vh - 340px);
    }
}