/* Parthograph — tablet-first stylesheet
   Design goals: large touch targets (min 48px), high contrast for bright wards,
   readable at arm's length, minimal typing, print-friendly referral notes. */

:root {
  --c-primary: #0e7a64;
  --c-primary-dark: #0a5a4a;
  --c-primary-light: #e2f3ef;
  --c-accent: #f2a922;
  --c-danger: #c62828;
  --c-danger-bg: #fdecea;
  --c-warn: #b26a00;
  --c-warn-bg: #fff4e0;
  --c-ok: #2e7d32;
  --c-ok-bg: #e8f5e9;
  --c-ink: #1c2b28;
  --c-ink-soft: #51635e;
  --c-line: #d4e0dc;
  --c-bg: #f4f8f6;
  --c-card: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 4px rgba(16, 42, 36, 0.12);
  --tap: 48px;
  font-size: 17px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", "Noto Sans Ethiopic", Roboto, system-ui, sans-serif;
  background: var(--c-bg);
  color: var(--c-ink);
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; }

.boot-splash { text-align: center; padding-top: 20vh; color: var(--c-primary); }
.boot-logo { font-size: 64px; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  background: var(--c-primary); color: #fff;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.topbar h1 { font-size: 1.15rem; margin: 0; flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .clock { font-variant-numeric: tabular-nums; opacity: .9; font-size: .95rem; text-align: right; line-height: 1.2; }
.topbar .clock .ec { font-size: .75rem; opacity: .85; display: block; }
.btn-back {
  background: rgba(255,255,255,.15); border: none; color: #fff;
  min-width: var(--tap); min-height: var(--tap); border-radius: 10px;
  font-size: 1.3rem; cursor: pointer;
}
.btn-home {
  background: none; border: none; color: #fff; padding: 0 4px;
  min-width: var(--tap); min-height: var(--tap); line-height: 1;
  font-size: 1.6rem; cursor: pointer; border-radius: 10px;
}
.btn-home:active { background: rgba(255,255,255,.15); }
.topbar h1.brand-title { cursor: pointer; }

.page { padding: 14px; max-width: 1100px; margin: 0 auto; padding-bottom: 90px; }

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: #fff; border-top: 1px solid var(--c-line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav button {
  flex: 1; min-height: 60px; border: none; background: none; cursor: pointer;
  color: var(--c-ink-soft); font-size: .8rem; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
}
.bottom-nav button .ico { font-size: 1.5rem; }
.bottom-nav button.active { color: var(--c-primary); font-weight: 700; }

