/* ==========================================================================
   MD-Chat web client — visual design
   A calm, premium, trustworthy sovereign-European encrypted messenger.
   Deep ink/navy base, refined teal/emerald accent, self-hosted fonts.
   Vanilla CSS. No external CDN at runtime (fonts bundled locally).

   FIXED contract ids/classes preserved:
     Auth: #view-auth #step-phone #inp-phone #btn-send-code #step-code
           #inp-code #btn-verify-code #btn-change-phone #phone-echo #auth-error
     App : #view-app #me #btn-logout #btn-new-room #room-list #room-title
           #timeline #inp-msg #btn-send  .hidden .msg .msg-mine .room-item
   ========================================================================== */

/* ---------- Self-hosted fonts (woff2, latin + latin-ext for RO diacritics) -- */
/* Brand / display: Sora — distinctive geometric grotesque */
@font-face {
  font-family: "Sora";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/sora-600.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Sora";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/sora-600-ext.woff2") format("woff2");
  unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Sora";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/sora-700.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Sora";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/sora-700-ext.woff2") format("woff2");
  unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* Body / messages: IBM Plex Sans — highly readable, strong identity */
@font-face {
  font-family: "Plex";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/plex-400.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Plex";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/plex-400-ext.woff2") format("woff2");
  unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Plex";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/plex-500.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Plex";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/plex-500-ext.woff2") format("woff2");
  unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Plex";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/plex-600.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Plex";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/plex-600-ext.woff2") format("woff2");
  unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Plex";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/plex-700.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Plex";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/plex-700-ext.woff2") format("woff2");
  unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---------- Design tokens ---------- */
:root {
  /* Surfaces — deep ink/navy with subtly elevated layers */
  --bg:            #0b0f14;   /* app backdrop, deepest */
  --bg-1:          #0d131a;   /* canvas behind chat */
  --bg-2:          #111922;   /* panels / sidebar */
  --bg-3:          #16202b;   /* raised elements, inputs */
  --bg-hover:      #19242f;
  --bg-active:     #13241f;   /* selected room (teal-tinted) */

  /* Bubbles */
  --bubble-in:        #16212c;
  --bubble-in-border: #223040;
  --bubble-mine:      #14b8a6;
  --bubble-mine-2:    #0f9d8f;
  --bubble-mine-soft: rgba(45, 212, 191, .12);

  /* Text */
  --text:          #e7edf3;
  --text-soft:     #9fb0bf;
  --text-dim:      #5f7180;
  --text-on-accent:#04201c;
  --text-on-mine:  #04241f;

  /* Accent — refined teal / emerald */
  --accent:        #2dd4bf;
  --accent-strong: #5eead4;
  --accent-deep:   #14b8a6;
  --accent-press:  #0d9488;
  --accent-glow:   rgba(45, 212, 191, .22);
  --accent-soft:   rgba(45, 212, 191, .12);

  /* Feedback */
  --danger:        #f97066;
  --danger-bg:     #2a1614;
  --danger-border: rgba(249, 112, 102, .32);

  /* Lines & shadows */
  --border:        #060a0e;
  --border-soft:   #1d2935;
  --hairline:      rgba(255, 255, 255, .055);
  --shadow:        0 18px 48px -12px rgba(0, 0, 0, .6);
  --shadow-sm:     0 1px 2px rgba(0, 0, 0, .3);
  --shadow-pop:    0 24px 64px -16px rgba(0, 0, 0, .7), 0 0 0 1px var(--border-soft);

  /* Geometry */
  --radius:        16px;
  --radius-sm:     11px;
  --radius-lg:     22px;
  --radius-pill:   999px;
  --sidebar-w:     340px;
  --header-h:      62px;

  /* Motion */
  --t-fast:        .14s cubic-bezier(.2, .8, .2, 1);
  --t:             .24s cubic-bezier(.2, .8, .2, 1);

  /* Fonts */
  --font-brand: "Sora", "Plex", ui-sans-serif, sans-serif;
  --font-body:  "Plex", ui-sans-serif, system-ui, sans-serif;

  color-scheme: dark;
}

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

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

button { font-family: inherit; }

.hidden { display: none !important; }

/* Custom scrollbars (tasteful, thin) */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-soft) transparent;
}
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb {
  background: var(--border-soft);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: #2a3a4a; background-clip: padding-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- Shared avatar (deterministic color via inline --av) ---------- */
.avatar {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  font-family: var(--font-brand);
  font-weight: 700;
  color: #fff;
  letter-spacing: .01em;
  text-transform: uppercase;
  user-select: none;
  background:
    linear-gradient(155deg,
      hsl(var(--av, 174) 62% 52%),
      hsl(var(--av, 174) 64% 38%));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .14), var(--shadow-sm);
}

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-body);
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  transition: background var(--t-fast), transform var(--t-fast),
              border-color var(--t-fast), box-shadow var(--t-fast), color var(--t-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-primary {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent-deep));
  color: var(--text-on-accent);
  box-shadow: 0 6px 18px -8px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.btn-primary:hover  { filter: brightness(1.06); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); filter: brightness(.96); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; filter: none; }

.btn-ghost {
  background: var(--bg-3);
  color: var(--text-soft);
  border-color: var(--border-soft);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); border-color: #2a3a4a; }
.btn-sm { padding: 8px 14px; font-size: 13.5px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-soft);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--accent-strong); }

/* ==========================================================================
   AUTH VIEW
   ========================================================================== */
#view-auth {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 620px at 50% -8%, var(--accent-soft), transparent 62%),
    radial-gradient(700px 500px at 90% 110%, rgba(20, 184, 166, .06), transparent 60%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 388px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  padding: 36px 30px 26px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow);
}

.auth-head { text-align: center; margin-bottom: 2px; }
.auth-mark {
  width: 62px; height: 62px;
  margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 18px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid rgba(45, 212, 191, .25);
  box-shadow: 0 8px 24px -10px var(--accent-glow);
}
.auth-logo {
  margin: 0;
  font-family: var(--font-brand);
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
}
.auth-sub { margin: 6px 0 0; font-size: 14px; color: var(--text-soft); }

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-step-hint {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-soft);
  text-align: center;
  line-height: 1.5;
}
.phone-echo { color: var(--text); font-weight: 600; white-space: nowrap; }

.field { display: block; }
.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 7px;
}

#inp-phone,
#inp-code {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 17px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
  outline: none;
}
#inp-phone::placeholder,
#inp-code::placeholder { color: var(--text-dim); }
#inp-phone:focus,
#inp-code:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: #18242f;
}

.phone-input { font-size: 20px !important; font-weight: 600; letter-spacing: .01em; }
.code-input {
  text-align: center;
  font-size: 27px !important;
  font-weight: 700;
  letter-spacing: .42em;
  text-indent: .42em;
  font-variant-numeric: tabular-nums;
}

.auth-actions { margin-top: 2px; }
#btn-send-code,
#btn-verify-code { width: 100%; padding: 14px 16px; font-size: 15px; }

.auth-link {
  align-self: center;
  background: none;
  border: none;
  padding: 4px 6px;
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--accent-strong);
  cursor: pointer;
  transition: color var(--t-fast);
}
.auth-link:hover { color: var(--accent); text-decoration: underline; }
.auth-link:disabled { opacity: .55; cursor: not-allowed; }

#auth-error {
  min-height: 0;
  margin: 0;
  font-size: 13.5px;
  color: var(--danger);
  text-align: center;
  word-break: break-word;
}
#auth-error:not(:empty) {
  padding: 10px 12px;
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-sm);
}

.auth-foot {
  margin: 6px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--hairline);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dim);
  text-align: center;
}
.auth-lock { margin-right: 4px; }

/* ==========================================================================
   APP VIEW
   ========================================================================== */
