:root {
  --bg: #f6f8f4;
  --card: #ffffff;
  --text: #253331;
  --muted: #7d8c87;
  --green: #4f9d7c;
  --green-soft: #e1f1ea;
  --sun: #f2b84b;
  --sun-soft: #fdf1d6;
  --sky: #5b9bd5;
  --sky-soft: #e2eef9;
  --rose: #e07a8c;
  --rose-soft: #fbe5ea;
  --line: #e6ece8;
  --shadow: 0 2px 12px rgba(40, 80, 60, .07);
  --ok: #3f9a5f; --warn: #d99a1e; --bad: #d1484f;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141a18; --card: #1f2724; --text: #ecf2ee; --muted: #94a39d;
    --green: #6fc29d; --green-soft: #243a31; --sun: #f0c266; --sun-soft: #3d331c;
    --sky: #7cb4e6; --sky-soft: #1f2f3f; --rose: #ec94a3; --rose-soft: #3f262c;
    --line: #2b3531; --shadow: none; --ok: #6fcf8c; --warn: #f0b94a; --bad: #f07078;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141a18; --card: #1f2724; --text: #ecf2ee; --muted: #94a39d;
  --green: #6fc29d; --green-soft: #243a31; --sun: #f0c266; --sun-soft: #3d331c;
  --sky: #7cb4e6; --sky-soft: #1f2f3f; --rose: #ec94a3; --rose-soft: #3f262c;
  --line: #2b3531; --shadow: none; --ok: #6fcf8c; --warn: #f0b94a; --bad: #f07078;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  max-width: 480px; margin: 0 auto;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  line-height: 1.45;
}
body.locked { overflow: hidden; }
h1 { font-size: 1.5rem; margin: 12px 0 4px; }
h2 { font-size: 1rem; margin: 0 0 10px; }
h3 { font-size: .9rem; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0; }
small, .muted { color: var(--muted); font-size: .82rem; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--green); }

