/* ilmChat v4.4 — premium design */
:root {
  --brand: #0F766E; --brand-2: #14A08F; --brand-deep: #0A4F4A; --brand-soft: #E1F3EF; --brand-tint: #F2FAF8;
  --bg: #F4F7F6; --panel: #FFFFFF; --line: #E4EBE9; --chatbg: #ECF2F0;
  --ink: #132421; --muted: #6F8079; --mine: #DCF3EA; --mine-2: #CFEEE2; --theirs: #FFFFFF;
  --danger: #DC2626; --ok: #22C55E; --shadow: 0 1px 2px rgba(19,36,33,.06), 0 1px 1px rgba(19,36,33,.03);
  --shadow-lg: 0 12px 32px rgba(19,36,33,.14); --r: 18px;
  --font: "Manrope", "Noto Sans Bengali", "Noto Sans Arabic", system-ui, sans-serif;
  --head-grad: linear-gradient(135deg, #0F766E 0%, #0B5C56 100%); --head-ink: #FFFFFF;
  color-scheme: light;
}
:root[data-theme="dark"] { --bg: #0B1413; --panel: #121D1B; --line: #1F2D2A; --chatbg: #0E1715; --ink: #E7F0ED; --muted: #8CA39C; --mine: #174A41; --mine-2: #134039; --theirs: #182523; --brand-soft: #163B36; --brand-tint: #11261F; --head-grad: linear-gradient(135deg, #121D1B, #0F1A18); --shadow: none; --shadow-lg: 0 12px 32px rgba(0,0,0,.5); color-scheme: dark; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg: #0B1413; --panel: #121D1B; --line: #1F2D2A; --chatbg: #0E1715; --ink: #E7F0ED; --muted: #8CA39C; --mine: #174A41; --mine-2: #134039; --theirs: #182523; --brand-soft: #163B36; --brand-tint: #11261F; --head-grad: linear-gradient(135deg, #121D1B, #0F1A18); --shadow: none; --shadow-lg: 0 12px 32px rgba(0,0,0,.5); color-scheme: dark; } }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; }
.hidden { display: none !important; }
[dir="rtl"] { direction: rtl; }
::-webkit-scrollbar { width: 6px; } ::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

/* ---------- Splash ---------- */
#splash { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: grid; place-items: center; align-content: center; gap: 22px; }
#splash img { width: 88px; height: 88px; border-radius: 22px; box-shadow: var(--shadow-lg); }
#splash .spin { width: 24px; height: 24px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Auth ---------- */
#auth { min-height: 100%; display: grid; place-items: center; padding: 28px 24px; background: radial-gradient(1200px 500px at 50% -10%, var(--brand-soft), transparent 70%), var(--bg); }
.auth-card { width: 100%; max-width: 380px; }
.logo { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.logo img { width: 54px; height: 54px; border-radius: 15px; box-shadow: 0 8px 22px rgba(15,118,110,.28); }
.logo h1 { font-size: 32px; margin: 0; letter-spacing: -.03em; font-weight: 800; }
.logo h1 span { color: var(--brand); }
.tagline { color: var(--muted); margin: 0 0 30px; }
.field { display: block; margin-bottom: 12px; }
.field input { width: 100%; padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); transition: border-color .15s, box-shadow .15s; }
.field input:focus { border-color: var(--brand-2); box-shadow: 0 0 0 4px var(--brand-soft); outline: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 14px 16px; border-radius: 14px; font-weight: 700; width: 100%; transition: transform .08s, box-shadow .15s; }
.btn:active { transform: scale(.985); }
.btn-brand { background: var(--head-grad); color: #fff; box-shadow: 0 6px 18px rgba(15,118,110,.32); }
.btn-ghost { background: var(--panel); border: 1px solid var(--line); }
.btn-text { width: auto; padding: 6px 8px; color: var(--brand); font-weight: 700; }
.sep { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 18px 0; font-size: 13px; }
.sep::before, .sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 8px; }
.lang-row { display: flex; gap: 6px; justify-content: center; margin-top: 26px; }
.lang-row button { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); font-size: 13px; }
.lang-row button[aria-pressed="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- App shell ---------- */
#app { position: fixed; inset: 0; display: grid; grid-template-columns: 380px 1fr; }
.side { border-inline-end: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chatbg); position: relative; }
.main::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .45; background-image: radial-gradient(circle at 1px 1px, var(--line) 1.2px, transparent 1.8px); background-size: 28px 28px; }
.main > * { position: relative; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--panel); border-bottom: 1px solid var(--line); min-height: 64px; flex: none; }
.topbar h2 { font-size: 24px; margin: 0 0 0 6px; flex: 1; font-weight: 800; letter-spacing: -.02em; }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); flex: none; transition: background .15s, color .15s, transform .08s; }
.icon-btn:hover { background: var(--brand-soft); color: var(--brand); } .icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.search { padding: 6px 12px 10px; background: var(--panel); flex: none; }
.search input { width: 100%; padding: 11px 18px; border-radius: 999px; border: 1px solid transparent; background: var(--bg); transition: border-color .15s, background .15s; }
.search input:focus { background: var(--panel); border-color: var(--brand-2); outline: none; }
.list { flex: 1; overflow-y: auto; min-height: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; width: 100%; text-align: start; transition: background .12s; }
.row + .row { border-top: 1px solid var(--line); }
.row:hover { background: var(--brand-tint); } .row[aria-current="true"] { background: var(--brand-soft); }
.avatar { width: 52px; height: 52px; border-radius: 50%; flex: none; background: linear-gradient(135deg, var(--brand-2), var(--brand-deep)); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 18px; overflow: hidden; position: relative; box-shadow: inset 0 0 0 1px rgba(255,255,255,.15); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 40px; height: 40px; font-size: 15px; }
.avatar.xl { width: 116px; height: 116px; font-size: 42px; box-shadow: 0 0 0 6px rgba(255,255,255,.08), var(--shadow-lg); }
.avatar.group { background: linear-gradient(135deg, #0B5C56, #083E3A); }
.dot { position: absolute; right: 2px; bottom: 2px; width: 13px; height: 13px; border-radius: 50%; background: var(--ok); border: 2.5px solid var(--panel); }
[dir="rtl"] .dot { right: auto; left: 2px; }
.row .meta { flex: 1; min-width: 0; }
.row .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.row .top b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; font-weight: 700; }
.row .time { font-size: 12px; color: var(--muted); flex: none; }
.row .preview { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; margin-top: 1px; }
.row .preview .badge { margin-inline-start: auto; }
.badge { background: var(--brand); color: #fff; font-size: 11px; font-weight: 800; border-radius: 999px; padding: 2px 7px; min-width: 20px; text-align: center; box-shadow: 0 2px 6px rgba(15,118,110,.35); }
.empty { padding: 48px 28px; text-align: center; color: var(--muted); line-height: 1.6; }
.placeholder { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 24px; }
.placeholder img { width: 88px; opacity: .28; margin-bottom: 14px; display: block; margin-inline: auto; filter: grayscale(.4); }

/* ---------- Conversation ---------- */
.chat-head { backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); background: color-mix(in srgb, var(--panel) 88%, transparent); }
.chat-head .meta { flex: 1; min-width: 0; }
.chat-head b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16.5px; font-weight: 700; }
.chat-head small { color: var(--muted); font-size: 12.5px; display: block; line-height: 1.25; }
.chat-head small.on { color: var(--brand); font-weight: 700; }
#messages { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 12px 12px; display: flex; flex-direction: column; gap: 3px; }
.day { align-self: center; font-size: 12px; font-weight: 700; color: var(--muted); background: var(--panel); box-shadow: var(--shadow); padding: 4px 12px; border-radius: 999px; margin: 12px 0 8px; }
.msg { max-width: min(78%, 560px); padding: 8px 11px 6px; border-radius: var(--r); background: var(--theirs); box-shadow: var(--shadow); align-self: flex-start; position: relative; word-break: break-word; white-space: pre-wrap; border-start-start-radius: 6px; animation: pop .16s ease-out; }
.msg.mine { background: linear-gradient(180deg, var(--mine), var(--mine-2)); align-self: flex-end; border-start-start-radius: var(--r); border-start-end-radius: 6px; }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.98); } }
.msg + .msg { margin-top: 1px; }
.msg .who { font-size: 12.5px; font-weight: 700; color: var(--brand); display: block; margin-bottom: 2px; }
.msg a { color: var(--brand); }
.msg img.pic { max-width: 100%; max-height: 380px; border-radius: 12px; display: block; margin: 2px 0 4px; cursor: zoom-in; }
.msg .filelink { display: inline-flex; gap: 8px; align-items: center; color: var(--brand); font-weight: 700; text-decoration: none; padding: 6px 4px; }
.msg .call-log { color: var(--muted); font-weight: 600; }
.msg .stamp { float: inline-end; font-size: 11px; color: var(--muted); margin: 8px 0 0 10px; display: inline-flex; gap: 3px; align-items: center; }
[dir="rtl"] .msg .stamp { margin: 8px 10px 0 0; }
.msg .stamp .ticks { font-weight: 800; letter-spacing: -.2em; }
.msg .stamp .ticks.seen { color: #2B7FFF; }
.msg.gone { font-style: italic; color: var(--muted); }
.msg .del { position: absolute; top: -8px; inset-inline-end: -4px; background: var(--panel); border: 1px solid var(--line); border-radius: 50%; width: 22px; height: 22px; font-size: 12px; display: none; line-height: 1; box-shadow: var(--shadow); }
.msg.mine:hover .del { display: grid; place-items: center; }
/* voice player */
.voice { display: flex; align-items: center; gap: 10px; min-width: 210px; padding: 4px 0 2px; }
.vplay { width: 38px; height: 38px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; flex: none; box-shadow: 0 3px 10px rgba(15,118,110,.3); }
.vplay svg { width: 20px; height: 20px; fill: currentColor; }
.vplay .ic-pause { display: none; } .playing .vplay .ic-play { display: none; } .playing .vplay .ic-pause { display: block; }
.vtrack { flex: 1; height: 6px; border-radius: 999px; background: rgba(0,0,0,.12); position: relative; cursor: pointer; }
:root[data-theme="dark"] .vtrack { background: rgba(255,255,255,.14); }
.vfill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 999px; background: var(--brand); transition: width .2s linear; }
[dir="rtl"] .vfill { inset: 0 0 0 auto; }
.voice .dur { font-size: 12px; color: var(--muted); min-width: 32px; text-align: end; font-variant-numeric: tabular-nums; }
/* composer */
.compose { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); flex: none; }
.compose textarea { flex: 1; resize: none; max-height: 140px; padding: 12px 18px; border-radius: 24px; border: 1px solid var(--line); background: var(--bg); line-height: 1.4; min-height: 46px; transition: border-color .15s, background .15s; }
.compose textarea:focus { outline: none; border-color: var(--brand-2); background: var(--panel); }
.compose .send { background: var(--head-grad); color: #fff; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; flex: none; box-shadow: 0 5px 14px rgba(15,118,110,.35); transition: transform .08s; }
.compose .send:active { transform: scale(.92); }
.compose .send svg { width: 21px; height: 21px; fill: currentColor; }
.compose .send.mic.rec { background: var(--danger); animation: pulse 1s infinite; box-shadow: 0 5px 14px rgba(220,38,38,.35); }
[dir="rtl"] .compose #btnSend svg { transform: scaleX(-1); }
.compose.recording textarea, .compose.recording #btnAttach { display: none; }
#recBar { flex: 1; display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 8px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- Call screen ---------- */
#callScreen { position: fixed; inset: 0; z-index: 40; background: radial-gradient(900px 600px at 50% 0%, #15423D, #0A1614 70%); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 48px 20px max(36px, env(safe-area-inset-bottom)); }
#remoteVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; background: #000; }
#localVideo { position: absolute; top: 16px; inset-inline-end: 16px; width: 112px; aspect-ratio: 3/4; object-fit: cover; border-radius: 16px; border: 2px solid rgba(255,255,255,.45); display: none; z-index: 2; box-shadow: var(--shadow-lg); }
#callScreen.video #remoteVideo, #callScreen.video #localVideo { display: block; }
#callScreen.video .call-info { background: linear-gradient(180deg, rgba(0,0,0,.6), transparent); position: absolute; top: 0; left: 0; right: 0; padding: 22px 20px 44px; flex-direction: row; gap: 14px; }
#callScreen.video .call-info .avatar.xl { width: 46px; height: 46px; font-size: 18px; box-shadow: none; }
#callScreen.video .call-info h2 { font-size: 18px; } #callScreen.video .call-info p { margin: 0; }
.call-info { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; z-index: 1; margin-top: 8vh; }
.call-info h2 { margin: 8px 0 0; font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.call-info p { margin: 0; color: rgba(255,255,255,.72); font-size: 15px; font-variant-numeric: tabular-nums; }
.call-btns { display: flex; gap: 28px; z-index: 3; }
.cbtn { width: 66px; height: 66px; border-radius: 50%; background: rgba(255,255,255,.14); backdrop-filter: blur(8px); display: grid; place-items: center; color: #fff; transition: transform .1s, background .15s; }
.cbtn:active { transform: scale(.92); }
.cbtn svg { width: 28px; height: 28px; fill: currentColor; }
.cbtn.off { background: #fff; color: #0A1614; }
.cbtn.accept { background: var(--ok); box-shadow: 0 8px 24px rgba(34,197,94,.45); } .cbtn.decline { background: var(--danger); box-shadow: 0 8px 24px rgba(220,38,38,.45); }
#incomingBtns .cbtn { width: 74px; height: 74px; }
#incomingBtns .cbtn.accept { animation: ring 1.2s infinite; }
@keyframes ring { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }

/* ---------- Dialogs ---------- */
dialog { border: 0; border-radius: 22px; padding: 0; background: var(--panel); color: var(--ink); width: min(440px, 94vw); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(10,20,18,.5); backdrop-filter: blur(4px); }
.dlg { padding: 22px; }
.dlg h3 { margin: 0 0 16px; font-size: 20px; letter-spacing: -.01em; }
.dlg input { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.dlg input:focus { outline: none; border-color: var(--brand-2); background: var(--panel); }
.dlg .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.dlg .actions .btn { width: auto; }
.pick { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 14px; }
.pick label { display: flex; align-items: center; gap: 10px; padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.pick input { accent-color: var(--brand); width: 18px; height: 18px; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; padding: 10px; border-radius: 12px; border: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }
.lbl { font-size: 13px; color: var(--muted); display: block; margin: 14px 0 6px; }
.avatar-edit { display: flex; align-items: center; gap: 14px; }
.avatar-edit .avatar { width: 66px; height: 66px; font-size: 24px; cursor: pointer; }
#lightbox { background: transparent; box-shadow: none; width: auto; max-width: 96vw; }
#lightbox img { max-width: 96vw; max-height: 90vh; border-radius: 14px; }
.toast { position: fixed; bottom: max(24px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 70; white-space: nowrap; box-shadow: var(--shadow-lg); }
.toast.show { opacity: 1; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  .side { border: 0; }
  #app.in-chat .side { display: none; }
  #app:not(.in-chat) .main { display: none; }
  .side .topbar { background: var(--head-grad); color: var(--head-ink); border: 0; min-height: 70px; padding: 12px 14px; }
  .side .topbar h2 { font-size: 26px; }
  .side .topbar .icon-btn { color: rgba(255,255,255,.92); } .side .topbar .icon-btn:hover { background: rgba(255,255,255,.16); color: #fff; }
  .side .topbar .avatar { box-shadow: 0 0 0 2px rgba(255,255,255,.55); }
  .side .search { padding: 10px 12px; background: var(--head-grad); }
  .side .search input { background: rgba(255,255,255,.95); border: 0; }
  :root[data-theme="dark"] .side .search input { background: var(--bg); }
  .side .list { border-top-left-radius: 18px; border-top-right-radius: 18px; margin-top: -8px; background: var(--panel); position: relative; }
  .msg { max-width: 86%; }
  .msg .del { display: none !important; }
}
@media (min-width: 761px) { .only-mobile { display: none !important; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
