/* WeShareKids — warm, light, calm.
 *
 * Mobile-first. Sized for thumbs and for readers who are not hunting for tiny
 * grey text: 16px base, 44px minimum tap target, AA contrast in both themes.
 *
 * The palette is built on warm paper rather than cool grey, with sage as the
 * one action colour and clay reserved for homes and for anything that needs a
 * decision. Nothing shouts.
 */

:root {
  --paper: #faf6f0;
  --surface: #fffcf8;
  --surface-2: #f2ebe1;
  --line: #e6dccf;
  --line-strong: #cdbeaa;
  --text: #2e2823;
  --text-soft: #5b5047;
  --text-faint: #7f7264;

  --accent: #4a7a62;          /* sage — every primary action */
  --accent-soft: #e2ede6;
  --accent-ink: #fffcf8;

  --clay: #b25f47;            /* warm second voice */
  --clay-soft: #f7e6df;

  --danger: #a04a37;
  --danger-soft: #f8e3dd;
  --warn: #8a6716;
  --warn-soft: #f8edd6;
  --ok: #3f7355;
  --ok-soft: #e0eee5;

  --shadow: 0 1px 2px rgba(74, 56, 38, 0.05), 0 10px 26px rgba(74, 56, 38, 0.07);
  --shadow-soft: 0 1px 2px rgba(74, 56, 38, 0.04);

  --radius: 18px;
  --radius-sm: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Warm charcoal, not cold slate — the calm should survive the lights going out. */
    --paper: #1b1714;
    --surface: #262019;
    --surface-2: #322a22;
    --line: #40372d;
    --line-strong: #5b4f41;
    --text: #f2eae0;
    --text-soft: #ccc0b1;
    --text-faint: #a49582;

    --accent: #8dc0a2;
    --accent-soft: #26372e;
    --accent-ink: #16241c;

    --clay: #e0947c;
    --clay-soft: #3a2620;

    --danger: #e79f8b;
    --danger-soft: #3b241d;
    --warn: #e0be72;
    --warn-soft: #3a2f14;
    --ok: #8dc9a4;
    --ok-soft: #22362a;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 12px 30px rgba(0, 0, 0, 0.3);
    --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

/* `hidden` must beat the display values set further down (grid, flex). */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.24; margin: 0; letter-spacing: -0.005em; }
h1, h2 { font-family: var(--serif); font-weight: 600; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.18rem; }
h3 { font-size: 0.95rem; font-weight: 650; }
p { margin: 0 0 0.75rem; }
a { color: var(--accent); }

.boot { padding: 4rem 1.5rem; text-align: center; color: var(--text-faint); }

:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}

/* ------------------------------------------------------------- layout --- */

.shell { min-height: 100dvh; display: flex; flex-direction: column; }

.appbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.7rem 0.95rem;
  padding-top: calc(0.7rem + env(safe-area-inset-top, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.appbar .title { flex: 1; min-width: 0; }
.appbar .title h1 { font-size: 1.08rem; }
.appbar .title small { display: block; color: var(--text-faint); font-size: 0.78rem; }

.main {
  flex: 1;
  padding: 0.95rem 0.95rem calc(5.5rem + var(--safe-bottom));
  max-width: 1100px; width: 100%; margin: 0 auto;
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 0.55rem 0.15rem 0.5rem;
  font-size: 0.68rem; font-weight: 600;
  color: var(--text-faint); text-decoration: none;
  min-height: 52px; position: relative;
}
.tabbar a[aria-current='page'] { color: var(--accent); }
.tabbar svg { width: 22px; height: 22px; }
.appbar .pip {
  position: absolute; top: 2px; right: 2px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--clay); color: #fffcf8;
  font-size: 0.6rem; line-height: 16px; text-align: center; font-weight: 700;
}
.tabbar .pip {
  position: absolute; top: 5px; right: calc(50% - 20px);
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--clay); color: #fffcf8;
  font-size: 0.62rem; line-height: 17px; text-align: center; font-weight: 700;
}
@media (prefers-color-scheme: dark) { .tabbar .pip { color: #2a1710; } }

/* -------------------------------------------------------------- pieces --- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.05rem;
  margin-bottom: 0.85rem;
  box-shadow: var(--shadow-soft);
}
.card > h2 { margin-bottom: 0.15rem; }
.card > .hint { color: var(--text-faint); font-size: 0.85rem; margin-bottom: 0.75rem; }

.row { display: flex; align-items: center; gap: 0.6rem; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 0.6rem; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--text-faint); }
.small { font-size: 0.85rem; }
.tiny { font-size: 0.76rem; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.center { text-align: center; }
.mt { margin-top: 0.85rem; }
.num { font-variant-numeric: tabular-nums; }

button, .btn {
  appearance: none; cursor: pointer;
  font: inherit; font-weight: 600;
  min-height: 44px; padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  text-decoration: none;
  transition: background-color 120ms ease, border-color 120ms ease;
}
button svg, .btn svg { width: 20px; height: 20px; flex: none; }
button:hover, .btn:hover { border-color: var(--text-faint); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.07); border-color: var(--accent); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--text-soft); }
.btn-quiet:hover { background: var(--surface-2); border-color: transparent; }
.btn-sm { min-height: 36px; padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.btn-block { width: 100%; }

label { display: block; font-weight: 600; font-size: 0.88rem; margin-bottom: 0.3rem; }
input, select, textarea {
  font: inherit; width: 100%; min-width: 0;
  min-height: 46px; padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 84px; resize: vertical; }
.field { margin-bottom: 0.9rem; }
.field .help { font-size: 0.8rem; color: var(--text-faint); margin-top: 0.28rem; }
/* Stacked on a phone — a datetime input in a 175px column is unusable. */
.field-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.6rem; }
.field-row > * { min-width: 0; }
@media (min-width: 520px) {
  .field-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.check { display: flex; align-items: center; gap: 0.6rem; font-weight: 500; }
.check input { width: 22px; height: 22px; min-height: 0; flex: none; }

.chip {
  display: inline-flex; align-items: center; gap: 0.38rem;
  padding: 0.2rem 0.6rem; border-radius: 999px;
  font-size: 0.76rem; font-weight: 600;
  background: var(--surface-2); color: var(--text-soft);
  border: 1px solid var(--line);
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
label.chip { border-radius: var(--radius-sm); padding: 0.35rem 0.65rem; font-size: 0.85rem; }
.chip input[type='checkbox'] { width: 18px; height: 18px; min-height: 0; flex: none; margin: 0; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.chip.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.banner {
  border-radius: var(--radius-sm); padding: 0.7rem 0.9rem;
  font-size: 0.9rem; margin-bottom: 0.8rem;
  border: 1px solid transparent;
}
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner.info { background: var(--accent-soft); color: var(--accent); }

.empty { text-align: center; padding: 2.2rem 1rem; color: var(--text-faint); }
.empty strong { display: block; font-family: var(--serif); font-size: 1.05rem; color: var(--text-soft); margin-bottom: 0.3rem; }

/* ------------------------------------------------------------ calendar --- */

.calbar { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.7rem; }
.calbar .period { flex: 1; font-family: var(--serif); font-weight: 600; font-size: 1.1rem; }
.seg {
  display: inline-flex; background: var(--surface-2);
  border-radius: 999px; padding: 3px; gap: 2px;
  border: 1px solid var(--line);
}
.seg button {
  min-height: 34px; padding: 0.2rem 0.75rem; font-size: 0.82rem;
  border: none; background: transparent; border-radius: 999px; color: var(--text-soft);
}
.seg button[aria-pressed='true'] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-soft); }

.legend { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.75rem; }
.legend button {
  min-height: 32px; padding: 0.2rem 0.65rem; font-size: 0.78rem; font-weight: 600;
  border-radius: 999px; gap: 0.35rem;
}
.legend button[aria-pressed='false'] { opacity: 0.42; }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; }

.month { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.month .dow {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.month .dow span {
  padding: 0.42rem 0.2rem; text-align: center;
  font-size: 0.68rem; font-weight: 700; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.05em;
}
.month .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.day {
  /* min-width:0 matters: grid items size to their content by default, and a
     nowrap event pill would otherwise force the column wider than 1/7th. */
  position: relative; min-width: 0; overflow: hidden;
  min-height: 74px; padding: 3px 3px 4px;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  background: var(--surface); text-align: left; align-items: stretch;
  border-radius: 0; font-weight: 400; justify-content: flex-start;
  flex-direction: column; gap: 2px;
}
.day:nth-child(7n) { border-right: none; }
.day.outside { background: var(--surface-2); }
.day.outside .num { color: var(--text-faint); }
.day .custody-band { height: 4px; border-radius: 2px; margin-bottom: 2px; }
.day .custody-band.split { background: repeating-linear-gradient(90deg, var(--line-strong) 0 5px, transparent 5px 10px); }
.day .num { font-size: 0.8rem; font-weight: 650; color: var(--text-soft); padding: 0 2px; }
.day.today .num {
  background: var(--accent); color: var(--accent-ink); border-radius: 999px;
  width: 22px; height: 22px; display: grid; place-items: center; font-size: 0.75rem;
}
.day .pill {
  max-width: 100%;
  font-size: 0.66rem; line-height: 1.25; font-weight: 600;
  padding: 1px 4px; border-radius: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-left: 3px solid var(--cal, var(--line-strong));
  background: color-mix(in srgb, var(--cal, var(--line-strong)) 18%, transparent);
  color: var(--text);
}
.day .pill.pending { opacity: 0.72; font-style: italic; }
.day .more { font-size: 0.62rem; color: var(--text-faint); padding-left: 4px; }
.day .pills { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

/* Phone month view: titles are unreadable in a 55px column, so each event
   becomes a dot in its calendar's colour. Detail lives in the day sheet,
   which is one tap away, and in the week and list views. */
@media (max-width: 700px) {
  .day .pills { flex-direction: row; flex-wrap: wrap; gap: 3px; align-content: flex-start; padding: 2px; }
  .day .pill {
    width: 8px; height: 8px; padding: 0; border-radius: 50%;
    border-left: none; font-size: 0; line-height: 0;
    background: var(--cal, var(--line-strong));
  }
  .day .pill.pending { opacity: 1; box-shadow: inset 0 0 0 2px var(--surface); outline: 1.5px dashed var(--cal); outline-offset: 1px; }
  .day .more { font-size: 0.58rem; padding: 0; align-self: center; }
}
.day.selected { box-shadow: inset 0 0 0 2px var(--accent); }

/* week + agenda */
.daylist { display: flex; flex-direction: column; gap: 0.6rem; }
.dayblock { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.dayblock > header {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.8rem; background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.dayblock > header .date { font-weight: 700; font-size: 0.9rem; }
.dayblock > header.is-today .date { color: var(--accent); }
.dayblock .events { display: flex; flex-direction: column; }
.eventrow {
  display: flex; gap: 0.65rem; align-items: flex-start;
  padding: 0.6rem 0.8rem; border-top: 1px solid var(--line);
  width: 100%; text-align: left; background: transparent; border-radius: 0;
  min-height: 48px; font-weight: 400;
}
.eventrow:first-child { border-top: none; }
.eventrow .bar { width: 4px; align-self: stretch; border-radius: 2px; flex: none; min-height: 30px; }
.eventrow .when { font-size: 0.76rem; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.eventrow .what { font-weight: 600; font-size: 0.92rem; }
.eventrow .meta { font-size: 0.76rem; color: var(--text-faint); }
.eventrow .tags { display: flex; gap: 0.25rem; flex-wrap: wrap; margin-top: 0.2rem; }

.custody-note {
  display: flex; align-items: center; gap: 0.45rem;
  font-size: 0.78rem; font-weight: 600; color: var(--text-soft);
}
.custody-note .dot { width: 10px; height: 10px; border-radius: 50%; }

/* --------------------------------------------------------------- money --- */

/* A row per home on a phone — with three or four homes, stacked cards push the
   list of costs off the screen entirely. */
.balance {
  display: flex; align-items: baseline; gap: 0.6rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border-left: 4px solid var(--home, var(--line-strong));
}
.balance .who { font-weight: 650; font-size: 0.92rem; flex: 1; min-width: 0; }
.balance .amount { font-family: var(--serif); font-size: 1.22rem; font-variant-numeric: tabular-nums; line-height: 1.2; }
.balance .state { font-size: 0.76rem; color: var(--text-faint); width: 4.6rem; text-align: right; }
.balance.owed .amount { color: var(--ok); }
.balance.owes .amount { color: var(--clay); }
.balances { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.4rem; }
@media (min-width: 720px) { .balances { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); } }

.settle-line {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.6rem 0.75rem; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--accent);
  font-size: 0.9rem; font-weight: 600;
}

.expense {
  display: flex; gap: 0.7rem; align-items: flex-start;
  padding: 0.75rem 0.85rem; border-top: 1px solid var(--line);
  width: 100%; text-align: left; background: transparent; border-radius: 0;
  font-weight: 400; min-height: 56px;
}
.expense:first-child { border-top: none; }
.expense .amt { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.expense .bar { width: 4px; align-self: stretch; border-radius: 2px; flex: none; min-height: 34px; }

/* --------------------------------------------------------------- sheet --- */

/* The whole overlay scrolls, not just the panel. If only the panel scrolled,
   a wheel or trackpad gesture with the pointer beside it — most of a desktop
   screen — would do nothing at all, and a tall form could only be reached by
   tabbing through it. `align-items: flex-start` with `margin-top: auto` keeps
   the panel pinned to the bottom when it fits, without the flexbox bug that
   clips the top of an item taller than its container. */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(46, 34, 24, 0.42);
  display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 560px;
  border-radius: 24px 24px 0 0;
  margin-top: auto;
  padding: 0.5rem 1.05rem calc(1.5rem + var(--safe-bottom));
  box-shadow: var(--shadow);
}
.sheet .handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 0.5rem auto 0.8rem; }
.sheet header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.9rem; }
.sheet header h2 { flex: 1; }
.sheet .actions { display: flex; gap: 0.5rem; margin-top: 1.15rem; }
.sheet .actions button { flex: 1; }
@media (min-width: 700px) {
  /* Auto margins on both sides centre it when it fits and fall back to a plain
     scroll when it does not. */
  .sheet-backdrop { padding: 1.5rem 1rem; }
  .sheet { border-radius: 24px; margin-top: auto; margin-bottom: auto; }
}

/* --------------------------------------------------------------- toast --- */

#toast-root {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(5.4rem + var(--safe-bottom)); z-index: 80;
  display: flex; flex-direction: column; gap: 0.4rem; width: min(92vw, 460px);
}
.toast {
  padding: 0.65rem 0.95rem; border-radius: var(--radius-sm);
  background: var(--text); color: var(--paper);
  font-size: 0.88rem; font-weight: 550; box-shadow: var(--shadow);
}
.toast.error { background: var(--danger); color: #fffcf8; }
@media (prefers-color-scheme: dark) { .toast.error { color: #2a1710; } }

/* --------------------------------------------------------------- lists --- */

.list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.list > * { border-top: 1px solid var(--line); }
.list > *:first-child { border-top: none; }
.listitem {
  display: flex; gap: 0.7rem; align-items: center;
  padding: 0.7rem 0.85rem; width: 100%; text-align: left;
  background: transparent; border-radius: 0; min-height: 56px; font-weight: 400;
}
.listitem .avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: #fffcf8; font-weight: 700; font-size: 0.8rem;
}
.listitem.unread { background: var(--accent-soft); }

.matrix { width: 100%; overflow-x: auto; }
.matrix table { border-collapse: collapse; min-width: 100%; font-size: 0.85rem; }
.matrix th, .matrix td { padding: 0.4rem 0.5rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.matrix th { font-size: 0.72rem; color: var(--text-faint); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.matrix td select { min-height: 38px; padding: 0.2rem 0.4rem; font-size: 0.82rem; }
.matrix .calname { font-weight: 650; position: sticky; left: 0; background: var(--surface); }

.steps { counter-reset: step; padding-left: 0; list-style: none; margin: 0.5rem 0 0; }
.steps li {
  counter-increment: step; position: relative;
  padding: 0 0 0.9rem 2.2rem; font-size: 0.9rem;
}
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: 0;
  width: 25px; height: 25px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: 0.78rem; font-weight: 700;
}
code.url {
  display: block; word-break: break-all; font-size: 0.78rem;
  background: var(--surface-2); padding: 0.55rem 0.65rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line); font-family: var(--mono);
}

/* --------------------------------------------------------------- auth --- */

.auth { max-width: 400px; margin: 0 auto; padding: 2.4rem 1.15rem 3rem; }
.auth .brand { text-align: center; margin-bottom: 1.7rem; }
.auth .brand img { width: 62px; height: 62px; }
.auth .brand h1 { margin-top: 0.7rem; font-size: 1.65rem; }
.auth .demo { margin-top: 1.3rem; font-size: 0.82rem; color: var(--text-faint); }
.auth .demo button { font-size: 0.8rem; min-height: 34px; }

/* ---------------------------------------------------------- rotation --- */

.rot-strip { display: grid; gap: 3px; margin-top: 0.4rem; }
.rot-strip span {
  height: 26px; border-radius: 5px;
  display: grid; place-items: center;
  font-size: 0.6rem; font-weight: 700; color: #fffcf8;
  background: var(--slot, var(--line-strong));
  overflow: hidden;
}

@media (min-width: 760px) {
  .main { padding: 1.2rem 1.2rem calc(5.5rem + var(--safe-bottom)); }
  .day { min-height: 104px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
