/* Chat app and launcher. Soft neutral canvas, white rounded panels, pastel
   cards and a deep green accent. Self-contained: does not load app.css. */

:root {
  color-scheme: light dark;
  --canvas: #f4f3f0;
  --surface: #fafaf9;
  --panel: #ffffff;
  --sunken: #f3f3f1;
  --line: #e7e5e1;
  --line-strong: #d9d6d0;
  --ink: #18181b;
  --ink-2: #3f3f46;
  --muted: #8a8780;
  --accent: #0b7a55;
  --accent-ink: #ffffff;
  --accent-soft: #e4f3ec;
  --danger: #b4372a;
  --danger-soft: #fbeae7;
  --shadow: 0 1px 2px rgba(24, 24, 27, .04), 0 12px 32px -12px rgba(24, 24, 27, .12);
  --radius-xl: 28px;
  --radius-l: 20px;
  --radius-m: 14px;
  --radius-s: 10px;

  /* Pastel card themes: background, border, title ink. */
  --rose-bg: #fbe6ee; --rose-line: #f3cfdc; --rose-ink: #8a1f4a;
  --sky-bg: #e6edfd;  --sky-line: #d3defa;  --sky-ink: #1f3f8a;
  --stone-bg: #f0efed; --stone-line: #e2e0dc; --stone-ink: #3f3f46;
  --mint-bg: #e3f5df; --mint-line: #cdebc6; --mint-ink: #2d6a1f;
  --sand-bg: #fbf1dc; --sand-line: #f1e1bd; --sand-ink: #7a5212;
  --lilac-bg: #eee7fb; --lilac-line: #ddd1f5; --lilac-ink: #4e2a8a;

  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #121214;
    --surface: #18181b;
    --panel: #1f1f23;
    --sunken: #26262b;
    --line: #2e2e33;
    --line-strong: #3a3a40;
    --ink: #f2f1ee;
    --ink-2: #d4d3cf;
    --muted: #9b9891;
    --accent: #3fbf8a;
    --accent-ink: #0d1f17;
    --accent-soft: #1b3229;
    --danger: #f0806f;
    --danger-soft: #3a2420;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px -12px rgba(0, 0, 0, .5);

    --rose-bg: #3a2530; --rose-line: #4a2e3c; --rose-ink: #f5b8cf;
    --sky-bg: #222c42;  --sky-line: #2c3853;  --sky-ink: #b5c8f7;
    --stone-bg: #26262a; --stone-line: #333338; --stone-ink: #d4d3cf;
    --mint-bg: #213425; --mint-line: #2b4330; --mint-ink: #b6e3a8;
    --sand-bg: #372e1d; --sand-line: #463a24; --sand-ink: #efd28f;
    --lilac-bg: #2e2640; --lilac-line: #3a3052; --lilac-ink: #d3c2f5;
  }
}

* { box-sizing: border-box; }

html, body, #root { height: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* --- buttons and fields -------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 34px; padding: 0 14px; font-size: 13.5px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--panel); color: var(--ink-2);
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--sunken); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 500; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; padding: 0;
  border: 0; border-radius: var(--radius-s);
  background: transparent; color: currentColor; cursor: pointer;
}
.icon-btn:hover { background: rgba(127, 127, 127, .12); }
.icon-btn svg, .btn svg { width: 18px; height: 18px; flex: none; }

svg.i { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.input {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-s);
  background: var(--panel); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 8px 12px; resize: vertical; min-height: 76px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: var(--muted); }

.search {
  position: relative; flex: 1; max-width: 360px;
}
.search .input { height: 34px; font-size: 13.5px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.search .input { padding-left: 34px; background: var(--sunken); border-color: var(--line); }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 6px;
  font-size: 12px; font-weight: 500; line-height: 18px;
  background: var(--sunken); color: var(--ink-2);
}
.chip-green { background: var(--accent-soft); color: var(--accent); }
.chip-outline { background: transparent; border: 1px solid var(--line-strong); }

.error {
  padding: 10px 14px; border-radius: var(--radius-s);
  background: var(--danger-soft); color: var(--danger); font-size: 14px;
}

.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  font-weight: 600; font-size: 14px;
  background: var(--sunken); color: var(--ink-2);
  border: 1px solid var(--line);
}
.avatar.lg { width: 44px; height: 44px; font-size: 17px; }
.avatar.sm { width: 28px; height: 28px; font-size: 12px; }

/* --- launcher ------------------------------------------------------------ */

