:root {
  --red: #e4002b;
  --red-hover: #ff2c4e;
  --red-rgb: 228, 0, 43;
  --white: #ffffff;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 28px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur-fast: 0.15s;
  --dur-med: 0.28s;
}

/* ---------- Theme tokens: dark (default) ---------- */
:root,
:root[data-theme="dark"] {
  --bg: #0a0a0c;
  --bg-rgb: 10, 10, 12;
  --bg-gradient: radial-gradient(circle at 15% 0%, rgba(228, 0, 43, 0.16) 0%, transparent 45%),
    radial-gradient(circle at 85% 100%, rgba(228, 0, 43, 0.08) 0%, transparent 50%), var(--bg);

  --glass-bg: rgba(255, 255, 255, 0.055);
  --glass-bg-strong: rgba(255, 255, 255, 0.09);
  --glass-border: rgba(255, 255, 255, 0.10);
  --glass-hover: rgba(255, 255, 255, 0.09);

  --text: #f5f5f7;
  --text-dim: #a4a4ac;
  --text-faint: #6f6f78;

  --bubble-theirs: rgba(255, 255, 255, 0.07);
  --bubble-theirs-border: rgba(255, 255, 255, 0.09);
  --bubble-mine: rgba(228, 0, 43, 0.28);
  --bubble-mine-border: rgba(228, 0, 43, 0.4);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5), 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-red: 0 8px 24px rgba(228, 0, 43, 0.28);

  --scrim: rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

/* ---------- Theme tokens: light ---------- */
:root[data-theme="light"] {
  --bg: #f2f2f5;
  --bg-rgb: 242, 242, 245;
  --bg-gradient: radial-gradient(circle at 15% 0%, rgba(228, 0, 43, 0.10) 0%, transparent 45%),
    radial-gradient(circle at 85% 100%, rgba(228, 0, 43, 0.06) 0%, transparent 50%), var(--bg);

  --glass-bg: rgba(255, 255, 255, 0.55);
  --glass-bg-strong: rgba(255, 255, 255, 0.75);
  --glass-border: rgba(20, 20, 25, 0.08);
  --glass-hover: rgba(255, 255, 255, 0.85);

  --text: #17171a;
  --text-dim: #5c5c66;
  --text-faint: #8a8a94;

  --bubble-theirs: rgba(255, 255, 255, 0.65);
  --bubble-theirs-border: rgba(20, 20, 25, 0.07);
  --bubble-mine: rgba(228, 0, 43, 0.12);
  --bubble-mine-border: rgba(228, 0, 43, 0.28);

  --shadow-sm: 0 1px 2px rgba(20, 20, 30, 0.06);
  --shadow-md: 0 8px 24px rgba(20, 20, 30, 0.10), 0 2px 6px rgba(20, 20, 30, 0.06);
  --shadow-lg: 0 20px 60px rgba(20, 20, 30, 0.16), 0 6px 20px rgba(20, 20, 30, 0.08);
  --shadow-red: 0 8px 24px rgba(228, 0, 43, 0.18);

  --scrim: rgba(20, 20, 25, 0.35);
  color-scheme: light;
}

* { box-sizing: border-box; }

/* Elements that toggle visibility via the `hidden` attribute also carry an explicit
   `display` rule for their visible state (flex/grid/etc). Author-stylesheet class
   rules and the UA default `[hidden] { display: none }` rule have equal specificity,
   so without this the later-defined class rule would win and the element would stay
   visible. Force `hidden` to always win. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--dur-med) var(--ease), color var(--dur-med) var(--ease);
}

button, input, select {
  font-family: inherit;
  color: inherit;
}

a { color: var(--red); text-decoration: none; }
a:hover { color: var(--red-hover); }

::selection { background: rgba(var(--red-rgb), 0.35); }

*:focus-visible {
  outline: 2px solid rgba(var(--red-rgb), 0.6);
  outline-offset: 2px;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(10px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes scale-in {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes pulse-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-3px); opacity: 1; }
}

/* ---------- Glass surface helper ---------- */

.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border: 1px solid var(--glass-border);
}

/* ---------- Theme toggle ---------- */

