:root {
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-input: #f1f5f9;
  --text: #0f172a;
  --text-secondary: #64748b;
  --accent: #6366f1;
  --accent-light: #e0e7ff;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --session: #0ea5e9;
  --session-light: #e0f2fe;
  --border: #e2e8f0;
  --summary-green: #15803d;
  --summary-green-bg: rgba(34, 197, 94, 0.14);
  --summary-green-border: rgba(34, 197, 94, 0.32);
  --summary-amber: #b45309;
  --summary-amber-bg: rgba(245, 158, 11, 0.16);
  --summary-amber-border: rgba(245, 158, 11, 0.32);
  --summary-red: #b91c1c;
  --summary-red-bg: rgba(239, 68, 68, 0.14);
  --summary-red-border: rgba(239, 68, 68, 0.32);
  --summary-pill-bg: rgba(255,255,255,0.62);
  --summary-pill-border: rgba(255,255,255,0.4);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --accent: #818cf8;
    --accent-light: #1e1b4b;
    --border: #334155;
    --danger-light: #450a0a;
    --session-light: #0c4a6e;
    --summary-green: #4ade80;
    --summary-green-bg: rgba(22, 163, 74, 0.24);
    --summary-green-border: rgba(74, 222, 128, 0.34);
    --summary-amber: #fbbf24;
    --summary-amber-bg: rgba(217, 119, 6, 0.24);
    --summary-amber-border: rgba(251, 191, 36, 0.34);
    --summary-red: #f87171;
    --summary-red-bg: rgba(185, 28, 28, 0.24);
    --summary-red-border: rgba(248, 113, 113, 0.34);
    --summary-pill-bg: rgba(15, 23, 42, 0.42);
    --summary-pill-border: rgba(148, 163, 184, 0.18);
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
}

/* --- Gate screen --- */
#gate-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
  background: linear-gradient(145deg, var(--bg) 0%, var(--accent-light) 100%);
}

.gate-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-card);
  border-radius: 20px;
  padding: 40px 32px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
}

.gate-icon {
  font-size: 48px;
  margin-bottom: 8px;
  animation: gentle-bounce 2s ease-in-out infinite;
}

@keyframes gentle-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.gate-title {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.gate-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 18px;
  text-align: center;
}

.child-chooser {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.child-chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  text-align: left;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--bg-input);
  color: var(--text);
  cursor: pointer;
}

.child-chip.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.14);
}

.child-chip-name {
  font-size: 15px;
  font-weight: 800;
}

.child-chip-state {
  font-size: 12px;
  color: var(--text-secondary);
}

.gate-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#gate-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  text-align: left;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--bg-input);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

#gate-input.password-mode {
  text-align: center;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

#gate-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

#gate-submit {
  width: 100%;
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.1s, opacity 0.15s;
}

#gate-submit:active {
  transform: scale(0.97);
  opacity: 0.9;
}

#gate-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  opacity: 0;
  transition: opacity 0.2s;
}

#gate-error.show {
  opacity: 1;
}

.gate-help {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 12px;
}

.gate-back {
  margin-top: 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
}

/* --- Main app --- */

header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  font-size: 20px;
  font-weight: 700;
}

.header-title {
  min-width: 0;
}

.header-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

header nav {
  display: flex;
  justify-content: center;
  gap: 8px;
  min-width: 0;
}

header nav button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 500;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-width: 0;
}

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

.nav-icon {
  display: none;
  line-height: 1;
}

/* --- Identity button --- */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-btn,
.identity-btn {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.settings-btn {
  font-size: 14px;
  padding: 4px 8px;
}

/* --- Identity modal --- */
.identity-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 4px;
}

.identity-opt {
  padding: 11px 8px;
  font-size: 14px;
  font-weight: 700;
  background: var(--bg-input);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.identity-opt:active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

@media (max-width: 420px) {
  .identity-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* --- Notes button & badge --- */
.nav-notes-btn {
  position: relative;
}

.unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 8px;
  padding: 0 4px;
}

@media (max-width: 420px) {
  header {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 12px 16px;
  }

  header nav {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
  }

  header nav button {
    padding: 9px 6px;
    font-size: 13px;
  }

  .nav-icon {
    display: inline-block;
    font-size: 15px;
  }

  .nav-label {
    display: none;
  }

  .identity-btn {
    padding: 6px 9px;
    font-size: 11px;
  }

  .settings-btn {
    padding: 4px 6px;
    font-size: 13px;
  }

  .nav-notes-btn .unread-badge {
    top: 2px;
    right: 2px;
  }
}

/* --- Settings modal --- */
.settings-modal {
  max-width: 420px;
}

.settings-section {
  margin-bottom: 20px;
}

.settings-section:last-child {
  margin-bottom: 0;
}

.settings-section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.settings-section-help {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0 0 10px;
}

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

.settings-child-chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  text-align: left;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--bg-input);
  color: var(--text);
  cursor: pointer;
}

