/* ============ TOKENS ============ */
:root{
  --bg: #14141c;
  --bg-elev: #1b1c27;
  --surface: #21222f;
  --surface-2: #2a2c3c;
  --border: rgba(255,255,255,.07);
  --text: #EDEEF3;
  --text-dim: #9a9db1;
  --text-faint: #686b80;

  --twinA: #8FB49C;
  --twinA-soft: rgba(143,180,156,.16);
  --twinB: #D98A96;
  --twinB-soft: rgba(217,138,150,.16);

  --amber: #E3B23C;
  --amber-soft: rgba(227,178,60,.16);
  --danger: #E0645A;
  --danger-soft: rgba(224,100,90,.14);

  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 11px;

  --font-display: "Fraunces", serif;
  --font-body: "Manrope", -apple-system, BlinkMacSystemFont, sans-serif;

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

*{ box-sizing: border-box; }
html,body{ margin:0; padding:0; }
body{
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button{ font-family: inherit; }
h1,h2,h3{ font-family: var(--font-display); margin:0; }

#app{
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  background: var(--bg);
  display:flex;
  flex-direction: column;
}

/* ============ TOPBAR ============ */
.topbar{
  position: sticky; top:0; z-index: 20;
  background: linear-gradient(180deg, var(--bg) 70%, rgba(20,20,28,0));
  padding: calc(14px + var(--safe-top)) 18px 6px;
}
.topbar-row{ display:flex; align-items:center; justify-content:space-between; }
.brand{ display:flex; align-items:center; gap:8px; }
.brand-name{ font-family: var(--font-display); font-weight:600; font-size: 19px; letter-spacing: .2px; }
.sync-dot{
  width:8px; height:8px; border-radius:50%;
  background: var(--text-faint);
  box-shadow: 0 0 0 3px rgba(255,255,255,.03);
  transition: background .3s;
}
.sync-dot.synced{ background: var(--twinA); }
.sync-dot.syncing{ background: var(--amber); animation: blink 1s infinite; }
.sync-dot.error{ background: var(--danger); }
@keyframes blink{ 50%{ opacity:.35; } }

.twin-switch{
  display:flex; gap:6px; margin-top:14px;
  background: var(--surface); border-radius: 100px; padding: 4px;
  border: 1px solid var(--border);
}
.twin-tab{
  flex:1; border:none; background:transparent; color: var(--text-dim);
  padding: 9px 8px; border-radius: 100px; font-weight:700; font-size: 14px;
  display:flex; align-items:center; justify-content:center; gap:7px;
  transition: background .2s, color .2s;
}
.twin-tab .dot{ width:8px; height:8px; border-radius:50%; flex-shrink:0; }
.twin-tab.active{ background: var(--surface-2); color: var(--text); }

/* ============ MAIN / VIEWS ============ */
main{ flex:1; padding: 14px 18px 130px; }
.view{ display:none; animation: fadein .25s ease; }
.view.active{ display:block; }
@keyframes fadein{ from{ opacity:0; transform: translateY(4px);} to{opacity:1; transform:none;} }

.section-title{
  font-size: 13px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-faint); font-weight:700; margin: 22px 2px 10px;
}
.section-title:first-child{ margin-top: 4px; }

/* pulse divider — signature element */
.pulse-divider{
  height: 26px; margin: 18px 0 4px;
  background-repeat: no-repeat; background-position: center;
  background-size: 200% 100%;
  background-image: linear-gradient(90deg, transparent, transparent);
  position: relative;
  opacity: .55;
}
.pulse-divider::before{
  content:"";
  position:absolute; inset:0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 26'%3E%3Cpath d='M0 13 H100 L112 3 L128 23 L142 13 H300' fill='none' stroke='%238FB49C' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 26'%3E%3Cpath d='M0 13 H140 L152 5 L168 21 L182 13 H300' fill='none' stroke='%23D98A96' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  background-size: 300px 26px;
  animation: pulse-scroll 9s linear infinite;
}
@media (prefers-reduced-motion: reduce){ .pulse-divider::before{ animation:none; } }
@keyframes pulse-scroll{ from{ background-position: 0 0, 0 0; } to{ background-position: -300px 0, 300px 0; } }

