:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --card: rgba(255, 255, 255, 0.92);
  --text: #182033;
  --muted: #667089;
  --border: rgba(35, 54, 96, 0.12);
  --primary: #5f7dff;
  --primary-dark: #3d5fff;
  --sleep: #8ea2ff;
  --wake: #ffd36a;
  --feed: #6fdcc0;
  --diaper: #bba8ff;
  --note: #ffb562;
  --danger: #df3f4c;
  --success: #109860;
  --shadow: 0 14px 36px rgba(21, 40, 82, 0.1);
  font-family: "SF Pro Text", "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: linear-gradient(180deg, #fff8fb 0%, #fff1e7 100%);
  color: var(--text);
}
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, #fff8fb 0%, #fff1e7 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 9999;
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 30, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10000;
}

.confirm-card {
  width: min(100%, 420px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.confirm-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.login-card {
  width: min(100%, 440px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.login-form {
  margin-top: 10px;
}
.login-error {
  margin-top: 10px;
  color: var(--danger);
  font-weight: 700;
}
body.auth-required .app-shell {
  filter: blur(2px);
  pointer-events: none;
  user-select: none;
}

body.night-mode {
  --card: rgba(20, 24, 33, 0.92);
  --text: #e8edf7;
  --muted: #aeb8cb;
  --border: rgba(164, 178, 213, 0.2);
  --shadow: 0 18px 48px rgba(4, 8, 18, 0.55);
  background: linear-gradient(180deg, #0f1420 0%, #161d2c 100%);
}
body.night-mode .eyebrow { color: #b8c8ff; }
body.night-mode .card,
body.night-mode .history-item,
body.night-mode .summary-box,
body.night-mode .stat-card,
body.night-mode .schedule-block,
body.night-mode #activeSleepNote,
body.night-mode #selectedDay,
body.night-mode input,
body.night-mode textarea,
body.night-mode select {
  background: rgba(20, 24, 33, 0.96);
  color: var(--text);
  border-color: var(--border);
}
body.night-mode .pill,
body.night-mode .ghost-button {
  background: rgba(35, 42, 58, 0.95);
  color: var(--text);
  border-color: var(--border);
}
body.night-mode .danger-button { background: rgba(88, 31, 43, 0.35); }
body.night-mode .history-filters .filter-btn.active {
  background: rgba(132, 154, 255, 0.26);
  border-color: rgba(132, 154, 255, 0.5);
  color: #dfe7ff;
}
button, input, textarea, select { font: inherit; }
button {
  font-family: "SF Pro Text", "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 120ms ease, filter 150ms ease, box-shadow 220ms ease;
  will-change: transform;
}
button:active,
button.is-pressed {
  transform: translateY(1px) scale(0.98);
  filter: brightness(0.96);
}

@keyframes tapFlash {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 139, 167, 0.45);
  }
  100% {
    box-shadow: 0 0 0 12px rgba(255, 139, 167, 0);
  }
}

button.tap-flash {
  animation: tapFlash 320ms ease-out;
}

.app-shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 24px max(40px, env(safe-area-inset-bottom));
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 24px;
}
.hero-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary-dark);
  font-size: 0.78rem;
  font-weight: 700;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; }
.subtitle { color: var(--muted); max-width: 60ch; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.quick-actions, .timeline-card { margin-bottom: 16px; }
.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.pill {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.9rem;
}
.pill.ok {
  color: var(--success);
  border-color: rgba(11, 143, 85, 0.18);
}
.pill.error {
  color: var(--danger);
  border-color: rgba(224, 49, 49, 0.18);
}

.active-sleep-panel,
.diaper-prompt-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  padding: 30px 22px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(142, 162, 255, 0.18) 0%, rgba(255,255,255,0.96) 100%);
  border: 1px solid rgba(95, 125, 255, 0.25);
  margin-bottom: 18px;
}
.active-sleep-label {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}
#activeSleepTimer {
  font-size: 4.25rem;
  line-height: 1;
}
.active-sleep-since {
  margin: 0;
  color: var(--muted);
}
#activeSleepNote {
  width: min(100%, 520px);
  min-height: 88px;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px 16px;
  background: rgba(255,255,255,0.95);
}
.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
}
.diaper-prompt-actions {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.diaper-prompt-actions .action-button {
  min-height: 110px;
}
.action-button,
.prompt-choice-button {
  border: 1px solid rgba(24, 32, 51, 0.08);
  border-radius: 18px;
  min-height: 118px;
  padding: 20px;
  color: #142033;
  font-size: 1.06rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: 0 8px 20px rgba(22, 39, 78, 0.1), inset 0 -2px rgba(255,255,255,0.25);
}
.sleep { background: var(--sleep); }
.wake { background: var(--wake); }
.feed { background: var(--feed); }
.diaper { background: var(--diaper); }
.note { background: var(--note); }

.quick-form {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.hidden { display: none !important; }
.form-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.field-group { margin-bottom: 12px; }
label {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
}
input[type="datetime-local"], input[type="search"], input[type="date"], textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
  box-shadow: inset 0 1px 2px rgba(23, 39, 78, 0.05);
}
textarea { resize: vertical; }
.choice-chips {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.choice-chip {
  position: relative;
  cursor: pointer;
}
.choice-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.choice-chip span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  padding: 12px 14px;
  border-radius: 999px;
  background: white;
  border: 1px solid var(--border);
  font-weight: 700;
}
.choice-chip input:checked + span {
  background: rgba(183, 161, 255, 0.18);
  border-color: rgba(123, 92, 255, 0.42);
  color: #5f3dc4;
}

.primary-button, .ghost-button, .danger-button, .text-button {
  border-radius: 12px;
  padding: 13px 16px;
  border: none;
  font-weight: 600;
}
.primary-button {
  background: linear-gradient(180deg, #6a86ff 0%, #4f72ff 100%);
  color: white;
  width: 100%;
  min-height: 60px;
  font-size: 1.06rem;
}
.ghost-button {
  background: rgba(255,255,255,0.9);
  color: var(--text);
  border: 1px solid var(--border);
}
.danger-button {
  background: #fff2f4;
  color: var(--danger);
  border: 1px solid rgba(223, 63, 76, 0.18);
}
.text-button {
  background: transparent;
  color: var(--primary-dark);
  padding-inline: 0;
}
.danger-text { color: var(--danger); }

.stats-grid, .summary-grid, .insights-grid {
  display: grid;
  gap: 12px;
}
.stats-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 16px;
}
.stats-grid.extended {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.stat-card strong {
  font-size: 1.05rem;
}
.stat-card.highlight {
  background: linear-gradient(180deg, rgba(255,255,255,0.96) 0%, rgba(255, 240, 245, 0.92) 100%);
}
.summary-card { margin-bottom: 16px; }
#selectedDay {
  width: auto;
  min-width: 170px;
  border-radius: 999px;
  padding: 12px 16px;
  background: linear-gradient(180deg, #ffffff 0%, #fff6f9 100%);
  border: 1px solid rgba(89, 52, 67, 0.12);
  box-shadow: 0 6px 18px rgba(100, 44, 65, 0.08);
  color: var(--text);
  font-weight: 700;
  appearance: none;
  -webkit-appearance: none;
}
#selectedDay::-webkit-date-and-time-value {
  text-align: left;
}
#selectedDay::-webkit-calendar-picker-indicator {
  opacity: 0.85;
  cursor: pointer;
}
.schedule-card { margin-bottom: 16px; }
.day-schedule-grid {
  overflow-x: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.schedule-hours {
  display: grid;
  grid-template-columns: 92px repeat(24, minmax(42px, 1fr));
  min-width: 1100px;
  gap: 0;
}
.schedule-hours .hour-label {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 6px 0 10px;
}
.schedule-hours .hour-label:first-child {
  text-align: left;
}
.schedule-row {
  display: grid;
  grid-template-columns: 92px repeat(24, minmax(42px, 1fr));
  min-width: 1100px;
  align-items: stretch;
  position: relative;
}
.schedule-row-label {
  padding: 12px 8px 12px 0;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--muted);
  display: flex;
  align-items: center;
}
.schedule-cells {
  grid-column: 2 / span 24;
  display: grid;
  grid-template-columns: repeat(24, minmax(42px, 1fr));
  position: relative;
  min-height: 64px;
}
.schedule-cell {
  border-left: 1px solid rgba(89, 52, 67, 0.08);
  border-bottom: 1px solid rgba(89, 52, 67, 0.08);
}
.schedule-cell:last-child {
  border-right: 1px solid rgba(89, 52, 67, 0.08);
}
.schedule-bar {
  position: absolute;
  top: 10px;
  height: 44px;
  border-radius: 14px;
  padding: 8px 10px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 0.9rem;
  font-weight: 700;
  border: 1px solid rgba(89, 52, 67, 0.08);
}
.schedule-bar.sleep { background: rgba(140, 158, 255, 0.35); }
.schedule-bar.feed { background: rgba(114, 221, 195, 0.36); }
.schedule-bar.diaper { background: rgba(183, 161, 255, 0.34); }
.schedule-bar.note { background: rgba(255, 169, 77, 0.34); }
.schedule-empty {
  color: var(--muted);
  text-align: center;
  padding: 18px 0;
}
.summary-grid {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.summary-box, .insight-box {
  border-radius: 18px;
  padding: 14px;
  background: white;
  border: 1px solid var(--border);
}
.summary-box span, .insight-box span {
  display: block;
  color: var(--muted);
  margin-bottom: 6px;
}
.summary-box strong {
  font-size: 1.5rem;
}
.recent-events {
  display: grid;
  gap: 8px;
}
.recent-events .mini-event {
  font-size: 0.95rem;
  color: var(--text);
}
.recent-events .mini-event small,
.rhythm-text {
  color: var(--muted);
}

.history-head { align-items: flex-start; }
.history-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.history-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.history-filters .filter-btn.active {
  background: rgba(255, 139, 167, 0.18);
  border: 1px solid rgba(238, 95, 134, 0.35);
  color: var(--primary-dark);
}
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-item {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.94);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}
.history-item > div:first-child {
  flex: 1;
  min-width: 0;
}
.history-item .history-type {
  font-size: 0.98rem;
}
.entry-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
  justify-content: center;
  padding-top: 0;
}
.entry-actions .ghost-button,
.entry-actions .danger-button {
  width: auto;
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.9rem;
}
.history-time, .history-details {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.3;
}
.history-details:empty { display: none; }
.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 20px;
}

