/* UI.CSS LAST BUILD: 2026-01-20 13:15:00 - WhatsApp-style premium chat UI with comprehensive token system */


/* ========================================
   GLOBAL MODERN THIN SCROLLBARS
   Applied to all scrollable containers to prevent flash on container switch
   ======================================== */
* {
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: var(--scrollbar-thumb) transparent;
}
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
  background-clip: padding-box;
}

:root {
  /* Default = Dark mode (recommended palette) */
  --bg: #021622;
  --surface: #032437;
  --surface-alt: #062C3F;
  --border: #0A374A;
  --text: #E8F4F7;
  --muted: #A7C4CF;

  --primary: #3DBFD2;
  --primary-hover: #5AC9D9;
  --primary-active: #34A2B2;
  --on-primary: #021622;

  --secondary: #043754;
  --secondary-hover: #2A556E;
  --secondary-active: #032F47;
  --on-secondary: #E8F4F7;

  --link: #70D6E1;
  --danger: #EF4444;

  /* Subtle background glow (per theme) */
  --bg-glow: #0437542e;

  /* Theme-driven component tokens */
  --bubble-me-bg: var(--primary);
  --bubble-other-bg: #1f2c33;
  --bubble-me-text: #021622;
  --bubble-other-text: var(--text);

  /* Component-specific alpha colors (for hovers, overlays, etc.) */
  --hover-overlay: rgba(6, 44, 63, 0.45);
  --hover-overlay-strong: rgba(6, 44, 63, 0.85);
  --hover-overlay-light: rgba(6, 44, 63, 0.25);
  --active-overlay: rgba(61, 191, 210, 0.14);
  --focus-ring: rgba(61, 191, 210, 0.18);
  
  /* Chat messages background pattern overlay */
  --messages-bg-overlay: rgba(2, 22, 34, 0.92);
  
  /* Avatar status dot */
  --avatar-online: #22c55e;
  --avatar-offline: rgba(168, 190, 201, 0.9);
  
  /* Scrollbar (WebKit) */
  --scrollbar-thumb: rgba(112, 214, 225, 0.35);
  --scrollbar-thumb-hover: rgba(112, 214, 225, 0.55);

  /* Input pill & Popovers (NEW) */
  --input-pill-bg: rgba(6, 44, 63, 0.72);
  --input-pill-border: rgba(61, 191, 210, 0.18);
  --popover-bg: rgba(3, 36, 55, 0.96);
  --popover-border: rgba(61, 191, 210, 0.22);
  --card-bg: rgba(12, 47, 69, 0.62);
  --card-border: rgba(127, 169, 187, 0.22);

  /* Hover buttons & menu items (NEW) */
  --button-menu-bg: rgba(3, 36, 55, 0.85);
  --button-menu-hover: rgba(6, 44, 63, 0.92);
  --button-menu-border: rgba(61, 191, 210, 0.18);
  --button-secondary-bg: rgba(6, 44, 63, 0.45);
  --avatar-gradient-start: rgba(4, 55, 116, 0.35);
  --avatar-gradient-end: rgba(61, 191, 210, 0.35);

  /* Additional component tokens (NEW) */
  --drawer-item-bg: rgba(6, 44, 63, 0.22);
  --drawer-item-hover: rgba(6, 44, 63, 0.34);
  --drawer-item-border: rgba(61, 191, 210, 0.16);
  --empty-state-bg: rgba(12, 47, 69, 0.45);
  --empty-state-border: rgba(127, 169, 187, 0.22);
  --under-bubble-bg: rgba(3, 36, 55, 0.92);
  --under-bubble-border: rgba(61, 191, 210, 0.18);
  --drawer-member-bg: rgba(6, 44, 63, 0.30);
  --drawer-member-border: rgba(61, 191, 210, 0.12);
  --tab-active-border: var(--primary);
  --bubble-me-text-color: #021622;

  /* Welcome hero gradient (theme-adaptive) */
  --welcome-glow-1: rgba(61, 191, 210, 0.24);
  --welcome-glow-2: rgba(127, 169, 187, 0.12);
}

:root {
  /* Safe area defaults for WebView/mobile (overridable via JS injection) */
  --safe-area-top: 0px; /* default to no top inset */
  --safe-area-right: 0px;
  --safe-area-bottom: 0px;
  --safe-area-left: 0px;
  /* Runtime keyboard height (set via visualViewport) */
  --kb: 0px;
  /* Apply a minimal fallback (44px) to avoid status-bar overlap if JS/env fails;
     RN WebView can override by setting --safe-area-top via injected JS. */
  --safe-top-effective: max(var(--safe-area-top), env(safe-area-inset-top, 0px));
}

/* Light mode (recommended palette) */
body[data-theme="light"] {
  --bg: #F5FBFD;
  --surface: #FFFFFF;
  --surface-alt: #EFFAFB;
  --border: #D7DFE4;
  --text: #06202C;
  --muted: #4F7387;

  --primary: #043754;
  --primary-hover: #032F47;
  --primary-active: #03263B;
  --on-primary: #FFFFFF;

  --secondary: #3DBFD2;
  --secondary-hover: #34A2B2;
  --secondary-active: #2B8693;
  /* IMPORTANT: do not use white on turquoise */
  --on-secondary: #043754;

  --link: #1E748D;
  --bg-glow: #3DBFD21a;

  /* Theme-driven component tokens */
  --bubble-me-bg: var(--secondary); /* outgoing bubble should stay turquoise in light mode */
  --bubble-other-bg: #ffffff;
  --bubble-me-text: #021622;
  --bubble-other-text: var(--text);

  /* Component-specific alpha colors (light mode) */
  --hover-overlay: rgba(255, 255, 255, 0.80);
  --hover-overlay-strong: rgba(239, 250, 251, 0.98);
  --hover-overlay-light: rgba(255, 255, 255, 0.70);
  --active-overlay: rgba(61, 191, 210, 0.18);
  --focus-ring: rgba(61, 191, 210, 0.18);
  
  /* Chat messages background pattern overlay */
  --messages-bg-overlay: rgba(245, 251, 253, 0.95);
  
  /* Avatar status dot */
  --avatar-online: #16a34a;
  --avatar-offline: rgba(79, 115, 135, 0.70);
  
  /* Scrollbar (WebKit) */
  --scrollbar-thumb: rgba(30, 116, 141, 0.30);
  --scrollbar-thumb-hover: rgba(30, 116, 141, 0.50);

  /* Input pill & Popovers (light mode) */
  --input-pill-bg: rgba(255, 255, 255, 0.90);
  --input-pill-border: rgba(215, 223, 228, 0.85);
  --popover-bg: rgba(255, 255, 255, 0.96);
  --popover-border: rgba(215, 223, 228, 0.90);
  --card-bg: rgba(255, 255, 255, 0.76);
  --card-border: rgba(6, 32, 44, 0.12);

  /* Hover buttons & menu items (light mode) */
  --button-menu-bg: rgba(255, 255, 255, 0.92);
  --button-menu-hover: rgba(239, 250, 251, 0.98);
  --button-menu-border: rgba(30, 116, 141, 0.18);
  --button-secondary-bg: rgba(255, 255, 255, 0.80);
  --avatar-gradient-start: rgba(4, 55, 116, 0.25);
  --avatar-gradient-end: rgba(61, 191, 210, 0.25);

  /* Additional component tokens (light mode) */
  --drawer-item-bg: rgba(255, 255, 255, 0.85);
  --drawer-item-hover: rgba(239, 250, 251, 0.92);
  --drawer-item-border: rgba(215, 223, 228, 0.85);
  --empty-state-bg: rgba(255, 255, 255, 0.78);
  --empty-state-border: rgba(6, 32, 44, 0.12);
  --under-bubble-bg: rgba(255, 255, 255, 0.94);
  --under-bubble-border: rgba(215, 223, 228, 0.85);
  --drawer-member-bg: rgba(255, 255, 255, 0.85);
  --drawer-member-border: rgba(215, 223, 228, 0.75);
  --tab-active-border: var(--primary);
  --bubble-me-text-color: #021622;

  /* Welcome hero gradient (light mode - softer glow) */
  --welcome-glow-1: rgba(61, 191, 210, 0.18);
  --welcome-glow-2: rgba(4, 55, 116, 0.08);
}

/* Light theme specific overrides for complex backgrounds */
body[data-theme="light"] .chat-shell {
  background: radial-gradient(1200px 700px at 20% 0%, var(--bg-glow), transparent), var(--bg);
}
body[data-theme="light"] .chat-sidebar {
  background: linear-gradient(180deg, var(--surface), var(--surface-alt));
}
body[data-theme="light"] .chat-main {
  background: var(--bg);
}
/* In light mode, toggles should blend into the floating-controls container */
body[data-theme="light"] .floating-toggle {
  background: transparent;
  box-shadow: none;
}
body[data-theme="light"] .msg.alert {
  background: var(--surface-alt);
}
body[data-theme="light"] .msg.alert.err {
  background: #fff5f5;
  border-color: #ffd2d2;
  color: #9b1c1c;
}
body[data-theme="light"] .msg.alert.ok {
  background: #f0fdfa;
  border-color: #a7f3d0;
  color: #065f46;
}
body[data-theme="light"] .msg.alert.info {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
}

/* Base */
body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: radial-gradient(1200px 700px at 20% 0%, var(--bg-glow), transparent), var(--bg);
  color: var(--text);
}

/* Layout helpers */
.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px;
}

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

.link {
  color: var(--link);
  text-decoration: none;
}
.link:hover { text-decoration: underline; }

/* Floating controls (top-right) — 5001 style */
.floating-controls {
  position: fixed;
  top: 3rem;
  right: 1rem;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem;
  border-radius: 0.625rem;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: all 0.2s ease;
  animation: floatIn 0.4s ease-out;
}

/* When mounted inside chat topbar, it should NOT be fixed */
.chat-topbar .floating-controls {
  position: static;
  top: auto;
  right: auto;
  z-index: auto;
  animation: none;
}

@keyframes floatIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.floating-toggle {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 0.5rem;
  background: transparent;
  border: 0;
  transition: background 0.15s ease;
}

.floating-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}

body[data-theme="light"] .floating-toggle:hover {
  background: rgba(0, 0, 0, 0.05);
}

.language-toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.language-toggle-icon {
  position: relative;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.language-toggle-icon span {
  position: absolute;
  font-size: 1.4rem;
  line-height: 1;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

/* TR shown by default (unchecked) */
.language-flag-tr { opacity: 1; transform: scale(1); }
.language-flag-en { opacity: 0; transform: scale(0.8); }

/* EN shown when checked */
.language-toggle-input:checked ~ .language-toggle-icon .language-flag-tr { opacity: 0; transform: scale(0.8); }
.language-toggle-input:checked ~ .language-toggle-icon .language-flag-en { opacity: 1; transform: scale(1); }

/* Theme toggle (FontAwesome icons) */
.theme-toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.theme-toggle-icon {
  position: relative;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle-icon i {
  position: absolute;
  font-size: 18px;
  transition: opacity 0.2s ease, transform 0.2s ease;
  color: rgba(255, 255, 255, 0.85);
}

body[data-theme="light"] .theme-toggle-icon i {
  color: rgba(6, 32, 44, 0.8);
}

/* Moon (dark) visible by default */
.theme-icon-dark {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}
.theme-icon-light {
  opacity: 0;
  transform: scale(0.8) rotate(90deg);
}

/* Sun (light) visible when checked */
.theme-toggle-input:checked ~ .theme-toggle-icon .theme-icon-dark {
  opacity: 0;
  transform: scale(0.8) rotate(-90deg);
}
.theme-toggle-input:checked ~ .theme-toggle-icon .theme-icon-light {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

/* Theme toggle (same floating style) */
.theme-toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.theme-toggle-icon {
  position: relative;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle-icon svg {
  position: absolute;
  width: 18px;
  height: 18px;
  transition: opacity 0.15s ease, transform 0.15s ease;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Dark icon shown by default (unchecked) */
.theme-icon-dark { opacity: 1; transform: scale(1); }
.theme-icon-light { opacity: 0; transform: scale(0.85); }

/* Light icon shown when checked */
.theme-toggle-input:checked ~ .theme-toggle-icon .theme-icon-dark { opacity: 0; transform: scale(0.85); }
.theme-toggle-input:checked ~ .theme-toggle-icon .theme-icon-light { opacity: 1; transform: scale(1); }

/* Login page */
.auth-shell {
  min-height: calc(100vh - var(--safe-area-top) - var(--safe-area-bottom));
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 28px;
  align-items: center;
  padding: calc(48px + var(--safe-area-top)) 0 calc(48px + var(--safe-area-bottom));
}

.auth-left {
  padding: 0 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.brand-logo {
  width: 50px;
  display: block;
  object-fit: contain;
}
.brand-logo-dark { display: block; }
.brand-logo-light { display: none; }
body[data-theme="light"] .brand-logo-dark { display: none; }
body[data-theme="light"] .brand-logo-light { display: block; }

.brand-meta{
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.brand-title{
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.01em;
  color: var(--text);
}
.brand-subtitle{
  font-size: 12px;
  color: var(--muted);
  line-height: 1.2;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 85%, var(--bg) 15%);
  color: var(--muted);
  font-size: 12px;
}

.kicker {
  display: inline-block;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 8px 0 8px;
}

.hero-title {
  font-size: 34px;
  line-height: 1.15;
  margin: 0 0 10px;
  letter-spacing: -0.02em;
}

.hero-subtitle {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
  max-width: 62ch;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 18px;
}

.info-card {
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--surface-alt) 88%, var(--bg) 12%),
    color-mix(in srgb, var(--surface) 88%, var(--bg) 12%)
  );
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}

.info-card h3 {
  margin: 0 0 8px;
  font-size: 13px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--text) 92%, var(--muted));
}

.info-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.auth-right {
  display: flex;
  justify-content: center;
}

/* Phone block collapses when OTP input is focused (mobile) */
.phone-block{
  overflow: hidden;
  transition: max-height 0.22s ease, opacity 0.2s ease, transform 0.2s ease;
  max-height: 420px;
  will-change: max-height, opacity, transform;
}
@media (max-width: 980px) {
  .login-card.code-focus .phone-block{
    max-height: 0px;
    opacity: 0;
    transform: translateY(-6px);
    pointer-events: none;
  }
}

.login-card {
  background: linear-gradient(180deg, var(--surface-alt), var(--surface));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 20px 80px #00000066;
  width: 100%;
  max-width: 440px;
}

.login-card h1 {
  font-size: 18px;
  margin: 0 0 6px;
}

.login-card p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.help {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}

.divider {
  height: 1px;
  background: var(--border);
  opacity: 0.6;
  margin: 14px 0;
}

.login-card label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 12px 0 6px;
}

.login-card input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, var(--bg) 12%);
  color: var(--text);
  outline: none;
}