.launcher {
  min-height: 100%; display: grid; place-items: center; padding: 48px 16px;
}
.launcher-inner { width: 100%; max-width: 920px; }
.launcher-head { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.launcher-head h1 { margin: 0; font-size: 28px; letter-spacing: -.02em; }
.launcher-head p { margin: 2px 0 0; color: var(--muted); }
.brand-mark { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.brand-mark svg { width: 22px; height: 22px; }

.launch-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }
.launch-card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 10px; border-radius: var(--radius-xl);
  text-decoration: none; border: 1px solid;
  transition: transform .15s, box-shadow .15s;
}
.launch-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.launch-card .lc-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 0; font-size: 20px; font-weight: 500; }
.launch-card .lc-body { flex: 1; background: var(--panel); border-radius: var(--radius-l); padding: 22px 24px 24px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.launch-card .lc-body h2 { margin: 12px 0 6px; font-size: 24px; letter-spacing: -.02em; }
.launch-card .lc-body p { margin: 0 0 16px; color: var(--ink-2); }
.launch-card .lc-go { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; color: var(--accent); }

/* --- pastel themes ------------------------------------------------------- */

.t-rose  { background: var(--rose-bg);  border-color: var(--rose-line);  --t-ink: var(--rose-ink); }
.t-sky   { background: var(--sky-bg);   border-color: var(--sky-line);   --t-ink: var(--sky-ink); }
.t-stone { background: var(--stone-bg); border-color: var(--stone-line); --t-ink: var(--stone-ink); }
.t-mint  { background: var(--mint-bg);  border-color: var(--mint-line);  --t-ink: var(--mint-ink); }
.t-sand  { background: var(--sand-bg);  border-color: var(--sand-line);  --t-ink: var(--sand-ink); }
.t-lilac { background: var(--lilac-bg); border-color: var(--lilac-line); --t-ink: var(--lilac-ink); }
[class*="t-"] .t-title { color: var(--t-ink); }
.avatar[class*="t-"] { color: var(--t-ink); }

/* --- auth (two-panel card) ---------------------------------------------- */

.auth {
  min-height: 100%; display: grid; place-items: center; padding: 32px 16px;
}
.auth-card {
  width: 100%; max-width: 820px;
  display: grid; grid-template-columns: 1fr 1.15fr;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-xl); box-shadow: var(--shadow); overflow: hidden;
}
.auth-side { padding: 28px; display: flex; flex-direction: column; gap: 18px; border-right: 1px solid var(--line); }
.auth-side h1 { margin: 6px 0 4px; font-size: 22px; font-weight: 500; letter-spacing: -.01em; }
.auth-side p { margin: 0; color: var(--muted); }
.auth-status {
  display: flex; gap: 12px; align-items: center;
  padding: 14px; border-radius: var(--radius-m);
  background: var(--panel); border: 1px solid var(--line);
}
.auth-status .tick { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.auth-status .tick svg { width: 18px; height: 18px; }
.auth-status b { display: block; font-weight: 500; }
.auth-tabs { margin-top: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.auth-tabs .btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.auth-main { padding: 24px; background: var(--canvas); display: grid; gap: 12px; align-content: start; }
.auth-panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-l);
  padding: 18px 20px; display: grid; gap: 14px;
}
.auth-panel-head { display: flex; gap: 12px; align-items: flex-start; }
.auth-panel-head .ico { width: 36px; height: 36px; border-radius: 50%; background: var(--sunken); display: grid; place-items: center; flex: none; color: var(--accent); }
.auth-panel-head .ico svg { width: 18px; height: 18px; }
.auth-panel-head b { font-weight: 500; }
.auth-panel-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

@media (max-width: 720px) {
  .auth-card { grid-template-columns: 1fr; }
  .auth-side { border-right: 0; border-bottom: 1px solid var(--line); }
}

/* --- app shell: top bar + (recent chats | conversation) ------------------- */

.app {
  height: 100%; display: grid; grid-template-rows: 52px minmax(0, 1fr);
  background: var(--panel);
}

.topbar {
  display: flex; align-items: center; gap: 6px; padding: 0 12px 0 10px;
  border-bottom: 1px solid var(--line); background: var(--panel); min-width: 0;
}
.topbar .spacer { flex: 1; }
.menu-toggle { display: none; }

.ws {
  display: inline-flex; align-items: center; gap: 8px; min-width: 0; max-width: min(280px, 55vw);
  height: 36px; padding: 0 8px 0 5px; border: 0; border-radius: var(--radius-s);
  background: none; cursor: pointer; font-weight: 600; font-size: 15px; letter-spacing: -.01em;
}
.ws:hover, .ws[aria-expanded="true"] { background: var(--sunken); }
.ws .mark {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
  background: var(--accent); color: var(--accent-ink);
}
.ws .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws svg { width: 14px; height: 14px; flex: none; color: var(--muted); }

.top-actions { display: flex; align-items: center; gap: 2px; }
.top-actions .icon-btn { color: var(--ink-2); }
.top-actions .icon-btn[aria-current="page"] { background: var(--sunken); color: var(--ink); }