#view-app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
  background: var(--bg);
  overflow: hidden;
}

/* ---------- Header ---------- */
.app-header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px 0 18px;
  background:
    linear-gradient(180deg, rgba(45, 212, 191, .05), transparent 80%),
    var(--bg-2);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--hairline);
  z-index: 20;
}

.back-btn { display: none; }

.app-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -.01em;
  color: var(--text);
}
.app-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 9px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid rgba(45, 212, 191, .22);
}

.app-header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Profile chip (avatar + display name) — replaces raw MXID */
#me {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 230px;
  padding: 5px 12px 5px 6px;
  border-radius: var(--radius-pill);
  background: var(--bg-3);
  border: 1px solid var(--border-soft);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast);
}
#me:hover { background: var(--bg-hover); border-color: #2a3a4a; }
#me .me-avatar { width: 28px; height: 28px; font-size: 12px; }
#me .me-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#btn-logout {
  padding: 8px 14px;
  background: transparent;
  color: var(--text-soft);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
#btn-logout:hover {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger-border);
}

/* ---------- Sidebar ---------- */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 12px 8px 18px;
}
.sidebar-title {
  font-family: var(--font-brand);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--text);
}
.sidebar-actions { margin-left: auto; display: flex; gap: 2px; }

.new-chat-btn {
  margin: 4px 12px 8px;
  padding: 12px 14px;
  font-size: 14.5px;
}

#room-list {
  list-style: none;
  margin: 0;
  padding: 4px 8px 14px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

/* Sidebar empty hint (when no rooms) */
.room-list-empty {
  margin: 28px 16px;
  padding: 22px 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.6;
  border: 1px dashed var(--border-soft);
  border-radius: var(--radius);
}
.room-list-empty strong { display: block; color: var(--text-soft); font-weight: 600; margin-bottom: 4px; }

/* ---------- Room list items ---------- */
.room-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: background var(--t-fast);
  position: relative;
  min-width: 0;
}
.room-item:hover { background: var(--bg-hover); }
.room-item.active { background: var(--bg-active); box-shadow: inset 2px 0 0 var(--accent); }

.room-item .avatar { width: 46px; height: 46px; font-size: 17px; }

.room-item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.room-item-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.room-item-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
}
.room-item-time {
  flex: 0 0 auto;
  font-size: 11.5px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.room-item-row2 {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.room-item-preview {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--text-soft);
}
.room-item.active .room-item-preview { color: var(--text-soft); }
.room-item-preview-mine { color: var(--text-dim); }

.room-lock { font-size: 11px; opacity: .9; margin-left: 2px; }

.room-item-badge {
  flex: 0 0 auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--text-on-accent);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1;
}

/* ---------- Main panel ---------- */
.chat {
  grid-area: main;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  position: relative;
  background:
    radial-gradient(1100px 760px at 78% -16%, rgba(45, 212, 191, .045), transparent 58%),
    var(--bg-1);
}

.chat-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  min-height: 56px;
  padding: 0 18px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--hairline);
  z-index: 5;
}
.chat-head-room { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.chat-avatar { width: 40px; height: 40px; font-size: 15px; }
.chat-search-btn { flex: 0 0 auto; margin-left: auto; }
.chat-head-room.hidden + .chat-search-btn { display: none; }
.chat-head-text { display: flex; flex-direction: column; min-width: 0; }

#room-title {
  margin: 0;
  font-family: var(--font-brand);
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-sub {
  font-size: 12px;
  color: var(--accent-strong);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ---------- Timeline ---------- */
#timeline {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 18px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
}
/* Hidden when empty-state is showing (no room open) — JS controls display */

/* Date separator */
.date-sep {
  align-self: center;
  margin: 14px 0 10px;
  padding: 4px 12px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text-soft);
  background: rgba(13, 19, 26, .7);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  backdrop-filter: blur(6px);
}

/* ---------- Message rows (avatar + bubble) ---------- */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  max-width: 100%;
}
.msg-row-mine { flex-direction: row-reverse; }
.msg-row .row-avatar { width: 30px; height: 30px; font-size: 12px; visibility: hidden; }
.msg-row.show-avatar .row-avatar { visibility: visible; }
.msg-row-mine .row-avatar { display: none; }

/* ---------- Message bubbles ---------- */
.msg,
.msg-mine {
  max-width: min(74%, 580px);
  padding: 9px 13px 7px;
  border-radius: 18px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  position: relative;
  animation: bubble-in .18s cubic-bezier(.2, .8, .2, 1) both;
}
.msg {
  align-self: flex-start;
  background: var(--bubble-in);
  color: var(--text);
  border: 1px solid var(--bubble-in-border);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-sm);
}
.msg-mine {
  align-self: flex-end;
  background: linear-gradient(160deg, var(--bubble-mine), var(--bubble-mine-2));
  color: var(--text-on-mine);
  border-bottom-right-radius: 6px;
  box-shadow: 0 4px 14px -8px var(--accent-glow);
}

.msg-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 1px; }
.msg-sender {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent-strong);
  letter-spacing: -.005em;
}
.msg-mine .msg-sender { display: none; }

.msg-body { font-size: 14.5px; line-height: 1.5; }

.msg-time,
.msg .msg-time {
  display: inline-block;
  float: right;
  margin: 5px 0 -2px 12px;
  font-size: 10.5px;
  line-height: 1;
  color: var(--text-dim);
  user-select: none;
  font-variant-numeric: tabular-nums;
}
.msg-meta .msg-time { float: none; margin: 0 0 0 auto; }
.msg-mine .msg-time { color: rgba(4, 36, 31, .55); }

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(7px) scale(.99); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.msg-failed {
  background: var(--danger-bg) !important;
  color: var(--danger) !important;
  border: 1px solid var(--danger-border) !important;
}

.timeline-status { margin: auto; color: var(--text-dim); font-size: 14px; }

/* ---------- Empty state ---------- */
.empty-state {
  position: absolute;
  inset: 56px 0 76px;       /* below header, above composer */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  gap: 6px;
  pointer-events: none;
}
.empty-state.active { pointer-events: auto; }
.empty-illust { margin-bottom: 8px; opacity: .96; }
.empty-title {
  margin: 0;
  font-family: var(--font-brand);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--text);
}
.empty-text {
  margin: 0;
  max-width: 360px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-soft);
}
.empty-actions {
  margin-top: 18px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.empty-actions .btn { padding: 11px 18px; font-size: 14px; }

/* ---------- Composer ---------- */
.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 13px 16px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  box-shadow: 0 -1px 0 var(--hairline);
  z-index: 5;
}

#inp-msg {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 160px;
  padding: 12px 16px;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
#inp-msg::placeholder { color: var(--text-dim); }
#inp-msg:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.composer-send {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  padding: 0;
  border-radius: var(--radius);
}
.composer-send svg { transform: translateX(-1px); }

