/* =====================================================================
   EasyTalk — design system
   Tokens · components · layout · animation · responsive (mobile-first)
   ===================================================================== */

:root {
  /* dark (default) */
  --bg: #0c0d11;
  --surface-1: #131419;
  --surface-2: #17181e;
  --surface-3: #1e2027;
  --surface-4: #262932;
  --surface-hover: #22242c;
  --border: #24262f;
  --border-strong: #33363f;

  --text: #eceef3;
  --text-2: #9aa1ae;
  --text-3: #676d79;

  --accent: #6366f1;
  --accent-strong: #7c80f7;
  --accent-contrast: #ffffff;
  --ring: rgba(99, 102, 241, 0.45);

  --ok: #3fb950;
  --warn: #d9a021;
  --danger: #f0555f;
  --danger-strong: #f4707a;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .28), 0 6px 22px rgba(0, 0, 0, .28);
  --shadow-2: 0 12px 48px rgba(0, 0, 0, .5);
  --shadow-pop: 0 8px 30px rgba(0, 0, 0, .4);

  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --radius-lg: 20px;

  --sidebar-w: 288px;
  --header-h: 56px;
  --ease: cubic-bezier(.22, .68, .24, 1);

  color-scheme: dark;
}

:root[data-theme="midnight"] {
  --bg: #06070f;
  --surface-1: #0b0d1a;
  --surface-2: #0e1120;
  --surface-3: #141830;
  --surface-4: #1c2246;
  --surface-hover: #191e3c;
  --border: #1b2140;
  --border-strong: #2a3363;
  --text: #e8ebf7;
  --text-2: #97a1c4;
  --text-3: #5e6790;
  --accent: #5b8cff;
  --accent-strong: #7aa2ff;
  --ring: rgba(91, 140, 255, 0.45);
  --shadow-2: 0 12px 48px rgba(0, 0, 8, .6);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #e9ebf1;
  --surface-1: #f5f6f9;
  --surface-2: #ffffff;
  --surface-3: #ffffff;
  --surface-4: #eef0f5;
  --surface-hover: #eef0f5;
  --border: #e2e5ec;
  --border-strong: #cfd4de;
  --text: #191c22;
  --text-2: #5b636f;
  --text-3: #8b93a0;
  --accent: #5457ee;
  --accent-strong: #4447e6;
  --accent-contrast: #ffffff;
  --ring: rgba(84, 87, 238, 0.35);
  --ok: #16a34a;
  --warn: #c98a12;
  --danger: #e23b46;
  --shadow-1: 0 1px 2px rgba(20, 24, 40, .06), 0 8px 24px rgba(20, 24, 40, .08);
  --shadow-2: 0 16px 50px rgba(20, 24, 40, .18);
  --shadow-pop: 0 10px 34px rgba(20, 24, 40, .14);
  color-scheme: light;
}

/* --------------------------------- reset -------------------------------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #root { height: 100%; }
#root {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
#root > .shell,
#root > .auth-wrap { height: 100%; }

body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  letter-spacing: -0.006em;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { letter-spacing: -0.02em; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--surface-4);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); background-clip: padding-box; }

/* ------------------------------ form fields ---------------------------- */
input, textarea, .input {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 11px 13px;
  width: 100%;
  outline: none;
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease), background .16s;
}
:root[data-theme="light"] input,
:root[data-theme="light"] textarea { background: #fff; }
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}
select {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 8px 10px;
  outline: none;
}

.field { margin-bottom: 15px; }
.field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-2);
  margin-bottom: 7px;
}

