/* troq: WhatsApp-like look. Colours as tokens, redefined for dark mode. */
:root {
  --bar: #008069; --bar-text: #fff; --bar-sub: #d9fdd3;
  --bg: #fff; --text: #111b21; --muted: #667781; --line: #e9edef; --hover: #f5f6f6;
  --chat-bg: #efeae2; --in: #fff; --out: #d9fdd3; --pill: #fff8c5; --pill-text: #54656f;
  --accent: #00a884; --badge: #25d366; --danger: #d93025; --input: #fff; --card: #fff;
  --shadow: 0 1px .5px rgba(11, 20, 26, .13);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bar: #202c33; --bar-text: #e9edef; --bar-sub: #8696a0;
    --bg: #111b21; --text: #e9edef; --muted: #8696a0; --line: #222d34; --hover: #202c33;
    --chat-bg: #0b141a; --in: #202c33; --out: #005c4b; --pill: #182229; --pill-text: #8696a0;
    --accent: #00a884; --badge: #00a884; --danger: #f15c6d; --input: #2a3942; --card: #1f2c34;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
#app { height: 100dvh; display: flex; flex-direction: column; max-width: 900px; margin: 0 auto; background: var(--bg); }
.boot { margin: auto; font-size: 28px; font-weight: 600; color: var(--accent); }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); }
a { color: var(--accent); }

