:root {
  --acc: #1769E0; --acc-soft: #deeafd; --hi: #8A2BE2; --navy: #001247; --bg: #eef1f4; --panel: #ffffff; --ink: #14181c; --muted: #5f6b76;
  --line: #e3e7eb; --in: #ffffff; --out: #e1ebfd; --chatbg: #eef2fb; --danger: #d93025; --blue: #1e88e5;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --acc: #5AB0FF; --acc-soft: #13284d; --hi: #B57BFF; --bg: #000a2b; --panel: #08163d; --ink: #e8edf5; --muted: #94a3b8;
    --line: #1c2b45; --in: #13223d; --out: #1a3470; --chatbg: #030f33; }
}
:root[data-theme="dark"] { --acc: #5AB0FF; --acc-soft: #13284d; --hi: #B57BFF; --bg: #000a2b; --panel: #08163d; --ink: #e8edf5; --muted: #94a3b8;
    --line: #1c2b45; --in: #13223d; --out: #1a3470; --chatbg: #030f33; }
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Arabic", sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
svg { width: 24px; height: 24px; fill: currentColor; }

/* linking screen */
.link { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.link-card { background: var(--panel); border-radius: 16px; box-shadow: 0 2px 12px rgba(0,0,0,.08); max-width: 920px; width: 100%;
  display: grid; grid-template-columns: 1fr auto; gap: 32px; padding: 40px; }
.link h1 { display: flex; align-items: center; gap: 12px; margin: 0 0 12px; font-size: 28px; color: var(--acc); }
.link .lead { font-size: 17px; margin: 0 0 20px; }
.link ol { padding-inline-start: 22px; font-size: 17px; line-height: 2; margin: 0 0 16px; }
.qr-box { text-align: center; }
#qr { background: #fff; padding: 12px; border-radius: 12px; display: inline-block; line-height: 0; }
#qr img, #qr svg { width: 264px; height: 264px; }
@media (max-width: 720px) { .link-card { grid-template-columns: 1fr; padding: 24px; gap: 16px; } #qr img, #qr svg { width: 220px; height: 220px; } }

/* main layout */
.app { height: 100%; display: grid; grid-template-columns: minmax(300px, 400px) 1fr; max-width: 1600px; margin: 0 auto;
  background: var(--panel); box-shadow: 0 0 12px rgba(0,0,0,.06); }
.side { display: flex; flex-direction: column; border-inline-end: 1px solid var(--line); min-width: 0; min-height: 0; }
.side-head, .chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; min-height: 60px; border-bottom: 1px solid var(--line); }
.me-text, .peer-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.me-text b, .peer-text b, .me-text small, .peer-text small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--bg); }
.avatar-btn { background: none; border: 0; padding: 0; border-radius: 50%; }
.avatar { width: 42px; height: 42px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700;
  font-size: 18px; background: var(--acc) center/cover no-repeat; }