/* -------------------------------- buttons ----------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: var(--accent-contrast);
  border-radius: var(--radius-xs);
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .18);
  transition: transform .12s var(--ease), box-shadow .16s var(--ease), background .16s, opacity .16s, filter .16s;
}
.btn:hover { filter: brightness(1.07); box-shadow: 0 4px 16px var(--ring); }
.btn:active { transform: translateY(1px) scale(.985); }
.btn:disabled { opacity: .55; cursor: not-allowed; filter: none; box-shadow: none; }

.btn.ghost {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
}
.btn.ghost:hover { background: var(--surface-4); filter: none; box-shadow: inset 0 0 0 1px var(--border-strong); }

.btn.subtle { background: transparent; color: var(--text-2); box-shadow: none; }
.btn.subtle:hover { background: var(--surface-3); color: var(--text); filter: none; box-shadow: none; }

.btn.danger { background: linear-gradient(180deg, var(--danger-strong), var(--danger)); color: #fff; }

.btn.sm { padding: 6px 11px; font-size: 12.5px; border-radius: var(--radius-xs); }
.btn.icon {
  padding: 0;
  width: 38px; height: 38px;
  border-radius: 12px;
  background: transparent;
  color: var(--text-2);
  box-shadow: none;
  font-size: 17px;
}
.btn.icon:hover { background: var(--surface-3); color: var(--text); filter: none; box-shadow: none; }
.btn.icon:active { transform: scale(.9); }

/* ------------------------------- avatars ----------------------------- */
.avatar {
  width: 40px; height: 40px; min-width: 40px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 15px; color: #fff;
  position: relative;
  overflow: hidden;
  user-select: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 88px; height: 88px; min-width: 88px; font-size: 32px; border-radius: 28px; }
.avatar.sm { width: 30px; height: 30px; min-width: 30px; font-size: 12px; }
.status-dot {
  position: absolute;
  right: -2px; bottom: -2px;
  width: 13px; height: 13px;
  border-radius: 50%;
  border: 3px solid var(--surface-1);
  background: var(--text-3);
  transition: background .2s;
}
.avatar.lg .status-dot { width: 22px; height: 22px; border-width: 4px; right: 2px; bottom: 2px; }
.status-dot.online { background: var(--ok); }
.status-dot.away { background: var(--warn); }
.status-dot.dnd { background: var(--danger); }

/* -------------------------------- badges ---------------------------- */
.badge {
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 3px var(--surface-1);
}
.badge.voice { background: var(--ok); }
.row-badges { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.row-badges:empty { display: none; }

.hide { display: none !important; }

/* =====================================================================
   AUTH
   ===================================================================== */
.auth-wrap {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 20px;
  background:
    radial-gradient(900px 500px at 15% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%),
    radial-gradient(800px 500px at 100% 110%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-2);
}
.auth-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 17px;
  margin-bottom: 22px;
}
.auth-brand .mark {
  width: 34px; height: 34px;
  border-radius: 11px;
  background: linear-gradient(150deg, var(--accent-strong), var(--accent));
  display: grid; place-items: center;
  color: #fff; font-size: 18px;
  box-shadow: 0 6px 18px var(--ring);
}
.auth-card h1 { font-size: 23px; margin-bottom: 6px; }
.auth-card .sub { color: var(--text-2); font-size: 14px; margin-bottom: 22px; line-height: 1.5; }
.strength { height: 6px; border-radius: 4px; background: var(--surface-1); margin-top: 9px; overflow: hidden; }
.strength > i { display: block; height: 100%; width: 0; border-radius: 4px; transition: width .3s var(--ease), background .3s; }
.form-msg { font-size: 13px; margin: 10px 0 2px; min-height: 18px; color: var(--text-2); }
.form-msg.err { color: var(--danger-strong); }
.form-msg.ok { color: var(--ok); }
.auth-switch { margin-top: 18px; font-size: 14px; color: var(--text-2); text-align: center; }
.link-btn { color: var(--accent-strong); font-weight: 600; }
.link-btn:hover { text-decoration: underline; }

/* =====================================================================
   APP SHELL
   ===================================================================== */
.shell { display: flex; height: 100%; position: relative; overflow: hidden; background: var(--bg); }

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface-1);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 30;
  transform: translateX(-100%);
  transition: transform .28s var(--ease);
  will-change: transform;
}
.sidebar.open { transform: translateX(0); box-shadow: var(--shadow-2); }
.scrim {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(2px);
  z-index: 25;
  opacity: 0; pointer-events: none;
  transition: opacity .24s var(--ease);
}
.scrim.show { opacity: 1; pointer-events: auto; }

