/* Dark-first: this app is read at 3am, one-handed, next to a sleeping baby. */

:root {
  --bg: #0e1116;
  --surface: #171c24;
  --surface-2: #1f2630;
  --border: #2a333f;
  --text: #e8edf4;
  --text-dim: #93a1b5;
  --text-faint: #65748a;

  --sleep: #7c8cf8;
  --feed: #4fc3a1;
  --nappy: #e8b84b;
  --milestone: #f0866b;

  --danger: #ef5f6b;
  --ok: #4fc3a1;

  --radius: 16px;
  --radius-sm: 10px;
  --tap: 52px;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #eef1f5;
    --border: #dde2e9;
    --text: #141a22;
    --text-dim: #5a6778;
    --text-faint: #8794a6;
    --sleep: #4f5fd4;
    --feed: #1f9b78;
    --nappy: #b8860b;
    --milestone: #d4583a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: contain;
}

body {
  /* Fill the screen in a wrapped Android app, notch included. */
  min-height: 100vh;
  min-height: 100dvh;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; border: none; background: none; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 92px);
}

/* ---------- header ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.baby-pick {
  flex: 1;
  min-width: 0;
}

.baby-name {
  font-size: 1.35rem;
  font-weight: 680;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  padding: 0;
}

.baby-age {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.sync-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); flex: none; }
.sync-chip[data-s='synced'] .dot { background: var(--ok); }
.sync-chip[data-s='syncing'] .dot { background: var(--nappy); animation: pulse 1s infinite; }
.sync-chip[data-s='error'] .dot { background: var(--danger); }
.sync-chip[data-s='offline'] .dot { background: var(--text-faint); }

@keyframes pulse { 50% { opacity: 0.3; } }

/* ---------- the hero: current state ---------- */

.hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px;
  margin-bottom: 14px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.hero.sleeping {
  background: linear-gradient(160deg, color-mix(in srgb, var(--sleep) 22%, var(--surface)), var(--surface));
  border-color: color-mix(in srgb, var(--sleep) 40%, var(--border));
}

.hero-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.hero-value {
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  margin-bottom: 4px;
}

.hero-sub { color: var(--text-dim); font-size: 0.9rem; }

.big-btn {
  display: block;
  width: 100%;
  margin-top: 18px;
  min-height: 60px;
  border-radius: 14px;
  font-size: 1.05rem;
  font-weight: 650;
  background: var(--sleep);
  color: #fff;
  transition: transform 0.08s, filter 0.15s;
}
.big-btn:active { transform: scale(0.98); filter: brightness(1.1); }
.big-btn.stop { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }

/* ---------- quick stats ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  text-align: center;
}
.stat-v { font-size: 1.2rem; font-weight: 680; font-variant-numeric: tabular-nums; }
.stat-l { font-size: 0.68rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }

/* ---------- quick actions ---------- */

.section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 22px 0 10px;
  font-weight: 650;
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.action {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-weight: 550;
  text-align: left;
  transition: transform 0.08s;
}
.action:active { transform: scale(0.97); }
.action .ic { font-size: 1.2rem; flex: none; }
.action.wide { grid-column: span 2; }

/* ---------- list / timeline ---------- */

.day-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 20px 0 8px;
  color: var(--text-dim);
  font-size: 0.8rem;
  font-weight: 600;
}

.ev {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 7px;
  width: 100%;
  text-align: left;
}

.ev-bar { width: 3px; align-self: stretch; border-radius: 2px; flex: none; }
.ev[data-t='sleep'] .ev-bar { background: var(--sleep); }
.ev[data-t='feed'] .ev-bar { background: var(--feed); }
.ev[data-t='nappy'] .ev-bar { background: var(--nappy); }
.ev[data-t='milestone'] .ev-bar { background: var(--milestone); }
.ev[data-t='note'] .ev-bar { background: var(--text-faint); }

.ev-body { flex: 1; min-width: 0; }
.ev-main { font-weight: 560; }
.ev-meta { font-size: 0.78rem; color: var(--text-dim); margin-top: 1px; }
.ev-time { font-size: 0.85rem; color: var(--text-dim); font-variant-numeric: tabular-nums; flex: none; text-align: right; }
.ev-dur { font-size: 0.72rem; color: var(--text-faint); }