.theme-toggle {
  position: relative;
  width: 34px; height: 34px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text);
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--glass-hover); box-shadow: var(--shadow-sm); }
.theme-toggle:active { transform: scale(0.92); }
.theme-toggle svg { width: 17px; height: 17px; transition: transform var(--dur-med) var(--ease), opacity var(--dur-med) var(--ease); }
.theme-toggle .icon-moon { position: absolute; }
:root[data-theme="dark"] .theme-toggle .icon-sun { opacity: 0; transform: rotate(90deg) scale(0.5); }
:root[data-theme="dark"] .theme-toggle .icon-moon { opacity: 1; transform: rotate(0) scale(1); }
:root[data-theme="light"] .theme-toggle .icon-sun { opacity: 1; transform: rotate(0) scale(1); }
:root[data-theme="light"] .theme-toggle .icon-moon { opacity: 0; transform: rotate(-90deg) scale(0.5); }

/* ---------- Auth pages ---------- */

.auth-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
}

.auth-page .theme-toggle { position: absolute; top: 24px; right: 24px; }

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(32px) saturate(160%);
  -webkit-backdrop-filter: blur(32px) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
  animation: pop-in var(--dur-med) var(--ease) both;
}

.auth-card h1 { font-size: 23px; margin: 4px 0; letter-spacing: -0.3px; }
.auth-sub { color: var(--text-dim); margin: 0 0 26px; font-size: 14px; }

.auth-form { display: flex; flex-direction: column; gap: 15px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }

.auth-form input {
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 15px;
  outline: none;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.auth-form input:focus { border-color: rgba(var(--red-rgb), 0.6); box-shadow: 0 0 0 4px rgba(var(--red-rgb), 0.12); }

.auth-error { color: var(--red-hover); font-size: 13px; margin: 0; animation: rise-in var(--dur-fast) var(--ease) both; }
.auth-switch { text-align: center; margin-top: 20px; font-size: 13px; color: var(--text-dim); }

.btn-primary {
  background: var(--red);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-red);
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.btn-primary:hover { background: var(--red-hover); transform: translateY(-1px); box-shadow: 0 12px 28px rgba(var(--red-rgb), 0.32); }
.btn-primary:active { transform: translateY(0) scale(0.98); }

.btn-ghost {
  background: var(--glass-bg);
  color: var(--text-dim);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.btn-ghost:hover { color: var(--text); background: var(--glass-hover); }

/* ---------- Brand ---------- */

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 36px; height: 36px;
  border-radius: 11px;
  background: var(--red);
  color: var(--white);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; letter-spacing: -0.5px;
  box-shadow: var(--shadow-red);
}
.brand-mark.large { width: 76px; height: 76px; border-radius: 22px; font-size: 27px; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -0.2px; }

/* ---------- App shell ---------- */

.app-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  background: var(--glass-bg);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 16px 14px;
  gap: 10px;
}
.sidebar-header .brand { flex: 1; min-width: 0; }
.sidebar-header-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--text);
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--glass-hover); box-shadow: var(--shadow-sm); }
.icon-btn:active { transform: scale(0.92); }

.search-box { padding: 0 16px 14px; position: relative; }
.search-box input {
  width: 100%;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  outline: none;
  font-size: 14px;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.search-box input:focus { border-color: rgba(var(--red-rgb), 0.6); box-shadow: 0 0 0 4px rgba(var(--red-rgb), 0.12); }

.search-results {
  position: absolute;
  left: 16px; right: 16px; top: 100%;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: 240px;
  overflow-y: auto;
  z-index: 5;
  animation: rise-in var(--dur-fast) var(--ease) both;
}
.search-result-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}
.search-result-item:hover { background: var(--glass-hover); }

.conversation-list { flex: 1; overflow-y: auto; padding: 4px 8px; scroll-behavior: smooth; }

.conversation-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  margin-bottom: 3px;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.conversation-item:hover { background: var(--glass-bg-strong); }
.conversation-item.active { background: var(--glass-hover); box-shadow: var(--shadow-sm); }
.conversation-item:active { transform: scale(0.985); }

.avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: var(--text-dim);
  flex-shrink: 0;
  object-fit: cover;
}

.conversation-meta { min-width: 0; flex: 1; }
.conversation-name {
  font-weight: 600; font-size: 14.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conversation-preview {
  font-size: 13px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.sidebar-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-top: 1px solid var(--glass-border);
  gap: 8px;
}
.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.me-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* ---------- Chat pane ---------- */

.chat-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.chat-empty {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px;
  color: var(--text-faint);
  animation: fade-in var(--dur-med) var(--ease) both;
}

.chat-active { display: flex; flex-direction: column; height: 100%; min-height: 0; animation: fade-in var(--dur-fast) var(--ease) both; }

.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  background: var(--glass-bg);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  border-bottom: 1px solid var(--glass-border);
}
.back-btn { display: none; }
.chat-title { font-weight: 700; font-size: 15px; }
.chat-subtitle { font-size: 12.5px; color: var(--text-dim); }
.chat-header-actions { display: flex; gap: 8px; margin-left: auto; }