.sidebar-head {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  font-weight: 800;
  font-size: 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-head .mark {
  width: 28px; height: 28px;
  border-radius: 9px;
  background: linear-gradient(150deg, var(--accent-strong), var(--accent));
  display: grid; place-items: center;
  color: #fff; font-size: 15px;
  box-shadow: 0 4px 14px var(--ring);
}

.side-search { padding: 12px 12px 6px; position: relative; }
.side-search input {
  background: var(--surface-3);
  border-color: transparent;
  padding: 9px 12px 9px 34px;
  font-size: 13px;
  border-radius: var(--radius-xs);
}
.side-search::before {
  content: "⌕";
  position: absolute;
  left: 24px; top: 21px;
  color: var(--text-3);
  font-size: 15px;
  pointer-events: none;
}
.side-search .search-results {
  margin-top: 6px;
  display: flex; flex-direction: column; gap: 2px;
}

.side-tabs {
  display: flex;
  gap: 4px;
  margin: 8px 12px 4px;
  background: var(--surface-3);
  border-radius: var(--radius-xs);
  padding: 4px;
}
.side-tabs button {
  flex: 1;
  padding: 8px;
  border-radius: 7px;
  color: var(--text-2);
  font-weight: 600;
  font-size: 13px;
  transition: background .18s var(--ease), color .18s, box-shadow .18s;
}
.side-tabs button:hover { color: var(--text); }
.side-tabs button.active {
  background: var(--surface-1);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

.side-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 6px 10px 14px; }

.side-section-title {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text-3);
  letter-spacing: .07em;
  padding: 16px 8px 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.side-section-title button {
  color: var(--text-3);
  font-size: 18px;
  line-height: 1;
  width: 22px; height: 22px;
  border-radius: 6px;
  transition: background .16s, color .16s, transform .16s;
}
.side-section-title button:hover { color: var(--text); background: var(--surface-3); transform: rotate(90deg); }

.side-empty { padding: 8px; color: var(--text-3); font-size: 13px; }

.conv-item, .friend-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  position: relative;
  transition: background .15s var(--ease), transform .12s var(--ease);
}
.conv-item:hover, .friend-row:hover { background: var(--surface-3); }
.conv-item:active { transform: scale(.99); }
.conv-item.active { background: var(--surface-4); }
.conv-item.active::before {
  content: "";
  position: absolute;
  left: -10px; top: 50%;
  width: 4px; height: 22px;
  border-radius: 0 4px 4px 0;
  background: var(--accent);
  transform: translateY(-50%);
  animation: barIn .22s var(--ease);
}
.conv-item .meta, .friend-row .meta { min-width: 0; flex: 1; }
.conv-item .name, .friend-row .name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item .preview, .friend-row .preview {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-transform: capitalize;
}
.conv-item .preview { text-transform: none; }

/* profile / settings entry at sidebar foot */
.me-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin: 6px;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  cursor: pointer;
  transition: background .16s var(--ease), transform .12s var(--ease);
}
.me-bar:hover { background: var(--surface-4); }
.me-bar:active { transform: scale(.99); }
.me-bar .meta { flex: 1; min-width: 0; }
.me-bar .name { font-weight: 700; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-bar .st { font-size: 11.5px; color: var(--text-3); text-transform: capitalize; }
.me-bar .cog {
  color: var(--text-3);
  font-size: 17px;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 8px;
  transition: color .16s, transform .3s var(--ease);
}
.me-bar:hover .cog { color: var(--text); transform: rotate(60deg); }

/* --------------------------------- main ----------------------------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface-2);
}
.topbar {
  height: var(--header-h);
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  z-index: 5;
}
.topbar .hamburger {
  font-size: 20px;
  width: 36px; height: 36px;
  border-radius: 10px;
  color: var(--text-2);
  display: grid; place-items: center;
  transition: background .16s, color .16s;
}
.topbar .hamburger:hover { background: var(--surface-3); color: var(--text); }
.topbar .title { font-weight: 700; font-size: 15px; flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar .title > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { font-size: 11.5px; color: var(--text-3); font-weight: 500; text-transform: capitalize; }
.topbar .actions { display: flex; gap: 4px; align-items: center; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  scroll-behavior: smooth;
}
.msg-load-more { text-align: center; padding: 10px; }
.day-sep {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin: 16px 4px 8px;
}
.day-sep::before, .day-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.msg-wrap { display: block; }
.msg {
  display: flex;
  gap: 14px;
  padding: 5px 10px;
  border-radius: 10px;
  position: relative;
  transition: background .12s;
}
.msg:hover { background: color-mix(in srgb, var(--surface-4) 55%, transparent); }
.msg.grouped { padding-top: 1px; padding-bottom: 1px; }
/* grouping is a pure class toggle — every part stays in the DOM, one 40px gutter always */
.msg .msg-time-inline { display: none; }
.msg.grouped .msg-avatar { display: none; }
.msg.grouped .msg-time-inline { display: block; visibility: hidden; }
.msg.grouped:hover .msg-time-inline { visibility: visible; }
.msg.grouped .msg-head { display: none; }
.msg-time-inline {
  font-size: 10px;
  color: var(--text-3);
  width: 40px; min-width: 40px;
  text-align: right;
  padding-top: 3px;
}
.msg-avatar { width: 40px; min-width: 40px; }
.msg-body { min-width: 0; flex: 1; }
.msg-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 1px; }
.msg-author { font-weight: 700; font-size: 14px; }
.msg-time { font-size: 11px; color: var(--text-3); }
.msg-text { font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; color: var(--text); }
.msg-text a { text-decoration: underline; text-underline-offset: 2px; }
.msg-text .edited { font-size: 10px; color: var(--text-3); margin-left: 5px; }
.msg-text.deleted { color: var(--text-3); font-style: italic; }
.msg-text textarea { margin-top: 4px; }