/* ============ STATUS CARDS ============ */
.status-row{ display:grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.status-card{
  background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-md);
  padding: 10px 12px; position:relative; overflow:hidden;
}
.status-card .baby-name{ font-weight:700; font-size:12px; display:flex; align-items:center; gap:5px; }
.status-card .baby-name .dot{ width:7px; height:7px; border-radius:50%; }
.status-card .state-label{ font-family: var(--font-display); font-size:16px; margin-top:4px; line-height:1.2; }
.status-card .state-sub{ color: var(--text-dim); font-size:11px; margin-top:1px; }
.status-card.active-timer{ box-shadow: inset 0 0 0 1.5px currentColor; }

/* ============ UPCOMING TASKS BAND ============ */
.upcoming-band{
  display:flex; gap:8px; overflow-x:auto; margin-top:10px; padding-bottom:2px;
}
.upcoming-band::-webkit-scrollbar{ display:none; }
.upcoming-chip{
  flex-shrink:0; min-width:126px; background: var(--amber-soft); border:1px solid rgba(227,178,60,.4);
  border-radius: var(--radius-md); padding: 9px 12px;
}
.upcoming-chip.overdue{ background: var(--danger-soft); border-color: var(--danger); }
.upcoming-chip .uc-title{ font-weight:700; font-size:12px; display:flex; align-items:center; gap:5px; white-space:nowrap; }
.upcoming-chip .uc-time{ font-family: var(--font-display); font-size:15px; margin-top:3px; }
.upcoming-chip .uc-sub{ font-size:10.5px; color: var(--text-faint); margin-top:1px; white-space:nowrap; }

/* ============ QUICK ACTIONS ============ */
.quick-grid{ display:grid; grid-template-columns: repeat(3,1fr); gap:10px; }
.quick-btn{
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 14px 6px 10px; display:flex; flex-direction:column; align-items:center; gap:7px;
  color: var(--text); font-weight:600; font-size: 12px; text-align:center;
  transition: transform .12s, background .12s;
}
.quick-btn:active{ transform: scale(.94); background: var(--surface-2); }
.quick-btn svg{ width:22px; height:22px; }
.quick-btn.running{ background: var(--amber-soft); border-color: var(--amber); color: var(--amber); }

/* ============ TODAY STATS ============ */
.today-stats{ display:grid; grid-template-columns: repeat(2,1fr); gap:10px; }
.stat-pill{
  background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-md);
  padding: 12px 14px;
}
.stat-pill .num{ font-family: var(--font-display); font-size: 22px; font-weight:600; }
.stat-pill .lbl{ font-size:12px; color: var(--text-dim); margin-top:2px; }

/* ============ TIMELINE ============ */
.filter-chips{ display:flex; gap:8px; overflow-x:auto; padding-bottom:4px; margin-bottom: 6px;}
.filter-chips::-webkit-scrollbar{ display:none; }
.chip{
  flex-shrink:0; padding: 7px 14px; border-radius:100px; background: var(--surface);
  border:1px solid var(--border); color: var(--text-dim); font-size:13px; font-weight:600;
}
.chip.active{ background: var(--surface-2); color: var(--text); border-color: var(--text-faint); }

.timeline-list{ display:flex; flex-direction:column; gap:8px; margin-top: 8px; }
.tl-day-label{ font-size:12px; color:var(--text-faint); font-weight:700; margin: 14px 2px 2px; text-transform:uppercase; letter-spacing:.06em; }
.tl-item{
  background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-md);
  padding: 12px 13px; display:flex; gap:11px; align-items:flex-start;
}
.tl-icon{
  width:34px; height:34px; border-radius:10px; flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
}
.tl-icon svg{ width:17px; height:17px; }
.tl-body{ flex:1; min-width:0; }
.tl-title{ font-weight:700; font-size:14px; display:flex; justify-content:space-between; gap:8px; }
.tl-title .baby-dot{ width:7px; height:7px; border-radius:50%; display:inline-block; margin-right:5px; }
.tl-meta{ color: var(--text-dim); font-size:12.5px; margin-top:2px; }
.tl-notes{ color: var(--text-dim); font-size:12.5px; margin-top:4px; font-style:italic; }
.tl-time{ color: var(--text-faint); font-size:12px; white-space:nowrap; }
.tl-empty{ text-align:center; color: var(--text-faint); padding: 40px 20px; font-size:14px; }

