:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --text: #1f2333;
  --text-soft: #5b6478;
  --primary: #5b8def;
  --primary-dark: #3f6fd1;
  --accent: #ff9aa2;
  --success: #2faa6a;
  --warning: #e3a324;
  --danger: #d6473e;
  --border: #e3e6ef;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(20, 30, 60, 0.05);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--primary); text-decoration: none; }
button { font: inherit; }

/* ===== Topbar ===== */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  max-width: 720px;
  margin: 0 auto;
}
.brand {
  font-weight: 600;
  font-size: 17px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.brand:hover { color: var(--primary); }
.topbar-actions { display: flex; gap: 8px; }
.btn-link {
  background: none;
  border: 0;
  color: var(--primary);
  cursor: pointer;
  padding: 6px 8px;
  font-size: 14px;
}

/* ===== Layout ===== */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 96px;
}

h1 { font-size: 22px; margin: 8px 0 16px; }
h2 { font-size: 18px; margin: 16px 0 8px; }
p { margin: 0 0 12px; color: var(--text-soft); }

/* ===== Tab bar (bottom nav, mobile) ===== */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  z-index: 9;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 4px;
  color: var(--text-soft);
  font-size: 11px;
}
.tabbar a span { font-size: 22px; line-height: 1; }
.tabbar a label { margin-top: 2px; }
.tabbar a.active { color: var(--primary); }

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.summary-tile {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 12px;
}
.summary-tile .label {
  font-size: 12px;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.summary-tile .value {
  font-size: 22px;
  font-weight: 600;
  margin-top: 4px;
}
.summary-tile .sub { font-size: 12px; color: var(--text-soft); margin-top: 2px; }

/* ===== Forms ===== */
.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form-row label { font-size: 13px; color: var(--text-soft); font-weight: 500; }
.form-row input,
.form-row select,
.form-row textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  font: inherit;
  color: var(--text);
  width: 100%;
}
.form-row textarea { min-height: 80px; resize: vertical; }
.form-row.inline { flex-direction: row; align-items: center; gap: 8px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--primary);
  background: var(--primary);
  color: white;
  font-weight: 500;
  cursor: pointer;
  min-height: 40px;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
}
.btn-block { width: 100%; }
.btn-fab {
  position: fixed;
  right: 16px;
  bottom: 80px;
  width: 56px; height: 56px;
  border-radius: 28px;
  font-size: 26px;
  padding: 0;
  box-shadow: 0 6px 20px rgba(91, 141, 239, 0.4);
  z-index: 8;
}

.field-error { color: var(--danger); font-size: 12px; margin-top: 2px; }

/* ===== Lists ===== */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 500; }
.list-item .li-sub { font-size: 13px; color: var(--text-soft); margin-top: 2px; }
.list-item .li-actions { display: flex; gap: 4px; }

.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--surface-2);
  color: var(--text-soft);
  margin-right: 4px;
}
.chip.left { background: #ffe9ec; color: #b53645; }
.chip.right { background: #e6f0ff; color: #2f5fbf; }
.chip.both { background: #efe6ff; color: #5a37b8; }
.chip.breast_milk { background: #fff3e0; color: #b56b00; }
.chip.formula { background: #e6f5ec; color: #1f7a45; }
.chip.nap { background: #e9f4ff; color: #2f5fbf; }
.chip.night { background: #2c2f54; color: #fff; }
.chip.in-progress { background: #fff3d6; color: #a37500; }

.list-item.in-progress {
  border-color: #f0c674;
  background: #fffaf0;
}

/* ===== Emoji rating ===== */
.emoji-rating {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.emoji-rating-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1 1 0;
  min-width: 52px;
  padding: 8px 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.1s, background 0.1s, transform 0.05s;
}
.emoji-rating-btn:hover { border-color: var(--primary); }
.emoji-rating-btn:active { transform: scale(0.97); }
.emoji-rating-btn.active {
  border-color: var(--primary);
  background: #eaf1ff;
}
.emoji-rating-emoji { font-size: 22px; line-height: 1; }
.emoji-rating-label {
  font-size: 10px;
  color: var(--text-soft);
  text-align: center;
  line-height: 1.1;
}

/* ===== Spacings ===== */
.spacer { height: 12px; }

.empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-soft);
}

/* ===== Tabs / segmented ===== */
.segmented {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 12px;
}
.segmented button {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 8px;
  border-radius: 6px;
  color: var(--text-soft);
  cursor: pointer;
  font-weight: 500;
}
.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* ===== Login ===== */
.login-card {
  max-width: 360px;
  margin: 40px auto;
  text-align: center;
}
.login-card .emoji { font-size: 48px; margin-bottom: 12px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2333;
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  z-index: 100;
  max-width: 90vw;
}
.toast.error { background: var(--danger); }

/* ===== Chart ===== */
.chart-wrap {
  width: 100%;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 12px;
}
.chart-title { font-size: 14px; color: var(--text-soft); margin-bottom: 6px; }
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 0 8px 4px;
  font-size: 11px;
  color: var(--text-soft);
}
.chart-legend-item { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
}
.chart-empty {
  text-align: center;
  padding: 24px;
  color: var(--text-soft);
  font-size: 13px;
}

/* ===== Loading ===== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
  color: var(--text-soft);
}

/* ===== Filter bar ===== */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.filter-bar button {
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-soft);
}
.filter-bar button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ===== Responsive ===== */
@media (min-width: 600px) {
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
}