.login-card input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 12%, transparent);
}

.login-card input.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px #ef44441f;
}

.row {
  display: flex;
  gap: 10px;
}
.row > * {
  flex: 1;
}

.btn, .btn2 {
  padding: 10px 12px;
  border-radius: 10px;
  border: 0;
  cursor: pointer;
  font-weight: 600;
}

.btn.sm, .btn2.sm {
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 12px;
}

.btn {
  background: var(--secondary);
  color: var(--on-secondary);
}
.btn:hover { background: var(--secondary-hover); }
.btn:active { background: var(--secondary-active); }

.btn2 {
  background: var(--primary);
  color: var(--on-primary);
}
.btn2:hover { background: var(--primary-hover); }
.btn2:active { background: var(--primary-active); }

/* Premium: Add Contact button (contacts toolbar) */
.btn2.btn-add-contact{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--primary) 28%, transparent);
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--primary) 92%, #ffffff) 0%,
    var(--primary) 100%
  );
  box-shadow:
    0 10px 22px rgba(0, 0, 0, 0.20),
    0 0 0 1px color-mix(in srgb, var(--primary) 20%, transparent);
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    filter 160ms ease,
    background 160ms ease;
}
.btn2.btn-add-contact i{
  font-size: 12px;
  opacity: 0.95;
}
.btn2.btn-add-contact:hover{
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--primary) 96%, #ffffff) 0%,
    var(--primary-hover) 100%
  );
  transform: translateY(-1px);
  box-shadow:
    0 14px 28px rgba(0, 0, 0, 0.24),
    0 0 0 1px color-mix(in srgb, var(--primary) 22%, transparent);
}
.btn2.btn-add-contact:active{
  transform: translateY(0px);
  filter: brightness(0.98);
}
.btn2.btn-add-contact:focus-visible{
  outline: none;
  box-shadow:
    0 14px 28px rgba(0, 0, 0, 0.22),
    0 0 0 3px color-mix(in srgb, var(--primary) 28%, transparent);
}

.btn:disabled, .btn2:disabled {
  opacity: .6;
  cursor: not-allowed;
}

.msg {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}

.msg.alert {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-alt) 88%, var(--bg) 12%);
}
.msg.alert.err {
  border-color: color-mix(in srgb, #ef4444 40%, var(--border));
  background: color-mix(in srgb, #ef4444 12%, var(--surface));
  color: color-mix(in srgb, #ffffff 88%, var(--text));
}
.msg.alert.ok {
  border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
  background: color-mix(in srgb, var(--primary) 10%, var(--surface));
  color: color-mix(in srgb, var(--on-primary) 80%, var(--text));
}
.msg.alert.info {
  border-color: color-mix(in srgb, var(--link) 40%, var(--border));
  background: color-mix(in srgb, var(--link) 12%, var(--surface));
  color: color-mix(in srgb, #ffffff 82%, var(--text));
}

@media (max-width: 980px) {
  .auth-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "left"
      "right"
      "bottom";
    align-items: end; /* keep the sign-in card near the top on mobile */
    padding: 18px 0 26px;
    gap: 18px;
  }
  .auth-right {
    justify-content: stretch;
    align-items: flex-start;
    align-self: start;
  }
  .login-card { max-width: none; }
  /* Mobile login: hide the info cards section */
  .auth-shell .info-grid { display: none; }
  .info-grid { grid-template-columns: 1fr; }
  .brand {
    display: block;
  }
  .brand-logo {
    width: 50px;
    margin-bottom: 8px;
  }
  .brand-meta {
    display: inline-flex;
    flex-direction: column;
    vertical-align: middle;
  }
  .brand-badge {
    display: inline-flex;
    vertical-align: middle;
    margin-left: 8px;
  }
  .hero-title { font-size: 28px; }
}

/* Chat page — WhatsApp-ish 3-column layout */
.chat-shell {
  height: 100vh;  /* fallback */
  height: 100dvh; /* mobile-safe viewport */
  min-height: 100dvh;
  display: grid;
  /* Responsive desktop widths: keep sidebar/drawer usable without wasting space */
  grid-template-columns: clamp(320px, 30vw, 420px) 1fr clamp(320px, 28vw, 420px);
  background: radial-gradient(1200px 700px at 20% 0%, var(--bg-glow), transparent), var(--bg);
  overflow: hidden; /* keep scrolling inside panels, not on the page */
}

.chat-shell.drawer-closed {
  grid-template-columns: clamp(320px, 30vw, 420px) 1fr;
}

.chat-drawer {
  border-left: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface), var(--surface-alt));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  transition: transform 0.2s ease;
  box-shadow: -14px 0 60px rgba(0,0,0,0.18);
}

.chat-shell.drawer-closed .chat-drawer {
  display: none;
}

/* Drawer scrim (tablet/mobile overlay) */
.drawer-scrim{
  position: fixed;
  inset: 0;
  background: rgba(2, 22, 34, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 45;
  display: none;
}
body[data-theme="light"] .drawer-scrim{
  background: rgba(6, 32, 44, 0.16);
}

.chat-drawer-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, var(--surface), var(--surface-alt));
  gap: 10px;
}

