/* ==========================================================================
   Blooming Baby — admin console
   Brand tokens are the 2026-07-23 design system, taken from
   lib/core/theme/bloom_ui.dart so the console reads as the same product.

   Two differences from the marketing site, both deliberate:
   - Density. The site runs a spacious 3/10 dial; a console that shows tables
     of parents needs the opposite, so the spacing scale here is tighter while
     the colour and type scales are identical.
   - Light only. The site has no dark mode and the brand is a pale lavender;
     an auto-flipped dark mode would invert pastels that the contrast rules
     depend on. Committing to one look is the safer choice here.

   THE ONE RULE THIS FILE RUNS ON (CLAUDE.md): a pastel is a SURFACE. It never
   carries text and is never used AS text. Every pastel below is a fill, and
   every fill carries --ink. Where a fill needed a white label it uses
   --cta-fill (#C64F2E, 4.6:1), never --coral (#FF9C85, 2.0:1).
   ========================================================================== */

:root {
  /* Brand — 1:1 with BloomColors */
  --lavender-bg: #fdf8ff;
  --surface: #ffffff;
  --violet: #7c3aed;
  --violet-deep: #6b21a8;
  --violet-mid: #8b5cf6;
  --violet-soft: #a78bfa; /* decorative only — 2.7:1 on white */
  --violet-tint: #ddd6fe;
  --coral: #ff9c85;       /* pastel identity only — never behind white text */
  --pink: #f6b1c3;
  --mint: #dcf2e5;
  --marigold: #ffb454;
  --card-border: #e8d7f6;
  --hairline: #ede9fe;
  --ink: #45375a;
  --ink-soft: #785589;

  /* Deep companions — these are the ones allowed to express something */
  --cta-fill: #c64f2e;       /* = BloomColors.ctaGold, 4.6:1 with white */
  --cta-fill-hover: #ae4527;
  --border-strong: #9579c2;  /* = BloomColors.borderStrong, 3.3:1 — controls */
  --focus-ring: #7c3aed;
  --sage-deep: #4f7a4a;
  --disabled-fill: #efeaf5;
  --disabled-ink: #785589;
  --danger: #b3261e;

  /* Tracker inks, reused for the activity feed */
  --feed-ink: #7c3aed;
  --sleep-ink: #047857;
  --diaper-ink: #be185d;

  /* Density: tighter than the marketing site */
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;
  --s7: 3rem;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(69, 55, 90, 0.04), 0 2px 8px rgba(69, 55, 90, 0.05);
  --shadow-md: 0 2px 4px rgba(69, 55, 90, 0.05), 0 10px 26px rgba(69, 55, 90, 0.08);
  --shadow-lg: 0 4px 8px rgba(69, 55, 90, 0.06), 0 20px 52px rgba(69, 55, 90, 0.12);

  --font-display: "Baloo 2", ui-rounded, "Segoe UI", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --sidebar-w: 232px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after { box-sizing: border-box; }

/* The `hidden` attribute is honoured by a UA-stylesheet rule
   (`[hidden] { display: none }`), and author styles beat UA styles regardless
   of specificity. So `.login-wrap { display: grid }` silently defeated
   `loginView.hidden = true`: after signing in, the app rendered AND the
   full-height login card stayed on the page, which reads exactly like being
   signed straight back out. Nothing in the auth path was wrong — every request
   was a 200.
   This rule is why `hidden` can be trusted here. Anything that sets `display`
   on an element the app also toggles with `hidden` needs it. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--lavender-bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; line-height: 1.2; font-weight: 700; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }

a { color: var(--violet-deep); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--violet); }

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --- Login ---------------------------------------------------------------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--s5);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--s6);
}

.login-card .brand {
  display: flex; align-items: center; gap: var(--s3);
  margin-bottom: var(--s5);
}
.login-card .brand img { width: 36px; height: 36px; }
.login-card .brand span { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; }
.login-card p.lede { color: var(--ink-soft); margin: 0 0 var(--s5); font-size: 0.875rem; }

/* --- Shell --------------------------------------------------------------- */

.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--card-border);
  padding: var(--s5) var(--s4);
  display: flex; flex-direction: column; gap: var(--s5);
  position: sticky; top: 0; height: 100vh;
}

