:root {
  --bg: #f4f4f8;
  --card: #ffffff;
  --text: #1c1c28;
  --muted: #6b6b7b;
  --border: #e2e2ea;
  --primary: #4a6cf7;
  --danger: #e5484d;
  --accent: #4a6cf7;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14141f;
    --card: #1e1e2d;
    --text: #ececf1;
    --muted: #9a9aad;
    --border: #2e2e40;
  }
}

* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 40px;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }

/* ---------- login ---------- */
.login {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-box { text-align: center; padding: 24px; width: min(320px, 90vw); }
.login-emoji { font-size: 56px; }
.login-box h1 { margin: 8px 0 4px; font-size: 24px; }
.login-box p { color: var(--muted); margin-bottom: 16px; }
.login-box input {
  width: 100%; padding: 14px; font-size: 28px; text-align: center;
  letter-spacing: 8px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--card); color: var(--text); margin-bottom: 12px;
}
.login-box .primary { width: 100%; }
.error { color: var(--danger); min-height: 1.2em; margin-top: 10px; }

/* ---------- layout ---------- */
#app { max-width: 480px; margin: 0 auto; padding: 12px 12px 0; }

.baby-tabs { display: flex; gap: 8px; }
.baby-tab {
  flex: 1; padding: 12px 0; font-size: 18px; font-weight: 700;
  border: 2px solid var(--border); border-radius: 14px;
  background: var(--card); color: var(--muted);
}
.baby-tab.on { color: #fff; border-color: transparent; background: var(--accent); }

.status-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 14px; margin-top: 10px; position: relative;
}
.last-feed { font-size: 16px; font-weight: 600; padding-right: 86px; }
.counters { display: flex; gap: 16px; margin-top: 6px; color: var(--muted); font-size: 15px; }
.sync-status { position: absolute; top: 10px; right: 12px; font-size: 12px; color: var(--muted); }
.sync-status a { color: var(--muted); text-decoration: none; padding: 6px 0 6px 6px; }
.sync-status a:active { color: var(--accent); }

.active-feed {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--accent); color: #fff; border-radius: 14px;
  padding: 12px 16px; margin-top: 10px;
}
.active-feed .timer { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.active-feed .stop {
  background: rgba(255,255,255,.22); color: #fff; border: none;
  border-radius: 12px; padding: 12px 18px; font-size: 16px; font-weight: 700;
}

/* ---------- botonera ---------- */
.actions {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px;
}
.action {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 10px 2px 12px; font-size: 12.5px; line-height: 1.25; color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-height: 76px;
}
.action .icon { font-size: 26px; }
.action:active { transform: scale(.96); }
.action.busy { opacity: .45; pointer-events: none; }

/* ---------- log ---------- */
.log { margin-top: 18px; }
.log-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.log h2 { font-size: 15px; color: var(--muted); }
.sheet-btn {
  display: inline-block; text-decoration: none; font-size: 13px; font-weight: 600;
  color: var(--text); background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 7px 12px;
}
.sheet-btn:active { transform: scale(.96); }
#event-list { list-style: none; padding: 0; }
#event-list li {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 6px;
}
#event-list .ev-icon { font-size: 20px; }
#event-list .ev-main { flex: 1; min-width: 0; }
#event-list .ev-title { font-weight: 600; font-size: 15px; }
#event-list .ev-sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#event-list .ev-time { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
#event-list .ev-date { font-size: 12px; color: var(--muted); text-align: right; }
.day-sep { color: var(--muted); font-size: 13px; margin: 10px 2px 4px; font-weight: 600; }

/* ---------- diálogos ---------- */
dialog {
  border: none; border-radius: 16px; background: var(--card); color: var(--text);
  width: min(360px, calc(100vw - 32px)); padding: 18px;
  /* anclado arriba: así el teclado del celular no tapa los inputs */
  margin: min(8vh, 64px) auto auto;
  max-height: calc(100dvh - min(8vh, 64px) - 12px);
  overflow-y: auto;
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h3 { margin-bottom: 14px; }
dialog label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
dialog input, dialog select {
  width: 100%; padding: 10px; margin-top: 4px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); font-size: 16px;
}
.row2 { display: flex; gap: 10px; }
.row2 label { flex: 1; }
.dlg-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; align-items: center; }
.dlg-btns .spacer { flex: 1; }

.seg { display: flex; gap: 6px; margin-bottom: 14px; }
.seg button {
  flex: 1; padding: 10px 4px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--muted); font-size: 14px;
}
.seg button.on { background: var(--primary); border-color: transparent; color: #fff; font-weight: 600; }

.stepper { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.stepper button {
  width: 52px; height: 52px; font-size: 26px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.stepper input { flex: 1; text-align: center; font-size: 24px !important; padding: 10px 4px !important; }
.stepper .unit { color: var(--muted); }

.primary {
  background: var(--primary); color: #fff; border: none;
  border-radius: 12px; padding: 12px 20px; font-size: 16px; font-weight: 600;
}
.ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 16px; font-size: 15px;
}
.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); border-radius: 12px; padding: 12px 14px; }
#load-more { width: 100%; margin: 4px 0 16px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: #2c2c3a; color: #fff; border-radius: 12px; padding: 12px 16px;
  display: flex; gap: 16px; align-items: center; z-index: 60;
  box-shadow: 0 6px 24px rgba(0,0,0,.3); width: max-content; max-width: 92vw;
}
.toast button {
  background: none; border: none; color: #8ab4ff; font-weight: 700; font-size: 15px;
}