/* Top bar */
.bar {
  display: flex; align-items: center; gap: 12px; min-height: 56px;
  padding: 8px 12px calc(8px) 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--bar); color: var(--bar-text); position: sticky; top: 0; z-index: 5;
}
.bar h1 { font-size: 19px; font-weight: 600; margin: 0; flex: 1; }
.bar .titles { flex: 1; min-width: 0; }
.bar .titles b { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .titles small { display: block; color: var(--bar-sub); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  background: none; border: 0; color: inherit; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; flex: none;
}
.icon-btn:hover { background: rgba(255, 255, 255, .12); }
.icon-btn svg { width: 24px; height: 24px; fill: currentColor; }
.offline { background: #f8d775; color: #3b3b3b; font-size: 13px; text-align: center; padding: 4px; }

/* Chat list */
.scroll { flex: 1; overflow-y: auto; }
.section { padding: 14px 16px 6px; font-size: 13px; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
.row {
  display: flex; gap: 12px; align-items: center; padding: 10px 16px; width: 100%;
  background: none; border: 0; text-align: left; color: inherit;
}
.row:hover, .row:focus-visible { background: var(--hover); outline: none; }
.row .main { flex: 1; min-width: 0; border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: -10px; }
.row .top, .row .sub { display: flex; gap: 8px; align-items: baseline; }
.row .name { flex: 1; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .time { font-size: 12px; color: var(--muted); flex: none; }
.row.unread .time { color: var(--badge); }
.row.unread .name { font-weight: 600; }
.row .preview { flex: 1; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--badge); color: #fff; border-radius: 10px; min-width: 20px; height: 20px; padding: 0 6px; font-size: 12px; font-weight: 600; display: grid; place-items: center; }
.chip { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--hover); color: var(--muted); flex: none; }
.chip.offered { background: #fff3cd; color: #7a5b00; }
.chip.declined { background: #fde2e1; color: #a1251b; }
.chip.accepted { background: #d9fdd3; color: #0a6b3d; }
@media (prefers-color-scheme: dark) {
  .chip.offered { background: #3b3112; color: #f0c64a; }
  .chip.declined { background: #3d1c1c; color: #f28b82; }
  .chip.accepted { background: #103529; color: #6ee7b7; }
}
.avatar {
  width: 48px; height: 48px; border-radius: 50%; flex: none; display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 17px;
}
.avatar.small { width: 40px; height: 40px; font-size: 15px; }
.avatar.group { border-radius: 14px; }
.empty { color: var(--muted); text-align: center; padding: 40px 24px; }
.fab {
  position: fixed; right: max(20px, calc(50vw - 430px)); bottom: max(20px, env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 16px; border: 0; background: var(--accent); color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25); display: grid; place-items: center;
}
.fab svg { width: 26px; height: 26px; fill: currentColor; }
.link-row { display: block; width: 100%; padding: 16px; background: none; border: 0; color: var(--muted); text-align: center; font-size: 14px; }

/* Thread */
.thread { flex: 1; overflow-y: auto; background: var(--chat-bg); padding: 10px 4% 16px; display: flex; flex-direction: column; gap: 3px; }
.card { background: var(--card); border-radius: 10px; padding: 12px 14px; box-shadow: var(--shadow); margin: 6px auto 10px; max-width: 560px; width: 100%; }
.card h2 { font-size: 17px; margin: 0 0 4px; }
.card p { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.card .meta { color: var(--muted); font-size: 13px; }
.pill { align-self: center; background: var(--pill); color: var(--pill-text); font-size: 12.5px; padding: 5px 12px; border-radius: 8px; margin: 6px 0; box-shadow: var(--shadow); text-align: center; max-width: 85%; }
.day { align-self: center; background: var(--card); color: var(--muted); font-size: 12px; padding: 4px 12px; border-radius: 8px; margin: 10px 0 4px; box-shadow: var(--shadow); text-transform: uppercase; }
.bubble { max-width: 78%; padding: 6px 9px 6px; border-radius: 8px; box-shadow: var(--shadow); position: relative; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.in { align-self: flex-start; background: var(--in); border-top-left-radius: 0; }
.bubble.out { align-self: flex-end; background: var(--out); border-top-right-radius: 0; }
.bubble .who { font-size: 13px; font-weight: 600; color: var(--accent); display: block; }
.bubble .stamp { float: right; font-size: 11px; color: var(--muted); margin: 6px 0 -4px 10px; }
.bubble.pending .stamp::after { content: " ◷"; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 8px 12px; background: var(--bg); border-top: 1px solid var(--line); }
.btn { border: 0; border-radius: 20px; padding: 8px 16px; background: var(--accent); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn:disabled { opacity: .5; cursor: default; }
.banner { background: var(--pill); color: var(--pill-text); padding: 10px 14px; font-size: 14px; display: flex; gap: 10px; align-items: center; }
.banner span { flex: 1; }
.composer { display: flex; gap: 8px; padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); background: var(--chat-bg); align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 0; border-radius: 22px; padding: 11px 16px; background: var(--input);
  max-height: 140px; min-height: 44px; box-shadow: var(--shadow); outline: none;
}
.send { width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.send svg { width: 22px; height: 22px; fill: currentColor; }

/* Forms and sheets */
.form { padding: 16px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; flex: 1; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.form input, .form textarea, .form select {
  border: 0; border-bottom: 2px solid var(--line); background: transparent; padding: 8px 2px; font-size: 16px; outline: none;
}
.form input:focus, .form textarea:focus, .form select:focus { border-bottom-color: var(--accent); }
.form textarea { min-height: 90px; resize: vertical; }
.choice { display: flex; gap: 12px; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--line); font-size: 15px; color: var(--text); }
.choice input { width: 18px; height: 18px; accent-color: var(--accent); }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.error { color: var(--danger); font-size: 14px; margin: 0; }
.center { margin: auto; max-width: 420px; width: 100%; padding: 24px; display: flex; flex-direction: column; gap: 16px; text-align: center; }
.center h1 { font-size: 26px; margin: 0; color: var(--accent); }
.center .card { text-align: left; }
.center input { border: 0; border-bottom: 2px solid var(--accent); background: transparent; padding: 10px 2px; font-size: 17px; outline: none; text-align: center; }
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 600px; border-radius: 16px 16px 0 0; padding: 18px 16px; padding-bottom: max(18px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; max-height: 85dvh; overflow-y: auto; }
.sheet h3 { margin: 0; font-size: 17px; }
.sheet .buttons { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.share-link { font-family: ui-monospace, monospace; font-size: 13px; background: var(--hover); padding: 10px; border-radius: 8px; overflow-wrap: anywhere; user-select: all; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #323232; color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 14px; z-index: 30; max-width: 90%; }
.list-item { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item div { flex: 1; min-width: 0; }
.list-item small { display: block; color: var(--muted); }
.btn svg { width: 18px; height: 18px; fill: currentColor; vertical-align: -3px; margin-right: 4px; }
a.btn { text-decoration: none; display: inline-block; }
.form label.choice { flex-direction: row; align-items: center; gap: 12px; font-size: 15px; color: var(--text); }
