:root {
  --bg: #0f1419;
  --panel: #171c24;
  --bubble-mine: #2563eb;
  --bubble-their: #272e3a;
  --text: #e6e9ef;
  --text-muted: #8b95a5;
  --accent: #2563eb;
  --send-btn: #2563eb;
  --send-btn-text: #ffffff;
  --frame: none;
  --edge: #3a414c;                          /* thin gray border */
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--app-bg, #070a0e);
  color: var(--text);
}
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

/* ---------- auth ---------- */
.auth-wrap { display: flex; min-height: 100%; align-items: center; justify-content: center; }
.auth-card {
  background: var(--panel); padding: 32px; border-radius: 16px; width: 340px;
  border: 1px solid var(--edge); position: relative; z-index: 0;
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-card p.sub { margin: 0 0 20px; color: var(--text-muted); font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid #2a3340;
  background: #0d1117; color: var(--text); font-size: 14px;
}
.btn-primary {
  width: 100%; padding: 12px; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600;
}
.link-row { margin-top: 14px; text-align: center; font-size: 13px; color: var(--text-muted); }
.link-row a { color: var(--accent); text-decoration: none; cursor: pointer; }
.err { color: #ff6b6b; font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ---------- chat layout ---------- */
.app { display: grid; grid-template-columns: var(--side-w, 300px) 1fr; height: 100vh; margin: 0 2mm; border: 1px solid var(--edge); position: relative; }
.sidebar { background: var(--panel); border: 1px solid var(--edge); border-radius: 14px; margin: 10px; display: flex; flex-direction: column; overflow: hidden; height: calc(100% - 20px); position: relative; z-index: 1; }
.me-bar { padding: 14px 16px; border-bottom: 1px solid #222a35; display: flex; align-items: center; gap: 10px; flex-shrink: 0; position: sticky; top: 0; background: var(--panel); z-index: 3; }
.me-bar .name { font-weight: 600; }
.me-bar select {
  margin-left: auto; background: #0d1117; color: var(--text);
  border: 1px solid #2a3340; border-radius: 8px; padding: 5px 8px; font-size: 12px;
}
.contacts { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.contact {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer;
  margin: 7px 9px; border: 1px solid var(--edge); border-radius: 12px;
  background: var(--contact-bg, #141a21);
  position: relative; z-index: 0;
}
/* tile glow sits BEHIND the card, peeking out from top/right/bottom (no left), fading at corners */
.contact::before {
  content: ""; position: absolute; inset: -6px; border-radius: 14px; z-index: -1; pointer-events: none;
  background:
    linear-gradient(90deg, transparent 12%, var(--glow-color, #4096ff) 50%, transparent 88%) top    / 100% 3px no-repeat,
    linear-gradient(90deg, transparent 12%, var(--glow-color, #4096ff) 50%, transparent 88%) bottom / 100% 3px no-repeat,
    linear-gradient(180deg, transparent 12%, var(--glow-color, #4096ff) 50%, transparent 88%) right / 3px 100% no-repeat;
  filter: blur(6px);
}
/* login panel keeps the glow on all four sides */
.auth-card::before {
  content: ""; position: absolute; inset: -3px; border-radius: inherit; z-index: -1; pointer-events: none;
  background:
    linear-gradient(90deg, transparent 12%, var(--glow-color, #4096ff) 50%, transparent 88%) top    / 100% 3px no-repeat,
    linear-gradient(90deg, transparent 12%, var(--glow-color, #4096ff) 50%, transparent 88%) bottom / 100% 3px no-repeat,
    linear-gradient(180deg, transparent 12%, var(--glow-color, #4096ff) 50%, transparent 88%) left  / 3px 100% no-repeat,
    linear-gradient(180deg, transparent 12%, var(--glow-color, #4096ff) 50%, transparent 88%) right / 3px 100% no-repeat;
  filter: blur(5px);
}
/* glow disabled from admin */
html.no-glow .contact::before,
html.no-glow .auth-card::before { display: none; }
.contact:hover, .contact.active { background: var(--contact-active-bg, #1e2530); }
.avatar {
  width: 61px; height: 61px; border-radius: 50%; background: #2a3340;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 28px; position: relative;
  flex-shrink: 0;
}
.dot { width: 18px; height: 18px; border-radius: 50%; position: absolute; right: 0; bottom: 0; border: 3px solid var(--panel); }
.dot.online { background: #2ecc71; }
.dot.away   { background: #f1c40f; }
.dot.busy   { background: #e74c3c; }
.dot.offline{ background: #6b7280; }
.contact .meta { overflow: hidden; }
.contact .meta .cname { font-weight: 700; font-size: 18px; color: var(--contact-text, var(--text)); }
.contact .meta .cstatus { font-size: 15px; color: var(--text-muted); }
.contact .badge {
  margin-left: auto; background: #e74c3c; color: #fff; font-size: 16px; font-weight: 700;
  border-radius: 14px; padding: 2px 10px; min-width: 28px; text-align: center; line-height: 1.3;
}
.admin-link { padding: 12px 16px; border-top: 1px solid #222a35; flex-shrink: 0; }
.admin-link a { color: var(--accent); text-decoration: none; font-size: 13px; }

/* ---------- chat main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
.chat-frame {
  flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; margin: 10px;
  border-radius: 14px; overflow: hidden;
  /* admin .png frame draws here */
  border-image: var(--frame); border-image-slice: 64 fill; border: 18px solid transparent;
  background-color: var(--bg);
  background-image: var(--chat-frame-grad, none);
  background-size: cover; background-position: center;
}
.chat-frame.no-frame { border: 1px solid #222a35; }
.chat-header {
  padding: 12px 16px; border-bottom: 1px solid var(--edge); display: flex; align-items: center; gap: 10px;
  background: var(--header-bg, var(--panel)); position: relative; z-index: 2;
}
.chat-header .title { font-weight: 700; font-size: 18px; }
.peer-avatar { width: 48px; height: 48px; font-size: 19px; }
.chat-header .sub { font-size: 12px; color: var(--text-muted); }
.call-buttons { margin-left: auto; display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid #2a3340;
  background: #1e2530; color: var(--text); display: flex; align-items: center; justify-content: center;
  font-size: 18px; padding: 0;
}
.icon-btn img { width: var(--header-icon-size, 22px); height: var(--header-icon-size, 22px); object-fit: contain; }
.icon-btn:hover { background: #283040; }

.messages { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.empty-hint { color: var(--text-muted); text-align: center; margin: auto; }

/* nothing selected: no input field, no header, no hint, no picker */
.empty-hint { display: none; }
.app:not(.has-peer) .composer { display: none; }
.app:not(.has-peer) .chat-header { display: none; }
.app:not(.has-peer) .picker { display: none !important; }

/* draggable sidebar width handle (desktop) */
.side-resizer {
  position: absolute; top: 0; bottom: 0; left: calc(var(--side-w, 300px) - 3px);
  width: 6px; cursor: col-resize; z-index: 30;
}
.side-resizer:hover { background: rgba(64,150,255,.30); }

/* top header icons: gray, same line style as the composer */
.call-buttons .icon-btn {
  background: none; border: none; color: var(--header-icon, #8b95a5); width: 40px; height: 40px;
}
.call-buttons .icon-btn:hover { color: var(--text); background: rgba(255,255,255,.06); }
.call-buttons .icon-btn svg { width: var(--header-icon-size, 23px); height: var(--header-icon-size, 23px); }
.msg { max-width: 72%; align-self: flex-start; padding: 11px 15px; border-radius: 16px; font-size: 17px; font-weight: 500; line-height: 1.5; word-wrap: break-word; box-shadow: 0 3px 8px rgba(0,0,0,.32), inset 0 1px 0 rgba(255,255,255,.18), inset 0 -3px 6px rgba(0,0,0,.12); }
.msg.mine {
  align-self: flex-start;
  margin-left: calc(33% - 2cm); margin-right: 0;   /* shifted ~2cm closer to the left */
  background:
    linear-gradient(180deg, rgba(255,255,255,.16), rgba(255,255,255,0) 42%, rgba(0,0,0,.12)),
    var(--bubble-mine);
  color: var(--bubble-mine-text, #fff);
  border-bottom-left-radius: 4px;
  border: var(--bubble-mine-bw, 0) solid transparent;
  border-image: var(--bubble-mine-img, none);
}
.msg.their {
  margin-right: 20%; margin-left: 1cm;   /* received messages shifted ~1cm to the right */
  background:
    linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,0) 42%, rgba(0,0,0,.14)),
    var(--bubble-their);
  color: var(--bubble-their-text, inherit);
  border-bottom-left-radius: 4px;    /* tail at bottom-left */
  border: var(--bubble-their-bw, 0) solid transparent;
  border-image: var(--bubble-their-img, none);
}
.msg img.attach { max-width: 260px; border-radius: 8px; display: block; cursor: pointer; }
.msg .file-link { color: inherit; text-decoration: underline; }
.msg audio { max-width: 240px; }
.msg .time { font-size: 10px; opacity: .7; margin-top: 4px; text-align: right; }
.msg .ticks { display: inline-block; margin-left: 4px; letter-spacing: -3px; }
.ticks.read { color: var(--tick-read, #5cd6ff); }
.typing-line { color: var(--text-muted); font-size: 12px; padding: 0 16px 4px; height: 16px; }

/* ---------- composer ---------- */
.composer { border-top: 1px solid #222a35; padding: 10px; display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.composer.top { flex-direction: column-reverse; }

/* Telegram-style single pill: [😊 GIF | textarea | 🖼 📎] + round mic/send */
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer-pill {
  flex: 1; display: flex; align-items: center; gap: 2px;
  background: var(--input-bg, #242f3d); border-radius: 24px; padding: 3px 6px; min-height: 48px;
  border: 1px solid var(--edge);
}
.composer-pill textarea#msgInput {
  flex: 1; min-width: 0; resize: none; max-height: 120px; min-height: 24px;
  background: transparent; border: none; outline: none; color: var(--input-text, var(--text));
  font-size: 16px; line-height: 1.4; padding: 11px 6px;
}
.composer-pill textarea#msgInput::placeholder { color: #6b7785; }
.pill-btn {
  flex: 0 0 auto; background: none; border: none; color: #8b95a5;
  font-size: 22px; line-height: 1; width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; padding: 0; cursor: pointer;
}
.pill-btn:hover { color: var(--text); background: rgba(255,255,255,.06); }
.pill-btn img { width: 24px; height: 24px; object-fit: contain; }
.pill-btn svg { width: 24px; height: 24px; }
#btnGif { font-size: 13px; font-weight: 700; }
/* mic / send icon inside the pill — transparent, studio icons */
.mic-pill { color: #8b95a5; }
.mic-pill.is-send { color: #4096ff; }
.mic-pill.recording { color: #e74c3c; animation: micPulse 1s ease-in-out infinite; }
@keyframes micPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.15); } }
.preview {
  display: flex; align-items: center; gap: 8px; background: #1e2530; padding: 8px 10px;
  border-radius: 8px; font-size: 13px; color: var(--text-muted);
}
.preview img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }
.preview button { background: none; border: none; color: #ff6b6b; font-size: 18px; }

/* ---------- call overlay ---------- */
.call-overlay {
  position: fixed; inset: 0; background: rgba(7,10,15,.92); z-index: 50;
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
.call-overlay.show { display: flex; }
.call-overlay h2 { margin: 0; }
.videos { position: relative; width: min(90vw, 900px); aspect-ratio: 16/9; background: #000; border-radius: 14px; overflow: hidden; }
#remoteVideo { width: 100%; height: 100%; object-fit: cover; }
#localVideo {
  position: absolute; right: 14px; bottom: 14px; width: 180px; border-radius: 10px;
  border: 2px solid #2a3340; background: #000;
}
.call-controls { display: flex; gap: 14px; }
.call-controls button {
  width: 58px; height: 58px; border-radius: 50%; border: none; font-size: 22px; color: #fff;
}
.call-hangup { background: #e74c3c; }
.call-accept { background: #2ecc71; }
.call-toggle { background: #334155; }

/* ===================== MOBILE ADAPTATION ===================== */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; height: 100vh; height: 100dvh; max-width: none; margin: 0; border: none; box-shadow: none; animation: none; }

  /* show ONE pane at a time: contact list OR chat */
  .sidebar { display: flex; width: 100%; border: none; border-radius: 0; margin: 0; height: 100%; box-shadow: none; animation: none; }
  .main { display: none; }
  .app.chat-open .sidebar { display: none; }
  .app.chat-open .main { display: flex; }

  .back-btn { display: flex !important; align-items: center; justify-content: center; }
  .side-resizer { display: none; }

  .chat-frame { margin: 0; border-radius: 0; border: 10px solid transparent; }
  .chat-frame.no-frame { border: none; }

  .messages { padding: 12px 10px; }
  .msg { max-width: 86%; }
  .msg.mine { margin-left: calc(33% - 2cm); margin-right: 0; }
  .msg.their { margin-right: 10%; }
  /* actions always slightly reachable via tap on mobile */

  .me-bar { padding: 12px; }
  .me-bar select { font-size: 13px; padding: 6px; }

  .composer { padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .toolbar { flex-wrap: wrap; }
  .tool-btn, .icon-btn { width: 44px; height: 44px; } /* touch-friendly */
  .send-btn { min-width: 56px; height: 46px; }
  .input-row textarea { min-height: 46px; font-size: 16px; } /* 16px avoids iOS zoom */

  .picker { height: 210px; }
  .chat-frame.picker-open .composer { order: 1; }
  .chat-frame.picker-open .picker { order: 2; }
  .emoji { font-size: 22px; padding: 4px; }
  .emoji-grid { grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); }
  .gif-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }

  .modal { width: 100%; max-height: 80vh; }
  .msg-search-inline.open .msg-search-field { width: 46vw; }

  /* call overlay fills screen */
  .videos { width: 100vw; height: 60vh; aspect-ratio: auto; border-radius: 0; }
  #localVideo { width: 110px; }
  .call-controls button { width: 64px; height: 64px; font-size: 24px; }

  .contact { padding: 14px 16px; }   /* bigger touch targets */
  .search-box input { font-size: 16px; }
}

@media (max-width: 400px) {
  .gif-grid { grid-template-columns: repeat(2, 1fr); }
  .send-btn { min-width: 48px; }
}


/* ---------- search ---------- */
.search-box { padding: 8px 12px; border-bottom: 1px solid #222a35; flex-shrink: 0; display: flex; align-items: center; gap: 8px; }
.menu-btn {
  flex: 0 0 auto; width: 40px; height: 40px; border: none; background: none;
  color: var(--text); font-size: 22px; line-height: 1; cursor: pointer; border-radius: 50%;
}
.menu-btn:hover { background: rgba(255,255,255,.08); }
.search-box input {
  flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--edge);
  background: var(--search-users-bg, #0d1117); color: var(--search-users-text, var(--text)); font-size: 13px;
}

/* left drawer (Telegram-style) */
.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 90;
  display: none; align-items: stretch;
}
.drawer {
  width: 300px; max-width: 85vw; height: 100%; background: var(--panel);
  box-shadow: 2px 0 24px rgba(0,0,0,.5); overflow-y: auto; padding-bottom: 20px;
  transform: translateX(-100%); transition: transform .22s ease;
}
.drawer.open { transform: translateX(0); }
.drawer-profile {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 26px 16px 18px; background: linear-gradient(160deg, #1c2733, var(--panel));
  border-bottom: 1px solid #222a35;
}
.drawer-avatar { width: 80px; height: 80px; font-size: 32px; }
.drawer-name { font-size: 18px; font-weight: 700; }
.drawer-section { padding: 14px 16px; border-bottom: 1px solid #222a35; }
.drawer-section .settings-subhead { margin-bottom: 8px; }
.drawer-section .profile-status { width: 100%; }
.drawer-links { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; }
.drawer-links a {
  display: block; padding: 12px 14px; border-radius: 8px; color: var(--text);
  text-decoration: none; font-size: 15px; cursor: pointer;
}
.drawer-links a:hover { background: #283040; }
/* inline sliding message search (expands left from the icon) */
.msg-search-inline { display: flex; align-items: center; }
.msg-search-field {
  width: 0; opacity: 0; padding: 0; border: 1px solid transparent; outline: none;
  background: var(--search-chat-bg, #0d1117); color: var(--search-chat-text, var(--text)); font-size: 14px; border-radius: 18px; height: 36px;
  transition: width .25s ease, opacity .2s ease, padding .25s ease;
}
.msg-search-field::placeholder { color: #6b7785; }
.msg-search-inline.open .msg-search-field {
  width: calc(210px + 5cm); opacity: 1; padding: 0 12px; border-color: var(--edge); margin-right: 4px;
}
.search-results {
  position: absolute; top: 60px; right: 10px; width: 320px; max-width: calc(100% - 20px);
  max-height: 300px; overflow-y: auto; background: var(--panel); border: 1px solid var(--edge);
  border-radius: 10px; padding: 6px; z-index: 40; display: none;
  box-shadow: 0 12px 34px rgba(0,0,0,.5);
}
.search-results.show { display: block; }
.sr-item { padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.sr-item:hover { background: #1e2530; }
.sr-peer { font-size: 11px; color: var(--text-muted); margin-bottom: 2px; }
.sr-body { font-size: 13px; }
.sr-body mark { background: #4b5d2a; color: #fff; border-radius: 3px; padding: 0 2px; }
.sr-empty { color: var(--text-muted); font-size: 13px; padding: 8px 10px; }
.msg.highlight { outline: 2px solid var(--accent); animation: pulse 1s ease; }
@keyframes pulse { from { background: rgba(37,99,235,.4); } }

/* ---------- emoji / gif picker ---------- */
.picker { border-top: 1px solid var(--edge); background: var(--panel); height: 210px; display: flex; flex-direction: column; flex-shrink: 0; }
.picker-tabs { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-bottom: 1px solid var(--edge); }
.ptab { background: #1e2530; color: var(--text); border: 1px solid #2a3340; border-radius: 8px; padding: 6px 12px; font-size: 13px; }
.ptab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.picker-close { margin-left: auto; background: none; border: none; color: var(--text-muted); font-size: 18px; }
.picker-body { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 0 10px 10px; position: relative; -webkit-overflow-scrolling: touch; scroll-behavior: smooth; }
.emoji-nav { position: sticky; top: 0; display: flex; gap: 2px; overflow-x: auto; padding: 5px 0 4px; background: var(--panel); z-index: 2; border-bottom: 1px solid var(--edge); }
.emoji-nav-chip { flex: 0 0 auto; background: none; border: none; font-size: 18px; line-height: 1; padding: 3px 6px; border-radius: 8px; cursor: pointer; }
.emoji-nav-chip:hover { background: #283040; }
.emoji-cat { font-size: 11px; color: var(--text-muted); margin: 6px 0 3px; text-transform: uppercase; position: sticky; top: 34px; background: var(--panel); padding: 2px 0; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(32px, 1fr)); gap: 2px; }
.emoji { background: none; border: none; font-size: 20px; line-height: 1; padding: 3px; border-radius: 6px; }
.emoji:hover { background: #283040; }
.gif-search { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid #2a3340; background: #0d1117; color: var(--text); font-size: 14px; margin: 8px 0; position: sticky; top: 0; }
.gif-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
.gif-item { width: 100%; border-radius: 8px; cursor: pointer; background: #0d1117; }
.gif-item:hover { outline: 2px solid var(--accent); }
.gif-note { color: var(--text-muted); font-size: 13px; text-align: center; padding: 24px 12px; line-height: 1.5; }

/* ---------- message context menu ---------- */
.msg { position: relative; cursor: pointer; }
.msg.menu-active { outline: 2px solid var(--accent); }
.msg-menu {
  position: fixed; z-index: 80; background: var(--panel); border: 1px solid #2a3340;
  border-radius: 12px; padding: 6px; min-width: 190px; box-shadow: 0 12px 34px rgba(0,0,0,.55);
}
.mm-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: none; border: none; color: var(--text); font-size: 15px;
  padding: 11px 14px; border-radius: 8px; cursor: pointer;
}
.mm-item:hover, .mm-item:active { background: #283040; }
.mm-item.danger { color: #ff6b6b; }
.mm-ic { width: 20px; text-align: center; font-size: 16px; }
/* quick-reaction row in the message menu */
.mm-reacts { display: flex; gap: 4px; padding: 4px 6px 8px; border-bottom: 1px solid var(--edge); margin-bottom: 4px; justify-content: space-between; }
.mm-react { font-size: 22px; line-height: 1; background: none; border: none; cursor: pointer; padding: 4px 6px; border-radius: 10px; }
.mm-react:hover, .mm-react:active { background: #283040; }
/* reaction chips under a message */
.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.react-chip {
  background: rgba(255,255,255,.08); border: 1px solid var(--edge); color: var(--text);
  border-radius: 12px; padding: 1px 8px; font-size: 13px; line-height: 1.6; cursor: pointer;
}
.react-chip.mine { background: rgba(64,150,255,.25); border-color: #4096ff; }
.fwd { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; font-style: italic; }
.edited { font-size: 10px; opacity: .7; }
.msg.deleted .deleted-text { font-style: italic; opacity: .6; }
.msg.deleted { cursor: default; }
.quote {
  border-left: 3px solid rgba(255,255,255,.55); padding: 4px 8px; margin-bottom: 6px;
  border-radius: 6px; background: rgba(0,0,0,.18); cursor: pointer; font-size: 13px;
}
.msg.their .quote { border-left-color: var(--accent); }
.quote-name { font-weight: 600; font-size: 12px; opacity: .9; margin-bottom: 1px; }
.quote-text { opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.reply-bar {
  display: flex; align-items: center; gap: 10px; background: #1e2530;
  border-left: 3px solid var(--accent); border-radius: 8px; padding: 8px 10px;
}
.reply-bar .reply-info { overflow: hidden; flex: 1; }
.reply-bar .reply-name { font-size: 12px; color: var(--accent); font-weight: 600; }
.reply-bar .reply-text { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar .reply-cancel { background: none; border: none; color: #ff6b6b; font-size: 18px; }

/* editing bar reuses reply-bar */
.reply-bar.editing { border-left-color: #f1c40f; }
.reply-bar.editing .reply-name { color: #f1c40f; }

/* ---------- forward modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(7,10,15,.7); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal { background: var(--panel); border-radius: 14px; width: 360px; max-width: 100%; max-height: 70vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid #222a35; font-weight: 600; }
.fwd-list { overflow-y: auto; padding: 6px; }
.fwd-contact { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; cursor: pointer; }
.fwd-contact:hover { background: #1e2530; }
.fwd-contact .cname { font-weight: 600; font-size: 14px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1e2530; color: var(--text); border: 1px solid #2a3340; padding: 10px 18px;
  border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 70;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- settings modal ---------- */
.settings-body { padding: 14px 16px; }
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 4px; font-size: 14px; cursor: pointer; border-bottom: 1px solid #1c232d;
}
.toggle-row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; }
.test-sound {
  margin-top: 14px; width: 100%; padding: 10px; border: 1px solid #2a3340; border-radius: 10px;
  background: #1e2530; color: var(--text); font-size: 14px;
}
.test-sound:hover { background: #283040; }

/* ---------- avatars (photo) ---------- */
.avatar-img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }

/* ---------- profile in settings ---------- */
.profile-section { display: flex; align-items: center; gap: 14px; padding: 8px 4px 16px; border-bottom: 1px solid #1c232d; }
.profile-avatar { width: 64px; height: 64px; font-size: 26px; flex-shrink: 0; }
.profile-meta { display: flex; flex-direction: column; gap: 8px; }
.profile-name { font-weight: 600; font-size: 16px; }
.btn-secondary { background: #1e2530; color: var(--text); border: 1px solid #2a3340; border-radius: 8px; padding: 7px 12px; font-size: 13px; }
.btn-secondary:hover { background: #283040; }
.settings-subhead { font-size: 11px; color: var(--text-muted); text-transform: uppercase; margin: 14px 0 4px; }


/* back button: hidden on desktop, shown on mobile */
.back-btn { display: none; font-size: 24px; line-height: 1; }

/* ---------- avatar cropper ---------- */
.crop-body { padding: 16px; }
.crop-viewport {
  position: relative; width: 280px; height: 280px; max-width: 100%; margin: 0 auto;
  overflow: hidden; border-radius: 12px; background: #000; cursor: grab; touch-action: none; user-select: none;
}
.crop-viewport:active { cursor: grabbing; }
#cropImg { position: absolute; max-width: none; pointer-events: none; }
.crop-circle {
  position: absolute; inset: 0; pointer-events: none;
  box-shadow: 0 0 0 999px rgba(0,0,0,.45); border-radius: 50%; border: 2px solid rgba(255,255,255,.8);
}
.crop-zoom { display: flex; align-items: center; gap: 10px; margin: 16px 0 6px; }
.crop-zoom input[type=range] { flex: 1; accent-color: var(--accent); }
.crop-zoom span { color: var(--text-muted); width: 16px; text-align: center; font-size: 18px; }
.crop-hint { font-size: 12px; color: var(--text-muted); text-align: center; margin: 0 0 14px; }

html.has-chat-bg .chat-frame {
  background-image: var(--chat-bg-img);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
html.has-chat-bg .messages,
html.has-chat-bg .typing-line,
html.has-chat-bg .composer { background: transparent; }

/* ---------- custom .png plate for contact rows ---------- */
html.has-contact-plate .contact {
  border-bottom: none;
  border: 14px solid transparent;
  border-image: var(--contact-img, none);
  background: transparent;
}
html.has-contact-plate .contact.active,
html.has-contact-plate .contact:hover { filter: brightness(1.12); }

/* custom .png plate for the pressed / selected contact row */
html.has-contact-plate-active .contact.active,
html.has-contact-plate-active .contact:active {
  border: 14px solid transparent;
  border-image: var(--contact-img-active, none);
  background: transparent;
  filter: none;
}

/* ===== chat-list rows (Telegram-style, shared) ===== */
.contact .meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.crow { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.contact .meta .cname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 700; font-size: 18px; }
.ctime { font-size: 13px; color: var(--text-muted); flex-shrink: 0; }
.cpreview { font-size: 15px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.contact .badge { margin-left: 0; flex-shrink: 0; }

/* ===== mobile-only chrome (hidden on desktop) ===== */
.fab, .bottom-nav { display: none; }
.app-header {
  display: flex; align-items: center; justify-content: center;
  padding: 12px 14px; border-bottom: 1px solid var(--edge);
}
.app-logo { height: var(--logo-size, 42px); width: auto; max-width: 100%; display: block; }
.app-title { font-size: 22px; font-weight: 700; color: var(--text); }

/* ===================== TELEGRAM-STYLE MOBILE ===================== */
@media (max-width: 760px) {
  /* Telegram-ish dark palette for the list chrome */
  .sidebar { background: #0e1621; }
  .me-bar { display: none; }              /* status moved into Settings */
  .desktop-links { display: none; }

  .app-header {
    display: flex; align-items: center; padding: 16px; position: relative;
    background: #17212b; border-bottom: 1px solid #0b1118;
  }
  .app-title { font-size: 22px; font-weight: 700; }
  .hdr-menu-btn { margin-left: auto; background: none; border: none; color: var(--text); font-size: 24px; width: 40px; height: 40px; line-height: 1; }
  .hdr-menu {
    position: absolute; top: 56px; right: 12px; background: #17212b; border: 1px solid #0b1118;
    border-radius: 12px; padding: 6px; z-index: 40; min-width: 190px; box-shadow: 0 12px 30px rgba(0,0,0,.55);
  }
  .hdr-menu a { display: block; padding: 12px 14px; color: var(--text); border-radius: 8px; font-size: 15px; cursor: pointer; text-decoration: none; }
  .hdr-menu a:active, .hdr-menu a:hover { background: #232e3c; }

  .search-box { padding: 8px 12px 10px; background: #17212b; border-bottom: none; }
  .search-box input {
    background: var(--search-users-bg, #242f3d); border: none; border-radius: 22px; padding: 11px 16px; font-size: 15px; color: var(--search-users-text, var(--text));
  }
  .search-box input::placeholder { color: #6b7785; }

  .contacts { background: #0e1621; padding-bottom: 150px; }   /* clear FAB + nav */
  .contact { padding: 10px 14px; border-bottom: none; gap: 13px; background: var(--contact-bg, #141a21); }
  .contact:active { background: var(--contact-active-bg, #232e3c); }
  .contact.active { background: var(--contact-active-bg, transparent); }
  .avatar { width: 82px; height: 82px; font-size: 30px; font-weight: 600; }
  .dot { width: 11px; height: 11px; border-width: 2px; }
  .peer-avatar { width: 48px; height: 48px; font-size: 19px; }
  .contact .meta .cname { font-size: 18px; font-weight: 600; color: var(--contact-text, var(--text)); }
  .cpreview { font-size: 16px; } .msg { font-size: 16px; font-weight: 400; padding: 10px 13px; }
  .ctime { font-size: 13px; } .cstatus { font-size: 16px; }
  .chat-header .title { font-size: 18px; font-weight: 600; }
  .dot { border-color: #0e1621; }

  /* floating compose button */
  .fab {
    display: flex; align-items: center; justify-content: center; position: fixed;
    right: 16px; bottom: 84px; width: 56px; height: 56px; border-radius: 50%;
    background: var(--accent); color: #fff; border: none; font-size: 22px;
    box-shadow: 0 6px 20px rgba(0,0,0,.5); z-index: 24;
  }

  /* bottom navigation */
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    background: #17212b; border-top: 1px solid #0b1118;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .nav-btn {
    flex: 1; background: none; border: none; color: #6b7785;
    display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 0 7px; font-size: 11px;
  }
  .nav-btn .nav-ic { font-size: 22px; line-height: 1; filter: grayscale(1) opacity(.7); }
  .nav-btn.active { color: var(--accent); }
  .nav-btn.active .nav-ic { filter: none; }

  /* in chat view on mobile, hide list-only chrome (sidebar already hidden) */
  .app.chat-open .bottom-nav, .app.chat-open .fab { display: none; }

  .chat-header { background: #17212b; }
  .profile-status { background: #242f3d; color: var(--text); border: 1px solid #0b1118; border-radius: 8px; padding: 8px; margin-top: 4px; }
}

.profile-status { background: #0d1117; color: var(--text); border: 1px solid #2a3340; border-radius: 8px; padding: 7px 8px; font-size: 13px; }

/* ---------- size & weight tweaks ---------- */
.me-bar .avatar { width: 41px; height: 41px; font-size: 17px; }
.me-bar .name { font-size: 17px; font-weight: 700; }
.profile-avatar { width: 88px; height: 88px; font-size: 34px; }
.input-row textarea { font-size: 16px; }
.send-btn { font-size: 16px; }
.msg .time { font-size: 11px; }
.contact { gap: 14px; }

/* ---------- avatar icon, status colors, blink ---------- */
.avatar-ico { width: 60%; height: 60%; color: #8b95a5; }
.status-online  { color: #2ecc71 !important; }
.status-away    { color: #f1c40f !important; }
.status-busy    { color: #e74c3c !important; }
.status-offline { color: #8b95a5 !important; }
/* unread blink: the whole tile pulses a soft red, numbers stay static */
@keyframes tileBlink {
  0%, 100% { background-color: var(--contact-bg, #141a21); }
  50%      { background-color: rgba(231, 76, 60, .22); }
}
.contact.blink-unread { animation: tileBlink 1.2s ease-in-out infinite; }

/* ---------- toggle switches & settings rows ---------- */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: #3a4453; border-radius: 26px; transition: .2s; cursor: pointer; }
.switch .slider::before { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: #0054ba; }
.switch input:checked + .slider::before { transform: translateX(20px); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 2px; font-size: 14px; }
.color-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 2px; font-size: 14px; }
.color-row input[type=color] { width: 44px; height: 30px; border: 1px solid #2a3340; border-radius: 8px; background: none; padding: 2px; cursor: pointer; }
.file-row { display: flex; flex-direction: column; gap: 6px; padding: 8px 2px; font-size: 14px; }
.file-row input[type=file] { font-size: 12px; color: var(--text-muted); }
.drawer-section .btn-secondary { margin-top: 10px; width: 100%; }

/* ---------- microphone / camera test modal ---------- */
.av-test-modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; align-items: center; justify-content: center; z-index: 100; }
.av-test-card { background: var(--panel); border: 1px solid var(--edge); border-radius: 14px; padding: 18px; width: min(92vw, 380px); }
.av-test-head { display: flex; align-items: center; justify-content: space-between; font-weight: 700; margin-bottom: 12px; }
.av-test-close { background: none; border: none; color: var(--text-muted); font-size: 18px; cursor: pointer; }
#avTestVideo { width: 100%; border-radius: 10px; background: #000; margin-bottom: 12px; transform: scaleX(-1); }
.av-level-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.av-level-wrap { height: 14px; border-radius: 8px; background: #1e2530; overflow: hidden; }
.av-level-bar { height: 100%; width: 0%; background: linear-gradient(90deg, #4caf50, #8bc34a, #ffc107, #ff5722); transition: width .06s linear; }
.av-test-hint { font-size: 12px; color: var(--text-muted); margin-top: 10px; line-height: 1.4; }

/* user theme picker (drawer) */
.theme-select { width: 100%; padding: 10px 12px; border-radius: 10px; background: #0d1117; color: var(--text); border: 1px solid var(--edge); font-size: 14px; margin-top: 6px; }
