:root {
  color-scheme: only light;
  --bg: #f8f8f3;
  --surface: #fff;
  --ink: #23332e;
  --muted: #5f6e65;
  --line: #dfe5dd;
  --primary: #355c48;
  --active: #547a68;
  --diaper-bg: #e5eee6;
  --diaper-ink: #355b48;
  --feeding-bg: #e6edf5;
  --feeding-ink: #3b5777;
  --medicine-bg: #f0e8f3;
  --medicine-ink: #6d537c;
  --radius: 14px;
  --large-radius: 18px;
  --gutter: clamp(16px, 5vw, 24px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html, body { color-scheme: only light; background-color: #f8f8f3; color: #23332e; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; }
.app { background-color: var(--bg); color: var(--ink); }
button, select, a { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: default; }
a { text-decoration: none; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible + span { outline: 3px solid #78a698; outline-offset: 3px; }
svg { width: 24px; height: 24px; flex: none; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(27px, 7vw, 34px); line-height: 1.12; letter-spacing: -1.15px; font-weight: 750; }
h2 { font-size: 22px; letter-spacing: -.6px; }
h3 { font-size: 16px; }
p { line-height: 1.5; }
.muted, .sub { color: var(--muted); }
.sub { font-size: 14px; margin-top: 7px; }

.app {
  height: 100vh;
  height: 100dvh;
  max-width: 540px;
  margin: auto;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  overflow: hidden;
}
.screen { overflow: hidden; }
.navbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 68px;
  padding: 10px var(--gutter);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.ip {
  font-size: 10px;
  line-height: 1.25;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.brand { font-family: "Cherry Bomb One", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 23px; font-weight: 400; letter-spacing: -1px; white-space: nowrap; }
.brand-dot { color: #72927b; }
.nav-button, .icon-button {
  width: 44px;
  height: 44px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: grid;
  place-items: center;
}
.nav-button { justify-self: end; }
.icon-button:disabled { opacity: .4; }

.main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: clamp(15px, 3vh, 28px) var(--gutter) 14px;
  gap: clamp(12px, 2.4vh, 22px);
}
.heading { flex: none; position: relative; }
.flash-toast {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: min(62%, 260px);
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--primary);
  color: white;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.25;
  box-shadow: 0 8px 24px #23332e26;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.flash-toast svg { width: 15px; height: 15px; }
.flash-toast.is-leaving { opacity: 0; transform: translateY(-4px); }
.flash-toast--diaper { background: var(--diaper-bg); color: var(--diaper-ink); }
.flash-toast--feeding { background: var(--feeding-bg); color: var(--feeding-ink); }
.flash-toast--medicine { background: var(--medicine-bg); color: var(--medicine-ink); }
.event-stack { display: flex; flex-direction: column; gap: 12px; flex: 1; min-height: 0; }
.event {
  width: 100%;
  display: flex;
  flex: 1;
  align-items: center;
  gap: 14px;
  border: 1px solid transparent;
  border-radius: var(--large-radius);
  padding: clamp(12px, 4vw, 20px);
  text-align: left;
  min-height: 64px;
}
.diaper { background: var(--diaper-bg); color: var(--diaper-ink); }
.feeding { background: var(--feeding-bg); color: var(--feeding-ink); }
.medicine { background: var(--medicine-bg); color: var(--medicine-ink); }
.event-icon {
  width: 58px;
  height: 58px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  background: #ffffffa8;
  flex: none;
}
.event-icon svg { width: 32px; height: 32px; }
.event-name { display: block; font-size: clamp(19px, 5.1vw, 24px); font-weight: 740; letter-spacing: -.5px; line-height: 1.15; }
.event-desc { display: block; font-size: 13px; margin-top: 5px; line-height: 1.3; }
.event .chevron { margin-left: auto; width: 20px; height: 20px; }

/* The medicine button is submitted through a form. */
.event-stack > form { display: flex; flex: 1; min-height: 0; }
.event-stack > form > .event { flex: 1; }

.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  min-height: 20px;
  flex: none;
}
.status svg { width: 16px; height: 16px; }
.status.success { color: var(--primary); font-weight: 650; }

.tag {
  display: flex;
  align-items: center;
  gap: 7px;
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 10px;
}
.tag svg { width: 17px; height: 17px; }

.event-form { display: flex; flex-direction: column; flex: 1; min-height: 0; gap: clamp(12px, 2.1vh, 18px); }
.form-fields { display: flex; flex-direction: column; gap: clamp(12px, 2vh, 18px); }
.field-label, legend { font-size: 14px; font-weight: 670; margin-bottom: 8px; display: block; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
select {
  width: 100%;
  min-height: 52px;
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--surface);
  border: 1px solid #ccd6cc;
  border-radius: 12px;
  padding: 10px 40px 10px 12px;
  font-size: 17px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235f6e65' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 18px 18px;
}
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.segments { display: flex; gap: 8px; }
.segment, .choice { position: relative; flex: 1; min-width: 0; cursor: pointer; display: block; }
.segment input, .choice input, .switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segment > span {
  display: grid;
  place-items: center;
  min-height: 50px;
  background: var(--surface);
  border: 1px solid #ccd6cc;
  border-radius: 12px;
  font-weight: 670;
  padding: 9px 5px;
  text-align: center;
}
.segment input:checked + span, .choice input:checked + span {
  background: var(--diaper-bg);
  border-color: var(--active);
  box-shadow: inset 0 0 0 1px var(--active);
  color: var(--diaper-ink);
}
.choice > span {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: clamp(105px, 20vh, 156px);
  background: var(--surface);
  border: 1px solid #ccd6cc;
  border-radius: 17px;
  font-weight: 730;
  font-size: 21px;
  position: relative;
}
.choice svg { width: 34px; height: 34px; }
.mark {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 20px;
  height: 20px;
  border: 1px solid #aab9ae;
  border-radius: 6px;
  display: grid;
  place-items: center;
}
.mark svg { width: 14px; height: 14px; visibility: hidden; }
.choice input:checked + span .mark { background: var(--primary); color: white; border-color: var(--primary); }
.choice input:checked + span .mark svg { visibility: visible; }
.hint { font-size: 13px; color: var(--muted); }

.form-errors {
  color: #8a3b3b;
  font-size: 13px;
  line-height: 1.4;
  border: 1px solid #e0c4c4;
  background: #fbf3f3;
  border-radius: 12px;
  padding: 10px 12px;
}
.form-errors p + p { margin-top: 4px; }

.actions { margin-top: auto; display: flex; flex-direction: column; gap: 6px; flex: none; }
.primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  border: 0;
  border-radius: 14px;
  background: var(--primary);
  color: white;
  font-size: 18px;
  font-weight: 690;
  width: 100%;
  padding: 10px 12px;
}
.primary:disabled { opacity: .48; }
.cancel { display: grid; place-items: center; min-height: 44px; color: var(--muted); font-size: 14px; }

.toggleline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  font-size: 14px;
  font-weight: 650;
}
.switch { position: relative; display: flex; align-items: center; min-height: 44px; cursor: pointer; }
.switch-track {
  width: 48px;
  height: 28px;
  border-radius: 20px;
  background: #a7b5aa;
  padding: 4px;
  display: flex;
  align-items: center;
  transition: background .15s;
}
.switch-track:before {
  content: "";
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px #0002;
}
.switch input:checked + .switch-track { background: var(--active); justify-content: flex-end; }

[hidden] { display: none !important; }

.history { display: flex; flex: 1; min-height: 0; flex-direction: column; overflow-y: auto; }
.history table { border-collapse: collapse; width: 100%; table-layout: fixed; text-align: left; font-size: 13px; }
.history thead th {
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: .7px;
  color: var(--muted);
  font-weight: 730;
  padding: 0 4px 10px;
  border-bottom: 1px solid #d6ded5;
}
.history thead { height: 30px; }
.history th:first-child { width: 23%; }
.history th:nth-child(2) { width: 37%; }
.history td {
  padding: 7px 4px;
  border-bottom: 1px solid var(--line);
  height: auto;
  vertical-align: middle;
  overflow-wrap: anywhere;
}
.time { display: block; font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; }
.date { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.log-name { display: flex; align-items: center; gap: 6px; font-weight: 650; line-height: 1.25; }
.log-name svg { width: 17px; height: 17px; }
.detail { color: var(--muted); line-height: 1.35; }
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: none;
  color: var(--muted);
  font-size: 13px;
}
.empty { padding: 28px 0; text-align: center; color: var(--muted); }

/* Feeding form panels are shown and hidden by the toggle controller. */
.breast-fields { display: flex; flex-direction: column; gap: clamp(12px, 2vh, 18px); }
#breast-bottle-field { display: flex; flex-direction: column; gap: clamp(12px, 2vh, 18px); }

@media (min-width: 541px) {
  .app { border-inline: 1px solid var(--line); }
}

@media (max-width: 365px) {
  .event { gap: 10px; }
  .event-icon { width: 46px; height: 46px; }
  .event-icon svg { width: 27px; height: 27px; }
  .event-desc { font-size: 12px; }
  .brand { font-size: 21px; }
  .flash-toast { max-width: 54%; padding: 6px 9px; font-size: 11px; }
  .history table { font-size: 12px; }
  .history td { padding-inline: 3px; }
  .log-name { gap: 4px; }
  .log-name svg { width: 15px; height: 15px; }
  .time { font-size: 12px; }
}

@media (max-height: 650px) {
  .navbar { min-height: 60px; padding-block: 7px; }
  .main { gap: 12px; padding-top: 13px; padding-bottom: 8px; }
  .event-stack { gap: 9px; }
  .event-form, .form-fields { gap: 10px; }
  .tag { margin-bottom: 6px; }
  .sub { margin-top: 4px; }
  .field-label, legend { margin-bottom: 5px; }
  .toggleline { min-height: 46px; padding-block: 0; }
  .actions { gap: 0; }
  .primary { min-height: 52px; }
  .cancel { min-height: 44px; }
}

@media (max-height: 515px) and (orientation: landscape) {
  .app { max-width: 850px; }
  .main { gap: 7px; padding-top: 7px; }
  .event-stack { flex-direction: row; }
  .event { flex-direction: column; justify-content: center; text-align: center; gap: 5px; }
  .event .chevron { display: none; }
  .event-stack > form > .event { flex-direction: column; }
  .event-form { flex-direction: row; align-items: stretch; }
  .form-fields { flex: 1; }
  .actions { width: 35%; align-self: flex-end; }
  .choice > span { min-height: 90px; }
  .tag { display: none; }
  .heading .sub { font-size: 12px; }
  .event-form select { min-height: 44px; }
  .segment > span { min-height: 44px; }
}

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