/* ---------- cards & widgets ---------- */
.card {
  background: var(--c-card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 10px; font-size: 1.05rem; color: var(--c-primary-dark); }
.card h3 { margin: 14px 0 6px; font-size: .95rem; color: var(--c-ink-soft); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 640px) { .grid3 { grid-template-columns: 1fr 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 10px 18px;
  border-radius: 12px; border: 1.5px solid var(--c-primary);
  background: var(--c-primary); color: #fff;
  font-size: 1rem; font-weight: 600; cursor: pointer;
  transition: transform .05s;
}
.btn:active { transform: scale(.97); }
.btn.secondary { background: #fff; color: var(--c-primary); }
.btn.ghost { background: none; border-color: transparent; color: var(--c-primary); }
.btn.danger { background: var(--c-danger); border-color: var(--c-danger); }
.btn.warn { background: var(--c-warn); border-color: var(--c-warn); }
.btn.big { width: 100%; min-height: 58px; font-size: 1.1rem; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

.fab {
  position: fixed; right: 18px; bottom: 78px; z-index: 25;
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--c-accent); color: #2b1d00; border: none;
  font-size: 2rem; box-shadow: 0 4px 12px rgba(0,0,0,.25); cursor: pointer;
}

/* ---------- forms ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: .85rem; color: var(--c-ink-soft); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=number], input[type=date], input[type=time],
input[type=tel], input[type=datetime-local], select, textarea {
  width: 100%; min-height: var(--tap);
  padding: 10px 12px; font-size: 1.05rem;
  border: 1.5px solid var(--c-line); border-radius: 10px;
  background: #fff; color: var(--c-ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--c-primary); border-color: var(--c-primary); }
textarea { min-height: 80px; resize: vertical; }

.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button {
  flex: 1 0 auto; min-height: var(--tap); padding: 8px 14px;
  border: 1.5px solid var(--c-line); border-radius: 10px;
  background: #fff; color: var(--c-ink); font-size: 1rem; cursor: pointer;
}
.seg button.sel { background: var(--c-primary); border-color: var(--c-primary); color: #fff; font-weight: 700; }
.seg button.sel.alertval { background: var(--c-danger); border-color: var(--c-danger); }
.seg.big button { min-height: 64px; font-size: 1.15rem; }

.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 320px; margin: 0 auto; }
.numpad button {
  min-height: 60px; font-size: 1.4rem; border-radius: 12px;
  border: 1.5px solid var(--c-line); background: #fff; cursor: pointer;
}
.numpad button:active { background: var(--c-primary-light); }
.num-display {
  font-size: 2.4rem; text-align: center; font-variant-numeric: tabular-nums;
  border: 2px solid var(--c-line); border-radius: 12px; padding: 6px;
  margin-bottom: 10px; min-height: 64px; background: #fff;
}
.num-display.alertval { border-color: var(--c-danger); color: var(--c-danger); }
.stepper { display: flex; align-items: center; justify-content: center; gap: 14px; }
.stepper button {
  width: 64px; height: 64px; font-size: 1.8rem; border-radius: 50%;
  border: 1.5px solid var(--c-line); background: #fff; cursor: pointer;
}
.stepper .val { font-size: 2.2rem; min-width: 90px; text-align: center; font-weight: 700; }

/* ---------- dashboard patient cards ---------- */
.pt-card {
  display: block; width: 100%; text-align: left;
  background: var(--c-card); border: none; border-left: 6px solid var(--c-primary);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px; cursor: pointer;
}
.pt-card.has-danger { border-left-color: var(--c-danger); background: var(--c-danger-bg); }
.pt-card.has-warn { border-left-color: var(--c-warn); background: var(--c-warn-bg); }
.pt-card .row1 { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.pt-card .name { font-size: 1.15rem; font-weight: 700; }
.pt-card .meta { color: var(--c-ink-soft); font-size: .9rem; }
.pt-card .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  border-radius: 999px; padding: 5px 12px; font-size: .85rem; font-weight: 600;
  background: var(--c-primary-light); color: var(--c-primary-dark);
}
.chip.due { background: var(--c-warn-bg); color: var(--c-warn); }
.chip.overdue { background: var(--c-danger-bg); color: var(--c-danger); animation: pulse 1.6s infinite; }
.chip.ok { background: var(--c-ok-bg); color: var(--c-ok); }
.chip.stage { background: #e8eefc; color: #2a4d9b; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

/* ---------- alerts ---------- */
.alert-banner {
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px;
  display: flex; gap: 10px; align-items: flex-start;
}
.alert-banner.danger { background: var(--c-danger-bg); border: 1.5px solid var(--c-danger); color: #7a1410; }
.alert-banner.warn { background: var(--c-warn-bg); border: 1.5px solid var(--c-warn); color: #6b4000; }
.alert-banner .ico { font-size: 1.4rem; }
.alert-banner .body { flex: 1; }
.alert-banner .title { font-weight: 700; }
.alert-banner .advice { font-size: .9rem; margin: 4px 0 0; padding-left: 18px; }
.alert-banner .advice li { margin-bottom: 2px; }

/* ---------- wizard ---------- */
.modal-scrim {
  position: fixed; inset: 0; background: rgba(12, 30, 26, .55); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 700px) { .modal-scrim { align-items: center; } }
.modal {
  background: #fff; width: 100%; max-width: 640px; max-height: 92vh;
  border-radius: 18px 18px 0 0; overflow-y: auto; padding: 18px;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
}
@media (min-width: 700px) { .modal { border-radius: 18px; } }
.modal h2 { margin: 0 0 4px; color: var(--c-primary-dark); }
.wizard-progress { display: flex; gap: 5px; margin: 10px 0 16px; }
.wizard-progress span { flex: 1; height: 6px; border-radius: 3px; background: var(--c-line); }
.wizard-progress span.done { background: var(--c-primary); }
.wizard-q { font-size: 1.25rem; font-weight: 700; margin: 6px 0 14px; }
.wizard-help { color: var(--c-ink-soft); font-size: .9rem; margin: -8px 0 14px; }
.wizard-nav { display: flex; gap: 10px; margin-top: 18px; }
.wizard-nav .btn { flex: 1; }

/* ---------- chart ---------- */
.chart-scroll { overflow-x: auto; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }
.chart-svg { display: block; }
.chart-legend { font-size: .8rem; color: var(--c-ink-soft); padding: 8px 12px; }

/* ---------- entries table ---------- */
table.entries { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.entries th, table.entries td { border-bottom: 1px solid var(--c-line); padding: 8px 6px; text-align: left; vertical-align: top; }
table.entries th { color: var(--c-ink-soft); font-size: .8rem; }
.flagged { color: var(--c-danger); font-weight: 700; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 12px; }
.tabs button {
  flex: 0 0 auto; min-height: 44px; padding: 8px 16px; border: none; cursor: pointer;
  border-radius: 10px 10px 0 0; background: none; color: var(--c-ink-soft); font-size: .95rem; font-weight: 600;
  border-bottom: 3px solid transparent;
}
.tabs button.active { color: var(--c-primary-dark); border-bottom-color: var(--c-primary); background: #fff; }

/* ---------- toast ---------- */
#toast-root { position: fixed; bottom: 84px; left: 0; right: 0; z-index: 90; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--c-ink); color: #fff; border-radius: 10px; padding: 12px 20px;
  font-size: .95rem; box-shadow: 0 4px 14px rgba(0,0,0,.3); max-width: 90%;
  animation: toast-in .25s;
}
.toast.danger { background: var(--c-danger); }
@keyframes toast-in { from { transform: translateY(20px); opacity: 0; } }

/* ---------- misc ---------- */
.muted { color: var(--c-ink-soft); font-size: .9rem; }
.spacer { flex: 1; }
.kv { display: flex; gap: 8px; margin-bottom: 4px; font-size: .95rem; }
.kv b { min-width: 160px; color: var(--c-ink-soft); font-weight: 600; }
.checklist label { display: flex; align-items: center; gap: 12px; min-height: var(--tap); font-size: 1rem; border-bottom: 1px solid var(--c-line); }
.checklist input[type=checkbox] { width: 26px; height: 26px; accent-color: var(--c-primary); }
.apgar-score { font-size: 3rem; font-weight: 800; text-align: center; }
.apgar-score.ok { color: var(--c-ok); } .apgar-score.warn { color: var(--c-warn); } .apgar-score.bad { color: var(--c-danger); }
.empty-state { text-align: center; color: var(--c-ink-soft); padding: 40px 10px; }
.empty-state .ico { font-size: 3rem; }

.support-note {
  text-align: center; color: var(--c-ink-soft); font-size: .92rem;
  max-width: 540px; margin: 30px auto 8px; padding: 16px 14px;
  border-top: 1px solid var(--c-line); line-height: 1.5;
}
.support-note a { color: var(--c-primary); font-weight: 700; text-decoration: none; }
.support-note a:active { text-decoration: underline; }

/* ---------- print (referral note / summary) ---------- */
@media print {
  body { background: #fff; }
  .topbar, .bottom-nav, .fab, .no-print, #toast-root { display: none !important; }
  .page { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #999; page-break-inside: avoid; }
  .print-only { display: block !important; }
}
.print-only { display: none; }
