/* ApplTech Messaging. Light/dark themes; --accent comes from the tenant branding. */
[hidden] { display: none !important; } /* layout classes set display, which would otherwise override the hidden attribute */
:root {
  --accent: #3390ec;
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --bg: #ffffff; --bg-2: #f4f4f5; --panel: #ffffff; --line: #e6e7ea; --text: #0f0f0f; --muted: #707579;
  --hover: #f4f4f5; --active: var(--accent); --active-text: #fff;
  --bubble-in: #ffffff; --bubble-out: color-mix(in srgb, var(--accent) 22%, #ffffff); --bubble-out-text: #0f0f0f; --meta-out: color-mix(in srgb, var(--accent) 70%, #2f5d2f);
  --chat-bg: #c9d9bd; --pattern-opacity: .35; --pattern-color: #6f8b5c;
  --danger: #e53935; --online: #4fae4e; --shadow: 0 1px 2px rgba(16, 35, 47, .15); --pop-shadow: 0 6px 24px rgba(0, 0, 0, .18);
  --radius: 12px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #212121; --bg-2: #181818; --panel: #212121; --line: #2f2f2f; --text: #f5f5f5; --muted: #aaaaaa;
  --hover: #2c2c2c; --bubble-in: #212121; --bubble-out: color-mix(in srgb, var(--accent) 55%, #1a1a1a); --bubble-out-text: #ffffff; --meta-out: rgba(255,255,255,.65);
  --chat-bg: #0f0f0f; --pattern-opacity: .18; --pattern-color: #4b5a66; --shadow: 0 1px 2px rgba(0,0,0,.4); --pop-shadow: 0 6px 24px rgba(0,0,0,.6);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 15px/1.4 Roboto, system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif; background: var(--bg-2); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
.ic { width: 22px; height: 22px; flex: none; vertical-align: middle; }
.ic.xs { width: 15px; height: 15px; }

/* ---------- classic pages (admin, account, new chat) ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .5rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; gap: .5rem; align-items: center; font-weight: 600; text-decoration: none; color: inherit; }
.brand img { height: 28px; }
nav { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
nav a, nav .link { display: inline-flex; gap: .35rem; align-items: center; text-decoration: none; color: var(--text); }
nav .ic { width: 18px; height: 18px; color: var(--muted); }
.container { max-width: 960px; margin: 1rem auto; padding: 0 1rem; }
.wide { height: calc(100vh - 52px); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; width: 100%; }
.form { display: flex; flex-direction: column; gap: .6rem; max-width: 520px; }
.form label { display: flex; flex-direction: column; gap: .2rem; }
.check { flex-direction: row !important; align-items: center; gap: .4rem; display: inline-flex; }
.checks { display: flex; flex-wrap: wrap; gap: .5rem 1rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
button { padding: .5rem .9rem; background: var(--accent); color: #fff; border: 0; border-radius: 10px; cursor: pointer; }
button.link { background: none; color: var(--accent); padding: 0; }
button:disabled { opacity: .6; cursor: default; }
.danger-btn { background: var(--danger); padding: .25rem .7rem; }
.inline { display: inline; }
table { border-collapse: collapse; width: 100%; } td, th { text-align: left; padding: .45rem; border-bottom: 1px solid var(--line); }
tr.muted td { color: var(--muted); }
.error { color: var(--danger); }
.flash { background: color-mix(in srgb, var(--online) 15%, var(--panel)); border: 1px solid color-mix(in srgb, var(--online) 45%, transparent); padding: .6rem; border-radius: 10px; margin-bottom: 1rem; word-break: break-word; }
.muted { color: var(--muted); font-size: .9em; } .danger { border-color: #fca5a5; }

/* ---------- app shell ---------- */
body.app-body { overflow: hidden; overscroll-behavior: none; }
/* App shell = the *visible* viewport. 100vh on Android (esp. installed PWAs, edge-to-edge with viewport-fit=cover)
   can include the area under the system/gesture bar, which pushed the FAB and composer off-screen.
   Fallback chain: 100vh -> -webkit-fill-available -> 100dvh (dynamic; shrinks with the keyboard thanks to
   interactive-widget=resizes-content in the viewport meta). Insets are applied inside the panes, not here. */
html:has(body.app-body) { height: -webkit-fill-available; }
body.app-body { min-height: -webkit-fill-available; }
.app-main { height: 100vh; height: -webkit-fill-available; }
@supports (height: 100dvh) { .app-main { height: 100dvh; } }
/* chat.js measures visualViewport.height into --app-h (fixes Android PWA/edge-to-edge where 100dvh can exceed the visible area). */
html.vv-fit .app-main { height: var(--app-h); }
.app-main > .flash { position: fixed; top: .5rem; left: 50%; transform: translateX(-50%); z-index: 50; }
.tg { position: relative; display: flex; height: 100%; background: var(--panel); overflow: hidden; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--hover); }
.icon-btn.sm { width: 28px; height: 28px; }

/* sidebar */
.sidebar { position: relative; width: 380px; min-width: 300px; max-width: 40%; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--panel);
  padding-top: env(safe-area-inset-top); padding-left: env(safe-area-inset-left); }