.msg--enter { animation: msgIn .26s var(--ease); }

.msg-actions {
  position: absolute;
  right: 10px; top: -14px;
  display: flex;
  gap: 2px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  box-shadow: var(--shadow-pop);
  opacity: 0;
  transform: translateY(4px) scale(.96);
  pointer-events: none;
  transition: opacity .14s var(--ease), transform .14s var(--ease);
}
.msg:hover .msg-actions { opacity: 1; transform: none; pointer-events: auto; }
.msg-actions button {
  padding: 6px 8px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--text-2);
  transition: background .14s, color .14s;
}
.msg-actions button:hover { background: var(--surface-4); color: var(--text); }

.attach {
  margin-top: 7px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  max-width: 420px;
  display: block;
}
.attach img { display: block; max-width: 100%; max-height: 340px; object-fit: contain; background: #000; }
.attach .file {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; background: var(--surface-3);
}
.attach .file .fi { font-size: 24px; }
.attach .file .fn { font-weight: 600; font-size: 13px; word-break: break-all; }
.attach .file .fs { font-size: 11px; color: var(--text-3); margin-top: 2px; }
a.attach:hover .file { background: var(--surface-4); }

.typing-row {
  min-height: 24px;
  padding: 2px 22px;
  font-size: 12px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 8px;
}
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots i {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--text-2);
  animation: typingBounce 1.2s infinite ease-in-out;
}
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }

.composer { padding: 6px 16px 16px; background: var(--surface-2); }
.composer .box {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 6px 6px 6px 8px;
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease);
}
.composer .box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.composer textarea {
  background: none;
  border: none;
  resize: none;
  max-height: 180px;
  padding: 9px 4px;
  flex: 1;
  line-height: 1.45;
}
.composer textarea:focus { box-shadow: none; }
.composer .box.disabled { opacity: .55; pointer-events: none; }
.composer .send {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: #fff;
  width: 38px; height: 38px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-size: 15px;
  transition: transform .12s var(--ease), filter .16s;
}
.composer .send:hover { filter: brightness(1.1); }
.composer .send:active { transform: scale(.9); }
.composer .attach-preview {
  display: flex; align-items: center; gap: 10px;
  font-size: 12px; color: var(--text-2);
  padding: 8px 6px 10px;
}
.emoji-btn {
  font-size: 18px;
  width: 38px; height: 38px;
  border-radius: 12px;
  color: var(--text-2);
  display: grid; place-items: center;
  transition: background .14s, transform .14s;
}
.emoji-btn:hover { background: var(--surface-4); transform: scale(1.08); }
.emoji-pop {
  position: absolute;
  bottom: 74px; right: 16px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  z-index: 20;
  max-width: 320px;
  box-shadow: var(--shadow-pop);
  animation: popIn .16s var(--ease);
}
.emoji-pop button { font-size: 21px; padding: 5px; border-radius: 8px; transition: background .12s, transform .12s; }
.emoji-pop button:hover { background: var(--surface-4); transform: scale(1.15); }

.empty-state {
  flex: 1;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--text-3);
  padding: 40px;
}
.empty-state .big { font-size: 44px; margin-bottom: 12px; opacity: .8; }
.empty-state h3 { color: var(--text-2); margin-bottom: 6px; }

