/* ===========================================================================
   Household — one stylesheet, mobile first.
   Designed against 375 / 390 / 430px, widened for desktop at 720px and 1040px.
   =========================================================================== */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e6e8ec;
  --border-strong: #d4d8de;

  --text: #16181d;
  --text-2: #5c6370;
  --text-3: #8b919c;

  --accent: #4f46e5;
  --accent-soft: #eef2ff;

  --neil: #2563eb;
  --neil-soft: #eff5ff;
  --craig: #0d9488;
  --craig-soft: #effbf9;
  --shared: #7c3aed;
  --shared-soft: #f5f1ff;

  --overdue: #dc2626;
  --overdue-soft: #fef2f2;
  --today: #b45309;
  --today-soft: #fffbeb;
  --done: #15803d;
  --done-soft: #f0fdf4;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 4px 12px rgba(16, 24, 40, .08);

  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --surface: #17191e;
    --surface-2: #1c1f25;
    --border: #262a31;
    --border-strong: #343943;

    --text: #f0f2f5;
    --text-2: #a2a9b5;
    --text-3: #767d89;

    --accent: #818cf8;
    --accent-soft: #1e1b40;

    --neil: #60a5fa;
    --neil-soft: #16233a;
    --craig: #2dd4bf;
    --craig-soft: #102f2c;
    --shared: #a78bfa;
    --shared-soft: #241c3d;

    --overdue: #f87171;
    --overdue-soft: #2c1517;
    --today: #fbbf24;
    --today-soft: #2b2110;
    --done: #4ade80;
    --done-soft: #0f2618;

    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* --- Layout ---------------------------------------------------------------- */

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px calc(var(--nav-h) + var(--safe-b) + 24px);
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0 12px;
  background: linear-gradient(var(--bg) 78%, transparent);
  backdrop-filter: blur(6px);
}

.topbar h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.topbar .sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-2);
}

section { margin-bottom: 26px; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 0 2px 10px;
}

.section-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-3);
}

.section-head .count { font-size: 13px; color: var(--text-3); }

/* --- Cards ----------------------------------------------------------------- */

.stack { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.task-card {
  display: flex;
  align-items: stretch;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: opacity .18s ease, transform .18s ease;
}

.task-card.is-completing { opacity: .45; transform: scale(.985); }
.task-card.is-overdue { border-color: color-mix(in srgb, var(--overdue) 35%, var(--border)); }

.task-card .accent {
  width: 4px;
  flex: 0 0 4px;
  background: var(--border-strong);
}
.task-card.owner-neil .accent { background: var(--neil); }
.task-card.owner-craig .accent { background: var(--craig); }
.task-card.owner-shared .accent { background: var(--shared); }
.task-card.is-overdue .accent { background: var(--overdue); }

.task-main {
  flex: 1 1 auto;
  min-width: 0;
  padding: 12px 4px 12px 13px;
  text-align: left;
  background: none;
  border: 0;
  cursor: pointer;
}

.task-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -.01em;
  overflow-wrap: anywhere;
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-top: 5px;
  font-size: 13px;
  color: var(--text-2);
}

.task-meta .dot { color: var(--text-3); }

.complete-btn {
  flex: 0 0 auto;
  align-self: center;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin: 6px 8px 6px 4px;
  border: 1.5px solid var(--border-strong);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-3);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}

.complete-btn:active { transform: scale(.9); }
.complete-btn:hover { border-color: var(--done); color: var(--done); }
.complete-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.complete-btn[aria-busy="true"] { opacity: .5; pointer-events: none; }
.complete-btn svg { width: 24px; height: 24px; }

/* --- Chips / badges -------------------------------------------------------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}

.chip-neil { background: var(--neil-soft); color: var(--neil); }
.chip-craig { background: var(--craig-soft); color: var(--craig); }
.chip-shared { background: var(--shared-soft); color: var(--shared); }
.chip-overdue { background: var(--overdue-soft); color: var(--overdue); }
.chip-today { background: var(--today-soft); color: var(--today); }
.chip-done { background: var(--done-soft); color: var(--done); }
.chip-muted { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

.effort-dots { display: inline-flex; gap: 2px; vertical-align: middle; }
.effort-dots i {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--border-strong); display: block;
}
.effort-dots i.on { background: var(--text-3); }

/* --- Person group headers -------------------------------------------------- */