/* ============ GROWTH ============ */
.growth-baby-toggle{ display:flex; gap:8px; margin-bottom:14px; }
.growth-baby-toggle .chip{ flex:1; text-align:center; justify-content:center; display:flex; }
#growthChart{ background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-lg); padding: 10px; margin-bottom: 14px; }
.btn-add-growth{
  width:100%; padding: 13px; border-radius: var(--radius-md); border:1px dashed var(--text-faint);
  background: transparent; color: var(--text-dim); font-weight:700; font-size:14px; margin-bottom:16px;
}
.growth-list{ display:flex; flex-direction:column; gap:8px; }
.growth-row{
  background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-md);
  padding: 11px 13px; display:flex; justify-content:space-between; align-items:center; font-size:13.5px;
}
.growth-row .g-date{ color:var(--text-faint); font-size:12px; }
.growth-row .g-vals{ display:flex; gap:14px; font-weight:600; }
.growth-row .g-vals small{ display:block; color:var(--text-faint); font-weight:500; font-size:10.5px; }
.growth-row .g-thumb{ width:38px; height:38px; border-radius:9px; object-fit:cover; margin-right:10px; flex-shrink:0; }
.photo-preview{ width:100%; max-height:180px; object-fit:cover; border-radius: var(--radius-md); margin-top:8px; display:none; }
.photo-preview.show{ display:block; }
.photo-remove{ color: var(--danger); background:none; border:none; font-size:12.5px; font-weight:700; margin-top:6px; display:none; }
.photo-remove.show{ display:inline-block; }

/* ============ MEDICATION ============ */
.med-plans-list, .med-agenda-list{ display:flex; flex-direction:column; gap:9px; }
.med-plan-card{
  background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-md);
  padding: 13px 14px;
}
.med-plan-top{ display:flex; justify-content:space-between; align-items:flex-start; gap:8px; }
.med-plan-name{ font-weight:700; font-size:14.5px; display:flex; align-items:center; gap:6px; }
.med-plan-name .dot{ width:8px; height:8px; border-radius:50%; flex-shrink:0; }
.med-plan-dose{ color: var(--text-dim); font-size:12.5px; margin-top:2px; }
.med-plan-next{ font-size:12.5px; margin-top:8px; font-weight:700; }
.med-plan-next.overdue{ color: var(--danger); }
.med-plan-next.upcoming{ color: var(--text-dim); font-weight:600; }
.med-plan-actions{ display:flex; gap:8px; margin-top:10px; }
.med-plan-actions button{ flex:1; padding:9px; border-radius:10px; font-weight:700; font-size:12.5px; border:1px solid var(--border); background:var(--surface-2); color:var(--text); }
.med-plan-actions .btn-give{ background: var(--twinA-soft); border-color: var(--twinA); color: var(--twinA); }
.med-plan-icon-btn{ background:none; border:none; color:var(--text-faint); padding:4px; font-size:16px; }
.med-plan-paused{ opacity:.55; }