/* ------------------------------ friends pane ---------------------- */
.friends-pane { flex: 1; overflow-y: auto; padding: 20px; max-width: 760px; width: 100%; margin: 0 auto; }
.friends-pane h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin: 22px 4px 8px;
  color: var(--text-3);
}
.friends-pane h2:first-child { margin-top: 0; }
.friend-row .actions { display: flex; gap: 6px; flex-shrink: 0; }
.add-friend {
  display: flex; gap: 8px;
  margin-bottom: 6px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px;
}
.add-friend input { flex: 1; background: var(--surface-1); border-color: transparent; }

/* =====================================================================
   SETTINGS VIEW
   ===================================================================== */
.settings-view { flex: 1; display: flex; min-height: 0; background: var(--surface-2); }
.settings-nav {
  width: 220px;
  min-width: 200px;
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--surface-1);
}
.settings-nav .grp {
  font-size: 11px; font-weight: 800; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-3);
  padding: 8px 10px 6px;
}
.settings-nav button {
  text-align: left;
  padding: 9px 12px;
  border-radius: 9px;
  color: var(--text-2);
  font-weight: 600;
  font-size: 13.5px;
  transition: background .15s var(--ease), color .15s;
}
.settings-nav button:hover { background: var(--surface-3); color: var(--text); }
.settings-nav button.active { background: var(--surface-4); color: var(--text); }
.settings-nav .spacer { flex: 1; }
.settings-nav .logout { color: var(--danger-strong); }
.settings-nav .logout:hover { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger-strong); }

.settings-body { flex: 1; overflow-y: auto; padding: 32px; }
.settings-body .wrap { max-width: 560px; }
.settings-body h2 { font-size: 20px; margin-bottom: 4px; }
.settings-body .lead { color: var(--text-2); font-size: 13.5px; margin-bottom: 24px; }
.settings-card {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.settings-card h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin-bottom: 14px; }
.profile-head { display: flex; align-items: center; gap: 18px; margin-bottom: 6px; }
.profile-head .who { flex: 1; }
.profile-head .uname { font-weight: 800; font-size: 19px; }
.profile-head .uid { color: var(--text-3); font-size: 12px; margin-top: 2px; }

/* segmented control */
.segmented {
  display: inline-flex;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.segmented button {
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-2);
  display: inline-flex; align-items: center; gap: 7px;
  transition: background .16s var(--ease), color .16s, box-shadow .16s;
}
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--surface-4); color: var(--text); box-shadow: var(--shadow-1); }
.segmented .swatch { width: 9px; height: 9px; border-radius: 50%; }
.segmented .swatch.online { background: var(--ok); }
.segmented .swatch.away { background: var(--warn); }
.segmented .swatch.dnd { background: var(--danger); }

/* theme picker */
.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.theme-tile {
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  cursor: pointer;
  transition: border-color .18s var(--ease), transform .14s var(--ease);
  background: var(--surface-1);
}
.theme-tile:hover { transform: translateY(-2px); }
.theme-tile.active { border-color: var(--accent); }
.theme-tile .swatch-row { display: flex; gap: 5px; margin-bottom: 8px; }
.theme-tile .sw { width: 100%; height: 26px; border-radius: 7px; }
.theme-tile .nm { font-size: 12.5px; font-weight: 700; text-align: center; color: var(--text-2); }
.theme-tile.active .nm { color: var(--text); }

.accent-row { display: flex; gap: 10px; flex-wrap: wrap; }
.accent-dot {
  width: 34px; height: 34px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform .14s var(--ease), border-color .14s;
  position: relative;
}
.accent-dot:hover { transform: scale(1.12); }
.accent-dot.active { border-color: var(--text); }
.accent-dot.active::after {
  content: "✓";
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: #fff; font-size: 14px; font-weight: 900;
  text-shadow: 0 1px 3px rgba(0,0,0,.5);
}

/* =====================================================================
   MODALS
   ===================================================================== */
.modal-scrim {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  z-index: 60;
  padding: 18px;
  animation: fade .16s var(--ease);
}
.modal {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 26px;
  box-shadow: var(--shadow-2);
  animation: modalIn .22s var(--ease);
}
.modal h3 { margin-bottom: 6px; font-size: 19px; }
.modal .modal-sub { color: var(--text-2); font-size: 13px; margin-bottom: 18px; }
.modal .row { display: flex; gap: 8px; margin-top: 20px; justify-content: flex-end; flex-wrap: wrap; }
.chk {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 8px;
  border-radius: 10px;
  transition: background .14s;
}
.chk:hover { background: var(--surface-3); }
.chk input { width: auto; }
.member-pick {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 5px;
  background: var(--surface-1);
}