.person-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 2px 8px;
}

.person-head .avatar {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 50%;
  font-size: 12px; font-weight: 700;
  color: #fff;
}
.avatar.neil { background: var(--neil); }
.avatar.craig { background: var(--craig); }
.avatar.shared { background: var(--shared); }

.person-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.person-head .tot { margin-left: auto; font-size: 13px; color: var(--text-3); }

/* --- Expanded task detail -------------------------------------------------- */

.task-detail {
  padding: 0 14px 14px 17px;
  border-top: 1px solid var(--border);
  margin-top: -1px;
}
.task-detail p { margin: 12px 0 8px; font-size: 14px; color: var(--text-2); }

.checklist { list-style: none; margin: 6px 0 0; padding: 0; }
.checklist li {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 7px 0; font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.checklist li:last-child { border-bottom: 0; }
.checklist input { width: 19px; height: 19px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.checklist input:checked + span { color: var(--text-3); text-decoration: line-through; }

.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* --- Buttons --------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn-danger { color: var(--overdue); border-color: color-mix(in srgb, var(--overdue) 40%, var(--border)); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn:disabled { opacity: .5; pointer-events: none; }

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  z-index: 30;
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 28px; line-height: 1;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
}

/* --- Bottom navigation ----------------------------------------------------- */

.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  display: flex;
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}

.nav a {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: var(--nav-h);
  text-decoration: none;
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .01em;
  -webkit-tap-highlight-color: transparent;
}
.nav a svg { width: 22px; height: 22px; }
.nav a[aria-current="page"] { color: var(--accent); }

/* --- Forms ----------------------------------------------------------------- */

.field { margin-bottom: 14px; }
.field label {
  display: block;
  margin-bottom: 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.input, .select, .textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px; /* 16px stops iOS zooming on focus */
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 0;
}
.switch-row input { width: 22px; height: 22px; accent-color: var(--accent); }

.month-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.month-grid label {
  display: grid; place-items: center;
  padding: 8px 0; margin: 0;
  border: 1px solid var(--border-strong); border-radius: 9px;
  font-size: 12px; font-weight: 600; cursor: pointer;
}
.month-grid input { position: absolute; opacity: 0; pointer-events: none; }
.month-grid input:checked + span { color: var(--accent); }
.month-grid label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

/* --- Filters --------------------------------------------------------------- */

.filters {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 2px 0 8px;
  margin: 0 -16px 4px;
  padding-inline: 16px;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }

.filter-chip {
  flex: 0 0 auto;
  padding: 7px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
  cursor: pointer;
}
.filter-chip[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

.search-wrap { position: relative; margin-bottom: 10px; }
.search-wrap .input { padding-left: 38px; }
.search-wrap svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--text-3); pointer-events: none;
}

/* --- Balance --------------------------------------------------------------- */

