/* ═══════════════════════════════════════════════════════════
   DESIGN TOKENS  —  WhatsApp-grade light theme
═══════════════════════════════════════════════════════════ */
:root {
  /* Surface */
  --bg-page:    #f0f2f5;
  --bg-sidebar: #ffffff;
  --bg-chat:    #efeae2;
  --bg-surface: #ffffff;

  /* Accent */
  --accent:         #00a884;
  --accent-dark:    #008069;
  --accent-xlight:  #d9fdd3;
  --accent-ring:    rgba(0,168,132,.22);

  /* Bubbles */
  --bubble-sent:    #d9fdd3;
  --bubble-recv:    #ffffff;
  --bubble-sent-tx: #111b21;
  --bubble-recv-tx: #111b21;

  /* Text */
  --tx1: #111b21;
  --tx2: #3b4a54;
  --tx3: #667781;
  --tx4: #8696a0;

  /* Chrome */
  --border:     #e9edef;
  --border-md:  #d1d7db;
  --hover:      #f5f6f6;
  --active:     #e9edef;
  --input-bg:   #f0f2f5;

  /* Auth */
  --auth-bg:    #f0f2f5;

  /* Misc */
  --header-height: 59px;
  --sb-width:      360px;
  --r-bubble:      7.5px;
  --shadow-sm:  0 1px 2px rgba(11,20,26,.08);
  --shadow-md:  0 2px 8px rgba(11,20,26,.10);
  --shadow-lg:  0 4px 24px rgba(11,20,26,.13);

  --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg-page); font-family: var(--font); color: var(--tx1); -webkit-font-smoothing: antialiased; overflow: hidden; }
button { font-family: var(--font); cursor: pointer; border: none; background: none; }
input  { font-family: var(--font); }
a { color: inherit; text-decoration: none; }

/* scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-md); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--tx4); }


/* ═══════════════════════════════════════════════════════════
   AUTH SCREEN
═══════════════════════════════════════════════════════════ */
#auth-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--auth-bg);
}

@media (max-width: 700px) {
  #auth-screen { grid-template-columns: 1fr; }
  .auth-left { display: none; }
}

/* Left panel */
.auth-left {
  background: var(--accent);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 60px 56px;
  gap: 16px;
}

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

.auth-brand-icon {
  width: 48px;
  height: 48px;
  background: rgba(255,255,255,.18);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}
.auth-brand-icon svg { width: 100%; height: 100%; }

.auth-brand-name {
  font-size: 30px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.02em;
}

.auth-tagline {
  font-size: 17px;
  color: rgba(255,255,255,.85);
  font-weight: 400;
  line-height: 1.5;
}

.auth-feature-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.auth-feature {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: rgba(255,255,255,.82);
  font-weight: 400;
}

.auth-feature-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,.7);
  flex-shrink: 0;
}

/* Right panel */
.auth-right {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
}

.auth-card {
  background: var(--bg-surface);
  border-radius: 16px;
  padding: 36px 36px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.auth-tabs {
  display: flex;
  background: var(--input-bg);
  border-radius: 10px;
  padding: 4px;
  gap: 4px;
  margin-bottom: 28px;
}

.auth-tab {
  flex: 1;
  padding: 9px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--tx3);
  transition: all .15s;
  letter-spacing: -.01em;
}

.auth-tab.active {
  background: var(--bg-surface);
  color: var(--tx1);
  box-shadow: var(--shadow-sm);
}

.auth-form { display: flex; flex-direction: column; gap: 14px; }

.field-group { display: flex; flex-direction: column; gap: 5px; }

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--tx2);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.field-input {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  font-size: 14.5px;
  font-weight: 400;
  color: var(--tx1);
  background: var(--bg-surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field-input::placeholder { color: var(--tx4); font-weight: 400; }
.field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* password */
.pw-wrap { position: relative; }
.pw-wrap .field-input { padding-right: 42px; }
.pw-eye {
  position: absolute;
  right: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--tx4);
  transition: color .12s;
}
.pw-eye:hover { color: var(--tx2); }
.pw-eye svg { width: 17px; height: 17px; }

.auth-error {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 12px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  font-size: 13px;
  color: #dc2626;
  font-weight: 500;
}

/* Buttons */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  background: var(--accent);
  color: #fff;
  border-radius: 9px;
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -.01em;
  transition: background .15s, transform .08s, box-shadow .15s;
  box-shadow: 0 2px 8px rgba(0,168,132,.3);
}
.btn-primary:hover  { background: var(--accent-dark); box-shadow: 0 3px 12px rgba(0,168,132,.4); }
.btn-primary:active { transform: scale(.99); }
.btn-primary:disabled { opacity: .65; cursor: not-allowed; }