.settings-child-chip.active {
  border-color: var(--accent);
  cursor: default;
}

.settings-child-name {
  font-size: 15px;
  font-weight: 800;
}

.settings-child-state {
  font-size: 12px;
  color: var(--text-secondary);
}

.settings-type-toggles {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-type-row {
  background: var(--bg-input);
  border-radius: 10px;
  overflow: hidden;
}

.settings-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  cursor: pointer;
}

.settings-toggle-label {
  font-size: 14px;
  font-weight: 600;
}

/* iOS-style toggle switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 12px;
  transition: background 0.2s;
  cursor: pointer;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-input:checked + .toggle-track {
  background: var(--accent);
}

.toggle-input:checked + .toggle-track::after {
  transform: translateX(20px);
}

/* Interval config row */
.settings-interval-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px 10px;
  border-top: 1px solid var(--border);
}

.settings-interval-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.settings-interval-input {
  display: flex;
  align-items: center;
  gap: 4px;
}

.interval-digit {
  width: 40px;
  padding: 4px 6px;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  -moz-appearance: textfield;
}

.interval-digit::-webkit-inner-spin-button,
.interval-digit::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.interval-unit {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
}

/* --- Notes modal --- */
.notes-modal {
  max-height: 85dvh;
}

.chat-overlay {
  align-items: stretch;
}