/* ==========================================================================
   MODALS + TOAST
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 8, 12, .62);
  backdrop-filter: blur(4px);
  animation: overlay-in .18s ease both;
}
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%;
  max-width: 440px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  padding: 24px;
  animation: modal-in .22s cubic-bezier(.2, .8, .2, 1) both;
}
.modal-sm { max-width: 380px; text-align: center; }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.modal-title {
  margin: 0;
  font-family: var(--font-brand);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.01em;
  color: var(--text);
}
.modal-head .modal-title { flex: 1; }
.modal-close { margin: -6px -6px -6px 0; }

.modal-mark {
  font-size: 34px;
  line-height: 1;
  margin-bottom: 12px;
}
.modal-sm .modal-title { margin-bottom: 4px; }

.modal-text {
  margin: 4px 0 16px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-soft);
}

.modal-input {
  width: 100%;
  padding: 13px 15px;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 15px;
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.modal-input::placeholder { color: var(--text-dim); }
.modal-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.modal-input[readonly] { color: var(--text-soft); }

.modal-error {
  min-height: 0;
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--danger);
}
.modal-hint { margin: 10px 0 0; font-size: 12.5px; color: var(--text-dim); min-height: 16px; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 18px;
}
.modal-actions .btn { padding: 11px 18px; font-size: 14px; }
.modal-btn-full { width: 100%; padding: 13px !important; }

.copy-row { display: flex; gap: 8px; }
.copy-row .modal-input { flex: 1; min-width: 0; }
.copy-btn { flex: 0 0 auto; padding: 0 16px; white-space: nowrap; }

.field-block { display: block; margin-top: 16px; }
.field-block .field-label { margin-bottom: 8px; }

/* Profile hero */
.profile-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 0 14px;
}
.profile-avatar { width: 64px; height: 64px; font-size: 24px; }
.profile-id-wrap { display: flex; flex-direction: column; min-width: 0; gap: 3px; }
.profile-name {
  font-family: var(--font-brand);
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.profile-mxid {
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--font-body);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(10px);
  z-index: 200;
  padding: 12px 20px;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity var(--t), transform var(--t);
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ==========================================================================
   RESPONSIVE — collapse to single column on phones
   ========================================================================== */
@media (max-width: 760px) {
  :root { --sidebar-w: 100%; }

  #view-app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) 1fr;
    grid-template-areas:
      "header"
      "sidebar";
  }
  .chat {
    grid-area: sidebar;
    grid-row: 2;
    grid-column: 1;
  }

  /* Default: list visible, chat hidden until a room opens (.show-chat) */
  #view-app:not(.show-chat) .chat { display: none; }
  #view-app.show-chat .sidebar { display: none; }
  #view-app.show-chat .chat { display: flex; }
  #view-app.show-chat .back-btn { display: inline-flex; }
  #view-app.show-chat .app-brand { display: none; }

  .msg, .msg-mine { max-width: 84%; }

  .chat-head { padding: 0 12px; }
  #timeline { padding: 16px 12px 8px; }
  .composer { padding: 11px 12px; padding-bottom: calc(11px + env(safe-area-inset-bottom)); }
  .empty-state { inset: 56px 0 72px; }
  #me { max-width: 150px; }
}

@media (max-width: 420px) {
  #view-auth { padding: 16px; }
  .auth-card { padding: 28px 22px 22px; }
}

/* ---------- Accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}
#inp-phone:focus-visible,
#inp-code:focus-visible,
#inp-msg:focus-visible,
.modal-input:focus-visible { outline: none; }

/* ==========================================================================
   RICH MESSAGING — media, reactions, reply, edit, voice, typing, receipts
   ========================================================================== */

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ---------- Typing indicator (under the peer name) ---------- */
.typing-row {
  display: block;
  font-size: 12px;
  line-height: 1.2;
  color: var(--accent-strong);
  font-style: italic;
  animation: typing-pulse 1.4s ease-in-out infinite;
}
@keyframes typing-pulse { 0%,100% { opacity: .55; } 50% { opacity: 1; } }
.chat-sub.is-typing { color: var(--accent-strong); }

/* ---------- Message action toolbar (hover / long-press) ---------- */
.msg, .msg-mine { /* anchor for the floating action bar */ }
.msg-actions {
  position: absolute;
  top: -14px;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--bg-3);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-pop);
  opacity: 0;
  transform: translateY(4px) scale(.96);
  pointer-events: none;
  transition: opacity var(--t-fast), transform var(--t-fast);
  z-index: 6;
}
.msg .msg-actions { right: 6px; }
.msg-mine .msg-actions { left: 6px; }
.msg-row:hover .msg-actions,
.actions-open .msg-actions {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.msg-action-btn {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none;
  background: transparent;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  transition: background var(--t-fast), transform var(--t-fast);
  color: var(--text);
}
.msg-action-btn:hover { background: var(--bg-hover); transform: scale(1.12); }

/* ---------- Reaction picker (floating) ---------- */
.reaction-picker {
  position: fixed;
  display: flex;
  gap: 2px;
  padding: 6px;
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-pop);
  z-index: 120;
  animation: bubble-in .14s cubic-bezier(.2,.8,.2,1) both;
}
.reaction-choice {
  width: 34px; height: 34px;
  border: none; background: transparent;
  border-radius: 50%;
  font-size: 19px; line-height: 1;
  cursor: pointer;
  transition: background var(--t-fast), transform var(--t-fast);
}
.reaction-choice:hover { background: var(--bg-hover); transform: scale(1.25); }

/* ---------- Reaction pills (under a bubble) ---------- */
.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}
.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 9px;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  background: var(--bg-3);
  color: var(--text-soft);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}
