/* Baby tracker UI — modeled on the old React+Tailwind look
   (gray-50 / white cards, indigo primary, typed-color accent per event). */

:root {
  --bg:           #f9fafb;      /* gray-50 */
  --fg:           #111827;      /* gray-900 */
  --muted:        #6b7280;      /* gray-500 */
  --muted-2:      #9ca3af;      /* gray-400 */
  --card:         #ffffff;
  --border:       #e5e7eb;      /* gray-200 */
  --border-soft:  #f3f4f6;      /* gray-100 */
  --primary:      #4f46e5;      /* indigo-600 */
  --primary-dark: #4338ca;      /* indigo-700 */
  --primary-fg:   #ffffff;
  --primary-soft: #eef2ff;      /* indigo-50 */
  --success:      #10b981;      /* emerald-500 */
  --success-soft: #ecfdf5;
  --success-border:#a7f3d0;
  --danger:       #dc2626;      /* red-600 */
  --shadow:       0 1px 2px rgba(17, 24, 39, 0.04), 0 1px 3px rgba(17, 24, 39, 0.06);
  --radius:       8px;          /* rounded-lg */
  --radius-sm:    6px;

  /* Event-type colors (match the old iconColorMap) */
  --et-feeding:   #06b6d4;      /* cyan-500 */
  --et-diaper:    #eab308;      /* yellow-500 */
  --et-sleep:     #3b82f6;      /* blue-500 */
  --et-nursing:   #a855f7;      /* purple-500 */
  --et-pumping:   #ec4899;      /* pink-500 */
  --et-milestone: #f59e0b;      /* amber-500 */
  --et-misc:      #ef4444;      /* red-500 */
}

.theme-dark {
  --bg:           #111827;      /* gray-900 */
  --fg:           #f9fafb;
  --muted:        #9ca3af;      /* gray-400 */
  --muted-2:      #6b7280;
  --card:         #1f2937;      /* gray-800 */
  --border:       #374151;      /* gray-700 */
  --border-soft:  #1f2937;
  --primary:      #6366f1;      /* indigo-500 */
  --primary-dark: #4338ca;
  --primary-fg:   #ffffff;
  --primary-soft: #312e81;
  --success:      #34d399;
  --success-soft: rgba(16, 185, 129, 0.15);
  --success-border:#059669;
  --danger:       #f87171;
  --shadow:       0 1px 2px rgba(0,0,0,0.4), 0 6px 16px rgba(0,0,0,0.30);

  --et-feeding:   #22d3ee;
  --et-diaper:    #facc15;
  --et-sleep:     #60a5fa;
  --et-nursing:   #c084fc;
  --et-pumping:   #f472b6;
  --et-milestone: #fbbf24;
  --et-misc:      #f87171;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
       "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
body { padding-bottom: env(safe-area-inset-bottom); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; color: inherit; }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

.container { padding: 0; max-width: 800px; margin: 0 auto; }
.container.narrow { max-width: 420px; padding: 48px 20px 40px; }
.page { padding: 24px 16px 100px; }
body.bare { background: var(--bg); }

/* --- Top bar --- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
}
.logout { margin-left: auto; }
.logout button { background: transparent; border: none; color: var(--muted); font-size: 20px; min-height: 36px; min-width: 36px; }

/* --- Child selector (header) — plain <select> + age badge, matches React ChildSelector.tsx --- */
.child-select {
  flex: 1; min-width: 0; max-width: 520px;
  padding: 10px 32px 10px 12px;
  background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--fg); font-size: 15px; min-height: 40px;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%236b7280' stroke-width='2'><path d='M6 8l4 4 4-4'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 18px;
}
.child-age { color: var(--muted); font-size: 13px; white-space: nowrap; }
.child-select-none { color: var(--primary); padding: 6px 10px; }

