:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-dim: #0ea5e9;
  --success: #4ade80;
  --danger: #f87171;
  --radius: 12px;
  --font: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: linear-gradient(160deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
  color: var(--text);
  min-height: 100dvh;
}

.blinkey-update-banner {
  position: fixed;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  max-width: min(520px, calc(100vw - 1.5rem));
  padding: .6rem .75rem;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
  font-size: .85rem;
}
.blinkey-update-banner span { flex: 1; min-width: 10rem; }

.page-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: 0 25px 50px rgba(0,0,0,.4);
  border: 1px solid var(--surface2);
}

.brand { text-align: center; margin-bottom: 1.5rem; }
.logo {
  display: block;
  margin: 0 auto 0.75rem;
  max-width: min(240px, 85vw);
  height: auto;
}
.brand h1 { font-size: 1.35rem; font-weight: 700; }
.subtitle { color: var(--accent); font-size: .95rem; font-weight: 600; margin-top: .25rem; }
.brand-hint { text-align: center; margin-top: .5rem; margin-bottom: 0; }

.form label { display: block; font-size: .8rem; color: var(--muted); margin: .75rem 0 .35rem; }
.form input {
  width: 100%;
  padding: .65rem .85rem;
  border: 1px solid var(--surface2);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
.form input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.form.compact label { margin-top: .5rem; }
.hint { font-size: .75rem; color: var(--muted); margin-top: .35rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: .7rem 1.2rem;
  border: none;
  border-radius: 8px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform .1s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: #0f172a; width: 100%; margin-top: 1.25rem; }
.btn-primary:hover { background: var(--accent-dim); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); width: 100%; margin-top: .75rem; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--surface2); }
.btn-sm { padding: .45rem .8rem; font-size: .85rem; margin-top: .5rem; width: 100%; }

