/* ------------------------------------------------------------------ base */
*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --radius: 14px;
  --radius-lg: 20px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --sidebar-w: 372px;
}

html[data-theme="dark"] {
  --bg: #0b141d;
  --bg-elev: #101b26;
  --sidebar: #121d28;
  --sidebar-2: #0f1923;
  --panel: #16222e;
  --panel-2: #1d2b39;
  --bubble-in: #172635;
  --bubble-out: #2b5278;
  --bubble-out-2: #28517a;
  --text: #eaf0f6;
  --text-dim: #93a5b8;
  --muted: #7d90a4;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);
  --accent: #4ea8ff;
  --accent-soft: rgba(78, 168, 255, 0.14);
  --danger: #ff6b6b;
  --ok: #4ade80;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  --shadow-soft: 0 6px 24px rgba(0, 0, 0, 0.35);
  --unread: #4ea8ff;
}

html[data-theme="light"] {
  --bg: #eef2f7;
  --bg-elev: #ffffff;
  --sidebar: #ffffff;
  --sidebar-2: #f6f8fb;
  --panel: #ffffff;
  --panel-2: #f1f5fa;
  --bubble-in: #ffffff;
  --bubble-out: #d6e9ff;
  --bubble-out-2: #cfe5ff;
  --text: #111a24;
  --text-dim: #56677a;
  --muted: #6b7c90;
  --border: rgba(16, 32, 48, 0.09);
  --border-strong: rgba(16, 32, 48, 0.16);
  --accent: #1d7fe0;
  --accent-soft: rgba(29, 127, 224, 0.1);
  --danger: #d92d2d;
  --ok: #17a34a;
  --shadow: 0 24px 70px rgba(15, 35, 60, 0.16);
  --shadow-soft: 0 6px 24px rgba(15, 35, 60, 0.1);
  --unread: #1d7fe0;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  overscroll-behavior: none;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
}

::selection {
  background: var(--accent-soft);
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-thumb {
  background: rgba(140, 165, 190, 0.28);
  border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(140, 165, 190, 0.45);
}
::-webkit-scrollbar-track {
  background: transparent;
}

/* ------------------------------------------------------------- typography */
h1,
h2,
h3 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.muted {
  color: var(--text-dim);
}

.hint {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
  margin: 0;
}

.fineprint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  margin: 4px 0 0;
  text-align: center;
}

