:root {
  --bg: #f3f6fb;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e6eaf2;
  --primary: #2f6fed;
  --primary-dark: #1e54c4;
  --verde: #22a06b;
  --verde-bg: #e6f6ee;
  --amarillo: #c9931a;
  --amarillo-bg: #fdf3dc;
  --rojo: #d64545;
  --rojo-bg: #fbe8e8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 25, 40, 0.04), 0 6px 20px rgba(20, 25, 40, 0.06);
  --sidebar-w: 260px;
  --practice: #7c5cff;
  --practice-bg: #f1edff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, Segoe UI, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-weight: 700; margin: 0 0 4px; letter-spacing: -0.01em; }
p { line-height: 1.55; color: var(--text); }
a { color: var(--primary); text-decoration: none; }
.muted { color: var(--muted); font-size: 13.5px; }
ul { margin: 8px 0; padding-left: 20px; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  height: 64px; padding: 0 20px;
  background: rgba(255,255,255,0.9); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.hamburger {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.hamburger span { display: block; width: 16px; height: 2px; background: var(--text); position: relative; }
.hamburger span::before, .hamburger span::after { content: ''; position: absolute; left: 0; width: 16px; height: 2px; background: var(--text); }
.hamburger span::before { top: -5px; } .hamburger span::after { top: 5px; }
.topbar h1#page-title { font-size: 17px; flex-shrink: 0; }

.search-wrap { position: relative; flex: 1; max-width: 420px; margin-left: auto; }
.search-wrap input {
  width: 100%; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: #f8f9fc; font-size: 14px; font-family: inherit;
}
.search-wrap input:focus { outline: none; border-color: var(--primary); background: #fff; }
.search-results {
  display: none; position: absolute; top: 44px; left: 0; right: 0; background: var(--card);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; z-index: 50;
}
.search-results.open { display: block; }
.search-item { padding: 10px 14px; display: flex; justify-content: space-between; gap: 10px; cursor: pointer; font-size: 13.5px; }
.search-item:hover { background: #f3f6fb; }
.search-item span { color: var(--muted); }
.search-item.empty { color: var(--muted); cursor: default; }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
  background: var(--card); border-right: 1px solid var(--border);
  transform: translateX(-100%); transition: transform .25s ease;
  z-index: 40; display: flex; flex-direction: column; padding: 18px 14px;
}
body.sidebar-open .sidebar { transform: translateX(0); }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }

/* ---------- pantalla de bienvenida (solo en la carga inicial) ---------- */
#splash {
  position: fixed; inset: 0; z-index: 999; background: #fff;
  display: flex; align-items: center; justify-content: center;
  animation: splash-out .45s ease .75s forwards;
}
#splash img {
  width: min(280px, 55vw); height: min(280px, 55vw); object-fit: contain;
  animation: splash-pop .45s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes splash-pop { from { opacity: 0; transform: scale(.75); } to { opacity: 1; transform: scale(1); } }
@keyframes splash-out { to { opacity: 0; visibility: hidden; pointer-events: none; } }
.brand div strong { display: block; font-size: 14.5px; }
.brand div span { font-size: 11.5px; color: var(--muted); }

.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--text); font-size: 14px; font-weight: 500; margin-bottom: 2px; transition: background .15s;
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; stroke: var(--muted); }
.nav-link:hover { background: #f3f6fb; }
.nav-link.active { background: #eaf0ff; color: var(--primary-dark); }
.nav-link.active svg { stroke: var(--primary-dark); }
.sidebar-footer { margin-top: auto; padding: 10px; font-size: 11px; color: var(--muted); }
.nav-sep { height: 1px; background: var(--border); margin: 10px 8px; }
.nav-link-practice { position: relative; }
.nav-link-practice svg { stroke: var(--practice); }
.nav-link-practice.active { background: var(--practice-bg); color: var(--practice); }
.nav-link-practice.active svg { stroke: var(--practice); }
.chip-demo {
  margin-left: auto; font-size: 9.5px; font-weight: 800; letter-spacing: .04em;
  background: var(--practice); color: #fff; padding: 2px 6px; border-radius: 6px;
}

/* ---------- modo práctica ---------- */
.practice-header { border: 1.5px solid var(--practice); background: linear-gradient(180deg, var(--practice-bg), #fff 65%); }
.practice-tag {
  display: inline-block; background: var(--practice); color: #fff; font-size: 10.5px; font-weight: 800;
  letter-spacing: .04em; padding: 4px 10px; border-radius: 999px; margin-bottom: 10px;
}
.practice-subnav { display: flex; gap: 8px; flex-wrap: wrap; }
.practice-subnav a { padding: 9px 16px; border-radius: 10px; font-size: 13.5px; font-weight: 600; color: var(--muted); background: var(--card); border: 1px solid var(--border); }
.practice-subnav a.active { background: var(--practice); color: #fff; border-color: var(--practice); }
.practice-quick-form.form-card { border: 1px dashed var(--practice); border-radius: var(--radius); padding: 16px; margin-top: 12px; }
body.practice-scope .topbar { border-bottom: 2px solid var(--practice); }

.sidebar-overlay { display: none; }
@media (max-width: 899px) {
  body.sidebar-open .sidebar-overlay {
    display: block; position: fixed; inset: 0; background: rgba(15, 20, 35, 0.4); z-index: 30;
  }
}
.main { padding: 22px 22px 60px; transition: margin-left .25s ease; }
@media (min-width: 900px) {
  body.sidebar-open .main { margin-left: var(--sidebar-w); }
}
.view { max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; animation: fadein .25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.site-footer { text-align: center; padding: 16px; color: var(--muted); font-size: 12px; }

/* ---------- cards & grids ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
  transition: box-shadow .2s ease, border-color .2s ease, transform .2s ease;
}
.card:hover { border-color: #d7e0f5; box-shadow: 0 4px 16px rgba(20,25,40,0.07), 0 1px 3px rgba(20,25,40,0.05); }
.card h3 { font-size: 15.5px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.card-head h3 { margin: 0; }
.grid { display: grid; gap: 14px; }
.stats-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.district-grid { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.stat-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
  transition: transform .2s ease, box-shadow .2s ease;
  display: block; text-decoration: none; color: inherit;
}
a.stat-card { cursor: pointer; }
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--primary), #6fa4ff);
  transform: scaleX(0); transform-origin: left; transition: transform .25s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(20,25,40,0.09); }
.stat-card:hover::before { transform: scaleX(1); }
.stat-value { font-size: 24px; font-weight: 800; }
.stat-label { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.stat-card.stat-warn .stat-value { color: var(--amarillo); }
.stat-card.stat-ok .stat-value { color: var(--verde); }

/* ---------- badges / dots ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.badge-verde { background: var(--verde-bg); color: var(--verde); }
.badge-amarillo { background: var(--amarillo-bg); color: var(--amarillo); }
.badge-rojo { background: var(--rojo-bg); color: var(--rojo); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-verde { background: var(--verde); } .dot-amarillo { background: var(--amarillo); } .dot-rojo { background: var(--rojo); }
.dot-history { display: flex; gap: 4px; margin-top: 4px; }
.dot-history .dot { width: 8px; height: 8px; }

/* ---------- avatar ---------- */
.avatar { border-radius: 50%; object-fit: cover; flex-shrink: 0; transition: transform .18s ease; }
.avatar-md { width: 44px; height: 44px; }
.avatar-lg { width: 64px; height: 64px; }
.avatar-fallback { display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 15px; }
.avatar-lg.avatar-fallback { font-size: 20px; }

/* ---------- patient cards ---------- */
.patient-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.patient-card {
  display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
  transition: transform .18s cubic-bezier(.2,.8,.2,1), box-shadow .18s ease, border-color .18s ease;
  position: relative; overflow: hidden;
}
.patient-card::after {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: linear-gradient(180deg, var(--primary), #6fa4ff);
  transform: scaleY(0); transform-origin: top; transition: transform .22s ease;
}
.patient-card:hover { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(20,25,40,0.1); border-color: #d7e0f5; }
.patient-card:hover::after { transform: scaleY(1); }
.patient-card:hover .avatar { transform: scale(1.06); }
.patient-card-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.patient-card-info strong { font-size: 14px; }
.patient-card-wide { align-items: flex-start; }

/* ---------- bars ---------- */
.bar-split { display: flex; height: 8px; border-radius: 6px; overflow: hidden; background: var(--border); margin-top: 10px; }
.bar-seg { min-width: 0; }
.bar-verde { background: var(--verde); } .bar-amarillo { background: var(--amarillo); } .bar-rojo { background: var(--rojo); }
.bar-legend { display: flex; gap: 14px; margin-top: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.bar-legend .dot { margin-right: 4px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  border-radius: 10px; padding: 9px 16px; font-size: 13.5px; font-weight: 600; border: 1px solid transparent;
  font-family: inherit; transition: filter .15s, background .15s, transform .12s ease, box-shadow .15s ease;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(47,111,237,0.28); }
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 5px 14px rgba(47,111,237,0.34); }
.btn-primary:active { transform: translateY(0); box-shadow: 0 2px 6px rgba(47,111,237,0.28); }
.btn-secondary { background: #eef2fb; color: var(--primary-dark); }
.btn-secondary:hover { background: #e3eaff; transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { background: #f3f6fb; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn:active { transform: translateY(0); }

/* ---------- forms ---------- */
.form-card h4 { margin-top: 18px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-top: 10px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.field-wide { grid-column: 1 / -1; }
.field-inline { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  font-family: inherit; font-size: 14px; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--border);
  background: #fbfcfe; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); background: #fff; }
input:disabled { color: var(--muted); background: #f3f4f7; }
.photo-field { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--muted); }
.photo-row { display: flex; align-items: center; gap: 14px; }
.photo-actions { display: flex; gap: 8px; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.form-error {
  background: var(--rojo-bg); color: var(--rojo); border-radius: 10px; padding: 10px 14px;
  font-size: 13.5px; font-weight: 600; margin-top: 12px;
}
.field-error { color: var(--rojo); font-weight: 600; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--rojo); background: var(--rojo-bg); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state svg { width: 40px; height: 40px; stroke: var(--muted); margin-bottom: 10px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(0);
  background: #1f2430; color: #fff; padding: 12px 20px; border-radius: 10px; font-size: 13.5px;
  box-shadow: var(--shadow); z-index: 200; display: flex; align-items: center; gap: 8px;
  animation: toast-in .25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ---------- table ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.table .group-row td { background: #f3f6fb; font-weight: 700; font-size: 13px; color: var(--primary-dark); border-bottom: 1px solid var(--border); padding: 8px 10px; }
.table a:hover { text-decoration: underline; }

/* ---------- filters ---------- */
.filters-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.filters-bar select, .filters-bar input { min-width: 140px; }
.filters-bar .btn { margin-left: auto; }

/* ---------- charts ---------- */
.chart-canvas { width: 100%; height: 240px; display: block; }
.chart-canvas-tall { height: 340px; }
.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.chart-title { font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.chart-tooltip {
  position: fixed; z-index: 100; background: #1f2430; color: #fff; font-size: 12px; padding: 8px 10px;
  border-radius: 8px; pointer-events: none; line-height: 1.4; box-shadow: var(--shadow); display: none;
}
.legend-list { list-style: none; padding: 0; font-size: 13.5px; }
.legend-list li { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }

/* ---------- ficha ---------- */
.ficha-header { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.ficha-header-info { flex: 1; min-width: 200px; }
.ficha-actions { display: flex; gap: 8px; margin-left: auto; }
.indicadores-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.indicadores-grid .stat-card { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.status-line {
  display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 800;
  letter-spacing: .03em; padding-top: 2px;
}
.status-verde { color: var(--verde); }
.status-amarillo { color: var(--amarillo); }
.status-rojo { color: var(--rojo); }
.icon-inline { width: 13px; height: 13px; vertical-align: -2px; stroke: var(--muted); }
.disclaimer { font-size: 12px; color: var(--muted); border-top: 1px dashed var(--border); padding-top: 10px; margin-top: 10px; }
.back-link { font-size: 13px; color: var(--muted); }

/* ---------- modal ---------- */
dialog#modal { border: none; border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); width: min(520px, 92vw); }
dialog#modal::backdrop { background: rgba(15, 20, 35, 0.45); }

/* ---------- responsive ---------- */
@media (max-width: 640px) {
  .main { padding: 16px 14px 50px; }
  .topbar { padding: 0 14px; gap: 10px; }
  .search-wrap { max-width: none; }
  .ficha-actions { width: 100%; margin-left: 0; }
}

/* ---------- print ---------- */
@media print {
  .topbar, .sidebar, .sidebar-overlay, .no-print, .no-print-actions .ficha-actions, .filters-bar button, .filters-bar select { display: none !important; }
  .main { margin-left: 0 !important; padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  body { background: #fff; }
}