/* =====================================================================
   CALL OVERLAY
   ===================================================================== */
.call-overlay {
  position: fixed; inset: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(140% 90% at 50% -10%, #22243180, transparent 60%),
    radial-gradient(120% 80% at 50% 120%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 55%),
    #0a0b0f;
}
:root[data-theme="light"] .call-overlay {
  background:
    radial-gradient(140% 90% at 50% -10%, #d7dae688, transparent 60%),
    #11131a;
}

/* stage / grid body */
.call-body {
  flex: 1;
  min-height: 0;
  position: relative;
}
.call-body.grid {
  display: grid;
  gap: 12px;
  padding: 72px 24px 108px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  grid-auto-rows: auto;
  align-content: center;
  justify-content: center;
  justify-items: center;
  overflow-y: auto;
}
.call-body.grid .tile { width: 100%; max-width: 560px; aspect-ratio: 16 / 10; }
.call-body.grid.g1 { grid-template-columns: minmax(0, min(760px, 88vw)); }

/* --- tiles --- */
.tile {
  position: relative;
  background: #14151b;
  border-radius: 18px;
  overflow: hidden;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .35);
}
.tile video {
  grid-area: 1 / 1;
  width: 100%; height: 100%;
  object-fit: cover;
  background: #000;
}
.tile.sharing video { object-fit: contain; background: #000; }
.tile .avatar { grid-area: 1 / 1; width: 96px; height: 96px; font-size: 38px; border-radius: 50%; }
.tile.audio-only video { display: none; }
.tile:not(.audio-only) .avatar { display: none; }
.tile.audio-only {
  background: radial-gradient(120% 120% at 50% 30%, #1e2029, #101117);
}
.tile .label {
  position: absolute; left: 12px; bottom: 12px;
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(8px);
  padding: 5px 11px; border-radius: 9px;
  font-size: 12.5px; font-weight: 600; color: #fff;
  display: flex; align-items: center; gap: 6px;
  max-width: calc(100% - 24px);
}
.tile .label span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .spk-ring {
  position: absolute; inset: 0;
  border: 3px solid var(--ok);
  border-radius: 18px;
  opacity: 0;
  transition: opacity .12s;
  pointer-events: none;
}
.tile.speaking .spk-ring { opacity: 1; animation: speakPulse 1.4s infinite; }

/* --- 1:1 stage layout --- */
.call-body.stage .tile.is-stage {
  position: absolute; inset: 0;
  border-radius: 0;
  box-shadow: none;
}
.call-body.stage .tile.is-stage .avatar { width: 128px; height: 128px; font-size: 46px; }
.call-body.stage .tile.is-stage .label { left: 20px; bottom: 20px; font-size: 13px; }
.call-body.stage .tile.is-pip {
  position: absolute;
  right: 18px; bottom: 116px;
  width: clamp(120px, 26vw, 220px);
  aspect-ratio: 16 / 11;
  border: 2px solid rgba(255, 255, 255, .16);
  border-radius: 14px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .55);
  z-index: 3;
}
.call-body.stage .tile.is-pip .avatar { width: 54px; height: 54px; font-size: 20px; }
.call-body.stage .tile.is-pip .label { display: none; }

/* --- floating header chip --- */
.call-head {
  position: absolute;
  top: 16px; left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(20, 21, 27, .6);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, .08);
  color: #fff;
  max-width: calc(100% - 32px);
}
.call-head .t { font-weight: 700; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-head .timer {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, .7);
  padding-left: 10px;
  border-left: 1px solid rgba(255, 255, 255, .15);
  white-space: nowrap;
}

/* --- floating controls pill --- */
.call-controls {
  position: absolute;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(20, 21, 27, .62);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, .08);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .45);
}
.call-controls .cbtn {
  width: 50px; height: 50px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  display: grid; place-items: center;
  font-size: 20px;
  transition: transform .12s var(--ease), background .16s, color .16s;
}
.call-controls .cbtn:hover { background: rgba(255, 255, 255, .18); transform: translateY(-2px); }
.call-controls .cbtn:active { transform: scale(.9); }
.call-controls .cbtn.active { background: #fff; color: #16171d; }
.call-controls .cbtn.hangup {
  background: linear-gradient(180deg, var(--danger-strong), var(--danger));
  width: 58px;
}
.call-controls .cbtn.hangup:hover { filter: brightness(1.08); }

/* --- minimized (picture-in-picture of the whole call) --- */
.call-overlay.minimized {
  inset: auto 16px 16px auto;
  width: min(320px, 80vw); height: min(200px, 45vw);
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .14);
  box-shadow: var(--shadow-2);
}
.call-overlay.minimized .call-head { display: none; }
.call-overlay.minimized .call-body { padding: 0; }
.call-overlay.minimized .call-body.grid { grid-template-columns: 1fr; grid-auto-rows: 1fr; gap: 2px; }
.call-overlay.minimized .call-body.grid .tile { max-width: none; aspect-ratio: auto; height: 100%; border-radius: 0; }
.call-overlay.minimized .tile.is-pip { display: none; }
.call-overlay.minimized .call-controls {
  bottom: 8px;
  padding: 5px 7px;
  gap: 5px;
  background: rgba(10, 11, 15, .7);
}
.call-overlay.minimized .call-controls .cbtn { width: 34px; height: 34px; font-size: 14px; }
.call-overlay.minimized .call-controls .cbtn:not(.min):not(.hangup) { display: none; }