.warn {
  color: #f0b26b;
  font-size: 12px;
  line-height: 1.5;
  margin: 4px 0 0;
  text-align: center;
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  margin: 0;
  min-height: 18px;
}

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 46px;
  padding: 0 20px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 15px;
  transition: transform 0.12s var(--ease), background 0.18s, opacity 0.18s;
  user-select: none;
}
.btn svg {
  width: 17px;
  height: 17px;
  flex: none;
}
.btn:active {
  transform: scale(0.985);
}
.btn.primary {
  background: var(--accent);
  color: #04121f;
  box-shadow: 0 10px 26px -12px var(--accent);
}
html[data-theme="light"] .btn.primary {
  color: #fff;
}
.btn.primary:hover {
  filter: brightness(1.06);
}
.btn.ghost {
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.btn.ghost:hover {
  background: var(--panel);
}
.btn.small {
  height: 38px;
  font-size: 13.5px;
  padding: 0 16px;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}
.btn.danger {
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
}

.link {
  align-self: center;
  color: var(--text-dim);
  font-size: 13.5px;
  padding: 8px 10px;
  border-radius: 8px;
}
.link:hover {
  color: var(--text);
  background: var(--panel-2);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  color: var(--text-dim);
  transition: background 0.16s, color 0.16s;
}
.icon-btn:hover {
  background: var(--panel-2);
  color: var(--text);
}
.icon-btn svg {
  width: 20px;
  height: 20px;
}

.field {
  display: grid;
  gap: 7px;
}
.field > span {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.01em;
}

input[type="text"],
input[type="search"],
textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 11px 13px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.16s, box-shadow 0.16s, background 0.16s;
}
input[type="text"]:focus,
input[type="search"]:focus,
textarea:focus {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.code-input {
  font-family: var(--mono);
  font-size: 17px !important;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  color: var(--text-dim);
  padding: 4px 2px;
  cursor: pointer;
  user-select: none;
}
.check input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

/* ------------------------------------------------------------------- auth */
.auth-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px 18px;
  overflow: auto;
  background:
    radial-gradient(circle at 15% 0%, rgba(78, 168, 255, 0.16), transparent 42%),
    radial-gradient(circle at 85% 100%, rgba(120, 86, 255, 0.14), transparent 45%),
    var(--bg);
}
.auth-glow {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 26px 26px;
  mask-image: radial-gradient(circle at 50% 30%, #000 0%, transparent 72%);
  pointer-events: none;
}
.auth-card {
  position: relative;
  width: min(430px, 100%);
  background: color-mix(in srgb, var(--sidebar) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 34px 30px 30px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  display: grid;
  gap: 22px;
  animation: cardIn 0.5s var(--ease);
}
@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.985);
  }
}
.auth-brand {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 10px;
}
.auth-brand h1 {
  font-size: 30px;
  letter-spacing: -0.03em;
}
.tagline {
  margin: 0;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.6;
}
.logo {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 17px;
  color: #fff;
  background: linear-gradient(140deg, #56b0ff, #2f6fd0 65%, #7a5cff);
  box-shadow: 0 14px 34px -12px rgba(78, 168, 255, 0.8);
}
.logo.small {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  box-shadow: none;
}
.auth-step {
  display: grid;
  gap: 12px;
  animation: stepIn 0.32s var(--ease);
}
@keyframes stepIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}
.auth-step h2 {
  font-size: 20px;
}
.auth-step > p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text-dim);
}

.code-display {
  font-family: var(--mono);
  font-size: clamp(15px, 4.3vw, 24px);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-align: center;
  padding: 18px 10px;
  border-radius: 14px;
  background: var(--panel-2);
  border: 1px dashed color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--accent);
  user-select: all;
  white-space: nowrap;
}

/* ------------------------------------------------------------------- app */
.main {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100dvh;
  background: var(--bg);
}

.sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  z-index: 3;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 10px 18px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.head-actions {
  display: flex;
  gap: 2px;
}
.search-wrap {
  position: relative;
  padding: 0 14px 12px;
}
.search-wrap input {
  padding-left: 38px;
  background: var(--panel-2);
  border-radius: 10px;
  height: 40px;
}
.search-icon {
  position: absolute;
  left: 27px;
  top: 12px;
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M10.5 3a7.5 7.5 0 1 0 4.7 13.35l4.2 4.2a1 1 0 0 0 1.4-1.4l-4.2-4.2A7.5 7.5 0 0 0 10.5 3Zm0 2a5.5 5.5 0 1 1 0 11 5.5 5.5 0 0 1 0-11Z'/%3E%3C/svg%3E")
    center / contain no-repeat;
}