.side-top { display: flex; gap: .5rem; align-items: center; padding: .45rem .75rem .45rem .5rem; }
.search { flex: 1; display: flex; align-items: center; gap: .5rem; background: var(--bg-2); border-radius: 22px; padding: 0 .9rem; height: 42px; color: var(--muted); border: 2px solid transparent; }
.search:focus-within { border-color: var(--accent); background: var(--panel); color: var(--accent); }
.search input { flex: 1; border: 0; background: none; padding: 0; height: 100%; outline: none; color: var(--text); min-width: 0; }
.search .ic { width: 20px; height: 20px; }
.chat-list { list-style: none; margin: 0; padding: 0 .4rem calc(5.5rem + env(safe-area-inset-bottom)); overflow-y: auto; flex: 1 1 0; min-height: 0; }
.chat-item { display: flex; gap: .65rem; align-items: center; padding: .5rem .55rem; border-radius: 12px; cursor: pointer; }
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); color: var(--active-text); }
.chat-item.active .ci-time, .chat-item.active .ci-preview, .chat-item.active .ci-who, .chat-item.active .ic { color: var(--active-text) !important; }
.chat-item.active .badge { background: #fff; color: var(--accent); }
.av-wrap { position: relative; flex: none; }
.online-dot { position: absolute; right: 1px; bottom: 1px; width: 13px; height: 13px; border-radius: 50%; background: var(--online); border: 2px solid var(--panel); }
.ci-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .15rem; }
.ci-top, .ci-bottom { display: flex; align-items: center; gap: .35rem; min-width: 0; }
.ci-title { flex: 1; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: .3rem; }
.ci-time { font-size: .78em; color: var(--muted); flex: none; }
.ci-preview { flex: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .93em; }
.ci-who { color: var(--text); }
.muted-ic, .pin-ic { color: var(--muted); }
.badge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--accent); color: #fff; font-size: .78em; font-weight: 500; display: inline-grid; place-items: center; flex: none; }
.badge.muted-badge { background: var(--muted); }
.list-section { padding: .6rem .7rem .3rem; color: var(--muted); font-size: .85em; font-weight: 500; }
.list-empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }
/* Positioned inside the list pane (not the viewport) and lifted above the gesture/nav bar inset. */
.fab { position: absolute; z-index: 4; right: 1.2rem; bottom: calc(1.2rem + env(safe-area-inset-bottom)); width: 54px; height: 54px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; box-shadow: 0 2px 8px rgba(0,0,0,.25); transition: transform .15s; }
.fab:hover { transform: scale(1.06); }