.tabs { display: flex; gap: .5rem; margin-bottom: 1rem; }
.tab {
  flex: 1;
  padding: .5rem;
  border: 1px solid var(--surface2);
  background: var(--bg);
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  font-size: .85rem;
}
.tab.active { background: var(--accent); color: #0f172a; border-color: var(--accent); font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.error { color: var(--danger); font-size: .85rem; margin-top: .75rem; }

.auth-alert {
  position: fixed;
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  max-width: min(92vw, 24rem);
  padding: .85rem 1.1rem;
  border-radius: 10px;
  font-size: .9rem;
  line-height: 1.35;
  text-align: center;
  z-index: 300;
  background: #450a0a;
  color: #fecaca;
  border: 1px solid #b91c1c;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}
.hidden { display: none !important; }
.footer-link { text-align: center; margin-top: 1.25rem; font-size: .85rem; }
.footer-link a { color: var(--accent); }

.result-panel { margin-top: 1rem; padding: 1rem; background: var(--bg); border-radius: 8px; }
.success-label { color: var(--success); font-size: .9rem; margin-bottom: .75rem; }
.credential-box > div {
  display: flex;
  justify-content: space-between;
  padding: .5rem 0;
  border-bottom: 1px solid var(--surface2);
  font-size: .9rem;
}
.credential-box strong { color: var(--accent); font-family: monospace; letter-spacing: .05em; }
.push-settings {
  margin: .75rem 0;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.push-settings .push-status { margin: 0; }

/* Chatroom */
.page-chat { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.page-chat .chat-layout { flex: 1; min-height: 0; }
.badge {
  font-size: .65rem;
  background: var(--accent);
  color: #0f172a;
  padding: .1rem .4rem;
  border-radius: 4px;
  margin-left: .25rem;
}

.chat-layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 280px;
  max-width: 35vw;
  background: var(--surface);
  border-right: 1px solid var(--surface2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-header-block {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 1rem 1rem .65rem;
  background: var(--surface);
}
.sidebar-logo {
  width: auto;
  max-width: min(180px, 78vw);
  height: auto;
  max-height: 52px;
  object-fit: contain;
  flex-shrink: 0;
}
.sidebar-tagline {
  margin-top: .4rem;
  font-size: .78rem;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: .02em;
}
.sync-status {
  margin: .35rem 0 0;
  font-size: .72rem;
  line-height: 1.35;
  color: var(--muted);
}
.sync-status.sync-status-syncing {
  color: var(--accent);
}
.sync-status.sync-status-offline {
  color: #fbbf24;
}
.sync-status.sync-status-ok {
  color: #86efac;
}
.sidebar-user-btn {
  flex-shrink: 0;
  display: block;
  width: calc(100% - 2rem);
  margin: 0 1rem .65rem;
  padding: .7rem .85rem;
  border: 1px solid var(--surface2);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  box-sizing: border-box;
}
.sidebar-user-btn:hover { background: rgba(56, 189, 248, .08); border-color: rgba(56, 189, 248, .35); }
.sidebar-user-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .75rem;
  padding: .2rem 0;
}
.sidebar-user-row + .sidebar-user-row {
  margin-top: .15rem;
  padding-top: .45rem;
  border-top: 1px solid var(--surface2);
}
.sidebar-user-label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  flex-shrink: 0;
}
.sidebar-user-value {
  font-size: .88rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
  min-width: 0;
}
.sidebar-actions-wrap {
  flex-shrink: 0;
  margin: 0 0 .5rem;
}
.sidebar-actions {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: safe center;
  gap: .4rem;
  width: 100%;
  padding: .15rem 1rem .65rem;
  scroll-behavior: smooth;
}
.sidebar-action-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  flex: 0 0 auto;
  min-width: 4.25rem;
  max-width: 5.5rem;
  padding: .5rem .45rem;
  border: 1px solid var(--surface2);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  font-size: .84rem;
  font-family: inherit;
}
.sidebar-action-btn:hover { background: rgba(56, 189, 248, .08); border-color: rgba(56, 189, 248, .35); }
.sidebar-action-btn.is-hide-mode {
  border-color: rgba(248, 113, 113, .55);
  background: rgba(248, 113, 113, .12);
}
.sidebar-action-btn.is-hide-mode i,
.sidebar-action-btn.is-hide-mode .sidebar-action-label {
  color: #fecaca;
}
.sidebar-action-btn.is-delete-mode {
  border-color: rgba(248, 113, 113, .55);
  background: rgba(248, 113, 113, .16);
}
.sidebar-action-btn.is-delete-mode i,
.sidebar-action-btn.is-delete-mode .sidebar-action-label {
  color: #fecaca;
}
#btnDeleteSelectedChats {
  display: none;
}
.sidebar-actions.selection-mode #btnDeleteSelectedChats {
  display: flex;
}
.sidebar-actions.selection-mode .sidebar-action-btn:not(#btnRevealHide):not(#btnDeleteSelectedChats) {
  display: none;
}
.sidebar-action-btn i {
  width: auto;
  text-align: center;
  font-size: 1.05rem;
  color: var(--accent);
  flex-shrink: 0;
}
.sidebar-action-label {
  flex: none;
  min-width: 0;
  font-size: .62rem;
  line-height: 1.15;
  font-weight: 600;
  color: var(--muted);
}
.sidebar-action-badge {
  position: absolute;
  top: .2rem;
  right: .2rem;
  margin-left: 0;
  flex-shrink: 0;
}
.member-list-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.member-list {
  list-style: none;
  flex: 1;
  min-height: 0;
  scroll-behavior: smooth;
}