.chat-list {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 6px 10px;
  overscroll-behavior: contain;
}
.chat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-width: 0;
  padding: 10px 10px;
  border-radius: 13px;
  text-align: left;
  transition: background 0.14s;
  position: relative;
}
.chat-row:hover {
  background: var(--panel-2);
}
.chat-row.active {
  background: var(--accent-soft);
}
.chat-row.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 16px;
  bottom: 16px;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
}
.chat-row-main {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 4px;
}
.chat-row-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.chat-row-name {
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.chat-row-time {
  font-size: 11.5px;
  color: var(--muted);
  flex: none;
}
.chat-row-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.chat-row-preview {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-row-preview.typing {
  color: var(--accent);
}
.badge {
  min-width: 19px;
  height: 19px;
  padding: 0 6px;
  border-radius: 99px;
  background: var(--unread);
  color: #04121f;
  font-size: 11.5px;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex: none;
}
html[data-theme="light"] .badge {
  color: #fff;
}
.badge.muted {
  background: var(--muted);
}

.avatar {
  --hue: 210;
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 650;
  font-size: 17px;
  color: #fff;
  background: linear-gradient(140deg, hsl(var(--hue) 72% 58%), hsl(calc(var(--hue) + 42) 68% 44%));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  user-select: none;
  position: relative;
}
.avatar.saved {
  background: linear-gradient(140deg, #4ea8ff, #7a5cff);
}
.avatar .online-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ok);
  border: 2.5px solid var(--sidebar);
}

.me-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--sidebar-2);
  cursor: pointer;
  transition: background 0.16s;
}
.me-strip:hover {
  background: var(--panel-2);
}
.me-strip .avatar {
  width: 34px;
  height: 34px;
  font-size: 14px;
}
.me-strip-text {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 1px;
}
.me-strip-name {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.me-strip-sub {
  font-size: 11.5px;
  color: var(--muted);
}
.conn-banner {
  position: absolute;
  left: 50%;
  bottom: 68px;
  transform: translateX(-50%);
  background: var(--panel-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 6px 14px;
  font-size: 12px;
  box-shadow: var(--shadow-soft);
  z-index: 5;
  white-space: nowrap;
}

/* ------------------------------------------------------------- chat pane */
.chat-pane {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(circle at 18% 0%, rgba(78, 168, 255, 0.07), transparent 40%),
    radial-gradient(circle at 92% 100%, rgba(122, 92, 255, 0.06), transparent 45%),
    var(--bg-elev);
}
.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 40px;
  text-align: center;
  color: var(--text-dim);
}
.empty-state h2 {
  color: var(--text);
  font-size: 19px;
  margin-top: 8px;
}
.empty-state p {
  margin: 0;
  max-width: 340px;
  font-size: 13.5px;
  line-height: 1.6;
}
.empty-art {
  color: var(--accent);
  opacity: 0.9;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  min-height: 62px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--sidebar) 80%, transparent);
  backdrop-filter: blur(14px);
  z-index: 2;
}
.chat-head .avatar {
  width: 40px;
  height: 40px;
  font-size: 15px;
}
.chat-head-text {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
}
.chat-head-name {
  font-weight: 650;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-head-sub {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-head-sub.typing {
  color: var(--accent);
}
.back-btn {
  margin-left: -8px;
}
.back-btn svg {
  width: 22px;
  height: 22px;
}

/* --------------------------------------------------------------- messages */
.messages-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: auto;
}
.messages {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 18px max(16px, min(4vw, 36px)) 14px;
  min-height: 100%;
  min-width: 0;
  justify-content: flex-end;
}
.day-sep {
  align-self: center;
  margin: 14px 0 10px;
  padding: 4px 12px;
  border-radius: 99px;
  background: color-mix(in srgb, var(--panel) 75%, transparent);
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 500;
  border: 1px solid var(--border);
  backdrop-filter: blur(6px);
}

.msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 2px;
  min-width: 0;
  max-width: 100%;
  animation: msgIn 0.18s var(--ease);
}
@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}
.msg.group-start {
  margin-top: 10px;
}
.msg.out {
  flex-direction: row-reverse;
}
.bubble {
  position: relative;
  max-width: min(78%, 620px);
  padding: 7px 12px 7px;
  border-radius: 16px;
  background: var(--bubble-in);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12);
  font-size: 14.5px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.in:not(.group-end) .bubble {
  border-bottom-left-radius: 5px;
}
.msg.out:not(.group-end) .bubble {
  border-bottom-right-radius: 5px;
}
.msg.out .bubble {
  background: linear-gradient(140deg, var(--bubble-out-2), var(--bubble-out));
  color: #fff;
}
.msg.in .bubble {
  border: 1px solid var(--border);
}
html[data-theme="light"] .msg.in .bubble {
  box-shadow: 0 1px 2px rgba(15, 35, 60, 0.08);
}
.msg .msg-avatar {
  width: 30px;
  height: 30px;
  font-size: 12px;
  margin-bottom: 2px;
  opacity: 0;
  pointer-events: none;
}
.msg.group-end .msg-avatar {
  opacity: 1;
  pointer-events: auto;
}
.msg.out .msg-avatar {
  display: none;
}
.msg-text {
  white-space: pre-wrap;
}
.msg-text a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
}
.msg.out .msg-text a {
  color: #d9ecff;
}
.msg.deleted .msg-text {
  color: var(--muted);
  font-style: italic;
}