/* ---------- Calls ---------- */

.call-btn {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  background: var(--glass-bg-strong);
  color: var(--text);
  border: 1px solid var(--glass-border);
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.call-btn:hover { transform: scale(1.06); }
.call-btn:active { transform: scale(0.94); }
.call-btn.active { background: rgba(var(--red-rgb), 0.28); border-color: rgba(var(--red-rgb), 0.5); }
.call-btn.accept { background: #1fa855; color: var(--white); border: none; }
.call-btn.accept:hover { background: #24c265; }
.call-btn.decline { background: var(--red); color: var(--white); border: none; }
.call-btn.decline:hover { background: var(--red-hover); }

.incoming-call {
  position: fixed;
  top: 24px; right: 24px;
  width: 260px;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(32px) saturate(160%);
  -webkit-backdrop-filter: blur(32px) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-lg);
  z-index: 40;
  text-align: center;
  animation: pop-in var(--dur-med) var(--ease) both;
}
.incoming-call .avatar.large { width: 64px; height: 64px; font-size: 20px; margin: 0 auto 10px; }
.incoming-call-name { font-weight: 700; font-size: 15px; }
.incoming-call-type { font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.incoming-call-actions { display: flex; justify-content: center; gap: 16px; margin-top: 16px; }

.call-overlay {
  position: fixed;
  inset: 0;
  background: #0a0a0c;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in var(--dur-fast) var(--ease) both;
}
.call-remote-video {
  width: 100%; height: 100%;
  object-fit: cover;
  background: #111;
}
.call-local-video {
  position: absolute;
  bottom: 110px; right: 24px;
  width: 140px; height: 190px;
  object-fit: cover;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: var(--shadow-lg);
  background: #1a1a1a;
}
.call-status {
  position: absolute;
  top: 32px; left: 50%;
  transform: translateX(-50%);
  color: var(--white);
  font-size: 15px;
  font-weight: 600;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.call-controls {
  position: absolute;
  bottom: 32px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 18px;
}

.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex; flex-direction: column; gap: 4px;
  scroll-behavior: smooth;
}

.message-row { display: flex; margin: 4px 0; animation: pop-in var(--dur-med) var(--ease) both; }
.message-row.mine { justify-content: flex-end; }

.bubble {
  max-width: 62%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--bubble-theirs);
  border: 1px solid var(--bubble-theirs-border);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  font-size: 14.5px;
  line-height: 1.4;
  word-wrap: break-word;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast) var(--ease);
}
.bubble:hover { transform: translateY(-1px); }
.message-row.active .bubble { box-shadow: 0 0 0 2px var(--red), var(--shadow-md); }
.message-row.mine .bubble {
  background: var(--bubble-mine);
  border: 1px solid var(--bubble-mine-border);
  border-bottom-right-radius: 6px;
}
.message-row:not(.mine) .bubble { border-bottom-left-radius: 6px; }
.bubble .meta {
  display: block;
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 4px;
}
.bubble img { max-width: 100%; border-radius: var(--radius-sm); margin-top: 4px; display: block; }
.bubble a.file-link { color: var(--red-hover); }
.bubble audio { max-width: 100%; margin-top: 4px; display: block; height: 36px; }

.bubble .ticks { display: inline-flex; margin-left: 4px; font-size: 11px; letter-spacing: -2px; color: var(--text-faint); }
.bubble .ticks.read { color: var(--red); }

.bubble .reply-quote {
  border-left: 2px solid rgba(var(--red-rgb), 0.5);
  padding: 4px 8px;
  margin-bottom: 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.08);
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bubble .star-indicator { margin-left: 4px; }

.message-row {
  position: relative;
}
.message-actions {
  display: none;
  position: absolute;
  top: -16px;
  gap: 2px;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 3px;
  box-shadow: var(--shadow-md);
  z-index: 2;
}
.message-row:not(.mine) .message-actions { left: 8px; }
.message-row.mine .message-actions { right: 8px; }
.message-row:hover .message-actions { display: flex; }
.message-action-btn {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.message-action-btn:hover { background: var(--glass-hover); transform: scale(1.08); }
.message-action-btn.active { color: var(--red); }

.reaction-picker {
  position: absolute;
  top: -52px;
  display: flex;
  gap: 4px;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 6px;
  box-shadow: var(--shadow-md);
  z-index: 3;
  animation: pop-in var(--dur-fast) var(--ease) both;
}
.reaction-picker button {
  width: 28px; height: 28px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  border-radius: 50%;
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.reaction-picker button:hover { transform: scale(1.2); background: var(--glass-hover); }

.reaction-pills { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.reaction-pill {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  font-size: 12px;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.reaction-pill:hover { transform: translateY(-1px); }
.reaction-pill.mine { border-color: rgba(var(--red-rgb), 0.5); background: rgba(var(--red-rgb), 0.14); }

.reply-bar, .recording-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: var(--glass-bg);
  border-top: 1px solid var(--glass-border);
  font-size: 13px;
}
.reply-bar-content { flex: 1; color: var(--text-dim); border-left: 2px solid var(--red); padding-left: 8px; }
.recording-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--red);
  animation: pulse-dot 1s ease-in-out infinite;
  flex-shrink: 0;
}
.recording-hint { flex: 1; color: var(--text-dim); }

.thread-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 360px;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(32px) saturate(160%);
  -webkit-backdrop-filter: blur(32px) saturate(160%);
  border-left: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  z-index: 15;
  box-shadow: var(--shadow-lg);
  animation: rise-in var(--dur-med) var(--ease) both;
}
.thread-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--glass-border);
  font-weight: 700;
}
.thread-root { padding: 14px 20px; border-bottom: 1px solid var(--glass-border); }
.thread-panel .message-list { flex: 1; padding: 14px 20px; }
.thread-panel .composer { padding: 12px 16px; }