.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--text-faint);
}
.empty-ic { font-size: 2.4rem; display: block; margin-bottom: 10px; opacity: 0.7; }

/* ---------- 24h strip ---------- */

.strip {
  display: flex;
  height: 30px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin-bottom: 6px;
}
.strip-seg { height: 100%; }
.strip-axis {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--text-faint);
  margin-bottom: 18px;
  font-variant-numeric: tabular-nums;
}

/* ---------- bottom nav ---------- */

.nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 40;
}

.nav button {
  flex: 1;
  padding: 9px 0 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text-faint);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.nav button .ic { font-size: 1.25rem; line-height: 1; }
.nav button[aria-current='page'] { color: var(--text); }

/* ---------- sheet (modal) ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.15s;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  background: var(--surface);
  width: 100%;
  max-width: 560px;
  border-radius: 20px 20px 0 0;
  padding: 8px 18px calc(var(--safe-bottom) + 20px);
  max-height: 88vh;
  overflow-y: auto;
  animation: rise 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes rise { from { transform: translateY(100%); } }

.grab { width: 38px; height: 4px; border-radius: 2px; background: var(--border); margin: 8px auto 14px; }

.sheet h2 { margin: 0 0 16px; font-size: 1.15rem; font-weight: 680; }

/* ---------- forms ---------- */

label.field { display: block; margin-bottom: 14px; }
label.field > span {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 620;
}

input[type='text'], input[type='email'], input[type='password'],
input[type='number'], input[type='date'], input[type='time'],
input[type='datetime-local'], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 0 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}
textarea { min-height: 88px; padding: 12px 14px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--sleep); }

.seg {
  display: flex;
  gap: 6px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.seg button {
  flex: 1;
  min-height: 44px;
  border-radius: 7px;
  font-weight: 600;
  color: var(--text-dim);
  font-size: 0.9rem;
}
.seg button[aria-pressed='true'] { background: var(--sleep); color: #fff; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 10px 15px;
  min-height: 44px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 560;
}
.chip[aria-pressed='true'] { background: var(--feed); color: #fff; border-color: transparent; }

.btn {
  width: 100%;
  min-height: 54px;
  border-radius: 12px;
  background: var(--sleep);
  color: #fff;
  font-weight: 650;
  font-size: 1rem;
  margin-top: 6px;
}
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); }
.btn:disabled { opacity: 0.5; }
.btn:active:not(:disabled) { filter: brightness(1.12); }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* ---------- family / settings ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card h3 { margin: 0 0 4px; font-size: 1rem; font-weight: 660; }
.card p { margin: 0 0 12px; color: var(--text-dim); font-size: 0.88rem; }

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-align: center;
  padding: 16px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  user-select: all;
}

.member {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.member:last-child { border-bottom: none; }
.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-weight: 680;
  flex: none;
  font-size: 0.9rem;
}
.member-body { flex: 1; min-width: 0; }
.member-name { font-weight: 580; }
.member-role { font-size: 0.76rem; color: var(--text-dim); }

.pill {
  font-size: 0.68rem;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  font-weight: 620;
}

.note {
  font-size: 0.82rem;
  color: var(--text-dim);
  background: var(--surface-2);
  border-left: 3px solid var(--sleep);
  padding: 11px 13px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 14px;
}
.note.warn { border-left-color: var(--nappy); }
.note.bad { border-left-color: var(--danger); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 78px);
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  z-index: 80;
  animation: rise 0.2s;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
  max-width: 88vw;
  text-align: center;
}

/* ---------- onboarding ---------- */

.welcome { padding-top: 8vh; text-align: center; }
.welcome .logo { font-size: 3.6rem; margin-bottom: 8px; }
.welcome h1 { font-size: 1.8rem; margin: 0 0 8px; letter-spacing: -0.02em; }
.welcome p { color: var(--text-dim); margin: 0 0 28px; }

.link { color: var(--sleep); text-decoration: underline; background: none; padding: 0; font-size: inherit; }

.hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
