/* Frankchat styles.
   Brand: #253031 slate · #315659 deep teal · #2978a0 blue · #bcab79 sand · #c6e0ff sky
   Tokens are defined on :root and redefined for dark mode. Components only use tokens. */

@font-face { font-family: "Source Sans 3"; font-weight: 400; font-style: normal; font-display: swap; src: url(/static/fonts/source-sans-3-400.woff2) format("woff2"); }
@font-face { font-family: "Source Sans 3"; font-weight: 400; font-style: italic; font-display: swap; src: url(/static/fonts/source-sans-3-400-italic.woff2) format("woff2"); }
@font-face { font-family: "Source Sans 3"; font-weight: 600; font-style: normal; font-display: swap; src: url(/static/fonts/source-sans-3-600.woff2) format("woff2"); }
@font-face { font-family: "Source Sans 3"; font-weight: 700; font-style: normal; font-display: swap; src: url(/static/fonts/source-sans-3-700.woff2) format("woff2"); }
@font-face { font-family: "Source Code Pro"; font-weight: 400; font-display: swap; src: url(/static/fonts/source-code-pro-400.woff2) format("woff2"); }
@font-face { font-family: "Source Code Pro"; font-weight: 600; font-display: swap; src: url(/static/fonts/source-code-pro-600.woff2) format("woff2"); }

:root {
  --slate: #253031; --teal: #315659; --blue: #2978a0; --sand: #bcab79; --sky: #c6e0ff;

  --bg: #eef4fa;
  --surface: #ffffff;
  --surface-2: #e4eef8;
  --surface-3: #d6e6f6;
  --text: #253031;
  --muted: #5a6a70;
  --border: #d3dfeb;
  --primary: #2978a0;
  --primary-hover: #236a8e;
  --on-primary: #ffffff;
  --link: #1f6a90;
  --accent: #bcab79;
  --accent-soft: #f1ecdd;
  --danger: #b03a37;
  --danger-soft: #fbe9e8;
  --ok: #2c7a57;
  --ok-soft: #e3f4ec;
  --warn-soft: #fff4d6;
  --focus: #2978a0;
  --shadow: 0 1px 2px rgb(37 48 49 / .06), 0 4px 16px rgb(37 48 49 / .08);
  --bubble-mine: #2978a0;
  --bubble-mine-text: #ffffff;
  --bubble-other: #ffffff;
  --bubble-other-text: #253031;
  --code-bg: #f3f7fb;
  --glow-1: #c6e0ff;
  --glow-2: rgb(188 171 121 / .35);

  --radius: 14px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --font: "Source Sans 3", "Source Sans Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Source Code Pro", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a2223; --surface: #253031; --surface-2: #2c3a3b; --surface-3: #33474a; --text: #e6eef5;
    --muted: #9db0b6; --border: #36484a; --primary: #2978a0; --primary-hover: #318bb8; --link: #9ccbff;
    --accent-soft: #3a3829; --danger: #f08a86; --danger-soft: #45282a; --ok: #7fd1a8; --ok-soft: #21392f;
    --warn-soft: #3d3622; --focus: #c6e0ff; --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 16px rgb(0 0 0 / .25);
    --bubble-other: #315659; --bubble-other-text: #eef5fb; --code-bg: #1d2728;
    --glow-1: rgb(41 120 160 / .45); --glow-2: rgb(49 86 89 / .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1a2223; --surface: #253031; --surface-2: #2c3a3b; --surface-3: #33474a; --text: #e6eef5;
  --muted: #9db0b6; --border: #36484a; --primary: #2978a0; --primary-hover: #318bb8; --link: #9ccbff;
  --accent-soft: #3a3829; --danger: #f08a86; --danger-soft: #45282a; --ok: #7fd1a8; --ok-soft: #21392f;
  --warn-soft: #3d3622; --focus: #c6e0ff; --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 16px rgb(0 0 0 / .25);
  --bubble-other: #315659; --bubble-other-text: #eef5fb; --code-bg: #1d2728;
  --glow-1: rgb(41 120 160 / .45); --glow-2: rgb(49 86 89 / .6);
  color-scheme: dark;
}

/* --- base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 400 16px/1.5 var(--font); color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0; font-weight: 600; }
h1 { font-size: 1.75rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.05rem; }
p { margin: 0; }
a, .link { color: var(--link); text-decoration: none; }
a:hover, .link:hover { text-decoration: underline; }
code, kbd, pre { font-family: var(--mono); font-size: .9em; }
img, svg { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
::selection { background: var(--sky); color: var(--slate); }

.icon { width: 1.25em; height: 1.25em; fill: currentColor; flex: none; vertical-align: -.25em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; justify-self: center; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: .85rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* --- buttons ---------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 44px;
  padding: .55rem 1.1rem; border-radius: var(--radius-pill); border: 1px solid transparent; font: 600 1rem var(--font);
  cursor: pointer; background: var(--surface-2); color: var(--text); transition: background .15s, border-color .15s;
  text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn.outline:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--link); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; }
.btn.small { min-height: 34px; padding: .3rem .8rem; font-size: .9rem; }
.icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: transparent; color: var(--muted); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn .icon { width: 22px; height: 22px; }

/* --- forms ------------------------------------------------------------------ */
label { display: grid; gap: .3rem; font-weight: 600; font-size: .95rem; }
label .muted { font-weight: 400; }
input, select, textarea { font: 400 1rem var(--font); color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .6rem .8rem; min-height: 44px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }
input[type="checkbox"], input[type="radio"] { width: 1.15rem; height: 1.15rem; min-height: 0; accent-color: var(--primary); }
.otp { font: 600 1.6rem var(--mono); letter-spacing: .35em; text-align: center; }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; }
.inline-form input { flex: 1 1 12rem; width: auto; }
.check { display: flex; align-items: center; gap: .6rem; font-weight: 400; }
details > summary { cursor: pointer; color: var(--link); font-weight: 600; padding: .35rem 0; }
details[open] > summary { margin-bottom: .6rem; }