.btn-full { width: 100%; margin-top: 4px; }

.btn-ghost {
  padding: 10px 20px;
  border: 1.5px solid var(--border-md);
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  color: var(--tx2);
  transition: background .12s, border-color .12s;
}
.btn-ghost:hover { background: var(--hover); border-color: var(--border-md); }

.btn-spinner {
  width: 18px;
  height: 18px;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }


/* ═══════════════════════════════════════════════════════════
   APP SHELL
═══════════════════════════════════════════════════════════ */
#app-screen {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-page);
}


/* ═══════════════════════════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sb-width);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.sb-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-page);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sb-me {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.sb-me-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--tx1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -.02em;
}

.sb-actions { display: flex; gap: 2px; }

.sb-icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--tx3);
  transition: background .12s, color .12s;
}
.sb-icon-btn svg { width: 20px; height: 20px; }
.sb-icon-btn:hover { background: var(--hover); color: var(--tx1); }

/* Search */
.sb-search-wrap {
  padding: 8px 12px;
  background: var(--bg-sidebar);
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.sb-search {
  position: relative;
  display: flex;
  align-items: center;
}

.sb-search-icon {
  position: absolute;
  left: 11px;
  width: 16px;
  height: 16px;
  color: var(--tx4);
  pointer-events: none;
  flex-shrink: 0;
}

.sb-search-input {
  width: 100%;
  padding: 9px 36px 9px 36px;
  background: var(--input-bg);
  border: none;
  border-radius: 8px;
  font-size: 14px;
  color: var(--tx1);
  outline: none;
  transition: box-shadow .15s;
}
.sb-search-input::placeholder { color: var(--tx4); }
.sb-search-input:focus { box-shadow: 0 0 0 2px var(--accent-ring); }

.sb-search-clear {
  position: absolute;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--tx4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: background .12s;
}
.sb-search-clear svg { width: 11px; height: 11px; }
.sb-search-clear:hover { background: var(--tx3); }

/* Body */
.sb-body {
  flex: 1;
  overflow-y: auto;
}

/* Conversation list */
.conv-list { display: flex; flex-direction: column; }

.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background .1s;
  position: relative;
  border-bottom: 1px solid var(--border);
  min-height: 72px;
}
.conv-item:hover  { background: var(--hover); }
.conv-item.active { background: var(--active); }

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

.conv-row1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.conv-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--tx1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -.015em;
}

.conv-time {
  font-size: 12px;
  color: var(--tx4);
  flex-shrink: 0;
  font-weight: 400;
}

.conv-row2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.conv-preview {
  font-size: 13.5px;
  color: var(--tx3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 400;
  flex: 1;
  min-width: 0;
}

.conv-preview-you { color: var(--tx3); }

.group-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
  background: rgba(0,168,132,.1);
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.conv-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  gap: 8px;
  color: var(--tx3);
}
.conv-empty p { font-size: 14px; font-weight: 500; color: var(--tx2); }
.conv-empty span { font-size: 13px; }

/* Search panel */
.search-section-label {
  padding: 8px 16px 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--tx4);
  letter-spacing: .05em;
}

.search-user-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background .1s;
  border-bottom: 1px solid var(--border);
}
.search-user-item:hover { background: var(--hover); }

.search-user-info { flex: 1; min-width: 0; }
.search-user-name  { font-size: 15px; font-weight: 600; color: var(--tx1); letter-spacing: -.015em; }
.search-user-email { font-size: 13px; color: var(--tx3); margin-top: 2px; }

.search-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 48px 24px;
  text-align: center;
  color: var(--tx3);
}
.search-empty svg { width: 64px; height: 64px; opacity: .5; }
.search-empty p   { font-size: 15px; font-weight: 600; color: var(--tx2); }
.search-empty span{ font-size: 13px; }


/* ═══════════════════════════════════════════════════════════
   AVATAR
═══════════════════════════════════════════════════════════ */
.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: rgba(255,255,255,.95);
  flex-shrink: 0;
  user-select: none;
  letter-spacing: -.01em;
}
.avatar.sm  { width: 36px; height: 36px; font-size: 13px; }
.avatar.lg  { width: 48px; height: 48px; font-size: 18px; }
.avatar.xs  { width: 28px; height: 28px; font-size: 10px; }


