/* === Variables === */
:root {
    --primary: #007acd;
    --primary-dark: #005fa3;
    --primary-light: #e6f2fb;
    --primary-hover: #0069b4;
    --white: #ffffff;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --red: #dc2626;
    --red-light: #fef2f2;
    --orange: #ea580c;
    --orange-light: #fff7ed;
    --green: #16a34a;
    --green-light: #f0fdf4;
    --yellow: #ca8a04;
    --yellow-light: #fefce8;
    --sidebar-width: 250px;
    --topbar-height: 60px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    display: flex;
    min-height: 100vh;
}
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select, textarea {
    font-family: inherit;
    font-size: 0.875rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    outline: none;
    transition: border-color 0.2s;
    width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.75rem 1rem; }
th { font-weight: 600; font-size: 0.75rem; text-transform: uppercase; color: var(--gray-500); letter-spacing: 0.05em; }
td { font-size: 0.875rem; border-top: 1px solid var(--gray-200); }
tr:hover td { background: var(--gray-50); }

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    background: var(--gray-800);
    color: var(--white);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform 0.3s;
}
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo { height: 32px; width: auto; filter: brightness(0) invert(1); }
.sidebar-title { font-size: 1.1rem; font-weight: 700; }
.sidebar-nav { flex: 1; padding: 0.5rem 0; overflow-y: auto; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    color: var(--gray-400);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-item:hover { color: var(--white); background: rgba(255,255,255,0.05); }
.nav-item.active {
    color: var(--white);
    background: rgba(0,122,205,0.2);
    border-left-color: var(--primary);
}
.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,0.1);
    text-align: center;
    font-size: 0.75rem;
}
.sidebar-powered { color: var(--gray-400); }
.sidebar-link { color: var(--primary); display: block; margin-top: 0.25rem; }

/* === Main Content === */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* === Topbar === */
.topbar {
    height: var(--topbar-height);
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 50;
}
.menu-toggle { display: none; }
.menu-toggle svg { width: 24px; height: 24px; }
.topbar-title { flex: 1; font-size: 1.25rem; font-weight: 600; color: var(--gray-800); }
.topbar-status { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; color: var(--gray-500); }
.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--gray-400);
}
.status-dot.connected { background: var(--green); }

/* === Page Content === */
.page-content { padding: 1.5rem; flex: 1; }

/* === Cards === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary);
}
.stat-card.emergencia { border-left-color: var(--red); }
.stat-card.pendiente { border-left-color: var(--orange); }
.stat-card.resuelto { border-left-color: var(--green); }
.stat-label { font-size: 0.75rem; text-transform: uppercase; color: var(--gray-500); letter-spacing: 0.05em; font-weight: 600; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--gray-800); margin-top: 0.25rem; }
.stat-sub { font-size: 0.8rem; color: var(--gray-500); margin-top: 0.25rem; }

/* === Card / Table Container === */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
}
.card-title { font-size: 1rem; font-weight: 600; }
.card-body { padding: 0; }
.card-body.padded { padding: 1.25rem; }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: var(--radius);
    transition: all 0.2s;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--green); color: var(--white); }
.btn-success:hover { opacity: 0.9; }
.btn-danger { background: var(--red); color: var(--white); }
.btn-danger:hover { opacity: 0.9; }
.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.75rem; }
.btn-icon { padding: 0.4rem; border-radius: 6px; }
.btn-icon:hover { background: var(--gray-100); }

/* === Badges === */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.badge-emergencia { background: var(--red-light); color: var(--red); }
.badge-alta { background: var(--orange-light); color: var(--orange); }
.badge-normal { background: var(--primary-light); color: var(--primary); }
.badge-baja { background: var(--gray-100); color: var(--gray-600); }
.badge-pending { background: var(--yellow-light); color: var(--yellow); }
.badge-sent { background: var(--primary-light); color: var(--primary); }
.badge-acknowledged { background: var(--orange-light); color: var(--orange); }
.badge-resolved { background: var(--green-light); color: var(--green); }
.badge-failed { background: var(--red-light); color: var(--red); }
.badge-active { background: var(--green-light); color: var(--green); }
.badge-inactive { background: var(--gray-100); color: var(--gray-500); }

/* === Form === */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--gray-600); margin-bottom: 0.3rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-actions { display: flex; justify-content: flex-end; gap: 0.5rem; padding-top: 0.5rem; }
.checkbox-group { display: flex; gap: 1rem; flex-wrap: wrap; }
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    cursor: pointer;
}
.checkbox-label input { width: auto; }

/* === Filters === */
.filters {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: center;
}
.filters select, .filters input { width: auto; min-width: 160px; }

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 200;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 90%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
}
.modal-title { font-size: 1.1rem; font-weight: 600; }
.modal-close { font-size: 1.5rem; color: var(--gray-400); padding: 0.25rem; }
.modal-close:hover { color: var(--gray-700); }
.modal-body { padding: 1.25rem; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--gray-200);
}

/* === Toast === */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.toast {
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--white);
    box-shadow: var(--shadow-md);
    animation: slideIn 0.3s ease;
    max-width: 360px;
}
.toast-success { background: var(--green); }
.toast-error { background: var(--red); }
.toast-info { background: var(--primary); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* === Live Alert Feed === */
.alert-feed { max-height: 500px; overflow-y: auto; }
.alert-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--gray-100);
    transition: background 0.2s;
}
.alert-item:hover { background: var(--gray-50); }
.alert-item.new { animation: highlight 2s ease; }
@keyframes highlight { 0% { background: var(--primary-light); } 100% { background: transparent; } }
.alert-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}
.alert-icon.enfermeria { background: var(--primary-light); }
.alert-icon.medico { background: var(--green-light); }
.alert-icon.farmacia { background: var(--yellow-light); }
.alert-icon.emergencia { background: var(--red-light); }
.alert-info { flex: 1; }
.alert-info-title { font-weight: 600; font-size: 0.875rem; }
.alert-info-desc { font-size: 0.8rem; color: var(--gray-500); margin-top: 0.15rem; }
.alert-meta { text-align: right; flex-shrink: 0; }
.alert-meta-time { font-size: 0.75rem; color: var(--gray-400); }
.alert-meta-room { font-size: 0.85rem; font-weight: 600; color: var(--primary); }

/* === Empty state === */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-400);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 0.75rem; }
.empty-state p { font-size: 0.9rem; }

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .menu-toggle { display: block; }
    .form-row { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .filters { flex-direction: column; }
    .filters select, .filters input { width: 100%; }
}
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* === Table responsive === */
.table-responsive { overflow-x: auto; }
