@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --blue:    #0077FF;
    --blue-dk: #005ecc;
    --success: #10b981;
    --warning: #f59e0b;
    --danger:  #ef4444;
    --bg:      #F8FAFC;
    --surface: #FFFFFF;
    --border:  #e2e8f0;
    --text:    #1E293B;
    --muted:   #64748B;
    --radius:  10px;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ===== LAYOUT ===== */
.contenedor { max-width: 1300px; margin: 0 auto; padding: 2rem; }

.section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 1rem;
}

/* ===== BANNER CRÍTICO ===== */
.banner-critico {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    background: #fee2e2;
    border: 1px solid #fca5a5;
    border-left: 3px solid var(--danger);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
}
.banner-critico-content {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    color: var(--danger);
    font-weight: 600;
    font-size: 0.875rem;
}
.banner-critico-close {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px;
}

/* ===== PAGE HEADER ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding: 1.25rem 1.5rem;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.page-header h1 { font-size: 1.4rem; font-weight: 700; color: var(--text); margin-bottom: 0.2rem; }
.page-header p  { font-size: 0.875rem; color: var(--muted); }

/* ===== KPI GRID ===== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.kpi-card {
    background: var(--surface);
    padding: 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    border-left: 3px solid transparent;
}
.kpi-card.normal      { border-left-color: var(--success); }
.kpi-card.advertencia { border-left-color: var(--warning); }
.kpi-card.critico     { border-left-color: var(--danger);  }

.kpi-header { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }

.kpi-icon {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}
.kpi-icon.presion   { background: #fee2e2; color: var(--danger);  }
.kpi-icon.frecuencia{ background: #fef3c7; color: var(--warning); }
.kpi-icon.estado    { background: #d1fae5; color: var(--success); }
.kpi-icon.registros { background: #dbeafe; color: var(--blue);    }

.kpi-label {
    font-size: 0.78rem;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.kpi-value { font-size: 1.75rem; font-weight: 700; color: var(--text); line-height: 1.2; margin-bottom: 0.2rem; }
.kpi-subtitle { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.5rem; }
.kpi-trend { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--muted); }
.kpi-trend.up   { color: var(--success); }
.kpi-trend.down { color: var(--danger);  }

.kpi-progress { margin-top: 0.75rem; }
.progress-bar-mini { height: 5px; background: #e2e8f0; border-radius: 999px; overflow: hidden; margin-bottom: 0.35rem; }
.progress-fill-mini { height: 100%; background: var(--blue); border-radius: 999px; transition: width 0.4s ease; }
.progress-text { font-size: 0.75rem; color: var(--muted); }

/* ===== MAIN GRID ===== */
.main-grid { display: grid; grid-template-columns: 1fr 300px; gap: 1.5rem; }

/* ===== CARDS ===== */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 1rem;
    overflow: hidden;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.card-title { display: flex; align-items: center; gap: 0.625rem; }
.card-title i { color: var(--blue); font-size: 1rem; }
.card-title h2, .card-title h3 { font-size: 1rem; font-weight: 600; color: var(--text); }
.card-actions { display: flex; gap: 0.5rem; }

/* ===== BOTONES ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--radius);
    cursor: pointer;
    border: 1px solid transparent;
    font-family: 'Inter', sans-serif;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-primary { background: var(--blue); color: white; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dk); border-color: var(--blue-dk); }
.btn-secondary { background: var(--surface); color: var(--blue); border-color: var(--blue); }
.btn-secondary:hover { background: #eff6ff; }

.btn-header {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-header:hover { background: var(--bg); }
.btn-yaqui-toggle {
    border-color: var(--border);
}
.btn-yaqui-toggle.active {
    background: var(--blue);
    color: white;
}
.btn-yaqui-toggle.active:hover {
    background: var(--blue-dk);
}

.btn-action {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.375rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.btn-action:hover { background: var(--blue); color: white; border-color: var(--blue); }
.btn-action.btn-danger:hover { background: var(--danger); color: white; border-color: var(--danger); }

.btn-help {
    width: 28px;
    height: 28px;
    background: #eff6ff;
    border: none;
    border-radius: 50%;
    color: var(--blue);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    transition: background 0.15s;
}
.btn-help:hover { background: var(--blue); color: white; }

/* ===== FORMS ===== */
.form-card form { padding: 1.25rem; }
.form-description { font-size: 0.875rem; color: var(--muted); margin-bottom: 1.25rem; }