.reaction-pill:hover { transform: translateY(-1px); }
.reaction-pill.mine {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
}
.msg-mine .reaction-pill { background: rgba(4,36,31,.18); color: rgba(4,36,31,.78); border-color: rgba(4,36,31,.22); }
.msg-mine .reaction-pill.mine { background: rgba(4,36,31,.32); color: #04241f; border-color: rgba(4,36,31,.4); }

/* ---------- Reply quote (above a bubble) + jump flash ---------- */
.reply-quote {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: -1px 0 6px;
  padding: 4px 9px;
  border-left: 3px solid var(--accent);
  background: rgba(45,212,191,.08);
  border-radius: 7px;
  cursor: pointer;
  max-width: 100%;
}
.msg-mine .reply-quote { border-left-color: rgba(4,36,31,.5); background: rgba(4,36,31,.12); }
.reply-quote-who { font-size: 12px; font-weight: 700; color: var(--accent-strong); }
.msg-mine .reply-quote-who { color: rgba(4,36,31,.85); }
.reply-quote-text {
  font-size: 12.5px;
  color: var(--text-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 320px;
}
.msg-mine .reply-quote-text { color: rgba(4,36,31,.7); }
.msg-row.flash .msg, .msg-row.flash .msg-mine {
  animation: flash-bubble 1.1s ease-out;
}
@keyframes flash-bubble {
  0% { box-shadow: 0 0 0 3px var(--accent-glow); }
  100% { box-shadow: none; }
}

/* ---------- Edit marker + redacted ---------- */
.msg-edited { font-size: 11px; color: var(--text-dim); font-style: italic; }
.msg-mine .msg-edited { color: rgba(4,36,31,.5); }
.msg-redacted .msg-body { font-style: italic; color: var(--text-dim); }
.msg-mine.msg-redacted .msg-body { color: rgba(4,36,31,.55); }

/* ---------- Read receipt ticks ---------- */
.msg-tick { font-size: 11px; letter-spacing: -1px; opacity: .7; }
.msg-tick.read { color: #5eead4; opacity: 1; }
.msg-mine .msg-tick { color: rgba(4,36,31,.6); }
.msg-mine .msg-tick.read { color: #043; opacity: .95; }

/* ---------- Media: images ---------- */
.media-image {
  position: relative;
  display: block;
  margin: 2px 0 4px;
  border-radius: 12px;
  overflow: hidden;
  cursor: zoom-in;
  max-width: 320px;
  background: var(--bg-3);
}
.media-thumb {
  display: block;
  width: 100%;
  max-width: 320px;
  max-height: 360px;
  object-fit: cover;
  border-radius: 12px;
}
.media-loading {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12.5px;
  color: var(--text-soft);
  background: var(--bg-3);
  min-height: 120px;
}

/* ---------- Media: video ---------- */
.media-video {
  margin: 2px 0 4px;
  border-radius: 12px;
  overflow: hidden;
  max-width: 360px;
}
.media-video video { width: 100%; max-width: 360px; border-radius: 12px; display: block; }
.media-video-poster {
  position: relative;
  width: 260px; max-width: 100%;
  min-height: 120px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px;
  border: 1px solid var(--border-soft);
  background: linear-gradient(135deg, var(--bg-3), var(--bg-2));
  border-radius: 12px;
  cursor: pointer;
  color: var(--text);
}
.media-play {
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--text-on-accent);
  font-size: 18px;
  box-shadow: 0 6px 18px -6px var(--accent-glow);
}
.media-video-meta { font-size: 12.5px; color: var(--text-soft); }

/* ---------- Media: file card ---------- */
.file-card {
  display: flex; align-items: center; gap: 11px;
  margin: 1px 0 2px;
  padding: 9px 12px;
  min-width: 200px; max-width: 300px;
  background: var(--bg-3);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.msg-mine .file-card { background: rgba(4,36,31,.14); border-color: rgba(4,36,31,.2); }
.file-card:hover { border-color: var(--accent); }
.file-icon {
  width: 40px; height: 40px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft);
  border-radius: 10px;
  font-size: 20px;
}
.file-meta { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.file-name { font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-mine .file-name { color: var(--text-on-mine); }
.file-size { font-size: 11.5px; color: var(--text-dim); }
.msg-mine .file-size { color: rgba(4,36,31,.6); }

/* ---------- Media: audio / voice ---------- */
.media-voice, .media-audio {
  --prog: 0%;
  display: flex; align-items: center; gap: 10px;
  margin: 1px 0;
  padding: 4px 2px;
  min-width: 200px; max-width: 280px;
}
.voice-play {
  width: 38px; height: 38px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--text-on-accent);
  font-size: 13px;
  cursor: pointer;
  transition: transform var(--t-fast);
}
.msg-mine .voice-play { background: rgba(4,36,31,.85); color: var(--accent-strong); }
.voice-play:hover { transform: scale(1.06); }
.voice-mid { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.voice-wave {
  display: flex; align-items: center; gap: 2px;
  height: 26px;
}
.voice-wave span {
  flex: 1;
  min-width: 2px;
  background: var(--accent);
  opacity: .45;
  border-radius: 2px;
  transition: opacity var(--t-fast);
}
.msg-mine .voice-wave span { background: rgba(4,36,31,.7); }
.voice-dur { font-size: 11.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.msg-mine .voice-dur { color: rgba(4,36,31,.6); }

/* ---------- Upload placeholder bubble ---------- */
.upload-ph { min-width: 200px; }
.upload-ph-label { font-size: 13.5px; margin-bottom: 7px; color: var(--text-on-mine); }
.upload-ph-bar {
  height: 6px;
  background: rgba(4,36,31,.22);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.upload-ph-fill {
  height: 100%; width: 0%;
  background: rgba(4,36,31,.7);
  border-radius: var(--radius-pill);
  transition: width .18s ease;
}

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(2,6,9,.92);
  backdrop-filter: blur(6px);
  padding: 24px;
  animation: bubble-in .16s ease both;
}
.lightbox-body { max-width: 94vw; max-height: 90vh; }
.lightbox-img { max-width: 94vw; max-height: 90vh; border-radius: 10px; box-shadow: var(--shadow); }
.lightbox-close {
  position: absolute; top: 18px; right: 22px;
  width: 42px; height: 42px;
  border: none; border-radius: 50%;
  background: var(--bg-3); color: var(--text);
  font-size: 18px; cursor: pointer;
}
.lightbox-close:hover { background: var(--bg-hover); }

/* ---------- Composer: attach (+) + mic ---------- */
.attach-wrap { position: relative; flex: 0 0 auto; }
.composer-attach, .composer-mic {
  width: 44px; height: 44px;
  border-radius: var(--radius);
  color: var(--text-soft);
}
.composer-attach:hover, .composer-mic:hover { color: var(--accent-strong); background: var(--bg-hover); }
.attach-menu {
  position: absolute;
  bottom: 54px;
  left: 0;
  min-width: 172px;
  padding: 6px;
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  z-index: 30;
  animation: bubble-in .14s cubic-bezier(.2,.8,.2,1) both;
}
.attach-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%;
  padding: 10px 12px;
  border: none; background: transparent;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--t-fast);
}
.attach-item:hover { background: var(--bg-hover); color: var(--accent-strong); }
.attach-item svg { color: var(--accent); flex: 0 0 auto; }

/* ---------- Composer context (reply/edit preview) ---------- */
.composer-ctx {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px;
  background: var(--bg-2);
  border-top: 1px solid var(--hairline);
}
.composer-ctx-icon { color: var(--accent); flex: 0 0 auto; display: flex; }
.composer-ctx[data-mode="edit"] .composer-ctx-icon { color: var(--accent-strong); }
.composer-ctx-main { display: flex; flex-direction: column; min-width: 0; gap: 1px; flex: 1; border-left: 2px solid var(--accent); padding-left: 9px; }
.composer-ctx-title { font-size: 12.5px; font-weight: 700; color: var(--accent-strong); }
.composer-ctx-text {
  font-size: 13px; color: var(--text-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.composer-ctx-cancel { width: 34px; height: 34px; flex: 0 0 auto; }

/* ---------- Recording bar ---------- */
.recording-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
}
.rec-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--danger);
  animation: rec-blink 1s steps(2, start) infinite;
}
@keyframes rec-blink { 50% { opacity: .25; } }
.rec-label { font-size: 14px; color: var(--text); }
.rec-time { margin-left: auto; font-size: 14px; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.rec-cancel { width: 44px; height: 44px; color: var(--danger); }
.rec-send { width: 46px; height: 46px; padding: 0; border-radius: var(--radius); flex: 0 0 auto; }
.rec-send svg { transform: translateX(-1px); }

/* ---------- Drag & drop overlay ---------- */
.chat { position: relative; }
.chat.drag-over::after {
  content: "Eliberează pentru a trimite fișierul";
  position: absolute;
  inset: 12px;
  z-index: 40;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-brand);
  font-size: 17px; font-weight: 700;
  color: var(--accent-strong);
  background: rgba(13,19,26,.78);
  border: 2px dashed var(--accent);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(3px);
  pointer-events: none;
}

@media (max-width: 720px) {
  .media-image, .media-thumb { max-width: 240px; }
  .reply-quote-text { max-width: 200px; }
  .msg-actions { opacity: 1; transform: none; pointer-events: auto; } /* touch */
}

/* ==========================================================================
   WAVE-3 — groups, people, pagination, sync status, send reliability
   ========================================================================== */

/* ---------- Sync status chip (header) ---------- */
.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px 5px 9px;
  border-radius: var(--radius-pill);
  background: var(--bg-3);
  border: 1px solid var(--border-soft);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
  white-space: nowrap;
  transition: opacity var(--t), color var(--t-fast), border-color var(--t-fast);
}
.sync-status .sync-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex: 0 0 auto;
}
.sync-status.ok .sync-dot { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.sync-status.connecting .sync-dot { background: #e0b34a; animation: sync-pulse 1.1s ease-in-out infinite; }
.sync-status.offline .sync-dot { background: var(--danger); }
.sync-status.ok { color: var(--accent-strong); border-color: rgba(45,212,191,.22); }
.sync-status.offline { color: var(--danger); border-color: var(--danger-border); background: var(--danger-bg); }
/* When everything is fine, keep it quietly present. */
.sync-status.settled { opacity: .68; }
.sync-status.settled:hover { opacity: 1; }
@keyframes sync-pulse { 0%,100% { opacity: .4; } 50% { opacity: 1; } }

/* ---------- Sidebar tabs ---------- */
.sidebar-tabs {
  display: flex;
  gap: 4px;
  padding: 2px 12px 8px;
}
.sidebar-tab {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-soft);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.sidebar-tab:hover { background: var(--bg-hover); color: var(--text); }
.sidebar-tab.active {
  background: var(--bg-active);
  color: var(--accent-strong);
  box-shadow: inset 0 -2px 0 var(--accent);
}
.sidebar-pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* ---------- Group room item (list) ---------- */
.room-item .group-avatar-el {
  position: relative;
  background-size: cover;
  background-position: center;
}
.avatar.has-image { color: transparent; background-size: cover; background-position: center; }
.group-badge {
  position: absolute;
  right: -2px; bottom: -2px;
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 9px;
  border-radius: 50%;
  background: var(--bg-2);
  border: 1.5px solid var(--bg-2);
  line-height: 1;
}
.room-item.is-group .group-avatar-el .group-badge { box-shadow: 0 0 0 1px var(--border-soft); }

/* ---------- Clickable chat header (groups) ---------- */
.chat-head-room {
  border: none;
  background: transparent;
  text-align: left;
  cursor: default;
  padding: 6px 8px;
  margin: 0 -8px;
  border-radius: var(--radius-sm);
  font: inherit;
  color: inherit;
  transition: background var(--t-fast);
}
.chat-head-room.clickable { cursor: pointer; }
.chat-head-room.clickable:hover { background: var(--bg-hover); }
.chat-avatar.has-image { color: transparent; }

/* ---------- People list ---------- */
.people-search-row { display: flex; gap: 6px; padding: 4px 12px 8px; }
.people-search {
  flex: 1; min-width: 0;
  padding: 10px 13px;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.people-search::placeholder { color: var(--text-dim); }
.people-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.people-add-btn { flex: 0 0 auto; }

.people-list {
  list-style: none;
  margin: 0;
  padding: 0 8px 14px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.person-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--t-fast);
}
.person-row:hover { background: var(--bg-hover); }
.person-row .person-avatar { width: 42px; height: 42px; font-size: 16px; }
.person-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.person-name {
  font-size: 14.5px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.person-sub {
  font-size: 12px; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.person-action {
  flex: 0 0 auto;
  font-size: 12.5px; font-weight: 600;
  color: var(--accent-strong);
  opacity: 0;
  transition: opacity var(--t-fast);
}
.person-row:hover .person-action { opacity: 1; }
.people-empty { margin: 24px 16px; }
.people-loading {
  display: flex; align-items: center; gap: 8px;
  padding: 18px 14px; color: var(--text-soft); font-size: 13.5px;
}

/* ---------- Small spinner ---------- */
.spinner-sm {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Pagination spinner (timeline top) ---------- */
.pagination-spinner {
  align-self: center;
  display: flex; align-items: center; gap: 8px;
  margin: 10px 0 6px;
  padding: 6px 14px;
  font-size: 12.5px;
  color: var(--text-soft);
  background: rgba(13,19,26,.7);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
}

/* ---------- Create-group modal ---------- */
.group-name-row { display: flex; align-items: center; gap: 12px; margin: 4px 0 6px; }
.group-avatar-pick {
  flex: 0 0 auto;
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px dashed var(--border-soft);
  background: var(--bg-3);
  cursor: pointer;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.group-avatar-pick:hover { border-color: var(--accent); }
.group-avatar-preview {
  width: 52px; height: 52px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-dim);
  background-size: cover; background-position: center;
}
.group-avatar-preview.has-image { color: transparent; }
.group-name-row .modal-input { flex: 1; min-width: 0; }

.group-contacts { margin-top: 14px; }
.group-contacts-label { margin-bottom: 8px; }
.group-contacts-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.contact-pick {
  flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  width: 62px;
  padding: 4px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--t-fast);
}
.contact-pick:hover { background: var(--bg-hover); }
.contact-pick .contact-pick-avatar { width: 44px; height: 44px; font-size: 16px; }
.contact-pick-name {
  font-size: 11.5px; color: var(--text-soft);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.invitee-list {
  list-style: none; margin: 12px 0 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 8px;
}
.invitee-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: var(--radius-pill);
  background: var(--bg-3);
  border: 1px solid var(--border-soft);
}
.invitee-chip .invitee-avatar { width: 26px; height: 26px; font-size: 11px; }
.invitee-name {
  font-size: 13px; font-weight: 600; color: var(--text);
  max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.invitee-remove {
  width: 20px; height: 20px;
  border: none; background: transparent;
  color: var(--text-dim); cursor: pointer;
  font-size: 13px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--t-fast), color var(--t-fast);
}
.invitee-remove:hover { background: var(--danger-bg); color: var(--danger); }

/* ---------- Group info modal ---------- */
.gi-avatar-btn {
  position: relative;
  border: none; background: transparent; padding: 0; cursor: pointer;
}
.gi-avatar-btn.locked { cursor: default; }
.gi-avatar-btn .profile-avatar.has-image { color: transparent; background-size: cover; background-position: center; }
.gi-avatar-edit {
  position: absolute; right: -2px; bottom: -2px;
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--accent-deep);
  color: var(--text-on-accent);
  font-size: 11px;
  border: 2px solid var(--bg-2);
}
.gi-avatar-btn.locked .gi-avatar-edit { display: none; }

.gi-rename-row { margin-top: 14px; }
.gi-add-row { margin-top: 14px; }

.member-list {
  list-style: none; margin: 8px 0 0; padding: 0;
  max-height: 280px; overflow-y: auto;
}
.member-row {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--hairline);
}
.member-row:last-child { border-bottom: none; }
.member-row .member-avatar { width: 38px; height: 38px; font-size: 14px; }
.member-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.member-name {
  font-size: 14px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.member-sub { font-size: 11.5px; color: var(--text-dim); }
.admin-badge {
  flex: 0 0 auto;
  font-size: 10.5px; font-weight: 700; letter-spacing: .03em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-strong);
  border: 1px solid rgba(45,212,191,.22);
}
.member-kick {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  border: none; background: transparent;
  color: var(--text-dim); cursor: pointer;
  font-size: 13px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background var(--t-fast), color var(--t-fast);
}
.member-kick:hover { background: var(--danger-bg); color: var(--danger); }

.gi-actions { justify-content: stretch; }
.gi-leave-btn {
  width: 100%;
  color: var(--danger);
  border-color: var(--danger-border);
}
.gi-leave-btn:hover { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }

.add-person-results { max-height: 320px; padding: 8px 0 0; }

/* ---------- Send reliability (ticks + retry) ---------- */
.msg-tick.sending { opacity: .8; }
.msg-tick.failed { color: var(--danger); }
.msg-mine.msg-send-failed {
  border: 1px solid var(--danger-border);
}
.msg-retry {
  display: flex; gap: 8px;
  margin-top: 6px;
  justify-content: flex-end;
}
.msg-retry-btn, .msg-retry-cancel {
  font-family: var(--font-body);
  font-size: 12px; font-weight: 600;
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  border: 1px solid var(--border-soft);
  transition: background var(--t-fast), color var(--t-fast);
}
.msg-retry-btn {
  background: var(--accent-deep);
  color: var(--text-on-accent);
  border-color: transparent;
}
.msg-retry-btn:hover { filter: brightness(1.06); }
.msg-retry-cancel {
  background: transparent;
  color: var(--text-soft);
}
.msg-retry-cancel:hover { background: var(--bg-hover); color: var(--text); }

@media (max-width: 760px) {
  .sync-status-text { display: none; }
  .sync-status { padding: 7px; }
}

/* ==========================================================================
   WAVE-4 — Settings · Profile · Search · Chat organisation
   Matches the teal/ink design system above. All colours via design tokens.
   ========================================================================== */

/* ---------- Global sidebar search ---------- */
.global-search-row {
  position: relative;
  display: flex;
  align-items: center;
  margin: 2px 12px 4px;
}
.global-search-icon {
  position: absolute;
  left: 12px;
  display: inline-flex;
  color: var(--text-dim);
  pointer-events: none;
}
.global-search {
  width: 100%;
  padding: 10px 34px 10px 36px;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.global-search::placeholder { color: var(--text-dim); }
.global-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.global-search-clear {
  position: absolute;
  right: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.global-search-clear:hover { background: var(--bg-hover); color: var(--text); }

.global-search-results {
  list-style: none;
  margin: 0;
  padding: 0 8px 10px;
}
.global-search-head {
  padding: 10px 8px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.global-person { border-radius: var(--radius-sm); }

/* ---------- Filter chips (folders feel) ---------- */
.filter-bar {
  display: flex;
  gap: 6px;
  padding: 2px 12px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip {
  flex: 0 0 auto;
  padding: 6px 13px;
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-soft);
  background: var(--bg-3);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.filter-chip:hover { background: var(--bg-hover); color: var(--text); }
.filter-chip.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: transparent;
  box-shadow: inset 0 0 0 1px var(--accent-glow);
}

/* ---------- Room item: flags + ⋯ menu ---------- */
.room-item-row { align-items: center; }
.room-flag {
  flex: 0 0 auto;
  font-size: 11px;
  margin-right: 4px;
  opacity: .85;
  line-height: 1;
}
.room-item.is-pinned { background: linear-gradient(90deg, var(--accent-soft), transparent 60%); }
.room-item.is-pinned:hover { background: var(--bg-hover); }
.room-item.is-muted .room-item-name { color: var(--text-soft); }
.room-item-badge.muted-badge {
  background: var(--text-dim);
  color: var(--bg);
  box-shadow: none;
}

.room-item-menu {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  color: var(--text-soft);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--t-fast), background var(--t-fast), color var(--t-fast);
}
.room-item:hover .room-item-menu { opacity: 1; }
.room-item-menu:hover { background: var(--bg-active); color: var(--accent-strong); }
@media (hover: none) {
  .room-item-menu { opacity: .6; background: transparent; }
}

/* ---------- Room context menu (pin/mute/archive/block) ---------- */
.room-menu {
  position: fixed;
  z-index: 130;
  min-width: 200px;
  padding: 6px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  animation: modal-in .14s cubic-bezier(.2, .8, .2, 1) both;
}
.room-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.room-menu-item:hover { background: var(--bg-hover); }
.room-menu-item.danger { color: var(--danger); }
.room-menu-item.danger:hover { background: var(--danger-bg); }

/* ---------- Settings gear button ---------- */
#btn-settings:hover { background: var(--bg-hover); color: var(--accent-strong); }

/* ---------- Profile: avatar pick + bio ---------- */
.profile-avatar-btn {
  position: relative;
  flex: 0 0 auto;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: var(--radius-pill);
  line-height: 0;
}
.profile-avatar-btn .profile-avatar.has-image {
  color: transparent;
  background-size: cover;
  background-position: center;
}
.profile-avatar-edit {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-on-accent);
  background: linear-gradient(180deg, var(--accent-strong), var(--accent-deep));
  border: 2px solid var(--bg-2);
  border-radius: var(--radius-pill);
}
.profile-avatar-remove {
  align-self: flex-start;
  margin-top: 2px;
  padding: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: color var(--t-fast);
}
.profile-avatar-remove:hover { color: var(--danger); }
.profile-foot { justify-content: flex-start; margin-top: 20px; }
.profile-foot .btn { padding: 9px 14px; font-size: 13.5px; }

/* ---------- Settings modal ---------- */
.modal-settings {
  max-width: 480px;
  max-height: min(86vh, 760px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-settings .modal-head { flex: 0 0 auto; }
.settings-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin: 0 -4px;
  padding: 0 4px;
}
.settings-section {
  padding: 14px 0;
  border-top: 1px solid var(--hairline);
}
.settings-section:first-of-type { border-top: none; }

.settings-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 0;
}
.settings-row-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.settings-row-title { font-size: 14px; font-weight: 600; color: var(--text); }
.settings-row-sub { font-size: 12.5px; color: var(--text-dim); }

.settings-note {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-soft);
}
.settings-note-lock { display: flex; gap: 8px; }

.settings-foot { flex: 0 0 auto; justify-content: center; margin-top: 6px; padding-top: 14px; border-top: 1px solid var(--hairline); }
.settings-logout-btn { color: var(--danger); border-color: var(--danger-border); }
.settings-logout-btn:hover { background: var(--danger-bg); color: var(--danger); }

/* ---------- Toggle switch ---------- */
.switch {
  flex: 0 0 auto;
  position: relative;
  width: 46px;
  height: 26px;
  border-radius: var(--radius-pill);
  background: var(--bg-3);
  border: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-pill);
  background: var(--text-soft);
  box-shadow: var(--shadow-sm);
  transition: transform var(--t), background var(--t);
}
.switch.on {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent-deep));
  border-color: transparent;
}
.switch.on .switch-knob { transform: translateX(20px); background: #fff; }

/* ---------- Theme chips ---------- */
.theme-row { display: flex; gap: 10px; margin-top: 8px; }
.theme-chip {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  background: var(--bg-3);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  color: var(--text-soft);
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast), color var(--t-fast);
}
.theme-chip:hover { background: var(--bg-hover); color: var(--text); }
.theme-chip.active {
  border-color: var(--accent);
  color: var(--accent-strong);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.theme-swatch {
  width: 100%;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--hairline);
}
.theme-swatch-dark { background: linear-gradient(135deg, #0b0f14 50%, #14b8a6 50%); }
.theme-swatch-midnight { background: linear-gradient(135deg, #05080c 50%, #2dd4bf 50%); }
.theme-swatch-light { background: linear-gradient(135deg, #eef2f6 50%, #14b8a6 50%); }

/* ---------- Blocked users list ---------- */
.blocked-list { list-style: none; margin: 8px 0 0; padding: 0; }
.blocked-empty { color: var(--text-dim); font-size: 13.5px; padding: 6px 2px; }
.blocked-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 2px;
}
.blocked-avatar { width: 38px; height: 38px; font-size: 14px; }
.blocked-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.blocked-name { font-size: 14px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.blocked-sub { font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.blocked-unblock { flex: 0 0 auto; }

/* ---------- Encryption info block ---------- */
.enc-info { margin: 10px 0 0; }
.enc-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-top: 1px solid var(--hairline);
}
.enc-row:first-child { border-top: none; }
.enc-row dt { color: var(--text-dim); font-size: 12.5px; }
.enc-row dd {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-soft);
  text-align: right;
  word-break: break-all;
  font-family: var(--font-body);
}
.enc-fp { font-feature-settings: "tnum"; letter-spacing: .02em; }

/* ---------- In-chat message search bar ---------- */
.chat-search-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--hairline);
  z-index: 4;
  animation: modal-in .16s cubic-bezier(.2, .8, .2, 1) both;
}
.chat-search-icon { display: inline-flex; color: var(--text-dim); margin-left: 4px; }
.chat-search-input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.chat-search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.chat-search-count {
  flex: 0 0 auto;
  min-width: 56px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-dim);
}
.chat-search-nav { width: 34px; height: 34px; }
.chat-search-nav:hover { background: var(--bg-hover); color: var(--text); }

/* Search hit highlighting in the timeline */
.msg-row.search-hit .msg,
.msg-row.search-hit .msg-mine {
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.msg-row.search-current .msg,
.msg-row.search-current .msg-mine {
  box-shadow: 0 0 0 2px var(--accent);
  animation: search-pulse .9s ease;
}
@keyframes search-pulse {
  0% { box-shadow: 0 0 0 6px var(--accent-glow); }
  100% { box-shadow: 0 0 0 2px var(--accent); }
}

/* ==========================================================================
   THEMES — applied via [data-theme] on <html>. Default (no attr) = Ink.
   Only override design tokens so every component re-themes automatically.
   ========================================================================== */
:root[data-theme="midnight"] {
  --bg:        #04070b;
  --bg-1:      #05090d;
  --bg-2:      #090f15;
  --bg-3:      #0e1620;
  --bg-hover:  #121d28;
  --bg-active: #0c211c;
  --border:    #02050a;
  --border-soft: #16222e;
}

:root[data-theme="light"] {
  --bg:            #eef2f6;
  --bg-1:          #f5f8fb;
  --bg-2:          #ffffff;
  --bg-3:          #eef3f8;
  --bg-hover:      #e6edf3;
  --bg-active:     #d8f1ec;

  --bubble-in:        #ffffff;
  --bubble-in-border: #d8e1ea;
  --bubble-mine:      #14b8a6;
  --bubble-mine-2:    #0f9d8f;
  --bubble-mine-soft: rgba(20, 184, 166, .12);

  --text:          #0d1b26;
  --text-soft:     #44586a;
  --text-dim:      #7d909f;
  --text-on-accent:#04201c;
  --text-on-mine:  #ffffff;

  --accent:        #0f9d8f;
  --accent-strong: #14b8a6;
  --accent-deep:   #0d9488;
  --accent-press:  #0b7d72;
  --accent-glow:   rgba(15, 157, 143, .20);
  --accent-soft:   rgba(15, 157, 143, .10);

  --danger:        #d9534f;
  --danger-bg:     #fdeceb;
  --danger-border: rgba(217, 83, 79, .32);

  --border:        #d3dde6;
  --border-soft:   #dde5ec;
  --hairline:      rgba(13, 27, 38, .06);
  --shadow:        0 18px 48px -16px rgba(13, 27, 38, .22);
  --shadow-sm:     0 1px 2px rgba(13, 27, 38, .12);
  --shadow-pop:    0 24px 64px -18px rgba(13, 27, 38, .28), 0 0 0 1px var(--border-soft);

  color-scheme: light;
}
:root[data-theme="light"] body { color: var(--text); }
:root[data-theme="light"] .msg-mine .msg-body,
:root[data-theme="light"] .msg-mine .msg-time { color: var(--text-on-mine); }

/* ---------- Mobile tweaks ---------- */
@media (max-width: 760px) {
  .room-menu { min-width: 56vw; }
  .modal-settings { max-height: 92vh; }
  .theme-name { font-size: 11.5px; }
}

/* ==========================================================================
   WAVE-5 — stickers + custom emoji (MSC2545)
   ========================================================================== */

/* ---------- Composer emoji + sticker buttons ---------- */
.composer-emoji, .composer-sticker {
  width: 44px; height: 44px;
  border-radius: var(--radius);
  color: var(--text-soft);
  flex: 0 0 auto;
}
.composer-emoji:hover, .composer-sticker:hover {
  color: var(--accent-strong);
  background: var(--bg-hover);
}
.composer-emoji.active, .composer-sticker.active { color: var(--accent-strong); background: var(--bg-active); }

/* ---------- Inline custom emoji (in message bubbles) ---------- */
.inline-emoji {
  display: inline-block;
  width: 1.45em;
  height: 1.45em;
  vertical-align: -0.32em;
  margin: 0 1px;
  object-fit: contain;
}

/* ---------- Sticker bubble (received / sent) ---------- */
.msg-sticker .msg-body { background: transparent !important; }
.msg-sticker.msg, .msg-sticker.msg-mine {
  background: transparent !important;
  box-shadow: none !important;
  border: none !important;
  padding: 2px 0 0 !important;
}
.media-sticker {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 180px;
  max-height: 180px;
}
.sticker-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: auto;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,.35));
  animation: bubble-in .16s cubic-bezier(.2,.8,.2,1) both;
}
.sticker-lottie { display: block; }
.sticker-loading {
  font-size: 22px;
  color: var(--text-dim);
}
.sticker-static-fallback {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  font-size: 13px; color: var(--text-soft);
  background: var(--bg-3);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  text-align: center;
  padding: 8px;
}

