/* ---------- colours ---------- */
:root {
  --bg: #f4efe8; --panel: #fffdf9; --sunk: #f8f3ec; --line: #e6ddd1; --ink: #1f1d1a; --mute: #786f65;
  --acc: #e0601f; --acc-ink: #ffffff; --acc-soft: #fbe5d6; --mine: #ffe3cf; --theirs: #ffffff;
  --ok: #2e8a55; --ok-soft: #dcf0e3; --warn: #b42318; --chip: #efe6da; --read: #1f7ae0;
  --shadow: 0 1px 2px rgba(60, 40, 20, .07), 0 2px 10px rgba(60, 40, 20, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131416; --panel: #1c1e21; --sunk: #17191b; --line: #2d3034; --ink: #ecebe8; --mute: #9d978e;
    --acc: #f07a3a; --acc-ink: #1a0f08; --acc-soft: #3b2417; --mine: #4a2c1a; --theirs: #26292d;
    --ok: #5cc28a; --ok-soft: #1d3326; --warn: #ff7b6e; --chip: #272a2e; --read: #6cb2ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
input, textarea { font-size: 16px; } /* 16px keeps iPhones from zooming in on a field */
h1, h2, h3, h4, p { margin: 0; }
[hidden] { display: none !important; }
.i { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.mute { color: var(--mute); }
.small { font-size: 13px; }
.boot { margin: auto; color: var(--mute); }
#app { height: 100vh; height: 100dvh; display: flex; }

/* ---------- buttons and fields ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { background: var(--sunk); }
.btn.primary { background: var(--acc); border-color: var(--acc); color: var(--acc-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.warn { color: var(--warn); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; border-radius: 10px; }
.btn.small .i { width: 16px; height: 16px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 0; border-radius: 50%; background: none; cursor: pointer; flex: none; color: var(--ink); }
.icon-btn:hover { background: var(--sunk); }
label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--mute); }
input:not([type=checkbox]):not([type=file]), textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); outline: none; font-weight: 400; }
input:focus, textarea:focus { border-color: var(--acc); box-shadow: 0 0 0 3px var(--acc-soft); }
textarea { resize: vertical; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
legend { font-size: 13px; font-weight: 600; color: var(--mute); margin-bottom: 6px; padding: 0; }
.stack { display: grid; gap: 14px; }
.err { color: var(--warn); font-size: 14px; min-height: 1em; }
.err:empty { display: none; }
.note { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; background: var(--acc-soft); font-size: 14px; }
.note .i { width: 18px; height: 18px; margin-top: 1px; }

/* ---------- sign in ---------- */
.auth { margin: auto; width: 100%; max-width: 420px; padding: 24px 16px; }
.auth-card { background: var(--panel); border-radius: 22px; padding: 26px 22px; box-shadow: var(--shadow); display: grid; gap: 18px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand svg { width: 48px; height: 48px; border-radius: 12px; }
.brand h1 { font-size: 28px; letter-spacing: -.02em; }
.lede { color: var(--mute); }
.seg { display: flex; background: var(--chip); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--mute); }
.seg button.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- the frame: tabs, list, detail ---------- */
/* On a phone: one screen at a time with tabs at the bottom. On a wide screen: rail, list and detail side by side. */
.shell { display: grid; grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; width: 100%; height: 100%; }
.tabs { grid-row: 2; display: flex; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 6px; font-size: 11px; font-weight: 600; color: var(--mute); position: relative; }
.tabs a.on { color: var(--acc); }
.tabs .badge { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--acc); color: var(--acc-ink); font-size: 11px; line-height: 18px; text-align: center; }
.tabs .badge:empty { display: none; }
.tabs .logo { display: none; }
.tabs .av.xs { width: 24px; height: 24px; font-size: 10px; }
.tabs a.on .av { box-shadow: 0 0 0 2px var(--acc); }
.list, .detail { min-height: 0; min-width: 0; display: flex; flex-direction: column; background: var(--panel); }
.list { grid-row: 1; }
.detail { display: none; background: var(--bg); }
.shell.has-detail .list, .shell.has-detail .tabs { display: none; }
.shell.has-detail .detail { display: flex; grid-row: 1 / 3; }
@media (min-width: 900px) {
  .shell { grid-template-columns: 76px 370px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .tabs, .shell.has-detail .tabs { display: flex; grid-row: 1; grid-column: 1; flex-direction: column; justify-content: flex-start; gap: 6px; border-top: 0; border-right: 1px solid var(--line); padding: 14px 0; }
  .tabs a { flex: none; padding: 8px 0; }
  .tabs .logo { display: block; margin: 0 auto 10px; width: 40px; height: 40px; border-radius: 11px; }
  .tabs .badge { left: calc(50% + 4px); }
  .list, .shell.has-detail .list { display: flex; grid-column: 2; grid-row: 1; border-right: 1px solid var(--line); }
  .detail, .shell.has-detail .detail { display: flex; grid-column: 3; grid-row: 1; }
  .back { display: none !important; }
}

/* ---------- panes ---------- */
.pane { display: flex; flex-direction: column; flex: 1; min-height: 0; width: 100%; }
.bar { display: flex; align-items: center; gap: 6px; min-height: 58px; padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top)); background: var(--panel); border-bottom: 1px solid var(--line); flex: none; }
.bar h2 { flex: 1; font-size: 20px; letter-spacing: -.01em; padding: 0 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.pad { padding: 14px; display: grid; gap: 12px; align-content: start; }
.pad > * { width: 100%; max-width: 720px; margin: 0 auto; }
.search { display: flex; align-items: center; gap: 8px; margin: 10px 12px 6px; padding: 0 12px; background: var(--chip); border-radius: 12px; color: var(--mute); flex: none; }
.search .i { width: 18px; height: 18px; }
.search input, .search input:focus { border: 0 !important; background: none !important; box-shadow: none !important; padding: 9px 0 !important; }
.empty { padding: 36px 24px; text-align: center; color: var(--mute); display: grid; gap: 10px; justify-items: center; }
.empty.small { padding: 18px; font-size: 14px; }
.empty .i { width: 34px; height: 34px; stroke-width: 1.6; }
.loading { padding: 30px; text-align: center; color: var(--mute); }
.placeholder { align-items: center; justify-content: center; text-align: center; color: var(--mute); gap: 10px; }
.placeholder svg.big { width: 72px; height: 72px; border-radius: 18px; opacity: .9; margin-bottom: 8px; }
.placeholder h3 { color: var(--ink); font-size: 18px; }
.card { background: var(--panel); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); display: grid; gap: 10px; }
.card h4 { font-size: 14px; display: flex; align-items: center; gap: 6px; }
.card h4 .i { width: 17px; height: 17px; }
.card.danger { background: none; box-shadow: none; padding: 0; }
.hero { display: grid; justify-items: center; gap: 6px; text-align: center; padding: 8px 0; }
.hero h3 { font-size: 22px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.body { white-space: pre-wrap; overflow-wrap: anywhere; }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--acc-soft); color: var(--acc); white-space: nowrap; }
.pill.done { background: var(--ok-soft); color: var(--ok); }

