/* ============================================================
   HEALTH APP (scoped)
   ============================================================ */
.health-app {
  --aman: #22c55e;
  --waspada: #eab308;
  --sedang: #f59e0b;
  --bahaya: #ef4444;
  --krisis: #7f1d1d;
  --dokter: #a78bfa;
  --record: #14b8a6;
  --h-card: var(--surface);
  --h-inner: var(--surface-2);
  --h-radius: 14px;
  --h-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  color: var(--text);
}

/* Adjust main tabs for 3 tabs */
.main-tabs { max-width: min(100%, 460px); }

.health-app .icon {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.health-app .icon-sm { width: 0.9em; height: 0.9em; vertical-align: -0.1em; }
.health-app .icon-lg { width: 1.35em; height: 1.35em; vertical-align: -0.25em; }

.health-app .health-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}
.health-app .health-tabs::-webkit-scrollbar { display: none; }
.health-app .health-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 0.95rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  white-space: nowrap;
  transition: all 0.15s;
  font-family: inherit;
}
.health-app .health-tab-btn:hover { color: var(--text); border-color: #475569; }
.health-app .health-tab-btn.active {
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-purple-2));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 3px 10px #8b5cf640;
}

.health-app .health-panel { display: none; }
.health-app .health-panel.active { display: grid; gap: 1.25rem; }

.health-app .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--h-radius);
  padding: 1.25rem;
  box-shadow: var(--h-shadow);
  display: block;
  flex-direction: initial;
  gap: 0;
}
.health-app .card h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text);
}
.health-app .card h2 .icon { color: var(--primary); }

.health-app .section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.health-app .section-head h2 { margin-bottom: 0; }

.health-app .form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.health-app .form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.health-app .form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}
.health-app .form-group input,
.health-app .form-group select {
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s;
}
.health-app .form-group input:focus,
.health-app .form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px #3b82f655;
}

.health-app .form-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.health-app .btn-cancel-edit { flex: 0 0 auto; padding: 0.8rem 1.2rem; }

/* CUSTOM SELECT (health version) */
.health-app .custom-select-wrapper { position: relative; user-select: none; }
.health-app .custom-select-trigger {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0.65rem 0.75rem;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.health-app .custom-select-trigger:hover { border-color: #475569; }
.health-app .custom-select-trigger.active { border-color: var(--primary); }
.health-app .custom-select-trigger .icon {
  transition: transform 0.2s;
  color: var(--muted);
}
.health-app .custom-select-trigger.active .icon { transform: rotate(180deg); }
.health-app .custom-select-options {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
  z-index: 100;
  max-height: 200px;
  overflow-y: auto;
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.health-app .custom-select-wrapper.open .custom-select-options {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.health-app .custom-select-option {
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid var(--border);
}
.health-app .custom-select-option:last-child { border-bottom: none; }
.health-app .custom-select-option:hover {
  background: rgba(59, 130, 246, 0.12);
  color: var(--primary);
}

.health-app .preview-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  min-height: 1.5rem;
}
.health-app .badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}
.health-app .badge-aman { background: var(--aman); }
.health-app .badge-waspada { background: var(--waspada); color: #1e293b; }
.health-app .badge-sedang { background: var(--sedang); }
.health-app .badge-bahaya { background: var(--bahaya); }
.health-app .badge-krisis { background: var(--krisis); }

.health-app .btn-primary {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.8rem 1.2rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}
.health-app .btn-primary:hover { background: var(--primary-hover); }
.health-app .btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.health-app .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
}
.health-app .btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.health-app .btn-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--bahaya);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: 6px;
  font-family: inherit;
  font-size: 1.05rem;
}
.health-app .btn-delete:hover { background: rgba(239, 68, 68, 0.15); }
.health-app .btn-edit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: 6px;
  font-family: inherit;
  font-size: 1.05rem;
}
.health-app .btn-edit:hover { background: rgba(59, 130, 246, 0.15); }

.health-app .table-wrap { overflow-x: auto; }
.health-app table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.health-app th, .health-app td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.health-app th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--surface-2);
}
.health-app tbody tr:hover { background: var(--surface-2); }
.health-app .empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2rem 0;
  font-style: italic;
}

.health-app .row-aman td:first-child { border-left: 4px solid var(--aman); }
.health-app .row-waspada td:first-child { border-left: 4px solid var(--waspada); }
.health-app .row-sedang td:first-child { border-left: 4px solid var(--sedang); }
.health-app .row-bahaya td:first-child { border-left: 4px solid var(--bahaya); }
.health-app .row-krisis td:first-child { border-left: 4px solid var(--krisis); }

.health-app .disclaimer {
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
}
.health-app .disclaimer .icon { color: var(--sedang); margin-top: 0.15rem; }

.health-app .chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
}
.health-app .chart-box {
  position: relative;
  height: 280px;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 0.75rem;
}

