/* ==========================================================================
   CSS GLOBAL Y TIPOGRAFÍA
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: #f3f4f6; /* Gris muy claro clínico */
    color: #1f2937; /* Gris oscuro para alta legibilidad */
    line-height: 1.5;
    padding-bottom: 2rem;
}

/* ==========================================================================
   NAVBAR & ESTADOS
   ========================================================================== */
.navbar {
    background-color: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.8rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.brand h1 {
    font-size: 1.35rem;
    font-weight: 700;
    color: #111827;
    letter-spacing: -0.025em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.badge-live {
    background-color: #ef4444;
    color: #ffffff;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    letter-spacing: 0.05em;
    animation: pulseRed 1.5s infinite;
}

.heart-pulse-icon {
    width: 28px;
    height: 28px;
    background-color: #0d9488; /* Verde médico */
    border-radius: 6px;
    position: relative;
}

.heart-pulse-icon::after {
    content: "♥";
    color: #ffffff;
    font-size: 1.1rem;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: #f9fafb;
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    border: 1px solid #f3f4f6;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot.connected {
    background-color: #10b981;
    box-shadow: 0 0 8px #10b981;
}

.status-dot.disconnected {
    background-color: #d1d5db;
}

.status-text {
    font-size: 0.8rem;
    font-weight: 500;
    color: #4b5563;
}

/* ==========================================================================
   LAYOUT PRINCIPAL
   ========================================================================== */
.dashboard {
    max-width: 1400px;
    margin: 1.5rem auto;
    padding: 0 1.5rem;
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1.5rem;
}

@media (max-width: 1024px) {
    .dashboard {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   COMPONENTES: TARJETAS (CARDS)
   ========================================================================== */
.card {
    background-color: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.03), 0 2px 4px -1px rgba(0, 0, 0, 0.02);
}

.sidebar h2 {
    font-size: 1rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 1rem;
    letter-spacing: -0.01em;
}

.divider {
    border: 0;
    height: 1px;
    background-color: #e5e7eb;
    margin: 1.5rem 0;
}

/* Formularios */
.form-group {
    margin-bottom: 1rem;
}

.form-row {
    display: flex;
    gap: 0.8rem;
}

.form-group.col {
    flex: 1;
}

label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: #6b7280;
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

input[type="text"],
input[type="number"],
input[type="email"],
select {
    width: 100%;
    padding: 0.55rem 0.75rem;
    font-family: inherit;
    font-size: 0.85rem;
    color: #1f2937;
    background-color: #f9fafb;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    transition: all 0.2s ease;
}

input:focus,
select:focus {
    outline: none;
    border-color: #0d9488;
    background-color: #ffffff;
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1.2rem;
}

.checkbox-group input {
    width: 16px;
    height: 16px;
    accent-color: #0d9488;
}

.checkbox-group label {
    margin-bottom: 0;
    text-transform: none;
    font-size: 0.85rem;
    font-weight: 500;
    color: #374151;
}

.form-help {
    font-size: 0.7rem;
    color: #9ca3af;
    margin-top: 0.8rem;
    text-align: center;
}

/* Botones */
.btn {
    width: 100%;
    padding: 0.65rem 1rem;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background-color: #0f172a;
    color: #ffffff;
}

.btn-primary:hover {
    background-color: #1e293b;
}

.btn-secondary {
    background-color: #f3f4f6;
    color: #374151;
    border: 1px solid #e5e7eb;
}

.btn-secondary:hover {
    background-color: #e5e7eb;
}

.btn-success {
    background-color: #0d9488;
    color: #ffffff;
}

.btn-success:hover {
    background-color: #0f766e;
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-top: 1rem;
}

/* ==========================================================================
   METRIC CARDS (INFORMACIÓN NUMÉRICA)
   ========================================================================== */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
}

.metric-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 140px;
}

.metric-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.metric-header h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.metric-icon {
    width: 20px;
    height: 20px;
    opacity: 0.6;
}

.ecg-icon { background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="%230d9488"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19V6l12-3v13M9 19c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zm12-3c0 1.105-1.343 2-3 2s-3-.895-3-2 1.343-2 3-2 3 .895 3 2zM9 10l12-3"/></svg>') no-repeat center; }
.oximeter-icon { background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="%233b82f6"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/></svg>') no-repeat center; }
.risk-icon { background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="%23ea580c"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/></svg>') no-repeat center; }

.metric-value {
    font-size: 2.2rem;
    font-weight: 700;
    color: #111827;
    margin: 0.4rem 0;
}

.metric-value .unit {
    font-size: 0.95rem;
    font-weight: 500;
    color: #9ca3af;
}

.metric-footer {
    font-size: 0.75rem;
    font-weight: 600;
}

/* Alertas de Tarjetas */
.text-success { color: #059669; }
.text-warning { color: #d97706; }
.text-danger { color: #dc2626; }

/* Animación crítica para alertas en tarjeta */
.alert-pulse-card {
    animation: pulseBorderRed 1.5s infinite;
    background-color: #fff1f2 !important;
}

/* ==========================================================================
   MONITOR OSCILOSCOPIO (CANVAS)
   ========================================================================== */
.monitor-card {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.monitor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.8rem;
}

.monitor-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: #374151;
}

.legend {
    display: flex;
    gap: 1rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #4b5563;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.ecg-color { background-color: #008080; } /* Verde azulado médico oscuro */
.ppg-color { background-color: #0056B3; } /* Azul cobalto */

.canvas-container {
    position: relative;
    width: 100%;
    height: 380px;
    background-color: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Superposición de Alerta en Canvas */
.sensor-alert-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease;
    z-index: 10;
}

.sensor-alert-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.alert-box {
    text-align: center;
    padding: 2rem;
    max-width: 400px;
}

.alert-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 0.5rem;
}

.alert-box h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #991b1b;
    margin-bottom: 0.35rem;
}

.alert-box p {
    font-size: 0.85rem;
    color: #4b5563;
}

/* ==========================================================================
   ALERTA FLOTANTE DEL SISTEMA
   ========================================================================== */
.system-alert {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background-color: #991b1b;
    color: #ffffff;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
}

.system-alert.hidden {
    transform: translateY(100px);
    opacity: 0;
    pointer-events: none;
}

.sys-alert-content {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.sys-alert-icon {
    font-size: 1.5rem;
    animation: bounce 1s infinite alternate;
}

.sys-alert-text {
    display: flex;
    flex-direction: column;
}

.sys-alert-text strong {
    font-size: 0.9rem;
    font-weight: 700;
}

.sys-alert-text span {
    font-size: 0.8rem;
    opacity: 0.9;
}

/* ==========================================================================
   ANIMACIONES
   ========================================================================== */
@keyframes pulseRed {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes pulseBorderRed {
    0%, 100% {
        border-color: #e5e7eb;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.03);
    }
    50% {
        border-color: #f43f5e;
        box-shadow: 0 0 10px rgba(244, 63, 94, 0.2);
    }
}

@keyframes bounce {
    0% { transform: translateY(0); }
    100% { transform: translateY(-4px); }
}
