html, body {
    margin: 0;
    padding: 0;
    overflow: hidden; /* Prevent scrollbars from appearing */
    width: 100%;
    height: 100%;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #eee;
    background-color: #1a1a1a;
}

#container {
    display: flex;
    width: 100%;
    height: 100%;
}

#controls-container {
    flex: 1;
    padding: 1em;
    background-color: #282828;
    overflow-y: auto;
}

.institution-logo { position: relative; width: 100%; max-width: 260px; aspect-ratio: 2.8; overflow: hidden; margin: 0 auto 14px; }
.institution-logo img { position: absolute; width: 190%; max-width: none; height: auto; left: -23%; top: -35%; }

#simulation-container {
    flex: 3;
}

#right-column-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1em;
    background-color: #282828;
    overflow-y: auto;
}

#telemetry-container {
    margin-bottom: 2em;
}

#panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 300px; /* Example width, can be adjusted */
    height: 100%;
    background-color: #282828;
    padding: 15px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow-y: auto; /* Allow scrolling if content overflows vertically */
    z-index: 100; /* Ensure panel is above the 3D scene */
    box-shadow: 2px 0 5px rgba(0,0,0,0.5);
}

#info {
    margin-bottom: 15px;
    text-align: center;
    color: white;
}

#info h1 {
    font-size: 1.5em;
    margin: 0;
}

#panel h2 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 16px;
    text-align: center;
    border-bottom: 1px solid #0f0;
    padding-bottom: 5px;
    flex-shrink: 0;
    color: #0f0; /* Green for telemetry header */
}

.control-group {
    margin-bottom: 10px;
}

.control-group label {
    display: block;
    margin-bottom: 5px;
    color: #ccc;
}

.control-group input[type="text"],
.control-group select {
    width: 100%;
    padding: 5px;
    box-sizing: border-box;
    background-color: #444;
    border: 1px solid #666;
    color: #eee;
    border-radius: 3px;
}

#panel h3 {
    color: #00ff00;
    border-bottom: 1px solid #555;
    padding-bottom: 5px;
    margin-top: 20px;
    margin-bottom: 15px;
    font-size: 1.1em;
}

.controls {
    margin-top: 20px; /* Add some space above controls */
}

#graph-container {
    flex-grow: 1; /* Allows graph container to take available space */
    display: flex;
    flex-direction: column; /* Stack charts vertically */
    gap: 10px; /* Space between charts */
    overflow-y: auto; /* Allow scrolling if charts overflow vertically */
    margin-bottom: 20px; /* Space below graph container */
}

#graph-container canvas {
    width: 100% !important; /* Important to override Chart.js inline styles */
    height: auto !important; /* Maintain aspect ratio */
    max-height: 200px; /* Limit individual chart height */
    background-color: #333;
    border-radius: 5px;
    padding: 5px;
    box-sizing: border-box;
}

/* Style for the sound button */
#sound_button {
    width: 100%; /* Make button full width of panel */
    padding: 10px 20px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    margin-top: 10px; /* Space above button */
}

#sound_button:hover {
    background-color: #0056b3;
}

/* Telemetry display styles */
.telemetry-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    font-size: 1.1em;
}

.telemetry-item span:first-child {
    font-weight: bold;
    color: #00ff00; /* Green for labels */
}

.telemetry-item span:last-child {
    color: #fff;
}

/* Slider styles */
.slider-group {
    margin-bottom: 10px;
}

.slider-group label {
    display: block;
    margin-bottom: 5px;
    color: #ccc;
}

.slider-group input[type="range"] {
    width: 100%;
    -webkit-appearance: none;
    height: 8px;
    background: #555;
    outline: none;
    opacity: 0.7;
    transition: opacity .2s;
    border-radius: 5px;
}

.slider-group input[type="range"]:hover {
    opacity: 1;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
}

.slider-group input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
}

.slider-value {
    float: right;
    color: #00ff00;
}
/* Panel compacto: etiqueta y campo numérico en una sola fila. */
#controls-container {
    flex: 0 0 300px;
    box-sizing: border-box;
    padding: 12px;
}
#controls-container h2 {
    font-size: 15px;
    margin: 14px 0 9px;
}
#controls-container h2:first-child { margin-top: 0; }
#controls-container .slider-group,
#controls-container .control-group {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 105px;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
#controls-container [hidden] { display: none !important; }
#controls-container label {
    margin: 0;
    font-size: 12px;
}
#controls-container input[type="number"],
#controls-container select {
    width: 100%;
    min-width: 0;
    height: 28px;
    padding: 3px 5px;
    box-sizing: border-box;
    background: #383838;
    border: 1px solid #666;
    border-radius: 4px;
    color: #eee;
    font-size: 12px;
    color-scheme: dark;
}
#controls-container input[type="number"]::-webkit-inner-spin-button {
    opacity: 1;
}
#controls-container input:disabled { opacity: 0.45; }
#controls-container input:invalid { border-color: #e9a461; }
#controls-container .control-group:has(select) { grid-template-columns: 1fr; gap: 4px; }
#controls-container p { font-size: 11px; margin: 3px 0 7px; line-height: 1.35; }
#control_description { grid-column: 1 / -1; }
#sound_button { font-size: 13px; padding: 7px; margin-top: 0; }