/* --- feedback --------------------------------------------------------------- */
.msg { padding: .6rem .85rem; border-radius: var(--radius-sm); font-size: .95rem; }
.msg.error { background: var(--danger-soft); color: var(--danger); }
.msg.ok { background: var(--ok-soft); color: var(--ok); }
.msg.warn { background: var(--warn-soft); }
.badge { display: inline-block; padding: .05rem .55rem; border-radius: var(--radius-pill); background: var(--surface-2);
  color: var(--muted); font-size: .75rem; font-weight: 600; vertical-align: middle; }
.badge.accent { background: var(--accent-soft); color: var(--text); border: 1px solid var(--accent); }
.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .85rem; margin: .25rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* --- cards & rows ----------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem;
  display: grid; gap: .8rem; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem 1rem; justify-content: space-between; }
.rows { list-style: none; margin: 0; padding: 0; display: grid; }
.row { display: flex; align-items: center; gap: .8rem; padding: .6rem 0; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }

/* --- auth pages ------------------------------------------------------------- */
.auth-page { background: radial-gradient(1200px 600px at 10% -10%, var(--glow-1), transparent 60%),
  radial-gradient(900px 500px at 110% 110%, var(--glow-2), transparent 60%), var(--bg); }
.auth { min-height: 100dvh; display: grid; place-content: center; gap: 1rem; padding: 1.5rem 1rem; }
.auth-card { width: min(420px, calc(100vw - 2rem)); background: var(--surface); border-radius: 22px; padding: 2rem 1.75rem;
  box-shadow: var(--shadow); display: grid; gap: 1.25rem; }
.brand { display: grid; justify-items: center; gap: .5rem; }
.brand h1 { color: var(--teal); letter-spacing: .01em; }
:root[data-theme="dark"] .brand h1 { color: var(--sky); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand h1 { color: var(--sky); } }
.auth-foot { text-align: center; color: var(--muted); font-size: .85rem; }
.option { display: grid; gap: .5rem; }
.totp-enroll .qr { justify-self: center; background: #fff; border-radius: var(--radius-sm); padding: 6px; }
.totp-enroll .steps { margin: 0; padding-left: 1.2rem; color: var(--muted); }
.secret { display: block; padding: .6rem; background: var(--code-bg); border-radius: var(--radius-sm); text-align: center;
  font-size: 1rem; letter-spacing: .05em; word-break: break-all; user-select: all; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ============================================================================
   App shell: chat list + main pane (two panes on wide screens, one on phones)
   ========================================================================== */
.app-page { height: 100dvh; overflow: hidden; }
.app { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; height: 100dvh; }
.sidebar { position: relative; display: flex; flex-direction: column; min-height: 0; background: var(--surface);
  border-right: 1px solid var(--border); padding-top: env(safe-area-inset-top); }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg); }

.side-head { display: flex; align-items: center; gap: .25rem; padding: .75rem .75rem .25rem 1rem; }
.me { display: flex; align-items: center; gap: .6rem; flex: 1; min-width: 0; color: var(--text); font-weight: 600;
  border-radius: var(--radius-pill); padding: .25rem .5rem .25rem .25rem; margin-left: -.25rem; }
