:root {
  --primary: #ef4444;
  --primary-soft: rgba(239, 68, 68, 0.12);
  --growth: #22c55e;
  --growth-soft: rgba(34, 197, 94, 0.12);
  --warning: #f59e0b;
  --bg-main: #f8fafc;
  --surface: #ffffff;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #f8fafc;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.05);
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
  line-height: 1.6;
  font-size: 14px;
}

.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 100;
  overflow: hidden;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.brand-icon { font-size: 20px; line-height: 1; }
.brand-name { font-size: 16px; font-weight: 700; color: #f8fafc; letter-spacing: -0.3px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 16px 12px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255,255,255,0.07); color: #f8fafc; }
.nav-item.active { background: var(--primary-soft); color: var(--primary); }
.nav-icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }

.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.06); }
.auth-link {
  font-size: 12px; color: var(--sidebar-text);
  text-decoration: none; display: block; text-align: center;
  padding: 8px; border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.1);
}
.auth-link:hover { background: rgba(255,255,255,0.06); color: #f8fafc; }

.main-wrapper { margin-left: 240px; flex: 1; display: flex; flex-direction: column; }

.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 24px 32px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.page-title { font-size: 20px; font-weight: 700; color: var(--text-main); letter-spacing: -0.4px; }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; text-transform: capitalize; }
.top-bar-right { display: flex; align-items: center; gap: 12px; }
.last-updated { font-size: 12px; color: var(--text-muted); }

.section { padding: 24px 32px; }
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.section-title { font-size: 15px; font-weight: 600; color: var(--text-main); letter-spacing: -0.2px; }
.section-link { font-size: 13px; color: var(--primary); text-decoration: none; font-weight: 500; }
.section-link:hover { text-decoration: underline; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.kpi-card.kpi-highlight { border-color: var(--primary); background: var(--primary-soft); }
.kpi-card.kpi-highlight .kpi-value { color: var(--primary); }
.kpi-value { font-size: 26px; font-weight: 700; color: var(--text-main); line-height: 1.1; letter-spacing: -0.5px; }
.kpi-label { font-size: 12px; color: var(--text-muted); margin-top: 6px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.4px; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
}

.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left; padding: 12px 16px;
  font-size: 11.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}
.data-table td { padding: 11px 16px; border-bottom: 1px solid var(--border); color: var(--text-main); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #f8fafc; }
.data-table a { color: var(--text-main); text-decoration: none; font-weight: 600; }
.data-table a:hover { color: var(--primary); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-nsr    { background: #dcfce7; color: #166534; }
.badge-afib   { background: #fee2e2; color: #991b1b; }
.badge-warn   { background: #fef3c7; color: #92400e; }
.badge-info   { background: #dbeafe; color: #1e40af; }
.badge-muted  { background: #f1f5f9; color: #64748b; }

.btn-primary {
  padding: 9px 16px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.btn-primary:hover { background: #dc2626; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost {
  padding: 8px 14px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.btn-ghost:hover { background: var(--bg-main); color: var(--text-main); }
.btn-danger {
  padding: 6px 12px;
  background: transparent;
  color: #dc2626;
  border: 1px solid #fca5a5;
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.btn-danger:hover { background: #fee2e2; }

.form-row { margin-bottom: 14px; }
.form-row label {
  display: block; font-size: 11.5px; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.4px; margin-bottom: 5px;
}
.form-row input, .form-row select, .form-row textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: inherit;
  background: white;
  outline: none;
}
.form-row textarea { resize: vertical; min-height: 90px; }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { border-color: var(--primary); }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
}

.info-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.info-block h3 { font-size: 15px; margin-bottom: 10px; color: var(--text-main); }
.info-block p { color: var(--text-main); font-size: 14px; margin-bottom: 10px; }
.info-block ul { padding-left: 22px; margin-bottom: 10px; }
.info-block li { margin-bottom: 4px; font-size: 14px; }
.info-block .alert {
  background: #fef2f2;
  border-left: 3px solid #ef4444;
  padding: 12px 16px;
  border-radius: 6px;
  color: #7f1d1d;
  font-size: 13.5px;
  margin: 12px 0;
}

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: #f1f5f9;
  color: #475569;
  margin-right: 4px;
}
.pill-on { background: var(--primary-soft); color: var(--primary); }

.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Modo embebido: cuando la vista se carga dentro de un iframe (?embed=1),
   ocultamos el sidebar y la barra superior para que solo se vea el contenido. */
body.embed .sidebar,
body.embed .top-bar { display: none !important; }
body.embed .main-wrapper { margin-left: 0 !important; }
body.embed .section:first-of-type { padding-top: 20px; }