/* Parámetros en tres columnas para dejar espacio vertical a los demás controles. */
#controls-container .parameter-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    margin-bottom: 8px;
}
#controls-container .parameter-grid .slider-group,
#controls-container .parameter-grid .control-group {
    grid-template-columns: minmax(0, 1fr);
    gap: 3px;
    margin: 0;
}
#controls-container .parameter-grid label { font-size: 11px; }

/* Osciloscopios Plotly configurables. */
#right-column-container { flex: 1.4; min-width: 300px; }
#telemetry-container { margin-bottom: 12px; }
#scope-settings { margin-bottom: 10px; font-size: 12px; }
#scope-settings summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
#scope-signals { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 8px; }
#scope-settings select, #scope-settings button {
    background: #383838; color: #eee; border: 1px solid #666;
    border-radius: 4px; padding: 4px; margin: 3px;
}
#graph-container { display: grid; align-content: start; gap: 10px; overflow: visible; }
.scope-card { min-width: 0; background: #252a30; border: 1px solid #404851; border-radius: 6px; overflow: hidden; }
.scope-card[hidden], #scope-empty[hidden] { display: none; }
.scope-header { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; font-size: 12px; }
.scope-header button { background: transparent; color: #b8c6d4; border: 0; font-size: 20px; cursor: pointer; }
.scope-header button:hover { color: #ff786b; }
.scope-plot { width: 100%; min-width: 0; }

#csv-controls { margin-bottom: 10px; font-size: 12px; }
#csv-controls button { padding: 5px 8px; background: #383838; color: #eee; border: 1px solid #666; border-radius: 4px; cursor: pointer; }
#csv-status { margin: 5px 0; font-size: 11px; color: #bac7d3; }

.scope-layout-controls {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 8px;
}
#scope-settings .scope-layout-controls select,
#scope-settings .scope-layout-controls button {
    margin: 0;
    min-width: 0;
}
.scope-layout-controls label { font-size: 11px; }
#scope-settings .scope-layout-controls button {
    margin-left: auto;
    flex: 0 0 auto;
    font-size: 11px;
}

#csv-controls > label { display: block; margin-bottom: 4px; }
#csv-controls select {
    background: #383838; color: #eee; border: 1px solid #666;
    border-radius: 4px; padding: 4px; color-scheme: dark;
}
#csv-controls > select { width: 100%; margin-bottom: 7px; }
#csv-record[hidden] { display: none; }

/* Vista docente junto al motor 3D. */
#middle-panel { flex: 3; min-width: 0; display: flex; flex-direction: column; }
.view-tabs { display: flex; gap: 4px; padding: 8px; background: #242930; }
.view-tabs button { background: #303842; color: #cad7e3; border: 1px solid #4c5866; border-radius: 5px; padding: 8px 12px; cursor: pointer; }
.view-tabs button[aria-selected="true"] { background: #315571; color: #fff; border-color: #79b9df; }
#middle-panel #simulation-container { flex: 1; min-height: 0; }
#simulation-container canvas { display: block; }
#middle-panel [hidden] { display: none !important; }
#diagram-panel { flex: 1; min-height: 0; overflow: auto; padding: 16px; background: #1d242d; container-type: inline-size; container-name: teaching; }
#diagram-panel h2 { font-size: 18px; margin: 0 0 8px; }
#diagram-description { font-size: 13px; color: #b9cad9; line-height: 1.5; }
#block-diagram { overflow-x: auto; background: #141b23; border: 1px solid #3b4857; border-radius: 8px; }
#block-diagram svg { display: block; width: 100%; min-width: 1000px; }
#model-teaching { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin-top: 14px; align-items: stretch; }
.teaching-card { background: #262f3a; border: 1px solid #3c4c5d; border-radius: 7px; padding: 12px; margin-top: 10px; font-size: 12px; line-height: 1.6; }
.teaching-card h3 { font-size: 14px; color: #8ed5ff; margin: 0 0 8px; }
.teaching-card p { margin: 6px 0; }
.teaching-card code { font-size: 12px; overflow-wrap: anywhere; color: #e4edf6; }
.teaching-card table { width: 100%; border-collapse: collapse; }
.teaching-card td { border-bottom: 1px solid #3c4652; padding: 3px 5px; }
.diagram-values { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 6px; font-variant-numeric: tabular-nums; }

/* Orden fijo: ecuaciones, parámetros, planta y control; señales debajo. */
#model-teaching > .teaching-card { margin-top: 0; min-width: 0; }
.teaching-card { box-sizing: border-box; overflow-wrap: anywhere; }
.teaching-signals { width: 100%; margin-top: 12px; }
.diagram-values { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 18px; }
#expand-diagram { margin-left: auto; }
#middle-panel.diagram-expanded {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: #1d242d;
}
@container teaching (min-width: 600px) {
    #model-teaching { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .diagram-values { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@container teaching (min-width: 1100px) {
    #model-teaching { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .diagram-values { grid-template-columns: repeat(6, minmax(0, 1fr)); }
    .teaching-card { padding: 16px; font-size: 13px; }
    .teaching-card h3 { font-size: 16px; }
}
@container teaching (max-width: 359px) {
    .diagram-values { grid-template-columns: minmax(0, 1fr); }
}