.chat-drawer-header .title {
  font-weight: 900;
  font-size: 15px;
  letter-spacing: -0.01em;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drawer-header-actions{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.icon-btn.drawer-leave-btn{
  color: color-mix(in srgb, var(--danger) 88%, var(--muted));
}
.icon-btn.drawer-leave-btn:hover{
  background: color-mix(in srgb, var(--danger) 10%, var(--surface-alt));
  color: var(--danger);
}

.chat-drawer-body {
  flex: 1;
  overflow: auto;
  padding: 14px;
  padding-bottom: calc(14px + var(--safe-area-bottom, 0px));
  -webkit-overflow-scrolling: touch;
}

/* Drawer: premium profile card */
.drawer-profile {
  /* Profile lives inside a section card; keep it clean (no double-card look) */
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
  box-shadow: none;
}

.drawer-contact-head {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 12px;
  align-items: center;
}

.drawer-avatar {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  background: radial-gradient(40px 40px at 30% 20%, rgba(61, 191, 210, 0.22), transparent),
    linear-gradient(135deg, #0A374A, var(--secondary));
  border: 1px solid rgba(61, 191, 210, 0.18);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
}

.drawer-contact-name {
  font-weight: 900;
  color: var(--text);
  font-size: 16px;
  line-height: 1.2;
}
.drawer-contact-title {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}
.drawer-contact-description {
  margin-top: 6px;
  color: var(--text);
  font-size: 12px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

.drawer-kv {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.drawer-kv .kv {
  display: grid;
  grid-template-columns: minmax(96px, 0.42fr) 1fr;
  gap: 10px;
  align-items: baseline;
}
.drawer-kv .k {
  color: var(--muted);
  font-size: 12px;
}
.drawer-kv .v {
  color: var(--text);
  font-size: 13px;
  overflow: hidden;
  word-break: break-word;
  white-space: normal;
  display: -webkit-box;
  line-clamp: 2;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.drawer-note {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: rgba(61, 191, 210, 0.04);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

body[data-theme="light"] .drawer-profile {
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.10);
}

.drawer-section {
  margin-bottom: 14px;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  border-radius: 16px;
  padding: 12px;
}

.drawer-section-title {
  font-size: 13px;
  font-weight: 900;
  color: var(--text);
  text-transform: none;
  letter-spacing: -0.01em;
  margin-bottom: 10px;
}

/* Drawer: Media & Files */
.drawer-media-loading{
  color: var(--muted);
  font-size: 13px;
}
.drawer-media-grid{
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.drawer-media-thumb{
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  border: 1px solid var(--button-menu-border);
  background: var(--hover-overlay-light);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(0,0,0,0.22);
  overflow: hidden;
  position: relative;
}
.drawer-media-thumb i{ font-size: 16px; opacity: 0.9; }
.drawer-media-thumb:hover{ background: var(--hover-overlay); }
.drawer-media-img{
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.drawer-files{
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.drawer-file-row{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 14px;
  border: 1px solid rgba(61,191,210,0.14);
  background: rgba(6, 44, 63, 0.25);
}
body[data-theme="light"] .drawer-file-row{
  background: rgba(255,255,255,0.88);
  border-color: rgba(215,223,228,0.75);
}
.drawer-file-row .ico{
  width: 34px;
  height: 34px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(61,191,210,0.14);
  border: 1px solid rgba(61,191,210,0.20);
  flex: 0 0 auto;
}
.drawer-file-row .ico i{ font-size: 14px; }
.drawer-file-row .meta{ min-width: 0; flex: 1; }
.drawer-file-row .name{
  font-weight: 800;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drawer-file-row .sub{
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.drawer-file-row .actions{
  display: flex;
  gap: 6px;
  align-items: center;
  flex: 0 0 auto;
}
.icon-btn.sm{
  width: 30px;
  height: 30px;
  border-radius: 12px;
}

/* Drawer: Group members list (Group Info) */
.drawer-group-members{
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(6, 44, 63, 0.18);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: rgba(127, 169, 187, 0.45) transparent;
}

/* Drawer: Group member search/filter */
.drawer-group-member-controls{
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.drawer-input-wrap{
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--input-pill-border);
  background: var(--input-pill-bg);
}
.drawer-input-wrap i{
  color: var(--muted);
  font-size: 13px;
}
.drawer-input-wrap input{
  width: 100%;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-weight: 800;
  font-size: 13px;
}
body[data-theme="light"] .drawer-input-wrap{
  background: rgba(255,255,255,0.80);
}
@media (max-width: 520px){
  .drawer-group-member-controls{
    flex-direction: column;
    align-items: stretch;
  }
  .drawer-group-member-controls .widget-select{
    width: 100%;
  }
}
body[data-theme="light"] .drawer-group-members{
  background: rgba(255,255,255,0.70);
  scrollbar-color: rgba(79, 115, 135, 0.42) transparent;
}
.drawer-group-members::-webkit-scrollbar{ width: 8px; }
.drawer-group-members::-webkit-scrollbar-track{ background: transparent; }
.drawer-group-members::-webkit-scrollbar-thumb{
  background: rgba(127, 169, 187, 0.32);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.drawer-group-members::-webkit-scrollbar-thumb:hover{
  background: rgba(127, 169, 187, 0.55);
  background-clip: padding-box;
}
body[data-theme="light"] .drawer-group-members::-webkit-scrollbar-thumb{
  background: rgba(79, 115, 135, 0.26);
  background-clip: padding-box;
}
body[data-theme="light"] .drawer-group-members::-webkit-scrollbar-thumb:hover{
  background: rgba(79, 115, 135, 0.44);
  background-clip: padding-box;
}

.drawer-member{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--drawer-member-border);
  background: var(--drawer-member-bg);
}
.drawer-member-avatar{
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  color: var(--text);
  background: rgba(61,191,210,0.14);
  border: 1px solid rgba(61,191,210,0.22);
  flex: 0 0 auto;
}
.drawer-member-meta{ min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.drawer-member-name{ display:flex; align-items:center; gap: 8px; min-width: 0; }
.drawer-member-name-text{ font-weight: 800; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-member-sub{ font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-member-badge{
  font-size: 11px;
  font-weight: 900;
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--text);
  background: rgba(61,191,210,0.16);
  border: 1px solid rgba(61,191,210,0.18);
  flex: 0 0 auto;
}
.drawer-member-actions{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}
.drawer-member-actions .btn2.sm,
.drawer-member-actions .btn.sm{
  padding: 6px 10px;
  height: 30px;
  border-radius: 12px;
}
.drawer-members-loading{
  padding: 10px 8px;
  color: var(--muted);
  font-size: 13px;
}

/* Drawer: Group summary + activity */
.drawer-group-summary{
  padding: 10px 10px;
  border-radius: 14px;
  border: 1px solid rgba(127, 169, 187, 0.18);
  background: rgba(12, 47, 69, 0.24);
  margin-bottom: 12px;
}
body[data-theme="light"] .drawer-group-summary{
  background: rgba(255,255,255,0.78);
  border-color: rgba(215,223,228,0.75);
}

.drawer-group-notifications{
  margin-bottom: 12px;
}
.drawer-notify-row{
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.drawer-select{
  width: 100%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(127, 169, 187, 0.18);
  background: rgba(6, 44, 63, 0.18);
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
}
body[data-theme="light"] .drawer-select{
  background: rgba(255,255,255,0.78);
  border-color: rgba(215,223,228,0.75);
}
.drawer-mute-actions{
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.drawer-mute-status{
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.drawer-group-about{
  margin-bottom: 12px;
}
.drawer-about-text{
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(127, 169, 187, 0.18);
  background: rgba(6, 44, 63, 0.18);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}
body[data-theme="light"] .drawer-about-text{
  background: rgba(255,255,255,0.78);
  border-color: rgba(215,223,228,0.75);
}
.drawer-about-actions{
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

.drawer-group-pinned{
  margin-bottom: 12px;
}
.drawer-pinned-card{
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(127, 169, 187, 0.18);
  background: rgba(6, 44, 63, 0.18);
}
body[data-theme="light"] .drawer-pinned-card{
  background: rgba(255,255,255,0.78);
  border-color: rgba(215,223,228,0.75);
}
.drawer-pinned-text{
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drawer-pinned-actions{
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.drawer-group-activity{
  margin-bottom: 14px;
}
.drawer-activity-list{
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.drawer-activity-item{
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(127, 169, 187, 0.16);
  background: rgba(6, 44, 63, 0.18);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}
body[data-theme="light"] .drawer-activity-item{
  background: rgba(255,255,255,0.70);
  border-color: rgba(215,223,228,0.75);
}
.drawer-activity-item:hover{
  transform: translateY(-1px);
  background: rgba(6, 44, 63, 0.26);
  border-color: rgba(127, 169, 187, 0.26);
}
body[data-theme="light"] .drawer-activity-item:hover{
  background: rgba(255,255,255,0.88);
}
.drawer-activity-item:focus-visible{
  outline: none;
  box-shadow: 0 0 0 2px var(--focus-ring);
  border-color: rgba(61, 191, 210, 0.38);
}
.drawer-activity-text{
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 800;
}
.drawer-activity-time{
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

/* Button badge (e.g., pending requests) */
.btn2.badgeable{ position: relative; }
.btn-badge{
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 900;
  color: #fff;
  background: #ef4444;
  border: 1px solid rgba(255,255,255,0.26);
  box-shadow: 0 10px 24px rgba(0,0,0,0.22);
  line-height: 1;
}

.chat-sidebar {
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface-alt), var(--surface));
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* Archived (WhatsApp-like row above conversations) */
.archived-bar{
  padding: 10px 12px 4px;
}
.archived-toggle{
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(127, 169, 187, 0.18);
  background: rgba(12, 47, 69, 0.42);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.archived-toggle:hover{
  transform: translateY(-1px);
  border-color: rgba(127, 169, 187, 0.28);
  background: rgba(255, 255, 255, 0.04);
}
.archived-toggle i{ color: var(--primary); }
.archived-count{
  margin-left: auto;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 900;
  color: var(--text);
  background: rgba(61,191,210,0.16);
  border: 1px solid rgba(61,191,210,0.18);
}
.archived-chev{
  color: rgba(127, 169, 187, 0.9);
}
body[data-theme="light"] .archived-toggle{
  background: rgba(255, 255, 255, 0.78);
  border-color: rgba(6, 32, 44, 0.12);
}

.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0; /* critical for keeping composer pinned + messages scrollable */
  background: linear-gradient(180deg, var(--surface), var(--bg));
}

.chat-topbar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
}

/* Back button (mobile Option A) */
.chat-topbar .back-btn{
  width: 36px;
  height: 36px;
  padding: 0;
  display: none; /* shown by JS + mobile media rules */
  align-items: center;
  justify-content: center;
}

/* Settings dropdown (mobile) */
.settings-menu{
  position: fixed;
  left: -9999px;
  top: -9999px;
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  padding: 8px;
  z-index: 6000;
}
.settings-me{
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(61, 191, 210, 0.10), rgba(6, 44, 63, 0.04));
  border: 1px solid rgba(61, 191, 210, 0.16);
}
.settings-me-avatar{
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 1000;
  letter-spacing: 0.6px;
  color: var(--text);
  background: rgba(6, 44, 63, 0.55);
  border: 1px solid rgba(61, 191, 210, 0.22);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  flex: 0 0 auto;
}
.settings-me-body{ min-width: 0; }
.settings-me-name{
  font-size: 14px;
  font-weight: 1000;
  color: var(--text);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.settings-me-meta{
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body[data-theme="light"] .settings-me{
  background: linear-gradient(180deg, rgba(239, 250, 251, 0.98), rgba(255, 255, 255, 0.88));
  border-color: rgba(30, 116, 141, 0.14);
}
body[data-theme="light"] .settings-me-avatar{
  background: rgba(255, 255, 255, 0.92);
  border-color: rgba(30, 116, 141, 0.18);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.12);
}
.settings-item{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 12px;
}
.settings-item:hover{ background: var(--surface-alt); }
.settings-item .left{
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}
.settings-item .left i{
  width: 18px;
  text-align: center;
  color: var(--muted);
}
.settings-sep{
  height: 1px;
  background: var(--border);
  margin: 6px 6px;
}
.settings-action{
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-radius: 12px;
  padding: 10px 10px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 900;
}

.settings-select{
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 900;
  outline: none;
}
body[data-theme="light"] .settings-select{
  background: rgba(255,255,255,0.92);
  border-color: rgba(30, 116, 141, 0.18);
}
.settings-action i{
  width: 18px;
  text-align: center;
  color: var(--muted);
}
.settings-action:hover{ background: var(--surface-alt); }
.settings-action.danger{ color: #ffd2d2; }
.settings-action.danger i{ color: #ffb4b4; }
body[data-theme="light"] .settings-action.danger{ color: #9b1c1c; }
body[data-theme="light"] .settings-action.danger i{ color: #b91c1c; }

/* iOS-style switch */
.switch{
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
  flex: 0 0 auto;
}
.switch input{
  opacity: 0;
  width: 0;
  height: 0;
}
.switch .slider{
  position: absolute;
  cursor: pointer;
  inset: 0;
  /* Higher-contrast track so it reads as a control */
  background: rgba(6, 44, 63, 0.85);
  border: 1px solid rgba(61,191,210,0.30);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.06),
    0 10px 26px rgba(0,0,0,0.22);
  transition: .18s;
  border-radius: 999px;
}
.switch .slider:before{
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  top: 2px;
  /* High-contrast knob */
  background: var(--text);
  transition: .18s;
  border-radius: 999px;
  box-shadow:
    0 8px 18px rgba(0,0,0,0.28),
    inset 0 0 0 1px rgba(0,0,0,0.22);
}
.switch input:checked + .slider{
  /* Obvious ON state */
  background: var(--primary);
  border-color: rgba(2, 22, 34, 0.22);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.14),
    0 10px 26px rgba(0,0,0,0.22);
}
.switch input:checked + .slider:before{
  transform: translateX(20px);
  background: var(--on-primary);
  box-shadow:
    0 8px 18px rgba(0,0,0,0.22),
    inset 0 0 0 1px rgba(2, 22, 34, 0.22);
}
body[data-theme="light"] .switch .slider{
  background: rgba(255,255,255,0.98);
  border-color: rgba(4,55,84,0.22);
  box-shadow:
    inset 0 0 0 1px rgba(4,55,84,0.06),
    0 10px 26px rgba(0,0,0,0.10);
}

/* Focus ring for keyboard accessibility */
.switch input:focus-visible + .slider{
  outline: none;
  box-shadow:
    0 0 0 3px rgba(61,191,210,0.25),
    inset 0 0 0 1px rgba(255,255,255,0.10),
    0 10px 26px rgba(0,0,0,0.18);
}

.chat-topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.chat-partner-avatar {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: linear-gradient(135deg, #0A374A, var(--secondary));
  border: 2px solid var(--border);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 14px;
  flex: 0 0 auto;
  box-shadow: 0 2px 6px #00000022;
}

.chat-topbar-info {
  min-width: 0;
  flex: 1;
}

.chat-topbar .title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--text);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-topbar .sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Typing indicator (WhatsApp-like animated dots) */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--primary);
}
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 2px;
}
.typing-dots span {
  animation: typingDot 1.4s infinite;
  opacity: 0.4;
}
.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
  0%, 60%, 100% { opacity: 0.4; }
  30% { opacity: 1; }
}

.chat-topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
  z-index: 1;
}

.chat-topbar-actions .icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-topbar-actions .icon-btn svg {
  width: 20px;
  height: 20px;
}

/* ========================================
   MESSAGE LOADING SKELETON (WhatsApp-like)
   ======================================== */
.messages-skeleton {
  position: absolute;
  inset: 0;
  z-index: 60; /* above pinned bar / jump-to-bottom */
  padding: 24px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: fadeIn 0.3s ease;
  pointer-events: none;
  overflow: hidden;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Premium: avoid scroll/layout flicker while switching conversations. */
.chat-messages.switch-loading > :not(#messagesLoadingSkeleton) {
  visibility: hidden;
}
.chat-messages.switch-loading #messagesLoadingSkeleton {
  visibility: visible;
}

.skeleton-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: skeletonPulse 1.5s ease-in-out infinite;
}

@keyframes skeletonPulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1.0; }
}

.skeleton-msg-left {
  justify-content: flex-start;
}

.skeleton-msg-right {
  justify-content: flex-end;
  margin-left: auto;
}

.skeleton-avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--hover-overlay-light);
  flex: 0 0 auto;
}

.skeleton-bubble {
  height: 48px;
  width: 280px;
  max-width: 60%;
  border-radius: 12px;
  background: linear-gradient(
    90deg,
    var(--surface-alt) 0%,
    var(--hover-overlay-light) 50%,
    var(--surface-alt) 100%
  );
  background-size: 200% 100%;
  animation: skeletonShimmer 1.5s ease-in-out infinite;
}

@keyframes skeletonShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-bubble-wide {
  width: 380px;
}

.skeleton-bubble-short {
  width: 180px;
}

.skeleton-msg-right .skeleton-bubble {
  background: linear-gradient(
    90deg,
    var(--active-overlay) 0%,
    var(--hover-overlay) 50%,
    var(--active-overlay) 100%
  );
  background-size: 200% 100%;
}

.chat-brandrow {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.chat-logo {
  width: 40px;
  height: auto;
  display: block;
  flex: 0 0 auto;
  opacity: 0.92;
  transition: opacity 0.2s ease;
  cursor: pointer;
}
.chat-logo:hover {
  opacity: 1;
}

/* Mobile: prevent focus zoom by keeping form controls >=16px */
@media (max-width: 768px) {
  input,
  textarea,
  select,
  button {
    font-size: 16px !important;
  }
  /* Chat composer explicitly */
  #composer {
    font-size: 16px !important;
  }
}

/* Logo theme switching */
.chat-logo-dark {
  display: block;
}
.chat-logo-light {
  display: none;
}
body[data-theme="light"] .chat-logo-dark {
  display: none;
}
body[data-theme="light"] .chat-logo-light {
  display: block;
}

.chat-user-avatar {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--primary-active));
  border: 2px solid var(--border);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 15px;
  flex: 0 0 auto;
  box-shadow: 0 2px 8px #00000033;
}

/* User avatar in topbar (smaller, cleaner) */
.chat-user-avatar-topbar {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--primary-active));
  border: 2px solid var(--border);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 13px;
  flex: 0 0 auto;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.20);
  position: relative;
}
.chat-user-avatar-topbar:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.30);
}
.chat-user-avatar-topbar .status-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--avatar-offline);
  border: 2px solid var(--surface);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}
.chat-user-avatar-topbar .status-dot.online {
  background: var(--avatar-online);
}
.chat-user-avatar-topbar .status-dot.st-busy {
  background: #f97316; /* orange */
  box-shadow: 0 2px 10px rgba(249, 115, 22, 0.26);
}
.chat-user-avatar-topbar .status-dot.st-in_meeting {
  background: #a855f7; /* purple */
  box-shadow: 0 2px 10px rgba(168, 85, 247, 0.26);
}
.chat-user-avatar-topbar .status-dot.st-dnd {
  background: #ef4444; /* red */
  box-shadow: 0 2px 10px rgba(239, 68, 68, 0.28);
}
.chat-user-avatar-topbar .status-dot.st-away {
  background: #f59e0b; /* amber */
  box-shadow: 0 2px 10px rgba(245, 158, 11, 0.25);
}

/* User Avatar Popover */
.user-popover {
  position: fixed;
  top: 60px;
  right: 12px;
  width: 280px;
  background: var(--popover-bg);
  border: 1px solid var(--popover-border);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 6000;
  padding: 12px;
}

.user-popover-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
}

.user-popover-avatar {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--primary-active));
  border: 2px solid var(--border);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 16px;
  flex: 0 0 auto;
}

.user-popover-info {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.user-popover-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-popover-phone {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-popover-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

.user-popover-setting{
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 8px;
}
.user-popover-setting .label{
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}
.user-popover-select{
  width: 100%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
  font-size: 13px;
}

.user-popover-action {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-radius: 12px;
  padding: 10px 12px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 700;
  transition: all 0.15s ease;
}

.user-popover-action:hover {
  background: var(--hover-overlay-light);
}

.user-popover-action i {
  width: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 16px;
}

.user-popover-action.danger {
  color: var(--danger);
}

.user-popover-action.danger i {
  color: var(--danger);
}

.chat-brandmeta {
  min-width: 0;
  flex: 1;
}

.chat-brandtitle {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--text);
  line-height: 1.2;
}

.chat-brandsubtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill {
  font-size: 11px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-alt);
}

.icon-btn {
  padding: 9px;
  border-radius: 999px;
  border: 0;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
}
.icon-btn:hover { 
  background: var(--surface-alt); 
  color: var(--text);
}
.icon-btn.notify-on {
  color: var(--primary);
  background: var(--surface-alt);
}
.icon-btn:disabled { opacity: .6; cursor: not-allowed; }

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 0;
}

.icon-btn i {
  font-size: 18px;
  line-height: 1;
}
.icon-btn.sm {
  padding: 7px;
}
.icon-btn.sm i {
  font-size: 14px;
}

/* In-chat search (topbar overlay) */
.chat-search {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--button-menu-bg), var(--hover-overlay));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.chat-search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 8px 10px;
}
.chat-search-bar i { color: var(--muted); }
.chat-search-bar input {
  flex: 1;
  min-width: 120px;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
}
.chat-search-meta {
  font-size: 12px;
  color: var(--muted);
  font-weight: 800;
  padding: 0 6px;
}

/* Mobile: keep search input + close button on-screen.
   On small widths, the meta/prev/next can wrap to a second line. */
@media (max-width: 480px) {
  .chat-search {
    padding: 8px 10px;
    /* Avoid overlapping the fixed mobile topbar (iOS notch / WebView safe areas). */
    top: calc(var(--chat-topbar-height-mobile, 0px) + var(--safe-top-effective, 0px));
  }
  .chat-search-bar {
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 10px;
  }
  .chat-search-bar i {
    order: 1;
    flex: 0 0 auto;
  }
  .chat-search-bar input {
    order: 2;
    flex: 1 1 160px;
    min-width: 0;
  }
  #chatSearchClose {
    order: 3;
    margin-left: auto;
  }
  .chat-search-meta {
    order: 10;
  }
  #chatSearchPrev {
    order: 11;
  }
  #chatSearchNext {
    order: 12;
  }
  /* Slightly tighter buttons so they don't get clipped */
  .chat-search-bar .icon-btn.sm {
    padding: 6px;
  }
  .chat-search-bar .icon-btn.sm i {
    font-size: 13px;
  }
}

