* { box-sizing: border-box; }
:root {
  --blue: #0084ff;
  --bg: #ffffff;
  --panel: #f0f2f5;
  --text: #050505;
  --muted: #65676b;
  --bubble-in: #e4e6eb;
}
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--panel);
  color: var(--text);
}
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

/* ---------- Auth pages ---------- */
.auth-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
  background: #fff; width: 100%; max-width: 400px; border-radius: 12px;
  padding: 28px; box-shadow: 0 2px 12px rgba(0,0,0,.12);
}
.logo { text-align: center; color: var(--blue); font-weight: 800; font-size: 34px; margin-bottom: 4px; }
.sub { text-align: center; color: var(--muted); margin-bottom: 20px; }
.auth-card input {
  width: 100%; padding: 14px; margin-bottom: 12px; border: 1px solid #dddfe2;
  border-radius: 8px; font-size: 16px; outline: none;
}
.auth-card input:focus { border-color: var(--blue); }
.btn {
  width: 100%; background: var(--blue); color: #fff; border: 0; padding: 13px;
  border-radius: 8px; font-size: 17px; font-weight: 700;
}
.btn:hover { filter: brightness(.95); }
.btn.secondary { background: #e4e6eb; color: var(--text); }
.err { color: #d93025; font-size: 14px; min-height: 20px; margin-bottom: 8px; }
.alt { text-align: center; margin-top: 16px; font-size: 15px; }
.alt a { color: var(--blue); text-decoration: none; font-weight: 600; }

/* ---------- Chat layout ---------- */
/* App screen-e fix thake: keyboard khulle shudhu niche-r ongsho choto hoy, upore-r header jayga theke nore na */
body.chat-page { overflow: hidden; overscroll-behavior: none; }
.app { position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h, 100dvh); display: flex; background: #fff; }
.sidebar { width: 360px; border-right: 1px solid #e4e6eb; display: flex; flex-direction: column; min-width: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.side-head h1 { margin: 0; font-size: 24px; }
.icon-btn { background: var(--panel); border: 0; width: 36px; height: 36px; border-radius: 50%; font-size: 16px; }
.icon-btn:hover { background: #e4e6eb; }
.search { padding: 8px 16px 10px; }
.search input { width: 100%; padding: 10px 14px; border-radius: 20px; border: 0; background: var(--panel); font-size: 15px; outline: none; }
.list { flex: 1; overflow-y: auto; }
.item { display: flex; gap: 12px; align-items: center; padding: 10px 16px; cursor: pointer; border-radius: 8px; margin: 0 6px; }
.item:hover { background: var(--panel); }
.item.active { background: #e7f3ff; }
.avatar {
  width: 48px; height: 48px; flex: 0 0 48px; border-radius: 50%; color: #fff; display: flex;
  align-items: center; justify-content: center; font-weight: 700; font-size: 20px; position: relative;
}
.avatar.sm { width: 36px; height: 36px; flex-basis: 36px; font-size: 15px; }
.avatar.lg { width: 96px; height: 96px; flex-basis: 96px; font-size: 40px; }
.avatar { background-size: cover; background-position: center; }
.avatar.clickable { cursor: pointer; }
.dot { position: absolute; right: 0; bottom: 0; width: 13px; height: 13px; background: #31a24c; border: 2px solid #fff; border-radius: 50%; }
.meta { min-width: 0; flex: 1; }
.name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.last { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item.unread .last, .item.unread .name { font-weight: 800; color: var(--text); }
.badge { background: var(--blue); color: #fff; border-radius: 10px; min-width: 20px; padding: 2px 6px; font-size: 12px; text-align: center; }
.me-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-top: 1px solid #e4e6eb; cursor: pointer; }
.me-bar:hover { background: var(--panel); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid #e4e6eb; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.back { display: none; }
.chat-head .t { flex: 1; min-width: 0; }
.chat-head .s { font-size: 13px; color: var(--muted); }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 3px; }
.empty { margin: auto; color: var(--muted); text-align: center; }
.row { display: flex; }
.row.me { justify-content: flex-end; }
.bubble { max-width: 68%; padding: 8px 12px; border-radius: 18px; background: var(--bubble-in); word-wrap: break-word; white-space: pre-wrap; font-size: 15px; }
.row.me .bubble { background: var(--blue); color: #fff; }
.time { font-size: 11px; color: var(--muted); text-align: center; margin: 10px 0 4px; }
.seen { font-size: 11px; color: var(--muted); text-align: right; padding-right: 6px; }
.typing { height: 18px; padding: 0 18px; font-size: 13px; color: var(--muted); }
.composer { display: flex; gap: 8px; padding: 10px 16px 14px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; max-height: 120px; border: 0; background: var(--panel); border-radius: 20px; padding: 10px 14px; font-size: 15px; outline: none; }
.send { background: var(--blue); color: #fff; border: 0; border-radius: 50%; width: 40px; height: 40px; font-size: 18px; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal-bg.show { display: flex; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 420px; padding: 22px; max-height: 92vh; overflow-y: auto; }
.modal h2 { margin: 0 0 14px; }
.modal label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.modal input, .modal textarea { width: 100%; padding: 10px 12px; border: 1px solid #dddfe2; border-radius: 8px; font-size: 15px; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.colors span { width: 28px; height: 28px; border-radius: 50%; cursor: pointer; border: 3px solid transparent; }
.colors span.sel { border-color: #222; }
.btns { display: flex; gap: 8px; margin-top: 16px; }
.center { text-align: center; }
.uid { display: inline-block; background: var(--panel); border-radius: 12px; padding: 3px 10px; font-size: 13px; color: var(--muted); margin: 4px 0; }

/* ---------- Media ---------- */
.bubble.media { padding: 4px; max-width: min(68%, 340px); }
.bubble.media img, .bubble.media video { display: block; max-width: 100%; max-height: 320px; border-radius: 14px; cursor: pointer; }
.bubble.media audio { display: block; width: 240px; max-width: 100%; }
.bubble .cap { padding: 4px 8px 2px; white-space: pre-wrap; word-wrap: break-word; }
.tool { background: transparent; border: 0; font-size: 22px; width: 36px; height: 40px; flex: 0 0 36px; }
.tool.on { background: #fbd9d6; border-radius: 50%; }
.rec { flex: 1; display: flex; align-items: center; gap: 10px; background: var(--panel); border-radius: 20px; padding: 10px 14px; color: #d93025; font-weight: 600; }
.rec button { margin-left: auto; border: 0; background: transparent; font-size: 16px; }

.bubble .dl { display: block; font-size: 12px; padding: 4px 8px 2px; color: inherit; opacity: .75; text-decoration: underline; }

/* ---------- Calls ---------- */
.chat-head .icon-btn { flex: 0 0 36px; }
.callui { position: fixed; inset: 0; background: #14161a; z-index: 100; display: none; flex-direction: column; align-items: center; justify-content: center; color: #fff; }
.callui #remoteVid { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.callui:not(.video) #remoteVid { inset: auto; width: 1px; height: 1px; opacity: 0; }
.callui #localVid { position: absolute; right: 14px; top: 70px; width: 110px; max-height: 160px; border-radius: 12px; object-fit: cover; background: #222; z-index: 2; transform: scaleX(-1); box-shadow: 0 2px 10px rgba(0,0,0,.5); }
.callui:not(.video) #localVid { display: none; }
.call-top { position: absolute; top: 18px; left: 0; right: 0; text-align: center; z-index: 3; text-shadow: 0 1px 4px rgba(0,0,0,.7); }
.call-name { font-size: 20px; font-weight: 700; }
.call-status, .call-sub { font-size: 14px; opacity: .85; margin-top: 2px; }
.call-info { position: relative; z-index: 1; }
.callui.live.video .call-info { display: none; }
.call-ctrl { position: absolute; bottom: 34px; left: 0; right: 0; display: flex; justify-content: center; gap: 18px; z-index: 3; }
.cbtn { width: 60px; height: 60px; border-radius: 50%; border: 0; font-size: 24px; background: rgba(255,255,255,.2); color: #fff; }
.cbtn.off { background: #fff; color: #111; }
.cbtn.end { background: #d93025; transform: rotate(135deg); }
.cbtn.ok { background: #31a24c; }
.callin { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 110; display: none; align-items: center; justify-content: center; padding: 16px; }
.callin .box { background: #fff; color: var(--text); border-radius: 16px; padding: 26px; text-align: center; min-width: 270px; }
.callin .call-sub { color: var(--muted); }
.callin-btns { display: flex; justify-content: center; gap: 40px; margin-top: 22px; }
.toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: #323232; color: #fff; padding: 10px 18px; border-radius: 20px; z-index: 200; font-size: 14px; max-width: 90%; text-align: center; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .sidebar { width: 100%; }
  .main { display: none; }
  .app.chatting .sidebar { display: none; }
  .app.chatting .main { display: flex; }
  .back { display: inline-block; }
  .bubble { max-width: 82%; }
}

/* ---------- Profile photo ---------- */
.photo-btns { display: flex; gap: 8px; justify-content: center; margin: 4px 0 8px; }
.photo-btns .btn { padding: 6px 12px; font-size: 13px; width: auto; }
.modal-bg.top { z-index: 60; }
.crop-modal { max-width: 360px; text-align: center; }
.crop-modal h2 { margin-bottom: 4px; }
.crop-hint { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.crop-cv { width: 100%; max-width: 300px; aspect-ratio: 1 / 1; border-radius: 8px; background: #111; touch-action: none; cursor: grab; display: block; margin: 0 auto 10px; }
.crop-cv:active { cursor: grabbing; }
.crop-modal input[type=range] { width: 100%; max-width: 300px; padding: 0; border: 0; }
.view-bg { background: rgba(0,0,0,.82); cursor: pointer; }
.view-box { text-align: center; color: #fff; max-width: 92vw; }
.avatar.view-av { width: min(80vw, 420px); height: min(80vw, 420px); flex-basis: auto; font-size: 120px; margin: 0 auto 16px; box-shadow: 0 8px 40px rgba(0,0,0,.5); }
.view-name { font-size: 22px; font-weight: 700; }
.view-user { font-size: 14px; opacity: .75; margin-top: 2px; }
.view-bio { font-size: 15px; opacity: .9; margin-top: 8px; white-space: pre-wrap; word-wrap: break-word; }

/* ---------- Message select (long press) / react / unsend ---------- */
.msgs .bubble { position: relative; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.row.sel { background: rgba(0,132,255,.14); border-radius: 12px; }
.bubble.hasreact { margin-bottom: 12px; }
.bubble .reacts {
  position: absolute; bottom: -13px; left: 8px; background: #fff; color: #222; border: 1px solid #e4e6eb;
  border-radius: 12px; padding: 0 6px; font-size: 13px; line-height: 20px; white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.row.me .bubble .reacts { left: auto; right: 8px; }
.bubble.unsent {
  background: transparent !important; color: var(--muted) !important; border: 1px dashed #ccd0d5;
  font-style: italic; font-size: 14px;
}
.react-bar {
  position: fixed; z-index: 40; display: none; gap: 2px; background: #fff; border-radius: 26px;
  padding: 4px 6px; box-shadow: 0 4px 18px rgba(0,0,0,.28);
}
.react-bar button { border: 0; background: transparent; font-size: 26px; width: 40px; height: 40px; border-radius: 50%; }
.react-bar button.on { background: #e7f3ff; }
.react-bar button:active { transform: scale(1.25); }
.chat-head .sel-bar { display: none; flex: 1; align-items: center; gap: 8px; }
.chat-head.selecting > :not(.sel-bar) { display: none; }
.chat-head.selecting .sel-bar { display: flex; }
.sel-sp { flex: 1; }

/* ---------- Edit / Pin ---------- */
.icon-btn.active { background: #cfe6ff; }
.bubble .edited { font-size: 11px; opacity: .7; margin-left: 6px; font-style: italic; }
.row .pinmark { font-size: 12px; align-self: flex-end; margin: 0 4px 2px; opacity: .8; }
.row.flash { animation: rowflash 1.3s ease-out; }
@keyframes rowflash { 0%, 40% { background: rgba(255,214,0,.45); border-radius: 12px; } 100% { background: transparent; } }
.pin-bar {
  display: flex; align-items: center; gap: 8px; padding: 7px 16px; background: #fffbe6;
  border-bottom: 1px solid #f0e6a8; cursor: pointer; font-size: 14px;
}
.pin-bar .pin-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pin-bar .pin-cnt { color: var(--muted); font-size: 12px; }
.edit-bar { display: flex; align-items: center; gap: 8px; padding: 6px 16px; background: var(--panel); border-top: 1px solid #e4e6eb; }
.edit-bar .edit-t { flex: 1; min-width: 0; font-size: 13px; }
.edit-bar .edit-t span { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.edit-bar .icon-btn { width: 30px; height: 30px; font-size: 13px; }