/* avatars: image or colored initials */
.avatar { --av: var(--accent); width: 54px; height: 54px; border-radius: 50%; flex: none; display: inline-grid; place-items: center; overflow: hidden; color: #fff; font-weight: 500; font-size: 1.05rem;
  background: linear-gradient(var(--av), color-mix(in srgb, var(--av) 75%, #000)); user-select: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 34px; height: 34px; font-size: .8rem; }
.avatar.lg { width: 52px; height: 52px; }
.avatar.xl { width: 120px; height: 120px; font-size: 2.6rem; }
.chat-header .avatar { width: 42px; height: 42px; font-size: .95rem; }

/* drawer */
.backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
.drawer { position: absolute; top: 0; left: 0; bottom: 0; width: 290px; padding-top: env(safe-area-inset-top); background: var(--panel); z-index: 21; box-shadow: var(--pop-shadow); display: flex; flex-direction: column; align-items: stretch; padding-bottom: 1rem; animation: slidein .18s ease-out; }
@keyframes slidein { from { transform: translateX(-100%); } to { transform: none; } }
.drawer-head { display: flex; flex-direction: column; gap: .25rem; align-items: flex-start; padding: 1.2rem 1.2rem 1rem; border-bottom: 1px solid var(--line); margin-bottom: .4rem; }
.drawer-head strong { margin-top: .5rem; }
.drawer a, .drawer button { display: flex; align-items: center; gap: 1.4rem; padding: .7rem 1.4rem; background: none; color: var(--text); text-decoration: none; border-radius: 0; width: 100%; text-align: left; font-weight: 500; }
.drawer a:hover, .drawer button:hover { background: var(--hover); }
.drawer form { width: 100%; margin: 0; display: block; }
.drawer button { justify-content: flex-start; font: inherit; font-weight: 500; }
.drawer .ic { color: var(--muted); }

/* chat pane */
.chat-pane { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; position: relative; padding-top: env(safe-area-inset-top); padding-right: env(safe-area-inset-right); background-color: var(--chat-bg); isolation: isolate; }
.chat-pane::before { content: ""; position: absolute; inset: 0; z-index: -1; opacity: var(--pattern-opacity); background-color: var(--pattern-color);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 30a10 10 0 1 0 20 0a10 10 0 1 0-20 0'/%3E%3Cpath d='M100 18l6 12 13 2-9 9 2 13-12-6-12 6 2-13-9-9 13-2z'/%3E%3Cpath d='M30 100h28v18H40l-8 7v-7h-2z'/%3E%3Cpath d='M118 96c6-10 22-4 14 8l-14 14-14-14c-8-12 8-18 14-8z'/%3E%3Cpath d='M70 60l10 10M80 60L70 70'/%3E%3Cpath d='M64 140h20M74 130v20'/%3E%3Cpath d='M130 140a6 6 0 1 0 12 0a6 6 0 1 0-12 0'/%3E%3Cpath d='M8 70q8-8 16 0t16 0'/%3E%3C/svg%3E") 0 0 / 160px 160px repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 30a10 10 0 1 0 20 0a10 10 0 1 0-20 0'/%3E%3Cpath d='M100 18l6 12 13 2-9 9 2 13-12-6-12 6 2-13-9-9 13-2z'/%3E%3Cpath d='M30 100h28v18H40l-8 7v-7h-2z'/%3E%3Cpath d='M118 96c6-10 22-4 14 8l-14 14-14-14c-8-12 8-18 14-8z'/%3E%3Cpath d='M70 60l10 10M80 60L70 70'/%3E%3Cpath d='M64 140h20M74 130v20'/%3E%3Cpath d='M130 140a6 6 0 1 0 12 0a6 6 0 1 0-12 0'/%3E%3Cpath d='M8 70q8-8 16 0t16 0'/%3E%3C/svg%3E") 0 0 / 160px 160px repeat; }
.chat-header { position: relative; display: flex; align-items: center; gap: .4rem; padding: .35rem .6rem .35rem 1rem; height: 56px; background: var(--panel); border-bottom: 1px solid var(--line); flex: none; }
.chat-header .back { display: none; }
.peer { flex: 1; min-width: 0; display: flex; align-items: center; gap: .75rem; background: none; color: inherit; padding: 0; text-align: left; border-radius: 0; }
.peer-text { display: flex; flex-direction: column; min-width: 0; }
.peer-text strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
#chatStatus { font-size: .85em; }
#chatStatus.on { color: var(--accent); }
.menu-pop { position: absolute; right: .6rem; top: 50px; z-index: 30; min-width: 220px; background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(10px); border-radius: 12px; box-shadow: var(--pop-shadow); padding: .3rem; }
.menu-pop button { display: flex; align-items: center; gap: 1rem; width: 100%; padding: .55rem .8rem; background: none; color: var(--text); border-radius: 8px; font-weight: 500; font-size: .93em; }
.menu-pop button:hover { background: var(--hover); }
.menu-pop button .ic { width: 20px; height: 20px; color: var(--muted); }
.menu-pop button.danger, .menu-pop button.danger .ic { color: var(--danger); }
.empty-state { flex: 1; display: grid; place-items: center; }
.pill { background: color-mix(in srgb, #000 22%, transparent); color: #fff; padding: .3rem .8rem; border-radius: 14px; font-size: .9em; font-weight: 500; }

/* messages */
.messages { flex: 1 1 0; min-height: 0; overflow-y: auto; padding: .8rem max(1rem, calc((100% - 760px) / 2)); display: flex; flex-direction: column; gap: 2px; }
.no-msgs { margin: auto; }
.day-group { display: flex; flex-direction: column; gap: 2px; }
.day-sep { position: sticky; top: .3rem; z-index: 2; display: flex; justify-content: center; margin: .6rem 0; pointer-events: none; }
.day-sep span { background: color-mix(in srgb, #000 45%, transparent); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); color: #fff; padding: .15rem .65rem; border-radius: 12px; font-size: .82em; font-weight: 500; }
.msg { display: flex; align-items: flex-end; gap: .4rem; max-width: min(78%, 560px); }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; flex-direction: row-reverse; }
.msg.tail { margin-bottom: 6px; }
.msg-av-space { width: 34px; flex: none; }
.bubble { position: relative; min-width: 64px; padding: .35rem .55rem .35rem .65rem; border-radius: 15px; background: var(--bubble-in); box-shadow: var(--shadow); word-wrap: break-word; overflow-wrap: anywhere; }
.msg.out .bubble { background: var(--bubble-out); color: var(--bubble-out-text); }
.msg.in.tail .bubble { border-bottom-left-radius: 4px; }
.msg.out.tail .bubble { border-bottom-right-radius: 4px; }
/* tails */
.msg.tail .bubble::after { content: ""; position: absolute; bottom: 0; width: 11px; height: 17px; background: inherit; }
.msg.in.tail .bubble::after { left: -8px; clip-path: path("M11 0 V17 H0 C5 15 9 11 11 0 Z"); }
.msg.out.tail .bubble::after { right: -8px; clip-path: path("M0 0 V17 H11 C6 15 2 11 0 0 Z"); }
.sender { font-weight: 500; font-size: .9em; margin-bottom: .1rem; }
.text { white-space: pre-wrap; }
.meta { float: right; display: inline-flex; align-items: center; gap: .2rem; margin: .45rem 0 -.25rem .6rem; font-size: .74em; color: var(--muted); white-space: nowrap; user-select: none; }
.msg.out .meta { color: var(--meta-out); }
.ticks { display: inline-flex; color: inherit; }
.ticks.read { color: var(--accent); }
.msg.out .ticks.read { color: color-mix(in srgb, var(--accent) 80%, #0a3); }
:root[data-theme="dark"] .msg.out .ticks.read { color: #fff; }
.msg.deleted .text { font-style: italic; color: var(--muted); }
.reply-ref { display: block; border-left: 3px solid var(--accent); padding: .1rem .5rem; margin: .1rem 0 .3rem; border-radius: 4px; background: var(--accent-soft); color: inherit; text-decoration: none; font-size: .87em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 320px; }
.att-img img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin: .1rem 0 .25rem; }
.att-file { display: flex; gap: .6rem; align-items: center; color: inherit; text-decoration: none; padding: .2rem 0 .3rem; }
.att-file .ic { width: 40px; height: 40px; padding: 9px; border-radius: 50%; background: var(--accent); color: #fff; }
.att-file span { display: flex; flex-direction: column; } .att-file small { color: var(--muted); }
.msg-actions { position: absolute; top: -14px; display: none; gap: 2px; background: var(--panel); border-radius: 14px; box-shadow: var(--pop-shadow); padding: 2px; }
.msg.in .msg-actions { right: -8px; } .msg.out .msg-actions { left: -8px; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { display: flex; }
.msg-actions button { background: none; color: var(--muted); padding: 4px; border-radius: 50%; display: grid; }
.msg-actions button:hover { background: var(--hover); color: var(--text); }

/* composer */
.readonly-bar { margin: 0 auto .9rem; background: var(--panel); padding: .7rem 1.4rem; border-radius: 14px; color: var(--muted); box-shadow: var(--shadow); }
.composer { position: relative; flex: none; display: flex; flex-direction: column; gap: .3rem; padding: .3rem max(1rem, calc((100% - 760px) / 2)) max(.9rem, calc(.4rem + env(safe-area-inset-bottom))); }
.composer-row { display: flex; align-items: flex-end; gap: .5rem; }
.composer-box { flex: 1; display: flex; align-items: flex-end; gap: .1rem; background: var(--panel); border-radius: 18px; padding: .2rem .3rem; box-shadow: var(--shadow); min-height: 54px; }
.composer-box .icon-btn { margin-bottom: 2px; }
.composer textarea { flex: 1; border: 0; background: none; resize: none; padding: .9rem .3rem .75rem; line-height: 1.35; max-height: 180px; outline: none; }
.send-btn { width: 54px; height: 54px; border-radius: 50%; padding: 0; display: grid; place-items: center; background: var(--accent); box-shadow: var(--shadow); flex: none; }
.send-btn .ic { transform: translateX(-1px); }
.reply-bar, .file-chip { display: flex; align-items: center; justify-content: space-between; gap: .5rem; background: var(--panel); border-radius: 12px; padding: .3rem .4rem .3rem .8rem; box-shadow: var(--shadow); border-left: 3px solid var(--accent); font-size: .9em; }
.reply-bar span, .file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; gap: .3rem; align-items: center; }
.emoji-pop { position: absolute; bottom: 4.6rem; left: max(1rem, calc((100% - 760px) / 2)); z-index: 30; width: 340px; height: 380px; display: flex; flex-direction: column; background: var(--panel); border-radius: 14px; box-shadow: var(--pop-shadow); overflow: hidden; }
.emoji-pop[hidden] { display: none; }
.emo-search { display: flex; align-items: center; gap: .5rem; margin: .6rem .6rem .3rem; padding: .35rem .7rem; background: var(--hover); border-radius: 18px; color: var(--muted); }
.emo-search input { flex: 1; border: 0; background: none; outline: none; color: var(--text); font: inherit; min-width: 0; padding: .15rem 0; }
.emo-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(8, 1fr); align-content: start; gap: 2px; padding: 0 .5rem .4rem; }
.emo-title { grid-column: 1 / -1; font-size: .78rem; font-weight: 500; color: var(--muted); padding: .35rem .2rem .2rem; }
.emo-tabs { display: flex; flex-wrap: nowrap; gap: 0; justify-content: space-between; border-top: 1px solid var(--line); padding: .25rem .4rem; }
.emo-tab { flex: 1 1 0; min-width: 0; background: none; color: var(--muted); padding: .35rem 0; border-radius: 8px; display: grid; place-items: center; }
.emo-tab.on, .emo-tab:hover { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.emo { background: none; font-size: 1.45rem; padding: .2rem; border-radius: 8px; line-height: 1.2; font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }
.emo:hover { background: var(--hover); }

/* info panel */
.info-panel { width: 360px; flex: none; border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; display: flex; flex-direction: column; }
.info-head { display: flex; align-items: center; gap: .6rem; padding: .35rem .6rem; height: 56px; }
.info-head strong { flex: 1; font-weight: 500; font-size: 1.05em; }
.info-hero { display: flex; flex-direction: column; align-items: center; gap: .4rem; padding: .5rem 1rem 1rem; text-align: center; }
.info-hero h2 { margin: .5rem 0 0; font-size: 1.25rem; font-weight: 500; }
.info-desc { padding: .6rem 1.4rem; white-space: pre-wrap; display: flex; flex-direction: column; gap: .2rem; }
.info-desc small { color: var(--muted); }
.info-form { display: flex; flex-direction: column; gap: .8rem; padding: 0 1.2rem 1rem; }
.info-form label { display: flex; flex-direction: column; gap: .3rem; font-size: .85em; color: var(--muted); }
.info-form input, .info-form textarea { color: var(--text); font-size: 1rem; }
.row-end { display: flex; justify-content: flex-end; gap: .5rem; }
.info-section { border-top: 8px solid var(--bg-2); padding: .4rem 0; }
.sec-title { padding: .5rem 1.4rem; color: var(--accent); font-weight: 500; font-size: .92em; }
.member-list, .add-results { list-style: none; margin: 0; padding: 0 .4rem; }
.member-list li, .add-results li { display: flex; align-items: center; gap: .8rem; padding: .45rem 1rem; border-radius: 10px; }
.member-list li:hover, .add-results li:hover { background: var(--hover); }
.add-results li { cursor: pointer; }
.mi { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mi b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mi small { color: var(--muted); } .mi .on { color: var(--accent); }
.role { color: var(--muted); font-size: .82em; }
.m-acts { display: flex; gap: 2px; }
.m-acts button { background: none; color: var(--muted); padding: 5px; border-radius: 50%; display: grid; }
.m-acts button:hover { background: var(--bg-2); color: var(--text); }
.m-acts button.danger:hover { color: var(--danger); }
.add-member { padding: 0 1rem .4rem; }
.add-member .search { height: 38px; }
.row-btn { display: flex; align-items: center; gap: 1.2rem; width: 100%; background: none; color: var(--text); padding: .8rem 1.4rem; border-radius: 0; text-align: left; }
.row-btn:hover { background: var(--hover); }
.row-btn.danger, .btn-text.danger { color: var(--danger); }
.btn-text { background: none; color: var(--accent); font-weight: 500; padding: .45rem .8rem; border-radius: 8px; display: inline-flex; align-items: center; gap: .3rem; cursor: pointer; }
.btn-text:hover { background: var(--accent-soft); }
.btn { background: var(--accent); color: #fff; }

/* dialogs & toast */
.dlg { border: 0; border-radius: 14px; padding: 1.2rem 1.4rem .8rem; width: min(380px, 92vw); background: var(--panel); color: var(--text); box-shadow: var(--pop-shadow); }
.dlg::backdrop { background: rgba(0,0,0,.4); }
.dlg h3 { margin: 0 0 .6rem; font-weight: 500; }
.dlg p { margin: 0 0 1rem; color: var(--muted); }
.dlg-actions { display: flex; justify-content: flex-end; gap: .3rem; }
.theme-pick { border: 0; padding: 0; margin: 0 0 1rem; display: flex; flex-direction: column; gap: .3rem; }
.theme-pick legend { color: var(--muted); font-size: .85em; margin-bottom: .3rem; }
.theme-pick label { display: flex; align-items: center; gap: .7rem; padding: .45rem .3rem; border-radius: 8px; cursor: pointer; }
.theme-pick label:hover { background: var(--hover); }
.theme-pick input { accent-color: var(--accent); }
.toast { position: fixed; left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; background: rgba(30,30,30,.92); color: #fff; padding: .6rem 1rem; border-radius: 10px; font-size: .92em; max-width: 90vw; }

/* ---------- responsive: list and chat are separate screens ---------- */
@media (max-width: 1100px) {
  .info-panel { position: absolute; right: 0; top: 0; bottom: 0; z-index: 15; box-shadow: var(--pop-shadow); }
}
@media (max-width: 768px) {
  .sidebar { width: 100%; max-width: none; min-width: 0; border-right: 0; }
  .chat-pane { position: absolute; inset: 0; transform: translateX(100%); transition: transform .2s ease-out; z-index: 5; }
  .chat-pane { visibility: hidden; transition: transform .2s ease-out, visibility 0s linear .2s; }
  .tg.chat-open .chat-pane { transform: none; visibility: visible; transition: transform .2s ease-out; }
  /* backdrop-filter on the sticky day separators (PR #25) inside the sliding pane breaks compositing on
     Android Chrome/PWA (pane painted blank/off-screen). Plain translucent pill on phones instead. */
  .day-sep span { -webkit-backdrop-filter: none; backdrop-filter: none; background: color-mix(in srgb, #000 55%, transparent); }
  .tg.chat-open .sidebar { visibility: hidden; }
  .chat-header { padding-left: .2rem; }
  .chat-header .back { display: inline-grid; }
  #infoBtn { display: none; }
  .msg { max-width: 88%; }
  .messages, .composer { padding-left: .5rem; padding-right: .5rem; }
  .composer { padding-bottom: max(.5rem, calc(.3rem + env(safe-area-inset-bottom))); }
  .chat-pane { padding-left: env(safe-area-inset-left); }
  .info-panel { width: 100%; z-index: 25; }
  .emoji-pop { left: .5rem; right: .5rem; width: auto; }
  .send-btn, .composer-box { min-height: 48px; } .send-btn { width: 48px; height: 48px; }
  .composer textarea { padding: .75rem .3rem .65rem; }
}

/* ---------- settings link, profile & new-chat pages ---------- */
.btn-row { display: flex; align-items: center; gap: .8rem; padding: .6rem .2rem; color: var(--accent); text-decoration: none; font-weight: 500; }
.page-shell { height: 100vh; height: -webkit-fill-available; padding-bottom: env(safe-area-inset-bottom); }
@supports (height: 100dvh) { .page-shell { height: 100dvh; } }
.page-shell { overflow-y: auto; background: var(--bg-2); }
.page-bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: .8rem; height: calc(56px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top) !important; padding: 0 .8rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.page-bar h1 { font-size: 1.1rem; margin: 0; flex: 1; }
.page-bar .icon-btn { background: none; color: var(--muted); border-radius: 50%; width: 40px; height: 40px; display: grid; place-items: center; text-decoration: none; }
.page-bar .icon-btn:hover { background: var(--hover); }
.page-body { max-width: 560px; margin: 0 auto; padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.sheet { background: var(--panel); border-radius: 14px; padding: 1rem; box-shadow: 0 1px 2px rgb(0 0 0 / .06); }
.sheet h2 { font-size: .85rem; color: var(--accent); margin: 0 0 .6rem; font-weight: 500; }
.av-edit { position: relative; width: 120px; height: 120px; margin: .5rem auto 1rem; display: block; cursor: pointer; border-radius: 50%; }
.av-edit .avatar { width: 120px; height: 120px; font-size: 2.6rem; }
.av-edit .av-cam { position: absolute; inset: 0; border-radius: 50%; display: grid; place-items: center; background: rgb(0 0 0 / .35); color: #fff; opacity: 0; transition: opacity .15s; }
.av-edit:hover .av-cam, .av-edit:focus-within .av-cam { opacity: 1; }
.av-edit input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .8rem; }
.field span { font-size: .8rem; color: var(--muted); }
.field input, .field textarea { font: inherit; color: var(--text); background: transparent; border: 0; border-bottom: 2px solid var(--line); padding: .45rem .1rem; outline: none; resize: vertical; }
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.hint { font-size: .8rem; color: var(--muted); margin: .2rem 0 0; }
.row-actions { display: flex; gap: .6rem; justify-content: flex-end; flex-wrap: wrap; }
.btn-primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: .6rem 1.2rem; font: inherit; font-weight: 500; cursor: pointer; }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: none; color: var(--accent); border: 0; border-radius: 10px; padding: .6rem 1rem; font: inherit; font-weight: 500; cursor: pointer; }
.btn-ghost.danger { color: #e53935; }
.btn-ghost:hover { background: var(--hover); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; background: var(--hover); padding: .3rem; border-radius: 12px; }
.seg label { display: flex; flex-direction: column; align-items: center; gap: .2rem; padding: .55rem .3rem; border-radius: 9px; cursor: pointer; color: var(--muted); font-size: .85rem; font-weight: 500; text-align: center; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--panel); color: var(--accent); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
.seg small { font-weight: 400; font-size: .72rem; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .5rem; min-height: 0; }
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: 2px .5rem 2px 2px; border-radius: 16px; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--text); font-size: .88rem; border: 0; cursor: pointer; font-family: inherit; }
.chip .avatar { width: 26px; height: 26px; font-size: .7rem; }
.chip:hover { background: color-mix(in srgb, #e53935 18%, transparent); }
.people { list-style: none; margin: .3rem 0 0; padding: 0; max-height: 360px; overflow-y: auto; }
.people li { display: flex; align-items: center; gap: .8rem; padding: .45rem .4rem; border-radius: 10px; cursor: pointer; }
.people li:hover, .people li:focus { background: var(--hover); outline: none; }
.people .mi { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.people .mi small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people .tick { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; color: #fff; }
.people li.sel .tick { background: var(--accent); border-color: var(--accent); }
.people li:not(.sel) .tick .ic { visibility: hidden; }
.search-box { display: flex; align-items: center; gap: .5rem; padding: .45rem .8rem; background: var(--hover); border-radius: 20px; color: var(--muted); }
.search-box input { flex: 1; border: 0; background: none; outline: none; color: var(--text); font: inherit; }
.form-error { color: #e53935; font-size: .9rem; }
.form-error:empty { display: none; }

/* ---- push prompt + notification settings ---- */
.push-prompt { display: flex; align-items: center; gap: .6rem; margin: .3rem .5rem .4rem; padding: .55rem .4rem .55rem .7rem; border-radius: 12px; background: color-mix(in srgb, var(--accent) 10%, var(--panel)); }
.push-prompt .pp-ic .ic { width: 22px; height: 22px; color: var(--accent); }
.pp-text { flex: 1; display: flex; flex-direction: column; min-width: 0; font-size: .9em; } .pp-text small { color: var(--muted); }
.push-prompt .btn-ghost { padding: .4rem .6rem; }
.push-prompt .icon-btn { width: 32px; height: 32px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .55rem 0; cursor: pointer; }
.switch-row > span { display: flex; align-items: center; gap: .8rem; } .switch-row > span > .ic { color: var(--muted); flex: none; }
.switch-row > span > span { display: flex; flex-direction: column; } .switch-row small { color: var(--muted); font-size: .8rem; }
.switch-row input[type=checkbox] { appearance: none; width: 40px; height: 22px; border-radius: 11px; background: var(--line); position: relative; flex: none; cursor: pointer; transition: background .15s; }
.switch-row input[type=checkbox]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgb(0 0 0 / .3); }
.switch-row input:checked { background: var(--accent); } .switch-row input:checked::after { transform: translateX(18px); }
.switch-row input:disabled { opacity: .5; cursor: default; }
.hint .ic { width: 14px; height: 14px; vertical-align: -2px; }

/* ---- file chips ---- */
.att-file { background: color-mix(in srgb, var(--accent) 7%, transparent); border-radius: 12px; padding: .45rem .7rem .45rem .45rem; margin: .1rem 0 .3rem; min-width: 220px; max-width: 320px; }
.att-file span { flex: 1; min-width: 0; } .att-file b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.att-file .att-dl { width: 18px; height: 18px; padding: 0; background: none; color: var(--muted); flex: none; }
.att-file:hover .att-dl { color: var(--accent); }
.att-img { cursor: zoom-in; display: inline-block; }

/* ---- media viewer ---- */
body.no-scroll { overflow: hidden; }
.viewer { position: fixed; inset: 0; z-index: 80; background: rgb(0 0 0 / .92); display: grid; grid-template-columns: 64px 1fr 64px; grid-template-rows: auto 1fr; outline: none; animation: vw-in .15s ease-out; }
.viewer[hidden] { display: none; }
@keyframes vw-in { from { opacity: 0; } }
.vw-top { grid-column: 1 / -1; display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem; color: #fff; }
.vw-who { flex: 1; display: flex; flex-direction: column; min-width: 0; } .vw-who small { color: #bbb; font-size: .8em; }
.vw-count { color: #ccc; font-size: .9em; margin-right: .5rem; }
.viewer .icon-btn { color: #eee; } .viewer .icon-btn:hover { background: rgb(255 255 255 / .12); }
.vw-stage { margin: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; padding-bottom: 1rem; touch-action: pan-y pinch-zoom; }
.vw-stage img { max-width: 100%; max-height: calc(100vh - 140px); object-fit: contain; user-select: none; transition: transform .1s; }
.vw-stage figcaption { color: #eee; margin-top: .6rem; max-width: 70ch; text-align: center; font-size: .95em; }
.vw-stage figcaption:empty { display: none; }
.vw-nav { align-self: center; justify-self: center; width: 48px; height: 48px; border-radius: 50%; border: 0; background: rgb(255 255 255 / .1); color: #fff; cursor: pointer; display: grid; place-items: center; }
.vw-nav:hover { background: rgb(255 255 255 / .2); } .vw-nav .ic { width: 28px; height: 28px; } .vw-nav[hidden] { visibility: hidden; display: grid; }
@media (max-width: 768px) {
  .viewer { grid-template-columns: 0 1fr 0; }
  .vw-nav { display: none !important; }
  .vw-stage img { max-height: calc(100vh - 120px); }
}
.att-img:focus:not(:focus-visible) { outline: none; }

/* "A new version is available" — top centre so it never covers the FAB or composer. */
.update-banner { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  top: calc(.6rem + env(safe-area-inset-top)); display: flex; align-items: center; gap: .6rem;
  max-width: calc(100vw - 1.5rem); padding: .45rem .5rem .45rem .9rem; border-radius: 999px;
  background: #1f2937; color: #fff; box-shadow: 0 6px 24px rgba(0,0,0,.25); font-size: .92rem; animation: upd-in .25s ease-out; }
.update-banner span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.update-banner .update-refresh { border: 0; border-radius: 999px; padding: .35rem .85rem; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.update-banner .update-close { border: 0; background: transparent; color: #cbd5e1; font-size: 1.2rem; line-height: 1; padding: 0 .3rem; cursor: pointer; }
[data-theme=dark] .update-banner { background: #e5e7eb; color: #111827; }
[data-theme=dark] .update-banner .update-close { color: #4b5563; }
@keyframes upd-in { from { opacity: 0; transform: translate(-50%, -8px); } }

/* ---------- reactions ---------- */
.reactions { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .3rem; }
.rx { display: inline-flex; align-items: center; gap: .25rem; border: 1px solid transparent; border-radius: 999px; padding: .05rem .45rem;
  font-size: .9rem; line-height: 1.5; background: rgba(0,0,0,.06); color: inherit; cursor: pointer; }
.rx span { font-size: .75rem; font-weight: 600; opacity: .8; }
.rx.mine { background: color-mix(in srgb, var(--accent) 18%, transparent); border-color: color-mix(in srgb, var(--accent) 55%, transparent); }
[data-theme=dark] .rx { background: rgba(255,255,255,.08); }
.react-bar { position: absolute; z-index: 20; display: flex; gap: .15rem; padding: .25rem; border-radius: 999px;
  background: var(--panel, #fff); box-shadow: 0 4px 18px rgba(0,0,0,.18); }
[data-theme=dark] .react-bar { background: #26303b; }
.react-bar button { border: 0; background: transparent; font-size: 1.35rem; width: 2.3rem; height: 2.3rem; border-radius: 50%; cursor: pointer; transition: transform .1s; }
.react-bar button:hover, .react-bar button:focus-visible { transform: scale(1.2); background: rgba(0,0,0,.06); }
@keyframes hit-flash { 0%, 60% { background: color-mix(in srgb, var(--accent) 22%, transparent); } 100% { background: transparent; } }
.msg.flash-hit { animation: hit-flash 1.8s ease-out; border-radius: .6rem; }
/* ---------- search ---------- */
.chat-search { position: relative; display: flex; align-items: center; gap: .4rem; padding: .4rem .75rem; border-bottom: 1px solid var(--line, rgba(0,0,0,.08)); flex: none; }
.chat-search .search { flex: 1; }
.cs-count { font-size: .8rem; white-space: nowrap; }
.cs-results { position: absolute; z-index: 15; left: 0; right: 0; top: 100%; max-height: min(60vh, 26rem); overflow: auto; margin: 0; padding: .25rem 0; list-style: none;
  background: var(--panel, #fff); box-shadow: 0 8px 24px rgba(0,0,0,.15); }
[data-theme=dark] .cs-results { background: #1f2933; }
.chat-item.hit mark { background: color-mix(in srgb, var(--accent) 30%, transparent); color: inherit; border-radius: .2rem; padding: 0 .1rem; }
.list-more { list-style: none; text-align: center; padding: .5rem; }
.list-more button { border: 0; background: transparent; color: var(--accent); font-weight: 600; cursor: pointer; }

/* External sign-in */
.ext-login { display: flex; flex-direction: column; gap: .75rem; }
.ext-btn { display: block; text-align: center; padding: .65rem .9rem; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text, inherit); font-weight: 600; text-decoration: none; }
.ext-btn:hover { border-color: var(--accent); }
.ext-login .or { display: flex; align-items: center; gap: .6rem; margin: 0; color: var(--muted, #888); font-size: .85rem; }
.ext-login .or::before, .ext-login .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* Bots */
.bot-badge { display: inline-block; margin-left: .35rem; padding: 0 .35rem; border-radius: 6px; font-size: .68rem; font-weight: 700; line-height: 1.3; letter-spacing: .02em; text-transform: uppercase; vertical-align: middle; background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.bot-list { display: grid; gap: .75rem; }
.bot-card { display: grid; grid-template-columns: 48px 1fr; gap: .75rem; align-items: start; }
.bot-card .avatar-lg { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; background: var(--line); display: grid; place-items: center; font-weight: 700; }
.bot-card h3 { margin: 0; font-size: 1rem; }
.bot-card .row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .5rem; }
.bot-card .row form { display: inline-flex; gap: .4rem; align-items: center; margin: 0; }
.bot-card .row input, .bot-card .row select { padding: .35rem .5rem; }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-all; background: var(--bg, #0001); padding: .5rem; border-radius: 8px; border: 1px dashed var(--accent); }
/* Filled red only for the Admin › Bots delete button (a global button.danger also painted the chat info panel). */
.bot-card button.danger { background: var(--danger); }
button.ghost { background: none; color: var(--accent); border: 1px solid var(--line); }

/* Assistant reply being streamed: blinking caret after the text. */
.msg .caret { margin-left: 1px; animation: caret 1s steps(1) infinite; opacity: .6; }
@keyframes caret { 50% { opacity: 0; } }

.m-acts button.on { color: var(--accent, #2b7de9); }

/* ---------- calls (Telegram-style full-screen call) ---------- */
.call-screen { position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: max(3rem, env(safe-area-inset-top)) 1rem max(2.5rem, env(safe-area-inset-bottom)); color: #fff; overflow: hidden;
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 75%, #1b2735), #16202b 70%); }
.call-screen[hidden] { display: none; }
.call-bg { position: absolute; inset: 0; background: radial-gradient(circle at 30% 20%, rgba(255,255,255,.18), transparent 55%); pointer-events: none; }
.call-top { position: relative; display: flex; flex-direction: column; align-items: center; gap: .4rem; text-align: center; }
.call-top h2 { margin: .6rem 0 0; font-size: 1.6rem; font-weight: 600; }
.call-status { margin: 0; opacity: .8; font-variant-numeric: tabular-nums; }
.call-avatar .avatar { width: 7.5rem; height: 7.5rem; font-size: 2.6rem; box-shadow: 0 0 0 .5rem rgba(255,255,255,.08), 0 0 0 1.1rem rgba(255,255,255,.04); }
.call-screen:not(.video) .call-avatar .avatar { animation: call-pulse 2s ease-in-out infinite; }
@keyframes call-pulse { 50% { box-shadow: 0 0 0 .9rem rgba(255,255,255,.1), 0 0 0 1.8rem rgba(255,255,255,.04); } }
.call-actions { position: relative; display: flex; gap: 2.2rem; justify-content: center; }
.call-act { display: flex; flex-direction: column; align-items: center; gap: .45rem; font-size: .8rem; opacity: .95; }
.call-btn { width: 3.75rem; height: 3.75rem; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer;
  background: rgba(255,255,255,.18); color: #fff; backdrop-filter: blur(8px); transition: transform .12s, background .12s; }
.call-btn:hover { background: rgba(255,255,255,.28); } .call-btn:active { transform: scale(.94); }
.call-btn .ic { width: 1.6rem; height: 1.6rem; }
.call-btn[aria-pressed="true"] { background: #fff; color: #16202b; }
.call-btn.accept { background: #4fae4e; } .call-btn.accept:hover { background: #5cc05b; }
.call-btn.accept .ic { animation: call-shake 1.2s ease-in-out infinite; }
@keyframes call-shake { 0%, 60%, 100% { transform: rotate(0); } 10%, 30%, 50% { transform: rotate(-14deg); } 20%, 40% { transform: rotate(14deg); } }
.call-btn.decline { background: #e5484d; } .call-btn.decline:hover { background: #f05a5f; }
.call-remote-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.call-local-video { position: absolute; right: 1rem; top: max(1rem, env(safe-area-inset-top)); width: 7.5rem; aspect-ratio: 3 / 4; object-fit: cover;
  border-radius: .9rem; box-shadow: 0 4px 18px rgba(0,0,0,.45); transform: scaleX(-1); z-index: 2; }
.call-remote-video[hidden], .call-local-video[hidden] { display: none; }
.call-screen.video .call-top, .call-screen.video .call-actions { z-index: 1; text-shadow: 0 1px 4px rgba(0,0,0,.5); }
body.in-call { overflow: hidden; }
