/* ---------- Tokens ---------- */
:root {
  --bg: #F6EFE7;
  --surface: #FFFFFF;
  --text: #2B211B;
  --muted: #7A6A5F;
  --border: #E7DCD0;
  --accent: #D9733F;
  --accent-press: #C0602F;
  --accent-text: #FFFFFF;
  --danger-bg: #FDECEA;
  --danger: #B3261E;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(43, 33, 27, .06), 0 8px 24px rgba(43, 33, 27, .06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1C1714;
    --surface: #27201C;
    --text: #F3EAE2;
    --muted: #A8978A;
    --border: #3A302A;
    --accent: #E8834F;
    --accent-press: #F09764;
    --accent-text: #1C1714;
    --danger-bg: #3B1E1B;
    --danger: #F2B8B5;
    --shadow: none;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
h1, h2, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; }

/* ---------- Components ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.form { display: flex; flex-direction: column; gap: 16px; padding: 20px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span:first-child, .field > label { font-size: 14px; font-weight: 600; color: var(--muted); }

.input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  font-size: 16px; /* >= 16px prevents iOS zoom on focus */
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.pw { position: relative; display: block; }
.pw .input { padding-right: 52px; }
.pw-toggle {
  position: absolute; top: 4px; right: 4px;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; border-radius: 10px;
  background: none; color: var(--muted);
  cursor: pointer;
}
.pw-toggle[aria-pressed="true"] { color: var(--accent); }

.btn {
  height: 52px;
  padding: 0 20px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border: 0; border-radius: 12px;
  font-size: 16px; font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color .15s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .75; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:active { background: var(--accent-press); }
.btn-ghost { height: 40px; padding: 0 12px; background: transparent; color: var(--muted); }
.btn.is-loading::after {
  content: "";
  width: 18px; height: 18px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }

.alert {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 15px;
}

/* ---------- Login ---------- */
.auth {
  min-height: 100dvh;
  max-width: 420px;
  margin: 0 auto;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  display: flex; flex-direction: column; justify-content: center; gap: 28px;
}
.brand { text-align: center; }
.brand img { margin: 0 auto 12px; border-radius: 22px; }
.brand h1 { font-size: 28px; font-weight: 700; letter-spacing: -.01em; }
.brand p { color: var(--muted); }

/* ---------- App shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: calc(8px + var(--safe-top)) 16px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.8) blur(16px);
  backdrop-filter: saturate(1.8) blur(16px);
}
.topbar h1 { font-size: 20px; font-weight: 700; text-align: center; }
.topbar-side { min-width: 44px; height: 44px; display: grid; place-items: center; justify-self: start; color: var(--text); text-decoration: none; }
.topbar-side:last-child { justify-self: end; }
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: none; color: var(--muted);
  cursor: pointer;
}
.icon-btn.is-spinning svg { animation: spin .7s linear infinite; }
.icon-btn:active { background: var(--border); }

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px calc(24px + var(--safe-bottom));
}
.narrow { max-width: 440px; }
.stack { display: flex; flex-direction: column; gap: 16px; }

.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;
}

/* ---------- Avatar ---------- */
.avatar {
  flex: none;
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--accent); color: var(--accent-text);
  font-weight: 700;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 40px; height: 40px; font-size: 17px; }
.avatar-lg { width: 112px; height: 112px; font-size: 44px; }

