
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Serif:wght@500;600;700&family=Bitter:wght@500;600;700&family=Inter:wght@400;500;600;700&display=swap');

  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

  :root {
    --bg:       #0f1015;
    --bg2:      #16171d;
    --bg3:      #1e1f28;
    --bg4:      #252631;
    --border:   #2a2b38;
    --text:     #e2e3ef;
    --muted:    #6b6d82;
    --accent:   #003153;
    --accent2:  #00223d;
    --green:    #2F6B57;
    --green-h:  #3A7A64;
    --green-a:  #255446;
    --online:   #34C88A; /* bright, lively online indicator */
    --forest:   #2F6B57; /* slate green — online dots, pills, active bar */
    --bubble-in:  #1e1f28;
    --bubble-out: #1a2f6e;
    --font:      'Inter', system-ui, -apple-system, sans-serif;
    --font-head: 'IBM Plex Serif', Georgia, serif;
    --font-name: 'Bitter', Georgia, serif;
    --mono: 'DM Mono', monospace;
  }

  html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; overscroll-behavior: none; }
  html { background: #0f1015; } /* фон при overscroll — совпадает с --bg */

  /* ── AUTH SCREEN ─────────────────────────────────────── */
  #auth-screen {
    min-height: 100vh;
    min-height: 100dvh;    /* Chrome Android fix */
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
  }

  .auth-box {
    width: 360px;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px 36px;
  }

  .auth-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 32px;
  }

  .auth-logo-icon {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .auth-logo-icon svg { width: 20px; height: 20px; }
  .auth-logo-name { font-size: 18px; font-weight: 600; letter-spacing: -0.3px; }

  .auth-tabs {
    display: flex;
    background: var(--bg3);
    border-radius: 8px;
    padding: 3px;
    margin-bottom: 24px;
    gap: 3px;
  }

  .auth-tab {
    flex: 1;
    padding: 7px;
    text-align: center;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--muted);
    transition: all .15s;
    user-select: none;
  }

  .auth-tab.active { background: var(--bg4); color: var(--text); font-weight: 500; }

  .auth-field { margin-bottom: 14px; }

  .auth-field label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 6px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .5px;
  }

  .auth-field input {
    width: 100%;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 14px;
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    outline: none;
    transition: border-color .15s;
  }

  .auth-field input:focus { border-color: var(--accent); }

  .auth-btn {
    width: 100%;
    margin-top: 8px;
    padding: 11px;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, transform .1s;
  }

  .auth-btn:hover { background: var(--accent2); }
  .auth-btn:active { transform: scale(0.98); }

  .auth-error {
    margin-top: 12px;
    padding: 10px 14px;
    background: #2d1a1a;
    border: 1px solid #5a2020;
    border-radius: 8px;
    color: #f07070;
    font-size: 13px;
    display: none;
  }

  /* ── CHAT SCREEN ─────────────────────────────────────── */
  #chat-screen {
    display: none;
    /* Height comes from the VisualViewport API (--app-h, set in index.html):
       it is the ONLY value that reliably equals the truly visible area across
       Chrome, Edge, Firefox and Safari — accounting for mobile browser
       toolbars AND the on-screen keyboard, which a fixed inset:0 box or even
       100dvh do not handle correctly on Firefox Android. Fallbacks: 100dvh,
       then 100vh, for the brief moment before JS runs / very old engines. */
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 100vh;
    height: 100dvh;
    height: var(--app-h, 100dvh);
    flex-direction: row;
  }

  /* Sidebar */
  .sidebar {
    width: 260px;
    background: var(--bg2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
  }

  .sidebar-header {
    padding: max(18px, calc(env(safe-area-inset-top) + 6px)) 16px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .sidebar-logo {
    width: 28px;
    height: 28px;
    background: var(--accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .sidebar-logo svg { width: 16px; height: 16px; }
  .sidebar-appname { font-size: 15px; font-weight: 600; flex: 1; }

  .sidebar-me {
    font-size: 12px;
    color: var(--muted);
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .me-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--online); box-shadow: 0 0 0 3px rgba(52,200,138,.2); }

  .new-chat-wrap { padding: 12px; border-bottom: 1px solid var(--border); display: flex; gap: 6px; }
  .new-chat-wrap .new-chat-input { flex: 1; min-width: 0; }
  .new-chat-wrap .new-chat-btn { flex-shrink: 0; }

  .new-chat-input {
    flex: 1;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 12px;
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
  }

  .new-chat-input:focus { border-color: var(--accent); }

  .new-chat-btn {
    background: var(--accent);
    border: none;
    border-radius: 8px;
    width: 34px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s;
  }

  .new-chat-btn:hover { background: var(--accent2); }
  .new-chat-btn svg { width: 16px; height: 16px; stroke: #fff; fill: none; stroke-width: 2; stroke-linecap: round; }

  .contacts-list { flex: 1; overflow-y: auto; }

  .contact-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background .1s;
    border-bottom: 1px solid #1a1b22;
  }

  .contact-item:hover { background: var(--bg3); }
  .contact-item.active { background: var(--bg4); }

  .contact-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
  }

  .contact-info { flex: 1; min-width: 0; }
  .contact-name { font-size: 13px; font-weight: 500; color: var(--text); }
  .contact-preview { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
  .contact-online-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--muted); }
  .contact-online-dot.online { background: var(--online); box-shadow: 0 0 0 3px rgba(52,200,138,.2); }

  .sidebar-footer {
    padding: 12px 14px max(12px, calc(env(safe-area-inset-bottom) - 10px));
    border-top: 1px solid var(--border);
  }

  .logout-btn {
    width: 100%;
    padding: 8px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--muted);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all .15s;
  }

  .logout-btn:hover { border-color: #c04040; color: #f07070; }
  .logout-btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }

  /* Chat area */
  .chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    min-width: 0;
    min-height: 0;   /* важно для flex scroll */
    overflow: hidden;
  }

  .chat-header {
    padding: max(14px, calc(env(safe-area-inset-top) + 6px)) 20px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg2);
    flex-shrink: 0;  /* не сжимается — всегда видна */
    z-index: 10;
  }

  .chat-header-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
  }

  .chat-header-info { flex: 1; }
  .chat-header-name { font-size: 14px; font-weight: 600; }
  .chat-header-status { font-size: 11px; color: var(--green); margin-top: 1px; }

  .e2e-badge {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--green);
    background: #0d2e1c;
    border: 1px solid #1a5c38;
    border-radius: 20px;
    padding: 3px 10px;
    cursor: pointer;
    user-select: none;
    transition: background .15s;
  }
  .e2e-badge:hover { background: #143d26; }
  .e2e-badge svg { width: 11px; height: 11px; stroke: currentColor; fill: none; stroke-width: 2.5; }

  /* E2E popup */
  .e2e-popup-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 20px;
  }
  .e2e-popup-overlay.visible { display: flex; }
  .e2e-popup {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    max-width: 400px;
    width: 100%;
  }
  .e2e-popup-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
  }
  .e2e-popup-icon {
    width: 36px; height: 36px;
    background: #0d2e1c;
    border: 1px solid #1a5c38;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
  .e2e-popup-icon svg { width: 18px; height: 18px; stroke: var(--green); fill: none; stroke-width: 2; }
  .e2e-popup-title { font-size: 16px; font-weight: 600; color: var(--text); }
  .e2e-popup-subtitle { font-size: 12px; color: var(--green); margin-top: 2px; }
  .e2e-layer {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 10px;
  }
  .e2e-layer-title {
    font-size: 13px; font-weight: 600; color: var(--text);
    margin-bottom: 4px;
    display: flex; align-items: center; gap: 6px;
  }
  .e2e-layer-title .lbadge {
    font-size: 10px; border-radius: 4px;
    padding: 1px 6px; font-weight: 500; color: #fff;
  }
  .e2e-layer-title .lbadge.blue { background: var(--accent); }
  .e2e-layer-title .lbadge.green { background: #0f6e56; }
  .e2e-layer-title .lbadge.teal { background: #0a5a6e; }
  .e2e-layer-desc { font-size: 12px; color: var(--muted); line-height: 1.5; }
  .e2e-popup-close {
    width: 100%; margin-top: 16px; padding: 10px;
    background: var(--bg4); border: 1px solid var(--border);
    border-radius: 8px; color: var(--muted);
    font-family: var(--font); font-size: 13px;
    cursor: pointer; transition: background .15s;
  }
  .e2e-popup-close:hover { background: var(--bg3); color: var(--text); }

  /* Empty state */
  .chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--muted);
  }

  .chat-empty svg { width: 48px; height: 48px; stroke: var(--border); fill: none; stroke-width: 1.5; }
  .chat-empty-title { font-size: 16px; font-weight: 500; color: var(--muted); }
  .chat-empty-sub { font-size: 13px; color: #3a3b4a; }

  /* Messages */
  .messages-wrap {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 20px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    /* iOS momentum scrolling */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }

  .msg-day {
    text-align: center;
    font-size: 11px;
    color: var(--muted);
    margin: 10px 0 6px;
  }

  .msg-row { display: flex; position: relative; } /* position:relative нужен для swipe icon */
  .msg-row.out { justify-content: flex-end; }
  .msg-row.in { justify-content: flex-start; }

  .msg-bubble {
    max-width: 62%;
    padding: 8px 13px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.45;
    word-break: break-word;
  }

  .msg-row.in .msg-bubble {
    background: var(--bubble-in);
    color: var(--text);
    border-bottom-left-radius: 3px;
  }

  .msg-row.out .msg-bubble {
    background: var(--bubble-out);
    color: #c8d8f5;
    border-bottom-right-radius: 3px;
  }

  .msg-time {
    font-size: 10px;
    color: var(--muted);
    margin-top: 3px;
    display: block;
    text-align: right;
  }

  .msg-row.in .msg-time { text-align: left; }

  .msg-status { font-size: 10px; color: var(--muted); margin-left: 4px; }
  .msg-status.sent { color: var(--muted); }
  .msg-status.delivered { color: var(--green); }
  .msg-status.read { color: #3b9eff; }
  .msg-status.failed { color: #e5534b; }

  /* Input */
  .input-area {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    align-items: center;
    background: var(--bg2);
    flex-shrink: 0;  /* всегда видна снизу, не сжимается */
    z-index: 10;
    /* Safe area для iPhone с чёлкой */
    padding-bottom: max(14px, calc(env(safe-area-inset-bottom) - 10px));
  }

  .msg-input-wrap { flex: 1; position: relative; }

  .msg-textarea {
    width: 100%;
    display: block; /* textarea defaults to inline-block → baseline offset lifts it ~2px above the buttons */
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 14px;
    color: var(--text);
    font-family: var(--font);
    font-size: 16px; /* iOS Safari зумит при font-size < 16px — не менять! */
    resize: none;
    outline: none;
    min-height: 42px;
    max-height: 120px;
    overflow-y: auto;
    transition: border-color .15s;
    line-height: 1.4;
    -webkit-text-size-adjust: 100%;
  }

  .msg-textarea:focus { border-color: var(--accent); }
  .msg-textarea::placeholder { color: var(--muted); }

  .send-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, transform .1s;
  }

  .send-btn:hover { background: var(--accent2); }
  .send-btn:active { transform: scale(0.95); }
  .send-btn svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2; stroke-linecap: round; }

  .attach-btn {
    width: 42px; height: 42px; border-radius: 12px;
    background: var(--bg3); border: 1px solid var(--border);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: background .15s;
  }
  .attach-btn:hover { background: var(--bg4); }
  .attach-btn svg { width: 18px; height: 18px; stroke: var(--muted); fill: none; stroke-width: 2; stroke-linecap: round; }

  /* ── Call UI ──────────────────────────────────────────── */
  /* ── Call UI — Discord style ──────────────────────────── */
  .call-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.82);
    z-index: 200;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
  }
  .call-overlay.visible { display: flex; }
  .call-box {
    background: #1e1f2e;
    border: 1px solid #2a2c40;
    border-radius: 24px;
    padding: 40px 48px 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    min-width: 300px;
    box-shadow: 0 24px 64px rgba(0,0,0,.5);
  }

  /* Avatar with pulse ring */
  .call-avatar-wrap {
    position: relative;
    margin-bottom: 20px;
  }
  .call-avatar {
    width: 88px; height: 88px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 34px; font-weight: 700; color: #fff;
    position: relative;
    z-index: 2;
  }
  .call-pulse {
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    border: 2px solid currentColor;
    opacity: 0;
    display: none;
  }
  .call-pulse.ring1 { animation: callPulse 2s ease-out infinite; }
  .call-pulse.ring2 { animation: callPulse 2s ease-out .6s infinite; }
  .call-pulse.ring3 { animation: callPulse 2s ease-out 1.2s infinite; }
  @keyframes callPulse {
    0% { transform: scale(1); opacity: .5; }
    100% { transform: scale(1.5); opacity: 0; }
  }
  .call-avatar-wrap.pulsing .call-pulse { display: block; }

  .call-name {
    font-size: 22px; font-weight: 700;
    color: #e8e9f0;
    margin-bottom: 6px;
    letter-spacing: -.3px;
  }
  .call-status {
    font-size: 13px; color: #6b6d82;
    margin-bottom: 4px;
    min-height: 20px;
  }
  .call-timer {
    font-size: 16px; color: #2ecc71;
    font-variant-numeric: tabular-nums;
    margin-bottom: 4px;
    display: none;
  }

  /* Volume slider */
  .call-volume {
    display: none;
    align-items: center;
    gap: 8px;
    margin: 16px 0 8px;
    width: 100%;
  }
  .call-volume.visible { display: flex; }
  .call-volume svg { width: 16px; height: 16px; stroke: #6b6d82; fill: none; stroke-width: 2; flex-shrink: 0; }
  .call-volume input[type=range] {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    background: #2a2c40;
    border-radius: 2px;
    outline: none;
  }
  .call-volume input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px; height: 14px;
    border-radius: 50%;
    background: #003153;
    cursor: pointer;
  }

  /* Buttons */
  .call-btns {
    display: flex;
    gap: 16px;
    margin-top: 28px;
    align-items: flex-end;
  }
  .call-btn-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
  }
  .call-btn-label {
    font-size: 11px;
    color: #6b6d82;
    font-weight: 500;
  }
  .call-btn {
    width: 60px; height: 60px; border-radius: 50%;
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: transform .12s, opacity .15s;
  }
  .call-btn:hover { transform: scale(1.08); }
  .call-btn:active { transform: scale(.95); }
  .call-btn svg { width: 22px; height: 22px; stroke: #fff; fill: none; stroke-width: 2; stroke-linecap: round; }

  /* ── Video call layout ────────────────────────────────────── */
  #remote-video, #local-video { display: none; }
  .call-overlay.video-mode { background: #000; }
  .call-overlay.video-mode #remote-video {
    display: block; position: absolute; inset: 0;
    width: 100%; height: 100%; object-fit: cover; background: #000; z-index: 0;
  }
  .call-overlay.video-mode #local-video {
    display: block; position: absolute;
    top: calc(env(safe-area-inset-top) + 14px); right: 14px;
    width: 96px; height: 132px; object-fit: cover;
    border-radius: 12px; border: 2px solid rgba(255,255,255,.35);
    background: #111; z-index: 3; transform: scaleX(-1); /* mirror self-view */
    box-shadow: 0 4px 16px rgba(0,0,0,.45);
  }
  .call-overlay.video-mode .call-avatar-wrap { display: none; }
  .call-overlay.video-mode .call-box {
    position: absolute; left: 0; right: 0; bottom: 0; top: auto;
    min-width: 0; width: 100%;
    background: linear-gradient(transparent, rgba(0,0,0,.6));
    border: none; border-radius: 0; box-shadow: none;
    padding: 48px 16px calc(22px + env(safe-area-inset-bottom));
    z-index: 2;
  }
  .call-overlay.video-mode .call-name { color: #fff; }
  .call-overlay.video-mode .call-status { color: rgba(255,255,255,.85); }
  .call-btn.end { background: #e03c3c; width: 68px; height: 68px; }
  .call-btn.end svg { width: 26px; height: 26px; }
  .call-btn.accept { background: #1a9c5b; width: 68px; height: 68px; }
  .call-btn.accept svg { width: 26px; height: 26px; }
  .call-btn.mute { background: #2a2c40; }
  .call-btn.mute.active { background: #e03c3c; }
  .call-btn.vol { background: #2a2c40; }

  /* ── Call bar — minimized indicator ─────────────────── */
  .call-bar {
    display: none;
    position: fixed;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    height: 32px;
    background: #1a4a2e;
    border: 1px solid #2a6a3e;
    border-radius: 20px;
    z-index: 150;
    align-items: center;
    gap: 10px;
    padding: 0 6px 0 12px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,.4);
    white-space: nowrap;
  }
  .call-bar.visible { display: flex; }
  .call-bar-left { display: flex; align-items: center; gap: 6px; }
  .call-bar-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: #2ecc71;
    animation: callBarPulse 1.5s ease-in-out infinite;
  }
  @keyframes callBarPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .4; }
  }
  .call-bar-name { font-size: 13px; font-weight: 600; color: #2ecc71; }
  .call-bar-timer { font-size: 12px; color: #2ecc71; font-variant-numeric: tabular-nums; }
  .call-bar-end {
    background: #e03c3c;
    border: none; border-radius: 14px;
    padding: 4px 10px;
    color: #fff; font-size: 11px; font-weight: 600;
    cursor: pointer;
  }
  .call-bar-end:hover { background: #c0392b; }

  .upload-progress {
    display: none;
    padding: 6px 16px;
    background: var(--bg2);
    border-top: 1px solid var(--border);
  }
  .upload-progress.visible { display: block; }
  .upload-progress-bar {
    height: 3px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
  }
  .upload-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width .1s;
    width: 0%;
  }
  .upload-progress-label {
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 4px;
  }

  /* ── File preview modal ─────────────────────────────────── */
  .fp-modal {
    display: none;
    position: fixed; inset: 0; z-index: 200;
    background: rgba(0,0,0,.65);
    align-items: center; justify-content: center;
    backdrop-filter: blur(4px);
  }
  .fp-modal.active { display: flex; }
  .fp-box {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px 28px 20px;
    display: flex; flex-direction: column; align-items: center;
    gap: 10px;
    min-width: 240px; max-width: 340px;
    box-shadow: 0 8px 40px rgba(0,0,0,.5);
  }
  .fp-box img {
    max-width: 280px; max-height: 220px;
    border-radius: 8px; object-fit: contain;
  }
  .fp-icon { font-size: 52px; line-height: 1; }
  .fp-fname {
    font-size: 13px; font-weight: 600; color: var(--text);
    text-align: center; word-break: break-all; max-width: 280px;
  }
  .fp-fsize { font-size: 11px; color: var(--muted); }
  .fp-hint  { font-size: 11px; color: var(--muted); }
  .fp-hint kbd {
    background: var(--bg4); border: 1px solid var(--border);
    border-radius: 4px; padding: 1px 5px; font-size: 10px;
  }
  .fp-actions { display: flex; gap: 10px; margin-top: 4px; }
  .fp-btn {
    padding: 7px 20px; border-radius: 8px; border: none;
    font-size: 13px; font-weight: 600; cursor: pointer;
    transition: opacity .15s;
  }
  .fp-btn:hover { opacity: .85; }
  .fp-cancel { background: var(--bg4); color: var(--muted); }
  .fp-send   { background: var(--accent); color: #fff; }

  .msg-image { max-width: 260px; max-height: 260px; height: auto; border-radius: 8px; cursor: pointer; display: block; margin-bottom: 4px; }
  .msg-video { max-width: 300px; height: auto; border-radius: 8px; display: block; margin-bottom: 4px; outline: none; }
  .msg-file { display: flex; align-items: center; gap: 8px; padding: 6px 0; color: inherit; text-decoration: none; }
  .msg-file svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; flex-shrink: 0; }

  /* ── Drop overlay ───────────────────────────────────────── */
  .drop-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 90;
    background: rgba(0, 49, 83, 0.82);
    border: 2px dashed var(--accent);
    border-radius: 12px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    pointer-events: none;
    backdrop-filter: blur(2px);
  }
  .drop-overlay.active { display: flex; }
  .drop-overlay svg {
    width: 52px; height: 52px;
    stroke: var(--accent); fill: none;
    stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
    opacity: .9;
  }
  .drop-overlay span {
    font-size: 16px; font-weight: 600;
    color: var(--accent); letter-spacing: .2px;
  }

  .msg-menu-btn {
    background: none; border: none; cursor: pointer; padding: 0 5px;
    color: var(--muted); font-size: 18px; line-height: 1; opacity: 0; transition: opacity .15s;
    position: absolute; top: 0; right: 2px;
  }
  .msg-bubble { position: relative; cursor: context-menu; }
  .msg-bubble:hover .msg-menu-btn, .msg-menu-btn:focus { opacity: .9; }
  .msg-edited { font-size: 10px; color: var(--muted); font-style: italic; margin-right: 5px; }
  .msg-deleted { font-style: italic; color: var(--muted); font-size: 12px; }
  .ctx-menu { position: fixed; background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 4px; z-index: 300; min-width: 160px; box-shadow: 0 8px 24px rgba(0,0,0,.4); display: block; opacity: 0; visibility: hidden; transform: scale(.95); transform-origin: top left; transition: opacity .13s ease, transform .13s ease, visibility .13s; pointer-events: none; }
  .ctx-menu.visible { opacity: 1; visibility: visible; transform: scale(1); pointer-events: auto; }
  .ctx-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text); transition: background .1s; }
  .ctx-item:hover { background: var(--bg3); }
  .ctx-item.danger { color: #e05c5c; }
  .ctx-item svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; flex-shrink: 0; }
  .reactions-bar { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
  .reaction-chip { background: var(--bg3); border: 1px solid var(--border); border-radius: 12px; padding: 2px 8px; font-size: 13px; cursor: pointer; transition: background .1s; display: inline-flex; align-items: center; gap: 4px; }
  .reaction-chip:hover { background: var(--bg4); }
  .reaction-chip.mine { border-color: var(--accent); }
  .reaction-chip .rcount { font-size: 11px; color: var(--muted); }
  .emoji-picker { position: fixed; background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 8px; z-index: 310; display: flex; opacity: 0; visibility: hidden; transform: scale(.95); transform-origin: top left; transition: opacity .13s ease, transform .13s ease, visibility .13s; pointer-events: none; gap: 4px; flex-wrap: wrap; width: 192px; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
  .emoji-picker.visible { opacity: 1; visibility: visible; transform: scale(1); pointer-events: auto; }
  .emoji-btn { font-size: 22px; cursor: pointer; padding: 4px; border-radius: 6px; transition: background .1s, transform .1s; background: none; border: none; }
  .emoji-btn:hover { background: var(--bg3); }
  .emoji-btn:active { transform: scale(.8); }

  /* ── Tap feedback + small motions ─────────────────────────── */
  .msg-menu-btn { transition: opacity .15s, transform .1s; }
  .msg-menu-btn:active { transform: scale(.8); }
  .attach-btn { transition: background .15s, transform .1s; }
  .attach-btn:active { transform: scale(.9); }
  .ctx-item:active { background: var(--bg4); }
  .reaction-chip { transition: background .1s, transform .1s; }
  .reaction-chip:active { transform: scale(.9); }
  @keyframes barSlideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
  #reply-bar-input, #edit-bar-input { animation: barSlideIn .16s ease; }
  .reply-bar { display: none; padding: 10px 16px; background: var(--bg2); border-top: 1px solid var(--border); align-items: center; gap: 12px; min-height: 52px; }
  .reply-bar.visible { display: flex; }
  .reply-bar-text { flex: 1; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.4; }
  .reply-bar-text strong { color: var(--accent); font-size: 13px; }
  .reply-bar-close { background: var(--bg4); border: none; cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; border-radius: 50%; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
  .msg-reply-quote { background: rgba(255,255,255,.06); border-left: 3px solid var(--accent); border-radius: 4px; padding: 4px 8px; margin-bottom: 4px; font-size: 12px; color: var(--muted); }
  .msg-reply-quote strong { color: var(--accent); display: block; margin-bottom: 2px; font-size: 11px; }
  .fwd-badge { font-size: 11px; color: var(--muted); margin-bottom: 2px; display: block; }

  .typing-indicator {
    display: none;
    padding: 6px 20px 2px;
    font-size: 12px;
    color: var(--muted);
    height: 22px;
  }
  .typing-indicator.visible { display: flex; align-items: center; gap: 6px; }
  .typing-dots span {
    display: inline-block;
    width: 5px; height: 5px;
    background: var(--muted);
    border-radius: 50%;
    animation: typingDot 1.2s infinite;
  }
  .typing-dots span:nth-child(2) { animation-delay: .2s; }
  .typing-dots span:nth-child(3) { animation-delay: .4s; }
  @keyframes typingDot {
    0%, 60%, 100% { transform: translateY(0); opacity: .4; }
    30% { transform: translateY(-4px); opacity: 1; }
  }

  /* Scrollbar */
  ::-webkit-scrollbar { width: 4px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

  /* Avatar colors */
  .av-0 { background:#1a2f6e; color:#6b9aff; }
  .av-1 { background:#0d3d2e; color:#2db887; }
  .av-2 { background:#2d2060; color:#9b8de8; }
  .av-3 { background:#3d1f10; color:#d4825a; }
  .av-4 { background:#2d1040; color:#c47ae0; }

  .no-chat { display: none; }

  /* ── MOBILE ──────────────────────────────────────── */
  .back-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px 4px 0;
    color: var(--text);
    align-items: center;
  }
  .back-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }

  @media (max-width: 600px) {
    .sidebar {
      width: 100%;
      position: absolute;
      top: 0; left: 0; right: 0; bottom: 0;
      z-index: 10;
      transition: transform .26s cubic-bezier(.4, 0, .2, 1);
    }
    .chat-area {
      width: 100%;
      position: absolute;
      top: 0; left: 0; right: 0; bottom: 0;
      z-index: 20;   /* above the sidebar so it slides over it */
      transition: transform .26s cubic-bezier(.4, 0, .2, 1);
      will-change: transform;
    }
    #chat-screen {
      overflow-x: hidden; /* запрещаем горизонтальный скролл; position:fixed задан выше */
    }
    /* Предотвращаем выход любого контента за ширину экрана */
    html, body { overflow-x: hidden; }
    .messages-wrap { overflow-x: hidden; }
    .msg-bubble { max-width: 80%; overflow-x: hidden; }

    /* Видео и картинки не шире экрана */
    .msg-video { max-width: 100%; width: 100%; height: auto; }
    .msg-image { max-width: 100%; height: auto; }

    /* Slide instead of display:none. In chat view the list stays behind with a
       slight parallax; in list view the chat sits off-screen to the right. */
    .sidebar.hidden { transform: translateX(-14%); }
    .chat-area.hidden { transform: translateX(100%); }
    .back-btn { display: flex; }
    .e2e-badge { font-size: 0; min-width: 30px; width: 30px; height: 30px; padding: 0; display: flex; justify-content: center; align-items: center; border-radius: 50%; flex-shrink: 0; margin-left: auto; gap: 0; }
    .e2e-badge svg { width: 14px; height: 14px; margin: 0; display: block; }
    .chat-header-status { display: none; }

    /* Auth inputs — тоже 16px чтобы не зумило */
    .auth-field input { font-size: 16px; }
    .new-chat-input { font-size: 16px; }
  }

  /* ── Swipe to reply icon (TG-style, появляется справа при свайпе влево) ── */
  .swipe-reply-icon {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%) scale(0.5);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--bg4);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    z-index: 5;
  }
  .swipe-reply-icon svg {
    width: 13px;
    height: 13px;
    stroke: var(--muted);
  }

  /* ── Floating date badge (появляется при скролле) ── */
  .floating-date-badge {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.45);
    color: #e2e3ef;
    font-size: 11px;
    font-weight: 500;
    padding: 4px 12px;
    border-radius: 12px;
    z-index: 20;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    white-space: nowrap;
    backdrop-filter: blur(4px);
  }
  .floating-date-badge.visible { opacity: 1; }

  /* Respect the OS "reduce motion" setting — keep everything instant. */
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
      animation-duration: .001ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: .001ms !important;
    }
  }

.msg-longtext { white-space: pre-wrap; word-break: break-word; }
.msg-expand {
  display: block; margin-top: 6px; font-size: 12px; cursor: pointer;
  background: none; border: none; color: var(--accent); padding: 0;
}

/* ── Search ─────────────────────────────────────── */
.search-wrap { padding: 0 12px 8px; }
.search-wrap .new-chat-input { width: 100%; }
.search-status {
  padding: 14px 16px; text-align: center;
  color: var(--muted); font-size: 13px; cursor: pointer;
}
.search-hit .contact-preview mark {
  background: rgba(0, 49, 83, .8); color: inherit; border-radius: 2px;
}
.search-date {
  float: right; font-size: 11px; font-weight: 400;
  color: var(--muted);
}

/* ── Groups ─────────────────────────────────────── */
.av-g { background: linear-gradient(135deg, #2b4d7a, #003153); }
.av-g-t { color: #7aa7d6; }
.msg-sender {
  font-size: 12px; font-weight: 600; margin: 0 0 3px;
  color: #7aa7d6;
}
.group-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 300;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
}
.group-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px;
  width: min(420px, calc(100vw - 32px)); max-height: 80vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.gp-header { display: flex; align-items: center; justify-content: space-between; }
.gp-title { font-size: 16px; font-weight: 600; }
.gp-close {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 16px; padding: 4px 8px;
}
.gp-close:hover { color: var(--text); }
.gp-sub { font-size: 12px; color: var(--muted); }
.gp-members { display: flex; flex-direction: column; gap: 4px; }
.gp-member {
  display: flex; align-items: center; gap: 10px; padding: 6px 4px;
  border-radius: 8px;
}
.gp-member:hover { background: var(--bg3); }
.gp-member-name { flex: 1; font-size: 14px; }
.gp-role { font-size: 11px; color: var(--green); margin-left: 4px; }
.gp-actions { display: flex; gap: 6px; }
.gp-act {
  background: var(--bg4); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; font-size: 11px; padding: 4px 8px; cursor: pointer;
}
.gp-act:hover { background: var(--bg3); }
.gp-danger { color: #e05c5c; }
.gp-add { display: flex; gap: 6px; }
.gp-add .new-chat-input { flex: 1; }
.gp-leave {
  background: none; border: 1px solid #e05c5c44; color: #e05c5c;
  border-radius: 8px; padding: 8px; cursor: pointer; font-size: 13px;
}
.gp-leave:hover { background: #e05c5c18; }

/* ── Unread badge ──────────────────────────────── */
.unread-badge {
  background: var(--forest); color: #cfe9db; font-size: 11px; font-weight: 700;
  min-width: 20px; height: 20px; line-height: 20px; text-align: center;
  border-radius: 10px; padding: 0 5px; margin-left: auto; flex-shrink: 0;
}

/* ── Visual polish ─────────────────────────────── */

/* Touch-скролл для iOS */
.messages-wrap {
  -webkit-overflow-scrolling: touch;
}

/* Контакты: жирный превью для непрочитанных */
.contact-item.has-unread .contact-preview { color: var(--text); font-weight: 500; }
.contact-item.has-unread .contact-name { font-weight: 700; }

/* Контакты: активный feedback */
.contact-item { transition: background .12s, transform .08s; }
.contact-item:active { transform: scale(0.98); }

/* Кнопки: feedback при нажатии */
.new-chat-btn, .send-btn, .attach-btn, .auth-btn {
  transition: background .12s, transform .08s;
}
.new-chat-btn:active, .send-btn:active, .attach-btn:active {
  transform: scale(0.92);
}

/* Фото-placeholder до загрузки (серый фон вместо скачка) */
.msg-image, .msg-video {
  background: var(--bg3);
  object-fit: cover;
}

/* Бабблы: мягкая тень для глубины */
.msg-bubble { 
  box-shadow: 0 1px 2px rgba(0,0,0,.18);
  transition: box-shadow .15s;
}

/* Скроллбар: скрываем на мобиле, стабильный на десктопе */
@media (max-width: 600px) {
  .messages-wrap::-webkit-scrollbar { display: none; }
  .messages-wrap { scrollbar-width: none; }
}
@media (min-width: 601px) {
  .messages-wrap { scrollbar-gutter: stable; }
}

/* Мобильный переход sidebar↔chat: плавный слайд */
@media (max-width: 600px) {
  .sidebar, .chat-area {
    transition: transform .2s ease-out, opacity .2s ease-out;
    will-change: transform, opacity;
  }
}

/* Инпут: фокус-подсветка */
.msg-textarea:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px rgba(0,49,83,.3);
}

/* Аватары: лёгкое свечение */
.contact-avatar, .chat-header-avatar {
  box-shadow: 0 0 0 2px var(--bg2);
  transition: box-shadow .15s;
}

/* ── Call quality & volume indicator ──── */
.call-quality { display:flex; align-items:center; gap:6px; margin-top:4px; font-size:12px; }
.volume-indicator { width:80px; height:4px; background:rgba(255,255,255,.2); border-radius:2px; margin-top:6px; overflow:hidden; }
.vol-bar { height:100%; background:var(--green); border-radius:2px; width:0%; transition:width .08s; }

/* ═══════════════════════════════════════════════════════════════════════════
   Design polish v2 — Linear/Notion-grade refinement.
   Palette & structure unchanged: only spacing, hierarchy, states, motion.
   Desktop-scoped so the mobile @media blocks above stay authoritative.
   ═════════════════════════════════════════════════════════════════════════ */
@media (min-width: 601px) {
  /* — Sidebar shell — */
  .sidebar { width: 288px; }
  .sidebar-header { padding: 16px 16px 12px; }
  .sidebar-logo {
    width: 30px; height: 30px; border-radius: 9px;
    background: linear-gradient(140deg, #0a3a63, var(--accent));
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.05);
  }
  .sidebar-appname { font-size: 15px; font-weight: 650; letter-spacing: -.2px; }
  .sidebar-me { padding: 8px 16px 10px; }

  /* — Unified fields (new-chat + search) — */
  .new-chat-wrap { padding: 8px 12px; border-bottom: none; gap: 8px; }
  .new-chat-input {
    height: 38px; border-radius: 10px; padding: 0 12px; font-size: 13px;
    transition: border-color .13s ease, background .13s ease;
  }
  .new-chat-input:focus { background: var(--bg); }
  .new-chat-btn { width: 38px; height: 38px; border-radius: 10px; }

  .search-wrap { padding: 0 12px 10px; position: relative; }
  .search-wrap .new-chat-input { height: 38px; padding-right: 50px; }
  .search-kbd {
    position: absolute; right: 21px; top: 4px; height: 30px;
    display: inline-flex; align-items: center; gap: 1px;
    font-size: 11px; font-weight: 500; color: var(--muted);
    padding: 0 7px; border: 1px solid var(--border); border-radius: 6px;
    background: var(--bg2); pointer-events: none; user-select: none;
  }
  .search-wrap:focus-within .search-kbd { opacity: 0; }

  /* — Chat list: air + Linear-style cards — */
  .contacts-list { padding: 4px 8px; }
  .contact-item {
    border-bottom: none; border-radius: 10px; padding: 9px 10px; gap: 11px;
    margin-bottom: 2px; position: relative;
    transition: background .14s ease, transform .12s ease;
  }
  .contact-item:hover { background: var(--bg3); transform: translateY(-1px); }
  .contact-item.active { background: var(--bg4); transform: none; }
  .contact-item.active::before {
    content: ''; position: absolute; left: 1px; top: 50%; transform: translateY(-50%);
    width: 3px; height: 22px; border-radius: 3px; background: var(--forest);
  }
  .contact-avatar { width: 42px; height: 42px; font-size: 14px; }
  .contact-name { font-size: 14px; font-weight: 600; }
  .contact-preview { font-size: 12.5px; margin-top: 2px; display: flex; align-items: center; gap: 5px; }
  .contact-preview .att-ico { width: 13px; height: 13px; flex-shrink: 0; stroke: var(--muted); fill: none; stroke-width: 2; }

  /* — Header: Encrypted becomes a quiet status, not a button — */
  .chat-header { padding: 12px 20px; }
  .e2e-badge {
    background: transparent; border: none; padding: 4px 6px; color: var(--muted);
    gap: 6px; border-radius: 8px;
  }
  .e2e-badge:hover { background: var(--bg3); color: var(--green); }
  .e2e-badge svg { stroke: var(--green); }

  /* — Feed rhythm & bubbles — */
  .messages-wrap { padding: 14px 22px; }
  .msg-row { margin-top: 2px; }
  .msg-bubble { padding: 8px 12px; border-radius: 16px; line-height: 1.5; }
  .msg-row.in  .msg-bubble { border-bottom-left-radius: 5px; }
  .msg-row.out .msg-bubble { border-bottom-right-radius: 5px; }
  .msg-time { font-size: 10.5px; margin-top: 2px; }

  /* — Composer — */
  .input-area { padding: 12px 20px; gap: 8px; align-items: flex-end; }
  .msg-textarea { border-radius: 14px; min-height: 44px; }
  .send-btn, .attach-btn { width: 40px; height: 40px; border-radius: 12px; }
}

/* — Reactions: more compact (all widths) — */
.reaction-chip { padding: 1px 7px; font-size: 12px; border-radius: 20px; gap: 3px; }
.reaction-chip:hover { transform: translateY(-1px); }

/* — Attach "+" composer menu (all widths) — */
.attach-wrap { position: relative; flex-shrink: 0; display: flex; }
.attach-btn.open { background: var(--bg4); }
.attach-btn.open svg { stroke: var(--text); }
.attach-menu {
  position: absolute; bottom: 50px; left: 0; min-width: 184px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: 12px;
  padding: 6px; display: none; flex-direction: column; gap: 2px; z-index: 40;
  box-shadow: 0 10px 30px -12px rgba(0,0,0,.6);
}
.attach-menu.open { display: flex; animation: attachIn .13s ease; }
@keyframes attachIn { from { opacity: 0; transform: translateY(5px) scale(.98); } to { opacity: 1; transform: none; } }
.attach-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 9px 10px; border: none; border-radius: 8px; background: none;
  color: var(--text); font-family: var(--font); font-size: 13px; text-align: left;
  cursor: pointer; transition: background .12s ease;
}
.attach-item:hover { background: var(--bg4); }
.attach-item svg { width: 17px; height: 17px; stroke: var(--muted); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* — Composer drag & drop hint — */
.input-area.dragover .msg-textarea { border-color: var(--accent); background: var(--accent2); }

/* — Mobile fixes for the polish layer —
   These must apply at ALL widths / on mobile, where the desktop-scoped
   block above does not reach. */
.contact-preview { display: flex; align-items: center; gap: 5px; }
.contact-preview .att-ico {
  width: 13px; height: 13px; flex-shrink: 0;
  stroke: var(--muted); fill: none; stroke-width: 2;
}
@media (max-width: 600px) {
  /* ⌘K/Ctrl K hint is desktop-only — no physical keyboard shortcut on phones. */
  .search-kbd { display: none !important; }
}

/* ═══════════════ Demo mode + new-message motion + empty states ═══════════════ */
/* DEMO tag in the sidebar header */
.demo-tag {
  font-size: 10px; font-weight: 700; letter-spacing: .06em;
  color: #bfe3ce; background: var(--forest);
  border: 1px solid rgba(63,160,106,.35); border-radius: 6px;
  padding: 2px 6px; margin-left: 2px; user-select: none; cursor: default;
}

/* Demo reset screen */
#demo-reset-screen {
  display: none; position: fixed; inset: 0; z-index: 10000;
  background: var(--bg); align-items: center; justify-content: center; padding: 24px;
}
.demo-reset-box { max-width: 340px; text-align: center; display: flex; flex-direction: column; align-items: center; }
.demo-reset-icon { width: 52px; height: 52px; border-radius: 14px; display: flex; align-items: center; justify-content: center; background: var(--bg3); border: 1px solid var(--border); color: var(--green); margin-bottom: 18px; }
.demo-reset-icon svg { width: 24px; height: 24px; }
.demo-reset-title { font-size: 19px; font-weight: 650; margin-bottom: 8px; }
.demo-reset-sub { font-size: 14px; color: var(--muted); line-height: 1.55; margin-bottom: 22px; }
#demo-reset-screen .auth-btn { max-width: 220px; }

/* New-message appear — added only to the last row when a genuinely new
   message arrives (see renderMessages), so the feed never re-flashes. */
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-row.msg-in { animation: msgIn .16s ease both; }

/* Empty contact list */
.contacts-empty {
  padding: 40px 24px; text-align: center; color: var(--text);
  font-size: 14px; font-weight: 500; line-height: 1.5;
}
.contacts-empty span { display: block; margin-top: 6px; font-size: 12.5px; font-weight: 400; color: var(--muted); }

/* ═══════════════ UX polish: toasts, skeletons, empty states, hierarchy ═══════════════ */
/* Toasts (non-blocking, replace alert) */
#toast-host {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 11000; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: max-content; max-width: min(92vw, 420px);
}
.toast {
  pointer-events: auto; padding: 11px 15px; border-radius: 11px;
  font-size: 13.5px; line-height: 1.4; color: var(--text);
  background: var(--bg4); border: 1px solid var(--border);
  box-shadow: 0 10px 30px -12px rgba(0,0,0,.6);
  opacity: 0; transform: translateY(8px); transition: opacity .18s ease, transform .18s ease;
  max-width: 100%;
}
.toast.in { opacity: 1; transform: none; }
.toast-error   { border-left: 3px solid #e5534b; }
.toast-success { border-left: 3px solid var(--green); }
.toast-info    { border-left: 3px solid var(--accent); }

/* Message time hierarchy: dim own-message meta a touch more, tighten day chip */
.msg-row.out .msg-time { opacity: .7; }
.msg-day {
  display: inline-block; align-self: center;
  padding: 2px 10px; border-radius: 20px;
  background: rgba(255,255,255,.03); color: var(--muted);
  font-size: 11px; font-weight: 500;
}

/* Empty states */
.contacts-empty, .chat-empty { color: var(--text); }
.contacts-empty .ce-ico, .chat-empty svg { color: var(--muted); }
.contacts-empty .ce-ico {
  width: 34px; height: 34px; margin: 0 auto 12px; display: block;
  stroke: var(--muted); fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
  opacity: .7;
}

/* Sidebar skeleton (first load, before contacts render) */
.skel-item { display: flex; align-items: center; gap: 11px; padding: 9px 10px; }
.skel-ava { width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0; }
.skel-lines { flex: 1; display: flex; flex-direction: column; gap: 7px; }
.skel-line { height: 9px; border-radius: 5px; }
.skel-line.short { width: 45%; }
.skel-ava, .skel-line {
  background: linear-gradient(100deg, var(--bg3) 30%, var(--bg4) 50%, var(--bg3) 70%);
  background-size: 200% 100%; animation: skelShimmer 1.3s ease-in-out infinite;
}
@keyframes skelShimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skel-ava, .skel-line { animation: none; } }

/* ═══════════════ Groups distinguishable + group online ═══════════════ */
/* Group avatars use a rounded square; individuals stay round. */
.contact-avatar.is-group, .chat-header-avatar.is-group { border-radius: 13px; }
.ct-avatar-wrap { position: relative; flex-shrink: 0; }
.ct-group-badge {
  position: absolute; right: -3px; bottom: -3px;
  width: 17px; height: 17px; border-radius: 50%;
  background: var(--bg2); border: 2px solid var(--bg2);
  display: flex; align-items: center; justify-content: center;
}
.contact-item.active .ct-group-badge { background: var(--bg4); border-color: var(--bg4); }
.ct-group-badge svg { width: 11px; height: 11px; stroke: var(--sub); fill: none; stroke-width: 2.2; }
/* "N online" for groups in the list. */
.group-online { display: inline-flex; align-items: center; gap: 5px; flex-shrink: 0; font-size: 11px; font-weight: 600; color: var(--online); }
.group-online .go-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--online); box-shadow: 0 0 0 3px rgba(52,200,138,.18); }
.group-online.none { color: var(--muted); }
.group-online.none .go-dot { background: var(--muted); box-shadow: none; }

/* ═══════════════ Typographic system (3 fonts) ═══════════════
   Body: Inter (sans). Headings: IBM Plex Serif. Names & avatar initials: Bitter. */
.contact-avatar, .chat-header-avatar,
.contact-name, .chat-header-name,
.sidebar-appname, .msg-sender,
.gp-name, .gp-title, .call-name, .call-bar-name {
  font-family: var(--font-name);
}
.chat-empty-title, .e2e-popup-title, .demo-reset-title, .contacts-empty {
  font-family: var(--font-head);
  letter-spacing: -.2px;
}
.contacts-empty span { font-family: var(--font); }

/* ═══════════════ Group manage affordance, density, reactions, modals ═══════════════ */
/* Only this pill (with its people glyph) opens group management. */
.gp-manage {
  display: inline-flex; align-items: center; gap: 5px;
  margin-left: 2px; padding: 2px 8px; border-radius: 20px;
  color: var(--sub); cursor: pointer; user-select: none;
  transition: background .12s ease, color .12s ease;
}
.gp-manage:hover { background: var(--bg3); color: var(--text); }
.gp-manage svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2; }

