/* Brutalist / Technical Archive Theme */
:root {
    --bg-color: #f4f1ea;
    /* Papier technique écru */
    --panel-bg: #f9f7f4;
    --text-color: #000000;
    --accent-color: #000000;
    --grid-line: 1px solid #000000;
    --mono-font: 'Courier New', 'Roboto Mono', monospace;
    --sans-font: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    --spacing: 0;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--sans-font);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    /* ENABLE SCROLL */
}

/* --- Layout Grid --- */
.grid-container {
    display: grid;
    min-height: 100vh;
    /* Allow growth */
    height: auto;
    width: 100vw;
    grid-template-columns: 2fr 1fr;
    /* Rows: Header, Tabs, Main View, Graphs, Theory, Footer */
    grid-template-rows: auto auto minmax(400px, 60vh) minmax(300px, auto) auto auto;
    grid-template-areas:
        "header header"
        "tabs tabs"
        "viewport controls"
        "graphs monitors"
        "theory theory"
        "footer footer";
    border: var(--grid-line);
}

/* For smaller screens */
@media (max-width: 1024px) {
    .grid-container {
        display: flex;
        flex-direction: column;
        height: auto;
    }
}

/* --- Sections --- */
section,
header,
footer {
    border-right: var(--grid-line);
    border-bottom: var(--grid-line);
    padding: 1rem;
    position: relative;
    background: var(--bg-color);
}

.header {
    grid-area: header;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.8rem 1.5rem;
    background: #ffffff;
    border-bottom: 2px solid black;
}

/* --- Navigation Tabs --- */
.tabs-nav {
    grid-area: tabs;
    display: flex;
    background: #e0e0e0;
    border-bottom: 2px solid #000;
}

.tab-btn {
    flex: 1;
    padding: 1rem;
    font-family: var(--sans-font);
    font-weight: bold;
    text-transform: uppercase;
    background: #d4d4d4;
    border: none;
    border-right: 1px solid #000;
    cursor: pointer;
    font-size: 0.9rem;
    letter-spacing: 0.5px;
    opacity: 0.7;
    transition: all 0.2s;
}

.tab-btn:hover {
    background: #ccc;
    opacity: 1;
}

.tab-btn.active {
    background: #fff;
    border-bottom: 2px solid #fff;
    /* Merge with content */
    margin-bottom: -2px;
    opacity: 1;
}

/* --- Lab Content Switching --- */
/* By default, lab-content containers follow the main grid layout */
.lab-content {
    display: contents;
    /* Allows children (viewport, controls, etc) to snap to grid-areas */
}

.hidden {
    display: none !important;
}

.viewport-box {
    grid-area: viewport;
    background: #e8e8e8;
    display: flex;
    flex-direction: column;
    padding: 0;
}

.controls-box {
    grid-area: controls;
    background: var(--panel-bg);
}

.monitors-box {
    grid-area: monitors;
    border-top: var(--grid-line);
}

.graphs-box {
    grid-area: graphs;
    display: flex;
    gap: 0;
    flex-wrap: wrap;
    /* Safety for small screens */
}

.theory-box {
    grid-area: theory;
    border-top: 2px solid black;
    background: #fff;
    /* REMOVED FIXED HEIGHT AND OVERFLOW TO ALLOW PAGE SCROLL */
    height: auto;
    overflow: visible;
}

.footer {
    grid-area: footer;
    font-family: var(--mono-font);
    font-size: 0.7rem;
    text-transform: uppercase;
    padding: 0.5rem;
    border: none;
    border-top: var(--grid-line);
}

/* --- Typography & Elements --- */
h1 {
    font-family: var(--sans-font);
    font-weight: 900;
    font-size: 1.5rem;
    letter-spacing: -1px;
    margin: 0;
    text-transform: uppercase;
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 1rem;
}

.ref-code {
    font-family: var(--mono-font);
    font-size: 0.8rem;
    opacity: 0.6;
}