/* --- Typography --- */
.page-title { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 4px; }
.page-title .page-sub { font-size: 16px; color: var(--muted); font-weight: 400; letter-spacing: 0; margin-left: 6px; }
.section-title { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
h1 { margin: 0 0 8px; font-size: 24px; letter-spacing: -0.02em; font-weight: 700; }
h2 { margin: 0 0 8px; font-size: 20px; font-weight: 600; }
h3 { margin: 14px 0 6px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.muted { color: var(--muted); }
.space-y-3 > * + * { margin-top: 12px; }
.space-y-6 > * + * { margin-top: 24px; }
code { background: var(--border-soft); padding: 1px 6px; border-radius: 4px; font-size: 13px; }

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

/* --- Quick Actions (Home) --- */
.qa-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 640px) { .qa-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.qa-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; padding: 12px 8px; min-height: 96px;
  background: transparent; border: none; color: var(--fg);
  border-radius: var(--radius);
}
.qa-btn:active { background: var(--border-soft); }
.qa-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.qa-form { margin: 0; padding: 0; display: block; }
.qa-form .qa-btn { width: 100%; }

.qa-btn.qa-active {
  background: var(--success-soft);
  border: 1px solid var(--success-border);
  color: var(--fg);
  padding: 14px 10px;
  gap: 6px;
}
.qa-active .qa-label { font-weight: 600; color: var(--success); }
.qa-active .qa-elapsed {
  font-size: 22px; font-weight: 700; letter-spacing: -0.02em;
  color: var(--fg); font-variant-numeric: tabular-nums;
}
.qa-actions { display: flex; gap: 6px; margin-top: 4px; }
.qa-actions .btn { padding: 6px 10px; min-height: 34px; font-size: 13px; }
.qa-actions form { margin: 0; }
.qa-btn .qa-icon {
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--et-misc);
}
.qa-btn.et-feeding   .qa-icon { color: var(--et-feeding); }
.qa-btn.et-diaper    .qa-icon { color: var(--et-diaper); }
.qa-btn.et-sleep     .qa-icon { color: var(--et-sleep); }
.qa-btn.et-nursing   .qa-icon { color: var(--et-nursing); }
.qa-btn.et-pumping   .qa-icon { color: var(--et-pumping); }
.qa-btn.et-milestone .qa-icon { color: var(--et-milestone); }
.qa-btn .qa-icon .icon { width: 32px; height: 32px; }
.qa-btn .qa-label { font-size: 14px; font-weight: 500; color: var(--fg); }
.qa-btn .qa-sub { font-size: 12px; color: var(--muted-2); }

