:root {
  color-scheme: light dark;
  --bg: #f7f3ec;
  --surface: #ffffff;
  --sunk: #efe8dc;
  --ink: #2b211a;
  --muted: #6f6257;
  --line: #e0d7c9;
  --brand: #3f2a1d;
  --brand-ink: #f7f3ec;
  --accent: #e7b44c;
  --action: #6b4423;
  --action-ink: #ffffff;
  --mine: #f3e4c4;
  --danger: #a3341f;
  --todo: #6b4423;
  --print: #2b5c8a;
  --shipping: #a3341f;
  --news: #3d6b4a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1612;
    --surface: #26201a;
    --sunk: #2f2820;
    --ink: #f1eadf;
    --muted: #b0a394;
    --line: #40362c;
    --brand: #2a1d14;
    --brand-ink: #f1eadf;
    --action: #e7b44c;
    --action-ink: #2b211a;
    --mine: #4a3722;
    --danger: #f0917c;
    --todo: #e7b44c;
    --print: #84b8e8;
    --shipping: #f0917c;
    --news: #8fc9a0;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
#app { height: 100%; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 24px; line-height: 1.2; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
a { color: var(--action); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.empty { color: var(--muted); text-align: center; padding: 32px 16px; }
.danger { color: var(--danger) !important; }

input, textarea, select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
input[type="checkbox"] { width: 20px; height: 20px; padding: 0; accent-color: var(--action); flex: none; }
textarea { resize: none; display: block; }
:is(input, textarea, select, button, a):focus-visible { outline: 2px solid var(--action); outline-offset: 1px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--action); color: var(--action-ink); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.wide { width: 100%; }
.icon-btn { width: 42px; padding: 0; flex: none; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.link { background: none; border: 0; padding: 6px 2px; font: inherit; color: var(--action); cursor: pointer; text-decoration: underline; }

.stack { display: grid; gap: 14px; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 14px; font-weight: 600; }
.check { display: flex; align-items: center; gap: 8px; }

/* Before sign-in */
.gate { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.gate-card {
  width: min(400px, 100%);
  display: grid;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px 20px;
}
.gate-card .brand { color: var(--action); font-weight: 700; }
.gate-card .link { justify-self: start; }

/* Signed in */
.shell { height: 100%; display: flex; flex-direction: column; }
.top {
  background: var(--brand);
  color: var(--brand-ink);
  border-bottom: 3px solid var(--accent);
  padding-top: env(safe-area-inset-top);
  flex: none;
}
.top .brand { font-weight: 700; padding: 8px 16px 0; }
.tabs { display: flex; gap: 4px; padding: 0 8px; overflow: auto hidden; scrollbar-width: none; }
.tab {
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  color: inherit;
  opacity: .8;
  font: inherit;
  font-weight: 600;
  padding: 10px 10px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.tab.on { opacity: 1; border-bottom-color: var(--brand-ink); }
.badge {
  background: var(--accent);
  color: #2b211a;
  font-size: 12px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  border-radius: 10px;
  padding: 0 5px;
}
.offline { background: var(--accent); color: #2b211a; text-align: center; font-size: 14px; padding: 2px; flex: none; }

.views { flex: 1; min-height: 0; display: grid; }
.panel { min-height: 0; min-width: 0; display: none; flex-direction: column; background: var(--bg); }
.views[data-view="updates"] .board,
.views[data-view="chat"] .chat,
.views[data-view="schedule"] .schedules,
.views[data-view="team"] .team,
.views[data-view="me"] .me { display: flex; }
.panel-head {
  flex: none;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 10px 16px;
  min-height: 62px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.panel-head h2 { margin-right: auto; }
.panel-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }

.segs { display: inline-flex; background: var(--sunk); border-radius: 8px; padding: 2px; }
.seg { background: none; border: 0; font: inherit; font-size: 14px; color: var(--muted); border-radius: 6px; padding: 7px 12px; cursor: pointer; }
.seg.on { background: var(--surface); color: var(--ink); font-weight: 600; }

/* Updates */
.posts { display: grid; gap: 12px; max-width: 720px; margin: 0 auto; }
.post {
  --type: var(--todo);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--type);
  border-radius: 8px;
  padding: 12px 14px;
  display: grid;
  gap: 8px;
}
.type-print { --type: var(--print); }
.type-shipping { --type: var(--shipping); }
.type-news { --type: var(--news); }
.post-top { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; }
.post-time { margin-left: auto; }
.tag { font-size: 13px; font-weight: 700; color: var(--type, var(--muted)); }
.pin { font-size: 12px; font-weight: 700; background: var(--accent); color: #2b211a; border-radius: 4px; padding: 0 6px; }
.post-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; }
.got { font-size: 14px; color: var(--muted); }
.post-form { max-width: 720px; margin: 0 auto 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.form-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.post-form .form-actions .link { margin-left: auto; }

.photo { display: block; width: fit-content; max-width: 100%; }
.photo img { display: block; max-width: 100%; max-height: 320px; border-radius: 6px; }
.picked { display: flex; align-items: center; gap: 12px; padding: 8px 16px; }
.picked img { height: 64px; max-width: 120px; object-fit: cover; border-radius: 6px; }
.post-form .picked { padding: 0; }

/* Schedule: shown as large as the screen allows, tap to open it full size */
.schedules .post { --type: var(--line); }
.schedule .photo { width: 100%; }
.schedule .photo img { width: 100%; max-height: none; }

/* Chat */
.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; }
.chat-rule { color: var(--muted); font-size: 13px; text-align: center; padding: 0 8px 8px; }
.earlier { align-self: center; }
.chat-log { margin-top: auto; display: flex; flex-direction: column; gap: 2px; }
.day { text-align: center; margin: 12px 0 8px; font-size: 13px; color: var(--muted); }
.msg { display: flex; flex-direction: column; align-items: flex-start; margin-top: 10px; max-width: 100%; }
.msg.grouped { margin-top: 2px; }
.msg.mine { align-items: flex-end; }
.who { font-size: 13px; color: var(--muted); margin: 0 2px 2px; }
.who b { color: var(--ink); }
.bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 7px 11px;
  max-width: min(85%, 560px);
  display: grid;
  gap: 6px;
}
.msg.mine .bubble { background: var(--mine); border-color: transparent; }
.msg.deleted .bubble { color: var(--muted); font-style: italic; font-size: 14px; }
.msg-del { font-size: 13px; color: var(--muted); padding: 0 2px; display: none; }
.msg:hover .msg-del, .msg:focus-within .msg-del { display: block; }
@media (hover: none) { .msg-del { display: block; } }
.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.composer textarea { min-height: 42px; overflow-y: hidden; }

/* Team */
.team .panel-scroll > * { max-width: 620px; margin-left: auto; margin-right: auto; }
.add-person { display: flex; gap: 8px; margin-top: 12px; }
.code-card { display: grid; gap: 8px; margin-top: 12px; background: var(--surface); border: 2px solid var(--accent); border-radius: 8px; padding: 14px; }
.code { font: 700 22px/1.3 ui-monospace, Consolas, monospace; letter-spacing: .03em; overflow-wrap: anywhere; user-select: all; }
.team-list { display: grid; gap: 8px; margin-top: 16px; }
.person { display: flex; align-items: center; flex-wrap: wrap; justify-content: space-between; gap: 8px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.person .tag { margin-left: 8px; color: var(--action); }
.person-actions { display: flex; align-items: center; gap: 12px; }

/* Me */
.settings { display: grid; gap: 14px; max-width: 460px; margin: 0 auto; }
.settings h3:not(:first-child) { margin-top: 14px; padding-top: 16px; border-top: 1px solid var(--line); }
.settings .btn { justify-self: start; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  max-width: calc(100vw - 32px);
  width: max-content;
  background: var(--ink);
  color: var(--bg);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s, transform .15s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Counter PC: updates and chat side by side */
@media (min-width: 960px) {
  .top { display: flex; align-items: center; gap: 24px; }
  .top .brand { padding: 0 0 0 20px; }
  .views[data-view="updates"], .views[data-view="chat"] { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .views[data-view="updates"] .chat, .views[data-view="chat"] .board { display: flex; }
  .board { border-right: 1px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