.sidebar .brand { display: flex; align-items: center; gap: var(--s2); padding: 0 var(--s2); }
.sidebar .brand img { width: 30px; height: 30px; }
.sidebar .brand span { font-family: var(--font-display); font-weight: 700; font-size: 1.0625rem; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s2) var(--s3);
  border-radius: var(--radius-sm);
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9062rem;
  transition: background var(--ease) 160ms;
}
.nav a:hover { background: var(--lavender-bg); }
.nav a[aria-current="page"] {
  background: var(--violet-tint);
  color: var(--violet-deep);
}
.nav a svg { width: 18px; height: 18px; flex: none; stroke-width: 1.75; }

.sidebar-foot { margin-top: auto; font-size: 0.8125rem; color: var(--ink-soft); }
.sidebar-foot .who { font-weight: 700; color: var(--ink); word-break: break-all; }
.sidebar-foot .role { text-transform: uppercase; letter-spacing: 0.04em; font-size: 0.6875rem; }

.main { padding: var(--s5) var(--s6) var(--s7); min-width: 0; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--s4); margin-bottom: var(--s5); flex-wrap: wrap;
}
.page-head .sub { color: var(--ink-soft); font-size: 0.875rem; margin-top: 2px; }

/* --- Cards & tiles ------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: var(--s5);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--s4); }
.card > h2 { margin-bottom: var(--s4); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s4); flex-wrap: wrap; }
.card-head h2 { margin: 0; }

.tiles { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); }

.tile {
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: var(--s4);
  box-shadow: var(--shadow-sm);
}
.tile .label {
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.03em;
  text-transform: uppercase; color: var(--ink-soft);
}
.tile .value { font-family: var(--font-display); font-size: 1.875rem; font-weight: 700; line-height: 1.1; margin-top: var(--s1); }
.tile .foot { font-size: 0.8125rem; color: var(--ink-soft); margin-top: 2px; }
.tile.flag { border-color: var(--border-strong); }
.tile.flag .value { color: var(--cta-fill); }

.section-title {
  font-family: var(--font-display); font-weight: 700; font-size: 0.8125rem;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft);
  margin: var(--s5) 0 var(--s3);
}

/* --- Controls ------------------------------------------------------------ */

label.field { display: block; margin-bottom: var(--s4); }
label.field > .lbl {
  display: block; font-size: 0.8125rem; font-weight: 700;
  color: var(--ink-soft); margin-bottom: var(--s1);
}