.balance-bar {
  display: flex;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.balance-bar span { display: block; transition: width .3s ease; }
.balance-bar .seg-neil { background: var(--neil); }
.balance-bar .seg-craig { background: var(--craig); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.stat {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.stat .who { display: flex; align-items: center; gap: 7px; margin-bottom: 8px; font-weight: 700; font-size: 14px; }
.stat .big { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.stat .big small { font-size: 14px; font-weight: 600; color: var(--text-3); margin-left: 2px; }
.stat .rows { margin-top: 8px; font-size: 13px; color: var(--text-2); }
.stat .rows div { display: flex; justify-content: space-between; padding: 2px 0; }

.diff-line {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; margin-top: 10px;
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  font-size: 14px;
}
.diff-line strong { font-size: 16px; }

/* --- Calendar -------------------------------------------------------------- */

.cal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 12px;
}
.cal-head .title { font-size: 17px; font-weight: 700; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow {
  text-align: center; font-size: 11px; font-weight: 700;
  color: var(--text-3); padding-bottom: 4px;
}
.cal-cell {
  position: relative;
  aspect-ratio: 1 / 1.15;
  padding: 4px 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 12px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.cal-cell.other-month { opacity: .38; }
.cal-cell.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cal-cell[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.cal-cell .n { font-weight: 600; }
.cal-cell .pips { display: flex; flex-wrap: wrap; gap: 2px; justify-content: center; }
.cal-cell .pips i { width: 5px; height: 5px; border-radius: 50%; display: block; }
.pip-neil { background: var(--neil); }
.pip-craig { background: var(--craig); }
.pip-shared { background: var(--shared); }
.pip-overdue { background: var(--overdue); }

.day-list { margin-top: 16px; }
.day-heading {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 18px 2px 8px; font-size: 14px; font-weight: 700;
}
.day-heading .m { font-weight: 500; font-size: 13px; color: var(--text-3); }

/* --- History --------------------------------------------------------------- */

.history-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
}
.history-row:last-child { border-bottom: 0; }
.history-row .body { flex: 1 1 auto; min-width: 0; }
.history-row .name { font-weight: 600; font-size: 15px; }
.history-row .sub { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }

/* --- Sheets / dialogs ------------------------------------------------------ */

dialog.sheet {
  width: 100%;
  max-width: 640px;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  max-height: 92dvh;
}
dialog.sheet::backdrop { background: rgba(8, 10, 14, .45); backdrop-filter: blur(2px); }

.sheet-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 16px 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.sheet-head h2 { margin: 0; font-size: 18px; font-weight: 700; }
.sheet-body { padding: 16px; overflow-y: auto; }
.sheet-foot {
  position: sticky; bottom: 0;
  display: flex; gap: 10px;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.sheet-foot .btn { flex: 1; }

@media (min-width: 720px) {
  dialog.sheet { margin: auto; border-radius: 20px; max-height: 86vh; }
}

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

.toasts {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(var(--nav-h) + var(--safe-b) + 12px);
  z-index: 60;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 12px;
  max-width: 640px; margin: 0 auto; width: 100%;
  padding: 12px 14px;
  border-radius: 13px;
  background: #1f2228;
  color: #fff;
  font-size: 14.5px;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in .2s ease;
}
.toast .msg { flex: 1 1 auto; }
.toast button {
  border: 0; background: none; color: #a5b4fc;
  font-weight: 700; font-size: 14.5px; cursor: pointer; padding: 4px 2px;
}
.toast.error { background: #7f1d1d; }
.toast.error button { color: #fecaca; }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

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

.empty {
  padding: 34px 20px;
  text-align: center;
  color: var(--text-2);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.empty .big { font-size: 30px; margin-bottom: 6px; }
.empty p { margin: 0; font-size: 14.5px; }

.skeleton {
  height: 76px;
  border-radius: var(--radius);
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.3s infinite linear;
}
@keyframes shimmer { to { background-position: -220% 0; } }

.banner {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 13px; margin-bottom: 14px;
  border-radius: 12px;
  font-size: 14px;
}
.banner.warn { background: var(--today-soft); color: var(--today); }
.banner.error { background: var(--overdue-soft); color: var(--overdue); }
.banner button { margin-left: auto; }

.muted { color: var(--text-3); }
.hidden { display: none !important; }
.sr-only {
  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: 100dvh;
  display: flex; flex-direction: column; justify-content: center;
  max-width: 380px; margin: 0 auto; padding: 24px;
}
.login-wrap h1 { font-size: 30px; margin: 0 0 4px; letter-spacing: -.02em; }
.login-wrap .lead { color: var(--text-2); margin: 0 0 26px; }

.who-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.who-picker button {
  padding: 16px 10px;
  border: 1.5px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface);
  font-weight: 700;
  cursor: pointer;
}
.who-picker button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.pin-input {
  width: 100%; text-align: center;
  font-size: 26px; letter-spacing: .4em; font-weight: 700;
  padding: 14px 12px;
  border: 1.5px solid var(--border-strong); border-radius: 14px;
  background: var(--surface);
}

/* --- Desktop --------------------------------------------------------------- */

@media (min-width: 900px) {
  .app { max-width: 880px; padding-bottom: 40px; padding-top: 8px; }
  .nav {
    position: sticky; top: 0; bottom: auto;
    max-width: 880px; margin: 0 auto 8px;
    border-top: 0; border-bottom: 1px solid var(--border);
    border-radius: 0 0 14px 14px;
  }
  .nav a { flex-direction: row; gap: 8px; height: 54px; font-size: 14px; }
  .fab { bottom: 28px; right: 28px; }
  .toasts { bottom: 24px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