.agenda-day-label{ font-size:12px; color:var(--text-faint); font-weight:700; margin: 12px 2px 2px; text-transform:uppercase; letter-spacing:.06em; }
.agenda-item{
  background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-md);
  padding: 11px 13px; display:flex; align-items:center; gap:11px;
}
.agenda-item.overdue{ border-color: var(--danger); }
.agenda-time{ font-weight:700; font-size:13.5px; width:52px; flex-shrink:0; color:var(--text-dim); }
.agenda-body{ flex:1; min-width:0; font-size:13.5px; font-weight:600; }
.agenda-body .baby-dot{ width:7px; height:7px; border-radius:50%; display:inline-block; margin-right:5px; }
.agenda-sub{ color: var(--text-faint); font-size:11.5px; font-weight:500; margin-top:1px; }
.agenda-status{ font-size:11.5px; font-weight:800; padding:5px 9px; border-radius:100px; flex-shrink:0; }
.agenda-status.given{ background: var(--twinA-soft); color: var(--twinA); }
.agenda-status.overdue{ background: var(--danger-soft); color: var(--danger); }
.agenda-status.upcoming{ background: var(--surface-2); color: var(--text-dim); }
.agenda-status button{ background:none; border:none; color:inherit; font-weight:800; font-size:11.5px; }

/* ============ STATS / OVERVIEW ============ */
.stat-chart-card{
  background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-lg);
  padding: 14px; margin-bottom: 14px;
}
.stat-chart-title{ font-size:12.5px; font-weight:700; color: var(--text-dim); margin-bottom:10px; }

/* ============ SETTINGS ============ */
.baby-settings{ display:flex; flex-direction:column; gap:10px; }
.baby-edit-row{
  background: var(--surface); border:1px solid var(--border); border-radius: var(--radius-md);
  padding: 12px 13px; display:flex; align-items:center; gap:12px;
}
.baby-edit-row input[type=text]{
  flex:1; background: transparent; border:none; color: var(--text); font-weight:700; font-size:15px;
  border-bottom: 1px solid var(--border); padding: 4px 0;
}
.color-dot-btn{ width:22px; height:22px; border-radius:50%; border: 2px solid rgba(255,255,255,.25); flex-shrink:0; }
.settings-hint{ color: var(--text-dim); font-size:13px; line-height:1.5; margin: 0 2px; }
.settings-row{ display:flex; gap:10px; }
.btn-secondary{
  flex:1; background: var(--surface); border:1px solid var(--border); color: var(--text);
  padding: 12px; border-radius: var(--radius-md); font-weight:700; font-size:13.5px;
}
.btn-danger{
  width:100%; background: var(--danger-soft); border:1px solid var(--danger); color: var(--danger);
  padding: 12px; border-radius: var(--radius-md); font-weight:700; font-size:13.5px;
}
.danger-zone-tiny{ display:flex; justify-content:flex-start; margin: 2px 2px 0; }
.btn-danger-tiny{
  background:none; border:none; color: var(--text-faint); font-size: 11px; font-weight:600;
  padding: 4px 0; text-decoration: underline; text-decoration-color: rgba(224,100,90,.4); text-underline-offset: 2px;
  opacity: .7;
}
.btn-danger-tiny:active{ opacity: 1; color: var(--danger); }

/* ============ SLEEP PREDICTION ============ */
.predict-card{
  background: linear-gradient(135deg, rgba(143,180,156,.10), rgba(217,138,150,.08));
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 14px 16px; margin-top: 12px;
}
.predict-title{ font-size:12px; text-transform:uppercase; letter-spacing:.08em; color: var(--text-faint); font-weight:700; margin-bottom:8px; }
.predict-row{ display:flex; align-items:center; justify-content:space-between; padding: 7px 0; }
.predict-row + .predict-row{ border-top: 1px solid var(--border); }
.predict-baby{ display:flex; align-items:center; gap:7px; font-weight:700; font-size:13.5px; }
.predict-baby .dot{ width:8px; height:8px; border-radius:50%; }
.predict-val{ font-family: var(--font-display); font-size:16px; font-weight:600; }
.predict-sub{ color: var(--text-faint); font-size:11px; margin-top:1px; }
.predict-hint{ color: var(--text-faint); font-size:12px; }

