/* ==========================================================================
   CHW / DPP Workforce Model — interface styles
   Design system: warm, approachable "community health" palette.
   ========================================================================== */

:root {
  --teal-900: #0b4f4a;
  --teal-700: #0f766e;
  --teal-600: #14897f;
  --teal-500: #1ea497;
  --teal-100: #e3f6f3;
  --amber-600: #d97706;
  --amber-500: #f59e0b;
  --amber-100: #fef3e0;

  --surface-0: #ffffff;
  --surface-1: #f7faf9;
  --surface-2: #eef3f2;
  --border: #dbe5e2;

  --text: #1f2933;
  --text-muted: #566b68;
  --text-faint: #829693;

  --good: #1a8f5c;
  --bad: #c23b3b;

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;

  --shadow-card: 0 1px 2px rgba(15, 60, 55, 0.06), 0 4px 14px rgba(15, 60, 55, 0.06);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;

  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
}

body {
  background: var(--surface-1);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 46rem;
  margin: 0 auto;
  padding-bottom: var(--space-6);
}

/* ---------- Header + tabs ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(180deg, var(--teal-900), var(--teal-700));
  color: #fff;
  padding: var(--space-4) var(--space-4) 0;
}

.app-header h1 {
  margin: 0 0 var(--space-1);
  font-size: clamp(1.05rem, 4vw, 1.35rem);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.app-header p {
  margin: 0 0 var(--space-4);
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.875rem;
  max-width: 40rem;
}

.tabbar {
  display: flex;
  gap: var(--space-1);
}

.tab-btn {
  flex: 1 1 0;
  appearance: none;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.85);
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.7rem 0.5rem;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  cursor: pointer;
  min-height: 44px;
}

.tab-btn[aria-selected="true"] {
  background: var(--surface-1);
  color: var(--teal-900);
}

.view { padding: var(--space-4); display: none; }
.view.active { display: block; }

/* ---------- Cards ---------- */

.card {
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.card h2 {
  margin: 0 0 var(--space-2);
  font-size: 1rem;
  font-weight: 700;
  color: var(--teal-900);
}

.card > .card-blurb {
  margin: 0 0 var(--space-3);
  font-size: 0.85rem;
  color: var(--text-muted);
}

details.card { padding: 0; }
details.card > summary {
  list-style: none;
  cursor: pointer;
  padding: var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  color: var(--teal-900);
  min-height: 44px;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after {
  content: "\25BE";
  color: var(--text-faint);
  transition: transform 0.15s ease;
  font-size: 0.8em;
}
details.card[open] > summary::after { transform: rotate(180deg); }
details.card > .details-body { padding: 0 var(--space-4) var(--space-4); }

/* ---------- Overview diagram ---------- */

.overview-diagram {
  width: 100%;
  height: auto;
  display: block;
}

.overview-legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.overview-legend .legend-item {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.overview-legend .swatch {
  flex: none;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 3px;
  margin-top: 0.2rem;
}

/* ---------- Intervention groups / switches ---------- */

.group-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
}

.group-count {
  font-size: 0.75rem;
  color: var(--text-faint);
  white-space: nowrap;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.65rem 0;
  border-top: 1px solid var(--surface-2);
  min-height: 44px;
  cursor: pointer;
}

.switch-row:first-of-type { border-top: none; }

.switch-row .switch-label {
  flex: 1 1 auto;
  font-size: 0.875rem;
}

.switch-row .switch-label .tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--teal-700);
  background: var(--teal-100);
  border-radius: var(--radius-sm);
  padding: 0.05rem 0.35rem;
  margin-right: 0.4rem;
  vertical-align: middle;
}

/* Toggle switch built from a checkbox */
.switch {
  position: relative;
  flex: none;
  width: 46px;
  height: 27px;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.switch .track {
  position: absolute;
  inset: 0;
  background: #c7d2cf;
  border-radius: var(--radius-pill);
  transition: background 0.15s ease;
  pointer-events: none;
}

.switch .thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 23px;
  height: 23px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease;
  pointer-events: none;
}

.switch input:checked ~ .track { background: var(--teal-600); }
.switch input:checked ~ .thumb { transform: translateX(19px); }
.switch input:disabled ~ .track { opacity: 0.5; }
.switch input:focus-visible ~ .track { outline: 2px solid var(--amber-500); outline-offset: 2px; }