/* ---------- Floating panels shared base (emoji panel + sticker tray) ---------- */
.emoji-panel, .sticker-tray {
  width: 348px;
  max-width: calc(100vw - 24px);
  background: var(--bg-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  z-index: 60;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: bubble-in .16s cubic-bezier(.2,.8,.2,1) both;
}

/* ---------- Emoji panel ---------- */
.emoji-panel { height: 360px; }
.emoji-panel-reaction { width: 320px; height: 320px; }
.emoji-search-wrap { padding: 10px 10px 6px; }
.emoji-search {
  width: 100%;
  padding: 9px 13px;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.emoji-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.emoji-search::placeholder { color: var(--text-dim); }

.emoji-tabs {
  display: flex;
  gap: 2px;
  padding: 4px 8px;
  overflow-x: auto;
  border-bottom: 1px solid var(--hairline);
  scrollbar-width: none;
}
.emoji-tabs::-webkit-scrollbar { display: none; }
.emoji-tab {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border: none; background: transparent;
  border-radius: var(--radius-sm);
  font-size: 18px; line-height: 1;
  cursor: pointer;
  opacity: .62;
  transition: background var(--t-fast), opacity var(--t-fast);
}
.emoji-tab:hover { background: var(--bg-hover); opacity: 1; }
.emoji-tab.active { background: var(--accent-soft); opacity: 1; box-shadow: inset 0 -2px 0 var(--accent); }

.emoji-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 1px;
  padding: 8px;
  align-content: start;
}
.emoji-cell {
  width: 100%;
  aspect-ratio: 1;
  border: none; background: transparent;
  border-radius: var(--radius-sm);
  font-size: 22px; line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t-fast), transform var(--t-fast);
}
.emoji-cell:hover { background: var(--bg-hover); transform: scale(1.18); }
.emoji-cell-custom img { width: 26px; height: 26px; object-fit: contain; }
.emoji-empty {
  grid-column: 1 / -1;
  padding: 24px 12px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* ---------- Sticker tray ---------- */
.sticker-tray { height: 380px; }
.sticker-head {
  display: flex; align-items: center;
  padding: 11px 14px 8px;
  border-bottom: 1px solid var(--hairline);
}
.sticker-head-title {
  font-family: var(--font-brand);
  font-size: 14px; font-weight: 700;
  color: var(--text);
}
.sticker-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 10px;
  align-content: start;
}
.sticker-cell {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid transparent;
  background: var(--bg-3);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 6px;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t-fast), transform var(--t-fast), border-color var(--t-fast);
}
.sticker-cell:hover { background: var(--bg-hover); border-color: var(--border-soft); transform: scale(1.06); }
.sticker-cell img { width: 100%; height: 100%; object-fit: contain; }
.sticker-empty {
  grid-column: 1 / -1;
  padding: 30px 12px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}
