:root {
  --blue: #1a6eff; --blue-d: #0f56d6; --blue-l: #e8f0ff; --blue-ll: #f3f7ff;
  --bg: #ffffff; --bg2: #f5f7fb; --bg3: #eceff5; --card: #ffffff;
  --text: #101828; --text2: #475467; --text3: #98a2b3; --line: #e6e9f0;
  --in: #f1f3f7; --out: #e3edff; --out-text: #101828;
  --note: #fff6d6; --note-line: #f5d565; --note-text: #5c4400;
  --red: #e5484d; --green: #12b76a; --orange: #f79009; --wa: #25d366; --fb: #0a7cff;
  --shadow: 0 6px 24px rgba(16, 24, 40, .12);
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1115; --bg2: #161a21; --bg3: #1f242d; --card: #181c23;
  --text: #eef1f6; --text2: #b3bccb; --text3: #6f7a8c; --line: #262c36;
  --in: #1f242d; --out: #19325f; --out-text: #eef1f6; --blue-l: #172a4d; --blue-ll: #121c30;
  --note: #3a3115; --note-line: #6b5617; --note-text: #f2dd9b;
  --shadow: 0 6px 24px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", Tahoma, sans-serif; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); }
a { color: var(--blue); text-decoration: none; }
svg.i { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i.s { width: 18px; height: 18px; } svg.i.xs { width: 14px; height: 14px; }
[dir="rtl"] .flip { transform: scaleX(-1); }

#app { height: 100%; }
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.top { display: flex; align-items: center; gap: 6px; min-height: 56px; padding: calc(6px + var(--safe-t)) 8px 6px; border-bottom: 1px solid var(--line); background: var(--bg); }
.top h1 { font-size: 20px; margin: 0 6px; font-weight: 700; }
.top .grow { flex: 1; min-width: 0; }
.ib { width: 40px; height: 40px; border-radius: 20px; display: inline-flex; align-items: center; justify-content: center; color: var(--text2); position: relative; }
.ib:active { background: var(--bg3); }
.ib.primary { color: var(--blue); }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.muted { color: var(--text3); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.pad { padding: 16px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 4px; display: inline-block; }
.dot.online { background: var(--green); } .dot.busy { background: var(--orange); } .dot.offline { background: var(--text3); }

/* view switcher */
.viewbtn { display: inline-flex; align-items: center; gap: 4px; font-size: 20px; font-weight: 700; padding: 4px 6px; border-radius: 8px; }
.viewbtn:active { background: var(--bg3); }
.chips { display: flex; gap: 8px; padding: 10px 12px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 6px 12px; border-radius: 16px; background: var(--bg2); color: var(--text2); font-size: 13.5px; font-weight: 600; border: 1px solid var(--line); }
.chip.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.chip .n { opacity: .8; margin-inline-start: 4px; font-weight: 500; }

/* conversation list */
.conv { position: relative; overflow: hidden; }
.conv .inner { display: flex; gap: 12px; padding: 12px 14px; align-items: center; background: var(--bg); transition: transform .15s; }
.conv .inner:active { background: var(--bg2); }
.conv + .conv .inner { border-top: 1px solid var(--line); }
.conv .name { font-weight: 600; font-size: 15.5px; }
.conv .time { font-size: 12px; color: var(--text3); flex: none; }
.conv .time.unread { color: var(--blue); font-weight: 700; }
.conv .preview { color: var(--text2); font-size: 14px; display: flex; gap: 4px; align-items: center; }
.conv .preview .ellipsis { flex: 1; }
.conv.unread .name { font-weight: 800; } .conv.unread .preview { color: var(--text); font-weight: 600; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--blue); color: #fff; font-size: 11.5px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.badge.red { background: var(--red); }
.ib .badge { position: absolute; top: 2px; inset-inline-end: 0; height: 17px; min-width: 17px; font-size: 10.5px; padding: 0 4px; }
.meta { display: flex; gap: 6px; align-items: center; margin-top: 4px; flex-wrap: wrap; }
.tagmini { font-size: 11px; padding: 1px 7px; border-radius: 8px; background: var(--bg3); color: var(--text2); max-width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lc { font-size: 11px; padding: 1px 7px; border-radius: 8px; background: var(--blue-l); color: var(--blue); }
.swipe-act { position: absolute; inset-block: 0; inset-inline-end: 0; width: 96px; display: flex; align-items: center; justify-content: center; background: var(--green); color: #fff; font-weight: 700; flex-direction: column; font-size: 12px; gap: 2px; }
.empty { padding: 48px 24px; text-align: center; color: var(--text3); }
.empty svg.i { width: 44px; height: 44px; stroke-width: 1.5; margin-bottom: 8px; }
.loadmore { padding: 16px; text-align: center; color: var(--text3); font-size: 13px; }

/* avatar */
.av { position: relative; flex: none; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; background-size: cover; background-position: center; }
.av .ch { position: absolute; bottom: -2px; inset-inline-end: -2px; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--bg); display: flex; align-items: center; justify-content: center; }
.av .ch svg { width: 10px; height: 10px; }
.av .as { position: absolute; top: -3px; inset-inline-end: -3px; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--bg); font-size: 9px; display: flex; align-items: center; justify-content: center; }

/* bottom nav */
.nav { display: flex; border-top: 1px solid var(--line); background: var(--bg); padding-bottom: var(--safe-b); }
.nav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; color: var(--text3); font-size: 11.5px; font-weight: 600; position: relative; }
.nav button.on { color: var(--blue); }
.nav .badge { position: absolute; top: 3px; left: 50%; margin-left: 6px; height: 17px; min-width: 17px; font-size: 10.5px; }

/* chat */
.chat-head .who { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; padding: 2px 4px; border-radius: 10px; }
.chat-head .who:active { background: var(--bg3); }
.chat-head .nm { font-weight: 700; font-size: 16px; }
.chat-head .sub { font-size: 12px; color: var(--text3); }
.chat-bar { display: flex; gap: 6px; padding: 6px 12px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; align-items: center; background: var(--bg); }
.chat-bar::-webkit-scrollbar { display: none; }
.pill { flex: none; display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 14px; background: var(--bg2); border: 1px solid var(--line); font-size: 12.5px; color: var(--text2); font-weight: 600; }
.pill.warn { background: #fff1e6; color: #b54708; border-color: #fcd9bd; }
.pill.ok { background: #e7f8ef; color: #067647; border-color: #b4ebcc; }
:root[data-theme="dark"] .pill.warn { background: #3a2412; color: #fdb022; border-color: #5a3510; }
:root[data-theme="dark"] .pill.ok { background: #0f2e20; color: #47cd89; border-color: #164a30; }
.msgs { flex: 1; overflow-y: auto; padding: 8px 10px 12px; background: var(--bg2); display: flex; flex-direction: column; gap: 3px; }
.day { align-self: center; margin: 10px 0 6px; font-size: 12px; color: var(--text2); background: var(--bg3); padding: 3px 10px; border-radius: 10px; }
.activity { align-self: center; text-align: center; max-width: 88%; font-size: 12px; color: var(--text3); margin: 6px 0; }
.bub { max-width: 82%; padding: 7px 10px 5px; border-radius: 14px; position: relative; word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; user-select: text; }
.bub.in { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-start-start-radius: 4px; }
.bub.out { align-self: flex-end; background: var(--out); color: var(--out-text); border-start-end-radius: 4px; }
.bub.note { align-self: flex-end; background: var(--note); color: var(--note-text); border: 1px solid var(--note-line); border-start-end-radius: 4px; }
.bub.pending { opacity: .65; }
.bub .who { font-size: 11.5px; font-weight: 700; color: var(--blue); margin-bottom: 2px; }
.bub.note .who { color: var(--note-text); }
.bub .ft { display: flex; justify-content: flex-end; align-items: center; gap: 3px; font-size: 11px; color: var(--text3); margin-top: 2px; }
.bub .ft svg.i { width: 15px; height: 15px; }
.bub .ft .read { color: var(--blue); }
.bub .ft .fail { color: var(--red); }
.bub .err { font-size: 11.5px; color: var(--red); margin-top: 2px; }
.bub img.media, .bub video.media { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin: 2px 0 4px; background: var(--bg3); }
.bub audio { width: 230px; max-width: 100%; height: 40px; margin: 2px 0; }
.bub .file { display: flex; align-items: center; gap: 8px; padding: 8px; background: rgba(0,0,0,.05); border-radius: 10px; margin: 2px 0 4px; color: inherit; }
.bub .quote { border-inline-start: 3px solid var(--blue); background: rgba(0,0,0,.05); padding: 4px 8px; border-radius: 6px; font-size: 13px; color: var(--text2); margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bub .mention { color: var(--blue); font-weight: 700; }
.bub.hl { animation: hl 1.4s; }
@keyframes hl { 0%, 60% { box-shadow: 0 0 0 3px var(--orange); } 100% { box-shadow: none; } }

/* composer */
.composer { border-top: 1px solid var(--line); background: var(--bg); padding: 6px 8px calc(6px + var(--safe-b)); }
.composer.note { background: var(--note); border-top-color: var(--note-line); }
.composer .box { display: flex; align-items: flex-end; gap: 4px; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 20px; padding: 9px 14px; max-height: 140px; min-height: 40px; background: var(--bg2); outline: none; line-height: 1.4; }
.composer.note textarea { background: #fffbea; border-color: var(--note-line); }
:root[data-theme="dark"] .composer.note textarea { background: #2b2410; }
.composer textarea:focus { border-color: var(--blue); }
.send { width: 40px; height: 40px; border-radius: 20px; background: var(--blue); color: #fff; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.send:disabled { opacity: .5; }
.mode { width: 40px; height: 40px; border-radius: 20px; display: inline-flex; align-items: center; justify-content: center; flex: none; color: var(--blue); }
.mode.note { color: #b88a00; }
.replybar, .suggest { display: flex; align-items: center; gap: 8px; padding: 6px 10px; margin-bottom: 6px; background: var(--bg2); border-radius: 10px; font-size: 13px; border-inline-start: 3px solid var(--blue); }
.suggest { flex-direction: column; align-items: stretch; max-height: 220px; overflow-y: auto; padding: 4px; border-inline-start: 0; border: 1px solid var(--line); background: var(--card); box-shadow: var(--shadow); }
.suggest button { text-align: start; padding: 8px 10px; border-radius: 8px; }
.suggest button:active { background: var(--bg3); }
.rec { display: flex; align-items: center; gap: 10px; height: 40px; flex: 1; padding: 0 10px; color: var(--red); font-weight: 700; }
.rec .rdot { width: 10px; height: 10px; border-radius: 5px; background: var(--red); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.closed-win { padding: 10px 12px calc(10px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--bg); display: flex; flex-direction: column; gap: 8px; }
.closed-win .txt { font-size: 13px; color: var(--text2); display: flex; gap: 8px; align-items: flex-start; }

/* sheets */
.backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); z-index: 50; animation: fade .15s; }
.sheet { position: fixed; inset-inline: 0; bottom: 0; z-index: 51; background: var(--card); border-radius: 18px 18px 0 0; max-height: 88vh; display: flex; flex-direction: column; animation: up .18s ease-out; padding-bottom: var(--safe-b); box-shadow: var(--shadow); }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--bg3); margin: 8px auto 2px; }
.sheet .sh { display: flex; align-items: center; padding: 6px 8px 6px 16px; gap: 8px; }
.sheet .sh h3 { margin: 0; font-size: 17px; flex: 1; }
.sheet .sb { overflow-y: auto; padding: 0 0 12px; }
@keyframes up { from { transform: translateY(40%); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }
.opt { display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 18px; text-align: start; font-size: 15.5px; }
.opt:active { background: var(--bg2); }
.opt.danger { color: var(--red); }
.opt .chk { margin-inline-start: auto; color: var(--blue); }
.opt .sub { font-size: 12.5px; color: var(--text3); }
.sep { height: 1px; background: var(--line); margin: 4px 0; }
.search { margin: 4px 12px 8px; display: flex; align-items: center; gap: 8px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 0 10px; }
.search input { flex: 1; border: 0; outline: none; background: none; padding: 10px 0; }

/* forms */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text2); }
.input, select.input, textarea.input { border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 11px 12px; outline: none; width: 100%; }
.input:focus { border-color: var(--blue); }
textarea.input { resize: vertical; min-height: 110px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 16px; border-radius: 12px; font-weight: 700; background: var(--blue); color: #fff; width: 100%; }
.btn:disabled { opacity: .55; }
.btn.ghost { background: var(--bg2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--red); }
.btn.sm { width: auto; padding: 8px 12px; font-size: 14px; }
.err-box { background: #fef3f2; color: #b42318; border: 1px solid #fecdca; border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
:root[data-theme="dark"] .err-box { background: #3b1513; color: #fda29b; border-color: #5a1f1b; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 15px; border: 3px solid transparent; }
.swatch.on { border-color: var(--text); }

/* contact */
.hero { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 20px 16px 12px; }
.hero .nm { font-size: 20px; font-weight: 800; text-align: center; }
.actions { display: flex; gap: 12px; justify-content: center; padding: 6px 0 14px; }
.actions button, .actions a { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--blue); font-weight: 600; min-width: 64px; }
.actions .circ { width: 44px; height: 44px; border-radius: 22px; background: var(--blue-l); display: flex; align-items: center; justify-content: center; }
.sec { padding: 12px 16px; border-top: 8px solid var(--bg2); }
.sec h4 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .02em; color: var(--text3); display: flex; align-items: center; }
.sec h4 .ib { margin-inline-start: auto; width: 32px; height: 32px; }
.kv { display: flex; padding: 9px 0; gap: 12px; border-bottom: 1px solid var(--line); align-items: center; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--text3); font-size: 13.5px; min-width: 96px; }
.kv .v { flex: 1; min-width: 0; font-weight: 500; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 14px; font-size: 13px; font-weight: 600; background: var(--bg2); border: 1px solid var(--line); }
.tag .sw { width: 9px; height: 9px; border-radius: 5px; }
.tag button { color: var(--text3); display: inline-flex; }
.stages { display: flex; flex-wrap: wrap; gap: 8px; }

/* misc */
.toast { position: fixed; bottom: calc(84px + var(--safe-b)); left: 50%; transform: translateX(-50%); background: #101828; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 80; font-size: 14px; max-width: 90vw; box-shadow: var(--shadow); animation: fade .2s; }
.toast.err { background: var(--red); }
.viewer { position: fixed; inset: 0; z-index: 90; background: #000; display: flex; flex-direction: column; }
.viewer .vt { display: flex; justify-content: space-between; padding: calc(8px + var(--safe-t)) 8px 8px; color: #fff; }
.viewer .vt .ib { color: #fff; }
.viewer img { flex: 1; object-fit: contain; width: 100%; min-height: 0; }
.login { max-width: 380px; margin: 0 auto; padding: 48px 24px; display: flex; flex-direction: column; min-height: 100%; justify-content: center; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; margin: 0 auto 12px; display: block; }
.login h2 { text-align: center; margin: 0 0 4px; }
.login p { text-align: center; margin: 0 0 24px; }
.set-group { margin: 12px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.set-group .opt + .opt { border-top: 1px solid var(--line); }
.set-title { margin: 18px 22px 0; font-size: 12.5px; font-weight: 700; color: var(--text3); text-transform: uppercase; }
.switch { margin-inline-start: auto; width: 46px; height: 28px; border-radius: 14px; background: var(--bg3); position: relative; transition: background .15s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 11px; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch.on { background: var(--blue); }
.switch.on::after { transform: translateX(18px); }
[dir="rtl"] .switch.on::after { transform: translateX(-18px); }
.seg { display: flex; background: var(--bg2); border-radius: 10px; padding: 3px; margin: 0 12px 8px; border: 1px solid var(--line); }
.seg button { flex: 1; padding: 7px; border-radius: 8px; font-size: 13.5px; font-weight: 600; color: var(--text2); }
.seg button.on { background: var(--card); color: var(--blue); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.banner { margin: 10px 12px; padding: 10px 12px; border-radius: 12px; background: var(--blue-ll); border: 1px solid var(--blue-l); font-size: 13.5px; display: flex; gap: 10px; align-items: flex-start; }
.offline { background: var(--orange); color: #fff; text-align: center; font-size: 12.5px; padding: 3px; font-weight: 600; }
.tpl-prev { background: var(--out); border-radius: 12px; padding: 10px 12px; white-space: pre-wrap; font-size: 14px; margin: 4px 0 12px; }
.spin { width: 22px; height: 22px; border: 3px solid var(--bg3); border-top-color: var(--blue); border-radius: 50%; animation: spin .7s linear infinite; margin: 24px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