.meta {
  float: right;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 7px -2px -2px 10px;
  font-size: 10.5px;
  color: var(--muted);
  line-height: 1;
  user-select: none;
}
.msg.out .meta {
  color: rgba(255, 255, 255, 0.62);
}
.bubble.media-only {
  padding: 4px;
}
.bubble.media-only .meta {
  position: absolute;
  right: 9px;
  bottom: 9px;
  margin: 0;
  padding: 3px 7px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.48);
  color: #fff;
  backdrop-filter: blur(6px);
}
.bubble.media-only .attachments {
  margin: 0;
}
.bubble.media-only .attachments + .msg-text {
  padding: 4px 6px 0;
}
.meta svg {
  width: 15px;
  height: 15px;
  margin-left: 1px;
}
.meta .edited {
  margin-right: 4px;
  font-style: italic;
  opacity: 0.85;
}
.meta .tick.read {
  color: #7ec8ff;
}

.msg.pending {
  opacity: 0.82;
}
.msg.failed .bubble {
  border: 1px solid var(--danger);
}

/* attachments */
.attachments {
  display: grid;
  gap: 6px;
  margin: -3px -6px 4px;
}
.attachments + .msg-text {
  margin-top: 4px;
}
.attachments.single {
  margin-bottom: 6px;
}
.att-img {
  display: block;
  border-radius: 12px;
  overflow: hidden;
  max-width: 320px;
  background: var(--panel-2);
  position: relative;
  padding: 0;
  line-height: 0;
}
.att-img img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 380px;
  object-fit: cover;
  background: var(--panel-2);
}
.att-img .play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.25);
  font-size: 12px;
}
.att-video {
  max-width: 320px;
  width: 100%;
  border-radius: 12px;
  display: block;
  background: #000;
}
.att-audio {
  width: min(320px, 70vw);
}
.att-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 11px;
  background: color-mix(in srgb, #000 12%, transparent);
  min-width: 230px;
  max-width: 320px;
  text-decoration: none;
  color: inherit;
}
.msg.in .att-file {
  background: var(--panel-2);
}
.att-file:hover {
  filter: brightness(1.08);
}
.att-file-icon {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #04121f;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.att-file-icon svg {
  width: 18px;
  height: 18px;
}
.att-file-text {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
}
.att-file-name {
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.att-file-size {
  font-size: 11.5px;
  color: var(--muted);
}
.att-file-dl {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, #fff 12%, transparent);
  color: inherit;
}
.msg.in .att-file-dl {
  background: var(--accent-soft);
  color: var(--accent);
}
.att-file-dl svg {
  width: 16px;
  height: 16px;
}
.att-file.downloading .att-file-size {
  color: var(--accent);
}

.dl-ring {
  position: relative;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(
    var(--accent) calc(var(--p, 0) * 1%),
    rgba(255, 255, 255, 0.18) 0
  );
}
.dl-ring::before {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
}
.dl-pct {
  position: relative;
  font-size: 8.5px;
  font-weight: 650;
  color: #fff;
}

.dl-topbar {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.18);
  z-index: 5;
}
.dl-topbar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.2s linear;
}

.upload-bar {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
  transition: width 0.2s linear;
}

/* jump button */
.jump-down {
  position: absolute;
  right: 18px;
  bottom: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
  display: grid;
  place-items: center;
  z-index: 4;
}
.jump-down svg {
  width: 19px;
  height: 19px;
  color: var(--text-dim);
}

