/* Household Chores -- mobile first. Desktop is the same layout, wider.
 *
 * The whole visual job is: make the top of the list readable at arm's length
 * and put a thumb-sized Done button next to every row. Nothing else earns
 * vertical space, because vertical space is how many chores you can see at
 * once, and that is the entire point of the screen. */

:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --line: #e7e0d5;
  --text: #1c1a17;
  --muted: #6b635a;

  --accent: #2f6f5e;
  --accent-ink: #ffffff;

  --overdue: #b3402c;
  --due: #b07617;
  --soon: #2f6f5e;

  --radius: 12px;
  --row-pad: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14130f;
    --surface: #1e1c18;
    --line: #322e28;
    --text: #f1ede5;
    --muted: #a29a8e;

    --accent: #4f9b86;
    --accent-ink: #0d1512;

    --overdue: #e2745c;
    --due: #d7a044;
    --soon: #4f9b86;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

/* No `overflow-x: hidden` here, tempting as it is: it makes the root a scroll
 * container and silently breaks the sticky header. Nothing overflows anyway --
 * `min-width: 0` on .row-main and `overflow-wrap: anywhere` on the chore name
 * are what actually keep long names from pushing the Done button off-screen. */

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

.loading, .empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
}

/* --- header ---------------------------------------------------------------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(8px, env(safe-area-inset-top)) 16px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.bar-title {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.bar-back {
  flex: 0 0 auto;
  margin-left: -8px;
  padding: 0 8px;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

/* The title takes the slack so the actions stay pinned right. */
.bar-title { flex: 1 1 auto; min-width: 0; }

.bar-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.bar-action {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
}

.bar-user {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}

/* --- sections -------------------------------------------------------------- */

.list {
  max-width: 640px;
  margin: 0 auto;
  padding: 4px 12px 32px;
}

.section { margin-top: 18px; }

.section-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 4px 8px;
  cursor: default;
}

details.section > summary.section-head {
  cursor: pointer;
  list-style: none;
}
details.section > summary.section-head::-webkit-details-marker { display: none; }
details.section > summary.section-head::after {
  content: "›";
  color: var(--muted);
  transform: rotate(90deg);
}
details.section[open] > summary.section-head::after { transform: rotate(-90deg); }

.section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-count {
  font-size: 12px;
  color: var(--muted);
  opacity: 0.7;
  margin-right: auto;
}

/* --- rows ------------------------------------------------------------------ */

.rows {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: var(--row-pad);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: var(--radius);
}

.row-overdue { border-left-color: var(--overdue); }
.row-due     { border-left-color: var(--due); }
.row-soon    { border-left-color: var(--soon); }
.row-never   { border-left-color: var(--overdue); }

/* min-width:0 is what keeps a long chore name from pushing the Done button
   off a 320px screen instead of wrapping. */
.row-main {
  flex: 1 1 auto;
  min-width: 0;
}

.row-name {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

/* On the home screen the name is a <button> into the chore's history. It has to
   look exactly like the text it replaced -- the affordance is the whole row. */
button.row-name {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.row-when {
  margin-top: 2px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}

.row-last {
  font-size: 12.5px;
  color: var(--muted);
}

.row-overdue .row-when, .row-never .row-when { color: var(--overdue); }
.row-due .row-when { color: var(--due); }

.chip {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  font-size: 11.5px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.row-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* --- buttons --------------------------------------------------------------- */

.btn {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:disabled { opacity: 0.5; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.btn-done {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  min-width: 76px;
  min-height: 44px;               /* thumb target */
  -webkit-touch-callout: none;    /* long-press must not raise iOS's own menu */
  -webkit-user-select: none;
  user-select: none;
}

.btn-more {
  min-width: 34px;
  min-height: 44px;
  padding: 0;
  color: var(--muted);
  line-height: 1;
}

/* The row is about to be re-sorted into another section; a brief flash is the
   whole "it moved" animation. Anything longer gets in the way. */
@keyframes flash {
  from { background: color-mix(in srgb, var(--accent) 22%, var(--surface)); }
  to   { background: var(--surface); }
}
.row.flash { animation: flash 700ms ease-out; }

@media (prefers-reduced-motion: reduce) {
  .row.flash { animation: none; }
}

/* --- login ----------------------------------------------------------------- */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-form {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-title { margin: 0; font-size: 30px; letter-spacing: -0.02em; }
.login-sub { margin: 0 0 10px; color: var(--muted); }
.login-error { margin: 0; color: var(--overdue); font-size: 14px; min-height: 1.2em; }

.login-form input {
  font: inherit;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}

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

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

@media (min-width: 560px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 16px; }
}

.sheet-title { margin: 0; font-size: 18px; }

.field { display: flex; flex-direction: column; gap: 4px; }

.field-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.field input, .field select {
  font: inherit;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}

.sheet-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.sheet-actions .btn { flex: 1; min-height: 46px; }

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

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 30;
  max-width: min(92vw, 420px);
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--overdue);
  color: var(--surface);
  font-size: 14px;
}

/* --- chore detail ---------------------------------------------------------- */

.detail {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 12px 32px;
}

.card {
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.detail-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.detail-name {
  margin: 0;
  font-size: 19px;
  font-weight: 650;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.detail-due {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 650;
  color: var(--muted);
}

.detail-due-overdue, .detail-due-never { color: var(--overdue); }
.detail-due-due { color: var(--due); }

.detail-meta {
  margin-top: 3px;
  font-size: 13px;
  color: var(--muted);
}

.detail-notes {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

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

.detail-actions .btn { flex: 1 1 auto; }

/* --- history --------------------------------------------------------------- */

.history-row { border-left-color: var(--line); }

/* A voided row stays legible -- it is still a record of what someone believed
   at the time -- but it must never be mistaken for a live completion. */
.history-row.voided .row-name,
.history-row.voided .row-when {
  text-decoration: line-through;
  color: var(--muted);
}

.history-row.voided { opacity: 0.72; }

.row-muted { opacity: 0.75; }

.tag {
  display: inline-block;
  padding: 1px 7px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--bg);
  vertical-align: 2px;
}

.tag-voided { color: var(--overdue); border-color: var(--overdue); }

.btn-void {
  padding: 7px 11px;
  font-size: 13px;
  color: var(--muted);
}

/* --- activity feed --------------------------------------------------------- */

/* The feed's date headings carry a "today"/"yesterday" label in the slot the
   home screen uses for a count, so it must not look like a number. */
.list .section-count { font-variant-numeric: tabular-nums; }

.row-name-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.row-name-line button.row-name { width: auto; }

button.row-name[disabled] {
  color: var(--muted);
  cursor: default;
}

/* --- chore form ------------------------------------------------------------ */

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* A checkbox is the one field whose label belongs beside the control, not
   above it, so it opts out of the column layout the other fields use. */
.field-check {
  flex-direction: row;
  align-items: center;
  gap: 9px;
}

.field-check input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

.field-label-inline {
  text-transform: none;
  letter-spacing: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.form .sheet-actions { margin-top: 2px; }