.me:hover { background: var(--surface-2); text-decoration: none; }
.me-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-search { position: relative; margin: .4rem .9rem .5rem; }
.side-search .icon { position: absolute; left: .9rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.side-search input { border-radius: var(--radius-pill); background: var(--surface-2); border-color: transparent; padding-left: 2.6rem; }

/* colour palettes (settings) */
.palette-picker { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-top: .25rem; }
.palette-choice { display: flex; flex-wrap: wrap; gap: .4rem; }
.palette-option { display: inline-flex; align-items: center; gap: .45rem; min-height: 40px; padding: .3rem .75rem .3rem .35rem;
  border: 1px solid var(--border); border-radius: var(--radius-pill); background: var(--surface); color: var(--text);
  font: inherit; cursor: pointer; }
.palette-option:hover { background: var(--surface-2); }
.palette-option[aria-checked="true"] { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.swatch { width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--sw-main) 0 55%, var(--sw-accent) 55% 100%); }
.swatch.rainbow { background: conic-gradient(#e53935, #fb8c00, #fdd835, #43a047, #1e88e5, #8e24aa, #e53935); }
.palette-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.theme-colors { display: flex; flex-wrap: wrap; gap: 1rem; }
.theme-colors input[type="color"] { display: block; width: 88px; height: 44px; padding: 2px; margin-top: .3rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; }

/* "turn on notifications?" prompt, once per device */
.notify-prompt { display: grid; grid-template-columns: auto 1fr; gap: .35rem .7rem; align-items: start; margin: .1rem .9rem .5rem;
  padding: .75rem .85rem; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.notify-prompt-icon { color: var(--primary); padding-top: .1rem; }
.notify-prompt-text { display: grid; gap: .15rem; min-width: 0; }
.notify-prompt-actions { grid-column: 2; display: flex; flex-wrap: wrap; gap: .4rem; }
.notify-prompt-actions .btn { min-height: 36px; padding-block: .3rem; }

/* avatars: colour classes, never inline styles (CSP) */
.avatar { display: inline-grid; place-items: center; flex: none; width: 48px; height: 48px; border-radius: 50%;
  color: #fff; font-weight: 600; font-size: 1.05rem; letter-spacing: .02em; user-select: none; }
.avatar.sm { width: 32px; height: 32px; font-size: .8rem; }
.avatar.xs { width: 26px; height: 26px; font-size: .7rem; }
.avatar.c0 { background: #2978a0; } .avatar.c1 { background: #315659; } .avatar.c2 { background: #7a6a3a; }
.avatar.c3 { background: #5b5f97; } .avatar.c4 { background: #9a4a72; } .avatar.c5 { background: #3f7d4e; }
.avatar.c6 { background: #a4552f; } .avatar.c7 { background: #44708f; }

/* chat list */
.room-list { flex: 1; overflow-y: auto; padding: .25rem .5rem 6rem; overscroll-behavior: contain; }
.room-item { display: flex; gap: .8rem; align-items: center; padding: .6rem .6rem; border-radius: var(--radius);
  color: var(--text); text-decoration: none; }
.room-item:hover { background: var(--surface-2); text-decoration: none; }
.room-item.active { background: color-mix(in srgb, var(--sky) 55%, var(--surface)); }
:root[data-theme="dark"] .room-item.active { background: var(--surface-3); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .room-item.active { background: var(--surface-3); } }
.room-text { flex: 1; min-width: 0; display: grid; gap: .1rem; }
.room-top, .room-bottom { display: flex; align-items: center; gap: .35rem; min-width: 0; }
.room-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-top .lock .icon { width: 14px; height: 14px; color: var(--muted); }
.room-time { margin-left: auto; color: var(--muted); font-size: .8rem; flex: none; }
.room-preview { flex: 1; min-width: 0; color: var(--muted); font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-preview .who { color: var(--text); opacity: .8; }
.room-item.has-draft .room-preview { display: none; }
.room-draft { flex: 1; min-width: 0; color: var(--muted); font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.draft-tag { color: var(--danger); font-weight: 600; }
.unread { flex: none; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--primary);
  color: var(--on-primary); font-size: .78rem; font-weight: 700; display: grid; place-items: center; }
.room-list-empty { padding: 1.5rem 1rem; text-align: center; }
.room-skeleton { height: 64px; margin: .3rem .2rem; border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* new-chat button and menu */
.fab-wrap { position: absolute; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); display: grid; justify-items: end; gap: .5rem; }
.fab { display: inline-flex; align-items: center; gap: .55rem; height: 56px; padding: 0 1.3rem 0 1.1rem; border: 0;
  border-radius: 18px; background: var(--primary); color: var(--on-primary); font: 600 1rem var(--font); cursor: pointer;
  box-shadow: var(--shadow); }
.fab:hover { background: var(--primary-hover); }
.fab-menu { display: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .35rem; min-width: 240px; }
.fab-wrap.open .fab-menu { display: grid; }
.fab-menu button { display: flex; align-items: center; gap: .7rem; padding: .7rem .8rem; border: 0; background: none;
  border-radius: var(--radius-sm); color: var(--text); font: 400 1rem var(--font); cursor: pointer; text-align: left; min-height: 44px; }
.fab-menu button:hover { background: var(--surface-2); }
.fab-menu .icon { color: var(--primary); }

/* main pane: empty state, page and room header */
.empty-state { margin: auto; max-width: 420px; text-align: center; display: grid; justify-items: center; gap: .8rem; padding: 2rem; }
.empty-state img { opacity: .9; }
.room, .page { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.room-head { display: flex; align-items: center; gap: .65rem; padding: .55rem .8rem; padding-top: calc(.55rem + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border); min-height: 64px; }
.room-head h2 { font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-title { display: grid; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; }
.e2ee-pill { display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .65rem; border-radius: var(--radius-pill);
  background: var(--ok-soft); color: var(--ok); font-size: .8rem; font-weight: 600; flex: none; }
.e2ee-pill .icon { width: 15px; height: 15px; }
.e2ee-pill.public { background: var(--accent-soft); color: var(--text); }
.e2ee-pill.warn { background: var(--warn-soft); color: var(--text); }
.page-body { overflow-y: auto; padding: 1.25rem; width: 100%; max-width: 760px; margin: 0 auto; }
.section-title { margin-top: .5rem; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: var(--radius-pill); padding: 3px; gap: 2px; justify-self: start; }
.segmented button { border: 0; background: none; padding: .45rem 1rem; border-radius: var(--radius-pill); color: var(--text);
  font: 600 .95rem var(--font); cursor: pointer; min-height: 38px; }
.segmented button[aria-checked="true"] { background: var(--surface); box-shadow: var(--shadow); }

/* dialogs */
.modal { border: 0; padding: 0; border-radius: 20px; width: min(520px, calc(100vw - 1.5rem)); max-height: min(86dvh, 760px);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.modal::backdrop { background: rgb(20 28 29 / .45); backdrop-filter: blur(2px); }
.modal-card { display: flex; flex-direction: column; max-height: min(86dvh, 760px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .8rem .6rem .5rem 1.25rem; }
.modal-content { padding: .25rem 1.25rem 1rem; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: .75rem 1.25rem 1rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-foot.spread { justify-content: space-between; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: .5rem; min-width: 0; }
legend { font-weight: 600; font-size: .95rem; margin-bottom: .35rem; padding: 0; }
.choice { grid-template-columns: 1fr 1fr; }
.radio-card { position: relative; display: block; cursor: pointer; font-weight: 400; }
.radio-card input { position: absolute; opacity: 0; }
.radio-card > span { display: grid; gap: .2rem; height: 100%; padding: .8rem .9rem; border: 2px solid var(--border); border-radius: var(--radius); }
.radio-card strong { font-weight: 600; }
.radio-card small { color: var(--muted); line-height: 1.35; }
.radio-card .icon { color: var(--primary); }
.radio-card input:checked + span { border-color: var(--primary); background: color-mix(in srgb, var(--sky) 30%, var(--surface)); }
.radio-card input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.public-only { display: none; }
form:has(#kind-public:checked) .public-only { display: flex; }
.pick-list { display: grid; gap: .1rem; max-height: 260px; overflow-y: auto; }
.pick { display: flex; align-items: center; gap: .65rem; font-weight: 400; padding: .4rem .3rem; border-radius: var(--radius-sm); cursor: pointer; }
.pick:hover { background: var(--surface-2); }
.pick-rows { gap: .15rem; }
.pick-btn { width: 100%; display: flex; align-items: center; gap: .8rem; padding: .55rem .5rem; border: 0; background: none;
  border-radius: var(--radius); color: var(--text); font: inherit; cursor: pointer; text-align: left; }
.pick-btn:hover { background: var(--surface-2); }
.pick-btn > .icon { color: var(--primary); }
.enc-note { display: flex; gap: .65rem; align-items: flex-start; padding: .75rem .9rem; border-radius: var(--radius); font-size: .92rem; }
.enc-note.secure { background: var(--ok-soft); }
.enc-note.secure > .icon { color: var(--ok); }
.enc-note.public { background: var(--accent-soft); }
.row-actions { display: flex; align-items: center; gap: .25rem; }
select.compact { min-height: 34px; padding: .2rem .5rem; width: auto; font-size: .9rem; }
.role { text-transform: capitalize; }
.role.owner { color: var(--primary); font-weight: 600; }
.icon-btn.danger { color: var(--danger); }
.fingerprint { font: .78rem var(--mono); color: var(--muted); letter-spacing: .03em; word-spacing: .2em; }

.toasts { position: fixed; left: 50%; bottom: calc(5.5rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: grid; gap: .5rem; z-index: 50; width: min(440px, calc(100vw - 2rem)); pointer-events: none; }
.toast { background: var(--slate); color: #fff; padding: .7rem 1rem; border-radius: var(--radius); box-shadow: var(--shadow);
  animation: toast-in .2s ease-out; }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* collapsible sidebar (wide screens only; phones already show one pane at a time) */
.side-expand { display: none; }
:root[data-sidebar="collapsed"] .app { grid-template-columns: 1fr; }
:root[data-sidebar="collapsed"] .sidebar { display: none; }
:root[data-sidebar="collapsed"] .side-expand { display: inline-grid; position: fixed; z-index: 20; left: .8rem;
  top: calc(.55rem + env(safe-area-inset-top)); background: var(--surface); box-shadow: var(--shadow); }
:root[data-sidebar="collapsed"] .room-head { padding-left: 4.2rem; }

/* phones: one pane at a time */
@media (max-width: 760px) {
  .side-collapse, :root[data-sidebar="collapsed"] .side-expand { display: none; }
  :root[data-sidebar="collapsed"] .room-head { padding-left: .8rem; }
  :root[data-sidebar="collapsed"] .sidebar { display: flex; }
  :root[data-sidebar="collapsed"] .in-main .sidebar { display: none; }
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; }
  .in-main .sidebar { display: none; }
  body:not(.in-main) .main { display: none; }
  .back { display: inline-grid; }
  .choice { grid-template-columns: 1fr; }
  .modal { width: 100vw; max-width: 100vw; max-height: 92dvh; margin: auto auto 0; border-radius: 20px 20px 0 0; }
  .modal-card { max-height: 92dvh; padding-bottom: env(safe-area-inset-bottom); }
  .page-body { padding: 1rem; }
}

/* ============================================================================
   Timeline & composer
   ========================================================================== */
.room-banner { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; padding: .6rem 1rem; background: var(--warn-soft);
  border-bottom: 1px solid var(--border); font-size: .92rem; }
.room-banner .icon { color: var(--accent); }
.room-banner .btn { margin-left: auto; }
.timeline { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: .75rem clamp(.5rem, 3vw, 2rem) 1rem; }
.timeline-inner { max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 2px; }
.timeline-start { display: flex; gap: .6rem; align-items: flex-start; align-self: center; max-width: 520px; margin: 1rem 0 .5rem;
  padding: .75rem 1rem; border-radius: var(--radius); background: var(--surface); color: var(--muted); font-size: .9rem; }
.timeline-start .icon { color: var(--primary); }
.timeline-more { align-self: center; color: var(--muted); font-size: .85rem; padding: .5rem; }
.day-sep { align-self: center; margin: .9rem 0 .4rem; }
.day-sep span { display: inline-block; padding: .15rem .75rem; border-radius: var(--radius-pill); background: var(--surface);
  color: var(--muted); font-size: .8rem; font-weight: 600; box-shadow: 0 1px 1px rgb(0 0 0 / .04); }
.sys-msg { align-self: center; color: var(--muted); font-size: .85rem; padding: .2rem .8rem; text-align: center; }

.msg-group { display: flex; gap: .5rem; align-items: flex-end; margin-top: .45rem; }
.msg-group.mine { justify-content: flex-end; }
.msg-group .avatar { margin-bottom: 2px; }
.msg-stack { display: flex; flex-direction: column; gap: 2px; min-width: 0; max-width: min(78%, 680px); }
.msg-group.mine .msg-stack { align-items: flex-end; }
.msg-group.theirs .msg-stack { align-items: flex-start; }
.sender { font-size: .82rem; font-weight: 600; color: var(--primary); margin: 0 0 1px .8rem; }

.bubble { position: relative; max-width: 100%; min-width: 64px; padding: .45rem .8rem .3rem; border-radius: 18px;
  background: var(--bubble-other); color: var(--bubble-other-text); box-shadow: 0 1px 1px rgb(0 0 0 / .05);
  overflow-wrap: anywhere; }
.mine .bubble { background: var(--bubble-mine); color: var(--bubble-mine-text); }
.theirs .bubble:not(:last-child) { border-bottom-left-radius: 6px; }
.theirs .bubble:not(:first-of-type) { border-top-left-radius: 6px; }
.mine .bubble:not(:last-child) { border-bottom-right-radius: 6px; }
.mine .bubble:not(:first-child) { border-top-right-radius: 6px; }
.bubble.pending { opacity: .7; }
.bubble.failed { outline: 2px solid var(--danger); }
.body.plain { white-space: pre-wrap; }
.body.deleted, .body.undecryptable { font-style: italic; opacity: .75; display: flex; gap: .4rem; align-items: center; }
.meta { display: flex; justify-content: flex-end; align-items: center; gap: .3rem; font-size: .72rem; opacity: .7; margin-top: 1px;
  white-space: nowrap; }
.meta .icon { width: 13px; height: 13px; }
.meta .link { color: inherit; text-decoration: underline; border: 0; background: none; cursor: pointer; padding: 0; font: inherit; }
.unverified { color: var(--danger); }
.mine .unverified { color: #ffd2cf; }
.msg-actions { position: absolute; top: -18px; display: none; gap: 2px; padding: 2px; border-radius: var(--radius-pill);
  background: var(--surface); box-shadow: var(--shadow); z-index: 2; }
.mine .msg-actions { right: 8px; }
.theirs .msg-actions { left: 8px; }
.msg-actions .icon-btn { width: 32px; height: 32px; }
.msg-actions .icon-btn .icon { width: 18px; height: 18px; }
.bubble:hover .msg-actions, .bubble:focus-within .msg-actions { display: flex; }

.composer { padding: .5rem clamp(.5rem, 3vw, 2rem) calc(.6rem + env(safe-area-inset-bottom)); background: var(--bg); }
.composer-extra { max-width: 900px; margin: 0 auto; }
.composer-bar { max-width: 900px; margin: 0 auto; display: flex; align-items: flex-end; gap: .15rem; padding: .25rem .3rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 26px; box-shadow: 0 1px 2px rgb(0 0 0 / .04); }
.composer-bar:focus-within { border-color: var(--primary); }
.composer textarea { flex: 1; border: 0; background: transparent; resize: none; min-height: 44px; max-height: 240px;
  padding: .6rem .3rem; line-height: 1.4; box-shadow: none; }
.composer textarea:focus { box-shadow: none; }
.composer .send { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; border: 0; flex: none;
  background: var(--primary); color: var(--on-primary); cursor: pointer; }
.composer .send:hover { background: var(--primary-hover); }
.composer .send .icon { width: 20px; height: 20px; margin-left: 2px; }
.composer .icon-btn[aria-pressed="true"] { color: var(--primary); background: var(--surface-2); }
.composer-readonly { display: flex; align-items: center; justify-content: center; gap: .75rem; flex-wrap: wrap; padding: .9rem 1rem;
  background: var(--surface); border-top: 1px solid var(--border); }

@media (max-width: 760px) {
  .msg-stack { max-width: 86%; }
  .msg-group .avatar.sm { width: 28px; height: 28px; font-size: .7rem; }
}
@media (hover: none) {
  .bubble:hover .msg-actions { display: none; }
  .bubble.show-actions .msg-actions { display: flex; }
}

/* --- encryption ---------------------------------------------------------------- */
.fingerprint.big { font-size: 1rem; color: var(--text); margin-top: .25rem; word-spacing: .35em; }
.trust { font-family: var(--font); font-size: .75rem; font-weight: 700; padding: 0 .4rem; border-radius: var(--radius-pill); }
.trust.verified { background: var(--ok-soft); color: var(--ok); }
.trust.ok, .trust.new { background: var(--surface-2); color: var(--muted); }
.trust.changed { background: var(--danger-soft); color: var(--danger); }

/* ============================================================================
   Rich messages: Markdown, code, files
   ========================================================================== */
.body.md { line-height: 1.45; }
.body.md > :first-child { margin-top: 0; }
.body.md > :last-child { margin-bottom: 0; }
.body.md p, .body.md ul, .body.md ol, .body.md blockquote, .body.md table { margin: .35em 0; }
.body.md ul, .body.md ol { padding-left: 1.4em; }
.body.md h1, .body.md h2, .body.md h3, .body.md h4 { margin: .5em 0 .25em; font-size: 1.1em; }
.body.md h1 { font-size: 1.25em; }
.body.md blockquote { border-left: 3px solid var(--accent); padding-left: .7em; opacity: .9; }
.body.md hr { border: 0; border-top: 1px solid currentColor; opacity: .25; }
.body.md a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.theirs .body.md a { color: var(--link); }
.body.md :not(pre) > code { font-family: var(--mono); font-size: .88em; padding: .08em .35em; border-radius: 5px;
  background: rgb(0 0 0 / .07); }
.mine .body.md :not(pre) > code { background: rgb(255 255 255 / .18); }
.body.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.body.md th, .body.md td { border: 1px solid rgb(127 127 127 / .35); padding: .25em .55em; }
.body.md input[type="checkbox"] { width: auto; min-height: 0; vertical-align: -2px; margin-right: .3em; }
.body.emoji-only { font-size: 2.4rem; line-height: 1.15; }
.bubble:has(.emoji-only) { background: transparent !important; box-shadow: none; padding-left: .2rem; padding-right: .2rem; }
.bubble:has(.emoji-only) .meta { color: var(--muted); opacity: 1; }

.code-block { margin: .4em 0; border-radius: 10px; overflow: hidden; background: var(--code-bg); color: var(--text);
  border: 1px solid var(--border); max-width: 100%; }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: .15rem .3rem .15rem .75rem;
  font: 600 .75rem var(--font); text-transform: lowercase; color: var(--muted); background: color-mix(in srgb, var(--code-bg) 80%, var(--border)); }
.code-copy { display: inline-flex; align-items: center; gap: .3rem; border: 0; background: none; color: var(--muted); cursor: pointer;
  font: 600 .75rem var(--font); padding: .3rem .5rem; border-radius: 6px; min-height: 30px; }
.code-copy:hover { background: var(--surface-2); color: var(--text); }
.code-copy .icon { width: 15px; height: 15px; }
.code-block pre { margin: 0; padding: .65rem .8rem; overflow: auto; max-height: 420px; font: .85rem/1.5 var(--mono);
  white-space: pre; overflow-wrap: normal; tab-size: 4; }

/* highlight.js tokens, using the brand palette in both themes */
.hljs-comment, .hljs-quote { color: #6b7d82; font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-built_in, .hljs-type { color: #2978a0; font-weight: 600; }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attribute { color: #3f7d4e; }
.hljs-number, .hljs-symbol, .hljs-bullet, .hljs-variable, .hljs-template-variable { color: #a4552f; }
.hljs-title, .hljs-section, .hljs-name, .hljs-function .hljs-title { color: #5b5f97; }
.hljs-meta, .hljs-attr, .hljs-property { color: #8a6d1f; }
.hljs-deletion { color: #b03a37; }
.hljs-emphasis { font-style: italic; } .hljs-strong { font-weight: 700; }
:root[data-theme="dark"] .hljs-keyword, :root[data-theme="dark"] .hljs-literal, :root[data-theme="dark"] .hljs-built_in,
:root[data-theme="dark"] .hljs-type, :root[data-theme="dark"] .hljs-selector-tag { color: #7fc0ea; }
:root[data-theme="dark"] .hljs-string, :root[data-theme="dark"] .hljs-addition, :root[data-theme="dark"] .hljs-attribute { color: #9fd3a8; }
:root[data-theme="dark"] .hljs-number, :root[data-theme="dark"] .hljs-variable, :root[data-theme="dark"] .hljs-symbol { color: #f0a77f; }
:root[data-theme="dark"] .hljs-title, :root[data-theme="dark"] .hljs-name { color: #b7b9f0; }
:root[data-theme="dark"] .hljs-meta, :root[data-theme="dark"] .hljs-attr, :root[data-theme="dark"] .hljs-property { color: #d8c98f; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .hljs-keyword, :root:not([data-theme="light"]) .hljs-literal, :root:not([data-theme="light"]) .hljs-built_in,
  :root:not([data-theme="light"]) .hljs-type, :root:not([data-theme="light"]) .hljs-selector-tag { color: #7fc0ea; }
  :root:not([data-theme="light"]) .hljs-string, :root:not([data-theme="light"]) .hljs-addition, :root:not([data-theme="light"]) .hljs-attribute { color: #9fd3a8; }
  :root:not([data-theme="light"]) .hljs-number, :root:not([data-theme="light"]) .hljs-variable, :root:not([data-theme="light"]) .hljs-symbol { color: #f0a77f; }
  :root:not([data-theme="light"]) .hljs-title, :root:not([data-theme="light"]) .hljs-name { color: #b7b9f0; }
  :root:not([data-theme="light"]) .hljs-meta, :root:not([data-theme="light"]) .hljs-attr, :root:not([data-theme="light"]) .hljs-property { color: #d8c98f; }
}

/* files */
.file-image-wrap { display: block; padding: 0; border: 0; background: none; cursor: zoom-in; margin: .15rem 0 .25rem;
  border-radius: 12px; overflow: hidden; max-width: min(360px, 100%); }
.file-image { display: block; max-width: 100%; max-height: 320px; min-height: 60px; min-width: 80px; object-fit: cover;
  background: color-mix(in srgb, currentColor 8%, transparent); }
.file-card { display: flex; align-items: center; gap: .7rem; width: min(320px, 100%); margin: .15rem 0 .25rem; padding: .55rem .7rem;
  border-radius: 12px; border: 1px solid rgb(127 127 127 / .3); background: rgb(127 127 127 / .08); color: inherit;
  font: inherit; text-align: left; cursor: pointer; }
.file-card:hover { background: rgb(127 127 127 / .16); }
.file-card.missing { cursor: default; font-style: italic; opacity: .7; }
.file-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--primary); color: #fff; flex: none; }
.mine .file-icon { background: rgb(255 255 255 / .22); }
.file-text { display: grid; min-width: 0; flex: 1; }
.file-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.file-text small { opacity: .75; }
.file-dl .icon { opacity: .8; }
.lightbox { max-height: 92dvh; }
.lightbox > img { display: block; max-width: 100%; max-height: calc(92dvh - 70px); margin: 0 auto; object-fit: contain; background: #111; }
.modal:has(.lightbox) { width: min(1100px, calc(100vw - 1.5rem)); }

/* composer extras */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; padding: .2rem .3rem .45rem; }
.chip { display: inline-flex; align-items: center; gap: .35rem; max-width: 260px; padding: .25rem .25rem .25rem .6rem;
  border-radius: var(--radius-pill); background: var(--surface); border: 1px solid var(--border); font-size: .88rem; }
.chip .icon { width: 16px; height: 16px; color: var(--primary); }
.chip small { color: var(--muted); flex: none; }
.chip-x { display: grid; place-items: center; width: 26px; height: 26px; border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; }
.chip-x:hover { background: var(--surface-2); color: var(--text); }
.composer-preview { margin: 0 .2rem .45rem; padding: .6rem .85rem; border-radius: 14px; background: var(--surface);
  border: 1px dashed var(--border); max-height: 260px; overflow-y: auto; }
.snippet-input { font: .88rem/1.5 var(--mono); min-height: 200px; resize: vertical; tab-size: 2; white-space: pre; }
.room.dropping .timeline { outline: 3px dashed var(--primary); outline-offset: -10px; background: color-mix(in srgb, var(--sky) 25%, var(--bg)); }

/* ============================================================================
   Admin console
   ========================================================================== */
.admin-page { min-height: 100dvh; }
.admin { max-width: 1180px; margin: 0 auto; padding: 0 1rem 3rem; }
.admin-head { display: flex; align-items: center; gap: .5rem; padding: calc(.75rem + env(safe-area-inset-top)) 0 .5rem; }
.admin-head h1 { display: flex; align-items: center; gap: .5rem; font-size: 1.35rem; }
.admin-head h1 .icon { color: var(--primary); }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .7rem 1rem; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.table-wrap { overflow-x: auto; margin: 0 -1.2rem; padding: 0 1.2rem; }
table.data { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.data th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  font-weight: 700; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
table.data td { padding: .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.disabled td { opacity: .55; }
table.data tr.warn td { background: color-mix(in srgb, var(--warn-soft) 60%, transparent); }
.right { text-align: right; } .nowrap { white-space: nowrap; }
.who-cell { display: flex; align-items: center; gap: .6rem; }
.link-card { border-color: var(--primary); background: color-mix(in srgb, var(--sky) 25%, var(--surface)); }
details.menu { position: relative; display: inline-block; }
details.menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: calc(100% + 4px); z-index: 10; min-width: 230px; display: grid; padding: .35rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); text-align: left; }
.menu-list button { display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem; min-height: 40px; border: 0; background: none;
  border-radius: var(--radius-sm); color: var(--text); font: 400 .95rem var(--font); cursor: pointer; text-align: left; width: 100%; }
.menu-list button:hover { background: var(--surface-2); }
.menu-list button.danger, .menu-list .danger { color: var(--danger); }
.menu-delete { display: grid; gap: .3rem; padding: .4rem .3rem .2rem; margin-top: .25rem; border-top: 1px solid var(--border); }
.menu-delete input { min-height: 36px; font-size: .9rem; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .75rem; }
.stat { gap: .2rem; }
.stat strong { font-size: 1.5rem; font-weight: 600; }
.stat strong.ok { color: var(--ok); } .stat strong.bad { color: var(--danger); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.2rem; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
pre.cmd { margin: 0; padding: .75rem .9rem; border-radius: var(--radius-sm); background: var(--code-bg); border: 1px solid var(--border);
  overflow-x: auto; font: .85rem/1.5 var(--mono); }
@media (max-width: 760px) {
  .kv { grid-template-columns: 1fr; }
  table.data th:nth-child(3), table.data td:nth-child(3) { display: none; }
}