/* Extra narrow: meta is the least important; hide it. */
@media (max-width: 360px) {
  .chat-search-meta {
    display: none;
  }
  .chat-search-bar input {
    flex-basis: 140px;
  }
}
.chat-search-results {
  margin-top: 10px;
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding-right: 2px;
}
.chat-search-item {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 10px;
  cursor: pointer;
  transition: all 0.12s ease;
}
.chat-search-item:hover { background: var(--surface-alt); }
.chat-search-item.active{
  box-shadow: 0 0 0 2px rgba(61, 191, 210, 0.28);
  border-color: rgba(61, 191, 210, 0.35);
}
.chat-search-item mark.search-hl{
  background: rgba(255, 209, 102, 0.28);
  color: var(--text);
  padding: 0 2px;
  border-radius: 6px;
}
body[data-theme="light"] .chat-search-item mark.search-hl{
  background: rgba(255, 208, 84, 0.45);
}
.chat-search-item .row1 {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.chat-search-item .row2 {
  margin-top: 4px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msgrow.flash .bubble {
  box-shadow: 0 0 0 2px rgba(61, 191, 210, 0.35), 0 18px 60px rgba(0,0,0,0.25);
}

.chat-sidebar-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.chat-sidebar-tabs .tab {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 10px;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chat-sidebar-tabs .tab:hover {
  background: var(--surface-alt);
  color: var(--text);
}
.chat-sidebar-tabs .tab.active {
  background: var(--active-overlay);
  border-color: var(--tab-active-border);
  color: var(--text);
}

.chat-sidebar-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.chat-sidebar-search input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  outline: none;
}
.chat-sidebar-search input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px #3dbfd21f;
}

/* Sidebar global search results (WhatsApp-like) */
.sidebar-search-results{
  margin-top: 10px;
  display: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  overflow: hidden;
  max-height: 340px;
}
.sidebar-search-results.show{ display: block; }
.ssr-section{
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 900;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}
.ssr-item{
  display: grid;
  gap: 4px;
  padding: 10px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s ease;
}
.ssr-item:last-child{ border-bottom: 0; }
.ssr-item:hover{ background: var(--surface-alt); }
.ssr-item.active{
  background: rgba(61, 191, 210, 0.10);
  box-shadow: inset 3px 0 0 rgba(61, 191, 210, 0.75);
}
.ssr-row1{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.ssr-title{
  font-size: 13px;
  font-weight: 900;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ssr-time{
  font-size: 12px;
  color: var(--muted);
  font-weight: 800;
  flex: 0 0 auto;
}
.ssr-snippet{
  font-size: 13px;
  color: var(--muted);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ssr-empty{
  padding: 12px 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.chat-sidebar-list-wrap{
  position: relative;
  flex: 1;
  min-height: 0;
}
.chat-sidebar-list {
  overflow: auto;
  padding: 10px;
  padding-bottom: 140px; /* extra room for Cayra AI FAB */
  height: 100%;
  -webkit-overflow-scrolling: touch;
}

/* Powered by Cayra footer (outside scroll list) */
.chat-powered-footer{
  /* Minimal, premium micro-footer */
  padding: 6px 10px calc(6px + var(--safe-area-bottom));
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  position: relative;
  z-index: 2;
}
.chat-powered-footer::before{
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  top: 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(127, 169, 187, 0.22),
    transparent
  );
  pointer-events: none;
}

#convList{
  padding-bottom: 72px; /* extra room after last row */
}
.chat-powered-link{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: color-mix(in srgb, var(--muted) 92%, var(--text));
  text-decoration: none;
  font-size: 11px;
  font-weight: 850;
  letter-spacing: -0.01em;
  line-height: 1;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, transform 160ms ease;
}
.chat-powered-kicker{
  color: color-mix(in srgb, var(--muted) 92%, var(--text));
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  line-height: 1;
  opacity: 0.85;
}
.chat-powered-logo{
  display: inline-flex;
  align-items: center;
  min-width: 0;
  height: 14px;
}
.chat-powered-logo-img{
  display: block;
  height: 20px;
  width: auto;
  margin-top: -6px;
  margin-left: -2px;
}
/* Theme toggle: show only relevant wordmark */
.chat-powered-logo-light{ display: none; }
body[data-theme="light"] .chat-powered-logo-light{ display: block; }
body[data-theme="light"] .chat-powered-logo-dark{ display: none; }
.chat-powered-link:hover{
  transform: translateY(-1px);
  border-color: rgba(127, 169, 187, 0.18);
  background: rgba(6, 44, 63, 0.22);
  color: var(--text);
}
.chat-powered-link:active{ transform: translateY(0px); }
body[data-theme="light"] .chat-powered-footer{
  background: transparent;
}
body[data-theme="light"] .chat-powered-link{
  color: rgba(9, 32, 45, 0.70);
}
body[data-theme="light"] .chat-powered-link:hover{
  background: rgba(255, 255, 255, 0.70);
  border-color: rgba(6, 32, 44, 0.10);
}

.cayra-fab {
  position: absolute;
  bottom: 18px;
  right: 18px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  background: #0B0F14;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.35), 0 6px 12px rgba(0, 0, 0, 0.22);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
  z-index: 3;
}
.cayra-fab img {
  width: 70%;
  height: 70%;
  object-fit: contain;
  pointer-events: none;
}
.cayra-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.38), 0 8px 14px rgba(0, 0, 0, 0.24);
}
.cayra-fab:active {
  transform: translateY(0);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.32), 0 5px 10px rgba(0, 0, 0, 0.22);
}

.cayra-fab-label {
  position: absolute;
  bottom: 28px;
  right: 84px;
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
  white-space: nowrap;
  transform: translateY(0);
  opacity: 1;
  transition: opacity 0.25s ease, transform 0.25s ease;
  animation: cayraAskPulse 2.6s ease-in-out infinite;
  z-index: 3;
}
.cayra-fab-label.hide {
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
}

@keyframes cayraAskPulse {
  0% { transform: translateY(0); opacity: 1; }
  50% { transform: translateY(-3px); opacity: 0.9; }
  100% { transform: translateY(0); opacity: 1; }
}

.contacts-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 10px 12px 6px;
}

.requests-section {
  margin: 6px 10px 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-alt);
  overflow: hidden;
}
.requests-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.requests-title {
  font-weight: 900;
  font-size: 13px;
  color: var(--text);
}
.requests-count {
  min-width: 22px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 12px;
  color: var(--on-primary);
  background: var(--primary);
}
.requests-list {
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.request {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.request .avatar {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--avatar-gradient-start), var(--avatar-gradient-end));
  border: 2px solid var(--border);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
}
.request .name {
  font-weight: 800;
  font-size: 14px;
  color: var(--text);
}
.request .meta {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 42vw;
}
.request-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.request-actions .req-more{
  width: 34px;
  height: 34px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.request-actions .req-more i{
  font-size: 14px;
  opacity: 0.9;
}

@media (max-width: 520px){
  /* Mobile: keep requests list compact */
  .request-actions .req-accept{ display: none; }
  .request .meta{ max-width: 56vw; }
}

.empty-state .empty-title {
  font-weight: 900;
  font-size: 16px;
  color: var(--text);
}
.empty-state .empty-body {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}
.empty-state button {
  margin-top: 12px;
}

.message-request-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  margin: 0 10px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}
.blocked-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  margin: 0 10px 8px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border));
  background: color-mix(in srgb, var(--danger) 10%, var(--surface-alt));
}
.message-request-bar .mr-text,
.blocked-bar .mr-text {
  font-weight: 800;
  font-size: 13px;
  color: var(--text);
}
.message-request-bar .mr-actions,
.blocked-bar .mr-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

@media (max-width: 900px) {
  .message-request-bar,
  .blocked-bar {
    flex-wrap: wrap;
  }

  .message-request-bar .mr-text,
  .blocked-bar .mr-text {
    flex: 1 1 100%;
    min-width: 0;
  }

  .message-request-bar .mr-actions,
  .blocked-bar .mr-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .message-request-bar .mr-actions button,
  .blocked-bar .mr-actions button {
    flex: 1 1 140px;
    min-width: 0;
    white-space: normal;
  }
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: color-mix(in srgb, var(--danger) 85%, #000);
}

.drawer-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.drawer-block-hint {
  font-size: 12px;
  color: var(--muted);
}

.contact {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.12s ease;
}
.contact:hover {
  background: var(--surface-alt);
  border-color: var(--border);
}
.contact .avatar {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--avatar-gradient-start), var(--avatar-gradient-end));
  border: 2px solid var(--border);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 16px;
  position: relative; /* for presence dot */
}
.contact-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.contact .name {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.contact .meta {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.contact-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.conv {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.12s ease;
  position: relative;
}
.conv:hover { 
  background: var(--surface-alt); 
  border-color: var(--border); 
}
.conv.active { 
  background: var(--surface-alt); 
  border-color: var(--primary); 
  box-shadow: 0 0 0 2px rgba(61, 191, 210, 0.08); 
}
.conv.pinned {
  background: rgba(61, 191, 210, 0.04);
}
.conv.muted .name {
  opacity: 0.6;
}

.conv .avatar {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--secondary), var(--secondary-active));
  border: 2px solid var(--border);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 16px;
  flex: 0 0 auto;
  position: relative; /* for presence dot */
}

/* Presence dot (WhatsApp-like) */
.presence-dot {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 11px;
  height: 11px;
  border-radius: 999px;
  background: rgba(168, 190, 201, 0.9); /* offline default */
  border: 2px solid var(--surface);
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
}
.presence-dot.online {
  background: #22c55e; /* green */
}
.presence-dot.st-busy{
  background: #f97316; /* orange */
  box-shadow: 0 2px 10px rgba(249, 115, 22, 0.26);
}
.presence-dot.st-in_meeting{
  background: #a855f7; /* purple */
  box-shadow: 0 2px 10px rgba(168, 85, 247, 0.26);
}
.presence-dot.st-dnd{
  background: #ef4444; /* red */
  box-shadow: 0 2px 10px rgba(239, 68, 68, 0.28);
}
.presence-dot.st-away{
  background: #f59e0b; /* amber */
  box-shadow: 0 2px 10px rgba(245, 158, 11, 0.25);
}
body[data-theme="light"] .presence-dot {
  border-color: var(--surface);
  box-shadow: 0 2px 10px rgba(0,0,0,0.10);
}

/* Group Badge (premium UX: indicates group conversation) */
.group-badge {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--primary-active));
  border: 2px solid var(--surface);
  box-shadow: 0 2px 10px rgba(0,0,0,0.20);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 8px;
}

/* Blocked badge overlay (Contacts + direct chats) */
.blocked-badge {
  position: absolute;
  left: -2px;
  bottom: -2px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--danger) 85%, #000);
  border: 2px solid var(--surface);
  box-shadow: 0 2px 10px rgba(0,0,0,0.20);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 11px;
  line-height: 1;
}

.conv-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conv .name {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 6px;
}

.conv-icon {
  font-size: 12px;
  color: var(--muted);
  opacity: 0.7;
}

.muted-pill{
  font-size: 11px;
  font-weight: 900;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(127, 169, 187, 0.18);
  background: rgba(6, 44, 63, 0.18);
  color: var(--muted);
  white-space: nowrap;
}
body[data-theme="light"] .muted-pill{
  background: rgba(255,255,255,0.78);
  border-color: rgba(215,223,228,0.75);
}

.conv .meta {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex: 0 0 auto;
}

/* Conversation 3-dot menu */
.conv-more{
  width: 28px;
  height: 28px;
  border-radius: 10px;
  border: 1px solid var(--button-menu-border);
  background: var(--button-secondary-bg);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  visibility: hidden;
  opacity: 0;
}
body[data-theme="light"] .conv-more{
  background: rgba(255,255,255,0.80);
  border-color: rgba(215,223,228,0.85);
}
.conv-more i{ font-size: 14px; opacity: 0.9; }
.conv:hover .conv-more,
.conv.active .conv-more{
  visibility: visible;
  opacity: 1;
}

.conv .time {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.badge {
  min-width: 18px;
  height: 28px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 900;
}

/* Sidebar mention badge (@2, @99+) */
.mention-badge{
  -webkit-appearance: none;
  appearance: none;
  min-width: 18px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid rgba(168, 85, 247, 0.38);
  background: rgba(88, 28, 135, 0.62);
  color: #f6edff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.01em;
  cursor: pointer;
}
body[data-theme="light"] .mention-badge{
  background: rgba(168, 85, 247, 0.14);
  border-color: rgba(168, 85, 247, 0.22);
  color: #4c1d95;
}
.mention-badge:focus{
  outline: 2px solid rgba(168, 85, 247, 0.55);
  outline-offset: 2px;
}

.chat-sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.chat-messages {
  flex: 1;
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  /* WhatsApp-like: do NOT smooth-scroll the main timeline. Smooth scrolling here can
     fight with infinite-scroll (load older) and prevent reaching the latest message. */
  scroll-behavior: auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  /* Chat background (WhatsApp-like) */
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--messages-bg-overlay), var(--messages-bg-overlay)),
    url("images/chat-bg-dark.png");
  background-repeat: repeat;
  background-size: 640px 640px;
  background-position: center top;
  scrollbar-gutter: stable;
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: var(--scrollbar-thumb) transparent; /* thumb / track */
}

/* Pinned bar (WhatsApp-like) */
.pinned-bar{
  position: sticky;
  top: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid rgba(127, 169, 187, 0.18);
  background: rgba(12, 47, 69, 0.62);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 14px 36px rgba(0,0,0,0.22);
}
body[data-theme="light"] .pinned-bar{
  background: rgba(255,255,255,0.86);
  border-color: rgba(215,223,228,0.75);
}
.pinned-bar-main{
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.pinned-bar-main i{
  color: var(--primary);
}
.pinned-bar-text{
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-weight: 900;
  font-size: 13px;
}
.pinned-bar-actions{
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.pinned-bar:focus-within{
  box-shadow: 0 0 0 2px var(--focus-ring), 0 14px 36px rgba(0,0,0,0.22);
}

/* (Message pinning removed) */

/* WhatsApp-like status ticks */
.bubble .meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}
.bubble .meta .mtime {
  display: inline-flex;
  align-items: center;
}
.bubble .meta .mstatus {
  display: inline-flex;
  align-items: center;
  line-height: 1;
  color: var(--muted);
}
.bubble .meta .mstatus .tick {
  font-size: 12px;
  line-height: 1;
  display: inline-block;
}
.bubble .meta .mstatus.single .tick { margin-left: 0; }
.bubble .meta .mstatus.double {
  gap: 0;
}
.bubble .meta .mstatus.double .tick.t2 {
  margin-left: -4px; /* WhatsApp-like overlap */
}
.bubble .meta .mstatus.read {
  color: var(--primary);
}

/* Outgoing bubble: ensure ticks have strong contrast against outgoing bubble bg in BOTH themes */
.bubble.me .meta .mstatus { color: rgba(2, 22, 34, 0.88); }
.bubble.me .meta .mstatus.read { color: #fff; } /* high contrast vs outgoing bubble */

/* Cayra AI: always show white ticks for outgoing user messages (premium, consistent) */
.bubble.cayra.me .meta .mstatus { color: rgba(255, 255, 255, 0.95); }

/* Modern thin scrollbar (WebKit) */
.chat-messages::-webkit-scrollbar {
  width: 10px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
  border: 3px solid transparent;
  background-clip: padding-box;
}

body[data-theme="light"] .chat-messages {
  background-color: var(--app-bg);
  background-image:
    linear-gradient(rgba(245, 251, 253, 0.90), rgba(245, 251, 253, 0.90)),
    url("images/chat-bg-light.png");
  background-repeat: repeat;
  background-size: 640px 640px;
  background-position: center top;
  scrollbar-color: rgba(30, 116, 141, 0.28) transparent;
}
body[data-theme="light"] .chat-messages::-webkit-scrollbar-thumb {
  background: rgba(30, 116, 141, 0.18);
  border: 3px solid transparent;
  background-clip: padding-box;
}
body[data-theme="light"] .chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(30, 116, 141, 0.30);
  border: 3px solid transparent;
  background-clip: padding-box;
}

.jump-to-bottom {
  position: absolute;
  bottom: 24px;
  right: 24px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px #00000044;
  z-index: 20;
  transition: all 0.15s ease;
}
.jump-to-bottom:hover {
  background: var(--surface-alt);
  transform: scale(1.05);
}
.jump-to-bottom.show {
  display: flex;
}
.jump-to-bottom i {
  font-size: 18px;
}

.empty-state {
  margin: auto;
  max-width: 64ch;
  text-align: center;
  padding: 18px 18px;
  border: 1px solid var(--empty-state-border);
  border-radius: 18px;
  background:
    radial-gradient(800px 240px at 20% 0%, var(--focus-ring), transparent),
    var(--empty-state-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--muted);
  box-shadow: 0 22px 90px rgba(0, 0, 0, 0.20);
}

/* Messages: load older (pagination) */
.load-older-wrap{
  display: none;
  justify-content: center;
  padding: 10px 0 14px;
}
.load-older-btn{
  appearance: none;
  border: 1px solid rgba(127, 169, 187, 0.22);
  background: rgba(12, 47, 69, 0.46);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--muted);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.02em;
  padding: 8px 12px;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.16);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.load-older-btn:hover{
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(127, 169, 187, 0.30);
}
.load-older-btn:disabled{
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}
body[data-theme="light"] .load-older-btn{
  background: rgba(255, 255, 255, 0.78);
  border-color: rgba(6, 32, 44, 0.12);
  box-shadow: 0 10px 26px rgba(0,0,0,0.10);
}