/* --------------------------------------------------------------- composer */
.composer {
  padding: 8px 12px max(10px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--sidebar) 78%, transparent);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(16px);
}
.composer.hidden {
  display: none;
}
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 5px 5px 5px 6px;
  transition: border-color 0.16s, box-shadow 0.16s;
}
.composer-row:focus-within {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
#input {
  flex: 1;
  border: 0;
  background: none;
  padding: 9px 4px;
  max-height: 148px;
  resize: none;
  font-size: 15px;
  line-height: 1.4;
  outline: none;
  box-shadow: none !important;
}
.attach svg {
  width: 22px;
  height: 22px;
}
.send-btn {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #04121f;
  display: grid;
  place-items: center;
  transition: transform 0.12s var(--ease), opacity 0.2s;
}
html[data-theme="light"] .send-btn {
  color: #fff;
}
.send-btn:active {
  transform: scale(0.94);
}
.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.send-btn svg {
  width: 19px;
  height: 19px;
  margin-left: 2px;
}
.send-btn.recording {
  background: var(--danger);
  color: #fff;
}

.pending-files {
  display: flex;
  gap: 8px;
  padding: 8px 6px;
  overflow-x: auto;
}
.pending-file {
  position: relative;
  flex: none;
  width: 62px;
  height: 62px;
  border-radius: 11px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  overflow: hidden;
  display: grid;
  place-items: center;
  font-size: 20px;
}
.pending-file img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.pending-file .remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 11px;
  line-height: 1;
}

/* -------------------------------------------------------------- modals etc */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(4, 10, 16, 0.55);
  backdrop-filter: blur(3px);
  padding: 18px;
  animation: fade 0.18s var(--ease);
}
@keyframes fade {
  from {
    opacity: 0;
  }
}
.modal {
  width: min(470px, 100%);
  max-height: min(86dvh, 760px);
  overflow-y: auto;
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 20px;
  display: grid;
  gap: 16px;
  animation: sheetIn 0.24s var(--ease);
}
@keyframes sheetIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.99);
  }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-head h2 {
  font-size: 18px;
}
.modal-sub {
  margin: -8px 0 0;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.55;
}
.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.modal-close:hover {
  background: var(--panel-2);
  color: var(--text);
}
.modal-close svg {
  width: 18px;
  height: 18px;
}
.modal-actions {
  display: grid;
  gap: 8px;
}

.settings-group {
  display: grid;
  gap: 8px;
  padding-top: 4px;
}
.settings-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  font-weight: 650;
}
.settings-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.settings-row .grow {
  flex: 1;
  min-width: 0;
}
.settings-row .title {
  font-size: 13.5px;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.settings-row .sub {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}
.settings-row .row-actions {
  display: flex;
  gap: 4px;
  flex: none;
}
.settings-row.code-row {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.code-inline {
  font-family: var(--mono);
  font-size: 16px;
  letter-spacing: 0.09em;
  color: var(--accent);
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border: 1px dashed color-mix(in srgb, var(--accent) 40%, transparent);
  user-select: all;
}
.seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 11px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.seg button {
  flex: 1;
  height: 34px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}
.seg button.on {
  background: var(--sidebar);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

.toast-root {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 60;
  display: grid;
  gap: 8px;
  justify-items: center;
  pointer-events: none;
  width: min(92vw, 520px);
}
.toast {
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toastIn 0.22s var(--ease);
  max-width: 100%;
}
@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}
.toast.error {
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  color: var(--danger);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(3, 7, 12, 0.94);
  display: grid;
  place-items: center;
  padding: 20px;
  animation: fade 0.2s var(--ease);
}
.lightbox img {
  max-width: 100%;
  max-height: calc(100dvh - 110px);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.lightbox-actions {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  display: flex;
  gap: 8px;
}
.lightbox-actions a,
.lightbox-actions button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  backdrop-filter: blur(8px);
  text-decoration: none;
}
.lightbox-actions svg {
  width: 20px;
  height: 20px;
}

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: rgba(4, 12, 20, 0.72);
  border: 2px dashed var(--accent);
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  pointer-events: none;
}

/* ---------------------------------------------------------------- groups */

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 11px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.tabs button {
  flex: 1;
  height: 34px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 550;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}
.tabs button.on {
  background: var(--sidebar);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

.avatar.group {
  border-radius: 15px;
}

.sender-name {
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.01em;
  margin: -1px 0 3px;
}

.msg-system {
  align-self: center;
  max-width: 82%;
  margin: 9px 0;
  padding: 4px 12px;
  border-radius: 99px;
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11.5px;
  text-align: center;
  backdrop-filter: blur(6px);
}

.member-list {
  display: grid;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
}
.member-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  font-size: 13.5px;
}
.member-row .avatar {
  width: 30px;
  height: 30px;
  font-size: 12px;
}

.pin-mark {
  display: inline-flex;
  width: 14px;
  height: 14px;
  margin-left: 2px;
  color: var(--muted);
  flex: none;
}
.pin-mark svg {
  width: 14px;
  height: 14px;
}

.action-row {
  width: 100%;
  text-align: left;
  cursor: pointer;
}
.action-row .grow {
  display: grid;
  gap: 2px;
  text-align: left;
}
.action-row .grow .title {
  font-size: 13.5px;
  font-weight: 550;
}

.member-picker {
  display: grid;
  gap: 2px;
  max-height: 190px;
  overflow-y: auto;
  padding: 2px;
}

.switch {
  position: relative;
  display: inline-flex;
  flex: none;
  width: 44px;
  height: 26px;
  cursor: pointer;
}
.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  z-index: 2;
  cursor: pointer;
}
.switch span {
  position: absolute;
  inset: 0;
  border-radius: 99px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  transition: background 0.15s, border-color 0.15s;
}
.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s, background 0.15s;
}
.switch input:checked + span {
  background: var(--accent);
  border-color: transparent;
}
.switch input:checked + span::after {
  transform: translateX(18px);
  background: #04121f;
}
.pick-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
}
.pick-row:hover {
  background: var(--panel-2);
}
.pick-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}
.pick-row .avatar {
  width: 28px;
  height: 28px;
  font-size: 11px;
}