/* --- incoming ring prompt --- */
.incoming-call {
  position: fixed;
  left: 50%; top: 22px;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 22px 24px;
  z-index: 90;
  width: min(340px, 92vw);
  box-shadow: var(--shadow-2);
  text-align: center;
  animation: dropIn .3s var(--ease);
}
.incoming-call .ring-avatar { position: relative; display: inline-grid; place-items: center; }
.incoming-call .ring-avatar::before {
  content: "";
  position: absolute; inset: -10px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: speakPulse 1.8s infinite;
}
.incoming-call .who { font-weight: 800; font-size: 18px; margin-top: 14px; }
.incoming-call .desc { color: var(--text-2); font-size: 13px; margin-top: 3px; }
.incoming-call .cta { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }
.incoming-call .cta .btn { flex: 1; }

/* =====================================================================
   TOASTS
   ===================================================================== */
.toasts {
  position: fixed;
  right: 16px; bottom: 16px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 100;
}
.toast {
  background: var(--surface-1);
  border: 1px solid var(--border);
  padding: 12px 15px;
  border-radius: 12px;
  font-size: 13px;
  max-width: 340px;
  box-shadow: var(--shadow-pop);
  display: flex; align-items: center; gap: 10px;
  cursor: pointer;
}
.toast-icon {
  width: 20px; height: 20px; min-width: 20px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 900; color: #fff;
  background: var(--accent);
}
.toast.err .toast-icon { background: var(--danger); }
.toast.ok .toast-icon { background: var(--ok); }

/* =====================================================================
   LOADING
   ===================================================================== */
.app-loading {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--text-2);
  gap: 14px;
  grid-auto-flow: row;
}
.spinner {
  display: inline-block;
  border: 2.5px solid var(--surface-4);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* =====================================================================
   KEYFRAMES
   ===================================================================== */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  from { opacity: 0; transform: scale(.94); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes dropIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-16px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes barIn {
  from { transform: translateY(-50%) scaleY(0); }
  to { transform: translateY(-50%) scaleY(1); }
}
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}
@keyframes speakPulse {
  0% { box-shadow: 0 0 0 0 var(--ring); }
  70% { box-shadow: 0 0 0 10px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
@media (min-width: 768px) {
  .sidebar { position: relative; transform: none; }
  .sidebar.open { box-shadow: none; }
  .scrim { display: none; }
  .topbar .hamburger { display: none; }
}

@media (min-width: 1024px) {
  :root { --sidebar-w: 312px; }
  .messages { padding: 22px 28px 10px; }
  .call-grid { padding: 16px 48px; }
  .call-grid.many { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .settings-body { padding: 44px; }
}

@media (max-width: 600px) {
  .settings-view { flex-direction: column; }
  .settings-nav {
    width: 100%;
    min-width: 0;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 10px;
    gap: 4px;
  }
  .settings-nav .grp, .settings-nav .spacer { display: none; }
  .settings-nav button { white-space: nowrap; }
  .settings-body { padding: 20px; }
  .friend-row { flex-wrap: wrap; }
  .friend-row .actions { width: 100%; padding-left: 41px; }
  .theme-grid { grid-template-columns: 1fr; }
  .call-grid.n2, .call-grid.n3, .call-grid.n4, .call-grid.many { grid-template-columns: 1fr; }
}

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