.body { display: grid; grid-template-columns: 288px minmax(0, 1fr); min-height: 0; }

/* --- recent chats ---------------------------------------------------------- */

.side {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-right: 1px solid var(--line);
}
.side-tools { display: flex; gap: 8px; padding: 12px 12px 8px; }
.side-tools .search { flex: 1; max-width: none; }
.side-tools .new {
  width: 34px; height: 34px; flex: none;
  background: var(--accent); color: var(--accent-ink);
}
.side-tools .new:hover { background: var(--accent); filter: brightness(1.1); }
.side-title { margin: 0; padding: 8px 18px 4px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.chat-list { flex: 1; overflow-y: auto; padding: 2px 8px 12px; display: grid; align-content: start; gap: 1px; }
.chat-item {
  display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px;
  border-radius: var(--radius-s); text-decoration: none; color: inherit;
}
.chat-item:hover { background: var(--sunken); }
.chat-item.active { background: var(--accent-soft); }
.chat-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.chat-item .avatar { width: 32px; height: 32px; font-size: 13px; }
.ci-main { min-width: 0; flex: 1; }
.ci-top { display: flex; align-items: baseline; gap: 8px; }
.ci-title { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-time { flex: none; font-size: 11.5px; color: var(--muted); }
.ci-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list .empty { padding: 32px 12px; font-size: 13px; }
.chat-list .empty h2 { font-size: 14px; }

/* --- main column ------------------------------------------------------------ */

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); }
.main-head {
  display: flex; align-items: center; gap: 12px; min-height: 56px;
  padding: 8px 20px; border-bottom: 1px solid var(--line);
}
.main-head .t { flex: 1; min-width: 0; }
.main-head h1 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main-head p { margin: 0; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main-body { flex: 1; overflow-y: auto; padding: 16px 20px 28px; }

.convo { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.convo .main-body { display: flex; flex-direction: column; }
.thread { flex: 1; display: flex; flex-direction: column; gap: 2px; max-width: 760px; width: 100%; margin: 0 auto; }
.thread .older { align-self: center; margin-bottom: 12px; }
.day { align-self: center; margin: 14px 0 6px; font-size: 11.5px; color: var(--muted); padding: 1px 10px; border-radius: 999px; background: var(--sunken); }

.msg { display: flex; gap: 10px; padding: 4px 0; }
.msg .avatar { margin-top: 2px; }
.msg.cont .avatar { visibility: hidden; height: 0; }
.msg .col { min-width: 0; max-width: min(560px, 80%); display: grid; gap: 3px; }
.msg .who { font-size: 12px; color: var(--muted); }
.msg .who b { color: var(--ink); font-weight: 500; margin-right: 6px; }
.msg.cont .who { display: none; }
.bubble {
  padding: 8px 12px; border-radius: 4px var(--radius-m) var(--radius-m) var(--radius-m);
  background: var(--sunken); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.45;
}
.bubble.image { padding: 5px; }
.bubble.image img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; }
.bubble.image .cap { padding: 6px 7px 2px; }
.bubble.image a { font-size: 12.5px; color: var(--muted); padding: 6px 7px 2px; display: inline-block; overflow-wrap: anywhere; }
.msg.mine { flex-direction: row-reverse; }
.msg.mine .col { justify-items: end; }
.msg.mine .bubble { background: var(--accent); color: var(--accent-ink); border-radius: var(--radius-m) 4px var(--radius-m) var(--radius-m); }
.msg.mine .bubble.image a, .msg.mine .bubble.image .cap { color: inherit; }
.msg.bot .bubble { background: var(--mint-bg); color: var(--ink); }
/* Reply quotes, WhatsApp style: a tinted block inside the bubble with the
   quoted author's colour as a bar and name. --t-ink comes from the t-* theme. */
.bubble .body { display: block; }
.bubble .quote, .reply-bar .quote {
  display: flex; align-items: stretch; gap: 8px; width: 100%; min-width: 0;
  margin: 0; padding: 5px 8px 5px 9px; border: 0; border-left: 3px solid var(--t-ink, var(--accent));
  border-radius: 8px; background: rgba(24, 24, 27, .06); color: inherit;
  font: inherit; font-size: 12.5px; line-height: 1.35; text-align: left; white-space: normal;
}
.bubble .quote { margin-bottom: 6px; cursor: pointer; }
.bubble.image .quote { margin: 0 0 5px; }
.bubble button.quote:hover { background: rgba(24, 24, 27, .1); }
.quote .q-main { flex: 1; min-width: 0; display: grid; gap: 1px; }
.quote .q-who { color: var(--t-ink, var(--accent)); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quote .q-text {
  opacity: .8; white-space: pre-wrap; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.quote .q-text svg { width: 13px; height: 13px; vertical-align: -2px; margin-right: 4px; }
.quote .q-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; flex: none; align-self: center; }
.msg.mine .bubble .quote { background: rgba(255, 255, 255, .18); border-left-color: rgba(255, 255, 255, .75); }
.msg.mine .bubble button.quote:hover { background: rgba(255, 255, 255, .26); }
.msg.mine .bubble .quote .q-who { color: inherit; }
@media (prefers-color-scheme: dark) {
  .bubble .quote, .reply-bar .quote { background: rgba(255, 255, 255, .07); }
}

/* The message a quote was clicked for flashes once. */
.msg.flash .bubble { animation: flash 1.4s ease-out; }
@keyframes flash { 0%, 30% { box-shadow: 0 0 0 3px var(--accent-soft), 0 0 0 5px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .msg.flash .bubble { animation: none; outline: 2px solid var(--accent); } }

/* Swipe right to reply on touch screens: the arrow shows behind the message. */
.msg { position: relative; }
.msg .col { transition: transform .15s ease-out; }
.swipe-hint {
  position: absolute; left: 0; top: 50%; transform: translateY(-50%) scale(.6); opacity: 0;
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 999px;
  background: var(--sunken); color: var(--muted); pointer-events: none; transition: opacity .12s, transform .12s;
}
.swipe-hint svg { width: 15px; height: 15px; }
.msg.swiping .swipe-hint { opacity: 1; transform: translateY(-50%) scale(1); color: var(--accent); }

/* The reply bar above the composer's text names the message being answered. */
.reply-bar { display: flex; align-items: center; gap: 6px; padding-top: 2px; }
.reply-bar[hidden] { display: none; }
.reply-bar .quote { flex: 1; }
.reply-bar .icon-btn { width: 28px; height: 28px; color: var(--muted); flex: none; }
.reply-bar .icon-btn:hover { color: var(--ink); }

/* Per-message actions: shown on hover (always on touch screens). */
.msg-tools { display: flex; gap: 4px; opacity: 0; transition: opacity .12s; }
.msg:hover .msg-tools, .msg-tools:focus-within, .msg-tool.busy { opacity: 1; }
@media (hover: none) { .msg-tools { opacity: 1; } }
.msg-tool {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); color: var(--muted); font: inherit; font-size: 12px; cursor: pointer;
}
.msg-tool:hover { color: var(--ink); border-color: var(--line-strong); }
.msg-tool svg { width: 13px; height: 13px; }
.msg-tool.icon-only { padding: 2px 6px; }
.msg-tool:disabled { cursor: progress; }
.msg-tool.busy svg { animation: pulse 1s ease-in-out infinite; color: var(--accent); }
@keyframes pulse { 50% { opacity: .3; } }

.composer-wrap { padding: 10px 20px 16px; background: var(--panel); }
.composer {
  max-width: 760px; margin: 0 auto;
  border: 1px solid var(--line-strong); border-radius: var(--radius-l);
  background: var(--panel); padding: 8px 8px 8px 14px;
  display: grid; gap: 4px;
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea { border: 0; outline: none; resize: none; background: transparent; padding: 4px 0; min-height: 22px; max-height: 180px; font-size: 14px; }
.composer .link-row { display: flex; gap: 8px; align-items: center; }
.composer .link-row .input { height: 32px; font-size: 13px; }
.composer .row { display: flex; align-items: center; gap: 4px; }
.composer .row .spacer { flex: 1; }
.composer .row .icon-btn { width: 30px; height: 30px; color: var(--muted); }
.composer .row .icon-btn:hover { color: var(--ink); }
.composer .row .btn { height: 32px; padding: 0 14px; font-size: 13.5px; }
.composer .hint { font-size: 11.5px; color: var(--muted); margin-left: 6px; }
.composer .icon-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.composer .row .icon-btn:disabled { opacity: .35; cursor: default; background: none; color: var(--muted); }
.composer .icon-btn.mic.recording { background: var(--danger); color: #fff; animation: mic-pulse 1.4s ease-in-out infinite; }
@keyframes mic-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(214, 69, 69, .45); } 50% { box-shadow: 0 0 0 6px rgba(214, 69, 69, 0); } }
@media (prefers-reduced-motion: reduce) { .composer .icon-btn.mic.recording { animation: none; } }

.blank { height: 100%; display: grid; place-content: center; justify-items: center; gap: 6px; text-align: center; padding: 24px; color: var(--muted); }
.blank h2 { margin: 6px 0 0; font-size: 16px; font-weight: 600; color: var(--ink); }
.blank p { margin: 0 0 10px; max-width: 320px; }
.blank .ico { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.blank .ico svg { width: 20px; height: 20px; }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty h2 { color: var(--ink); font-weight: 600; font-size: 16px; margin: 0 0 6px; }

.scrim { display: none; position: fixed; inset: 52px 0 0 0; background: rgba(0,0,0,.25); z-index: 20; }

@media (max-width: 860px) {
  .menu-toggle { display: inline-grid; }
  .body { grid-template-columns: 1fr; }
  .side {
    position: fixed; top: 52px; bottom: 0; left: 0; width: 300px; max-width: 88vw; z-index: 30;
    transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow);
  }
  body.drawer .side { transform: none; }
  body.drawer .scrim { display: block; }
  .main-head { padding: 8px 14px; }
  .main-body { padding: 12px 14px 24px; }
  .composer-wrap { padding: 8px 12px 12px; }
  .composer .hint { display: none; }
}

/* --- popover menu ---------------------------------------------------------- */

.menu {
  position: fixed; z-index: 50; min-width: 200px; max-width: 280px; padding: 5px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m);
  box-shadow: var(--shadow); font-size: 14px;
}
.menu button, .menu a {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 7px 10px; border: 0; border-radius: 8px; background: none; cursor: pointer;
  text-align: left; text-decoration: none; color: inherit;
}
.menu button:hover, .menu a:hover { background: var(--sunken); }
.menu button.danger { color: var(--danger); }
.menu svg { width: 16px; height: 16px; flex: none; }
.menu .label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu .menu-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu .menu-head .n { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu .menu-head .e { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu .menu-title { padding: 6px 10px 4px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.menu .tick { color: var(--accent); }

/* --- settings -------------------------------------------------------------- */

.settings { max-width: 760px; margin: 0 auto; display: grid; gap: 16px; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-l);
  padding: 20px; display: grid; gap: 14px;
}
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.panel-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.invite { display: flex; gap: 8px; }
.invite .input { flex: 1; }
.people { display: grid; gap: 2px; }
.person { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.person:first-child { border-top: 0; }
.person .avatar { width: 34px; height: 34px; font-size: 14px; }
.person .who { flex: 1; min-width: 0; }
.person .who .n { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person .who .e { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-select {
  border: 0; background: transparent; color: var(--muted); font-weight: 500; font-size: 13px;
  padding: 4px 2px; cursor: pointer; border-radius: 6px;
}
.role-select:hover { color: var(--ink); background: var(--sunken); }
.role-label { color: var(--muted); font-weight: 500; font-size: 13px; }
.acct-list { display: grid; gap: 6px; }
.acct-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-m); }
.acct-row .avatar { width: 30px; height: 30px; font-size: 13px; }
.acct-row .grow { flex: 1; min-width: 0; }
.acct-row .grow span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- dialog -------------------------------------------------------------- */

dialog.modal {
  width: min(460px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line);
  border-radius: var(--radius-l); background: var(--panel); color: var(--ink);
  box-shadow: var(--shadow);
}
dialog.modal::backdrop { background: rgba(20, 20, 22, .35); backdrop-filter: blur(2px); }
.modal form { padding: 24px; display: grid; gap: 16px; }
.modal h2 { margin: 0; font-size: 18px; font-weight: 500; }
.modal p { margin: -8px 0 0; color: var(--muted); }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; }

/* --- toasts (static/toast.js, shared with the stock app) -------------------
   The same stacking toaster as app.css, on this app's colour tokens. */

.toaster {
  position: fixed; right: 24px; bottom: 24px; z-index: 1000; width: 356px;
  margin: 0; padding: 0; list-style: none; transition: height .4s ease;
}
.toast {
  position: absolute; right: 0; bottom: 0; left: 0;
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; overflow: hidden;
  --toast-tone: var(--muted);
  background: color-mix(in srgb, var(--toast-tone) 8%, var(--panel)); color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--toast-tone) 40%, var(--line-strong));
  border-radius: var(--radius-m); box-shadow: 0 6px 18px rgba(24, 24, 27, .16);
  font-size: 14px; line-height: 1.35; opacity: 0; transform-origin: center bottom;
  transition: transform .4s cubic-bezier(.21, 1.02, .73, 1), opacity .4s, height .4s;
  touch-action: pan-y; user-select: none;
}
.toast[data-mounted="true"] { opacity: 1; }
.toast[data-hidden="true"], .toast[data-removed="true"] { opacity: 0; pointer-events: none; }
.toast[data-swiping="true"] { transition: none; }
/* Older cards in the collapsed deck show only their edge. */
.toast[data-front="false"][data-expanded="false"] > * { opacity: 0; }
.toast > * { transition: opacity .4s; }
/* Bridges the gap to the next toast so moving between them keeps the stack open. */
.toast::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 15px; }
.toast-icon { flex: none; display: flex; width: 18px; height: 18px; }
.toast-icon svg { width: 100%; height: 100%; }
/* Each type tints the card's background and border via --toast-tone. */
.toast[data-type="success"] { --toast-tone: var(--accent); }
.toast[data-type="error"] { --toast-tone: var(--danger); }
.toast[data-type="info"] { --toast-tone: var(--muted); }
.toast-icon { color: var(--toast-tone); }
.toast-text { flex: 1; min-width: 0; }
.toast-title { font-weight: 500; overflow-wrap: anywhere; }
.toast-desc { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.toast-close {
  flex: none; padding: 0 3px; border: 0; background: none; color: var(--muted);
  font-size: 12px; cursor: pointer; opacity: 0;
}
.toast:hover .toast-close, .toast-close:focus-visible { opacity: 1; }
@media (max-width: 600px) {
  .toaster { right: 16px; left: 16px; bottom: 16px; width: auto; }
  .toast-close { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .toaster, .toast, .toast > * { transition: none; }
}

.spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; margin: 48px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- palettes ---------------------------------------------------------------
   "classic" is the default set of variables above. "signage" is selected with
   <html data-palette="signage"> and comes from the signage reference: cool
   grey surfaces, slate-navy ink and a navy-blue accent, with squarer corners.
   Every text/background pair below meets WCAG AA (4.5:1 for text, 3:1 for
   input borders); keep it that way when changing a value. */

:root[data-palette="signage"] {
  --canvas: #e9eaee;
  --surface: #f1f2f5;
  --panel: #fbfbfc;
  --sunken: #eceef3;
  --line: #d8dbe3;
  --line-strong: #868ca1;
  --ink: #232a3f;
  --ink-2: #3d4457;
  --muted: #596075;
  --accent: #3a4a82;
  --accent-ink: #ffffff;
  --accent-soft: #dde2f1;
  --danger: #a1352b;
  --danger-soft: #f3dedb;
  --shadow: 0 1px 2px rgba(35, 42, 63, .06), 0 12px 32px -12px rgba(35, 42, 63, .18);
  --radius-xl: 18px;
  --radius-l: 12px;
  --radius-m: 9px;
  --radius-s: 7px;

  --rose-bg: #efe3e7;  --rose-line: #e0cfd5;  --rose-ink: #5a2e3f;
  --sky-bg: #dfe5f4;   --sky-line: #cdd5ea;   --sky-ink: #26346a;
  --stone-bg: #e6e7eb; --stone-line: #d6d8de; --stone-ink: #3d4457;
  --mint-bg: #dbe9ee;  --mint-line: #c8dbe2;  --mint-ink: #1d4553;
  --sand-bg: #f0e9d8;  --sand-line: #e1d8c0;  --sand-ink: #5a4515;
  --lilac-bg: #e6e1f3; --lilac-line: #d6cfe9; --lilac-ink: #3f3470;
}

@media (prefers-color-scheme: dark) {
  :root[data-palette="signage"] {
    --canvas: #1c2136;
    --surface: #222842;
    --panel: #282f4b;
    --sunken: #323a5c;
    --line: #3b4468;
    --line-strong: #6c77a6;
    --ink: #eceef4;
    --ink-2: #d3d6e2;
    --muted: #aeb3c8;
    --accent: #a3b3f2;
    --accent-ink: #11162b;
    --accent-soft: #363f6a;
    --danger: #f59a8d;
    --danger-soft: #432a30;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px -12px rgba(0, 0, 0, .5);

    --rose-bg: #4a3040;  --rose-line: #5b3d4f;  --rose-ink: #f3c4d5;
    --sky-bg: #34416e;   --sky-line: #425084;   --sky-ink: #c9d3f7;
    --stone-bg: #3a4263; --stone-line: #49527a; --stone-ink: #d9dbe6;
    --mint-bg: #2f4a52;  --mint-line: #3c5b64;  --mint-ink: #bfe3dc;
    --sand-bg: #4a4333;  --sand-line: #5c5441;  --sand-ink: #ecdba8;
    --lilac-bg: #403a6c; --lilac-line: #504a82; --lilac-ink: #d8d0f6;
  }
}

/* Signage details: square-ish tags instead of pills and circles. The open chat
   is a soft tinted row with an accent bar, and light bubbles get a hairline so
   they stand out from the panel. */
:root[data-palette="signage"] .btn { border-radius: var(--radius-s); }
:root[data-palette="signage"] .avatar { border-radius: var(--radius-s); }
:root[data-palette="signage"] .chip { border-radius: 4px; }
:root[data-palette="signage"] .ws .mark { border-radius: 6px; }
:root[data-palette="signage"] .day { border-radius: 4px; }
:root[data-palette="signage"] .composer { border-radius: var(--radius-m); }
:root[data-palette="signage"] .chat-item.active { box-shadow: inset 3px 0 0 var(--accent); }
:root[data-palette="signage"] .msg:not(.mine) .bubble { border: 1px solid var(--line); }
:root[data-palette="signage"] .msg.bot .bubble { color: var(--ink); }

/* "studio": from the chat-view reference. A light grey page, white panels, soft
   grey-blue bubbles and one bright blue accent. The blue is a shade deeper than
   the reference (#3082ff) so white text on it passes WCAG AA. */

:root[data-palette="studio"] {
  --canvas: #e8e9eb;
  --surface: #ffffff;
  --panel: #ffffff;
  --sunken: #f6f7fb;
  --line: #e4e7ed;
  --line-strong: #8a93a6;
  --ink: #1f2430;
  --ink-2: #3a4252;
  --muted: #5b6474;
  --accent: #2a6ae8;
  --accent-ink: #ffffff;
  --accent-soft: #e8f0fe;
  --danger: #b4372a;
  --danger-soft: #fbeae7;
  --shadow: 0 1px 2px rgba(31, 36, 48, .05), 0 12px 32px -12px rgba(31, 36, 48, .16);
  --radius-xl: 20px;
  --radius-l: 16px;
  --radius-m: 12px;
  --radius-s: 8px;

  --rose-bg: #fde8ee;  --rose-line: #f3cfdc;  --rose-ink: #8a1f4a;
  --sky-bg: #e3eeff;   --sky-line: #cfe0fb;   --sky-ink: #1d4fa0;
  --stone-bg: #eef0f4; --stone-line: #dfe2e9; --stone-ink: #3a4252;
  --mint-bg: #e1f6e8;  --mint-line: #c9ecd6;  --mint-ink: #1f6a3d;
  --sand-bg: #fdf3d3;  --sand-line: #f2e3b0;  --sand-ink: #7a5212;
  --lilac-bg: #ece6fb; --lilac-line: #ddd3f5; --lilac-ink: #4e2a8a;
}

@media (prefers-color-scheme: dark) {
  :root[data-palette="studio"] {
    --canvas: #0f1218;
    --surface: #151922;
    --panel: #1a1f2b;
    --sunken: #232a38;
    --line: #2b3243;
    --line-strong: #6b7690;
    --ink: #e9ecf3;
    --ink-2: #cdd2de;
    --muted: #9ba4b7;
    --accent: #5b9bff;
    --accent-ink: #08122b;
    --accent-soft: #1f3358;
    --danger: #f59a8d;
    --danger-soft: #3a2425;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 12px 32px -12px rgba(0, 0, 0, .6);

    --rose-bg: #3d2634;  --rose-line: #4d3243;  --rose-ink: #f5b8cf;
    --sky-bg: #1f3358;   --sky-line: #2a4470;   --sky-ink: #b5ceff;
    --stone-bg: #2a3140; --stone-line: #363e50; --stone-ink: #cdd2de;
    --mint-bg: #1f3a2c;  --mint-line: #2a4a39;  --mint-ink: #aee3c0;
    --sand-bg: #3b3220;  --sand-line: #4a402a;  --sand-ink: #efd28f;
    --lilac-bg: #31294d; --lilac-line: #3f3660; --lilac-ink: #d3c2f5;
  }
}

/* Studio details: rounded-rect buttons, a bordered sidebar and soft bubbles. */
:root[data-palette="studio"] .btn { border-radius: var(--radius-s); }
:root[data-palette="studio"] .side { background: var(--surface); }
:root[data-palette="studio"] .msg:not(.mine) .bubble { border: 1px solid var(--line); }
:root[data-palette="studio"] .msg.bot .bubble { background: var(--accent-soft); color: var(--ink); border-color: transparent; }
:root[data-palette="studio"] .chat-item.active { background: var(--accent-soft); }
:root[data-palette="studio"] .search .input { background: var(--sunken); border-color: var(--line); }

/* "inbox": from the multichannel inbox reference. A periwinkle page, white
   panels on a near-white ground, an indigo accent and pale-blue bubbles for
   your own messages. Text/background pairs meet WCAG AA. */

:root[data-palette="inbox"] {
  --canvas: #d9deef;
  --surface: #f7f8fb;
  --panel: #ffffff;
  --sunken: #f3f5f9;
  --line: #e6e9f0;
  --line-strong: #8b93a7;
  --ink: #1d2433;
  --ink-2: #3b4354;
  --muted: #5f6878;
  --accent: #4450d4;
  --accent-ink: #ffffff;
  --accent-soft: #e8f0fd;
  --danger: #b4372a;
  --danger-soft: #fbeae7;
  --shadow: 0 1px 2px rgba(29, 36, 51, .04), 0 16px 40px -16px rgba(68, 80, 212, .18);
  --radius-xl: 24px;
  --radius-l: 16px;
  --radius-m: 12px;
  --radius-s: 8px;

  --rose-bg: #fde8ee;  --rose-line: #f3cfdc;  --rose-ink: #8a1f4a;
  --sky-bg: #e3edfd;   --sky-line: #cfdffb;   --sky-ink: #1f4796;
  --stone-bg: #eff1f5; --stone-line: #e0e3ea; --stone-ink: #3b4354;
  --mint-bg: #e0f5e7;  --mint-line: #c8ebd4;  --mint-ink: #1d6a3b;
  --sand-bg: #fdf2d6;  --sand-line: #f2e2b2;  --sand-ink: #7a5212;
  --lilac-bg: #e9e8fc; --lilac-line: #d7d5f6; --lilac-ink: #3d3a9a;
}

@media (prefers-color-scheme: dark) {
  :root[data-palette="inbox"] {
    --canvas: #161a2b;
    --surface: #1b2033;
    --panel: #212739;
    --sunken: #2a3146;
    --line: #323a52;
    --line-strong: #6d7695;
    --ink: #eceef6;
    --ink-2: #d0d4e2;
    --muted: #a2a9be;
    --accent: #8f98f5;
    --accent-ink: #12153a;
    --accent-soft: #283a5e;
    --danger: #f59a8d;
    --danger-soft: #3a2425;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 16px 40px -16px rgba(0, 0, 0, .6);

    --rose-bg: #3d2634;  --rose-line: #4d3243;  --rose-ink: #f5b8cf;
    --sky-bg: #233459;   --sky-line: #2e4270;   --sky-ink: #b9cdfb;
    --stone-bg: #2b3246; --stone-line: #383f56; --stone-ink: #d0d4e2;
    --mint-bg: #1f3a2c;  --mint-line: #2a4a39;  --mint-ink: #aee3c0;
    --sand-bg: #3b3220;  --sand-line: #4a402a;  --sand-ink: #efd28f;
    --lilac-bg: #2e2c58; --lilac-line: #3b386c; --lilac-ink: #cfccf8;
  }
}

/* Inbox details: own messages are soft blue with dark text, others are white
   cards with a hairline, the open chat is a tinted row. */
:root[data-palette="inbox"] .btn { border-radius: var(--radius-s); }
:root[data-palette="inbox"] .msg.mine .bubble { background: var(--accent-soft); color: var(--ink); }
:root[data-palette="inbox"] .msg:not(.mine) .bubble { background: var(--panel); border: 1px solid var(--line); }
:root[data-palette="inbox"] .msg.bot .bubble { background: var(--lilac-bg); color: var(--ink); border-color: transparent; }
:root[data-palette="inbox"] .chat-item.active { background: var(--accent-soft); }
:root[data-palette="inbox"] .day { background: var(--panel); border: 1px solid var(--line); }
:root[data-palette="inbox"] .search .input { background: var(--sunken); border-color: var(--line); }

/* palette picker: swatches in the menu and the settings cards */
.swatch {
  width: 20px; height: 20px; flex: none; border-radius: 6px; border: 1px solid var(--line-strong);
}
.sw-classic { background: linear-gradient(135deg, #0b7a55 0 50%, #f4f3f0 50% 100%); }
.sw-signage { background: linear-gradient(135deg, #3a4a82 0 50%, #e9eaee 50% 100%); }
.sw-studio { background: linear-gradient(135deg, #2a6ae8 0 50%, #e8e9eb 50% 100%); }
.sw-inbox { background: linear-gradient(135deg, #4450d4 0 50%, #d9deef 50% 100%); }
.palettes { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.palette {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; text-align: left; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--panel);
}
.palette:hover { background: var(--sunken); }
.palette[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.palette .swatch { width: 32px; height: 32px; border-radius: 8px; }
.palette b { display: block; font-weight: 500; }
.palette span.d { display: block; font-size: 12.5px; color: var(--muted); }

/* --- prompts ------------------------------------------------------------- */
.notice {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border-radius: var(--radius-m);
  background: var(--sand-bg); color: var(--sand-ink); border: 1px solid var(--sand-line);
}
.notice > span { flex: 1; min-width: 200px; }
.prompt-list { display: grid; }
.prompt { padding: 12px 0; border-top: 1px solid var(--line); display: grid; gap: 6px; }
.prompt:first-child { border-top: 0; padding-top: 0; }
.prompt-top { display: flex; align-items: flex-start; gap: 8px; }
.prompt-top .grow { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.prompt-tools { display: flex; gap: 2px; }
.prompt-content {
  margin: 0; color: var(--ink-2); font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
dialog.modal.wide { width: min(640px, calc(100vw - 32px)); }
.modal .field small { font-size: 12px; }