/* ═══════════════════════════════════════════════════════════
   CHAT PANEL
═══════════════════════════════════════════════════════════ */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Empty state */
.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-chat);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='440' height='440'%3E%3Cpath d='M0 0h440v440H0z' fill='%23e5ddd5'/%3E%3Cg fill='none' stroke='%23d5cfc7' stroke-width='.5' opacity='.5'%3E%3Ccircle cx='220' cy='220' r='80'/%3E%3Ccircle cx='220' cy='220' r='120'/%3E%3Ccircle cx='220' cy='220' r='160'/%3E%3Ccircle cx='220' cy='220' r='200'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 440px;
}

.empty-content {
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(8px);
  border-radius: 16px;
  padding: 40px 48px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 420px;
  box-shadow: var(--shadow-md);
}

.empty-icon-wrap svg { width: 88px; height: 88px; }

.empty-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--tx1);
  letter-spacing: -.03em;
}

.empty-desc {
  font-size: 14px;
  color: var(--tx3);
  line-height: 1.6;
  font-weight: 400;
}

.empty-lock {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 8px 16px;
  background: var(--bg-page);
  border-radius: 20px;
  font-size: 12px;
  color: var(--tx3);
  font-weight: 500;
}
.empty-lock svg { width: 13px; height: 13px; }

/* Chat view */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Chat header */
.chat-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg-page);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.back-btn {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  color: var(--tx3);
  transition: background .12s;
}
.back-btn svg { width: 20px; height: 20px; }
.back-btn:hover { background: var(--hover); }

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

.chat-header-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--tx1);
  letter-spacing: -.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-sub {
  font-size: 12.5px;
  color: var(--tx3);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

/* Messages scroll area */
.messages-scroll {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-chat);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Crect width='200' height='200' fill='%23e5ddd5'/%3E%3Cpath d='M0 0l200 200M200 0L0 200' stroke='%23ddd5cd' stroke-width='.4' opacity='.4'/%3E%3C/svg%3E");
  background-size: 200px;
}

.messages-area {
  display: flex;
  flex-direction: column;
  padding: 12px 8%;
  min-height: 100%;
}

/* Date separator */
.date-sep {
  display: flex;
  justify-content: center;
  margin: 16px 0 8px;
}
.date-sep span {
  background: rgba(255,255,255,.88);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--tx3);
  box-shadow: var(--shadow-sm);
}

/* Message wrapper */
.msg-wrap {
  display: flex;
  flex-direction: column;
  margin-bottom: 2px;
}

.msg-wrap.sent  { align-items: flex-end; }
.msg-wrap.recv  { align-items: flex-start; }
.msg-wrap.first { margin-top: 4px; }
.msg-wrap.last  { margin-bottom: 8px; }

/* Sender label in groups */
.msg-sender-name {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 3px;
  padding-left: 4px;
}

/* Bubble */
.msg-bubble {
  position: relative;
  max-width: 65%;
  padding: 7px 9px 7px 9px;
  border-radius: var(--r-bubble);
  word-break: break-word;
  line-height: 1.45;
}

.sent .msg-bubble {
  background: var(--bubble-sent);
  border-top-right-radius: 2px;
  box-shadow: var(--shadow-sm);
}

.recv .msg-bubble {
  background: var(--bubble-recv);
  border-top-left-radius: 2px;
  box-shadow: var(--shadow-sm);
}

/* WhatsApp-style tail */
.sent .msg-bubble::after {
  content: '';
  position: absolute;
  top: 0;
  right: -8px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 8px 0 0 9px;
  border-color: transparent transparent transparent var(--bubble-sent);
}

.recv .msg-bubble::after {
  content: '';
  position: absolute;
  top: 0;
  left: -8px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 8px 9px 0 0;
  border-color: transparent var(--bubble-recv) transparent transparent;
}

/* No tail for consecutive messages */
.no-tail .msg-bubble::after { display: none; }
.sent.no-tail .msg-bubble  { border-top-right-radius: var(--r-bubble); }
.recv.no-tail .msg-bubble  { border-top-left-radius: var(--r-bubble); }

.msg-text {
  font-size: 14.5px;
  color: var(--tx1);
  white-space: pre-wrap;
  font-weight: 400;
  padding-right: 52px; /* leave room for timestamp */
}

/* Timestamp row inside bubble */
.msg-meta {
  display: flex;
  align-items: center;
  gap: 3px;
  float: right;
  margin: -4px -2px -2px 6px;
  position: relative;
}

.msg-time {
  font-size: 11px;
  color: var(--tx4);
  font-weight: 400;
  white-space: nowrap;
}