/* --- Event card (Home recent + Daily list) --- */
.event-card {
  display: flex; gap: 16px;
  align-items: flex-start; width: 100%;
  padding: 16px; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
  text-align: left; color: var(--fg);
  transition: background-color 150ms ease;
}
.event-card:hover { background: var(--border-soft); }
.event-card.empty { display: block; }
.event-card-icon {
  flex-shrink: 0; margin-top: 2px;
  color: var(--et-misc);
}
.event-card-icon .icon { width: 22px; height: 22px; }
.event-card-icon.et-feeding   { color: var(--et-feeding);   }
.event-card-icon.et-diaper    { color: var(--et-diaper);    }
.event-card-icon.et-sleep     { color: var(--et-sleep);     }
.event-card-icon.et-nursing   { color: var(--et-nursing);   }
.event-card-icon.et-pumping   { color: var(--et-pumping);   }
.event-card-icon.et-milestone { color: var(--et-milestone); }
.event-card-main  { flex: 1; min-width: 0; }
.event-card-head  { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.event-card-title { margin: 0; font-weight: 500; color: var(--fg); }
.event-card-time  { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.event-card-right { font-size: 13px; color: var(--fg); text-align: right; }
.event-card-right p { margin: 0; }
.event-card-notes { margin: 8px 0 0; font-size: 13px; color: var(--muted); }

.empty-state { padding: 24px; text-align: center; color: var(--muted); }

/* Averages table */
.table-card { padding: 0; overflow-x: auto; }
table.averages { width: 100%; }
table.averages th, table.averages td { white-space: nowrap; padding: 10px 12px; }
table.averages .right { text-align: right; }
table.averages .sticky-left { position: sticky; left: 0; background: var(--card); z-index: 1; }
table.averages thead .sticky-left { background: var(--bg); }
table.averages tbody tr { border-top: 1px solid var(--border-soft); }

/* Settings toggle switch */
.toggle-switch {
  display: inline-flex; align-items: center;
  width: 44px; height: 24px; border-radius: 999px;
  background: var(--border); border: none; padding: 0; min-height: 0;
  transition: background 120ms ease;
  cursor: pointer;
}
.toggle-switch .toggle-knob {
  width: 18px; height: 18px; border-radius: 999px;
  background: #fff; margin-left: 3px; transition: margin 120ms ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.toggle-switch.on { background: var(--primary); }
.toggle-switch.on .toggle-knob { margin-left: 23px; }

.hidden { display: none; }
.border-top { border-top: 1px solid var(--border-soft); padding-top: 12px; }
.no-col { flex-direction: row; align-items: center; color: var(--fg); font-weight: 500; }
.btn.small, button.small { padding: 6px 10px; min-height: 32px; font-size: 13px; }

/* Settings children list */
.settings-children { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.settings-children details summary { list-style: none; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.settings-children details summary::-webkit-details-marker { display: none; }
.settings-child-name p { margin: 0; }

/* --- Timer card --- */
.timer-card {
  background: var(--success-soft);
  border: 1px solid var(--success-border);
  border-radius: var(--radius); padding: 16px;
}
.timer-label { margin: 0; color: var(--success); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; }
.timer-elapsed {
  font-size: 44px; font-weight: 700; letter-spacing: -0.03em; margin: 6px 0 2px;
  color: var(--fg); font-variant-numeric: tabular-nums;
}

/* --- Forms / buttons --- */
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; color: var(--fg); }
label.check span { color: var(--fg); }
input, select, textarea {
  width: 100%; font: inherit; color: var(--fg);
  background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; min-height: 44px;
}
input[type="checkbox"], input[type="radio"] { width: auto; min-height: auto; }
input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(79, 70, 229, 0.18); outline-offset: 0;
  border-color: var(--primary);
}

.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--card); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; min-height: 44px;
  text-decoration: none;
}
.btn.ghost, button.ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn.primary, button.primary {
  background: var(--primary); color: var(--primary-fg);
  border: 1px solid transparent; font-weight: 600;
}
.btn.primary:hover, button.primary:hover { background: var(--primary-dark); text-decoration: none; }
.btn.danger, button.danger {
  background: var(--danger); color: #fff; border: 1px solid transparent; font-weight: 600;
}
.btn.wide, button.wide { width: 100%; }
.icon-btn { background: transparent; border: none; padding: 6px; min-height: 36px; }
.linkish  { background: transparent; border: none; color: var(--primary); padding: 4px 0; text-align: left; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.row   { display: flex; flex-wrap: wrap; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.inline { display: inline-block; margin-right: 8px; }
.inline label { display: inline-flex; gap: 8px; align-items: center; color: var(--fg); }

.date-nav {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
}
.date-nav input { text-align: center; }

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 10px 8px; border-bottom: 1px solid var(--border-soft); text-align: left; }
table.data th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }

/* --- Timeline (Detail) --- */
.timeline-wrap { overflow: auto; border-radius: var(--radius-sm); }
.timeline { border-collapse: collapse; table-layout: fixed; width: 100%; font-size: 11px; }
.timeline th, .timeline td {
  border: 1px solid var(--border-soft); padding: 0; height: 22px;
  text-align: center; color: var(--muted); min-width: 56px;
}
.timeline th { background: var(--card); position: sticky; top: 0; z-index: 2; }
.timeline td.sleep { background: rgba(59, 130, 246, 0.18); }
.timeline .dot {
  display: inline-block; width: 6px; height: 6px; margin: 1px;
  border-radius: 999px; background: var(--primary);
}
.timeline .corner { background: var(--card); }

/* --- Bottom nav --- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav .tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  text-align: center; padding: 10px 0 12px; color: var(--muted);
  min-height: 54px; font-size: 11px; text-decoration: none;
}
.bottom-nav .tab .icon { width: 22px; height: 22px; }
.bottom-nav .tab:hover { color: var(--fg); background: var(--border-soft); }
.bottom-nav .tab.active { color: var(--primary); }
.bottom-nav .tab.active span { font-weight: 600; }

/* --- Children list in Settings --- */
.children { list-style: none; padding: 0; margin: 0; }
.children li + li { border-top: 1px solid var(--border-soft); }
.children details { padding: 10px 0; }
.children summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; }
.children summary::-webkit-details-marker { display: none; }
.children summary strong { font-weight: 600; }

