:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f5f7fb;
  --border: #e3e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-2: #1d4ed8;
  --primary-soft: #e8f0ff;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #15803d;
  --success-soft: #dcfce7;
  --online: #22c55e;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.09);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(100, 116, 139, 0.35); border-radius: 999px; }
::-webkit-scrollbar-track { background: transparent; }

.login-view {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
  background: linear-gradient(160deg, #e6efff 0%, #f8fafc 45%, #e9f7f2 100%);
}

.login-bg { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.login-bg::before,
.login-bg::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(2px);
}
.login-bg::before {
  width: 420px; height: 420px;
  top: -160px; right: -120px;
  background: radial-gradient(circle at 30% 30%, rgba(37, 99, 235, 0.22), transparent 65%);
}
.login-bg::after {
  width: 380px; height: 380px;
  bottom: -140px; left: -120px;
  background: radial-gradient(circle at 60% 60%, rgba(13, 148, 136, 0.18), transparent 65%);
}

.login-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 26px;
  padding: 32px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.13);
  text-align: center;
}

.brand-logo {
  width: 62px; height: 62px;
  margin: 0 auto 14px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff;
  font-weight: 800;
  font-size: 24px;
  letter-spacing: 0.02em;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.3);
}
.brand-logo.small { width: 54px; height: 54px; font-size: 20px; border-radius: 16px; margin-bottom: 4px; }

.login-card h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.login-sub { margin: 6px 0 22px; color: var(--muted); font-size: 14px; }
.login-hint { margin: 16px 0 0; color: var(--muted); font-size: 12.5px; }

.stack { display: flex; flex-direction: column; gap: 12px; }

.server-fields { display: grid; grid-template-columns: minmax(0, 1fr) 100px; gap: 10px; }

.field { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }

.field input,
.field select,
.input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus,
.field select:focus,
.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.form-error {
  background: var(--danger-soft);
  color: #b91c1c;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  text-align: left;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  font-size: 14px;
  background: var(--surface-2);
  color: var(--text);
  transition: background 0.15s, transform 0.05s, opacity 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-small { padding: 6px 10px; font-size: 12.5px; border-radius: 9px; }
.btn-primary { background: linear-gradient(135deg, #3b82f6, #1d4ed8); color: #fff; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-soft { background: var(--primary-soft); color: var(--primary); }
.btn-soft:hover { background: #dbe7ff; }
.btn-danger-soft { background: var(--danger-soft); color: #b91c1c; }
.btn-danger-soft:hover { background: #fecaca; }

.icon-btn {
  width: 40px; height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: 12px;
  color: #475569;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: #eef2f7; color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

.avatar {
  position: relative;
  width: 46px; height: 46px;
  flex-shrink: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.01em;
  user-select: none;
}
.avatar.large { width: 56px; height: 56px; font-size: 19px; }
.avatar-btn { border: none; cursor: pointer; }
.avatar .presence-dot {
  position: absolute;
  right: -1px; bottom: -1px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #94a3b8;
  border: 2px solid #fff;
}
.avatar .presence-dot.online { background: var(--online); }

.app-view {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  width: 366px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 10px;
}
.sidebar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sidebar-title strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn-status { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); }
.conn-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; }
.conn-status.online .dot { background: var(--online); }
.conn-status.offline .dot { background: #ef4444; }
.head-actions { display: flex; gap: 2px; }

.search-wrap { padding: 2px 16px 8px; }
.search-wrap input {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--surface-2);
  outline: none;
}
.search-wrap input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }

.notify-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 16px 8px;
  padding: 9px 10px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: #1e40af;
  font-size: 12.5px;
}
.notify-banner > span { flex: 1; }
.notify-banner .icon-btn { width: 30px; height: 30px; color: #1e40af; }
.notify-banner .icon-btn svg { width: 16px; height: 16px; }

.tabs { display: flex; gap: 6px; padding: 0 12px 8px; }
.tab {
  flex: 1;
  padding: 8px 10px;
  border: none;
  background: transparent;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 600;
  font-size: 13.5px;
}
.tab:hover { background: var(--surface-2); }
.tab.active { background: var(--primary-soft); color: var(--primary); }

.list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 8px 14px;
}

.list-action {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 4px 0 8px;
  padding: 11px 12px;
  border: 1px dashed #bfd3f8;
  background: #f7faff;
  border-radius: 13px;
  color: var(--primary);
  font-weight: 600;
  font-size: 13.5px;
}
.list-action:hover { background: var(--primary-soft); }
.list-action svg { width: 18px; height: 18px; }

.conv-item,
.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: background 0.12s;
}
.conv-item:hover,
.contact-item:hover { background: #f5f8fd; }
.conv-item.active { background: var(--primary-soft); }

.conv-main,
.contact-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.conv-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.conv-name,
.contact-name {
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-time { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.conv-preview {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item.unread .conv-preview { color: #334155; font-weight: 600; }
.conv-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.contact-sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }

.empty-list { padding: 26px 16px; text-align: center; color: var(--muted); font-size: 13.5px; }

.chat {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background-color: #edf1f7;
  background-image:
    radial-gradient(circle at 18% 18%, rgba(37, 99, 235, 0.06), transparent 42%),
    radial-gradient(circle at 82% 82%, rgba(13, 148, 136, 0.06), transparent 42%);
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}
.chat-empty h2 { margin: 8px 0 0; font-size: 20px; color: var(--text); }
.chat-empty p { margin: 0; font-size: 14px; }

.chat-panel { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.chat-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: calc(11px + env(safe-area-inset-top)) 16px 11px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  z-index: 5;
}
.back-btn { margin-left: -8px; }
.chat-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.chat-title strong { font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status.online { color: var(--success); }
.chat-status.typing { color: var(--primary); }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px clamp(12px, 5vw, 42px) 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.messages::before { content: ""; margin-top: auto; }

.date-sep {
  align-self: center;
  margin: 10px 0 6px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.07);
  color: #475569;
  font-size: 11.5px;
  font-weight: 600;
}

.msg-row { display: flex; margin: 1px 0; }
.msg-row.mine { justify-content: flex-end; }

.msg-bubble {
  max-width: min(560px, 82%);
  padding: 8px 12px;
  border-radius: 16px;
  border-bottom-left-radius: 6px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.07);
  font-size: 14.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.msg-row.mine .msg-bubble {
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 6px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff;
}
.msg-sender {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 2px;
}
.msg-text { white-space: pre-wrap; }
.msg-text a { color: inherit; text-decoration: underline; }
.msg-meta {
  display: flex;
  justify-content: flex-end;
  margin-top: 3px;
  font-size: 10.5px;
  color: var(--muted);
}
.msg-row.mine .msg-meta { color: rgba(255, 255, 255, 0.78); }

.msg-bubble.has-image { padding: 4px; }
.msg-image {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 12px;
  cursor: zoom-in;
  background: #dbe4f0;
  object-fit: cover;
}
.msg-caption { padding: 6px 8px 2px; }

.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 3px 2px;
  text-decoration: none;
  color: inherit;
}
.file-icon {
  width: 42px; height: 42px;
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--primary);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.file-icon svg { width: 21px; height: 21px; }
.msg-row.mine .file-icon { background: rgba(255, 255, 255, 0.18); color: #fff; }
.file-info { min-width: 0; display: flex; flex-direction: column; }
.file-name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 230px; }
.file-size { font-size: 11px; opacity: 0.72; }

.typing-indicator {
  padding: 2px clamp(12px, 5vw, 42px) 2px;
  min-height: 18px;
  font-size: 12px;
  color: var(--primary);
}

.pending-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.pending-file img {
  width: 44px; height: 44px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--surface-2);
}
.pending-file-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pending-file-info strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-file-info span { font-size: 11.5px; color: var(--muted); }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: #f8fafc;
  resize: none;
  outline: none;
  font-size: 15px;
  line-height: 1.4;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer textarea:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.attach-btn { width: 42px; height: 44px; }
.send-btn {
  width: 44px; height: 44px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.3);
  transition: filter 0.15s, opacity 0.15s;
}
.send-btn:hover { filter: brightness(1.06); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.send-btn svg { width: 19px; height: 19px; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 28px 70px rgba(15, 23, 42, 0.3);
  overflow: hidden;
  animation: pop 0.16s ease-out;
}
.modal-card.small { max-width: 410px; }
.modal-card.wide { max-width: 760px; }
@keyframes pop { from { transform: scale(0.97); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 16.5px; }
.modal-body { padding: 16px 18px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.section-title {
  margin: 6px 0 0;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.grid-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: end;
}
.grid-form .form-error { grid-column: 1 / -1; }
.grid-form .btn { grid-column: 1 / -1; }

.profile-row { display: flex; align-items: center; gap: 14px; }
.profile-row > div:last-child { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.role-chip {
  align-self: flex-start;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
}
.settings-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.settings-actions .btn { flex: 1; min-width: 150px; }

.pick-list { display: flex; flex-direction: column; gap: 2px; max-height: 46vh; overflow-y: auto; }
.pick-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  border-radius: 12px;
  text-align: left;
}
.pick-item:hover { background: var(--surface-2); }
.pick-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pick-main strong { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-main span { font-size: 11.5px; color: var(--muted); }
.pick-item input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: var(--primary);
  margin-left: auto;
  flex-shrink: 0;
}

.admin-users { display: flex; flex-direction: column; gap: 8px; }
.admin-user {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
}
.admin-user.inactive { opacity: 0.62; }
.admin-main { flex: 1; min-width: 150px; display: flex; flex-direction: column; gap: 2px; }
.admin-main strong { font-size: 13.5px; }
.admin-sub { font-size: 11.5px; color: var(--muted); }
.admin-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.admin-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.admin-actions .btn { padding: 7px 11px; font-size: 12.5px; border-radius: 10px; }
.status-chip {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
}
.status-chip.active { background: var(--success-soft); color: var(--success); }
.status-chip.inactive { background: var(--danger-soft); color: #b91c1c; }
.status-chip.admin { background: #fef3c7; color: #b45309; }
.status-chip.pending { background: #e0e7ff; color: #4338ca; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(2, 6, 23, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.lightbox img { max-width: 94vw; max-height: 88dvh; object-fit: contain; border-radius: 10px; }
.lightbox-close {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  right: 16px;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 18px;
}

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 100;
  width: min(92vw, 430px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 14px;
  border-radius: 12px;
  background: #0f172a;
  color: #fff;
  font-size: 13.5px;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.3);
  animation: toast-in 0.18s ease-out;
}
.toast.success { background: #14532d; }
.toast.error { background: #7f1d1d; }
.toast.out { opacity: 0; transition: opacity 0.25s; }
.toast.message-toast {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
  cursor: pointer;
  border-left: 3px solid #60a5fa;
}
.toast.message-toast strong { font-size: 13px; }
.toast.message-toast span {
  font-size: 12.5px;
  opacity: 0.85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.is-loading { pointer-events: none; opacity: 0.6; }

.pinned-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  width: calc(100% - 24px);
  margin: 8px 12px 0;
  padding: 8px 10px;
  border: none;
  border-left: 3px solid var(--primary);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 12.5px;
}
.pinned-bar svg { width: 15px; height: 15px; color: var(--primary); flex-shrink: 0; }
#pinned-bar-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.reply-bar-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-left: 3px solid var(--primary);
  padding-left: 8px;
}
.reply-bar-info strong { font-size: 12px; color: var(--primary); }
.reply-bar-info span {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.record-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
  animation: record-pulse 1s infinite;
}
@keyframes record-pulse { 50% { opacity: 0.25; } }
#record-timer { flex: 1; font-variant-numeric: tabular-nums; }

.mention-btn {
  width: 36px;
  height: 44px;
  font-weight: 800;
  color: var(--primary);
  font-size: 17px;
}
.voice-btn { width: 40px; height: 44px; }

.msg-meta { align-items: center; gap: 6px; }
.msg-actions { display: inline-flex; gap: 2px; margin-right: 4px; }
.msg-action-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0 2px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
.msg-action-btn svg { width: 13px; height: 13px; }
.msg-row.mine .msg-action-btn { color: rgba(255, 255, 255, 0.82); }
.msg-pin-mark,
.read-status { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.msg-pin-mark { color: var(--primary); font-weight: 600; }
.msg-row.mine .msg-pin-mark,
.msg-row.mine .read-status { color: rgba(255, 255, 255, 0.82); }

.reply-quote {
  border-left: 3px solid rgba(37, 99, 235, 0.7);
  background: rgba(37, 99, 235, 0.08);
  border-radius: 8px;
  padding: 5px 8px;
  margin-bottom: 4px;
  font-size: 12.5px;
  cursor: pointer;
  overflow: hidden;
}
.msg-row.mine .reply-quote {
  border-left-color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.14);
}
.reply-quote strong { display: block; font-size: 11.5px; color: var(--primary); margin-bottom: 1px; }
.msg-row.mine .reply-quote strong { color: #fff; }
.reply-quote span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: 0.85; }

.mention {
  color: var(--primary);
  font-weight: 700;
  background: rgba(37, 99, 235, 0.09);
  padding: 0 3px;
  border-radius: 4px;
}
.msg-row.mine .mention { color: #fff; background: rgba(255, 255, 255, 0.2); }
.msg-bubble.mentioned-me { box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.78); }

.msg-row.highlight .msg-bubble { animation: message-highlight 2.4s ease-out; }
@keyframes message-highlight {
  0% { box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.95); }
  100% { box-shadow: 0 1px 2px rgba(15, 23, 42, 0.07); }
}

.msg-audio { width: 260px; max-width: 100%; margin: 2px 0; }

.preview-card { height: min(88dvh, 820px); }
.preview-body { flex: 1; min-height: 0; background: var(--surface-2); }
.preview-body iframe { width: 100%; height: 100%; border: 0; display: block; background: #fff; }

.search-results { max-height: 55vh; }
.search-result {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  text-align: left;
  border-radius: 10px;
  cursor: pointer;
}
.search-result:hover { background: var(--surface-2); }
.search-result strong { font-size: 13px; }
.search-result span { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result small { font-size: 11px; color: var(--muted); }

.group-member {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 12px;
}
.group-member:hover { background: var(--surface-2); }
.group-member-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.group-member-main strong { font-size: 13px; }
.group-member-main span { font-size: 11.5px; color: var(--muted); }

.backup-list { display: flex; flex-direction: column; gap: 6px; }
.backup-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 12.5px;
}
.backup-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.backup-item small { color: var(--muted); white-space: nowrap; }
.backup-item a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

:root[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111a2b;
  --surface-2: #1a2538;
  --border: #24324a;
  --text: #e6edf7;
  --muted: #9aa8bd;
  --primary: #3b82f6;
  --primary-2: #2563eb;
  --primary-soft: #1b2a44;
  --danger: #ef4444;
  --danger-soft: #3a1d22;
  --success: #34d399;
  --success-soft: #12352a;
  --online: #34d399;
}
[data-theme="dark"] body { background: var(--bg); }
[data-theme="dark"] .login-view {
  background: linear-gradient(160deg, #0b1424 0%, #0f172a 50%, #0c1f1b 100%);
}
[data-theme="dark"] .login-card { background: var(--surface); }
[data-theme="dark"] .chat {
  background-color: #0e1726;
  background-image:
    radial-gradient(circle at 18% 18%, rgba(59, 130, 246, 0.09), transparent 42%),
    radial-gradient(circle at 82% 82%, rgba(13, 148, 136, 0.08), transparent 42%);
}
[data-theme="dark"] .chat-head { background: rgba(17, 26, 43, 0.94); }
[data-theme="dark"] .msg-bubble { background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); }
[data-theme="dark"] .msg-row.mine .msg-bubble {
  background: linear-gradient(135deg, #2563eb, #1e40af);
}
[data-theme="dark"] .composer { background: var(--surface); }
[data-theme="dark"] .composer textarea { background: #0f1929; color: var(--text); }
[data-theme="dark"] .composer textarea:focus { background: #12203a; }
[data-theme="dark"] .search-wrap input { background: var(--surface-2); color: var(--text); }
[data-theme="dark"] .icon-btn { color: #b9c6d8; }
[data-theme="dark"] .icon-btn:hover { background: var(--surface-2); color: var(--text); }
[data-theme="dark"] .conv-item:hover,
[data-theme="dark"] .contact-item:hover { background: #152136; }
[data-theme="dark"] .conv-item.active { background: var(--primary-soft); }
[data-theme="dark"] .conv-item.unread .conv-preview { color: #dbe6f5; }
[data-theme="dark"] .date-sep { background: rgba(255, 255, 255, 0.08); color: #b6c3d6; }
[data-theme="dark"] .list-action { background: #12203a; border-color: #2a3d5e; }
[data-theme="dark"] .modal-card { background: var(--surface); }
[data-theme="dark"] .field input,
[data-theme="dark"] .field select,
[data-theme="dark"] .input { background: #0f1929; color: var(--text); }
[data-theme="dark"] .pending-file,
[data-theme="dark"] .reply-bar,
[data-theme="dark"] .record-bar { background: var(--surface); }
[data-theme="dark"] .file-icon { background: var(--surface-2); }
[data-theme="dark"] .preview-body { background: #0b1424; }
[data-theme="dark"] .preview-body iframe { background: #fff; }

.back-btn { display: none; }

@media (max-width: 860px) {
  .sidebar { width: 100%; border-right: none; }
  .chat {
    position: fixed;
    inset: 0;
    z-index: 30;
    transform: translateX(100%);
    transition: transform 0.24s ease;
  }
  .app-view.chat-open .chat { transform: translateX(0); }
  .back-btn { display: inline-flex; }
  .chat-head { padding: calc(10px + env(safe-area-inset-top)) 12px 10px; }
  .messages { padding: 14px 12px 6px; }
  .typing-indicator { padding: 2px 14px; }
  .msg-bubble { max-width: 86%; }
  .modal { padding: 12px; }
  .modal-card { max-height: calc(100dvh - 24px); }
  .grid-form { grid-template-columns: 1fr; }
  .grid-form .btn { grid-column: auto; }
}

@media (max-width: 420px) {
  .login-card { padding: 25px 20px; border-radius: 22px; }
  .msg-bubble { max-width: 88%; }
  .sidebar-head { padding: calc(12px + env(safe-area-inset-top)) 12px 8px; }
  .search-wrap { padding: 2px 12px 8px; }
  .notify-banner { margin: 0 12px 8px; }
  .tabs { padding: 0 8px 8px; }
  .list { padding: 2px 6px 14px; }
}