.chat-modal {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 600px;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  padding: 0;
  border-radius: 0;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.chat-header h2 {
  font-size: 17px;
}

.chat-close-btn {
  padding: 7px 14px;
  font-size: 13px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background:
    radial-gradient(circle at top, rgba(99, 102, 241, 0.06), transparent 32%),
    var(--bg);
}

.chat-thread {
  min-height: 100%;
  padding: 18px 14px 14px;
}

.chat-empty {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  color: var(--text-secondary);
  font-size: 15px;
}

.chat-date-divider {
  display: flex;
  justify-content: center;
  margin: 8px 0 14px;
}

.chat-date-divider span {
  display: inline-block;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  background: rgba(148, 163, 184, 0.16);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.chat-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.chat-group.mine {
  align-items: flex-end;
}

.chat-group.theirs {
  align-items: flex-start;
}

.chat-author {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 0 4px;
}

.chat-bubble-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.chat-group.mine .chat-bubble-stack {
  align-items: flex-end;
}

.chat-group.theirs .chat-bubble-stack {
  align-items: flex-start;
}

.chat-bubble {
  width: fit-content;
  max-width: 80%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  word-break: break-word;
}

.chat-bubble.mine {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  border-radius: 16px 16px 6px 16px;
}

.chat-bubble.theirs {
  background: var(--bg-card);
  color: var(--text);
  border-radius: 16px 16px 16px 6px;
  box-shadow: var(--shadow);
}

.chat-bubble-text {
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.chat-bubble.with-photo .chat-bubble-text {
  margin-top: 8px;
}

.chat-time {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  text-align: right;
  opacity: 0.85;
}

.chat-photo {
  display: block;
  width: 100%;
  max-height: 300px;
  object-fit: cover;
  border-radius: 12px;
  background: var(--bg-input);
  cursor: pointer;
}

.chat-compose-shell {
  flex-shrink: 0;
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}

.chat-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 0 10px;
}

.chat-preview img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.chat-preview-remove {
  padding: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--danger);
  background: none;
  border: none;
  cursor: pointer;
}

.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.chat-camera-btn {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  cursor: pointer;
  flex-shrink: 0;
}

.chat-camera-btn input {
  display: none;
}

.chat-input {
  flex: 1;
  min-height: 42px;
  max-height: 96px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: var(--font);
  line-height: 1.4;
  border: 2px solid var(--border);
  border-radius: 16px;
  background: var(--bg-input);
  color: var(--text);
  resize: none;
  outline: none;
  overflow-y: hidden;
}

.chat-input:focus {
  border-color: var(--accent);
}

.chat-send-btn {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.1s, opacity 0.15s;
}

.chat-send-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.chat-send-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.photo-overlay {
  background: rgba(15, 23, 42, 0.92);
  align-items: center;
  justify-content: center;
  z-index: 60;
}

.chat-photo-viewer {
  width: min(92vw, 680px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.chat-photo-viewer img {
  display: block;
  width: 100%;
  max-height: 78vh;
  object-fit: contain;
  border-radius: 16px;
}

.chat-photo-close {
  align-self: flex-end;
}

.note-compose {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.note-compose textarea {
  width: 100%;
  padding: 10px;
  font-size: 14px;
  font-family: var(--font);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  resize: none;
  outline: none;
  margin-bottom: 8px;
}

.note-compose textarea:focus { border-color: var(--accent); }

.note-compose-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.photo-upload-btn {
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* --- Note items --- */
.note-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.note-item:last-child { border-bottom: none; }

.note-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.note-author {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}

.note-time {
  font-size: 11px;
  color: var(--text-secondary);
}

.note-unread {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.note-body {
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.note-photo {
  margin-top: 8px;
  max-width: 100%;
  border-radius: var(--radius-sm);
}

/* --- Request items --- */
.request-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.request-item:last-child { border-bottom: none; }

.request-item.done {
  opacity: 0.5;
}

.request-status {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
}

.request-status.open {
  background: var(--accent-light);
  color: var(--accent);
}

.request-status.done {
  background: #d1fae5;
  color: #059669;
}

main { padding: 16px 20px 140px; max-width: 600px; margin: 0 auto; }

/* --- Section headings --- */
.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin: 20px 0 10px;
}

.section-title:first-child { margin-top: 0; }

/* --- Next Up cards --- */
.status-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-card .icon { font-size: 28px; flex-shrink: 0; }

.status-card .info { flex: 1; min-width: 0; }

.status-card .info .label {
  font-weight: 600;
  font-size: 16px;
}

.status-card .info .detail {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.status-card.overdue {
  border-color: var(--danger);
  background: var(--danger-light);
}

.status-card.overdue .info .label { color: var(--danger); }

.status-card.in-progress {
  border-color: var(--session);
  background: var(--session-light);
}

.status-card.in-progress .info .label { color: var(--session); }

.status-card .end-btn {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  background: var(--session);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
}

/* --- Recent list --- */
.recent-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.recent-item:last-child { border-bottom: none; }

.recent-item .time {
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 60px;
  flex-shrink: 0;
}

.recent-item .icon { font-size: 18px; }

.recent-item .desc {
  font-size: 14px;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-item .who {
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

/* --- Quick-log bar --- */
.quick-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  z-index: 10;
}

.quick-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 14px;
  min-width: 68px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: transform 0.1s;
}

.quick-btn:active { transform: scale(0.95); }

.quick-btn .btn-icon { font-size: 22px; }

.quick-btn.session-active {
  background: var(--session);
  color: #fff;
  border-color: var(--session);
}

/* --- Compact time rows --- */
.compact-time-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
}

.compact-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  width: 36px;
  flex-shrink: 0;
  text-align: right;
  margin-right: 2px;
}

.compact-end-inner {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.time-digit {
  width: 46px;
  padding: 8px 4px;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  outline: none;
  -moz-appearance: textfield;
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.time-digit::-webkit-inner-spin-button,
.time-digit::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.time-digit:focus {
  border-color: var(--accent);
}

.time-colon {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-secondary);
  margin: 0 -1px;
}

.ampm-toggle {
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  margin-left: 4px;
  min-width: 40px;
  text-align: center;
}

.date-trigger-wrap {
  position: relative;
  display: inline-block;
  margin-left: auto;
  flex-shrink: 0;
}

.date-toggle {
  display: inline-block;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
}

.date-hidden-input {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  -webkit-appearance: none;
}

/* --- End mode tabs --- */
.end-mode-tabs {
  display: flex;
  gap: 0;
  margin-left: auto;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
}

.end-tab {
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 700;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  min-width: 38px;
  text-align: center;
}

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

/* --- Inline fields row --- */
.inline-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.inline-field {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* Push side picker to the right when it's the first visible child */
.inline-field#modal-side-field {
  margin-left: auto;
}

.modal .inline-field input[type="number"] {
  width: 56px;
  padding: 8px 6px;
  text-align: center;
  border: 1px dashed var(--border);
}

.modal .inline-field input[type="text"] {
  width: 100%;
  min-width: 60px;
  padding: 8px 10px;
  font-size: 14px;
  border: 1px dashed var(--border);
}

.inline-unit {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* --- Who picker --- */
.who-picker {
  display: flex;
  gap: 4px;
}

.who-btn {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 700;
  background: var(--bg-input);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.who-btn.selected {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* --- Sub-type picker (B-Milk / Formula) --- */
#modal-subtype-field {
  margin-bottom: 14px;
}

.subtype-picker {
  display: flex;
  gap: 0;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  width: 100%;
}

.subtype-btn {
  flex: 1;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 700;
  background: var(--bg-input);
  color: var(--text);
  border: none;
  border-right: 1px solid var(--border);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.subtype-btn:last-child {
  border-right: none;
}

.subtype-btn.selected {
  background: var(--accent);
  color: #fff;
}

/* --- Nappy type checks --- */
#modal-nappy-field {
  margin-bottom: 14px;
}

.nappy-checks {
  display: flex;
  gap: 10px;
}

.nappy-check {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.nappy-check input {
  display: none;
}

.nappy-tag {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  background: var(--bg-input);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}

.nappy-check input:checked + .nappy-tag {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* --- Side picker --- */
.side-picker {
  display: flex;
  gap: 0;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.side-btn {
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 700;
  background: var(--bg-input);
  color: var(--text);
  border: none;
  border-right: 1px solid var(--border);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.side-btn:last-child {
  border-right: none;
}

.side-btn.selected {
  background: var(--accent);
  color: #fff;
}

/* --- Toast --- */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  text-align: center;
  max-width: 90%;
}

.toast.show { opacity: 1; }

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 50;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.show { display: flex; }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  width: 100%;
  max-width: 600px;
  max-height: 80dvh;
  overflow-y: auto;
}

.modal-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
}

.modal-top-row h2 {
  font-size: 17px;
  margin: 0;
  white-space: nowrap;
}

.modal-top-row .who-picker {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.modal .field { margin-bottom: 10px; }

.modal label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 3px;
}

.modal input, .modal textarea {
  width: 100%;
  padding: 8px 10px;
  font-size: 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  outline: none;
}

.modal input.time-digit {
  width: 46px;
  padding: 8px 4px;
  font-size: 22px;
  flex-shrink: 0;
}

.modal #modal-duration.time-digit {
  width: 52px;
}

.dur-unit {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.modal input:focus, .modal textarea:focus { border-color: var(--accent); }

.modal .actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.modal .actions button {
  flex: 1;
  padding: 13px 8px;
  font-size: 15px;
  font-weight: 700;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.modal .btn-primary { background: var(--accent); color: #fff; }
.modal .btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.modal .btn-danger { background: var(--danger); color: #fff; }

/* --- Summary view --- */
#history-view { display: none; }

.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.summary-eyebrow {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.summary-title {
  font-size: 14px;
  color: var(--text-secondary);
}

.summary-rolling {
  position: relative;
  overflow: hidden;
}

.summary-rolling::after {
  content: '';
  position: absolute;
  top: -50px;
  right: -50px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  opacity: 0.08;
  background: currentColor;
  pointer-events: none;
}

.summary-rolling.green {
  color: var(--summary-green);
  background: linear-gradient(145deg, var(--summary-green-bg), var(--bg-card));
  border-color: var(--summary-green-border);
}

.summary-rolling.amber {
  color: var(--summary-amber);
  background: linear-gradient(145deg, var(--summary-amber-bg), var(--bg-card));
  border-color: var(--summary-amber-border);
}

.summary-rolling.red {
  color: var(--summary-red);
  background: linear-gradient(145deg, var(--summary-red-bg), var(--bg-card));
  border-color: var(--summary-red-border);
}

.summary-rolling-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.summary-status-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 5px rgba(255,255,255,0.4);
}

.summary-rolling-amount {
  font-size: 30px;
  font-weight: 800;
  line-height: 1.05;
  color: var(--text);
}

.summary-rolling-sub {
  margin-top: 6px;
  font-size: 14px;
  color: var(--text-secondary);
}

.summary-rolling-meta {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.summary-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--summary-pill-bg);
  border: 1px solid var(--summary-pill-border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.summary-pill-deadline {
  font-weight: 700;
  color: inherit;
}

.summary-worm {
  margin: 12px 0 4px;
  position: relative;
  z-index: 1;
}

.summary-worm svg {
  width: 100%;
  height: 140px;
  display: block;
}

.worm-label {
  font-size: 11px;
  fill: var(--text-secondary);
  font-family: inherit;
}

.worm-label-threshold {
  font-weight: 700;
  fill: currentColor;
  opacity: 0.6;
}

.summary-chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.summary-chart-detail {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: right;
}

.summary-chart-shell {
  position: relative;
}

.summary-chart-grid {
  position: relative;
  height: 240px;
  padding: 12px 0 0;
}

.summary-chart-target {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 2px dashed rgba(99, 102, 241, 0.5);
  pointer-events: none;
}

.summary-chart-target span {
  position: absolute;
  top: -11px;
  right: 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: var(--bg-card);
  padding-left: 8px;
}

.summary-bars {
  height: 100%;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

.summary-bar {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  color: inherit;
  text-align: center;
}

.summary-bar-column {
  position: relative;
  height: 180px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 3px;
  border-radius: 14px;
  background: rgba(148, 163, 184, 0.08);
}

.summary-bar-fill {
  width: 100%;
  min-height: 4px;
  border-radius: 12px 12px 8px 8px;
  transition: transform 0.12s ease;
}

.summary-bar.good .summary-bar-fill {
  background: linear-gradient(180deg, #34d399, #10b981);
}

.summary-bar.okay .summary-bar-fill {
  background: linear-gradient(180deg, #fbbf24, #f59e0b);
}

.summary-bar.low .summary-bar-fill {
  background: linear-gradient(180deg, #fb7185, #ef4444);
}

.summary-bar.today .summary-bar-column {
  box-shadow: inset 0 0 0 2px rgba(99, 102, 241, 0.3);
}

.summary-bar.selected .summary-bar-fill {
  transform: scale(1.04);
}

.summary-bar-label {
  font-size: 12px;
  color: var(--text-secondary);
}

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

.summary-mini-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.summary-mini-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.summary-mini-primary {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.05;
  color: var(--text);
}

.summary-mini-secondary {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.summary-log-section {
  margin-top: 12px;
}

.summary-log-toggle {
  width: 100%;
  padding: 13px 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: center;
}

#summary-log-body {
  margin-top: 12px;
}

.history-filters {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
}

.filter-btn {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.filter-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.day-group h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 12px 0 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.load-more {
  display: block;
  width: 100%;
  padding: 12px;
  font-size: 14px;
  font-weight: 500;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  margin-top: 12px;
}

/* --- Empty state --- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.empty-state .big-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* --- AI Chat (tab view) --- */
#aichat-view {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* undo main padding; quick-bar is hidden when chat is active */
  margin: -16px -20px -140px;
  padding: 0;
  height: calc(100vh - 56px);
  height: calc(100dvh - 56px);
}

.ai-chat-thread-bar {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  overflow-x: auto;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.ai-thread-btn {
  padding: 6px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.ai-thread-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.ai-thread-end {
  border-color: var(--text-secondary);
  color: var(--text-secondary);
}

.ai-history-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
}
.ai-history-item:hover {
  background: var(--bg-input);
}

.ai-history-date {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.ai-history-summary {
  font-size: 14px;
  color: var(--text);
  line-height: 1.4;
}

.ai-chat-notice {
  padding: 6px 12px;
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
  background: var(--bg-input);
  flex-shrink: 0;
}

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.ai-chat-empty {
  color: var(--text-secondary);
  font-size: 14px;
  text-align: center;
  padding: 40px 16px;
}

.ai-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
}

.ai-msg-user {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.ai-msg-assistant {
  background: var(--bg-input);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.ai-typing {
  display: flex;
  gap: 4px;
  padding: 12px 18px;
}

.ai-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: ai-bounce 1.2s infinite;
}
.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ai-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

.ai-chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.ai-chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  background: var(--bg-input);
  max-height: 120px;
  line-height: 1.4;
}
.ai-chat-input:focus { border-color: var(--accent); }

.ai-send-btn,
.ai-mic-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ai-send-btn {
  background: var(--accent);
  color: #fff;
}
.ai-send-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.ai-mic-btn {
  background: var(--bg-input);
  color: var(--text);
}
.ai-mic-btn.listening {
  background: var(--danger);
  color: #fff;
  animation: ai-pulse 1.5s infinite;
}

@keyframes ai-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

@media (max-width: 560px) {
  .summary-other-grid {
    grid-template-columns: 1fr;
  }

  .summary-bar-column {
    height: 160px;
  }

  .chat-thread {
    padding-left: 10px;
    padding-right: 10px;
  }

  .chat-bubble {
    max-width: 86%;
  }
}