/* Premium subtle top progress (replaces noisy "Loading…" toast during jumps/previews) */
.msg-top-progress{
  position: sticky;
  top: 0;
  height: 3px;
  border-radius: 999px;
  margin: 6px 10px 8px;
  z-index: 2;
  overflow: hidden;
  background: rgba(127, 169, 187, 0.12);
  border: 1px solid rgba(127, 169, 187, 0.12);
}
.msg-top-progress::before{
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(61, 191, 210, 0.95), transparent);
  transform: translateX(-100%);
  animation: msgProgress 1.05s ease-in-out infinite;
}
@keyframes msgProgress{
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
@media (prefers-reduced-motion: reduce) {
  .msg-top-progress::before{ animation: none; transform: translateX(0); opacity: 0.65; }
}
body[data-theme="light"] .msg-top-progress{
  background: rgba(6, 32, 44, 0.06);
  border-color: rgba(6, 32, 44, 0.10);
}

/* Welcome screen (WhatsApp Web-like empty state) */
.welcome-screen {
  margin: auto;
  max-width: 720px;
  width: min(720px, calc(100% - 24px));
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px 10px;
  position: relative;
  isolation: isolate;
}

.welcome-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  position: relative;
}
.welcome-hero::before{
  content: "";
  position: absolute;
  inset: -40px -94px -18px -24px;
  z-index: -1;
  background:
    radial-gradient(380px 220px at 50% 12%, var(--welcome-glow-1), transparent 60%),
    radial-gradient(420px 220px at 18% 0%, var(--welcome-glow-2), transparent 62%);
  filter: blur(18px);
  opacity: 0.9;
  pointer-events: none;
}

.welcome-icon {
  width: 78px;
  height: 78px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(42px 42px at 30% 22%, rgba(255, 255, 255, 0.26), transparent 60%),
    radial-gradient(60px 60px at 30% 20%, var(--focus-ring), transparent),
    linear-gradient(135deg, var(--border), var(--secondary));
  border: 1px solid var(--focus-ring);
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.30);
  color: #ffffff;
  position: relative;
}
.welcome-icon::after{
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 999px;
  background: radial-gradient(closest-side, var(--focus-ring), transparent 70%);
  pointer-events: none;
}
.welcome-icon i { font-size: 30px; }

.welcome-title {
  font-weight: 900;
  letter-spacing: -0.02em;
  color: var(--text);
  font-size: 26px;
  line-height: 1.15;
}
.welcome-sub {
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.55;
  max-width: 62ch;
}

.welcome-card {
  border-radius: 20px;
  border: 1px solid var(--card-border);
  background:
    radial-gradient(900px 380px at 10% 0%, var(--focus-ring), transparent 60%),
    linear-gradient(180deg, var(--card-bg), var(--card-bg));
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 26px 110px rgba(0, 0, 0, 0.26);
  padding: 16px;
}

.welcome-bullets {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
}
.welcome-bullet {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 12px;
  align-items: start;
  color: rgba(235, 246, 247, 0.74);
  font-size: 13px;
  line-height: 1.4;
  padding: 10px 10px;
  border-radius: 14px;
  border: 1px solid transparent;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.welcome-bullet i {
  margin-top: 0;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  background: var(--active-overlay);
  border: 1px solid var(--focus-ring);
}
.welcome-bullet:hover{
  transform: translateY(-1px);
  background: var(--hover-overlay-light);
  border-color: var(--button-menu-border);
}

.welcome-foot {
  margin-top: 12px;
  display: flex;
  justify-content: center;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.welcome-pill {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid var(--focus-ring);
  background: var(--active-overlay);
  color: rgba(235, 246, 247, 0.74);
  font-size: 12px;
}
.welcome-pill i { color: var(--primary); }

body[data-theme="light"] .welcome-icon {
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.12);
}
body[data-theme="light"] .empty-state{
  background:
    radial-gradient(820px 260px at 20% 0%, rgba(61, 191, 210, 0.12), transparent 60%),
    rgba(255, 255, 255, 0.78);
  border-color: rgba(6, 32, 44, 0.12);
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.10);
}
body[data-theme="light"] .welcome-card{
  background:
    radial-gradient(900px 380px at 10% 0%, rgba(61, 191, 210, 0.14), transparent 60%),
    rgba(255, 255, 255, 0.76);
  border-color: rgba(6, 32, 44, 0.12);
  box-shadow: 0 26px 110px rgba(0, 0, 0, 0.10);
}
body[data-theme="light"] .welcome-bullet{
  color: rgba(6, 32, 44, 0.70);
}
body[data-theme="light"] .welcome-pill{
  color: rgba(6, 32, 44, 0.70);
  background: rgba(61, 191, 210, 0.10);
  border-color: rgba(61, 191, 210, 0.22);
}

@media (min-width: 680px) {
  .welcome-bullets{
    grid-template-columns: 1fr 1fr;
  }
  .welcome-bullet:last-child{
    grid-column: 1 / -1;
  }
}

@media (max-width: 480px) {
  .welcome-title{ font-size: 22px; }
  .welcome-icon{ width: 72px; height: 72px; }
  .welcome-card{ padding: 14px; }
}

/* Date separator (inline + sticky header) */
.date-separator {
  display: flex;
  justify-content: center;
  margin: 20px 0 14px;
  position: relative;
}
.date-separator span {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  box-shadow: 0 4px 12px #00000033;
}

.msgrow {
  display: flex;
  margin-bottom: 4px;
  position: relative;
}
.msgrow.start { margin-top: 12px; }
.msgrow.has-rx{
  padding-bottom: 16px; /* legacy */
}
.msgrow.has-under{
  padding-bottom: 18px; /* space for reaction + favorite pills */
}

/* WhatsApp-like message context chevron */
.msg-menu-btn {
  position: absolute; /* anchored to .bubble (position: relative) */
  top: 6px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid var(--button-menu-border);
  background: var(--button-menu-bg);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateX(6px);
  transition: opacity 0.15s ease, transform 0.15s ease, background 0.15s ease;
  z-index: 12;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}
.msg-menu-btn:hover { background: var(--button-menu-hover); }
.msg-menu-btn i { font-size: 12px; line-height: 1; }
.msgrow:hover .msg-menu-btn { opacity: 1; pointer-events: auto; transform: translateX(0); }

/* Reaction button (hover) */
.react-btn{
  position: absolute;
  top: 50%;
  right: -36px;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--button-menu-border);
  background: var(--button-menu-bg);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease, background 0.15s ease;
  z-index: 12;
}
.bubble.me .react-btn{
  left: -36px;
  right: auto;
}
.react-btn i { font-size: 14px; line-height: 1; }
.msgrow:hover .react-btn { opacity: 1; pointer-events: auto; }
.react-btn:hover { background: var(--button-menu-hover); }
body[data-theme="light"] .react-btn{
  background: rgba(255,255,255,0.92);
  border-color: rgba(30, 116, 141, 0.18);
  color: var(--text);
}

/* Reactions row (pills) */
.reactions{
  margin-top: 6px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.bubble.me .reactions{ justify-content: flex-end; }
.reaction-pill{
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(61, 191, 210, 0.18);
  background: rgba(6, 44, 63, 0.55);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}
.reaction-pill .cnt{ opacity: 0.85; font-weight: 900; }
.reaction-pill.me{
  border-color: rgba(61, 191, 210, 0.55);
  background: rgba(61, 191, 210, 0.14);
}
body[data-theme="light"] .reaction-pill{
  background: rgba(239, 250, 251, 0.95);
  border-color: rgba(215, 223, 228, 0.85);
  color: var(--text);
}

/* Under-bubble pills (reactions + favorite) */
.under-bubbles{
  position: absolute;
  bottom: 4px;
  left: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  z-index: 5;
  pointer-events: none; /* purely decorative */
}
.under-bubbles.me{
  left: auto;
  right: 12px;
  justify-content: flex-end;
}

.rx-bubble{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 20px;
  min-width: 20px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--under-bubble-border);
  background: var(--under-bubble-bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1;
  box-shadow: 0 10px 24px rgba(0,0,0,0.30);
}
.rx-item{
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.rx-mine{
  font-weight: 900;
  color: var(--accent);
}

.fav-bubble{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 20px;
  min-width: 20px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--under-bubble-border);
  background: var(--hover-overlay);
  color: #FFD36A; /* warm star, readable on dark + outgoing cyan */
  font-size: 12px;
  line-height: 1;
  box-shadow: 0 10px 24px rgba(0,0,0,0.30);
}
.fav-bubble i{ font-size: 12px; }
body[data-theme="light"] .fav-bubble{
  color: #B07A00;
}

/* Reaction popover */
.react-popover{
  position: fixed;
  left: -9999px;
  top: -9999px;
  padding: 8px;
  border-radius: 16px;
  border: 1px solid var(--popover-border);
  background: var(--popover-bg);
  box-shadow: 0 24px 80px rgba(0,0,0,0.45);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: none;
  z-index: 5000;
}
.react-popover{
  max-width: calc(100vw - 16px);
}
.react-popover.show{ display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.react-emoji-btn{
  width: 34px;
  height: 34px;
  border-radius: 12px;
  border: 1px solid var(--button-menu-border);
  background: var(--hover-overlay);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.08s ease, background 0.12s ease, border-color 0.12s ease;
}
.react-emoji-btn:hover{ 
  transform: translateY(-1px); 
  background: var(--active-overlay); 
  border-color: var(--focus-ring);
}
.react-emoji-btn.active{
  background: var(--active-overlay);
  border-color: var(--primary);
}
body[data-theme="light"] .react-popover{
  background: rgba(255,255,255,0.96);
  border-color: rgba(215,223,228,0.9);
  box-shadow: 0 20px 70px rgba(0,0,0,0.18);
}
body[data-theme="light"] .react-emoji-btn{
  background: rgba(239, 250, 251, 0.95);
  border-color: rgba(215, 223, 228, 0.9);
}
body[data-theme="light"] .msg-menu-btn {
  background: rgba(255, 255, 255, 0.92);
  border-color: rgba(30, 116, 141, 0.18);
  color: var(--text);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.10);
}
body[data-theme="light"] .msg-menu-btn:hover { background: rgba(239, 250, 251, 0.98); }

/* Dropdown menu (WhatsApp-like) */
.msg-menu-scrim{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.38);
  backdrop-filter: blur(2px);
  z-index: 3990;
  display: none;
}
.msg-menu-scrim.show{ display: block; }