.forward-list { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.forward-list-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.forward-list-item:hover { background: var(--glass-hover); }
.forward-list-item.selected { background: rgba(var(--red-rgb), 0.16); }

.typing-indicator { font-size: 12.5px; color: var(--text-dim); padding: 0 20px 6px; height: 16px; display: flex; align-items: center; gap: 6px; }
.typing-indicator.live::before {
  content: "";
  display: inline-flex;
}
.typing-dots { display: inline-flex; gap: 3px; align-items: center; }
.typing-dots span {
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--text-dim);
  animation: pulse-dot 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

.composer {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 20px;
  background: var(--glass-bg);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  border-top: 1px solid var(--glass-border);
}
.composer input[type="text"] {
  flex: 1;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 12px 17px;
  outline: none;
  font-size: 14.5px;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.composer input[type="text"]:focus { border-color: rgba(var(--red-rgb), 0.6); box-shadow: 0 0 0 4px rgba(var(--red-rgb), 0.12); }

.btn-send {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--red);
  color: var(--white);
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: var(--shadow-red);
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn-send:hover { background: var(--red-hover); transform: scale(1.06); }
.btn-send:active { transform: scale(0.94); }

/* ---------- Modal ---------- */

.modal {
  position: fixed; inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 20;
  padding: 20px;
  animation: fade-in var(--dur-fast) var(--ease) both;
}
.modal-card {
  background: var(--glass-bg-strong);
  backdrop-filter: blur(32px) saturate(160%);
  -webkit-backdrop-filter: blur(32px) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  padding: 26px;
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: var(--shadow-lg);
  animation: scale-in var(--dur-med) var(--ease) both;
}
.modal-card h2 { margin: 0; font-size: 18px; }
.modal-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
.modal-card input, .modal-card select {
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  font-size: 14px;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.modal-card input:focus, .modal-card select:focus { border-color: rgba(var(--red-rgb), 0.6); box-shadow: 0 0 0 4px rgba(var(--red-rgb), 0.12); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ---------- Responsive ---------- */

@media (min-width: 769px) and (max-width: 1080px) {
  .app-shell { grid-template-columns: 280px 1fr; }
}

@media (max-width: 768px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0; z-index: 10; }
  .sidebar.hidden-mobile { display: none; }
  .chat-pane { position: fixed; inset: 0; z-index: 9; background: var(--bg-gradient); }
  .chat-pane.hidden-mobile { display: none; }
  .back-btn { display: flex; }
  .bubble { max-width: 80%; }
  .thread-panel { width: 100%; }
  .incoming-call { left: 16px; right: 16px; width: auto; top: 16px; }
  .call-local-video { width: 96px; height: 130px; bottom: 100px; right: 16px; }
}

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