/* --- Flash + error --- */
.flash { margin: 10px 16px 0; padding: 10px 14px; background: var(--primary-soft); color: var(--primary-dark); border-radius: var(--radius-sm); font-size: 14px; }
.error { margin: 10px 0; padding: 10px 14px; background: rgba(220, 38, 38, 0.10); color: var(--danger); border-radius: var(--radius-sm); font-size: 14px; }

/* --- Modal --- */
.modal { position: fixed; inset: 0; display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(17, 24, 39, 0.50); }
.modal-body {
  position: relative; z-index: 51;
  width: 100%; max-width: 520px; margin: 0;
  background: var(--card);
  border-radius: 18px 18px 0 0; padding: 20px 20px 24px; max-height: 92vh; overflow: auto;
  box-shadow: 0 -10px 30px rgba(0,0,0,0.2);
}
.modal-title { margin: 0 0 12px; font-size: 18px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.modal-title-icon { display: inline-flex; }
.modal-title-icon .icon { width: 24px; height: 24px; }
.modal-title-icon.et-feeding   { color: var(--et-feeding); }
.modal-title-icon.et-diaper    { color: var(--et-diaper); }
.modal-title-icon.et-sleep     { color: var(--et-sleep); }
.modal-title-icon.et-nursing   { color: var(--et-nursing); }
.modal-title-icon.et-pumping   { color: var(--et-pumping); }
.modal-title-icon.et-milestone { color: var(--et-milestone); }

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 6px; }

