:root {
  --bg-app: #f4f7f9;
  --bg-card: #ffffff;
  --sidebar-bg: #0f172a;
  --primary: #0d9488;
  --primary-hover: #0f766e;
  --primary-soft: #ccfbf1;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --ok-bg: #dcfce7;
  --ok-text: #166534;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --danger-bg: #fee2e2;
  --danger-text: #991b1b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
  background: var(--bg-app);
  color: var(--text-main);
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid #1e293b;
}

.brand-logo {
  width: 40px;
  height: 40px;
  background: var(--primary);
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.1rem;
}

.brand h1 { font-size: 1.15rem; }
.brand span { font-size: 0.75rem; color: #94a3b8; }

.side-nav {
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

.nav-item {
  background: transparent;
  border: none;
  color: #cbd5e1;
  text-align: left;
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: 0.2s;
}

.nav-item.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.nav-item.disabled { opacity: 0.45; cursor: not-allowed; }

.sidebar-footer {
  border-top: 1px solid #1e293b;
  padding-top: 1rem;
  font-size: 0.78rem;
  color: #94a3b8;
}

.plan-badge {
  display: inline-block;
  background: rgba(13, 148, 136, 0.25);
  color: #5eead4;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 1.5rem 2rem;
  max-width: 1400px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.patient-selector-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.patient-selector-group label { font-weight: 600; font-size: 0.9rem; }

select, input, textarea {
  padding: 0.5rem 0.68rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
  background: #fff;
  color: var(--text-main);
  width: 100%;
}

.patient-selector-group select {
  width: auto;
  min-width: 240px;
  font-weight: 600;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

/* Buttons */
.btn {
  padding: 0.56rem 1rem;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  font-size: 0.86rem;
  cursor: pointer;
  transition: 0.2s;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-outline {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text-main);
}
.btn-outline:hover { background: #f8fafc; }

.btn-sm { padding: 0.38rem 0.75rem; font-size: 0.8rem; }

.btn-danger-icon {
  background: transparent;
  border: none;
  color: #dc2626;
  cursor: pointer;
  font-weight: bold;
  font-size: 1rem;
}

/* Patient Banner */
.patient-banner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem 1.4rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.patient-banner h2 { font-size: 1.2rem; }
.patient-banner p { color: var(--text-muted); font-size: 0.88rem; margin-top: 0.2rem; }

.banner-kpis { display: flex; gap: 0.75rem; flex-wrap: wrap; }

.kpi-pill {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.9rem;
  text-align: center;
  min-width: 120px;
}

.kpi-pill span { display: block; font-size: 0.72rem; color: var(--text-muted); }
.kpi-pill strong { font-size: 1.02rem; color: var(--primary); }

/* Tabs */
.tabs-bar {
  display: flex;
  gap: 0.5rem;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1.25rem;
  overflow-x: auto;
}

.tab-btn {
  background: transparent;
  border: none;
  padding: 0.75rem 1.1rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
}

.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Cards & Grids */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

.card h3 { font-size: 1rem; margin-bottom: 0.9rem; color: #0f172a; }

.card-header-flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
}

.card-header-flex h3 { margin-bottom: 0; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(460px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.25rem;
}

.form-grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.75rem; }

.field { margin-bottom: 0.7rem; }
.field label {
  display: block;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.inline-field { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0; }
.inline-field label { margin-bottom: 0; white-space: nowrap; }

/* Pediatric OMS Card */
.pediatric-card {
  border-color: #7dd3fc;
  background: linear-gradient(180deg, #ffffff 0%, #f0f9ff 100%);
}

.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: #e0f2fe;
  border: 1px solid #bae6fd;
  color: #0369a1;
  padding: 0.42rem 0.8rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.toggle-pill input[type="checkbox"] {
  width: auto;
  cursor: pointer;
}

.muted-block {
  display: block;
  font-size: 0.73rem;
  color: var(--text-muted);
  font-weight: 400;
}

.pct-badge {
  display: inline-block;
  background: #e0f2fe;
  color: #0369a1;
  padding: 0.16rem 0.55rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.78rem;
}

/* ISAK Switch & Subheaders */
.isak-mode-switch { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.isak-sub {
  font-size: 0.84rem;
  color: var(--primary-hover);
  background: #f0fdfa;
  border-left: 3px solid var(--primary);
  padding: 0.35rem 0.65rem;
  border-radius: 0 6px 6px 0;
  margin: 1rem 0 0.65rem;
}

/* Results, Formulas & Somatotype */
.results-card {
  background: linear-gradient(180deg, #ffffff 0%, #f0fdfa 100%);
  border-color: #99f6e4;
}

.results-grid, .somato-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.7rem;
}

.formulas-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
}

.formula-box {
  background: #fff;
  border: 1px solid #ccfbf1;
  border-radius: 9px;
  padding: 0.6rem 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.formula-box span { font-size: 0.76rem; color: var(--text-muted); font-weight: 600; }
.formula-box strong { font-size: 0.98rem; color: #0f172a; }

.res-box {
  background: #fff;
  border: 1px solid #ccfbf1;
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
}

.res-box span { display: block; font-size: 0.74rem; color: var(--text-muted); }
.res-box strong { display: block; font-size: 1.1rem; color: #0f172a; margin: 0.15rem 0; }
.res-box small { font-size: 0.74rem; color: var(--primary-hover); font-weight: 600; }

/* Lab Grid */
.lab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem;
}

.lab-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem;
  background: #f8fafc;
}

.lab-item label { display: block; font-size: 0.8rem; font-weight: 600; margin-bottom: 0.4rem; }

.status-tag {
  display: inline-block;
  margin-top: 0.45rem;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 700;
  background: #e2e8f0;
  color: #475569;
}

.status-ok { background: var(--ok-bg); color: var(--ok-text); }
.status-low { background: var(--warn-bg); color: var(--warn-text); }
.status-high { background: var(--danger-bg); color: var(--danger-text); }

.bio-indices-bar {
  margin-top: 1.25rem;
  padding: 1rem;
  background: #f0fdfa;
  border: 1px solid #99f6e4;
  border-radius: 10px;
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
}

.bio-indices-bar span { font-size: 0.85rem; color: var(--text-muted); margin-right: 0.4rem; }
.bio-indices-bar strong { font-size: 1.05rem; color: var(--primary-hover); }

/* Checklists, Escalas Clínicas y Tables */
.checklist-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
}

.checklist-grid label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.86rem;
  background: #f8fafc;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
}

.checklist-grid input[type="checkbox"] { width: auto; }

.scale-options { display: flex; flex-direction: column; gap: 0.55rem; }

.scale-card {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  transition: 0.15s;
}

.scale-card:hover { border-color: var(--primary); background: #f0fdfa; }
.scale-card input[type="radio"] { width: auto; margin-top: 0.2rem; cursor: pointer; }
.scale-card strong { display: block; font-size: 0.86rem; color: #0f172a; }
.scale-card small { display: block; font-size: 0.78rem; color: var(--text-muted); margin-top: 0.1rem; }

.table-responsive { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th, .data-table td {
  padding: 0.55rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.data-table th { background: #f8fafc; color: var(--text-muted); font-weight: 600; }

.freq-table td:not(:first-child), .freq-table th:not(:first-child) { text-align: center; }
.freq-table input[type="radio"] { width: auto; cursor: pointer; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 100;
}

.hidden { display: none !important; }

.modal-content {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 780px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
}

.modal-sm { max-width: 440px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.8rem;
  margin-bottom: 1rem;
}

.btn-close {
  background: transparent;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  color: var(--text-muted);
}

.report-body { display: grid; gap: 0.8rem; font-size: 0.9rem; line-height: 1.5; }

.report-block {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem 1rem;
}

.json-details { margin-top: 1rem; }
.json-details summary { cursor: pointer; font-weight: 600; color: var(--primary); font-size: 0.85rem; }

.json-details pre {
  background: #0f172a;
  color: #38bdf8;
  padding: 1rem;
  border-radius: 8px;
  margin-top: 0.5rem;
  font-size: 0.78rem;
  overflow-x: auto;
  max-height: 240px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--border);
}

/* Caja condicional para tutor de menor de edad */
.guardian-box {
  background: #f0fdfa;
  border: 1px solid #99f6e4;
  border-radius: 10px;
  padding: 0.85rem;
  margin-bottom: 0.85rem;
}

.guardian-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary-hover);
  margin-bottom: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

@media (max-width: 900px) {
  .app-layout { flex-direction: column; }
  .sidebar { width: 100%; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid-4, .formulas-grid { grid-template-columns: 1fr 1fr; }
}