.install-dialog {
  max-width: 360px;
  width: calc(100% - 32px);
  border: none;
  border-radius: 20px;
  padding: 0;
}
.install-dialog::backdrop { background: rgba(35, 22, 29, 0.35); }
.install-dialog > div { padding: 20px; }
.install-dialog ol { padding-left: 18px; color: var(--muted); }

@media (max-width: 900px) {
  .app-shell {
    padding-inline: 18px;
  }
  #activeSleepTimer {
    font-size: 3.3rem;
  }
  .action-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .hero, .section-title-row, .history-head {
    flex-direction: column;
    align-items: stretch;
  }
  .hero-actions { justify-content: stretch; }
  .stats-grid { grid-template-columns: 1fr; }
  .history-item {
    flex-direction: column;
    align-items: flex-start;
  }
  .entry-actions {
    flex-direction: row;
    align-items: center;
    gap: 14px;
  }
  .entry-actions .ghost-button,
  .entry-actions .danger-button {
    width: 100%;
  }
  .history-tools,
  .history-filters {
    width: 100%;
  }
  .action-grid {
    grid-template-columns: 1fr;
  }
  .action-button {
    min-height: 104px;
    font-size: 1.08rem;
  }
  .schedule-hours,
  .schedule-row {
    min-width: 820px;
  }
}