/* Icon toggle buttons (diaper wet/dirty, breast left/right) */
.toggle-row { display: flex; justify-content: center; gap: 32px; padding: 4px 0; }
.toggle-ic {
  display: flex; flex-direction: column; align-items: center;
  gap: 6px; padding: 10px 14px;
  background: transparent; border: 2px solid transparent; border-radius: 10px;
  color: var(--muted); cursor: pointer;
}
.toggle-ic .icon { width: 40px; height: 40px; }
.toggle-ic.on.wet    { color: #2563eb; background: rgba(37, 99, 235, 0.12);  border-color: #3b82f6; }
.toggle-ic.on.dirty  { color: #b45309; background: rgba(217, 119, 6, 0.14);  border-color: #d97706; }
.toggle-ic.on.left   { color: #6d28d9; background: rgba(124, 58, 237, 0.12); border-color: #7c3aed; }
.toggle-ic.on.right  { color: #be185d; background: rgba(236, 72, 153, 0.12); border-color: #ec4899; }
.modal .close-btn {
  position: absolute; top: 10px; right: 10px;
  background: transparent; border: none; padding: 6px; color: var(--muted); min-height: 36px; min-width: 36px;
}
@media (min-width: 640px) {
  .modal { align-items: center; }
  .modal-body { border-radius: 18px; max-height: 86vh; }
}

.icon { width: 20px; height: 20px; display: inline-block; vertical-align: middle; flex-shrink: 0; }

/* ==========================================================================
   Detail page — replicates the old React layout: typed filter tiles,
   alternating column tints, proportional sleep bars, colored dots,
   dashed-green current-time line.
   ========================================================================== */

.detail-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
}
.detail-dates { display: flex; gap: 10px; }
.detail-dates input[type="date"] {
  min-height: 40px; width: auto; min-width: 140px;
}

.detail-filters {
  display: flex; flex-wrap: wrap; gap: 14px; justify-content: center;
}
.filter-tile {
  display: flex; flex-direction: column; align-items: center;
  gap: 6px; padding: 14px 18px; min-width: 96px;
  background: transparent; border: 2px solid var(--border); border-radius: var(--radius);
  color: var(--muted-2);
  text-decoration: none; transition: color 120ms ease, border-color 120ms ease;
}
.filter-tile:hover { text-decoration: none; }
.filter-tile .icon { width: 24px; height: 24px; }
.filter-tile-label { font-size: 12px; font-weight: 500; }
.filter-tile.off { color: var(--muted-2); border-color: var(--border); }
.filter-tile.active { border-color: currentColor; }
.filter-tile.active.et-feeding   { color: var(--et-feeding);   }
.filter-tile.active.et-diaper    { color: var(--et-diaper);    }
.filter-tile.active.et-sleep     { color: var(--et-sleep);     }
.filter-tile.active.et-nursing   { color: var(--et-nursing);   }
.filter-tile.active.et-pumping   { color: var(--et-pumping);   }
.filter-tile.active.et-milestone { color: var(--et-milestone); }

/* Grid shell */
.detail-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
.detail-grid {
  display: grid;
  grid-template-columns: 48px 1fr;
}
.detail-hours { display: flex; flex-direction: column; }
.detail-hour-header { height: 40px; border-bottom: 1px solid var(--border); background: var(--card); }
.detail-hour-body  { position: relative; }
.detail-hour-label {
  font-size: 11px; color: var(--muted); text-align: right;
  padding: 2px 8px 0 0; height: 24px; line-height: 22px;
  border-bottom: 1px solid var(--border-soft);
}

.detail-days { overflow-x: auto; }
/* min-width: max-content lets head/body grow to the summed column width
   when the viewport is narrower than N × 80px. Without it, the flex row
   stays at viewport width while its columns overflow, and the absolutely-
   positioned .now-line (left:0; right:0) only spans the viewport instead
   of every day. */
.detail-days-head { display: flex; min-width: max-content; }
.detail-day-head {
  flex: 1; min-width: 80px; text-align: center;
  padding: 12px 6px; font-size: 13px; font-weight: 500;
  color: var(--fg); border-bottom: 1px solid var(--border);
  border-left: 1px solid var(--border-soft);
}
.detail-day-head:first-child { border-left: none; }
.detail-days-body { display: flex; position: relative; min-width: max-content; }

.detail-col {
  flex: 1; min-width: 80px; position: relative;
  height: calc(24 * 24px); /* 24 rows × 24px = 576px */
  border-left: 1px solid var(--border-soft);
}
.detail-col:first-child { border-left: none; }
.detail-col.even { background: var(--bg); }

/* Hour gridlines inside columns (skipping row 0 top edge and row 24 bottom) */
.hour-rule {
  position: absolute; left: 0; right: 0; height: 1px;
  background: var(--border-soft);
}

/* Sleep bar — blue translucent block spanning its duration. */
.sleep-bar {
  position: absolute; left: 6px; right: 6px;
  background: rgba(59, 130, 246, 0.35);
  border-radius: 4px;
  min-height: 2px;
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.15);
}
.theme-dark .sleep-bar { background: rgba(96, 165, 250, 0.35); }

/* Event dot — absolutely-placed 8px dot in typed color, horizontally centered. */
.event-dot {
  position: absolute; left: 50%; transform: translate(-50%, -50%);
  width: 8px; height: 8px; border-radius: 999px;
  background: var(--et-misc);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.15);
  z-index: 2;
}
.event-dot.et-feeding   { background: var(--et-feeding); }
.event-dot.et-diaper    { background: var(--et-diaper); }
.event-dot.et-sleep     { background: var(--et-sleep); }
.event-dot.et-nursing   { background: var(--et-nursing); }
.event-dot.et-pumping   { background: var(--et-pumping); }
.event-dot.et-milestone { background: var(--et-milestone); }

/* Current-time line — dashed green horizontal line spanning every date
   column, with a left-edge dot. Lives on the flex body so it's drawn
   above all columns/events. */
.now-line {
  position: absolute; left: 0; right: 0; height: 0;
  border-top: 1.5px dashed var(--success);
  z-index: 3; pointer-events: none;
}
.now-dot {
  position: absolute; left: -4px; top: -5px;
  width: 8px; height: 8px; border-radius: 999px;
  background: var(--success);
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.25);
}