.section-label {
    font-family: var(--mono-font);
    font-size: 0.8rem;
    margin: 0 0 1rem 0;
    text-transform: uppercase;
    border-bottom: 1px solid black;
    padding-bottom: 0.2rem;
    display: inline-block;
}

.digital-value {
    font-family: var(--mono-font);
    font-weight: bold;
    font-size: 1.1rem;
    background: #000;
    color: #fff;
    padding: 0.1rem 0.3rem;
    min-width: 60px;
    text-align: right;
    display: inline-block;
}

/* --- Controls --- */
.control-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    font-weight: bold;
    font-size: 0.9rem;
    margin-bottom: 0.3rem;
    text-transform: uppercase;
}

.range-readout {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

input[type="range"] {
    flex-grow: 1;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 2px;
    background: #000;
    border: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    background: #000;
    margin-top: -7px;
    border: 1px solid #000;
    border-radius: 0;
}

input[type="range"]:focus::-webkit-slider-thumb {
    background: #333;
}

.tech-select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #000;
    background: #fff;
    font-family: var(--mono-font);
    font-weight: bold;
    border-radius: 0;
    -webkit-appearance: none;
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, black 50%), linear-gradient(135deg, black 50%, transparent 50%);
    background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}

/* --- Monitors --- */
.data-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: #000;
    border: 1px solid #000;
    margin-bottom: 1rem;
}

.data-item {
    background: #fff;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
}

.data-item.highlight {
    background: #e6e6e6;
}

.data-item .label {
    font-size: 0.7rem;
    font-weight: bold;
    color: #666;
}

.data-item .value {
    font-family: var(--mono-font);
    font-size: 1.2rem;
    font-weight: bold;
}

.pv-module {
    border: 2px solid black;
    padding: 0.5rem;
    background: #fff;
    margin-top: 1rem;
}

.pv-readout div {
    font-family: var(--mono-font);
    font-size: 0.85rem;
    border-bottom: 1px dashed #ccc;
    padding: 0.2rem 0;
    display: flex;
    justify-content: space-between;
}

.efficiency-block {
    background: #000;
    color: #fff !important;
    padding: 0.3rem !important;
    margin-top: 0.3rem;
    font-weight: bold;
}

/* --- Canvas --- */
.canvas-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 400px;
    /* Ensure visibility */
    background: #222;
    overflow: hidden;
}

#simCanvas,
#pvCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

.overlay-info {
    position: absolute;
    top: 10px;
    left: 10px;
    font-family: var(--mono-font);
    color: #0f0;
    font-size: 0.8rem;
    pointer-events: none;
}

/* --- Graphs --- */
.graph-container {
    flex: 1;
    border-right: 1px solid #000;
    padding: 0.5rem;
    position: relative;
    min-height: 250px;
    min-width: 300px;
    /* stacking safety */
}

.graph-container:last-child {
    border-right: none;
}

/* --- Theory --- */
.theory-toggle {
    cursor: pointer;
    font-weight: bold;
    padding: 0.5rem;
    background: #eee;
    font-family: var(--mono-font);
    list-style: none;
}

.theory-toggle:hover {
    background: #ddd;
}

.theory-content {
    padding: 1rem;
    font-size: 0.9rem;
    line-height: 1.5;
    border-top: 1px solid #000;
}

/* --- Zoom Window --- */
.zoom-window {
    position: absolute;
    bottom: 0;
    right: 0;
    /* Moved to right */
    width: 250px;
    height: 250px;
    background: #000;
    border-top: 2px solid #fff;
    border-left: 2px solid #000;
    /* Border left */
    z-index: 10;
    display: flex;
    flex-direction: column;
}

.zoom-label {
    background: #000;
    color: #0f0;
    font-family: var(--mono-font);
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-bottom: 1px solid #333;
}

#zoomCanvas {
    width: 100%;
    height: 100%;
    background: #111;
    cursor: crosshair;
}