input[type="text"], input[type="email"], input[type="password"],
input[type="search"], input[type="date"], select, textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  /* borderStrong, not cardBorder: a control a parent — or here, an operator —
     has to find needs a 3:1 edge, not a 1.36:1 decoration. */
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6875rem;
  min-height: 40px;
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%2345375a' stroke-width='1.75'%3E%3Cpath d='M4 6.5 8 10.5l4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 16px;
  padding-right: 2rem;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.18);
}
input::placeholder { color: var(--ink-soft); opacity: 0.85; }
textarea { min-height: 76px; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  font: inherit; font-weight: 700;
  padding: 0.5rem 1rem;
  min-height: 40px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--ease) 160ms, border-color var(--ease) 160ms;
}
/* Filled CTA: --cta-fill under white, never the coral pastel. */
.btn-primary { background: var(--cta-fill); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--cta-fill-hover); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--lavender-bg); }
.btn-ghost { background: transparent; color: var(--violet-deep); padding: 0.375rem 0.625rem; min-height: 34px; }
.btn-ghost:hover:not(:disabled) { background: var(--violet-tint); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #fdf2f1; }
.btn-sm { min-height: 32px; padding: 0.25rem 0.6875rem; font-size: 0.8125rem; }
.btn:disabled {
  cursor: not-allowed;
  /* Not a faded fill: 50% alpha on the coral put white text at ~2.1:1 on
     something that still looked tappable. */
  background: var(--disabled-fill);
  color: var(--disabled-ink);
  border-color: var(--border-strong);
}

.btn-block { width: 100%; }

.filters {
  display: flex; flex-wrap: wrap; gap: var(--s3); align-items: flex-end;
  margin-bottom: var(--s4);
}
.filters label.field { margin-bottom: 0; }
.filters .grow { flex: 1 1 220px; min-width: 180px; }
.filters .narrow { flex: 0 0 150px; }

/* --- Badges (pastel fill, ink label, always with text) ------------------- */

.badge {
  display: inline-flex; align-items: center; gap: var(--s1);
  padding: 0.125rem 0.5rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem; font-weight: 700;
  white-space: nowrap;
  /* Every pastel fill below carries --ink, never --ink-soft: inkSoft on blush
     is 3.47:1. */
  color: var(--ink);
  background: var(--hairline);
}
.badge-premium  { background: var(--violet-tint); }
.badge-free     { background: #f1edf9; }
.badge-active   { background: var(--mint); }
.badge-trialing { background: #ffe9cc; }
.badge-expired,
.badge-canceled { background: var(--pink); }
.badge-none     { background: var(--disabled-fill); }
.badge-warn     { background: var(--marigold); } /* ink on marigold = 6.1:1 */

.role-pill {
  display: inline-block; padding: 0.0625rem 0.5rem;
  border-radius: var(--radius-pill);
  background: var(--violet-tint); color: var(--violet-deep);
  font-size: 0.6875rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.04em;
}

/* --- Tables ------------------------------------------------------------- */

.table-wrap {
  /* Wide tables scroll inside their own box; the page body never scrolls
     sideways. */
  overflow-x: auto;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
  text-align: left;
  font-family: var(--font-body);
  font-size: 0.75rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ink-soft);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--card-border);
  background: var(--lavender-bg);
  white-space: nowrap;
}
tbody td { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--hairline); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--lavender-bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.nowrap { white-space: nowrap; }
.mono { font-family: var(--font-mono); font-size: 0.8125rem; }
.muted { color: var(--ink-soft); }
.strong { font-weight: 700; }

.pager {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s4); margin-top: var(--s3); font-size: 0.875rem; color: var(--ink-soft);
}
.pager .btns { display: flex; gap: var(--s2); }

/* --- States ------------------------------------------------------------- */

.empty, .loading, .error-box {
  padding: var(--s6) var(--s5);
  text-align: center;
  color: var(--ink-soft);
}
.empty h3 { color: var(--ink); margin-bottom: var(--s2); }
.error-box {
  color: var(--ink);
  background: #fdf2f1;
  border: 1px solid var(--danger);
  border-radius: var(--radius-md);
  text-align: left;
  padding: var(--s4);
}
.error-box .t { font-weight: 800; margin-bottom: var(--s1); }

.skeleton {
  height: 12px; border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--hairline), #f7f3fd, var(--hairline));
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
  * { transition-duration: 1ms !important; }
}

/* --- Chart -------------------------------------------------------------- */

/* Built from divs rather than a scaled <svg>: a viewBox at width:100% scales
   its text along with its geometry, which blew 10px axis labels up to ~17px in
   a wide card. Here the bars flex and the labels keep their set size. */

.chart { --y-gutter: 28px; }

.chart-plot {
  position: relative;
  height: 180px;
  margin-left: var(--y-gutter);
}
.chart-plot:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 3px; }