.health-app .stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.health-app .stat-card {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.12) 0%, rgba(59, 130, 246, 0.05) 100%);
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
}
.health-app .stat-label {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
  font-weight: 600;
}
.health-app .stat-value {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.health-app .stat-value small {
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: 0.15rem;
}
.health-app .stat-card .badge { margin-top: 0.25rem; font-size: 0.65rem; padding: 0.15rem 0.5rem; }

.health-app .distribution h3 {
  font-size: 0.9rem;
  margin: 1.25rem 0 0.6rem;
  color: var(--muted);
  font-weight: 600;
}
.health-app .dist-bars { display: flex; flex-direction: column; gap: 0.5rem; }
.health-app .dist-bar { display: flex; align-items: center; gap: 0.75rem; }
.health-app .dist-bar-label { min-width: 100px; font-size: 0.8rem; font-weight: 600; }
.health-app .dist-bar-track {
  flex: 1;
  height: 20px;
  background: var(--surface-2);
  border-radius: 10px;
  overflow: hidden;
}
.health-app .dist-bar-fill { height: 100%; border-radius: 10px; transition: width 0.3s; }
.health-app .dist-bar-count {
  min-width: 2.5rem;
  text-align: right;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.health-app .today-meds {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}
.health-app .med-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: all 0.15s;
}
.health-app .med-item.overdue {
  border-color: var(--bahaya);
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.18);
  animation: healthPulse 2s infinite;
}
@keyframes healthPulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.18); }
  50% { box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.3); }
}
.health-app .med-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.8rem;
  height: 1.8rem;
  background: rgba(59, 130, 246, 0.15);
  border-radius: 6px;
  color: var(--primary);
  margin-top: 0.1rem;
}
.health-app .med-icon svg { width: 1rem; height: 1rem; }
.health-app .med-body { flex: 1; min-width: 0; }
.health-app .med-time {
  font-size: 0.65rem;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 0.15rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.health-app .med-name { font-weight: 700; font-size: 0.85rem; line-height: 1.2; }
.health-app .med-dose {
  font-weight: 400;
  font-size: 0.7rem;
  color: var(--muted);
  display: inline-block;
  margin-left: 0.2rem;
}
.health-app .med-meta {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.2rem;
  display: flex;
  align-items: center;
  gap: 0.2rem;
  flex-wrap: wrap;
  line-height: 1.2;
}

.health-app .checkbox-group { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.health-app .checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.15s;
}
.health-app .checkbox-label:hover { border-color: #475569; }
.health-app .checkbox-label .icon { color: var(--muted); }
.health-app .checkbox-label input[type="checkbox"] {
  accent-color: var(--primary);
  width: auto;
  margin: 0;
}
.health-app .checkbox-label:has(input:checked) {
  background: rgba(59, 130, 246, 0.12);
  border-color: var(--primary);
  color: var(--primary);
}
.health-app .checkbox-label:has(input:checked) .icon { color: var(--primary); }

.health-app .med-preview {
  padding: 0.75rem 1rem;
  background: rgba(59, 130, 246, 0.1);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text);
  margin: 1rem 0;
  line-height: 1.7;
}
.health-app .med-preview:empty { display: none; }
.health-app .med-preview .icon { color: var(--primary); }

.health-app .med-plan {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 0.85rem;
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  background: var(--surface-2);
}
.health-app .med-plan:last-child { margin-bottom: 0; }
.health-app .med-plan-info { flex: 1; min-width: 0; }
.health-app .med-plan h3 { font-size: 1rem; margin-bottom: 0.3rem; }
.health-app .med-plan-meta { font-size: 0.8rem; color: var(--muted); line-height: 1.7; }
.health-app .med-plan-meta .icon { color: var(--muted); }
.health-app .med-plan-actions { display: flex; gap: 0.25rem; }

.health-app .calendar-controls { display: flex; align-items: center; gap: 0.5rem; }
.health-app .month-label { font-weight: 700; font-size: 1rem; min-width: 130px; text-align: center; }
.health-app .calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.health-app .cal-head {
  text-align: center;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0.5rem 0;
}
.health-app .calendar-cells { display: contents; }
.health-app .cal-cell {
  min-height: 85px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: all 0.15s;
  position: relative;
}
.health-app .cal-cell.other-month { opacity: 0.4; background: var(--surface); }
.health-app .cal-cell.today { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.health-app .cal-date { font-size: 0.8rem; font-weight: 600; margin-bottom: 2px; }
.health-app .cal-cell.today .cal-date { color: var(--primary); }
.health-app .cal-events { display: flex; flex-direction: column; gap: 3px; overflow: hidden; }
.health-app .cal-event {
  font-size: 0.65rem;
  padding: 2px 4px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff;
  font-weight: 500;
}
.health-app .cal-event.med-start { background: var(--primary); }
.health-app .cal-event.med-end { background: var(--bahaya); }
.health-app .cal-event.appointment { background: var(--dokter); }
.health-app .cal-event.record { background: var(--record); }
.health-app .calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.health-app .calendar-legend .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
}

@media (max-width: 640px) {
  .health-app .card { padding: 1rem; }
  .health-app th, .health-app td { padding: 0.5rem; font-size: 0.78rem; }
  .health-app .chart-box { height: 240px; }
  .health-app .dist-bar-label { min-width: 80px; font-size: 0.75rem; }
  .health-app .cal-cell { min-height: 60px; padding: 0.25rem; }
  .health-app .cal-event { display: none; }
  .health-app .cal-cell.has-events::after {
    content: '';
    display: block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--record);
    position: absolute;
    bottom: 4px;
    right: 4px;
  }
  .health-app .cal-cell.has-events.appointment-dot::after { background: var(--dokter); }
  .health-app .form-actions { flex-direction: column; }
  .health-app .btn-cancel-edit { width: 100%; }
}