/* Tick marks for sent messages */
.msg-ticks {
  display: flex;
  align-items: center;
  color: var(--tx4);
}
.msg-ticks svg { width: 16px; height: 16px; }
.msg-ticks.read svg { color: #53bdeb; }

/* No messages placeholder */
.no-messages-yet {
  display: flex;
  justify-content: center;
  margin: auto;
  padding: 12px 20px;
  background: rgba(255,255,255,.88);
  border-radius: 8px;
  font-size: 13px;
  color: var(--tx3);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}


/* ═══════════════════════════════════════════════════════════
   INPUT ROW
═══════════════════════════════════════════════════════════ */
.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-page);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrap {
  flex: 1;
  background: var(--bg-surface);
  border-radius: 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  overflow: hidden;
}

.msg-input {
  flex: 1;
  padding: 11px 18px;
  border: none;
  background: transparent;
  font-size: 15px;
  color: var(--tx1);
  outline: none;
  min-width: 0;
}
.msg-input::placeholder { color: var(--tx4); }

.send-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  transition: background .15s, transform .08s, box-shadow .15s;
  box-shadow: 0 2px 8px rgba(0,168,132,.35);
}
.send-btn svg { width: 18px; height: 18px; margin-left: 2px; }
.send-btn:hover  { background: var(--accent-dark); box-shadow: 0 3px 12px rgba(0,168,132,.45); }
.send-btn:active { transform: scale(.93); }


/* ═══════════════════════════════════════════════════════════
   GROUP MODAL
═══════════════════════════════════════════════════════════ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11,20,26,.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn .15s ease;
  padding: 16px;
}
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

.modal {
  background: var(--bg-surface);
  border-radius: 16px;
  width: 480px;
  max-width: 100%;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideUp .2s cubic-bezier(.16,1,.3,1);
  overflow: hidden;
}
@keyframes slideUp {
  from { transform: translateY(20px); opacity: .7; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--tx1);
  letter-spacing: -.025em;
  flex: 1;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--tx3);
  transition: background .12s;
}
.modal-close svg { width: 16px; height: 16px; }
.modal-close:hover { background: var(--hover); color: var(--tx1); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.modal-sect { display: flex; flex-direction: column; gap: 8px; }

.modal-label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--tx4);
  letter-spacing: .06em;
  text-transform: uppercase;
}

/* Chips */
.chips-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 6px 5px 10px;
  background: rgba(0,168,132,.1);
  border: 1px solid rgba(0,168,132,.2);
  border-radius: 20px;
  animation: chipIn .15s ease;
}
@keyframes chipIn { from { transform: scale(.85); opacity:0; } to { transform: scale(1); opacity:1; } }

.chip-label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--accent-dark);
}

.chip-remove {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,168,132,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-dark);
  font-size: 14px;
  line-height: 1;
  transition: background .12s;
  flex-shrink: 0;
}
.chip-remove:hover { background: rgba(0,168,132,.38); }

/* Modal search */
.modal-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.modal-search-wrap svg {
  position: absolute;
  left: 11px;
  width: 15px;
  height: 15px;
  color: var(--tx4);
  pointer-events: none;
}
.modal-search-input {
  width: 100%;
  padding: 10px 12px 10px 34px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  font-size: 14px;
  color: var(--tx1);
  background: var(--input-bg);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.modal-search-input::placeholder { color: var(--tx4); }
.modal-search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

/* Modal user list */
.modal-user-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
}

.modal-user-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .1s;
}
.modal-user-item:hover    { background: var(--hover); }
.modal-user-item.selected { background: rgba(0,168,132,.08); }

.modal-user-item-info { flex: 1; min-width: 0; }
.modal-user-item-name  { font-size: 14.5px; font-weight: 600; color: var(--tx1); }
.modal-user-item-email { font-size: 12.5px; color: var(--tx3); margin-top: 1px; }

.check-box {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all .15s;
}
.modal-user-item.selected .check-box {
  background: var(--accent);
  border-color: var(--accent);
}
.check-box svg { width: 12px; height: 12px; display: none; }
.modal-user-item.selected .check-box svg { display: block; }

.modal-search-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 10px;
  font-size: 13.5px;
  color: var(--tx3);
  font-weight: 500;
}
.modal-search-loading svg { flex-shrink: 0; }
.spin { animation: spin .7s linear infinite; }

.modal-search-empty {
  padding: 16px 10px;
  font-size: 13.5px;
  color: var(--tx4);
  font-weight: 500;
}

.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}


