/* CalmChore -- iOS-flavoured, light only, no framework.
   Series colours come from the reference categorical palette, in slot order. */

:root {
  color-scheme: light;
  --bg:            #f2f2f7;
  --surface:       #ffffff;
  --surface-sunk:  #ececef;
  --border:        #e2e2e7;
  --text-primary:  #12121a;
  --text-secondary:#5f5f6b;
  --text-muted:    #8e8e97;
  --accent:        #2a78d6;

  /* Categorical slots 1 and 2. Keyed by colour token, not by person, so
     renaming or adding someone can't silently collapse two series to one. */
  --series-blue:    #2a78d6;
  --series-amber:   #eb6834;
  --series-aqua:    #1baf7a;
  --series-violet:  #4a3aa7;
  --series-magenta: #e87ba4;

  --grid:          #e6e6eb;
  --ok:            #1baf7a;
  --idle:          #b3b3bb;

  --radius:        14px;
  --tap:           52px;
  --shadow:        0 1px 2px rgba(0, 0, 0, .05);
}

/* Light only, by choice -- `color-scheme: light` above also stops iOS from
   auto-darkening form controls when the phone is in dark mode. */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button, input, textarea, .sheet-row { touch-action: manipulation; }
/* Any author `display` beats the UA's [hidden] rule, and this app sets display
   on several hideable elements. Assert it once rather than per-selector. */