/* Density (desktop): readability-only type bumps. Deliberately NO layout
   changes (widths, paddings, centering) so it can't break the flex layout. */
@media (min-width: 601px) {
  .contact-name { font-size: 14.5px; }
  .contact-preview { font-size: 13px; }
  .chat-header-name { font-size: 15.5px; }
  .msg-bubble { font-size: 14.5px; }
}

/* Reactions: pop the chip in gently instead of the bubble snapping wider. */
@keyframes reactionPop { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: scale(1); } }
.reaction-chip { animation: reactionPop .17s cubic-bezier(.2,.9,.3,1.2) both; }
.reactions-bar { animation: fadeUp .18s ease both; }
@media (prefers-reduced-motion: reduce) { .reaction-chip, .reactions-bar { animation: none !important; } }

/* Hexeris-styled confirm / prompt modal (replaces native confirm()/prompt()). */
.hex-modal-overlay {
  position: fixed; inset: 0; z-index: 12000; display: none;
  align-items: center; justify-content: center; padding: 20px;
  background: rgba(0,0,0,.55);
}
.hex-modal-overlay.open { display: flex; }
.hex-modal {
  width: 100%; max-width: 360px; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 16px; padding: 22px;
  box-shadow: 0 24px 60px -20px rgba(0,0,0,.7);
  animation: fadeUp .16s ease both;
}
.hex-modal-title { font-family: var(--font-head); font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.hex-modal-msg { font-size: 13.5px; color: var(--sub); line-height: 1.5; margin-bottom: 16px; }
.hex-modal input {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; color: var(--text);
  font-family: var(--font); font-size: 14px; outline: none; margin-bottom: 16px;
}
.hex-modal input:focus { border-color: var(--accent); }
.hex-modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.hex-btn {
  padding: 8px 16px; border-radius: 9px; font-family: var(--font);
  font-size: 13px; font-weight: 500; cursor: pointer; border: 1px solid var(--border);
  background: transparent; color: var(--sub); transition: all .14s ease;
}
.hex-btn:hover { color: var(--text); background: var(--bg3); }
.hex-btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.hex-btn.primary:hover { background: var(--accent-h); color: #fff; }
.hex-btn.danger { background: #b5352d; color: #fff; border-color: transparent; }
.hex-btn.danger:hover { background: #c8403a; }

/* Sidebar wordmark uses the landing heading serif (IBM Plex Serif), not Bitter. */
.sidebar-appname { font-family: var(--font-head); font-weight: 600; letter-spacing: -.2px; }