/* ═══════════════════════════════════════════════════════════
   TOAST
═══════════════════════════════════════════════════════════ */
#toast-root {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  padding: 11px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  animation: toastIn .2s cubic-bezier(.16,1,.3,1);
}
@keyframes toastIn {
  from { transform: translateY(12px); opacity:0; }
  to   { transform: translateY(0);    opacity:1; }
}
.toast.out { animation: toastOut .2s ease forwards; }
@keyframes toastOut {
  to { transform: translateY(8px); opacity:0; }
}
.toast.success { background: #1f7a1f; }
.toast.error   { background: #c0392b; }
.toast.info    { background: #2c3e50; }


/* ═══════════════════════════════════════════════════════════
   MOBILE  (≤ 720px)
═══════════════════════════════════════════════════════════ */
@media (max-width: 720px) {
  :root { --sb-width: 100%; }

  .sidebar {
    position: absolute;
    inset: 0;
    z-index: 10;
    transition: transform .25s cubic-bezier(.4,0,.2,1);
  }
  .sidebar.slide-out { transform: translateX(-100%); }

  .chat-panel {
    position: absolute;
    inset: 0;
    z-index: 9;
    transform: translateX(100%);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
  }
  .chat-panel.slide-in { transform: translateX(0); }

  .back-btn { display: flex !important; }

  .messages-area { padding: 10px 4%; }
}


/* ═══════════════════════════════════════════════════════════
   NEW ADDITIONS
═══════════════════════════════════════════════════════════ */

/* Tick marks */
.msg-ticks { display:flex; align-items:center; color:var(--tx4); flex-shrink:0; }
.msg-ticks svg { width:18px; height:11px; }
.msg-ticks.read { color:#53bdeb; }

/* System messages (join/leave/created) */
.system-msg {
  display: flex;
  justify-content: center;
  margin: 10px 0 4px;
}
.system-msg span {
  background: rgba(255,255,255,.75);
  border-radius: 8px;
  padding: 5px 14px;
  font-size: 12px;
  color: var(--tx3);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
  font-style: italic;
}

/* Leave group button in header */
.leave-group-btn {
  color: #c0392b !important;
  flex-shrink: 0;
}
.leave-group-btn:hover { background: #fef2f2 !important; }

/* Char counter */
.char-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--tx4);
  min-width: 28px;
  text-align: right;
  flex-shrink: 0;
  align-self: center;
}

/* Inline field error (group name) */
.field-inline-error {
  font-size: 12px;
  color: #dc2626;
  font-weight: 500;
  margin-top: -2px;
  padding: 0 2px;
}

/* Confirm modal (small) */
.modal-sm { max-width: 380px !important; }
.confirm-body-text {
  font-size: 14px;
  color: var(--tx2);
  line-height: 1.6;
  font-weight: 400;
}

/* Danger button */
.btn-danger {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  background: #dc2626;
  color: #fff;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 700;
  transition: background .15s;
}
.btn-danger:hover  { background: #b91c1c; }
.btn-danger:active { transform: scale(.99); }

/* Emoji reactions */
.reactions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 3px;
  padding: 0 4px;
}
.sent .reactions-row { justify-content: flex-end; }
.recv .reactions-row { justify-content: flex-start; }

.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  background: rgba(255,255,255,.85);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 13px;
  cursor: pointer;
  transition: all .12s;
  user-select: none;
  box-shadow: var(--shadow-sm);
}
.reaction-chip:hover { background: var(--hover); border-color: var(--border-md); transform: scale(1.08); }
.reaction-chip.mine  { background: rgba(0,168,132,.12); border-color: var(--accent); }

/* Reaction picker popup */
.reaction-picker {
  position: absolute;
  display: flex;
  gap: 2px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 5px 8px;
  box-shadow: var(--shadow-md);
  z-index: 100;
  bottom: calc(100% + 6px);
  left: 0;
  animation: popIn .12s cubic-bezier(.16,1,.3,1);
}
.sent .reaction-picker { left: auto; right: 0; }
@keyframes popIn { from { transform: scale(.8); opacity:0; } to { transform: scale(1); opacity:1; } }

.reaction-emoji-btn {
  font-size: 20px;
  padding: 4px 5px;
  border-radius: 50%;
  transition: transform .1s, background .1s;
  line-height: 1;
}
.reaction-emoji-btn:hover { transform: scale(1.3); background: var(--hover); }

/* Conv preview system italic */
.conv-preview-system { font-style: italic; color: var(--tx4); }

/* Ensure msg-wrap is positioned for picker */
.msg-wrap { position: relative; }