.sticker-tabs {
  display: flex;
  gap: 3px;
  padding: 6px 8px;
  overflow-x: auto;
  border-top: 1px solid var(--hairline);
  background: var(--bg-2);
  scrollbar-width: none;
}
.sticker-tabs::-webkit-scrollbar { display: none; }
.sticker-tab {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border: none; background: transparent;
  border-radius: var(--radius-sm);
  font-size: 19px; line-height: 1;
  cursor: pointer;
  opacity: .6;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t-fast), opacity var(--t-fast);
}
.sticker-tab:hover { background: var(--bg-hover); opacity: 1; }
.sticker-tab.active { background: var(--accent-soft); opacity: 1; box-shadow: inset 0 -2px 0 var(--accent); }
.sticker-tab img { width: 26px; height: 26px; object-fit: contain; border-radius: 6px; }

/* "+" in the quick reaction picker */
.reaction-more { font-size: 22px; color: var(--text-soft); font-weight: 400; }
.reaction-more:hover { color: var(--accent-strong); }

@media (max-width: 720px) {
  .emoji-panel, .sticker-tray { width: calc(100vw - 24px); }
  .media-sticker { max-width: 150px; max-height: 150px; }
}

/* ==========================================================================
   MESSAGING CORE — pin bar, forward, formatting (spoiler/links/code/quote),
   link previews, multi-select, drafts, jump highlight.
   ========================================================================== */

