:root {
  color-scheme: light;
  --bg: #f6f1ea;
  --surface: #fff8ed;
  --surface-strong: #ffffff;
  --text: #27231d;
  --muted: #756d61;
  --line: #e5d9c8;
  --accent: #1d7a6f;
  --accent-dark: #115b53;
  --coral: #d96d57;
  --rose: #c7668b;
  --gold: #d59b32;
  --blue: #3b6f9f;
  --violet: #8c5fbf;
  --mint: #4fa986;
  --shadow: 0 14px 34px rgba(69, 52, 28, 0.14);
  --soft-shadow: 0 8px 22px rgba(69, 52, 28, 0.09);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(29, 122, 111, 0.18) 0, rgba(29, 122, 111, 0) 210px),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(150px + env(safe-area-inset-bottom));
}

.topbar,
.section-heading,
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: calc(-1 * max(18px, env(safe-area-inset-top))) -16px 14px;
  padding: max(16px, env(safe-area-inset-top)) 16px 12px;
  background: rgba(246, 241, 234, 0.9);
  backdrop-filter: blur(18px);
}

.runtime-warning {
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid #e8c06f;
  border-radius: 8px;
  background: #fff2ca;
  color: #6d4b05;
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.35;
}

.brand-header {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 10px;
  box-shadow: var(--soft-shadow);
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.6rem;
  line-height: 1.08;
  white-space: nowrap;
}

h2 {
  margin-bottom: 0;
  font-size: 1.02rem;
  letter-spacing: 0;
}

.icon-button,
.text-button,
.primary-button,
.quick-card {
  border: 0;
  border-radius: 8px;
}

.icon-button {
  display: grid;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  place-items: center;
  background: var(--accent);
  color: #fff;
  box-shadow: var(--soft-shadow);
  font-size: 1.55rem;
  font-weight: 900;
  line-height: 1;
}

.text-button {
  min-height: 38px;
  border: 1px solid rgba(17, 91, 83, 0.16);
  padding: 0 13px;
  background: rgba(255, 253, 248, 0.92);
  color: var(--accent-dark);
  box-shadow: var(--soft-shadow);
  font-weight: 900;
}

.text-button.danger {
  border-color: rgba(199, 102, 139, 0.2);
  background: #fff2f5;
  color: var(--rose);
}

.avatar {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border-radius: 50%;
  background: var(--child-color, var(--accent));
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 -7px 12px rgba(0, 0, 0, 0.08);
  font-size: 1.12rem;
  font-weight: 950;
  line-height: 1;
}

.avatar[data-sex="female"],
.avatar[data-sex="male"] {
  font-size: 1.35rem;
}

.avatar-large {
  width: 58px;
  height: 58px;
  flex-basis: 58px;
  font-size: 1.65rem;
}

.avatar img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
}

.child-name {
  display: block;
  font-weight: 900;
}

.child-age {
  display: block;
  margin-top: 2px;
  color: inherit;
  font-size: 0.78rem;
  opacity: 0.82;
}

.selected-child,
.quick-log,
.summary,
.health,
.timeline {
  margin-bottom: 18px;
}

.selected-child {
  position: relative;
  overflow: hidden;
  padding: 16px;
  border: 0;
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.selected-child::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 8px;
  background: var(--child-color, var(--accent));
}

.selected-child h2 {
  margin-bottom: 6px;
  font-size: 1.28rem;
}

.selected-child p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.35;
}

.selected-child-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-left: 8px;
}

.child-switcher {
  display: grid;
  gap: 7px;
  margin: 14px 0 0 8px;
}

.child-switcher label {
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 950;
}

.child-switcher select {
  min-height: 42px;
  border-color: var(--line);
  background: #fffdf8;
  font-weight: 850;
}

.avatar-picker {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 12px;
  align-items: center;
  padding: 12px;
  border-radius: 8px;
  background: #f7f3ea;
}

.avatar-picker .avatar {
  grid-row: span 2;
}

.photo-input {
  min-width: 0;
}

.photo-input input {
  margin-top: 7px;
  padding: 10px;
  background: #fffdf8;
}

.avatar-picker .small-button {
  justify-self: start;
}

.growth-snapshot {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
  padding-left: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.25;
}

.growth-snapshot span {
  padding: 9px;
  border-radius: 8px;
  background: #f7f3ea;
}