.avatar-edit { display: flex; flex-direction: column; align-items: center; gap: 8px; padding-top: 8px; }
.avatar-pick { position: relative; cursor: pointer; border-radius: 50%; }
.avatar-pick:focus-within { outline: 3px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 3px; }
.avatar-badge {
  position: absolute; right: 0; bottom: 0;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 3px solid var(--bg); border-radius: 50%;
  background: var(--surface); color: var(--text);
}
.avatar-hint { font-size: 14px; color: var(--muted); }
.avatar-edit.is-uploading .avatar-lg { opacity: .5; }
.avatar-edit.is-uploading .avatar-badge::after {
  content: ""; position: absolute; inset: -3px;
  border: 3px solid var(--accent); border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite;
}
.ok { color: #2E7D32; font-size: 14px; font-weight: 600; }
@media (prefers-color-scheme: dark) { .ok { color: #81C784; } }
.muted-note { text-align: center; font-size: 13px; color: var(--muted); }

/* ---------- Home ---------- */
.hero {
  position: relative;
  aspect-ratio: 1 / .92;
  margin-bottom: 16px;
  border-radius: 20px;
  overflow: hidden;
  background: var(--border);
  color: #fff;
}
.hero img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover; object-position: center 35%;
}
.hero::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(rgba(0,0,0,.35), transparent 30%, transparent 55%, rgba(0,0,0,.6));
}
.hero-top, .hero-hello { position: absolute; z-index: 1; left: 18px; right: 18px; text-shadow: 0 1px 8px rgba(0,0,0,.35); }
.hero-top { top: 14px; display: flex; justify-content: space-between; gap: 12px; font-weight: 600; font-size: 15px; }
.hero-top time { font-weight: 500; }
.hero-top time::first-letter { text-transform: uppercase; }
.hero-hello { bottom: 16px; font-size: 26px; font-weight: 700; line-height: 1.2; letter-spacing: -.01em; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  min-height: 128px;
  padding: 14px;
  display: flex; flex-direction: column; align-items: flex-start;
  color: inherit; text-decoration: none;
  transition: transform .1s;
}
a.tile:active { transform: scale(.97); }
div.tile .app-ico { filter: saturate(.85); }
.tile .app-ico { margin-bottom: auto; }
.tile-name { margin-top: 12px; font-size: 17px; font-weight: 600; line-height: 1.25; }
.tile-sub { font-size: 13px; color: var(--muted); }

/* iOS-style app icon: white glyph on a gradient squircle */
.app-ico {
  flex: none;
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: 13px;
  color: #fff;
  background:
    linear-gradient(180deg, rgba(255,255,255,.22), rgba(255,255,255,0) 60%),
    linear-gradient(160deg, var(--tile), color-mix(in srgb, var(--tile) 78%, #000));
  box-shadow: 0 1px 2px rgba(0,0,0,.12), inset 0 0 0 .5px rgba(0,0,0,.08);
}
.app-ico svg .t { fill-opacity: .3; }
.app-ico svg .o { fill-opacity: .55; }
.app-ico svg .bg { fill: color-mix(in srgb, var(--tile) 88%, #000); }
.app-ico-sm { width: 36px; height: 36px; border-radius: 9px; }

/* Duotone icon parts */
svg .t { fill: currentColor; fill-opacity: .18; stroke: none; }
svg .d { fill: currentColor; stroke: none; }
svg .o { fill-opacity: .45; }
svg .bg { fill: var(--surface); stroke: none; }

@media (min-width: 560px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- Shopping ---------- */
.shopping { --tile: #3B82F6; --c: #3B82F6; }
.new-row { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 16px; }
.input-bare {
  flex: 1; min-width: 0; height: 44px;
  border: 0; background: none; outline: none;
  font-size: 16px;
}
.input-bare::placeholder { color: var(--muted); }
.btn-sm { height: 40px; padding: 0 16px; font-size: 15px; border-radius: 10px; }
.btn-accent { background: var(--c); color: #fff; }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-block { width: 100%; }
.add-btn {
  flex: none; width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 0; border-radius: 10px;
  background: var(--c); color: #fff;
  cursor: pointer;
}
.add-btn:active { transform: scale(.94); }
.empty { text-align: center; color: var(--muted); padding: 20px 0; }

.items { list-style: none; margin: 0; padding: 0; overflow: hidden; }
.items:not(:has(li)) { display: none; }
.items:has(li) + .todo-empty { display: none; }
.done-wrap:not(:has(li)) { display: none; }

.item {
  display: flex; align-items: center; gap: 12px;
  min-height: 52px;
  padding: 4px 4px 4px 14px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  -webkit-user-select: none; user-select: none;
}
.item:first-child { border-top: 0; }
.item:active { background: var(--bg); }
.item.is-pending { opacity: .55; }
.check {
  flex: none; width: 26px; height: 26px; padding: 0;
  display: grid; place-items: center;
  border: 2px solid color-mix(in srgb, var(--muted) 55%, transparent); border-radius: 50%;
  background: none; color: transparent;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s, transform .15s;
}
.item.is-checked .check { background: var(--c); border-color: var(--c); color: #fff; }
.item.is-checked .check svg { animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(.4); } }
.item-text { flex: 1; min-width: 0; overflow-wrap: anywhere; transition: color .15s; }
.item.is-checked .item-text { color: var(--muted); text-decoration: line-through; }
.item-del {
  flex: none; width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 0; border-radius: 10px;
  background: none; color: var(--muted); opacity: .55;
  cursor: pointer;
}

.section-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 4px 6px;
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted);
}
.link-btn { border: 0; background: none; padding: 6px; color: var(--c); font-size: 14px; font-weight: 600; text-transform: none; letter-spacing: 0; cursor: pointer; }

.list-settings summary {
  list-style: none; cursor: pointer;
  padding: 8px; text-align: center;
  font-size: 14px; color: var(--muted);
}
.list-settings summary::-webkit-details-marker { display: none; }
.list-settings[open] summary { margin-bottom: 8px; }

.topbar h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-bottom)); z-index: 50;
  transform: translateX(-50%);
  padding: 10px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg);
  font-size: 14px;
}

/* ---------- Lists (settings) ---------- */
.list { padding: 4px 0; overflow: hidden; }
.list-row {
  width: 100%; min-height: 60px;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  border: 0; background: none;
  color: var(--text); text-decoration: none; text-align: left;
  font-size: 16px; cursor: pointer;
}
.list-row:active { background: var(--bg); }
.list-text { flex: 1; display: flex; flex-direction: column; }
.list-text small { font-size: 13px; color: var(--muted); }
.list-ico { width: 40px; display: grid; place-items: center; }
.list-end { color: var(--muted); display: grid; }
.list-danger { color: var(--danger); font-weight: 600; }

/* ---------- Tasks ---------- */
.tasks { --tile: #F5A524; --c: #D97706; padding-bottom: calc(96px + var(--safe-bottom)); }
.tasks.narrow { padding-bottom: calc(24px + var(--safe-bottom)); }

.segmented {
  display: grid; grid-auto-columns: 1fr; grid-auto-flow: column;
  padding: 3px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg);
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span, .segmented-links a {
  display: block; padding: 8px 4px;
  border-radius: 9px;
  text-align: center; font-size: 14px; font-weight: 600; color: var(--muted); text-decoration: none;
  cursor: pointer;
}
.segmented input:checked + span, .segmented-links a[aria-current] {
  background: var(--surface); color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
.segmented input:focus-visible + span { outline: 2px solid var(--c); }

.task { align-items: center; padding-top: 10px; padding-bottom: 10px; padding-right: 12px; cursor: default; }
.task-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; color: inherit; text-decoration: none; }
.task-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; color: var(--muted); }
.task-meta span { display: inline-flex; align-items: center; gap: 4px; }
.is-overdue { color: var(--danger) !important; }
.task.is-leaving { opacity: 0; transform: translateX(16px); transition: opacity .3s, transform .3s; }
.avatar-xs { width: 28px; height: 28px; font-size: 12px; }
.avatar-task { width: 38px; height: 38px; font-size: 16px; }

.section-head.is-overdue { color: var(--danger); }
.done-tasks summary { list-style: none; cursor: pointer; }
.done-tasks summary::-webkit-details-marker { display: none; }

.fab {
  position: fixed; z-index: 20;
  right: max(20px, calc((100vw - 640px) / 2 + 20px));
  bottom: calc(24px + var(--safe-bottom));
  width: 58px; height: 58px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: linear-gradient(160deg, var(--tile), var(--c));
  color: #fff;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--c) 45%, transparent), 0 2px 4px rgba(0,0,0,.15);
}
.fab:active { transform: scale(.94); }

.task-card { padding: 18px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.task-title { font-size: 22px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.task-title.is-done { text-decoration: line-through; color: var(--muted); }
.task-desc { color: var(--text); white-space: normal; overflow-wrap: anywhere; }
.chip { padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.chip-ok { background: color-mix(in srgb, #22C55E 18%, transparent); color: #15803D; }
.chip-alert { background: var(--danger-bg); color: var(--danger); }
@media (prefers-color-scheme: dark) { .chip-ok { color: #86EFAC; } }

.task-photo { display: block; border-radius: var(--radius); overflow: hidden; background: var(--border); }
.task-photo img { width: 100%; height: auto; max-height: 70vh; object-fit: cover; }

.details { margin: 0; padding: 4px 16px; }
.details > div { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 50px; border-top: 1px solid var(--border); }
.details > div:first-child { border-top: 0; }
.details dt { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.details dd { margin: 0; display: flex; align-items: center; gap: 8px; font-weight: 600; text-align: right; }

.btn-soft { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.textarea { height: auto; min-height: 88px; padding: 12px 16px; resize: vertical; field-sizing: content; line-height: 1.45; }
select.input {
  appearance: none; -webkit-appearance: none;
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%237A6A5F' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 16px center;
}
input[type="datetime-local"].input { display: flex; align-items: center; min-width: 0; -webkit-appearance: none; }
.photo-field { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.photo-preview { width: 100%; max-height: 260px; object-fit: cover; border-radius: 12px; }
.photo-field .btn { height: 44px; font-size: 15px; cursor: pointer; }
.check-label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }

/* Primary action pinned above the home indicator */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: saturate(1.8) blur(16px);
  backdrop-filter: saturate(1.8) blur(16px);
  border-top: 1px solid var(--border);
}
.bottom-bar > .btn { display: flex; max-width: 440px; margin: 0 auto; }
.has-bottom-bar, .tasks.narrow.has-bottom-bar { padding-bottom: calc(100px + var(--safe-bottom)); }

/* ---------- Discussions ---------- */
.discussions { --tile: #14B8A6; --c: #0D9488; padding-bottom: calc(96px + var(--safe-bottom)); }
.discussions.narrow { padding-bottom: calc(24px + var(--safe-bottom)); }
.discussions.has-bottom-bar { padding-bottom: calc(110px + var(--safe-bottom)); }

.topic { align-items: center; }
.topic-thumb { flex: none; width: 36px; height: 36px; border-radius: 9px; object-fit: cover; }
.topic-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topic-last { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topic .list-text { min-width: 0; }
.topic-side { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 12px; color: var(--muted); }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--c); color: #fff;
  font-size: 12px; font-weight: 700;
}
.chip-muted { display: inline-flex; align-items: center; gap: 4px; background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.topic-photo { width: 100%; margin-top: 4px; }
.topic-foot { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 4px; color: var(--muted); }
.avatar-stack { display: flex; }
.avatar-stack .avatar { border: 2px solid var(--surface); margin-left: -8px; }
.avatar-stack .avatar:first-child { margin-left: 0; }

/* Chat thread */
.thread { display: flex; flex-direction: column; gap: 3px; }
.msg { display: flex; align-items: flex-end; gap: 8px; max-width: 86%; }
.msg.is-first { margin-top: 10px; }
.msg.is-mine { align-self: flex-end; }
.msg-avatar { flex: none; width: 28px; }
.msg-bubble {
  display: flex; flex-direction: column;
  padding: 8px 12px;
  border-radius: 18px;
  background: var(--surface); border: 1px solid var(--border);
}
.msg.is-mine .msg-bubble { background: var(--c); border-color: var(--c); color: #fff; }
.msg-author { font-size: 12px; font-weight: 700; color: var(--c); }
.msg-text { overflow-wrap: anywhere; }
.msg-time { align-self: flex-end; font-size: 11px; opacity: .6; }
.msg.is-new { animation: msg-in .25s ease-out; }
@keyframes msg-in { from { opacity: 0; transform: translateY(8px); } }

.composer { display: flex; align-items: flex-end; gap: 8px; }
.composer > * { max-width: none; }
.composer-input {
  flex: 1; min-width: 0;
  height: auto; min-height: 44px; max-height: 140px;
  padding: 10px 14px;
  border-radius: 22px;
  resize: none; field-sizing: content; line-height: 1.4;
  background: var(--surface);
}
.composer .add-btn { width: 44px; height: 44px; border-radius: 50%; }
.composer, .closed-note { max-width: none; }
@media (min-width: 480px) { .composer { padding-left: calc((100vw - 440px) / 2); padding-right: calc((100vw - 440px) / 2); } }
.closed-note { display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--muted); font-size: 14px; }

/* Member picker */
.member-pick { cursor: pointer; }
.member-pick input { position: absolute; opacity: 0; pointer-events: none; }
.member-pick input:checked + .check { background: var(--c); border-color: var(--c); color: #fff; }
.member-pick input:disabled + .check { opacity: .6; }
.member-pick input:focus-visible + .check { outline: 2px solid var(--c); outline-offset: 2px; }
.topic-action { width: 100%; padding-top: 4px; border-top: 1px solid var(--border); }
.topic-action .btn { width: 100%; margin-top: 8px; }
.delete-form { margin-top: 24px; }