/* ---------- Pinned-messages bar (above the timeline) ---------- */
.pinned-bar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 12px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  box-shadow: inset 3px 0 0 var(--accent);
}
.pinned-bar-icon { color: var(--accent); flex: 0 0 auto; display: flex; }
.pinned-bar-main {
  flex: 1; min-width: 0;
  display: flex; align-items: center;
  border: none; background: transparent;
  cursor: pointer; text-align: left;
  padding: 0;
}
.pinned-bar-label { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.pinned-bar-head { font-size: 12px; font-weight: 700; color: var(--accent-strong); }
.pinned-bar-count { font-weight: 600; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.pinned-bar-text {
  font-size: 13px; color: var(--text-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pinned-bar-list-btn { width: 34px; height: 34px; flex: 0 0 auto; }

/* ---------- Pinned messages list (modal) ---------- */
.pinned-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 50vh; overflow-y: auto; }
.pinned-list-empty { padding: 18px 6px; text-align: center; color: var(--text-dim); font-size: 14px; }
.pinned-list-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--t-fast);
}
.pinned-list-item:hover { background: var(--bg-hover); }
.pinned-list-main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
  border: none; background: transparent; cursor: pointer; text-align: left; padding: 0;
}
.pinned-list-who { font-size: 12.5px; font-weight: 700; color: var(--accent-strong); }
.pinned-list-text {
  font-size: 13.5px; color: var(--text-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pinned-list-unpin { width: 30px; height: 30px; flex: 0 0 auto; font-size: 15px; }

/* ---------- Forwarded-from tag (above a bubble) ---------- */
.forward-tag {
  font-size: 12px; font-weight: 600;
  color: var(--accent-strong);
  margin: -1px 0 4px;
  opacity: .9;
}
.msg-mine .forward-tag { color: rgba(4,36,31,.78); }

/* ---------- Forward picker (modal) ---------- */
.forward-list { list-style: none; margin: 10px 0 0; padding: 0; max-height: 46vh; overflow-y: auto; }
.forward-empty { padding: 16px 6px; text-align: center; color: var(--text-dim); }
.forward-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--t-fast);
}
.forward-item:hover { background: var(--bg-hover); }
.forward-avatar { width: 36px; height: 36px; font-size: 14px; flex: 0 0 auto; }
.forward-item-name {
  flex: 1; min-width: 0; font-size: 14.5px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.forward-send-btn { flex: 0 0 auto; }

/* ---------- Multi-select ---------- */
.msg-select-check {
  position: absolute;
  left: -2px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px;
  border: 2px solid var(--border-soft);
  border-radius: 50%;
  background: var(--bg-3);
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast);
  z-index: 5;
}
.msg-row.selectable { cursor: pointer; padding-left: 30px; border-radius: 10px; transition: background var(--t-fast); }
.msg-row.selectable:hover { background: var(--accent-soft); }
.msg-row.selected { background: var(--accent-soft); }
.msg-row.selected .msg-select-check {
  background: var(--accent);
  border-color: var(--accent);
}
.msg-row.selected .msg-select-check::after {
  content: "✓";
  display: flex; align-items: center; justify-content: center;
  height: 100%;
  color: #04241f; font-size: 13px; font-weight: 800;
}
/* While selecting, suppress the hover action toolbar and hide the composer +
   reply/edit context bar (the selection bar takes their place). */