[hidden] { display: none !important; }
/* iOS zooms the page when focusing any control under 16px. */
input, textarea, select { font-size: 16px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

/* --- chrome --------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 20px 8px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}
.topbar h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -.02em; }

.sync-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--idle); transition: background .3s, opacity .3s;
}
.sync-dot[data-status="syncing"] { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.sync-dot[data-status="synced"]  { background: var(--ok); }
.sync-dot[data-status="offline"] { background: var(--idle); }
@keyframes pulse { 50% { opacity: .25; } }

.segmented {
  display: flex; gap: 2px; margin: 4px 20px 16px;
  padding: 2px; border-radius: 10px; background: var(--surface-sunk);
}
.segmented.sub { margin-top: 0; }
.seg {
  flex: 1; padding: 8px 12px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text-secondary);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.seg.active { background: var(--surface); color: var(--text-primary); box-shadow: var(--shadow); }

main { padding: 0 20px calc(40px + env(safe-area-inset-bottom)); }
.view { display: none; }
.view.active { display: block; }

.period-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.nav-btn {
  width: 40px; height: 40px; flex: none;
  border: 0; border-radius: 10px; background: var(--surface); box-shadow: var(--shadow);
  color: var(--accent); font-size: 24px; line-height: 1; cursor: pointer;
}
.nav-btn:disabled { opacity: .3; cursor: default; }
.period-label {
  flex: 1; padding: 10px; border: 0; border-radius: 10px;
  background: var(--surface); box-shadow: var(--shadow);
  color: var(--text-primary); font: inherit; font-weight: 600; cursor: pointer;
}

/* --- today ---------------------------------------------------------------- */

.chores { list-style: none; margin: 0 0 12px; padding: 0;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.chore { border-bottom: 1px solid var(--border); }
.chore:last-child { border-bottom: 0; }
.chore-row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.chore-icon { font-size: 24px; flex: none; }
.chore-name { flex: 1; font-weight: 500; }
.chore-taps { display: flex; gap: 8px; flex: none; }

.note-toggle {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 9px; background: var(--surface-sunk);
  font-size: 15px; line-height: 1; cursor: pointer; opacity: .55;
}
.note-toggle.has-note { opacity: 1; background: color-mix(in srgb, var(--accent) 14%, var(--surface-sunk)); }
.note-toggle[aria-expanded="true"] { outline: 2px solid var(--accent); outline-offset: 1px; }

.note-wrap { padding: 0 14px 14px; display: grid; gap: 8px; }
.note-field { display: flex; gap: 8px; align-items: flex-start; }
/* Fixed height so the row never jumps as you type; longer notes scroll
   inside the box rather than pushing the chore list around. */
.note-field textarea {
  flex: 1; padding: 10px 12px;
  height: 76px; min-height: 76px; max-height: 76px; resize: none;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  border: 0; border-radius: 10px; background: var(--surface-sunk);
  color: var(--text-primary); font: inherit; line-height: 1.5;
}
.note-field textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Initials tag marking whose note this is. */
.note-owner {
  flex: none; margin-top: 9px; padding: 3px 7px; border-radius: 6px;
  font-size: 11px; font-weight: 700; color: #fff; letter-spacing: .02em;
}


.hint { margin: 0 0 20px 4px; font-size: 12px; color: var(--text-muted); }

.tap {
  width: var(--tap); height: var(--tap); flex: none;
  display: grid; place-items: center;
  border: 2px solid var(--border); border-radius: 50%;
  background: transparent; color: var(--text-muted);
  font: inherit; font-size: 15px; font-weight: 700; letter-spacing: .02em;
  cursor: pointer; transition: transform .12s, background .15s, color .15s, border-color .15s;
}
.tap:active { transform: scale(.9); }
.tap[aria-pressed="true"] { color: #fff; border-color: transparent; }
.tap[data-color="blue"][aria-pressed="true"]    { background: var(--series-blue); }
.tap[data-color="amber"][aria-pressed="true"]   { background: var(--series-amber); }
.tap[data-color="aqua"][aria-pressed="true"]    { background: var(--series-aqua); }
.tap[data-color="violet"][aria-pressed="true"]  { background: var(--series-violet); }
.tap[data-color="magenta"][aria-pressed="true"] { background: var(--series-magenta); }

/* --- trends --------------------------------------------------------------- */

.section-heading {
  margin: 26px 0 10px 4px; font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted);
}

.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.total-card {
  padding: 16px; border-radius: var(--radius); width: 100%;
  border: 0; background: var(--surface); box-shadow: var(--shadow);
  color: inherit; font: inherit; text-align: left; cursor: pointer;
  transition: opacity .15s, box-shadow .15s;
}
.total-card:active { transform: scale(.99); }
/* Selecting one card filters the view; the other recedes but stays legible
   so it still reads as a control you can switch to. */
.totals.filtered .total-card { opacity: .45; }
/* Must out-specify the rule above, or the selected card dims along with it. */
.totals.filtered .total-card.selected { opacity: 1; }
.total-card.selected {
  box-shadow: inset 0 0 0 2px var(--card-accent), var(--shadow);
}
.total-name { display: flex; align-items: center; gap: 7px;
  font-size: 14px; font-weight: 600; color: var(--text-secondary); }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.total-count { margin-top: 6px; font-size: 40px; font-weight: 700;
  letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.total-unit { font-size: 13px; color: var(--text-muted); }

.history {
  padding: 14px 12px 8px; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
}
.history svg { display: block; width: 100%; height: auto; }
.history .grid-line { stroke: var(--grid); stroke-width: 1; }
.history .axis-label { fill: var(--text-muted); font-size: 10px; }
.history .value-label { fill: var(--text-secondary); font-size: 10px; font-weight: 600; }

.legend { display: flex; gap: 16px; margin-top: 10px; padding-left: 2px; }
.legend-item { display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-secondary); }

.by-chore { list-style: none; margin: 0; padding: 0;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.by-chore li { border-bottom: 1px solid var(--border); }
.by-chore li:last-child { border-bottom: 0; }
.chore-link {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 14px; border: 0; background: transparent;
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.by-chore .chore-name { font-weight: 500; }
.by-chore .count { font-weight: 700; font-variant-numeric: tabular-nums; }
.chev { color: var(--text-muted); font-size: 20px; line-height: 1;
  transition: transform .15s; }
.chore-link.open .chev { transform: rotate(90deg); }
.chore-link.open { background: var(--surface-sunk); }

.chore-detail {
  margin-top: 12px; padding: 14px; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
}
.detail-head { font-weight: 600; margin-bottom: 10px; }
.detail-list { list-style: none; margin: 0; padding: 0; }
.detail-list li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.detail-list li:last-child { border-bottom: 0; }
.detail-row { display: flex; align-items: center; gap: 10px; }
.detail-date { flex: 1; font-size: 14px; color: var(--text-secondary); }
.detail-who { display: flex; gap: 5px; }
.chip {
  padding: 3px 7px; border-radius: 6px;
  font-size: 11px; font-weight: 700; color: #fff; letter-spacing: .02em;
}

.detail-note {
  display: flex; gap: 8px; align-items: flex-start;
  margin: 8px 0 0; padding: 9px 11px; border-radius: 9px;
  background: var(--surface-sunk); color: var(--text-secondary);
  font-size: 14px; line-height: 1.45; white-space: pre-wrap;
  overflow-wrap: anywhere;                    /* long unbroken text can't overflow */
  max-height: 132px; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.detail-note .note-owner { margin-top: 1px; }

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

/* --- screens --------------------------------------------------------------
   One screen visible at a time: loading, sign-in, first-run setup, or the app. */

.screen { display: none; }
.screen.active { display: block; }

.centered {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px;
  padding: 32px 24px calc(32px + env(safe-area-inset-bottom));
}
.centered.narrow > * { width: 100%; max-width: 360px; }

.brand { margin: 0; font-size: 32px; font-weight: 700; letter-spacing: -.02em; text-align: center; }
.tagline { margin: 0 0 8px; text-align: center; color: var(--text-secondary); }
.fineprint { margin: 4px 0 0; font-size: 12px; color: var(--text-muted); text-align: center; }

.stack { display: grid; gap: 12px; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-secondary); padding-left: 2px; }
.field input {
  width: 100%; padding: 13px 14px; border: 0; border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow);
  color: var(--text-primary); font: inherit;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  padding: 13px 16px; border: 0; border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow);
  color: var(--text-primary); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:active { transform: scale(.99); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.link { background: none; box-shadow: none; color: var(--accent); font-weight: 500; }
.btn.tiny { padding: 6px 10px; font-size: 12px; border-radius: 8px; background: var(--surface-sunk); }

.notice {
  margin: 0; padding: 11px 13px; border-radius: 10px;
  background: var(--surface-sunk); color: var(--text-secondary); font-size: 14px;
}
.notice.error { background: #fdecec; color: #a3251f; }

.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- app chrome ---------------------------------------------------------- */

.household-btn {
  flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0;
  padding: 0; border: 0; background: none; color: var(--text-primary);
  font: inherit; font-size: 22px; font-weight: 700; letter-spacing: -.02em;
  cursor: pointer; text-align: left;
}
.household-btn #household-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caret { font-size: 13px; color: var(--text-muted); flex: none; }

.icon-btn {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 9px;
  background: var(--surface-sunk); color: var(--text-secondary);
  font-size: 16px; line-height: 1; cursor: pointer;
}

/* --- sheets -------------------------------------------------------------- */

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: 80dvh; overflow-y: auto;
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0; background: var(--bg);
  display: grid; gap: 12px;
}
.sheet h2 { margin: 0; font-size: 18px; }
.sheet-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.sheet-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 13px 14px; border: 0; border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow);
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.sheet-row.current { outline: 2px solid var(--accent); }

.member-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow);
}
.role-tag {
  padding: 3px 8px; border-radius: 20px; background: var(--surface-sunk);
  font-size: 11px; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .04em;
}

.invite-out { display: grid; gap: 8px; }
.invite-link {
  width: 100%; padding: 11px 12px; border: 0; border-radius: 10px;
  background: var(--surface-sunk); color: var(--text-secondary);
  font: inherit; font-size: 13px;
}

.tap:disabled { opacity: .45; cursor: default; }
.tap:disabled:active { transform: none; }

/* --- members button -------------------------------------------------------
   Replaces a small gear. Shows who is actually in the household and carries a
   visible "+", so "tap here to add someone" needs no explaining. */

.members-btn {
  display: flex; align-items: center; gap: 6px; flex: none;
  height: 44px; padding: 0 10px 0 8px;
  border: 0; border-radius: 22px;
  background: var(--surface); box-shadow: var(--shadow);
  cursor: pointer;
}
.members-btn:active { transform: scale(.96); }

.member-chips { display: flex; align-items: center; }
/* Overlap the avatars slightly so several people still fit in the bar. */
.member-chips .mini {
  width: 28px; height: 28px; margin-left: -8px;
  display: grid; place-items: center;
  border: 2px solid var(--surface); border-radius: 50%;
  font-size: 11px; font-weight: 700; color: #fff; letter-spacing: .01em;
}
.member-chips .mini:first-child { margin-left: 0; }
.member-chips .mini.more { background: var(--surface-sunk); color: var(--text-secondary); }
.member-chips .empty-people { font-size: 19px; line-height: 1; padding: 0 2px; }

.add-person {
  display: grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 17px; font-weight: 600; line-height: 1;
}

.rule { width: 100%; height: 1px; margin: 6px 0; border: 0; background: var(--border); }