/* ---------- Sliders / number fields ---------- */

.field {
  margin-bottom: var(--space-4);
}
.field:last-child { margin-bottom: 0; }

.field-label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-2);
  margin-bottom: 0.3rem;
}

.field-label {
  font-size: 0.875rem;
  font-weight: 600;
}

.field-unit {
  font-size: 0.75rem;
  color: var(--text-faint);
  font-weight: 400;
}

.field-value {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--teal-700);
  white-space: nowrap;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 44px;
  background: transparent;
  margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
}
input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  margin-top: -11px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--teal-700);
  border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
input[type="range"]::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--teal-700);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
input[type="range"]:disabled::-webkit-slider-thumb { background: #9fb0ac; }
input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--amber-500); outline-offset: 2px; }

.field-hint {
  font-size: 0.75rem;
  color: var(--text-faint);
  margin-top: 0.25rem;
}

input[type="number"], input[type="text"].num {
  width: 100%;
  min-height: 44px;
  font: inherit;
  font-size: 1rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  color: var(--text);
}
input[type="number"]:focus, input[type="text"].num:focus {
  outline: 2px solid var(--teal-500);
  outline-offset: -1px;
}

.number-with-slider {
  display: grid;
  grid-template-columns: 1fr 6.5rem;
  gap: var(--space-3);
  align-items: center;
}

/* ---------- Buttons ---------- */

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin: var(--space-2) 0 var(--space-4);
}

button {
  font: inherit;
  cursor: pointer;
}

.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-pill);
  padding: 0.75rem 1.4rem;
  font-weight: 700;
  font-size: 0.9rem;
  min-height: 44px;
  min-width: 44px;
}

.btn-primary {
  background: var(--teal-700);
  color: #fff;
}
.btn-primary:disabled {
  background: #9fb0ac;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--teal-900);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--teal-700);
  border: 1px solid var(--teal-600);
}

.btn:focus-visible { outline: 2px solid var(--amber-500); outline-offset: 2px; }

/* ---------- Status / notices ---------- */

.status-line {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.85rem;
  color: var(--text-muted);
  min-height: 1.4rem;
}

.status-dot {
  flex: none;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--text-faint);
}
.status-dot.busy { background: var(--amber-500); animation: pulse 1s ease-in-out infinite; }
.status-dot.ok { background: var(--good); }
.status-dot.warn { background: var(--bad); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.notice {
  display: none;
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: 0.85rem;
  margin-bottom: var(--space-4);
  border: 1px solid transparent;
}
.notice.show { display: block; }
.notice.warn {
  background: #fdf1f1;
  border-color: #f2c6c6;
  color: #7a2323;
}
.notice.info {
  background: var(--teal-100);
  border-color: #bfe4de;
  color: var(--teal-900);
}

/* ---------- Charts ---------- */

.chart-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

@media (min-width: 40rem) {
  .chart-grid { grid-template-columns: 1fr 1fr; }
}

.chart-card {
  position: relative;
}

.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.chart-head h3 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
}

.chart-head .chart-current {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--teal-700);
  white-space: nowrap;
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: clamp(160px, 38vw, 220px);
  touch-action: pan-y;
}

.chart-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: var(--radius-sm);
  background: var(--surface-1);
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--text-faint);
  text-align: center;
  padding: var(--space-3);
  pointer-events: none;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-2);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.chart-legend .item { display: flex; align-items: center; gap: 0.3rem; }
.chart-legend .line { width: 14px; height: 0; border-top-width: 2px; border-top-style: solid; }
.chart-legend .line.dashed { border-top-style: dashed; }

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(20, 40, 38, 0.92);
  color: #fff;
  font-size: 0.72rem;
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.55rem;
  transform: translate(-50%, -110%);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.1s ease;
  z-index: 5;
}
.chart-tooltip.show { opacity: 1; }
.chart-tooltip .row { display: flex; gap: 0.4rem; align-items: center; }
.chart-tooltip .dot { width: 6px; height: 6px; border-radius: 50%; flex: none; }

/* ---------- Parameters page ---------- */

.param-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}

@media (min-width: 34rem) {
  .param-grid { grid-template-columns: 1fr 1fr; }
}

.footer-note {
  font-size: 0.75rem;
  color: var(--text-faint);
  text-align: center;
  margin-top: var(--space-5);
  padding: 0 var(--space-4);
}