/* Header */
.top { display: flex; justify-content: space-between; align-items: center; padding: calc(12px + env(safe-area-inset-top)) 12px 8px 12px; gap: 8px; }
.child-pick { display: flex; align-items: center; gap: 10px; padding: 6px 10px 6px 6px; border-radius: 16px; background: var(--card); box-shadow: var(--shadow); text-align: left; min-width: 0; flex: 1; }
.child-ava { width: 40px; height: 40px; border-radius: 50%; background: var(--green-soft); display: grid; place-items: center; font-size: 1.3rem; overflow: hidden; flex: none; }
.child-ava img { width: 100%; height: 100%; object-fit: cover; }
.child-info { display: flex; flex-direction: column; min-width: 0; }
.child-info b { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.child-info small { white-space: nowrap; }
.chev { color: var(--muted); }
.top-actions { display: flex; gap: 2px; flex: none; }
.icon-btn { font-size: 1.2rem; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; }
.icon-btn:active { background: var(--green-soft); }

main { padding: 0 14px; }
.tab { display: none; }
.tab.active { display: block; animation: fade .2s; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.card { background: var(--card); border-radius: 20px; padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.card.tap { cursor: pointer; }
.card.tap:active { transform: scale(.99); }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.empty-state { text-align: center; padding: 40px 16px; }
.empty-state .big { font-size: 4rem; }
.empty-state p { margin: 8px 0 20px; }

/* Buttons */
.btn { display: block; width: 100%; padding: 13px; border-radius: 14px; background: var(--green); color: #fff; font-weight: 700; text-align: center; text-decoration: none; margin-top: 10px; }
.btn:disabled { opacity: .6; }
.btn.ghost { background: var(--green-soft); color: var(--green); }
.btn.danger { color: var(--bad); background: var(--rose-soft); }
.btn.sm { display: inline-block; width: auto; padding: 8px 14px; margin: 0; font-size: .85rem; }
.row-btns { display: flex; gap: 8px; }
.row-btns .btn { margin-top: 8px; }

/* Segmented */
.seg { display: flex; background: var(--bg); border-radius: 12px; padding: 3px; margin: 8px 0; }
.seg button { flex: 1; padding: 9px; border-radius: 10px; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* Forms */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin: 10px 0 0; }
label input:not([type=checkbox]), label textarea, label select {
  display: block; width: 100%; margin-top: 4px; padding: 11px 12px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--bg); color: var(--text); font-weight: 400;
}
label textarea { resize: vertical; }
label.check { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--text); padding: 8px 0; }
label.check input { width: 20px; height: 20px; accent-color: var(--green); }
.login-err { color: var(--bad); font-size: .85rem; min-height: 1.2em; margin-top: 6px; }
.ava-preview { margin-top: 8px; }
.ava-preview img { max-width: 120px; max-height: 120px; border-radius: 14px; }

/* Progress */
.bar { height: 10px; background: var(--bg); border-radius: 99px; overflow: hidden; margin: 6px 0; }
.bar i { display: block; height: 100%; background: var(--green); border-radius: 99px; transition: width .3s; }
.bar i.warn { background: var(--sun); }

/* Ring (beranda) */
.ring-wrap { position: relative; width: 110px; height: 110px; margin: 0 auto; }
.ring { width: 110px; height: 110px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--bg); stroke-width: 10; }
.ring-fg { fill: none; stroke: var(--green); stroke-width: 10; stroke-linecap: round; stroke-dasharray: 327; stroke-dashoffset: 327; transition: stroke-dashoffset .5s; }
.ring-text { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-text b { font-size: 1.3rem; }
.ring-text small { display: block; }

/* Beranda */
.hero { background: linear-gradient(135deg, var(--green-soft), var(--sky-soft)); }
.hero .age-big { font-size: 1.5rem; font-weight: 800; }
.stat-row { display: flex; gap: 8px; margin-top: 10px; }
.stat { flex: 1; background: var(--card); border-radius: 14px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 1.05rem; }
.stat small { font-size: .72rem; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .75rem; font-weight: 700; }
.pill.ok { background: var(--green-soft); color: var(--ok); }
.pill.warn { background: var(--sun-soft); color: var(--warn); }
.pill.bad { background: var(--rose-soft); color: var(--bad); }
.pill.info { background: var(--sky-soft); color: var(--sky); }
.pill.muted { background: var(--bg); color: var(--muted); }

/* Perkembangan */
.band-nav { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.band-nav::-webkit-scrollbar { display: none; }
.band-nav button { flex: none; padding: 8px 12px; border-radius: 99px; background: var(--card); font-weight: 700; font-size: .82rem; box-shadow: var(--shadow); color: var(--muted); white-space: nowrap; }
.band-nav button.active { background: var(--green); color: #fff; }
.band-nav button.now { border: 2px solid var(--green); }
.aspect-head { display: flex; align-items: center; gap: 8px; margin: 14px 0 6px; }
.aspect-head .ic { font-size: 1.2rem; }
.aspect-head b { font-size: .95rem; }
.aspect-head small { margin-left: auto; }
.item { display: flex; align-items: flex-start; gap: 10px; padding: 11px 12px; background: var(--card); border-radius: 14px; margin-bottom: 6px; box-shadow: var(--shadow); }
.item .box { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line); display: grid; place-items: center; flex: none; margin-top: 1px; font-size: .95rem; }
.item.done .box { background: var(--green); border-color: var(--green); color: #fff; }
.item .txt { flex: 1; min-width: 0; font-size: .92rem; }
.item.done .txt { color: var(--muted); }
.item .txt small { display: block; }
.item .more { color: var(--muted); padding: 2px 4px; }
.flag-list, .stim-list { margin: 0; padding-left: 20px; font-size: .9rem; }
.flag-list li, .stim-list li { margin-bottom: 6px; }
.card.warnbox { background: var(--sun-soft); }
.card.badbox { background: var(--rose-soft); }
.stim-box { background: var(--green-soft); border-radius: 14px; padding: 12px; margin-top: 10px; font-size: .92rem; }

/* Pertumbuhan */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .zone-ok { fill: var(--green); opacity: .12; }
.chart .zone-warn { fill: var(--sun); opacity: .12; }
.chart .med { stroke: var(--green); stroke-width: 1.5; fill: none; stroke-dasharray: 4 3; }
.chart .sd { stroke: var(--sun); stroke-width: 1; fill: none; }
.chart .sd3 { stroke: var(--bad); stroke-width: 1; fill: none; opacity: .6; }
.chart .line { stroke: var(--sky); stroke-width: 2.5; fill: none; stroke-linejoin: round; }
.chart .dot { fill: var(--sky); stroke: var(--card); stroke-width: 2; }
.chart text { font-size: 10px; fill: var(--muted); font-family: inherit; }
.chart-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.chart-tabs button { flex: 1; padding: 8px; border-radius: 10px; background: var(--bg); font-size: .8rem; font-weight: 700; color: var(--muted); }
.chart-tabs button.active { background: var(--green); color: #fff; }
.measure-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.measure-row:last-child { border: 0; }
.measure-row .d { width: 72px; font-size: .8rem; color: var(--muted); flex: none; }
.measure-row .v { flex: 1; font-size: .9rem; }
.measure-row .v b { margin-right: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: .75rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 4px; border-radius: 2px; }

/* Imunisasi */
.imun-group { margin-bottom: 14px; }
.imun-group h3 { margin: 8px 0 6px; }
.imun { display: flex; align-items: center; gap: 10px; padding: 11px 12px; background: var(--card); border-radius: 14px; margin-bottom: 6px; box-shadow: var(--shadow); }
.imun .ic { font-size: 1.3rem; width: 34px; text-align: center; flex: none; }
.imun .txt { flex: 1; min-width: 0; font-size: .9rem; }
.imun .txt small { display: block; }
.imun.done { opacity: .75; }
.imun.done .txt b { text-decoration: line-through; color: var(--muted); }
.imun.skip .txt b { color: var(--muted); }
.imun.overdue { border-left: 4px solid var(--bad); }
.imun.due { border-left: 4px solid var(--sun); }

/* Momen */
.moment { padding: 0; overflow: hidden; }
.moment img { width: 100%; max-height: 300px; object-fit: cover; display: block; cursor: zoom-in; }
.moment .body { padding: 12px 14px; }
.moment .body p { white-space: pre-wrap; font-size: .92rem; margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { padding: 6px 12px; border-radius: 99px; background: var(--bg); font-size: .8rem; font-weight: 600; color: var(--muted); border: 1.5px solid transparent; }
.chip.active { background: var(--green-soft); color: var(--green); border-color: var(--green); }
.fab { position: fixed; right: max(16px, calc(50% - 240px + 16px)); bottom: calc(76px + env(safe-area-inset-bottom)); width: 54px; height: 54px; border-radius: 50%; background: var(--green); color: #fff; font-size: 1.6rem; box-shadow: 0 6px 18px rgba(40,100,70,.3); display: grid; place-items: center; z-index: 5; }

/* Bottom nav */
.bottom {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 480px;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 10;
}
.nav-btn { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: .68rem; font-weight: 700; color: var(--muted); padding: 4px 0; border-radius: 12px; }
.nav-btn span { font-size: 1.3rem; }
.nav-btn.active { color: var(--green); }

/* Sheets */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet[hidden] { display: none; }
.sheet-body {
  background: var(--card); width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  border-radius: 22px 22px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up .2s;
}
@keyframes up { from { transform: translateY(40px); } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 1.1rem; }
.child-row { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 14px; }
.child-row.active { background: var(--green-soft); }
.child-row .grow b { display: block; }
.child-row .edit { color: var(--muted); padding: 6px; }

/* Login */
.login-screen { position: fixed; inset: 0; background: var(--bg); z-index: 30; overflow-y: auto; }
.login-wrap { max-width: 400px; margin: 0 auto; padding: calc(40px + env(safe-area-inset-top)) 20px 40px; text-align: center; }
.login-logo img { border-radius: 22px; }
.login-card { text-align: left; margin-top: 20px; }
.login-links { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; font-size: .85rem; text-align: center; }
.login-note { margin-top: 16px; }
.account { display: flex; align-items: center; gap: 10px; }
.account .avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--green-soft); color: var(--green); display: grid; place-items: center; font-weight: 800; }
.account b { display: block; font-size: .9rem; word-break: break-all; }
.account small { display: block; }
.ck-link { margin-top: 8px; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 40; display: grid; place-items: center; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; }
.lightbox .icon-btn { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 10px; color: #fff; font-size: 1.5rem; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-size: .85rem; font-weight: 600; z-index: 50; white-space: nowrap; max-width: 90vw; overflow: hidden; text-overflow: ellipsis; animation: fade .2s; }
.toast[hidden] { display: none; }

.hint { background: var(--sky-soft); border-radius: 14px; padding: 10px 12px; font-size: .85rem; margin-bottom: 12px; }
.badge-n { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--bad); color: #fff; font-size: .68rem; font-weight: 800; }