.vital-ranges-guide {
    background: #f0fdf4;
    border-left: 3px solid var(--success);
    padding: 0.625rem 0.875rem;
    border-radius: 6px;
    margin-bottom: 1.25rem;
}
.range-badge { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--text); }

.inputs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.input-group { display: flex; flex-direction: column; }
.input-group label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.4rem;
}
.input-group label i { color: var(--blue); font-size: 0.85rem; }
.input-wrapper { position: relative; }
.input-wrapper input {
    width: 100%;
    padding: 0.625rem 3.5rem 0.625rem 0.875rem;
    font-size: 0.9rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.15s, box-shadow 0.15s;
    font-family: 'Inter', sans-serif;
}
.input-wrapper input:focus {
    outline: none;
    background: var(--surface);
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(0,119,255,0.1);
}
.input-wrapper input.success { border-color: var(--success); }
.input-wrapper input.warning { border-color: var(--warning); }
.input-wrapper input.error   { border-color: var(--danger);  }
.input-unit {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.78rem;
    color: var(--muted);
    font-weight: 600;
    pointer-events: none;
}
.form-actions { display: flex; gap: 0.75rem; }

/* ===== ALERTAS ===== */
.alerta-container { margin-bottom: 1rem; }
.alerta {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius);
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
    font-weight: 500;
}
.alerta-normal      { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alerta-advertencia { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alerta-critica     { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

.alertas-sidebar { padding: 0.75rem; min-height: 48px; }
.alertas-empty { display: flex; align-items: center; gap: 0.5rem; color: var(--success); font-size: 0.85rem; font-weight: 500; }
.alertas-silenciadas { font-size: 0.85rem; color: var(--muted); font-style: italic; }
.alertas-sidebar .alerta { font-size: 0.8rem; padding: 0.5rem 0.75rem; }

.alerta-meds-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
}
.alerta-meds-summary-left { display: flex; align-items: center; gap: 0.5rem; color: var(--warning); font-size: 0.8rem; font-weight: 600; }
.alerta-meds-chevron { color: var(--warning); font-size: 0.7rem; transition: transform 0.2s; }
.alerta-meds-detail {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-top: none;
    border-radius: 0 0 6px 6px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}
.alerta-meds-item { display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.75rem; font-size: 0.78rem; color: var(--muted); border-bottom: 1px solid rgba(0,0,0,0.04); }
.alerta-meds-item:last-child { border-bottom: none; }
.alerta-meds-item i { color: var(--warning); font-size: 0.7rem; flex-shrink: 0; }

/* ===== MENSAJES ===== */
.mensaje-guardado {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    margin-top: 0.75rem;
    transition: opacity 0.3s;
}
.mensaje-exito { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.mensaje-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* ===== GRÁFICA ===== */
.chart-container { padding: 1rem 1.25rem; height: 300px; position: relative; }
.chart-actions { display: flex; gap: 0.5rem; }
.btn-chart-period {
    padding: 0.35rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.btn-chart-period:hover { border-color: var(--blue); color: var(--blue); }
.btn-chart-period.active { background: var(--blue); color: white; border-color: var(--blue); }

/* ===== ESTADÍSTICAS ===== */
.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    padding: 1.25rem;
}
.stat-item {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.875rem 1rem;
    background: var(--bg);
    border-radius: var(--radius);
    text-align: center;
}
.stat-label { font-size: 0.75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
.stat-value { font-size: 1.4rem; font-weight: 700; color: var(--blue); }

/* ===== MEDICATIONS CHECKLIST ===== */
.medications-checklist { padding: 1rem; }
.medication-item {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    border-left: 3px solid transparent;
}
.medication-item.taken   { background: #f0fdf4; border-left-color: var(--success); }
.medication-item.pending { background: #fffbeb; border-left-color: var(--warning); }
.medication-checkbox {
    width: 22px;
    height: 22px;
    border: 1.5px solid var(--border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.75rem;
    color: transparent;
}
.medication-item.taken .medication-checkbox { background: var(--success); border-color: var(--success); color: white; }
.medication-info  { flex: 1; min-width: 0; }
.medication-name  { font-weight: 600; font-size: 0.875rem; color: var(--text); }
.medication-dose  { font-size: 0.8rem; color: var(--muted); }
.medication-actions { display: flex; gap: 0.4rem; }

/* ===== TABLAS ===== */
.table-container { padding: 1rem; overflow-x: auto; }
.historial-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.historial-table thead th {
    text-align: left;
    padding: 0.625rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--muted);
    background: var(--bg);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 1px solid var(--border);
}
.historial-table tbody tr { border-bottom: 1px solid var(--border); }
.historial-table tbody tr:hover { background: var(--bg); }
.historial-table tbody td { padding: 0.625rem 0.75rem; color: var(--muted); }
.historial-table tbody td strong { color: var(--text); }

/* ===== BADGES ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.625rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-normal      { background: #f0fdf4; color: #166534; }
.badge-advertencia { background: #fffbeb; color: #92400e; }
.badge-critico     { background: #fee2e2; color: #991b1b; }

/* ===== SIDEBAR ===== */
.sidebar-card { margin-bottom: 1rem; }
.sidebar-card .card-title h3 { font-size: 0.9rem; }
.consejos-list { padding: 0.75rem; }
.consejo-item { display: flex; align-items: flex-start; gap: 0.625rem; padding: 0.625rem; margin-bottom: 0.4rem; border-radius: 6px; }
.consejo-item:hover { background: var(--bg); }
.consejo-item i { color: var(--success); font-size: 0.85rem; margin-top: 0.125rem; flex-shrink: 0; }
.consejo-item p { font-size: 0.85rem; color: var(--muted); line-height: 1.5; }

/* ===== EMPTY STATE ===== */
.empty-state { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.empty-state svg { width: 48px; height: 48px; margin-bottom: 0.75rem; opacity: 0.3; }

/* ===== MODAL ===== */
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 9999; align-items: center; justify-content: center; padding: 20px; }
.modal.show { display: flex; }
.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    max-width: 540px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    border: 1px solid var(--border);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 1rem; font-weight: 600; color: var(--text); }
.modal-close { width: 28px; height: 28px; background: var(--bg); border: none; border-radius: 50%; color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.15s; }
.modal-close:hover { background: var(--danger); color: white; }
.modal-body { padding: 1.25rem; }
.ayuda-section { margin-bottom: 1.5rem; }
.ayuda-section h4 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.75rem; color: var(--text); }
.ayuda-section ol, .ayuda-section ul { padding-left: 1.25rem; }
.ayuda-section li { margin-bottom: 0.5rem; color: var(--muted); font-size: 0.875rem; line-height: 1.6; }
.badge-demo { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; margin-right: 0.35rem; }

/* ===== FOOTER ===== */
.footer { margin-top: 3rem; background: var(--surface); border-top: 1px solid var(--border); padding: 2rem; }
.footer-container { max-width: 1300px; margin: 0 auto; display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 2rem; margin-bottom: 1.5rem; }
.footer-brand p { font-size: 0.85rem; color: var(--muted); margin-top: 0.5rem; line-height: 1.6; }
.logo-footer { height: 28px; }
.footer-links h4, .footer-contact h4 { font-size: 0.85rem; font-weight: 600; color: var(--text); margin-bottom: 0.75rem; }
.footer-links a { display: block; color: var(--muted); text-decoration: none; margin-bottom: 0.4rem; font-size: 0.85rem; }
.footer-links a:hover { color: var(--blue); }
.footer-contact p { margin-bottom: 0.4rem; font-size: 0.85rem; color: var(--muted); }
.footer-contact i { margin-right: 0.4rem; }
.footer-bottom { max-width: 1300px; margin: 0 auto; padding-top: 1rem; border-top: 1px solid var(--border); display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; font-size: 0.8rem; color: var(--muted); }
.disclaimer { font-style: italic; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1100px) {
    .main-grid { grid-template-columns: 1fr; }
    .footer-container { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
    .contenedor { padding: 1rem; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .inputs-grid { grid-template-columns: 1fr; }
    .form-actions { flex-direction: column; }
    .btn { width: 100%; }
    .chart-container { height: 240px; }
    .stats-container { grid-template-columns: 1fr 1fr; }
    .footer-container { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .stats-container { grid-template-columns: 1fr; }
    .card-header { flex-wrap: wrap; gap: 0.75rem; }
}