.chart-grid { position: absolute; inset: 0; }
.chart-gridline {
  position: absolute;
  left: 0; right: 0;
  /* Hairline, solid, one shade off the surface — never dashed. */
  border-top: 1px solid var(--hairline);
}
.chart-ytick {
  position: absolute;
  right: calc(100% + 6px);
  transform: translateY(-50%);
  font-size: 0.6875rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.chart-bars {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  /* A 2px surface gap separates neighbours — a gap, not a stroke around each
     bar, which would read as chrome. */
  gap: 2px;
}
.chart-col {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: flex-end;
  cursor: default;
}
.chart-bar {
  width: 100%;
  min-height: 2px;
  background: var(--violet);
  /* Rounded data-end, anchored to the baseline: only the top corners. */
  border-radius: 4px 4px 0 0;
  transition: background 120ms var(--ease);
}
.chart-col:hover .chart-bar { background: var(--violet-deep); }

.chart-xaxis {
  display: flex;
  gap: 2px;
  margin: var(--s2) 0 0 var(--y-gutter);
}
.chart-xlabel {
  flex: 1 1 0;
  min-width: 0;
  font-size: 0.6875rem;
  color: var(--ink-soft);
  white-space: nowrap;
  /* Labels sit on only ~5 of 30 columns, so each one overflows its own slot;
     centring it on that slot keeps it under its bar. */
  text-align: center;
  overflow: visible;
}

.chart-tip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: var(--s1) var(--s3);
  font-size: 0.8125rem;
  white-space: nowrap;
  opacity: 0;
  transform: translateX(-50%);
  transition: opacity 120ms var(--ease);
  z-index: 5;
}
.chart-tip.on { opacity: 1; }
.chart-tip .d { color: var(--ink-soft); }
.chart-tip .v { font-weight: 800; }

/* --- Detail view -------------------------------------------------------- */

.detail-grid { display: grid; gap: var(--s4); grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); }
@media (max-width: 1080px) { .detail-grid { grid-template-columns: 1fr; } }

dl.kv { margin: 0; display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: var(--s2) var(--s4); }
dl.kv dt { color: var(--ink-soft); font-size: 0.8125rem; font-weight: 700; }
dl.kv dd { margin: 0; font-size: 0.875rem; min-width: 0; overflow-wrap: anywhere; }

.baby-card {
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: var(--s3) var(--s4);
}
.baby-card + .baby-card { margin-top: var(--s2); }
.baby-card .nm { font-family: var(--font-display); font-weight: 700; }
.counts { display: flex; flex-wrap: wrap; gap: var(--s3); margin-top: var(--s1); font-size: 0.8125rem; color: var(--ink-soft); }
.counts b { color: var(--ink); font-variant-numeric: tabular-nums; }

.feed-list { list-style: none; margin: 0; padding: 0; }
.feed-list li { display: flex; gap: var(--s3); padding: var(--s2) 0; border-bottom: 1px solid var(--hairline); font-size: 0.875rem; }
.feed-list li:last-child { border-bottom: none; }
.feed-list .kind { font-weight: 800; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; flex: 0 0 62px; }
.kind-feed { color: var(--feed-ink); }
.kind-sleep { color: var(--sleep-ink); }
.kind-diaper { color: var(--diaper-ink); }
.feed-list .when { margin-left: auto; color: var(--ink-soft); white-space: nowrap; font-size: 0.8125rem; }

/* --- Modal -------------------------------------------------------------- */

dialog.modal {
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--s5);
  width: min(480px, calc(100vw - 2rem));
  color: var(--ink);
  background: var(--surface);
}
dialog.modal::backdrop { background: rgba(69, 55, 90, 0.42); }
dialog.modal h2 { margin-bottom: var(--s2); }
dialog.modal .lede { color: var(--ink-soft); font-size: 0.875rem; margin: 0 0 var(--s4); }
dialog.modal .actions { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s5); }

.warn-note {
  background: var(--marigold);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: var(--s2) var(--s3);
  font-size: 0.8125rem;
  font-weight: 600;
}

/* --- Toasts ------------------------------------------------------------- */

.toasts {
  position: fixed; bottom: var(--s5); right: var(--s5);
  display: flex; flex-direction: column; gap: var(--s2);
  z-index: 40; max-width: min(380px, calc(100vw - 2rem));
}
.toast {
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-left: 4px solid var(--violet);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: var(--s3) var(--s4);
  font-size: 0.875rem;
}
.toast.ok { border-left-color: var(--sage-deep); }
.toast.bad { border-left-color: var(--danger); }
.toast .t { font-weight: 800; }

/* --- Responsive --------------------------------------------------------- */

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto;
    flex-direction: row; align-items: center; flex-wrap: wrap;
    gap: var(--s3);
    border-right: none; border-bottom: 1px solid var(--card-border);
  }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav a span.lbl { display: none; }
  .nav a { padding: var(--s2); }
  .sidebar-foot { margin-left: auto; }
  .main { padding: var(--s4) var(--s4) var(--s6); }
}