.msg-menu {
  position: fixed;
  left: -9999px;
  top: -9999px;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  padding: 6px;
  z-index: 4000;
  display: none;
}
.msg-menu.show { display: block; }
.msg-menu.sheet{
  left: 0;
  right: 0;
  bottom: 0;
  top: auto;
  min-width: 0;
  width: auto;
  border-radius: 18px 18px 0 0;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  max-height: 72vh;
  overflow: auto;
  box-shadow: 0 -24px 80px rgba(0, 0, 0, 0.45);
  transform: translateY(14px);
  opacity: 0;
  transition: transform 0.16s ease, opacity 0.16s ease;
}
.msg-menu.sheet.show{
  transform: translateY(0);
  opacity: 1;
}
.msg-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-radius: 10px;
  font-size: 13px;
  text-align: left;
}
.msg-menu-item i {
  width: 18px;
  text-align: center;
  color: var(--muted);
}
.msg-menu-item:hover { background: var(--surface-alt); }
.msg-menu-item.danger { color: #ffd2d2; }
.msg-menu-item.danger i { color: #ffb4b4; }
body[data-theme="light"] .msg-menu-item.danger { color: #9b1c1c; }
body[data-theme="light"] .msg-menu-item.danger i { color: #b91c1c; }

/* Mobile mini action bar (tap) */
.mobile-msg-actions{
  position: fixed;
  left: -9999px;
  top: -9999px;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(12, 35, 48, 0.92);
  border: 1px solid rgba(61, 191, 210, 0.18);
  border-radius: 999px;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.45);
  z-index: 4100;
  backdrop-filter: blur(6px);
}
.mobile-msg-actions.show{ display: inline-flex; }
.mobile-msg-actions .act-btn{
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.mobile-msg-actions .act-btn:active{
  transform: scale(0.98);
  background: rgba(255,255,255,0.10);
}
body[data-theme="light"] .mobile-msg-actions{
  background: rgba(255, 255, 255, 0.92);
  border-color: rgba(30, 116, 141, 0.18);
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.16);
}
body[data-theme="light"] .mobile-msg-actions .act-btn{
  background: rgba(239, 250, 251, 0.92);
  border-color: rgba(30, 116, 141, 0.12);
}

.bubble {
  max-width: 76ch;
  padding: 9px 40px 9px 12px; /* extra right space for the message menu chevron */
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  position: relative;
}

/* Mobile: reclaim right padding (menu chevron hidden) */
@media (max-width: 900px) {
  .bubble {
    padding-right: 12px;
  }
}

/* Prevent text selection on bubbles for mobile long-press menus */
@media (max-width: 900px) {
  .bubble,
  .bubble .txt,
  .bubble .txt .markdown-body {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
}
.bubble.me {
  margin-left: auto;
  background: var(--bubble-me-bg); /* WhatsApp-like: outgoing bubble (theme-driven) */
  border-color: rgba(2, 22, 34, 0.12);
}
.bubble.other {
  background: var(--bubble-other-bg); /* WhatsApp-like: incoming bubble (theme-driven) */
  border-color: rgba(255, 255, 255, 0.08);
}

/* Cayra AI: premium start header (tablet/desktop base) */
.bubble.cayra.other .cayra-startline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px 0;
  padding: 6px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(6, 44, 63, 0.22);
  color: color-mix(in srgb, var(--text) 84%, var(--muted));
  width: max-content;
  max-width: 100%;
}
body[data-theme="light"] .bubble.cayra.other .cayra-startline {
  background: rgba(255, 255, 255, 0.70);
  border-color: rgba(6, 32, 44, 0.10);
}
.bubble.cayra.other .cayra-start-avatar {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  box-shadow:
    0 0 0 2px rgba(61, 191, 210, 0.18),
    0 10px 26px rgba(0, 0, 0, 0.18);
  background: linear-gradient(135deg, var(--avatar-gradient-start), var(--avatar-gradient-end));
}
.bubble.cayra.other .cayra-start-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.bubble.cayra.other .cayra-start-title {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40ch;
}
.bubble.cayra.other .cayra-start-badge {
  height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  border: 1px solid rgba(61, 191, 210, 0.26);
  background: rgba(61, 191, 210, 0.10);
  color: color-mix(in srgb, var(--text) 86%, #fff);
  font-size: 11px;
  font-weight: 900;
  line-height: 18px;
  flex: 0 0 auto;
}

/* Mobile: tighter Cayra start header */
@media (max-width: 900px) {
  .bubble.cayra.other {
    border-color: color-mix(in srgb, rgba(61, 191, 210, 0.28) 55%, var(--border));
  }
  body[data-theme="light"] .bubble.cayra.other {
    border-color: rgba(6, 32, 44, 0.10);
  }

  .bubble.cayra.other .cayra-startline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 8px 0;
    padding: 6px 8px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    background: rgba(6, 44, 63, 0.35);
    color: color-mix(in srgb, var(--text) 82%, var(--muted));
    width: max-content;
    max-width: 100%;
  }
  body[data-theme="light"] .bubble.cayra.other .cayra-startline {
    background: rgba(255, 255, 255, 0.70);
    border-color: rgba(6, 32, 44, 0.10);
  }

  .bubble.cayra.other .cayra-start-avatar {
    width: 18px;
    height: 18px;
    border-radius: 999px;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow:
      0 0 0 2px rgba(61, 191, 210, 0.22),
      0 8px 20px rgba(0, 0, 0, 0.22);
    flex: 0 0 auto;
    background: linear-gradient(135deg, var(--avatar-gradient-start), var(--avatar-gradient-end));
  }
  .bubble.cayra.other .cayra-start-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }
  .bubble.cayra.other .cayra-start-title {
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 54vw;
  }
  .bubble.cayra.other .cayra-start-badge {
    height: 18px;
    padding: 0 6px;
    border-radius: 999px;
    border: 1px solid rgba(61, 191, 210, 0.30);
    background: rgba(61, 191, 210, 0.12);
    color: color-mix(in srgb, var(--text) 86%, #fff);
    font-size: 11px;
    font-weight: 900;
    line-height: 18px;
    flex: 0 0 auto;
  }
}

/* Cayra AI feedback controls (stars + report) */
.cayra-feedback {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  opacity: 0;
  transform: translateY(-2px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

body[data-theme="light"] .cayra-feedback {
  border-top-color: rgba(2, 22, 34, 0.14);
}

.bubble:hover .cayra-feedback,
.bubble:focus-within .cayra-feedback {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

@media (max-width: 900px) {
  /* Mobile: always visible (no hover) */
  .cayra-feedback {
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }
}

/* Mobile: make Cayra feedback minimal (project uses 900px mobile breakpoint) */
@media (max-width: 900px) {
  .cayra-feedback{
    gap: 6px;
    margin-top: 6px;
    padding-top: 4px;
  }
  .cayra-feedback-stars{
    gap: 2px;
  }
  .cayra-feedback-star{
    font-size: 14px;
    padding: 0;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
  }
  .cayra-feedback-report{
    padding: 0;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
  }
  .cayra-feedback-report span{
    display: none;
  }
}

.cayra-feedback-stars {
  display: inline-flex;
  gap: 4px;
}

.cayra-feedback-star {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: rgba(255, 255, 255, 0.35);
}

body[data-theme="light"] .cayra-feedback-star {
  color: rgba(2, 22, 34, 0.35);
}

.cayra-feedback-star.active {
  color: #fbbf24;
}

.cayra-feedback-report {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12px;
}

.cayra-feedback-report.active {
  border-color: rgba(239, 68, 68, 0.35);
  color: #ffb4b4;
}

body[data-theme="light"] .cayra-feedback-report.active {
  border-color: rgba(185, 28, 28, 0.35);
  color: #9b1c1c;
}
.bubble .txt {
  white-space: normal;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
}
.bubble .txt .markdown-body {
  white-space: normal;
  font-size: 14px;
  line-height: 1.6;
  color: inherit;
  word-break: break-word;
}
.bubble .txt .markdown-body h1,
.bubble .txt .markdown-body h2,
.bubble .txt .markdown-body h3,
.bubble .txt .markdown-body h4,
.bubble .txt .markdown-body h5,
.bubble .txt .markdown-body h6 {
  margin: 0.6rem 0;
  font-weight: 600;
  color: inherit;
}
.bubble .txt .markdown-body p {
  margin: 0.4rem 0;
  color: inherit;
}
.bubble .txt .markdown-body ul,
.bubble .txt .markdown-body ol {
  margin: 0.5rem 0 0.5rem 1.5rem;
  padding-left: 1rem;
  color: inherit;
}
.bubble .txt .markdown-body li {
  margin: 0.2rem 0;
}
.bubble .txt .markdown-body a {
  color: var(--link);
  text-decoration: underline;
}
.bubble .txt .markdown-body a:hover {
  color: var(--primary-hover);
}
.bubble .txt .markdown-body code {
  background: var(--surface);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-family: "JetBrains Mono", "Courier New", Courier, monospace;
  font-size: 0.9em;
}
.bubble .txt .markdown-body pre {
  background: var(--surface);
  padding: 8px 10px;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.9rem;
  border: 1px solid var(--border);
}
.bubble .txt .markdown-body pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
}
.bubble .txt .markdown-body .md-table{
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0.75rem 0;
}
.bubble .txt .markdown-body .md-table table{
  /* Allow table to be as wide as needed, but never smaller than bubble width */
  width: max-content;
  min-width: 100%;
  margin: 0;
}
.bubble .txt .markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
  background: rgba(255, 255, 255, 0.01);
}
.bubble .txt .markdown-body th,
.bubble .txt .markdown-body td {
  border: 1px solid var(--border);
  padding: 0.65rem 0.75rem;
  text-align: left;
  vertical-align: top;
}
.bubble .txt .markdown-body thead th {
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
}
.bubble .txt .markdown-body tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}
.bubble .txt .markdown-body blockquote {
  border-left: 3px solid var(--primary);
  padding-left: 1rem;
  margin: 0.75rem 0;
  color: var(--muted);
  font-style: italic;
}
body[data-theme="light"] .bubble .txt .markdown-body table {
  background: #ffffff;
  border: 1px solid rgba(10, 59, 87, 0.08);
}
body[data-theme="light"] .bubble .txt .markdown-body thead th {
  background: #f0f4f8;
  color: #0A3B57;
}
body[data-theme="light"] .bubble .txt .markdown-body tbody tr:nth-child(even) {
  background: #f8fbfd;
}
body[data-theme="light"] .bubble .txt .markdown-body tbody tr:nth-child(odd) {
  background: #ffffff;
}
body[data-theme="light"] .bubble .txt .markdown-body th,
body[data-theme="light"] .bubble .txt .markdown-body td {
  border-color: rgba(10, 59, 87, 0.08);
  color: #0A3B57;
}

/* Mobile: tighter cells + avoid unreadable wrapping in narrow bubbles */
@media (max-width: 480px){
  .bubble .txt .markdown-body .md-table th,
  .bubble .txt .markdown-body .md-table td{
    padding: 0.45rem 0.55rem;
    font-size: 0.9em;
    white-space: nowrap;
  }
}
.bubble .txt.deleted{
  opacity: 0.92;
}
.bubble .txt.deleted .deleted-placeholder{
  display: inline-flex;
  gap: 8px;
  align-items: center;
  font-style: italic;
  color: var(--muted);
}
.bubble .txt.deleted .deleted-placeholder i{
  color: rgba(127, 169, 187, 0.9);
}
.bubble .senderline{
  font-size: 12px;
  font-weight: 900;
  color: var(--muted);
  margin-bottom: 4px;
}

/* Group system events (join/leave/rename) */
.sysrow{
  display:flex;
  justify-content:center;
  margin: 10px 0;
}
.syspill{
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(61,191,210,0.16);
  background: rgba(6, 44, 63, 0.35);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
body[data-theme="light"] .syspill{
  background: rgba(255,255,255,0.75);
  border-color: rgba(215,223,228,0.75);
}
.bubble.me .txt { color: var(--bubble-me-text-color); }
.bubble .meta {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  text-align: right;
}
.bubble.me .meta { color: rgba(2, 22, 34, 0.72); }

body[data-theme="light"] .bubble.other {
  background: var(--bubble-other-bg); /* WhatsApp-like: incoming bubble (light, theme-driven) */
  border-color: rgba(215, 223, 228, 0.85);
}

.chat-composer {
  border-top: 1px solid var(--border);
  padding: 10px 14px calc(10px + var(--safe-area-bottom, 0px) + var(--kb, 0px));
  background: var(--surface);
  position: sticky;
  bottom: 0;
  z-index: 20;
}

/* WhatsApp Web-like composer */
.wa-composer {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Cayra AI composer minimal (hide unused left icons everywhere; not just mobile) */
.wa-composer.cayra-min .wa-left {
  display: none;
}
@media (max-width: 900px) {
  .wa-composer.cayra-min {
    gap: 10px;
    flex-wrap: nowrap;
  }
  .wa-composer.cayra-min .wa-input-pill {
    padding: 0 12px;
  }
}

/* Reply bar */
.reply-bar{
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(61,191,210,0.18);
  background: rgba(6, 44, 63, 0.30);
}
body[data-theme="light"] .reply-bar{
  background: rgba(255,255,255,0.85);
  border-color: rgba(215,223,228,0.85);
}
.reply-left{ min-width:0; display:flex; flex-direction:column; gap: 2px; }
.reply-label{ font-size: 11px; font-weight: 800; color: var(--muted); }
.reply-name{ font-size: 12px; font-weight: 900; color: var(--text); }
.reply-preview{ font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 70vw; }

/* Reply message card */
.reply-card{
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.reply-quote{
  position: relative;
  border-left: 3px solid rgba(61,191,210,0.85);
  border: 1px solid rgba(61,191,210,0.18);
  padding: 10px 12px 10px 12px;
  padding-left: 12px;
  background: rgba(6, 44, 63, 0.22);
  border-radius: 12px;
  overflow: hidden;
}
body[data-theme="light"] .reply-quote{
  background: rgba(239, 250, 251, 0.92);
  border-left-color: rgba(30, 116, 141, 0.55);
  border-color: rgba(215,223,228,0.85);
}
.reply-quote-name{
  font-weight: 900;
  font-size: 12px;
  margin-bottom: 4px;
  color: var(--text);
  line-height: 1.15;
}
.reply-quote-text{
  font-size: 12px;
  color: var(--muted);
  line-height: 1.25;
  display: -webkit-box;
  line-clamp: 2;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reply-text{
  font-size: 14px;
  white-space: normal;
  word-break: break-word;
}

/* Reply card: make markdown spacing feel tighter and more chat-like */
.reply-text .markdown-body > :first-child{ margin-top: 0; }
.reply-text .markdown-body > :last-child{ margin-bottom: 0; }

/* Forwarded message */
.forward-card{ display:flex; flex-direction:column; gap: 8px; }
.forward-pill{
  display:inline-flex;
  align-items:center;
  gap: 8px;
  width: fit-content;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(61,191,210,0.32);
  background: rgba(6, 44, 63, 0.35);
  font-size: 12px;
  font-weight: 900;
  color: rgba(61,191,210,0.95);
}
body[data-theme="light"] .forward-pill{
  background: rgba(30, 116, 141, 0.08);
  border-color: rgba(30, 116, 141, 0.28);
  color: rgba(30, 116, 141, 0.95);
}
.forward-text{ 
  font-size: 14px; 
  white-space: normal; 
  word-break: break-word;
  /* Show full forwarded content (no clamp/truncation) */
  overflow: visible;
}

/* Forwarded structured content (e.g., forwarded reply card) */
.forward-inner{
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Forward modal */
.forward-modal{ width: min(520px, calc(100vw - 24px)); }
.forward-list{ display:flex; flex-direction:column; gap: 8px; margin-top: 10px; max-height: 46vh; overflow: auto; }
.forward-item{
  display:flex;
  align-items:center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(61,191,210,0.18);
  background: rgba(6, 44, 63, 0.22);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
body[data-theme="light"] .forward-item{
  background: rgba(255,255,255,0.85);
  border-color: rgba(215,223,228,0.85);
}
.forward-item.active{
  border-color: rgba(61,191,210,0.55);
  background: rgba(61,191,210,0.14);
}
.forward-item .avatar{
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(61,191,210,0.22);
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight: 900;
  flex: 0 0 auto;
}
.forward-item .meta{ min-width:0; display:flex; flex-direction:column; gap: 2px; flex: 1; }
.forward-item .name{ font-weight: 900; font-size: 13px; }
.forward-item .sub{ font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Emoji popover (corporate set) */
.wa-left { position: relative; }
.add-popover{
  position: absolute;
  left: 0;
  bottom: 54px;
  width: 220px;
  border: 1px solid var(--popover-border);
  background: var(--popover-bg);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.45);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 6px;
  z-index: 90;
}
body[data-theme="light"] .add-popover{
  background: rgba(255, 255, 255, 0.96);
  border-color: rgba(215, 223, 228, 0.9);
  box-shadow: 0 20px 70px rgba(0,0,0,0.18);
}
.add-item{
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
}
.add-item i{ width: 18px; text-align: center; color: var(--muted); }
.add-item:hover{ background: rgba(61, 191, 210, 0.10); }
.add-sep{
  height: 1px;
  margin: 6px 8px;
  background: rgba(61,191,210,0.16);
}
body[data-theme="light"] .add-sep{
  background: rgba(215,223,228,0.85);
}

.poll-opt{ display:flex; align-items:center; gap: 10px; margin-top: 8px; }
.poll-emoji{ width: 26px; text-align:center; }
.poll-input{ flex: 1; }

.share-card{
  display:flex;
  flex-direction: column;
  gap: 8px;
}
.share-title{
  font-weight: 900;
  font-size: 13px;
  display:flex;
  align-items:center;
  gap: 8px;
}
.share-title i{ color: rgba(2,22,34,0.75); }
.bubble.other .share-title i{ color: var(--muted); }
.share-sub{
  font-size: 12px;
  color: var(--muted);
}
.share-btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap: 8px;
  border: 1px solid rgba(61,191,210,0.22);
  background: rgba(3, 36, 55, 0.55);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 10px;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
  width: fit-content;
}
.share-btn:hover{ background: rgba(6, 44, 63, 0.70); }
body[data-theme="light"] .share-btn{
  background: rgba(255,255,255,0.88);
  border-color: rgba(215,223,228,0.85);
}
.share-btn.active{
  border-color: rgba(61,191,210,0.55);
  background: rgba(61,191,210,0.14);
}

.poll-rows{ display:flex; flex-direction:column; gap: 6px; }
.poll-row{
  width: 100%;
  display:flex;
  align-items:center;
  gap: 10px;
  border: 1px solid rgba(61,191,210,0.16);
  background: rgba(6, 44, 63, 0.30);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 10px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
body[data-theme="light"] .poll-row{
  background: rgba(255,255,255,0.85);
  border-color: rgba(215,223,228,0.75);
}
.poll-row.active{
  border-color: rgba(61,191,210,0.55);
  background: rgba(61,191,210,0.14);
}
.poll-row:disabled{
  cursor: not-allowed;
  opacity: 0.75;
}
.poll-row > *{
  position: relative;
  z-index: 1;
}
.poll-bar{
  position: absolute;
  inset: 0;
  width: 0;
  background: rgba(61,191,210,0.14);
  pointer-events: none;
  border-radius: 12px;
  z-index: 0;
  transition: width 160ms ease;
}
body[data-theme="light"] .poll-bar{
  background: rgba(61,191,210,0.10);
}
.poll-row.leading .poll-bar{
  background: rgba(61,191,210,0.20);
}
body[data-theme="light"] .poll-row.leading .poll-bar{
  background: rgba(61,191,210,0.14);
}
.poll-opt-text{ flex: 1; min-width:0; text-align:left; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.poll-meta{ display:flex; align-items: baseline; gap: 8px; }
.poll-pct{ font-weight: 800; color: var(--muted); font-size: 12px; }
.poll-cnt{ font-weight: 900; color: var(--muted); }

.attach-card{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.attach-actions{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.attach-btn.preview{
  background: rgba(6, 44, 63, 0.22);
}
body[data-theme="light"] .attach-btn.preview{
  background: rgba(239, 250, 251, 0.92);
}
.attach-head{
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.attach-head i{
  width: 28px;
  height: 28px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 44, 63, 0.22);
  border: 1px solid rgba(61,191,210,0.18);
  color: var(--text);
  flex: 0 0 auto;
}
body[data-theme="light"] .attach-head i{
  background: rgba(239, 250, 251, 0.95);
  border-color: rgba(215,223,228,0.85);
}
.attach-meta{ min-width: 0; }
.attach-name{
  font-weight: 900;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attach-sub{
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attach-btn{
  border: 1px solid rgba(61,191,210,0.22);
  background: rgba(3, 36, 55, 0.55);
  color: var(--text);
  border-radius: 12px;
  padding: 8px 10px;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
  flex: 0 0 auto;
}
.attach-btn:hover{ background: rgba(6, 44, 63, 0.70); }
body[data-theme="light"] .attach-btn{
  background: rgba(255,255,255,0.88);
  border-color: rgba(215,223,228,0.85);
}

/* Attachment preview modal */
.preview-modal{
  width: min(860px, calc(100vw - 24px));
}
.preview-body{
  max-height: min(70vh, 620px);
  overflow: auto;
}
.preview-img{
  width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}
.preview-frame{
  width: 100%;
  height: min(70vh, 620px);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-alt);
}
.preview-text{
  white-space: normal;
  word-break: break-word;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-alt);
  padding: 12px;
  color: var(--text);
  font-size: 13px;
}

/* Drawer items (Starred/Pinned lists) */
.drawer-item{
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--drawer-item-border);
  background: var(--drawer-item-bg);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  margin-top: 8px;
}
.drawer-item:hover{ background: var(--drawer-item-hover); }
.drawer-item .t{ flex: 1; min-width: 0; font-weight: 800; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-item .s{ flex: 0 0 auto; font-size: 11px; color: var(--muted); }
.emoji-popover{
  position: absolute;
  left: 0;
  bottom: 54px;
  width: 280px;
  max-width: min(320px, calc(100vw - 32px));
  border: 1px solid var(--popover-border);
  background: var(--popover-bg);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.45);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 10px;
  z-index: 80;
}
body[data-theme="light"] .emoji-popover{
  background: rgba(255, 255, 255, 0.96);
  border-color: rgba(215, 223, 228, 0.9);
  box-shadow: 0 20px 70px rgba(0,0,0,0.18);
}
.emoji-head{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.emoji-title{
  font-size: 12px;
  font-weight: 900;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.emoji-grid{
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  max-height: 220px;
  overflow: auto;
  padding-right: 2px;
}
.emoji-btn{
  width: 30px;
  height: 30px;
  border-radius: 10px;
  border: 1px solid var(--button-menu-border);
  background: var(--hover-overlay);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  transition: transform 0.08s ease, background 0.12s ease, border-color 0.12s ease;
}
.emoji-btn:hover{
  background: var(--active-overlay);
  border-color: var(--focus-ring);
  transform: translateY(-1px);
}
.emoji-btn:active{ transform: translateY(0); }

/* Mention autocomplete popover (WhatsApp-like @user) */
.mention-popover{
  position: fixed;
  bottom: 80px;
  left: 20px;
  width: 360px;
  max-width: min(360px, calc(100vw - 40px));
  max-height: 280px;
  border: 1px solid var(--popover-border);
  background: var(--popover-bg);
  border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.45);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 10px;
  z-index: 85;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body[data-theme="light"] .mention-popover{
  background: rgba(255, 255, 255, 0.96);
  border-color: rgba(215, 223, 228, 0.9);
  box-shadow: 0 20px 70px rgba(0,0,0,0.18);
}
.mention-head{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.mention-title{
  font-size: 11px;
  font-weight: 900;
  color: var(--muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.mention-list{
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  max-height: 240px;
}
.mention-item{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--hover-overlay);
  cursor: pointer;
  transition: all 0.12s ease;
  text-align: left;
}
.mention-item:hover,
.mention-item.active{
  background: var(--active-overlay);
  border-color: var(--focus-ring);
}
.mention-avatar{
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--avatar-gradient-start), var(--avatar-gradient-end));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 900;
  color: #ffffff;
  flex: 0 0 auto;
}
.mention-meta{
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.mention-name{
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mention-sub{
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mention-empty{
  padding: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

/* Mention links in message bubbles (clickable, blue) */
.mention-link{
  color: var(--link);
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.12s ease;
}
.mention-link:hover{
  opacity: 0.8;
  text-decoration: underline;
}
.bubble.me .mention-link{
  color: var(--on-primary);
  opacity: 0.95;
}
.bubble.me .mention-link:hover{
  opacity: 1;
  text-decoration: underline;
}

.wa-left,
.wa-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.wa-input-pill {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 15px;
  border: 1px solid var(--input-pill-border);
  background: var(--input-pill-bg);
  transition: all 0.15s ease;
}
.wa-input-pill:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.wa-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 0;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.12s ease;
  flex: 0 0 auto;
}
.wa-icon-btn[hidden] {
  display: none !important;
}
.wa-icon-btn:hover { background: rgba(61, 191, 210, 0.10); color: var(--text); }
.wa-icon-btn:active { transform: scale(0.98); }
.wa-icon-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.wa-icon-btn i { font-size: 18px; line-height: 1; }

.wa-input {
  width: 100%;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 16px; /* >=16px to prevent iOS zoom/shift */
  line-height: 1.4;
  padding: 10px 0;
  overflow-y: hidden; /* JS toggles to auto after 4 lines */
  scrollbar-gutter: stable;
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: rgba(112, 214, 225, 0.45) transparent; /* thumb / track */
}

/* Modern thin scrollbar (WebKit) */
.wa-input::-webkit-scrollbar {
  width: 8px;
}
.wa-input::-webkit-scrollbar-track {
  background: transparent;
}
.wa-input::-webkit-scrollbar-thumb {
  background: rgba(112, 214, 225, 0.35);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.wa-input::-webkit-scrollbar-thumb:hover {
  background: rgba(112, 214, 225, 0.55);
  border: 2px solid transparent;
  background-clip: padding-box;
}

body[data-theme="light"] .wa-input {
  scrollbar-color: rgba(30, 116, 141, 0.42) transparent;
}
body[data-theme="light"] .wa-input::-webkit-scrollbar-thumb {
  background: rgba(30, 116, 141, 0.30);
  border: 2px solid transparent;
  background-clip: padding-box;
}
body[data-theme="light"] .wa-input::-webkit-scrollbar-thumb:hover {
  background: rgba(30, 116, 141, 0.46);
  border: 2px solid transparent;
  background-clip: padding-box;
}

.wa-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: none;
  background: var(--primary);
  color: var(--on-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 10px 22px rgba(65, 195, 214, 0.18);
  flex: 0 0 auto;
}
.wa-send-btn:hover { background: var(--primary-hover); transform: translateY(-1px); }
.wa-send-btn:active { background: var(--primary-active); transform: translateY(0); }
.wa-send-btn:disabled {
  background: var(--surface-alt);
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.7;
  box-shadow: none;
}
.wa-send-btn i { font-size: 18px; line-height: 1; }

body[data-theme="light"] .wa-send-btn {
  box-shadow: 0 10px 22px rgba(65, 195, 214, 0.14);
}

body[data-theme="light"] .wa-input-pill {
  background: rgba(239, 250, 251, 0.92);
  border-color: rgba(30, 116, 141, 0.18);
}

.statusbar {
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
}
.statusbar.err { color: #ffd2d2; background: #2a0f1a; }
.statusbar.ok { color: #d6f7ff; background: #0b2430; }

/* Toast (replaces status bar) */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 2500;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(12, 47, 69, 0.72);
  color: var(--text);
  font-size: 13px;
  max-width: min(680px, calc(100vw - 40px));
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-2px);
}
.toast.has-action{
  pointer-events: auto;
  padding: 10px 10px;
}
.toast-inner{
  display: flex;
  align-items: center;
  gap: 10px;
}
.toast-text{
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toast-btn{
  flex: 0 0 auto;
  height: 28px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid rgba(127, 169, 187, 0.28);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  cursor: pointer;
  font-weight: 900;
  font-size: 12px;
}
.toast-btn:hover{
  background: rgba(255,255,255,0.12);
  border-color: rgba(127, 169, 187, 0.45);
}
.toast-btn:active{ transform: translateY(1px); }
.toast.ok { border-color: rgba(61, 191, 210, 0.45); }
.toast.err { border-color: rgba(239, 68, 68, 0.55); background: rgba(42, 15, 26, 0.86); }

body[data-theme="light"] .toast {
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
}

/* Mobile premium: mention chip (top banner in chat list) */
.mention-chip{
  position: fixed;
  left: 50%;
  top: calc(10px + env(safe-area-inset-top, 0px));
  transform: translateX(-50%) translateY(-6px);
  opacity: 0;
  pointer-events: none;
  z-index: 2600;
  max-width: min(560px, calc(100vw - 20px));
}
.mention-chip.show{
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
  transition: opacity 0.16s ease, transform 0.16s ease;
}
.mention-chip-btn{
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(127, 169, 187, 0.24);
  background: rgba(9, 33, 49, 0.86);
  color: var(--text);
  box-shadow: 0 10px 28px rgba(0,0,0,0.28);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
}
body[data-theme="light"] .mention-chip-btn{
  background: rgba(255,255,255,0.92);
  border-color: rgba(215,223,228,0.9);
  box-shadow: 0 10px 26px rgba(0,0,0,0.12);
}
.mention-chip-pill{
  flex: 0 0 auto;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(168, 85, 247, 0.34);
  background: rgba(88, 28, 135, 0.56);
  color: #f6edff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 12px;
}
body[data-theme="light"] .mention-chip-pill{
  background: rgba(168, 85, 247, 0.12);
  border-color: rgba(168, 85, 247, 0.22);
  color: #4c1d95;
}
.mention-chip-body{
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
}
.mention-chip-title{
  font-weight: 950;
  font-size: 13px;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mention-chip-sub{
  font-size: 12px;
  color: var(--muted);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mention-chip-cta{
  flex: 0 0 auto;
  font-weight: 900;
  font-size: 12px;
  opacity: 0.95;
}
/* Chip visibility is controlled by JS (mobile-only). */

/* Mobile polish */
@media (max-width: 520px){
  .mention-badge{
    height: 24px;
    padding: 0 7px;
    font-size: 10px;
  }
  .badge{
    height: 24px;
    font-size: 10px;
  }
  .toast{
    max-width: min(560px, calc(100vw - 20px));
  }
  .toast-inner{
    gap: 8px;
  }
  .toast-text{
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.25;
  }
  .toast-btn{
    height: 26px;
    padding: 0 9px;
    border-radius: 9px;
    font-size: 12px;
  }
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 2000;
}
.modal-backdrop.show { display: flex; }

/* New group modal (MVP) */
.group-modal{
  width: min(560px, calc(100vw - 32px));
}
.group-modal .modal-body{
  display: block;
}
.group-modal .modal-title{
  display:flex;
  align-items:center;
  justify-content: space-between;
}
.group-modal .modal-body{
  max-height: min(70vh, 560px);
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: rgba(127, 169, 187, 0.45) transparent; /* thumb track */
}
.group-modal .modal-body::-webkit-scrollbar{
  width: 8px;
}
.group-modal .modal-body::-webkit-scrollbar-track{
  background: transparent;
}
.group-modal .modal-body::-webkit-scrollbar-thumb{
  background: rgba(127, 169, 187, 0.35);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.group-modal .modal-body::-webkit-scrollbar-thumb:hover{
  background: rgba(127, 169, 187, 0.55);
  background-clip: padding-box;
}
body[data-theme="light"] .group-modal .modal-body{
  scrollbar-color: rgba(79, 115, 135, 0.42) transparent;
}
body[data-theme="light"] .group-modal .modal-body::-webkit-scrollbar-thumb{
  background: rgba(79, 115, 135, 0.28);
  background-clip: padding-box;
}
body[data-theme="light"] .group-modal .modal-body::-webkit-scrollbar-thumb:hover{
  background: rgba(79, 115, 135, 0.45);
  background-clip: padding-box;
}
.group-label{
  display:block;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 6px;
}
.group-input{
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  background: rgba(6, 44, 63, 0.42);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
}
body[data-theme="light"] .group-input{
  background: rgba(255,255,255,0.90);
}
.group-user-list{
  margin-top: 10px;
  max-height: 260px;
  overflow-y: auto;
  overflow-x: hidden;
  border-radius: 12px;
  border: 1px solid var(--drawer-item-border);
  background: var(--drawer-member-bg);
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: var(--scrollbar-thumb) transparent;
}
.group-user-list::-webkit-scrollbar{
  width: 8px;
}
.group-user-list::-webkit-scrollbar-track{
  background: transparent;
}
.group-user-list::-webkit-scrollbar-thumb{
  background: var(--scrollbar-thumb);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.group-user-list::-webkit-scrollbar-thumb:hover{
  background: var(--scrollbar-thumb-hover);
  background-clip: padding-box;
}
.group-user{
  display:flex;
  align-items:center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.group-user:last-child{ border-bottom: none; }
.group-user:hover{ background: var(--hover-overlay-light); }
.group-user-check{ width: 16px; height: 16px; }
.group-user-avatar{
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display:flex;
  align-items:center;
  justify-content:center;
  background: var(--active-overlay);
  border: 1px solid var(--focus-ring);
  font-weight: 900;
  color: var(--text);
  flex: 0 0 auto;
}
.group-user-meta{ display:flex; flex-direction:column; min-width:0; }
.group-user-name{ font-weight: 800; color: var(--text); font-size: 13px; white-space:nowrap; overflow:hidden; text-overflow: ellipsis; }
.group-user-sub{ color: var(--muted); font-size: 12px; white-space:nowrap; overflow:hidden; text-overflow: ellipsis; }
.group-help{ margin-top: 8px; font-size: 12px; color: var(--muted); }

/* Group picker: blocked users */
.group-user.blocked{
  opacity: 0.65;
  cursor: not-allowed;
}
.group-user.blocked:hover{ background: transparent; }
.group-user-badge{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 18px;
  padding: 0 8px;
  margin-left: 6px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 11px;
  color: #fff;
  background: color-mix(in srgb, var(--danger) 85%, #000);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border));
  vertical-align: middle;
}

/* Group edit chips */
.group-member-chips{
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.member-chip{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(61,191,210,0.18);
  background: rgba(6, 44, 63, 0.55);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}
body[data-theme="light"] .member-chip{
  background: rgba(255,255,255,0.90);
  border-color: rgba(215,223,228,0.85);
}
.member-chip-role{
  font-size: 11px;
  font-weight: 900;
  color: var(--muted);
  padding-left: 4px;
}
.member-chip-remove{
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
body[data-theme="light"] .member-chip-remove{
  background: rgba(4,55,84,0.06);
  border-color: rgba(4,55,84,0.10);
  color: var(--text);
}
.member-chip-remove i{ font-size: 12px; }
.modal {
  position: relative;
  width: 100%;
  /* Prevent overflow on small screens (padding + content should stay inside viewport) */
  max-width: min(460px, calc(100vw - 40px));
  box-sizing: border-box;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.45);
  padding: 16px;
}
.modal-title {
  font-weight: 800;
  font-size: 16px;
  color: var(--text);
}
.modal-body {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  max-height: calc(70vh - 120px);
  overflow-y: auto;
  overflow-x: hidden;
}
.modal-actions {
  margin-top: 14px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* Privacy policy modal: keep agreement controls visible */
.privacy-modal {
  display: flex;
  flex-direction: column;
}
.privacy-modal .modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 12px;
}
.privacy-modal .modal-actions {
  flex: 0 0 auto;
}
.privacy-modal .privacy-policy-scroll {
  max-height: calc(70vh - 220px);
  height: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: rgba(127, 169, 187, 0.45) transparent;
}
.privacy-modal .privacy-policy-scroll::-webkit-scrollbar {
  width: 8px;
}
.privacy-modal .privacy-policy-scroll::-webkit-scrollbar-track {
  background: transparent;
}
.privacy-modal .privacy-policy-scroll::-webkit-scrollbar-thumb {
  background: rgba(127, 169, 187, 0.35);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.privacy-modal .privacy-policy-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(127, 169, 187, 0.55);
  background-clip: padding-box;
}
body[data-theme="light"] .privacy-modal .privacy-policy-scroll {
  scrollbar-color: rgba(79, 115, 135, 0.42) transparent;
}
body[data-theme="light"] .privacy-modal .privacy-policy-scroll::-webkit-scrollbar-thumb {
  background: rgba(79, 115, 135, 0.28);
  background-clip: padding-box;
}
body[data-theme="light"] .privacy-modal .privacy-policy-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(79, 115, 135, 0.45);
  background-clip: padding-box;
}

/* Mobile: premium bottom-sheet modals */
@media (max-width: 900px) {
  .modal-backdrop {
    align-items: flex-end;
    padding: 10px;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  .modal {
    width: 100%;
    max-width: 100%;
    max-height: min(88vh, calc(100vh - 14px));
    border-radius: 18px 18px 14px 14px;
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 26px 90px rgba(0, 0, 0, 0.55);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: modalSheetIn 180ms ease-out 1;
    transform-origin: bottom center;
  }

  /* Subtle handle */
  .modal::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 44px;
    height: 4px;
    border-radius: 999px;
    background: rgba(127, 169, 187, 0.35);
  }
  body[data-theme="light"] .modal::before {
    background: rgba(79, 115, 135, 0.28);
  }

  .modal-title {
    padding-top: 8px; /* make room for handle */
    font-size: 16px;
    line-height: 1.25;
    letter-spacing: 0.01em;
  }

  .modal-body {
    flex: 1 1 auto;
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-right: 2px;
  }

  .modal-actions {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    justify-content: stretch;
  }
  body[data-theme="light"] .modal-actions {
    border-top-color: rgba(6, 32, 44, 0.10);
  }
  .modal-actions > button,
  .modal-actions > .btn,
  .modal-actions > .btn2 {
    flex: 1 1 auto;
    min-height: 42px;
  }

  /* Privacy modal: make scroll area fill the sheet nicely */
  .privacy-modal {
    height: min(88vh, calc(100vh - 14px));
    max-height: min(88vh, calc(100vh - 14px));
    overflow: hidden;
  }
  .privacy-modal .modal-body {
    flex: 1 1 auto;
    overflow: hidden;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
  }
  .privacy-modal .privacy-policy-scroll {
    max-height: none;
    height: 100%;
    flex: 1 1 auto;
    min-height: 0;
  }
}

@keyframes modalSheetIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Theme-only visibility helpers */
body[data-theme="dark"] .theme-light-only { display: none !important; }
body[data-theme="light"] .theme-dark-only { display: none !important; }

/* Tablet breakpoint: keep 2-column only when there's enough vertical space.
   This avoids "wide mobile" (landscape phones) being treated like tablet. */
@media (max-width: 980px) and (min-height: 700px) {
  /* Tablet: 2-column (sidebar + chat). Drawer becomes overlay sheet. */
  .chat-shell { grid-template-columns: 340px 1fr; }
  .chat-shell.drawer-closed { grid-template-columns: 340px 1fr; }

  /* Override desktop "display:none" drawer behavior: keep in DOM as overlay */
  .chat-drawer{
    position: fixed;
    inset: 0 0 0 auto;
    width: min(360px, 92vw);
    transform: translateX(0);
    z-index: 50;
    box-shadow: 0 24px 90px rgba(0,0,0,0.45);
    border-left: 1px solid var(--border);
  }
  .chat-shell.drawer-closed .chat-drawer{
    display: flex;
    transform: translateX(104%);
  }
  body.drawer-open .drawer-scrim{ display: block; }
}

/* Wide mobile (landscape) should behave like phone: Option A (single column, two-screen). */
@media (max-width: 980px) and (max-height: 699px) {
  .chat-shell { grid-template-columns: 1fr; }
  .chat-shell.drawer-closed { grid-template-columns: 1fr; }

  /* Wide mobile (landscape): drawer should still be an overlay sheet */
  .chat-drawer{
    position: fixed;
    inset: 0 0 0 auto;
    width: min(360px, 92vw);
    height: 100dvh;
    transform: translateX(0);
    z-index: 50;
    box-shadow: 0 24px 90px rgba(0,0,0,0.45);
    border-left: 1px solid var(--border);
  }
  .chat-shell.drawer-closed .chat-drawer{
    display: flex;
    transform: translateX(104%);
  }
  body.drawer-open .drawer-scrim{ display: block; }
}

@media (max-width: 768px) {
  :root{
    --chat-topbar-height-mobile: 60px;
  }
  /* Mobile Option A: two screens (list ↔ chat) */
  .chat-shell {
    display: flex;
    flex-direction: column;
    grid-template-columns: 1fr;
    position: relative;
    min-height: 100dvh;
    overflow: hidden;
  }

  /* Both screens occupy the same space; animate between them.
     Default (no class yet): LIST visible, CHAT hidden (prevents initial stacking/flash). */
  .chat-sidebar,
  .chat-main{
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }

  .chat-sidebar{
    display: flex;
    transform: none;
    opacity: 1;
    pointer-events: auto;
    transition: transform 0.18s ease, opacity 0.18s ease;
  }
  .chat-main{
    display: flex;
    flex: 1 1 auto;
    min-height: 100dvh;
    overflow: hidden;
    transform: translateX(6%);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.18s ease, opacity 0.18s ease;
  }

  body.mobile-list-open .chat-sidebar{
    transform: none;
    opacity: 1;
    pointer-events: auto;
  }
  body.mobile-list-open .chat-main{
    transform: translateX(6%);
    opacity: 0;
    pointer-events: none;
  }

  body.mobile-chat-open .chat-sidebar{
    transform: translateX(-6%);
    opacity: 0;
    pointer-events: none;
  }
  body.mobile-chat-open .chat-main{
    /* Keep active panel untransformed so fixed children stay viewport-anchored
       (prevents topbar from drifting when the keyboard opens on mobile). */
    transform: none;
    opacity: 1;
    pointer-events: auto;
  }

  /* Safe areas (notch/home indicator) */
  .chat-topbar{
    padding-left: 12px;
    padding-right: 12px;
    gap: 10px;
    position: fixed;
    top: var(--safe-top-effective);
    left: 0;
    right: 0;
    z-index: 50;
    background: var(--surface);
  }
  .chat-sidebar-tabs{
    padding-top: 18px;
    margin-top: calc(var(--chat-topbar-height-mobile) + var(--safe-top-effective));
  }
  .chat-composer{
    padding-bottom: calc(10px + var(--safe-area-bottom, 0px) + var(--kb, 0px));
    padding-left: 10px;
    padding-right: 10px;
  }

  /* Lock layout to prevent page scroll/jump when keyboard opens on mobile */
  body.mobile-chat-open,
  body.mobile-list-open {
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }
  /* Offset chat content to avoid overlap with fixed topbar (esp. when keyboard opens) */
  .chat-main{
    box-sizing: border-box;
    padding-top: calc(var(--chat-topbar-height-mobile) + var(--safe-top-effective));
    min-height: 100dvh;
  }

  /* Back button only on chat screen */
  .chat-topbar .back-btn{ display: none; }
  body.mobile-chat-open .chat-main .chat-topbar .back-btn{ display: inline-flex; }

  /* Mobile topbar cleanup: settings dropdown instead of floating toggles + logout icon */
  .chat-topbar .floating-controls{ display: none !important; }
  #btnSettings{ display: inline-flex !important; }
  #btnLogout{ display: none !important; }

  /* Tighter topbar actions so they don't wrap */
  .chat-topbar-actions{ gap: 2px; }
  .chat-topbar-actions .icon-btn{ width: 34px; height: 34px; }
  .chat-partner-avatar{ width: 36px; height: 36px; }
  .chat-topbar .title{ font-size: 14px; }
  .chat-topbar .sub{ font-size: 12px; }

  /* Messages padding tuned for small screens */
  .chat-messages{ padding: 12px; }
  .jump-to-bottom{ display: none !important; }

  /* Prevent any bubble content (attachments) from overflowing the viewport */
  .bubble{
    max-width: calc(100vw - 48px);
  }
  .bubble .attach-card{
    max-width: 100%;
    flex-wrap: wrap;
  }
  .bubble .attach-actions{
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }
  .bubble .attach-btn{
    flex: 1 1 120px;
    min-width: 0;
    padding: 7px 10px;
  }

  /* Drawer as full-width sheet on phones */
  .chat-drawer{
    position: fixed;
    inset: 0 0 0 auto;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    transform: translateX(0);
    z-index: 50;
  }
  .chat-shell.drawer-closed .chat-drawer{
    display: flex;
    transform: translateX(104%);
  }
  body.drawer-open .drawer-scrim{ display: block; }

  /* Contact Info drawer: respect safe area at the top on mobile */
  .chat-drawer-header{
    padding-top: calc(12px + var(--safe-top-effective));
    padding-left: 14px;
    padding-right: 14px;
  }
  .chat-drawer-header .title{
    font-size: 14px;
  }
  .chat-drawer-body{
    padding-left: 12px;
    padding-right: 12px;
  }
  /* Make close button easier to tap */
  #btnCloseDrawer.icon-btn{
    width: 40px;
    height: 40px;
    border-radius: 12px;
  }
  .drawer-kv .kv{
    grid-template-columns: minmax(90px, 0.44fr) 1fr;
  }
  #drawerSmartAgentMeta .kv{
    grid-template-columns: minmax(110px, 0.42fr) 1fr;
  }
}

/* Touch devices: make hover-only controls reachable */
@media (hover: none) and (pointer: coarse) {
  .conv-more{
    visibility: visible;
    opacity: 1;
  }
  .msgrow.touch-active .msg-menu-btn,
  .msgrow.touch-active .react-btn{
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
  }
}


