/* Layout: white chat rail | soft mint chat stream | optional group-info drawer. One pane at a time on phones.
   Deliberately light-only, so it looks the same on every device. */
:root {
  --bg: #F4F8F6; --panel: #FFFFFF; --ink: #1B2A27; --muted: #6A7A75; --line: #E2EAE7;
  --accent: #F5C842; --accent-ink: #2A2000;
  --rail: #FFFFFF; --rail-ink: #1B2A27; --rail-muted: #74847F; --rail-hover: #F1F6F4; --rail-active: #FFF5D1; --rail-field: #F2F6F4;
  --gate: #E9F4EF; --mine: #FFF0BE; --other: #FFFFFF; --notice: #FFFAEA; --danger: #B3261E;
  --display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --body: "Figtree", "Helvetica Neue", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 15px; line-height: 1.45;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; font-family: var(--display); font-weight: 800; font-size: 1.45rem; letter-spacing: -0.02em; }
.label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin: 0; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 0.85rem; }
.error { color: var(--danger); font-size: 0.88rem; margin: 0; }
.error.light { color: var(--danger); }
.pad { padding: 4px 20px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack.tight { gap: 8px; }

.btn { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 10px; padding: 9px 16px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.wide { width: 100%; padding-block: 12px; font-size: 1rem; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost.danger { color: var(--danger); }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 0; font-size: 0.9rem; }
.link.light { color: var(--rail-muted); }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 1.4rem; line-height: 1; cursor: pointer; }
.icon-btn.plain { background: none; color: var(--muted); }

/* Gate: sign in, sign up, join */
.gate { min-height: 100%; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-left, 0px)); background: var(--gate); }
.gate-card { width: min(400px, 100%); background: var(--panel); border-radius: 18px; border: 1px solid var(--line); box-shadow: 0 12px 32px rgba(27, 42, 39, 0.08); padding: 28px 24px; display: flex; flex-direction: column; gap: 18px; }
.invite-box { background: var(--notice); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.invite-name { margin: 0; font-family: var(--display); font-weight: 800; font-size: 1.35rem; }
.invite-box .btn { margin-top: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.9rem; }
.field input, .at { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px 12px; font-weight: 400; font-size: 1rem; min-width: 0; }
.at { display: flex; align-items: center; gap: 2px; padding-block: 0; }
.at b { color: var(--muted); font-weight: 600; }
.at input { border: 0; background: none; padding: 10px 0; flex: 1; min-width: 0; outline: none; font-size: 1rem; }
.at:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.at.dark, .dark-input { background: var(--rail-field); border: 1px solid var(--line); color: var(--rail-ink); }
.at.dark b { color: var(--rail-muted); }
.dark-input { border-radius: 10px; padding: 9px 12px; }
.dark-input option { color: #13201E; }
.hint { margin: 0; font-size: 0.85rem; color: var(--muted); }

/* App shell */
.app { height: 100%; display: grid; grid-template-columns: minmax(260px, 320px) 1fr auto; }
.side { background: var(--rail); color: var(--rail-ink); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; gap: 14px;
  padding-block: 16px; padding-left: max(14px, env(safe-area-inset-left, 0px)); padding-right: 14px; }
.side .label { color: var(--rail-muted); }
.side-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.me { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; color: var(--rail-muted); }
.newpanel { display: flex; flex-direction: column; gap: 16px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; min-height: 0; flex: 1; margin-inline: -4px; }
.c { display: grid; grid-template-columns: 42px 1fr auto; gap: 10px; align-items: center; text-align: left; background: none; border: 0;
  padding: 8px; border-radius: 12px; cursor: pointer; color: var(--rail-ink); width: 100%; }
.c:hover { background: var(--rail-hover); }
.c[aria-current="true"] { background: var(--rail-active); box-shadow: inset 3px 0 0 var(--accent); }
.av { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-family: var(--display); font-weight: 800; font-size: 1.05rem; background: #E3F1EC; color: #1F5A4F; }
.av.dm { border-radius: 50%; }
.av.announce { background: var(--accent); color: var(--accent-ink); }
.c-body { min-width: 0; }
.c-name { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-last { font-size: 0.82rem; color: var(--rail-muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 0.72rem; color: var(--rail-muted); font-variant-numeric: tabular-nums; }
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 999px; min-width: 20px; padding: 1px 6px; text-align: center; font-weight: 700; font-size: 0.75rem; }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.placeholder { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--muted); }
.chat-head { display: flex; align-items: center; gap: 8px; background: var(--panel); border-bottom: 1px solid var(--line);
  padding-block: 10px; padding-left: 16px; padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.head-info { background: none; border: 0; text-align: left; cursor: pointer; padding: 4px; border-radius: 8px; min-width: 0; display: flex; flex-direction: column; }
.head-info:hover { background: var(--bg); }
.h-name { font-family: var(--display); font-weight: 800; font-size: 1.15rem; letter-spacing: -0.01em; }
.h-sub { color: var(--muted); font-size: 0.82rem; }
.back { display: none; background: none; border: 0; font-size: 1.6rem; cursor: pointer; padding: 0 8px; color: var(--ink); }
.stream { flex: 1; overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 5px;
  padding-block: 16px; padding-left: 20px; padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.day { align-self: center; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; margin-block: 8px; }
.msg { max-width: min(560px, 84%); display: flex; flex-direction: column; gap: 2px; align-self: flex-start; }
.msg.mine { align-self: flex-end; }
.who { font-size: 0.8rem; font-weight: 600; padding-left: 4px; color: hsl(var(--h, 170) 60% var(--who-l)); }
:root { --who-l: 34%; }
.bubble { background: var(--other); border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; padding: 7px 11px 5px; overflow-wrap: anywhere; white-space: pre-wrap; }
.mine .bubble { background: var(--mine); border-color: transparent; border-radius: 14px 14px 4px 14px; }
.meta { display: flex; justify-content: flex-end; gap: 10px; font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 2px; }
.del { background: none; border: 0; color: var(--muted); font-size: 0.72rem; cursor: pointer; padding: 0; }
.del[data-armed] { color: var(--danger); font-weight: 600; }
.stream.announce .msg { max-width: 640px; align-self: stretch; }
.stream.announce .bubble { background: var(--notice); border-left: 4px solid var(--accent); border-radius: 6px; padding: 12px 14px 8px; font-size: 1.02rem; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 34ch; }
.more { align-self: center; }
.composer { display: flex; gap: 10px; align-items: flex-end; background: var(--panel); border-top: 1px solid var(--line);
  padding-block: 10px; padding-left: 16px; padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 9px 12px; max-height: 140px; min-height: 42px; }
.readonly { margin: 0; background: var(--panel); border-top: 1px solid var(--line); color: var(--muted); font-size: 0.88rem; text-align: center; padding: 14px 16px; }

.info { width: 340px; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; gap: 22px;
  padding-block: 16px; padding-left: 18px; padding-right: max(18px, env(safe-area-inset-right, 0px)); }
.info-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.info-head h2 { margin: 0; font-family: var(--display); font-weight: 800; font-size: 1.2rem; }
.invite { display: flex; flex-direction: column; gap: 10px; }
#qr { width: 232px; max-width: 100%; height: auto; align-self: center; border-radius: 12px; background: #fff; }
.linkrow { display: flex; gap: 8px; }
.linkrow input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 10px; font-size: 0.85rem; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.members { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.members li { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.members .av { width: 34px; height: 34px; font-size: 0.9rem; background: var(--bg); color: var(--ink); border-radius: 50%; }
.members .who-n { font-weight: 600; display: block; }
.members .who-u { color: var(--muted); font-size: 0.82rem; }
.members .role { margin-left: auto; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app[data-view="list"] .chat, .app[data-view="list"] .info { display: none; }
  .app[data-view="chat"] .side { display: none; }
  .info { position: fixed; inset: 0; width: auto; z-index: 5; border: 0;
    padding-top: calc(16px + env(safe-area-inset-top, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); }
  .back { display: block; }
  .side { padding-right: max(14px, env(safe-area-inset-right, 0px)); }
  .stream, .composer, .chat-head { padding-left: max(12px, env(safe-area-inset-left, 0px)); }
}
@media (prefers-reduced-motion: no-preference) { .msg.new { animation: pop .18s ease-out; } }
@keyframes pop { from { transform: translateY(6px); opacity: .4; } to { transform: none; opacity: 1; } }

/* Admin area */
.me-links { display: flex; gap: 12px; flex: none; white-space: nowrap; }
.me { gap: 10px; }
#meName { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-info.static { cursor: default; }
.head-info.static:hover { background: none; }
.admin-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.admin-body { flex: 1; overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 18px;
  padding-block: 18px; padding-left: 20px; padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.admin-body > * { width: 100%; max-width: 760px; }
.search { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 10px 12px; font-size: 1rem; }
.ulist { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.urow + .urow { border-top: 1px solid var(--line); }
.urow-main { display: grid; grid-template-columns: 38px 1fr auto; gap: 12px; align-items: center; padding: 12px 14px; }
.urow .av { width: 38px; height: 38px; font-size: 0.95rem; border-radius: 50%; }
.u-name { font-weight: 600; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.u-meta { color: var(--muted); font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.pill { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; border-radius: 999px; padding: 1px 8px; }
.pill.admin { background: var(--accent); color: var(--accent-ink); }
.pill.warn { background: #FCE8E6; color: var(--danger); }
.editor { border-top: 1px dashed var(--line); background: var(--bg); padding: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 18px; border-radius: 0 0 14px 14px; }
.editor .stack { gap: 10px; }
.editor h3 { margin: 0; font-size: 0.95rem; }
.editor .field input, .editor .at { background: var(--panel); }
.check { display: flex; gap: 8px; align-items: center; font-size: 0.9rem; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 10px; }
.ok { color: #1E6B3A; font-size: 0.88rem; margin: 0; }
.temp { background: var(--notice); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.temp code { font-size: 1.25rem; font-weight: 700; letter-spacing: 0.06em; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.log ul { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 0.88rem; }
.log li { display: flex; gap: 10px; color: var(--ink); }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; min-width: 9.5em; }
@media (max-width: 760px) {
  .editor { grid-template-columns: 1fr; }
  .admin-body { padding-left: max(12px, env(safe-area-inset-left, 0px)); }
  .log li { flex-direction: column; gap: 0; }
}
.name-line { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; min-width: 0; }
.name-line h2 { overflow-wrap: anywhere; }
.rename { display: flex; flex-direction: column; gap: 10px; margin-top: -8px; }
/* Medium widths: the info panel floats over the chat instead of squeezing it. */
@media (min-width: 761px) and (max-width: 1150px) {
  .app { position: relative; grid-template-columns: minmax(240px, 300px) 1fr; }
  .info { position: absolute; top: 0; right: 0; bottom: 0; z-index: 4; box-shadow: -12px 0 32px rgba(27, 42, 39, 0.12); }
}
.settings { display: flex; flex-direction: column; gap: 8px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg span { display: block; text-align: center; padding: 8px 6px; border-radius: 9px; font-weight: 600; font-size: 0.9rem; color: var(--muted); }
.seg input:checked + span { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(27, 42, 39, 0.12); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.m-side { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.m-side .role { margin-left: 0; }
.m-acts { display: flex; gap: 10px; }