/* ============ BOTTOM NAV ============ */
.bottombar{
  position: fixed; bottom:0; left:50%; transform:translateX(-50%);
  width:100%; max-width:480px; z-index: 30;
  background: rgba(27,28,39,.9); backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  display:flex; padding: 8px 6px calc(8px + var(--safe-bottom));
}
.nav-btn{
  flex:1; background:none; border:none; color: var(--text-faint);
  display:flex; flex-direction:column; align-items:center; gap:3px; padding:6px 0; font-size:9.5px; font-weight:700;
}
.nav-btn svg{ width:19px; height:19px; }
.nav-btn.active{ color: var(--text); }
.nav-btn span{ white-space:nowrap; }

/* ============ TIMER BAR (floating, running timers) ============ */
.timer-bar{
  position: fixed; left:50%; transform: translateX(-50%);
  bottom: 78px; max-width: 440px; width: calc(100% - 32px); z-index: 25;
  display:flex; flex-direction:column; gap:8px; pointer-events:none;
}
.timer-chip{
  pointer-events:all;
  background: var(--surface-2); border:1px solid var(--border); border-radius: 100px;
  padding: 10px 16px; display:flex; align-items:center; justify-content:space-between;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.timer-chip .tc-left{ display:flex; align-items:center; gap:9px; font-weight:700; font-size:13.5px; }
.timer-chip .dot{ width:8px; height:8px; border-radius:50%; animation: blink 1.4s infinite; }
.timer-chip .tc-time{ font-variant-numeric: tabular-nums; color: var(--text-dim); font-size:13px; margin-right:10px;}
.timer-chip button{ background: none; border:none; color: var(--danger); font-weight:800; font-size:12.5px; padding: 6px 10px; }

/* ============ SHEET / MODAL ============ */
.sheet-overlay{
  position: fixed; inset:0; background: rgba(0,0,0,.55); z-index: 50;
  display:none; align-items:flex-end; justify-content:center;
}
.sheet-overlay.open{ display:flex; }
.sheet{
  background: var(--bg-elev); width:100%; max-width:480px;
  border-radius: 26px 26px 0 0; padding: 10px 20px calc(22px + var(--safe-bottom));
  max-height: 88vh; overflow-y:auto;
  animation: sheet-up .28s cubic-bezier(.2,.9,.25,1);
}
@keyframes sheet-up{ from{ transform: translateY(24px); opacity:0;} to{ transform:none; opacity:1;} }
.sheet-handle{ width:38px; height:4px; background: var(--border); border-radius:4px; margin: 6px auto 14px; }
.sheet h3{ font-size:19px; margin-bottom: 4px; }
.sheet .sheet-sub{ color:var(--text-dim); font-size:13px; margin-bottom: 16px; }

.form-group{ margin-bottom: 14px; }
.form-label{ font-size:12.5px; color:var(--text-dim); font-weight:700; margin-bottom:6px; display:block; }
.form-row{ display:flex; gap:8px; }
.form-row .form-group{ flex:1; }
.seg{ display:flex; gap:7px; flex-wrap:wrap; }
.seg-btn{
  flex:1; min-width: 70px; background: var(--surface); border:1px solid var(--border); color: var(--text-dim);
  padding: 10px 8px; border-radius: var(--radius-sm); font-weight:700; font-size:13px; text-align:center;
}
.seg-btn.active{ background: var(--surface-2); color: var(--text); border-color: var(--text-faint); }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=datetime-local], textarea, select{
  width:100%; background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 11px 12px; border-radius: var(--radius-sm); font-size:14.5px; font-family: inherit;
}
textarea{ resize:vertical; min-height: 54px; }
.sheet-actions{ display:flex; gap:10px; margin-top: 18px; }
.btn-primary{
  flex:1; padding: 14px; border-radius: var(--radius-md); border:none; font-weight:800; font-size:14.5px;
  color: #14141c;
}
.btn-cancel{
  padding: 14px 18px; border-radius: var(--radius-md); border:1px solid var(--border); background:none; color: var(--text-dim); font-weight:700;
}
.btn-delete-entry{ color: var(--danger); background:none; border:none; font-weight:700; font-size:13px; margin-top:8px; }