.load-earlier {
  display: block;
  margin: 4px auto 12px;
  padding: 6px 12px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.load-earlier:hover {
  color: var(--text);
}

.share-list {
  display: grid;
  gap: 2px;
  max-height: 60vh;
  overflow-y: auto;
}

/* -------------------------------------------------------------------- qr */
.qr-box {
  width: min(280px, 100%);
  margin: 0 auto;
  padding: 14px;
  border-radius: 16px;
  background: #fff;
  display: grid;
  place-items: center;
}
.qr-box svg {
  display: block;
  width: 100%;
  height: auto;
}
.qr-loading {
  padding: 70px 10px;
  color: #555;
  font-size: 13px;
}

.scanner {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
}
.scanner video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scan-frame {
  position: absolute;
  inset: 16%;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 16px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

/* ------------------------------------------------------------ responsive */
@media (max-width: 860px) {
  .main {
    grid-template-columns: 1fr;
  }
  .chat-pane {
    position: fixed;
    inset: 0;
    z-index: 20;
    transform: translateX(100%);
    transition: transform 0.26s var(--ease);
    padding-top: env(safe-area-inset-top);
  }
  body.chat-open .chat-pane {
    transform: none;
  }
  body.chat-open .sidebar {
    transform: translateX(-12%);
    opacity: 0.55;
    pointer-events: none;
  }
  .sidebar {
    transition: transform 0.26s var(--ease), opacity 0.26s;
    padding-top: env(safe-area-inset-top);
  }
  .chat-head {
    padding-top: 8px;
  }
  .bubble {
    max-width: 84%;
  }
  .messages {
    padding: 12px 12px 10px;
  }
  .modal-root {
    padding: 0;
    align-items: end;
  }
  .modal {
    width: 100%;
    border-radius: 22px 22px 0 0;
    max-height: 88dvh;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
  .toast-root {
    bottom: max(18px, env(safe-area-inset-bottom));
  }
  .jump-down {
    bottom: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/*
 * In the Android shell the WebView itself is already padded for the status
 * bar, navigation bar and keyboard. Applying env(safe-area-inset-*) on top
 * would count those insets twice and leave a blank band at the top.
 */
html.native-shell .sidebar,
html.native-shell .chat-pane {
  padding-top: 0;
}
html.native-shell .composer {
  padding-bottom: 10px;
}