/* ---------- avatars ---------- */
.av { position: relative; display: inline-flex; align-items: center; justify-content: center; flex: none; width: 46px; height: 46px; border-radius: 50%; font-weight: 700; font-size: 16px; color: #fff; user-select: none; }
.av img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.av.xs { width: 26px; height: 26px; font-size: 11px; }
.av.sm { width: 36px; height: 36px; font-size: 13px; }
.av.xl { width: 96px; height: 96px; font-size: 34px; }
.av.on::after { content: ""; position: absolute; right: 1px; bottom: 1px; width: 11px; height: 11px; border-radius: 50%; background: #2fbf6b; border: 2px solid var(--panel); }
.av.grp { background: var(--chip); color: var(--mute); }
.c0 { background: #d9622b; } .c1 { background: #2f7d6d; } .c2 { background: #5a63c9; } .c3 { background: #b0457c; }
.c4 { background: #7a8b2b; } .c5 { background: #2a7bb8; } .c6 { background: #9a6a2f; } .c7 { background: #6d4fb0; }

/* ---------- lists of chats and people ---------- */
.row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; cursor: pointer; }
.row:hover { background: var(--sunk); }
.row.on { background: var(--acc-soft); }
button.row { width: 100%; border: 0; background: none; text-align: left; font: inherit; color: inherit; }
.row-main { flex: 1; min-width: 0; display: grid; gap: 1px; }
.row-top, .row-sub { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.row-top time { font-size: 12px; color: var(--mute); }
.row-sub { color: var(--mute); font-size: 14px; }
.row-sub > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub .i { width: 14px; height: 14px; }
.row.unread .row-top time { color: var(--acc); font-weight: 700; }
.row.unread .row-sub > span { color: var(--ink); }
.count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--acc); color: var(--acc-ink); font-size: 12px; line-height: 20px; text-align: center; }
.typing { color: var(--acc); font-style: normal; flex: 1; }
.pick { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.pick .i { width: 16px; height: 16px; stroke-width: 3; color: var(--acc-ink); opacity: 0; }
.row.picked .pick { background: var(--acc); border-color: var(--acc); }
.row.picked .pick .i { opacity: 1; }
.pickbar { display: flex; gap: 8px; align-items: center; padding: 10px 12px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); flex: none; }
.pickbar p { flex: 1; color: var(--mute); font-size: 14px; }
.pickbar input { flex: 1; }

/* ---------- a chat ---------- */
.head-link { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 2px 4px; border-radius: 10px; }
.head-link > div { display: grid; min-width: 0; }
.head-link b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-link small { color: var(--mute); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-link small.live { color: var(--acc); }
.msgs { display: flex; flex-direction: column; padding: 10px 12px 14px; gap: 2px; }
.msgs > :first-child { margin-top: auto; }
.msg { max-width: min(78%, 560px); padding: 7px 10px 5px; border-radius: 16px; box-shadow: 0 1px 1px rgba(0, 0, 0, .06); overflow-wrap: anywhere; margin-top: 6px; }
.msg.cont { margin-top: 0; }
.msg.mine { align-self: flex-end; background: var(--mine); border-bottom-right-radius: 6px; }
.msg.theirs { align-self: flex-start; background: var(--theirs); border-bottom-left-radius: 6px; }
.msg .who { display: block; font-size: 13px; margin-bottom: 2px; background: none; }
.who.c0 { color: #d9622b; } .who.c1 { color: #2f7d6d; } .who.c2 { color: #5a63c9; } .who.c3 { color: #b0457c; }
.who.c4 { color: #7a8b2b; } .who.c5 { color: #2a7bb8; } .who.c6 { color: #9a6a2f; } .who.c7 { color: #6d4fb0; }
.msg .text { white-space: pre-wrap; }
.msg .meta { display: flex; justify-content: flex-end; align-items: center; gap: 3px; font-size: 11px; color: var(--mute); margin-top: 1px; }
.tick .i { width: 16px; height: 16px; }
.tick.read { color: var(--read); }
.photo { display: block; max-width: 100%; max-height: 360px; border-radius: 11px; margin: 2px 0 4px; cursor: zoom-in; }
.lockedmsg { color: var(--mute); font-size: 14px; display: flex; gap: 6px; align-items: center; }
.lockedmsg .i { width: 15px; height: 15px; }
.sys { align-self: center; margin: 8px 0; padding: 4px 10px; border-radius: 10px; background: var(--chip); color: var(--mute); font-size: 12.5px; text-align: center; }
.day { align-self: center; margin: 12px 0 4px; font-size: 12px; font-weight: 700; color: var(--mute); }
.day span { background: var(--panel); padding: 3px 10px; border-radius: 10px; box-shadow: var(--shadow); }
.more { align-self: center; margin: 6px 0; border: 0; background: var(--chip); color: var(--mute); border-radius: 10px; padding: 5px 12px; cursor: pointer; }
.refcard { display: grid; grid-template-columns: auto 1fr; gap: 0 8px; align-items: center; padding: 7px 9px; margin: 2px 0 5px; border-radius: 10px; background: rgba(127, 127, 127, .12); border-left: 3px solid var(--acc); }
.refcard .i { grid-row: span 2; width: 18px; height: 18px; color: var(--acc); }
.refcard b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.refcard small { font-size: 12px; color: var(--mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px; padding: 8px 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); flex: none; }
.refslot { flex-basis: 100%; }
.composer .refcard { flex-basis: 100%; margin: 0 0 2px; grid-template-columns: auto 1fr auto; }
.composer .refcard .icon-btn { grid-row: span 2; width: 30px; height: 30px; }
.composer textarea { flex: 1; resize: none; min-height: 42px; max-height: 150px; border-radius: 21px; padding: 9px 15px; line-height: 1.4; }
.composer .icon-btn { width: 42px; height: 42px; color: var(--mute); }
.send { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--acc); color: var(--acc-ink); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: none; }
.send .i { fill: currentColor; stroke-width: 1.5; width: 20px; height: 20px; margin-left: 2px; }
.locked-note { padding: 14px; padding-bottom: calc(14px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); color: var(--mute); font-size: 14px; display: flex; gap: 8px; }
.code { font: 600 19px/1.6 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .04em; text-align: center; padding: 12px; background: var(--sunk); border-radius: 12px; word-spacing: .3em; }
.viewer { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .88); display: flex; align-items: center; justify-content: center; padding: 16px; cursor: zoom-out; }
.viewer img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ---------- supplies board ---------- */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 4px 12px 10px; flex: none; scrollbar-width: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; padding: 0; }
.chip { position: relative; display: inline-flex; flex: none; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span, button.chip { padding: 6px 12px; border-radius: 999px; background: var(--chip); color: var(--ink); font-size: 13px; font-weight: 600; border: 1px solid transparent; cursor: pointer; white-space: nowrap; }
.chip input:checked + span, button.chip.on { background: var(--acc-soft); color: var(--acc); border-color: var(--acc); }
.chip input:focus-visible + span { box-shadow: 0 0 0 3px var(--acc-soft); }
.post { display: grid; gap: 8px; margin: 0 12px 10px; padding: 13px 14px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); cursor: pointer; }
.post:hover { border-color: var(--acc); }
.post.on { border-color: var(--acc); background: var(--acc-soft); }
.list .post { background: var(--bg); }
.list .post.on { background: var(--acc-soft); }
.card .post { margin: 0; }
.post-top { display: flex; align-items: flex-start; gap: 8px; }
.post-top b, .post-top h3 { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.post-top h3 { font-size: 21px; letter-spacing: -.01em; }
.needs { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; font-size: 14px; }
.needs li { display: flex; gap: 6px; align-items: baseline; }
.needs li::before { content: ""; width: 7px; height: 7px; border-radius: 2px; background: var(--acc); flex: none; transform: translateY(-1px); }
.needs li.found { color: var(--mute); text-decoration: line-through; }
.needs li.found::before { background: var(--ok); }
.needs li.more { color: var(--mute); }
.needs li.more::before { visibility: hidden; }
.qty { font-weight: 700; color: var(--acc); white-space: nowrap; }
.found .qty { color: inherit; }
.post-foot { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--mute); min-width: 0; }
.post-foot .i { width: 15px; height: 15px; }
.post-foot .sp { flex: 1; }
.post-foot .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.statusbar { display: flex; gap: 6px; padding: 0 12px 10px; flex: none; }
.byline { display: flex; align-items: center; gap: 10px; }
.byline span { display: grid; }
.byline small { color: var(--mute); font-size: 13px; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--chip); color: var(--mute); }
.items { list-style: none; margin: 0; padding: 0; display: grid; }
.item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item-main { flex: 1; min-width: 0; display: grid; overflow-wrap: anywhere; }
.item-main small { color: var(--mute); font-size: 13px; }
.item.found .item-main b { text-decoration: line-through; color: var(--mute); }
.check { width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--line); background: none; display: inline-flex; align-items: center; justify-content: center; flex: none; padding: 0; color: transparent; }
button.check { cursor: pointer; }
button.check:hover { border-color: var(--ok); }
.check .i { width: 18px; height: 18px; stroke-width: 3; }
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.comments { display: grid; gap: 12px; }
.comment { display: flex; gap: 10px; }
.comment > div { flex: 1; min-width: 0; display: grid; gap: 2px; }
.comment small { color: var(--mute); font-size: 12.5px; }
.comment .x { margin-left: 6px; border: 0; background: none; color: var(--mute); cursor: pointer; font-size: 12.5px; padding: 0; text-decoration: underline; }
.comment-form { display: flex; gap: 8px; align-items: flex-end; }
.comment-form textarea { flex: 1; resize: none; }
.item-edit { display: grid; grid-template-columns: 1fr 110px 40px; gap: 6px; padding: 10px; border-radius: 12px; background: var(--sunk); }
.item-edit input[name=inote] { grid-column: 1 / 3; }
.item-edit .icon-btn { grid-row: 1 / 3; grid-column: 3; align-self: center; color: var(--mute); }
#itemRows { display: grid; gap: 8px; }

/* ---------- me ---------- */
.devices { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.devices li { display: flex; align-items: center; gap: 10px; }
.devices li > div { flex: 1; display: grid; }
.devices small { color: var(--mute); font-size: 12.5px; }
.switch { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 400; color: var(--ink); cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--acc); flex: none; }
.filebtn input { display: none; }

/* ---------- notices ---------- */
#toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 14px; background: var(--ink); color: var(--bg); font-size: 14px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