/* Scroll strips — hidden scrollbars + edge arrows */
.scroll-strip { position: relative; }
.scroll-strip-viewport {
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-behavior: smooth;
}
.scroll-strip-viewport::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}
.scroll-strip-x {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  width: 100%;
  min-width: 0;
}
.scroll-strip-x > .scroll-strip-viewport {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
}
.scroll-strip-y {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.scroll-strip-y > .scroll-strip-viewport {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}
.scroll-arrow {
  position: absolute;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--accent);
  background: transparent;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.scroll-strip.overflows.can-scroll-start .scroll-arrow-start,
.scroll-strip.overflows.can-scroll-end .scroll-arrow-end {
  opacity: 1;
  pointer-events: auto;
}
.scroll-strip-x .scroll-arrow {
  top: 0;
  bottom: 0;
  width: 1.75rem;
}
.scroll-strip-x .scroll-arrow-start {
  left: 0;
  background: linear-gradient(90deg, var(--surface) 35%, transparent);
}
.scroll-strip-x .scroll-arrow-end {
  right: 0;
  background: linear-gradient(270deg, var(--surface) 35%, transparent);
}
.scroll-strip-y .scroll-arrow {
  left: 0;
  right: 0;
  height: 1.75rem;
}
.scroll-strip-y .scroll-arrow-start {
  top: 0;
  background: linear-gradient(180deg, var(--surface) 40%, transparent);
}
.scroll-strip-y .scroll-arrow-end {
  bottom: 0;
  background: linear-gradient(0deg, var(--surface) 40%, transparent);
}
.scroll-arrow i {
  font-size: .85rem;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .45));
}
.messages-scroll-wrap {
  flex: 1;
  min-height: 0;
}
.messages-scroll-wrap .scroll-arrow-start {
  background: linear-gradient(180deg, var(--surface) 40%, transparent);
}
.messages-scroll-wrap .scroll-arrow-end {
  background: linear-gradient(0deg, var(--surface) 40%, transparent);
}
.emoji-picker-scroll {
  position: absolute;
  bottom: calc(100% + .5rem);
  left: 0;
  width: min(320px, calc(100vw - 2rem));
  max-height: 220px;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.emoji-picker-scroll .scroll-strip-viewport.emoji-picker {
  position: static;
  width: 100%;
  flex: 1;
  min-height: 0;
  max-height: 220px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
}
.emoji-picker-scroll .scroll-arrow-start {
  background: linear-gradient(180deg, var(--surface) 40%, transparent);
}
.emoji-picker-scroll .scroll-arrow-end {
  background: linear-gradient(0deg, var(--surface) 40%, transparent);
}
.attachment-preview-scroll {
  flex: 1;
  min-width: 0;
}
.attachment-preview-scroll .scroll-strip-viewport.attachment-preview-list {
  flex-wrap: nowrap;
}
.seen-by-scroll-wrap {
  width: 100%;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
}
.seen-by-scroll-wrap .scroll-strip-viewport.seen-by-sheet {
  position: static;
  width: 100%;
  flex: 1;
  min-height: 0;
  max-height: 60vh;
  border-radius: 16px 16px 0 0;
  padding: 1rem 1rem max(1rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--surface2);
  background: var(--surface);
}
.seen-by-scroll-wrap .scroll-arrow-start {
  background: linear-gradient(180deg, var(--surface) 40%, transparent);
}
.seen-by-scroll-wrap .scroll-arrow-end {
  background: linear-gradient(0deg, var(--surface) 40%, transparent);
}
.sidebar-user-avatar,
.chat-list-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--surface2);
}
.sidebar-user-avatar img,
.chat-list-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.avatar-initials {
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
}
.avatar-initials.lg { font-size: 1.75rem; }
.sidebar-user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.sidebar-user-meta strong {
  font-size: .92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-user-meta small { color: var(--muted); font-size: .75rem; }
.btn-logout-profile {
  width: 100%;
  margin-top: .75rem;
  color: var(--danger);
}
.btn-logout-profile:hover {
  background: rgba(239, 68, 68, .12);
}
.chat-list-btn,
li.group-chat-item.chat-list-btn {
  display: flex;
  align-items: center;
  gap: .65rem;
  width: 100%;
  padding: .65rem 1rem;
  border: none;
  border-bottom: 1px solid var(--surface2);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  box-sizing: border-box;
}
li.group-chat-item.chat-list-btn {
  list-style: none;
  -webkit-tap-highlight-color: transparent;
}
.chat-list-btn:hover { background: var(--bg); }
.member-list > li:last-child,
.member-list > li:last-child > .chat-list-btn {
  border-bottom: none;
}
.chat-list-btn.active {
  background: var(--bg);
  border-left: 3px solid var(--accent);
}
.chat-list-btn.hide-selected {
  box-shadow: inset 0 0 0 2px rgba(248, 113, 113, .7);
  background: rgba(248, 113, 113, .12);
}
.chat-list-avatar.group-avatar .group-flag {
  font-size: .75rem;
  font-weight: 800;
  color: var(--accent);
}
.chat-list-top .group-flag,
.peer-name .group-flag {
  flex-shrink: 0;
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--accent);
  padding: .12rem .4rem;
  border: 1px solid color-mix(in srgb, var(--accent) 50%, transparent);
  border-radius: 4px;
  line-height: 1.15;
}
.chat-list-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.chat-list-top { display: flex; align-items: center; gap: .35rem; min-width: 0; }
.chat-list-name {
  font-weight: 600;
  font-size: .92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-list-has-unread .chat-list-name,
.chat-list-has-unread .chat-list-preview {
  font-weight: 700;
  color: var(--text);
}
.chat-list-preview.chat-list-typing {
  font-style: italic;
  font-weight: 600;
  color: var(--accent);
}
li.group-chat-item.is-typing .chat-list-name,
li.dm-member.is-typing .chat-list-name {
  color: var(--accent);
}
.chat-list-preview-row {
  display: flex;
  align-items: center;
  gap: .4rem;
  min-width: 0;
}
.chat-list-preview-row .chat-list-preview {
  flex: 1;
  min-width: 0;
}
.chat-list-preview {
  font-size: .78rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-list-unread {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 .35rem;
  border-radius: 999px;
  background: var(--accent);
  color: #0f172a;
  font-size: .68rem;
  font-weight: 700;
  line-height: 1;
  text-align: center;
}
.chat-list-btn .online-dot {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  margin-left: auto;
}
.chat-list-btn .online-dot.on { background: var(--success); }
.conn-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 .3rem;
  margin-left: .25rem;
  border-radius: 999px;
  font-size: .68rem;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
}
.connection-requests-list {
  list-style: none;
  margin: .75rem 0;
  display: flex;
  flex-direction: column;
  gap: .65rem;
}
.connection-request-item {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  padding: .65rem .75rem;
  border: 1px solid var(--surface2);
  border-radius: 8px;
  background: var(--bg);
}
.connection-request-meta {
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.connection-request-meta strong { font-size: .95rem; }
.connection-request-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}
.msg.system-msg {
  align-self: center;
  max-width: 92%;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: .35rem .5rem;
}
.msg.system-msg .msg-text {
  font-size: .78rem;
  color: var(--muted);
  text-align: center;
  font-style: italic;
}
.composer-disabled {
  opacity: .55;
  pointer-events: none;
}
.chat-list-empty {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--surface2);
}
.chat-list-empty .hint { margin: 0; font-size: .78rem; }
.msg.group-msg .msg-sender {
  display: block;
  font-size: .7rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: .2rem;
}
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.chat-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.chat-active {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}
.chat-active .messages-scroll-wrap {
  flex: 1;
  min-height: 0;
}
.chat-active .messages,
.chat-active .messages-scroll-wrap .messages {
  flex: 1;
  min-height: 0;
}
.chat-peer-bar {
  padding: .5rem .65rem;
  background: var(--surface);
  border-bottom: 1px solid var(--surface2);
  display: flex;
  gap: .5rem;
  align-items: center;
  min-height: 52px;
  flex-shrink: 0;
}
.peer-bar-left {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.btn-peer-nav .icon.hidden { display: none; }
.btn-peer-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  color: var(--text);
  cursor: pointer;
  padding: 0;
}
.btn-peer-nav:hover { color: var(--accent); }
.peer-bar-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .1rem;
}
.peer-bar-identity {
  display: flex;
  align-items: center;
  gap: .55rem;
  min-width: 0;
}
.peer-bar-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--surface2);
}
.peer-bar-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.peer-bar-avatar .avatar-initials {
  font-size: .95rem;
}
.peer-bar-avatar .peer-bar-group-mark {
  font-size: .72rem;
  font-weight: 800;
  color: var(--accent);
}
.peer-bar-titles {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .1rem;
}
.peer-bar-room-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  margin-left: auto;
  gap: .2rem;
}
.peer-bar-room-actions.hidden { display: none !important; }
.btn-peer-invite {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  border-radius: 8px;
}
.btn-peer-invite.hidden { display: none !important; }
.btn-peer-invite:hover { color: var(--text); background: var(--surface2); }
.group-members-list {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin: .75rem 0 0;
  list-style: none;
  padding: 0;
}
.group-member-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: .5rem;
  padding: .55rem .65rem;
  background: var(--surface2);
  border-radius: 8px;
}
.group-member-main {
  display: flex;
  flex: 1;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem .5rem;
  font-size: .9rem;
}
.group-member-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.group-member-main .hint {
  margin: 0;
  font-size: .78rem;
}
.member-badge {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: .12rem .35rem;
  border-radius: 4px;
  background: rgba(56, 189, 248, .15);
  color: var(--accent);
}
.member-online {
  font-size: .72rem;
  color: #86efac;
  font-weight: 600;
}
.group-member-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: .2rem;
  flex-shrink: 0;
  margin-left: auto;
}
.btn-member-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  width: auto;
  min-width: 34px;
  height: 34px;
  padding: 0 .45rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: .95rem;
}
.btn-member-icon:hover {
  background: var(--bg);
  color: var(--text);
}
.btn-member-icon.btn-member-mute {
  color: #fbbf24;
}
.btn-member-icon.btn-member-mute:hover {
  background: rgba(251, 191, 36, .12);
  color: #fde68a;
}
.btn-member-icon.btn-member-unmute {
  color: #86efac;
}
.btn-member-icon.btn-member-connect {
  color: #86efac;
}
.btn-member-icon.btn-member-connect:hover {
  background: rgba(134, 239, 172, .12);
  color: #bbf7d0;
}
.btn-member-icon.btn-member-chat {
  color: var(--accent);
}
.member-connect-pending {
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0 .35rem;
  white-space: nowrap;
}
.btn-member-label {
  font-size: .72rem;
  font-weight: 700;
}
.group-members-connect-hint {
  margin: .35rem 0 0;
  font-size: .78rem;
}
.member-badge-muted {
  background: rgba(251, 191, 36, .18);
  color: #fbbf24;
}
.member-action-message {
  width: 100%;
  margin-top: .35rem;
  resize: vertical;
  min-height: 4.5rem;
  font-family: inherit;
  font-size: .9rem;
  padding: .5rem .65rem;
  border-radius: 8px;
  border: 1px solid var(--surface2);
  background: var(--bg);
  color: var(--text);
}
.connection-request-item.is-room-invite {
  flex-direction: column;
  align-items: stretch;
  gap: .65rem;
}
.connection-request-item.is-room-invite .connection-request-actions {
  justify-content: flex-end;
}
.peer-bar-actions {
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-shrink: 0;
  margin-left: auto;
}
.peer-bar-actions.hidden { display: none !important; }
.btn-peer-action {
  font-size: .72rem;
  font-weight: 600;
  padding: .4rem .65rem;
  border-radius: 8px;
  border: 1px solid var(--surface2);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn-peer-action-delete {
  color: #fecaca;
  border-color: rgba(248, 113, 113, .45);
  background: rgba(248, 113, 113, .12);
}
.chat-peer-bar.has-msg-actions .peer-bar-info {
  opacity: .55;
}
.peer-name {
  display: flex;
  align-items: center;
  gap: .35rem;
  min-width: 0;
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.2;
}
.peer-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.peer-status {
  font-size: .75rem;
  color: var(--muted);
  line-height: 1.3;
}
.peer-status.is-typing .typing-indicator { color: var(--accent); font-style: italic; }
.peer-status-label { color: inherit; }
.typing-indicator { font-style: italic; }
.typing-indicator.hidden { display: none !important; }

.messages-loading {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  color: var(--muted);
  font-size: .9rem;
}
.messages-loading.hidden { display: none !important; }
.loading-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--surface2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chat-active.is-loading-messages .messages { visibility: hidden; min-height: 120px; }

.composer-flag {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .4rem .75rem;
  border-bottom: 1px solid var(--surface2);
}
.composer-flag.hidden { display: none !important; }
.editing-bar { background: rgba(248, 113, 113, .08); }
.editing-label {
  font-size: .75rem;
  font-weight: 700;
  color: var(--danger);
  letter-spacing: .02em;
}
.flag-cancel {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}
.sending-indicator {
  padding: .25rem .75rem 0;
  font-size: .75rem;
  color: var(--accent);
  font-style: italic;
}
.sending-indicator.hidden { display: none !important; }
.composer.is-sending .btn-send { opacity: .55; pointer-events: none; }

.msg .meta {
  display: flex;
  align-items: center;
  gap: .35rem;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: .25rem;
  font-size: .65rem;
  opacity: .85;
}
.seen-by-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.seen-by-modal .seen-by-scroll-wrap {
  position: relative;
  width: min(420px, 100%);
  max-height: 60vh;
}
.seen-by-modal.hidden { display: none !important; }
.seen-by-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .55);
}
.seen-by-sheet {
  position: relative;
  width: min(420px, 100%);
  background: transparent;
  border-radius: 0;
  padding: 0;
  border-top: none;
  max-height: none;
  overflow: visible;
}
.seen-by-sheet h3 { font-size: 1rem; margin-bottom: .75rem; }
.seen-by-list { list-style: none; margin-bottom: 1rem; }
.seen-by-list li {
  padding: .55rem 0;
  border-bottom: 1px solid var(--surface2);
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  font-size: .9rem;
}
.seen-by-list li:last-child { border-bottom: none; }
.seen-by-list small { color: var(--muted); font-size: .75rem; white-space: nowrap; }
.seen-by-empty { color: var(--muted); font-size: .9rem; margin-bottom: 1rem; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal.hidden { display: none !important; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .55);
}
.modal-sheet {
  position: relative;
  width: min(400px, 100%);
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 0;
}
.modal-sheet-scroll {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.modal-sheet-scroll .scroll-arrow-start {
  background: linear-gradient(180deg, var(--surface) 40%, transparent);
}
.modal-sheet-scroll .scroll-arrow-end {
  background: linear-gradient(0deg, var(--surface) 40%, transparent);
}
.modal-sheet-body {
  padding: 1.25rem;
}
.modal-sheet h3 { margin-bottom: 1rem; font-size: 1.05rem; }
.modal-sheet label { display: block; font-size: .8rem; color: var(--muted); margin: .65rem 0 .35rem; }
.modal-sheet input {
  width: 100%;
  padding: .6rem .8rem;
  border: 1px solid var(--surface2);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.modal-actions { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.profile-avatar-upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .65rem;
  cursor: pointer;
  margin-bottom: .5rem;
  width: 100%;
  text-align: center;
}
.modal-sheet label.profile-avatar-upload {
  display: flex;
  margin: 0 0 .5rem;
}
.profile-avatar-lg {
  width: 80px;
  height: 80px;
  flex-shrink: 0;
  margin-left: auto;
  margin-right: auto;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 2px solid var(--surface2);
}
.profile-avatar-lg img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.profile-avatar-lg .avatar-initials.lg {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.messages {
  flex: 1;
  min-height: 0;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.msg {
  max-width: 75%;
  padding: .55rem .85rem;
  border-radius: 14px;
  font-size: .92rem;
  line-height: 1.4;
  position: relative;
  touch-action: pan-y;
  transition: transform .15s ease, box-shadow .15s ease;
  user-select: none;
  -webkit-user-select: none;
}
.msg.swiping {
  transition: none;
  touch-action: none;
}
.msg.msg-selected {
  box-shadow: 0 0 0 2px var(--accent);
  z-index: 2;
}
.msg.swipe-hint-right::before,
.msg.swipe-hint-left::after {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: .65rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s;
}
.msg.swipe-hint-right::before {
  content: 'Reply';
  left: .35rem;
  color: var(--accent);
}
.msg.swipe-hint-left::after {
  content: 'Edit';
  right: .35rem;
  color: #fde68a;
}
.msg.mine.swipe-hint-left::after { opacity: .9; }
.msg.swipe-hint-right::before { opacity: .9; }

.msg-context-menu {
  position: fixed;
  z-index: 200;
  min-width: 9.5rem;
  padding: .35rem 0;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 10px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, .45);
}
.msg-context-menu.hidden { display: none !important; }
.msg-context-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: .55rem .85rem;
  font-size: .88rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.msg-context-item:hover { background: var(--surface2); }
.msg-context-item.hidden { display: none; }
.msg-context-delete { color: #fecaca; }
.msg-context-delete:hover { background: rgba(248, 113, 113, .12); }

.msg.mine { align-self: flex-end; background: var(--accent-dim); color: #fff; border-bottom-right-radius: 4px; }
.msg.theirs { align-self: flex-start; background: var(--surface); border: 1px solid var(--surface2); border-bottom-left-radius: 4px; }
.msg.theirs.unread .msg-sender,
.msg.theirs.unread .msg-text,
.msg.theirs.unread .msg-caption {
  font-weight: 700;
}
.msg.theirs.unread {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--surface2));
}
.msg.deleted { font-style: italic; color: var(--muted); }
.msg .edited-label {
  display: block;
  margin: 0 0 .25rem;
  padding: 0;
  font-size: .68rem;
  font-weight: 500;
  font-style: normal;
  line-height: 1.2;
  color: var(--muted);
  background: none;
  border: none;
}
.msg.mine .edited-label {
  color: rgba(255, 255, 255, 0.55);
}
.status-icon { letter-spacing: -2px; }
.status-icon.seen { color: #7dd3fc; }

.reply-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .5rem .75rem;
  background: var(--bg);
  border-top: 1px solid var(--surface2);
  border-left: 3px solid var(--accent);
}
.reply-bar-inner { flex: 1; min-width: 0; }
.reply-bar-label {
  display: block;
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--accent);
  font-weight: 700;
}
.reply-bar-preview {
  display: block;
  font-size: .85rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-bar-cancel {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--surface2);
  color: var(--text);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.reply-bar-cancel:hover { background: var(--danger); color: #fff; }

.attachment-bar {
  display: flex;
  align-items: flex-start;
  gap: .65rem;
  padding: .55rem .75rem;
  border-bottom: 1px solid var(--surface2);
  background: rgba(56, 189, 248, .06);
}
.attachment-bar.hidden { display: none !important; }
.attachment-preview-list {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  flex: 1;
  min-width: 0;
}
.attachment-preview-item {
  position: relative;
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.attachment-preview-item img,
.attachment-preview-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.attachment-preview-item .file-icon {
  width: 32px;
  height: 32px;
  color: var(--accent);
}
.attachment-preview-item .heic-label {
  font-size: .55rem;
  font-weight: 600;
  color: var(--muted);
  margin-top: .15rem;
  letter-spacing: .02em;
}
.attachment-preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.attachment-preview-remove:hover {
  background: var(--danger);
}
.attachment-bar-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .5rem;
  padding-top: .15rem;
}
.attachment-file-name {
  font-size: .8rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-image {
  cursor: pointer;
  touch-action: pan-y;
  border: none;
  padding: 0;
  background: transparent;
  text-align: left;
  font: inherit;
  color: inherit;
}
.msg-image img {
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.chat-composer-dock {
  flex-shrink: 0;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: .45rem;
  padding: .75rem;
  padding-bottom: max(.75rem, env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--surface2);
  position: relative;
}
.composer-field {
  flex: 1;
  min-width: 0;
  display: flex;
}
.composer-tools {
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-shrink: 0;
  position: relative;
}
.composer textarea.message-input {
  flex: 1;
  width: 100%;
  min-height: 42px;
  max-height: 140px;
  padding: .6rem .85rem;
  border: 1px solid var(--surface2);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.4;
  font-family: inherit;
  resize: none;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}
.composer textarea.message-input:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}
.composer textarea.message-input.is-scrollable {
  overflow-y: auto;
}
.attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--surface2);
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: color .15s, border-color .15s;
}
.attach-btn:hover { color: var(--accent); border-color: var(--accent); }
.emoji-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--surface2);
  font-size: 1.25rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color .15s, transform .1s;
}
.emoji-btn:hover { border-color: var(--accent); transform: scale(1.05); }
.emoji-picker {
  position: static;
  width: 100%;
  max-height: none;
  overflow: visible;
  padding: .5rem;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: .15rem;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
}
.emoji-item {
  border: none;
  background: transparent;
  font-size: 1.35rem;
  line-height: 1.2;
  padding: .2rem;
  border-radius: 6px;
  cursor: pointer;
}
.emoji-item:hover { background: var(--surface2); }
.composer .btn-send {
  width: 42px;
  height: 42px;
  min-width: 42px;
  margin-top: 0;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.composer .icon { display: block; }

.msg-file { display: block; margin: .25rem 0; }
.msg-image img {
  max-width: min(280px, 100%);
  max-height: 220px;
  border-radius: 10px;
  display: block;
}
.msg-image-fallback {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .65rem;
  max-width: min(280px, 100%);
  background: rgba(0, 0, 0, .15);
  border-radius: 10px;
  color: inherit;
  text-decoration: none;
}
.msg-image-fallback:hover { background: rgba(0, 0, 0, .25); }
.msg-image-fallback .file-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  color: var(--accent);
}
.msg-image-fallback .file-info {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  min-width: 0;
}
.msg-image-fallback .file-info strong {
  font-size: .85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-image-fallback .file-info small { font-size: .7rem; opacity: .8; }
.msg-video, .msg-audio { max-width: min(300px, 100%); border-radius: 8px; }
.msg-download {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .65rem;
  background: rgba(0,0,0,.15);
  border-radius: 10px;
  color: inherit;
  text-decoration: none;
}
.msg-download:hover { background: rgba(0,0,0,.25); }
.msg-download .file-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  color: var(--accent);
}
.msg-download .file-info { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
.msg-download .file-info strong {
  font-size: .85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-download .file-info small { font-size: .7rem; opacity: .8; }
.msg-caption { margin-top: .35rem; }
.msg-text { white-space: pre-wrap; word-break: break-word; }
.msg-reply-quote {
  display: block;
  width: 100%;
  text-align: left;
  margin-bottom: .4rem;
  padding: .35rem .5rem;
  border: none;
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  background: rgba(0,0,0,.12);
  color: inherit;
  cursor: pointer;
  font: inherit;
}
.msg.mine .msg-reply-quote { background: rgba(0,0,0,.18); }
.msg-reply-name {
  display: block;
  font-size: .7rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: .1rem;
}
.msg-reply-text {
  display: block;
  font-size: .78rem;
  opacity: .9;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-highlight {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  animation: msg-pulse .4s ease 2;
}
@keyframes msg-pulse {
  50% { outline-color: #fff; }
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  padding: .75rem 1.25rem;
  border-radius: 8px;
  font-size: .9rem;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

@media (max-width: 768px) {
  .peer-bar-left { display: flex; }

  .chat-layout {
    position: relative;
    overflow: hidden;
  }

  .chat-main {
    width: 100%;
    min-width: 0;
    z-index: 1;
  }

  .sidebar {
    position: absolute;
    inset: 0;
    width: 100%;
    max-width: none;
    z-index: 30;
    transform: translateX(100%);
    transition: transform .28s cubic-bezier(.4, 0, .2, 1);
    border-right: none;
    box-shadow: -8px 0 32px rgba(0, 0, 0, .35);
  }

  .chat-layout.show-chat-list .sidebar {
    transform: translateX(0);
  }

  .peer-bar-info {
    cursor: default;
  }

  .chat-layout.show-chat-list .chat-main {
    visibility: hidden;
    pointer-events: none;
  }

  .chat-composer-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    background: var(--surface);
    border-top: 1px solid var(--surface2);
    box-shadow: 0 -6px 28px rgba(0, 0, 0, .28);
    transition: bottom .12s ease-out;
  }

  .chat-composer-dock .composer {
    border-top: none;
    padding-bottom: max(.65rem, env(safe-area-inset-bottom, 0px));
  }

  .chat-composer-dock .reply-bar,
  .chat-composer-dock .attachment-bar {
    border-top: none;
    border-bottom: 1px solid var(--surface2);
  }

  .chat-layout.show-chat-list .chat-composer-dock {
    display: none;
  }

  .messages {
    padding-bottom: calc(var(--composer-dock-height, 88px) + 0.75rem);
  }

  .toast {
    bottom: calc(var(--composer-dock-height, 88px) + 1rem + env(safe-area-inset-bottom, 0px));
  }
}

@media (min-width: 769px) {
  .peer-bar-left { display: none; }
  .peer-bar-actions { display: none !important; }
  .chat-peer-bar.has-msg-actions .peer-bar-info { opacity: 1; }
  .chat-layout.show-chat-list .sidebar {
    transform: none;
  }
}

@media (max-width: 768px) {
  .msg-context-menu { display: none !important; }
}
