/* --- VARIABLES GLOBALES --- */
:root {
    --primary: #2563eb;
    --primary-dark: #1e3a8a;
    --bg: #f8fafc;
    --card: #ffffff;
    --border: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --terminal-bg: #0f172a;
    --success: #22c55e;
    --danger: #ef4444;
}

/* --- RESET Y BASE --- */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    padding: 15px;
    color: var(--text-main);
    margin: 0;
    line-height: 1.5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

/* --- HEADER --- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.main-title {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-main);
    margin: 0;
}

.status-bar {
    font-size: 0.7rem;
    font-weight: 800;
    padding: 4px 12px;
    border-radius: 20px;
    background: #dcfce7;
    color: #166534;
}

/* --- GRID Y PANELES --- */
.grid {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 15px;
}

@media (max-width: 900px) {
    .grid { grid-template-columns: 1fr; }
    .chart-header-wrapper { flex-direction: column; }
    .display-box { width: 100%; margin-top: 10px; }
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
    display: flex;
    flex-direction: column;
}

/* --- TERMINAL --- */
.terminal {
    height: 180px;
    background: var(--terminal-bg);
    color: #38bdf8;
    padding: 12px;
    border-radius: 8px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.75rem;
    overflow-y: auto;
    margin-bottom: 15px;
    border: 1px solid #1e293b;
}

/* --- CONTROLES (IZQUIERDA) --- */
.control-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f1f5f9;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 0.85rem;
    font-weight: 600;
}

.led-circle {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #94a3b8;
    transition: 0.3s;
}

/* --- INPUT DE COMANDOS MANUALES --- */
.command-row {
    display: flex;
    gap: 8px;
    margin-top: 5px;
}

.command-row input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.8rem;
    outline: none;
}

.command-row input:focus {
    border-color: var(--primary);
}

.command-row button {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0 15px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.2s;
}

.command-row button:hover {
    background: var(--primary-dark);
}

/* --- SWITCH --- */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #cbd5e1;
    transition: .4s;
    border-radius: 24px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 18px; width: 18px;
    left: 3px; bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider { background-color: var(--success); }
input:checked + .slider:before { transform: translateX(20px); }

/* --- PANEL DERECHO (HEADER Y DISPLAY) --- */
.chart-header-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
    gap: 15px;
}

.chart-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}

/* --- BOTONES DE TIEMPO --- */
.time-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.time-selector button {
    background: #f1f5f9;
    border: none;
    color: var(--text-muted);
    padding: 5px 10px;
    font-size: 0.65rem;
    border-radius: 4px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s;
}

.time-selector button:hover {
    background: #e2e8f0;
}

.time-selector button.active {
    background: var(--primary);
    color: white;
}

/* --- BOTÓN DE PAUSA --- */
.pause-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #fee2e2;
    color: #b91c1c;
    padding: 6px 12px;
    font-size: 0.7rem;
    border-radius: 6px;
    font-weight: 800;
    cursor: pointer;
    width: fit-content;
}

/* --- CUADRO AZUL (NIVEL) --- */
.display-box {
    background: var(--primary);
    color: white;
    padding: 15px 25px;
    border-radius: 10px;
    text-align: center;
    min-width: 140px;
}

.display-box label {
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 1px;
    opacity: 0.9;
    display: block;
    margin-bottom: 2px;
}

.display-box span {
    font-size: 2.5rem;
    font-weight: 800;
    line-height: 1;
    display: block;
}

/* --- GRÁFICA Y FOOTER --- */
.chart-container {
    position: relative;
    height: 350px;
    width: 100%;
}

.card-footer {
    margin-top: 15px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    text-align: right;
}

#last-update {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin: 0;
    font-weight: 500;
}