/* Family To-Do — phone first, iOS-style look. */
:root {
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --text: #1C1C1E;
  --muted: #6C6C70;
  --faint: #AEAEB2;
  --line: #D8D8DC;
  --blue: #0A66D0;
  --red: #C62828;
  --star: #B86E00;
  --theme: #0A66D0;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body { margin: 0; font-family: var(--font); color: var(--text); background: var(--bg); -webkit-text-size-adjust: 100%; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--blue); text-decoration: none; }
svg { flex: none; }
.loading { padding: 40px 20px; color: var(--muted); text-align: center; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- screen frame ---------- */
.screen { min-height: 100vh; min-height: 100dvh; max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; background: var(--bg); }
.themed { background: var(--theme); }
html.is-themed, html.is-themed body { background: var(--theme); }
.bar { display: flex; align-items: center; gap: 4px; padding: calc(var(--top) + 8px) 8px 2px; min-height: 52px; position: sticky; top: 0; z-index: 5; background: inherit; }
.bar .spacer { flex: 1; }
.iconbtn { width: 44px; height: 44px; border: 0; background: transparent; color: var(--blue); display: inline-flex; align-items: center; justify-content: center; border-radius: 22px; padding: 0; }
.themed .iconbtn, .themed .back, .themed .members-btn { color: #FFFFFF; }
.back { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding: 0 6px; font-size: 17px; color: var(--blue); max-width: 70%; }
.back span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.members-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 8px; border: 0; background: transparent; font-size: 17px; }
.avatar-btn { width: 40px; height: 40px; margin-left: 6px; border-radius: 20px; border: 0; background: var(--blue); color: #FFFFFF; font-weight: 600; font-size: 15px; }
h1.large { margin: 2px 16px 6px; font-size: 34px; font-weight: 700; letter-spacing: -0.5px; line-height: 1.15; overflow-wrap: anywhere; }
.themed h1.large { color: #FFFFFF; }
.sortnote { margin: -2px 16px 6px; font-size: 13px; font-weight: 500; color: #FFFFFF; opacity: 0.92; }
.main { flex: 1; padding: 6px 16px 24px; display: flex; flex-direction: column; gap: 20px; }
.themed .main { padding: 8px 12px 24px; gap: 6px; }
.toolbar { position: sticky; bottom: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px calc(var(--bottom) + 8px); background: rgba(249,249,251,0.94); border-top: 0.5px solid var(--line); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); }
.toolbar .textbtn { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 8px; border: 0; background: transparent; color: var(--blue); font-size: 17px; font-weight: 600; }
.toolbar .meta { font-size: 13px; color: var(--muted); padding-left: 12px; }
.hint { margin: 0; padding: 0 4px; font-size: 13px; color: var(--muted); line-height: 1.4; }
.empty { margin: 24px 8px; text-align: center; color: #FFFFFF; font-size: 15px; opacity: 0.95; }

/* ---------- cards and rows ---------- */
.card { background: var(--card); border-radius: 12px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 12px 0 14px; color: var(--text); background: var(--card); width: 100%; border: 0; text-align: left; font-size: 17px; }
.row + .row .row-inner, .row + .row.divided { border-top: 0.5px solid var(--line); }
.row-inner { flex: 1; display: flex; align-items: center; gap: 8px; min-height: 52px; min-width: 0; }
.row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .value { color: var(--muted); }
.row .count { min-width: 28px; text-align: right; color: var(--muted); }
.row.danger { color: var(--red); }
.row.accent { color: var(--blue); }
.row.divided + .row.divided { border-top: 0.5px solid var(--line); }
.badge { width: 30px; height: 30px; border-radius: 8px; color: #FFFFFF; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.chev { color: var(--faint); }
/* An empty group (or the no-group area) only shows as a drop zone while a list is being dragged. */
.lists-card:empty { display: none; }
.group .lists-card:empty, .dragging .lists-card:empty { display: block; min-height: 52px; background: rgba(255,255,255,0.5); border: 1.5px dashed var(--line); }
.group .lists-card:empty::after, .dragging .lists-card:empty::after { content: "Drag a list here"; display: block; padding: 16px; color: var(--muted); font-size: 15px; text-align: center; }
.row, .task { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.group { display: flex; flex-direction: column; gap: 6px; }
.group-head { display: flex; align-items: center; gap: 2px; }
.group-toggle { flex: 1; display: flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 4px; border: 0; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: 0.4px; text-transform: uppercase; text-align: left; }
.group-toggle .n { font-weight: 500; text-transform: none; letter-spacing: 0; }
.group-toggle svg { transition: transform .2s; }
.group.collapsed .group-toggle svg { transform: rotate(-90deg); }
.group.collapsed .lists-card { display: none; }
.group-head .iconbtn { width: 36px; height: 36px; color: var(--muted); }
.sortable-ghost { opacity: 0.35; }
.sortable-chosen { box-shadow: 0 8px 24px rgba(0,0,0,0.22); }

/* ---------- tasks ---------- */
.tasks { display: flex; flex-direction: column; gap: 6px; }
.task { display: flex; align-items: flex-start; gap: 8px; padding: 10px 2px 10px 8px; background: var(--card); border-radius: 12px; box-shadow: 0 1px 2px rgba(0,0,0,0.12); }
.check { width: 36px; height: 32px; flex: none; border: 0; background: transparent; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.ring { width: 24px; height: 24px; border-radius: 12px; border: 2px solid #8E8E93; display: inline-flex; align-items: center; justify-content: center; color: #FFFFFF; }
.is-done .ring { background: var(--theme); border-color: var(--theme); }
.task .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; padding-top: 4px; cursor: pointer; }
.task .title { color: var(--text); font-size: 17px; line-height: 1.3; overflow-wrap: anywhere; }
.task.is-done .title { color: var(--muted); text-decoration: line-through; }
.meta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 13px; color: var(--muted); }
.meta-row > * { display: inline-flex; align-items: center; gap: 4px; }
.chip-link { color: #3B30A8; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.star { width: 44px; height: 32px; flex: none; border: 0; background: transparent; color: #8E8E93; display: inline-flex; align-items: center; justify-content: center; }
.star.on { color: var(--star); }
.star.on svg { fill: currentColor; }
.done-tag { padding: 2px 8px; margin: 6px 8px 0 0; border-radius: 6px; background: #E8F3EA; color: #1E6B2A; font-size: 12px; font-weight: 600; flex: none; }
.initials { width: 20px; height: 20px; border-radius: 10px; color: #FFFFFF; font-size: 9px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex: none; letter-spacing: 0; }
.initials.big { width: 34px; height: 34px; border-radius: 17px; font-size: 13px; }
.completed-toggle { align-self: flex-start; display: flex; align-items: center; gap: 6px; min-height: 36px; margin-top: 12px; padding: 0 12px; border: 0; border-radius: 8px; background: rgba(0,0,0,0.22); color: #FFFFFF; font-size: 15px; font-weight: 600; }
.completed-toggle svg { transition: transform .2s; }
.completed-toggle[aria-expanded="false"] svg { transform: rotate(-90deg); }
.addbar { position: sticky; bottom: 0; z-index: 5; padding: 8px 12px calc(var(--bottom) + 10px); background: var(--theme); }
.addbar label { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 16px; border-radius: 12px; background: rgba(0,0,0,0.22); color: #FFFFFF; }
.addbar input { flex: 1; min-width: 0; border: 0; background: transparent; color: #FFFFFF; font-size: 17px; outline: none; padding: 14px 0; }
.addbar input::placeholder { color: rgba(255,255,255,0.9); }

/* ---------- task details ---------- */
.title-card { display: flex; align-items: flex-start; gap: 6px; padding: 12px 4px 12px 8px; }
.title-input { flex: 1; border: 0; resize: none; background: transparent; font-size: 22px; font-weight: 600; line-height: 1.25; padding: 4px 0; outline: none; overflow: hidden; }
.section-label { margin: 0 0 6px; padding: 0 4px; font-size: 13px; font-weight: 600; letter-spacing: 0.4px; text-transform: uppercase; color: var(--muted); display: block; }
.sub { display: flex; align-items: center; gap: 4px; min-height: 50px; padding: 0 0 0 6px; background: var(--card); }
.sub + .sub, .add-sub { border-top: 0.5px solid var(--line); }
.sub .ring { width: 22px; height: 22px; }
.sub-input { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 17px; padding: 12px 0; outline: none; }
.sub.is-done .sub-input { color: var(--muted); text-decoration: line-through; }
.sub .iconbtn { color: var(--muted); }
.add-sub { display: flex; align-items: center; gap: 12px; min-height: 50px; padding: 0 14px; color: var(--blue); }
.add-sub input { flex: 1; border: 0; background: transparent; font-size: 17px; outline: none; padding: 12px 0; }
.add-sub input::placeholder { color: var(--blue); }
.notes { width: 100%; min-height: 120px; padding: 12px 14px; border: 0; border-radius: 12px; background: var(--card); font-size: 17px; line-height: 1.4; resize: vertical; outline: none; }
.links { margin-top: 8px; }
.links a { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 0 14px; font-size: 15px; overflow: hidden; }
.links a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.links a + a { border-top: 0.5px solid var(--line); }

/* ---------- search ---------- */
.search-field { display: flex; align-items: center; gap: 8px; margin: 4px 16px 8px; padding: 0 10px; border-radius: 10px; background: #E3E3E8; color: var(--muted); }
.search-field input { flex: 1; border: 0; background: transparent; padding: 9px 0; font-size: 17px; outline: none; color: var(--text); }
.result .dot { width: 10px; height: 10px; border-radius: 5px; flex: none; }
.result .two { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 8px 0; }
.result .two small { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result.is-done .two > span { text-decoration: line-through; color: var(--muted); }

/* ---------- sign-in screens ---------- */
.auth { max-width: 420px; margin: 0 auto; padding: calc(var(--top) + 48px) 20px 40px; display: flex; flex-direction: column; gap: 16px; }
.auth h1 { margin: 0; font-size: 30px; font-weight: 700; }
.auth p { margin: 0; color: var(--muted); line-height: 1.45; }
.field { display: flex; flex-direction: column; background: var(--card); border-radius: 12px; overflow: hidden; }
.field label { display: flex; flex-direction: column; padding: 8px 14px; font-size: 13px; color: var(--muted); }
.field label + label { border-top: 0.5px solid var(--line); }
.field input { border: 0; padding: 4px 0 2px; font-size: 17px; outline: none; background: transparent; color: var(--text); }
.primary { min-height: 50px; border: 0; border-radius: 12px; background: var(--blue); color: #FFFFFF; font-size: 17px; font-weight: 600; }
.primary:disabled { opacity: 0.6; }
.linkbtn { border: 0; background: transparent; color: var(--blue); font-size: 15px; min-height: 44px; }
.error { color: var(--red); font-size: 15px; min-height: 1em; }

/* ---------- sheets ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,0.42); display: flex; align-items: flex-end; justify-content: center; animation: fade .18s ease-out; }
.sheet { width: 100%; max-width: 640px; max-height: calc(100dvh - var(--top) - 40px); background: var(--bg); border-radius: 14px 14px 0 0; display: flex; flex-direction: column; animation: rise .22s ease-out; }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 8px 8px 6px; }
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 600; text-align: center; }
.sheet-head .done { justify-self: end; min-height: 44px; padding: 0 8px; border: 0; background: transparent; color: var(--blue); font-size: 17px; font-weight: 600; }
.sheet-body { overflow-y: auto; padding: 4px 16px calc(var(--bottom) + 24px); display: flex; flex-direction: column; gap: 18px; }
.grabber { width: 36px; height: 5px; border-radius: 3px; background: #C7C7CC; margin: 6px auto 0; }
.opts { padding: 12px 14px; display: flex; flex-direction: column; gap: 14px; }
.opts .lbl { font-size: 13px; color: var(--muted); display: block; margin-bottom: 6px; }
.opts input[type=text] { width: 100%; border: 0; border-bottom: 0.5px solid var(--line); padding: 4px 0 6px; font-size: 17px; outline: none; background: transparent; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 36px; height: 36px; border-radius: 18px; border: 0; padding: 0; }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 3px #FFFFFF, 0 0 0 5px var(--c); }
.segmented { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px; padding: 2px; border-radius: 9px; background: #E3E3E8; }
.segmented button { min-height: 34px; border: 0; border-radius: 7px; background: transparent; font-size: 13px; font-weight: 600; }
.segmented button[aria-checked="true"] { background: #FFFFFF; box-shadow: 0 1px 3px rgba(0,0,0,0.15); }
.pick .tick { color: var(--blue); }
.sheet-note { margin: 0; padding: 0 4px; font-size: 13px; color: var(--muted); line-height: 1.4; }
.prompt-input { width: 100%; padding: 14px; border: 0; border-radius: 12px; background: var(--card); font-size: 17px; outline: none; }
.btn-row { display: flex; gap: 10px; }
.btn-row button { flex: 1; }
.secondary { min-height: 50px; border: 0; border-radius: 12px; background: #E3E3E8; color: var(--text); font-size: 17px; font-weight: 600; }
.primary.danger { background: var(--red); }
@keyframes rise { from { transform: translateY(40px); opacity: 0.4; } }
@keyframes fade { from { opacity: 0; } }

#toast { position: fixed; left: 50%; bottom: calc(var(--bottom) + 90px); transform: translateX(-50%); z-index: 80; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; background: rgba(28,28,30,0.92); color: #FFFFFF; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.show { opacity: 1; }

/* ---------- printing a list ---------- */
#print { display: none; }
@media print {
  html, body, html.is-themed, html.is-themed body { background: #FFFFFF; }
  body > *:not(#print) { display: none !important; }
  #print { display: block; color: #000000; font: 12pt/1.45 var(--font); }
  #print h1 { font-size: 20pt; margin: 0 0 4pt; }
  #print .when { color: #444444; font-size: 10pt; margin: 0 0 14pt; }
  #print ul { list-style: none; margin: 0; padding: 0; }
  #print li { padding: 3pt 0 3pt 22pt; position: relative; break-inside: avoid; }
  #print li::before { content: ""; position: absolute; left: 0; top: 6pt; width: 11pt; height: 11pt; border: 1pt solid #000000; border-radius: 6pt; }
  #print li.ticked::before { content: "✓"; font-size: 9pt; line-height: 11pt; text-align: center; }
  #print ul ul { margin-top: 2pt; }
  #print .note { display: block; color: #444444; font-size: 10pt; white-space: pre-wrap; }
}