body.selecting .msg-actions { display: none; }
body.selecting .composer { display: none; }
body.selecting .composer-ctx { display: none; }

.selection-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
}
.sel-cancel { width: 34px; height: 34px; flex: 0 0 auto; }
.selection-count { font-size: 14px; font-weight: 600; color: var(--text); flex: 1; }
.selection-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.sel-delete { color: var(--danger); border-color: var(--danger-border); }
.sel-delete:hover { background: var(--danger-bg); color: var(--danger); }

/* ---------- Draft indicator in the room list ---------- */
.room-item-draft { color: var(--danger); font-weight: 600; }

/* ---------- Rich text formatting inside bubbles ---------- */
.msg-body strong { font-weight: 700; }
.msg-body em { font-style: italic; }
.msg-body del { text-decoration: line-through; opacity: .8; }
.msg-body code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .88em;
  background: rgba(127,127,127,.18);
  padding: 1px 5px;
  border-radius: 5px;
}
.msg-mine .msg-body code { background: rgba(4,36,31,.22); }
.msg-body pre {
  margin: 5px 0;
  padding: 9px 11px;
  background: rgba(127,127,127,.16);
  border-radius: 9px;
  overflow-x: auto;
}
.msg-mine .msg-body pre { background: rgba(4,36,31,.2); }
.msg-body pre code { background: transparent; padding: 0; font-size: .85em; }
.msg-body blockquote {
  margin: 4px 0;
  padding: 2px 0 2px 10px;
  border-left: 3px solid var(--accent);
  color: var(--text-soft);
}
.msg-mine .msg-body blockquote { border-left-color: rgba(4,36,31,.5); color: rgba(4,36,31,.8); }
.msg-link { color: var(--accent-strong); text-decoration: underline; word-break: break-word; }
.msg-mine .msg-link { color: #04241f; }

/* Spoiler — tap to reveal */
.spoiler {
  background: var(--text-dim);
  color: transparent;
  border-radius: 5px;
  padding: 0 3px;
  cursor: pointer;
  user-select: none;
  transition: color var(--t-fast), background var(--t-fast);
}
.spoiler::selection { background: transparent; }
.msg-mine .spoiler { background: rgba(4,36,31,.55); }
.spoiler.revealed {
  background: rgba(127,127,127,.15);
  color: inherit;
  cursor: text;
  user-select: text;
}

/* ---------- Link preview card (below a bubble) ---------- */
.link-preview {
  display: flex;
  margin-top: 7px;
  border-left: 3px solid var(--accent);
  background: rgba(45,212,191,.07);
  border-radius: 8px;
  overflow: hidden;
  text-decoration: none;
  max-width: 340px;
  transition: background var(--t-fast);
}
.link-preview:hover { background: rgba(45,212,191,.12); }
.msg-mine .link-preview { border-left-color: rgba(4,36,31,.5); background: rgba(4,36,31,.12); }
.link-preview-img {
  width: 64px; height: 64px;
  object-fit: cover;
  flex: 0 0 auto;
}
.link-preview-main {
  display: flex; flex-direction: column; gap: 2px;
  padding: 7px 10px;
  min-width: 0;
}
.link-preview-site { font-size: 11px; font-weight: 700; color: var(--accent-strong); text-transform: none; }
.msg-mine .link-preview-site { color: rgba(4,36,31,.85); }
.link-preview-title {
  font-size: 13px; font-weight: 600; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.msg-mine .link-preview-title { color: #04241f; }
.link-preview-desc {
  font-size: 12px; color: var(--text-soft);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.msg-mine .link-preview-desc { color: rgba(4,36,31,.72); }

@media (max-width: 720px) {
  .pinned-bar-list-btn { width: 30px; height: 30px; }
  .selection-actions .btn-sm { padding: 7px 10px; font-size: 12.5px; }
  .link-preview { max-width: 240px; }
  /* On touch the action toolbar is always visible (see base rule); pin button
     fits because the bar wraps naturally. */
}