.day-picker {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  margin-bottom: 16px;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.quick-card {
  --tile: var(--accent);
  --tile-bg: #edf7f4;
  display: grid;
  min-height: 104px;
  grid-template-rows: auto 1fr;
  gap: 10px;
  align-items: start;
  padding: 13px;
  background: var(--tile-bg);
  border: 1px solid rgba(255, 255, 255, 0.72);
  color: var(--text);
  text-align: left;
  box-shadow: var(--soft-shadow);
}

.quick-card:active {
  transform: translateY(1px);
}

.quick-card[data-type="feeding"] { --tile: #d96d57; --tile-bg: #fff0eb; }
.quick-card[data-type="nursing"] { --tile: #c7668b; --tile-bg: #fff0f5; }
.quick-card[data-type="sleep"] { --tile: #3b6f9f; --tile-bg: #edf4ff; }
.quick-card[data-type="poop"] { --tile: #b07732; --tile-bg: #fff3df; }
.quick-card[data-type="temperature"] { --tile: #d94f45; --tile-bg: #ffefed; }
.quick-card[data-type="medicine"] { --tile: #4f76c7; --tile-bg: #eef3ff; }
.quick-card[data-type="activity"] { --tile: #4fa986; --tile-bg: #eefaf4; }
.quick-card[data-type="growth"] { --tile: #8c5fbf; --tile-bg: #f5efff; }
.quick-card[data-type="note"] { --tile: #d59b32; --tile-bg: #fff6df; }

.quick-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  background: var(--tile);
  color: #fff;
  font-size: 1.28rem;
  box-shadow: 0 8px 18px rgba(70, 51, 31, 0.12);
}

.quick-title {
  display: block;
  font-weight: 950;
  line-height: 1.15;
}

.quick-hint {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.22;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.summary-item {
  min-height: 78px;
  padding: 11px;
  border: 0;
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: var(--soft-shadow);
}

.summary-item[data-summary="pasti"] { border-top: 4px solid var(--coral); }
.summary-item[data-summary="poppate"] { border-top: 4px solid var(--rose); }
.summary-item[data-summary="sonno"] { border-top: 4px solid var(--blue); }
.summary-item[data-summary="cacca"] { border-top: 4px solid #b07732; }
.summary-item[data-summary="febbre"] { border-top: 4px solid #d94f45; }
.summary-item[data-summary="crescita"] { border-top: 4px solid var(--violet); }

.summary-value {
  display: block;
  color: var(--text);
  font-size: 1.35rem;
  font-weight: 950;
}

.summary-label {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  line-height: 1.15;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.bottom-tabs {
  position: fixed;
  right: max(10px, calc((100vw - 560px) / 2 + 10px));
  bottom: max(10px, env(safe-area-inset-bottom));
  left: max(10px, calc((100vw - 560px) / 2 + 10px));
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  padding: 7px;
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 8px;
  background: rgba(255, 252, 246, 0.94);
  box-shadow: 0 18px 40px rgba(55, 42, 24, 0.2);
  backdrop-filter: blur(18px);
}

.ad-banner {
  grid-column: 1 / -1;
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fff1c9;
  color: #6d4b05;
  font-size: 0.82rem;
  font-weight: 900;
}

.ad-banner button {
  min-height: 30px;
  border: 0;
  border-radius: 8px;
  background: #ffffff;
  color: var(--accent-dark);
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 950;
}

.ad-banner[hidden] {
  display: none;
}

.tab-button {
  display: grid;
  min-height: 52px;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
}

.tab-button::before {
  display: block;
  margin-bottom: 2px;
  font-size: 1.05rem;
  line-height: 1;
}

.tab-button[data-tab="today"]::before { content: "●"; color: var(--coral); }
.tab-button[data-tab="health"]::before { content: "+"; color: var(--blue); }
.tab-button[data-tab="family"]::before { content: "◆"; color: var(--mint); }
.tab-button[data-tab="settings"]::before { content: "⋯"; color: var(--violet); }

.tab-button.active {
  background: var(--accent);
  color: #fff;
}

.tab-button.active::before {
  color: #fff;
}

.health-panel {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.growth-chart-section {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding: 14px;
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: var(--soft-shadow);
}

#growth-chart {
  width: 100%;
  min-height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.family-panel,
.settings-panel {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.family-card,
.settings-card {
  padding: 14px;
  border: 0;
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: var(--soft-shadow);
}

.family-card {
  border-left: 8px solid var(--child-color, var(--accent));
}

.settings-card.install-card {
  background: #edf8f5;
  border: 1px solid #cde7de;
}

.settings-card.primary-flow {
  border: 1px solid #cde7de;
  background: #fffdf8;
}

.settings-card.muted-card {
  background: #f8f1e7;
  box-shadow: none;
}

.family-title,
.settings-title {
  display: block;
  font-weight: 950;
}

.settings-kicker {
  display: block;
  margin-bottom: 5px;
  color: var(--accent-dark);
  font-size: 0.72rem;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

.family-meta,
.settings-meta {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.event-extra-grid {
  display: grid;
  gap: 14px;
}

.event-extra-grid[hidden] {
  display: none;
}

.sync-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 12px;
}

.small-button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: #f1eadf;
  color: var(--accent-dark);
  padding: 0 12px;
  font-weight: 900;
}

.small-link-button {
  display: inline-grid;
  min-height: 40px;
  place-items: center;
  border-radius: 8px;
  background: #f1eadf;
  color: var(--accent-dark);
  padding: 0 12px;
  font-weight: 900;
  text-decoration: none;
}

.small-button.danger-inline {
  background: #f7e1df;
  color: var(--rose);
}

.small-button.primary-inline {
  background: var(--accent);
  color: #fff;
}

.settings-details {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.settings-details summary {
  color: var(--accent-dark);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 950;
}

.settings-details p {
  margin: 8px 0 10px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.reminder-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.reminder-row {
  padding: 10px;
  border-radius: 8px;
  background: #f7f3ea;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.3;
}

.reminder-row strong {
  display: block;
  color: var(--text);
  margin-bottom: 2px;
}

.danger-button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: #f7e1df;
  color: var(--rose);
  padding: 0 12px;
  font-weight: 950;
}

.danger-button[hidden] {
  display: none;
}

.color-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--child-color, var(--accent));
  vertical-align: -1px;
}

.health-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.health-card,
.health-list {
  border: 0;
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: var(--soft-shadow);
}

.health-card {
  min-height: 96px;
  padding: 12px;
}

.health-card:nth-child(1) { border-top: 4px solid #d94f45; }
.health-card:nth-child(2) { border-top: 4px solid #4f76c7; }

.health-label {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  line-height: 1.2;
}

.health-value {
  display: block;
  margin-top: 8px;
  color: var(--text);
  font-size: 1.18rem;
  font-weight: 950;
}

.health-subtext {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
}

.health-list {
  overflow: hidden;
}

.health-row {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 10px;
  padding: 11px 12px;
  border-top: 1px solid var(--line);
}

.health-row:first-child {
  border-top: 0;
}

.health-row-time {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.health-row-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 900;
}

.health-row-meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.25;
}

.event-dot {
  display: inline-grid;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  place-items: center;
  border-radius: 8px;
  background: #edf4f2;
  font-size: 1rem;
}

#timeline-list {
  margin-top: 10px;
}

.calendar-agenda {
  display: grid;
  max-height: 360px;
  gap: 12px;
  overflow-y: auto;
  padding: 4px 2px 8px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.calendar-day {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.48);
  border: 1px solid rgba(229, 217, 200, 0.8);
}

.calendar-day.selected {
  background: #eef8f5;
  border-color: #c9e6dc;
}

.calendar-day-header {
  position: sticky;
  top: -4px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 9px;
  border-radius: 8px;
  background: rgba(255, 252, 246, 0.94);
  color: var(--accent-dark);
  font-size: 0.84rem;
  font-weight: 950;
  backdrop-filter: blur(12px);
}

.calendar-day-header strong {
  display: grid;
  min-width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.78rem;
}

.timeline-list-empty {
  margin: 12px 0 0;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.45);
  color: var(--muted);
  text-align: center;
}

.timeline-item {
  --event-color: var(--accent);
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 10px;
  align-items: start;
  margin-top: 0;
  padding: 12px;
  border: 0;
  border-left: 6px solid var(--event-color);
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: var(--soft-shadow);
}

.timeline-item[data-type="feeding"] { --event-color: #d96d57; }
.timeline-item[data-type="nursing"] { --event-color: #c7668b; }
.timeline-item[data-type="sleep"] { --event-color: #3b6f9f; }
.timeline-item[data-type="poop"] { --event-color: #b07732; }
.timeline-item[data-type="temperature"] { --event-color: #d94f45; }
.timeline-item[data-type="medicine"] { --event-color: #4f76c7; }
.timeline-item[data-type="activity"] { --event-color: #4fa986; }
.timeline-item[data-type="growth"] { --event-color: #8c5fbf; }
.timeline-item[data-type="note"] { --event-color: #d59b32; }

.timeline-time {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 900;
}

.timeline-title {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 4px;
  font-weight: 950;
}

.timeline-meta,
.timeline-notes {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.3;
}

.timeline-notes {
  margin-top: 4px;
}

.delete-event {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: #f7e1df;
  color: var(--rose);
  font-weight: 950;
}

dialog {
  width: min(calc(100% - 28px), 520px);
  border: 0;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(39, 35, 29, 0.38);
}

form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 900;
}

.field-hint {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  line-height: 1.3;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--text);
  padding: 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 122, 111, 0.12);
}

textarea {
  resize: vertical;
}

.primary-button {
  min-height: 48px;
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 950;
}

@media (min-width: 460px) {
  .quick-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 360px) {
  .quick-grid,
  .summary-grid,
  .health-cards,
  .growth-snapshot {
    grid-template-columns: 1fr;
  }

  .timeline-item {
    grid-template-columns: 1fr auto;
  }

  .timeline-time {
    grid-column: 1 / -1;
  }
}