.banner { background: #fff4d6; color: #5b4500; padding: 10px 14px; font-size: 14px; }
.relink { background: none; border: 0; padding: 0; color: #0b57d0; font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; }
.search { padding: 8px 12px; }
.search input, .dlg input { width: 100%; border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 10px; padding: 9px 12px; font: inherit; }
.tabs { display: flex; gap: 6px; padding: 0 12px 6px; }
.tab { border: 0; background: var(--bg); border-radius: 16px; padding: 5px 14px; color: var(--muted); }
.tab.on { background: var(--acc-soft); color: var(--acc); font-weight: 600; }
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.list li { display: flex; gap: 12px; align-items: center; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--line); }
.list li:hover, .list li.on { background: var(--bg); }
.list .section { cursor: default; background: none !important; color: var(--acc); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; border: 0; padding-top: 14px; padding-bottom: 4px; }
.row-text { flex: 1; min-width: 0; }
.row-top, .row-bottom { display: flex; gap: 8px; align-items: center; }
.row-top b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-top small { color: var(--muted); font-size: 12px; flex: none; }
.row-bottom span { flex: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-bottom span.badge { flex: none; }
.badge { background: var(--acc); color: #fff; border-radius: 10px; min-width: 20px; padding: 0 6px; font-size: 12px; text-align: center; flex: none; }
.unread .row-top small { color: var(--acc); font-weight: 600; }
.tick { width: 16px; height: 16px; flex: none; color: var(--muted); }
.tick.done { color: var(--blue); }
.tick.fail { color: var(--danger); }
.empty { padding: 24px; text-align: center; color: var(--muted); cursor: default !important; border: 0 !important; display: block !important; }

/* chat */
.chat { display: flex; min-width: 0; min-height: 0; background: var(--chatbg); }
.welcome { margin: auto; text-align: center; padding: 24px; max-width: 420px; }
.welcome h2 { color: var(--acc); margin: 12px 0 6px; }
.conv { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }
.chat-head { background: var(--panel); }
.back { display: none; }
.msgs { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 4px; min-height: 0; }
.day { align-self: center; background: var(--panel); color: var(--muted); font-size: 12px; padding: 4px 10px; border-radius: 8px; margin: 8px 0; }
.bubble { max-width: min(75%, 640px); padding: 6px 10px 4px 12px; border-radius: 10px; background: var(--in); box-shadow: 0 1px 1px rgba(0,0,0,.08);
  align-self: flex-start; white-space: pre-wrap; overflow-wrap: anywhere; unicode-bidi: plaintext; }
.bubble.mine { align-self: flex-end; background: var(--out); }
.bubble .from { font-size: 13px; font-weight: 700; display: block; }
.bubble .orig { display: block; color: var(--muted); font-size: 13px; margin-top: 3px; }
.bubble .meta { display: flex; gap: 4px; align-items: center; justify-content: flex-end; font-size: 11px; color: var(--muted); margin-top: 2px; }
.bubble.can-flip { cursor: pointer; }
.bubble.failed { cursor: pointer; }
.hint { text-align: center; font-size: 12px; margin: 0; padding: 4px 12px; }
.composer { display: flex; gap: 8px; padding: 8px 12px; background: var(--panel); align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 0; border-radius: 10px; background: var(--bg); color: var(--ink); padding: 10px 12px; font: inherit; max-height: 140px; unicode-bidi: plaintext; }
.send { border: 0; width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(135deg, #12b5ea, #8A2BE2); color: #fff; display: grid; place-items: center; flex: none; }
.send:disabled { opacity: .5; }
html[dir=rtl] .send svg, html[dir=rtl] .back svg { transform: scaleX(-1); }

/* menu and dialogs */
.menu { position: fixed; background: var(--panel); border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.18); padding: 6px 0; z-index: 10; min-width: 220px; }
.menu button { display: block; width: 100%; text-align: start; padding: 10px 16px; background: none; border: 0; }
.menu button:hover { background: var(--bg); }
dialog { border: 0; border-radius: 16px; padding: 0; background: var(--panel); color: var(--ink); width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.dlg { padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.dlg h3 { margin: 0; }
.dlg p { margin: 0; font-size: 13px; }
.dlg-buttons { display: flex; justify-content: flex-end; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.dlg-buttons .text { background: none; border: 0; color: var(--acc); padding: 8px 12px; border-radius: 18px; font-weight: 600; }
.dlg-buttons .filled { background: var(--acc); border: 0; color: #fff; padding: 8px 18px; border-radius: 18px; font-weight: 600; }
.found { display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: 10px; background: var(--bg); }
.found div { display: flex; flex-direction: column; min-width: 0; }
.pick { max-height: 280px; overflow-y: auto; display: flex; flex-direction: column; }
.pick label { display: flex; gap: 10px; align-items: center; padding: 6px 2px; }

/* phones and small windows: one pane at a time */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app.in-chat .side { display: none; }
  .app:not(.in-chat) .chat { display: none; }
  .back { display: grid; }
  .msgs { padding: 12px; }
}
.link h1 img, .welcome img { border-radius: 22%; }

/* theme and wallpaper */
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; }
.seg button.on { background: var(--acc-soft); color: var(--acc); font-weight: 600; }
.walls { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; max-height: 300px; overflow-y: auto; }
.walls button { border: 2px solid transparent; border-radius: 10px; aspect-ratio: 3 / 4; padding: 0; position: relative; background-color: var(--chatbg); }
.walls button.on { border-color: var(--acc); }
.walls button span { position: absolute; inset: auto 0 4px; font-size: 11px; color: var(--ink); text-shadow: 0 0 4px var(--panel); }
.brand { width: 28px; height: 28px; border-radius: 22%; flex: none; }

/* filters, calls list */
.chips { display: flex; gap: 6px; padding: 0 12px 8px; flex-wrap: wrap; }
.chips button { border: 1px solid var(--line); background: none; border-radius: 16px; padding: 3px 12px; font-size: 13px; color: var(--muted); }
.chips button.on { background: var(--acc-soft); color: var(--acc); border-color: transparent; font-weight: 600; }
.row-bottom span.missed { color: var(--danger); }
.row-call { color: var(--acc); }

/* chat extras */
.peer-text { cursor: pointer; }
.chat { position: relative; }
.conv-search { display: flex; gap: 6px; align-items: center; padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.conv-search input { flex: 1; border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 10px; padding: 8px 12px; font: inherit; }
mark { background: #ffe58a; color: inherit; border-radius: 3px; }
.bubble .pic { display: block; max-width: 100%; width: 280px; max-height: 320px; object-fit: cover; border-radius: 8px; margin: 2px 0 4px; cursor: zoom-in; background: rgba(0,0,0,.06); min-height: 120px; }
.doc { display: block; border: 0; background: rgba(0,0,0,.06); border-radius: 8px; padding: 8px 10px; margin: 2px 0 4px; text-align: start; overflow-wrap: anywhere; }
.msgs.drop { outline: 3px dashed var(--acc); outline-offset: -10px; }
.composer .icon-btn { width: 40px; height: 44px; }
.emoji-box { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 2px; padding: 8px 12px; background: var(--panel); border-top: 1px solid var(--line); max-height: 180px; overflow-y: auto; }
.emoji-box button { border: 0; background: none; font-size: 24px; padding: 4px; border-radius: 8px; }
.emoji-box button:hover { background: var(--bg); }

/* contact info panel */
.info { position: absolute; inset: 0 0 0 auto; width: min(380px, 100%); background: var(--panel); border-inline-start: 1px solid var(--line); display: flex; flex-direction: column; z-index: 5; box-shadow: -4px 0 16px rgba(0,0,0,.08); }
html[dir=rtl] .info { inset: 0 auto 0 0; }
.info-body { padding: 24px 20px; overflow-y: auto; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.info-body h3 { margin: 8px 0 0; }
.info-body p { margin: 0; overflow-wrap: anywhere; }
.info-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 10px 0; }
.info-actions .filled { background: var(--acc); border: 0; color: #fff; padding: 8px 18px; border-radius: 18px; font-weight: 600; }
.info-actions .text { background: var(--bg); border: 0; color: var(--acc); padding: 8px 14px; border-radius: 18px; font-weight: 600; }
.info-media { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; width: 100%; }
.info-media img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; cursor: zoom-in; background: var(--bg); }
.info-media .doc { grid-column: 1 / -1; }
.avatar.big { width: 112px; height: 112px; font-size: 44px; }

/* calls */
.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; }
.overlay.call, .overlay.ring { background: linear-gradient(160deg, #001247, #0b2a7a 55%, #4b1a8c); color: #fff; }
.overlay.ring { background: rgba(0, 18, 71, .9); }
.call-card { width: min(520px, 100%); display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; max-height: 100%; }
.call-card h2 { margin: 8px 0 0; }
.call-card .muted { color: rgba(255,255,255,.75); margin: 0; }
.call-card .small { font-size: 13px; }
.captions { width: 100%; flex: 1; min-height: 120px; max-height: 40vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.cap { max-width: 85%; padding: 6px 10px; border-radius: 10px; background: rgba(255,255,255,.12); text-align: start; unicode-bidi: plaintext; }
.cap small { display: block; opacity: .7; font-size: 12px; }
.cap.mine { align-self: flex-end; background: rgba(90,176,255,.25); }
.cap.theirs { align-self: flex-start; }
.cap.note { align-self: center; background: rgba(255,200,80,.25); }
.partial { min-height: 1.4em; margin: 0; opacity: .7; font-style: italic; }
.call-buttons { display: flex; gap: 28px; margin-top: 16px; }
.round { width: 64px; height: 64px; border-radius: 50%; border: 0; display: grid; place-items: center; background: rgba(255,255,255,.18); color: #fff; }
.round svg { width: 30px; height: 30px; }
.round.on { background: #fff; color: #001247; }
.round.red { background: #e53935; }
.round.green { background: #2e9d4f; }

/* photo viewer and toast */
.overlay.viewer { background: rgba(0,0,0,.92); grid-template-rows: auto 1fr; place-items: stretch; padding: 0; }
.viewer-bar { display: flex; gap: 8px; align-items: center; padding: 10px 16px; color: #fff; }
.viewer-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-bar .text { background: rgba(255,255,255,.14); border: 0; color: #fff; padding: 8px 14px; border-radius: 18px; }
.viewer img { max-width: 100%; max-height: calc(100vh - 64px); margin: auto; object-fit: contain; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 18px; border-radius: 20px; z-index: 30; max-width: calc(100vw - 32px); }
