/* واتسي بوت — team inbox (WhatsApp Web layout) */
:root {
  --wa-bg: #efeae2; --wa-in: #ffffff; --wa-out: #d9fdd3; --wa-note: #fff4c7; --wa-note-line: #f0d98a;
  --wa-meta: #667781; --wa-tick: #53bdeb; --wa-hover: #f6f8fa; --wa-sel: #eef1f5; --wa-head: #f6f8fa;
  --wa-pattern: rgba(11,59,44,.045);
}
:root[data-theme="dark"] {
  --wa-bg: #0b0d0f; --wa-in: #1a1d22; --wa-out: #0f4a34; --wa-note: #2e2810; --wa-note-line: #5c4d1c;
  --wa-meta: #8b929c; --wa-hover: #14171a; --wa-sel: #1b1f24; --wa-head: #0e1012; --wa-pattern: rgba(255,255,255,.02);
}
html, body { height: 100%; }
body.ib { overflow: hidden; background: var(--bg); }
.ib-app { height: 100dvh; display: flex; }

/* ------------------------------------------------------------ narrow rail */
.ib-rail { width: 64px; flex: none; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 0; background: var(--wa-head); border-inline-end: 1px solid var(--line); }
.ib-rail img { width: 40px; height: 40px; margin-bottom: 10px; }
.ib-rail button, .ib-rail a { all: unset; cursor: pointer; position: relative; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; color: var(--muted); }
.ib-rail button:hover, .ib-rail a:hover { background: var(--line); color: var(--text); }
.ib-rail .on { background: var(--gold-soft); color: var(--gold-ink); }
.ib-rail .spacer { flex: 1; }
.ib-rail .badge { position: absolute; top: 4px; inset-inline-end: 3px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--gold); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.av { flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 16px; color: #fff; background: #8aa79a; }
.av.sm { width: 36px; height: 36px; font-size: 13px; }
.av.xs { width: 26px; height: 26px; font-size: 11px; }
.av.xl { width: 92px; height: 92px; font-size: 32px; }
.me-av { position: relative; }
.me-av i { position: absolute; bottom: 0; inset-inline-end: 0; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--wa-head); background: #25d366; }
.me-av i.busy { background: #f59e0b; } .me-av i.away { background: #9ca3af; }

/* ------------------------------------------------------------ chat list */
.ib-list { width: 400px; flex: none; display: flex; flex-direction: column; background: var(--surface); border-inline-end: 1px solid var(--line); min-width: 0; }
.ib-list-h { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--wa-head); min-height: 60px; box-sizing: border-box; }
.ib-list-h h1 { margin: 0; font-size: 19px; flex: 1; }
.ib-tools { padding: 8px 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.ib-search { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border-radius: 10px; background: var(--wa-sel); color: var(--muted); }
.ib-search input { all: unset; flex: 1; font-size: 14px; color: var(--text); }
.ib-tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.ib-tabs::-webkit-scrollbar { display: none; }
.ib-tabs button { all: unset; cursor: pointer; flex: none; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 99px; font-size: 13.5px; background: var(--wa-sel); color: var(--text-2); }
.ib-tabs button.on { background: var(--gold-soft); color: var(--gold-ink); font-weight: 700; }
.ib-tabs b { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--gold); color: #fff; font-size: 11px; display: grid; place-items: center; }
.ib-tabs button:not(.on) b { background: var(--faint); }
.ib-items { flex: 1; overflow-y: auto; }
.ib-item { all: unset; box-sizing: border-box; cursor: pointer; width: 100%; display: flex; align-items: center; gap: 12px; padding: 0 14px; height: 74px; }
.ib-item:hover { background: var(--wa-hover); }
.ib-item.sel { background: var(--wa-sel); }
.ib-item .body { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: center; gap: 2px; border-bottom: 1px solid var(--line); }
.ib-item .r1, .ib-item .r2 { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ib-item .nm { flex: 1; min-width: 0; font-size: 16px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-item time { font-size: 12px; color: var(--wa-meta); }
.ib-item.unread time { color: var(--gold-ink); font-weight: 700; }
.ib-item .pv { flex: 1; min-width: 0; font-size: 14px; color: var(--wa-meta); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 4px; }
.ib-item .un { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: #25d366; color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.tagx { flex: none; font-size: 11.5px; padding: 1px 8px; border-radius: 99px; background: var(--wa-sel); color: var(--text-2); max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tagx.me { background: var(--gold-soft); color: var(--gold-ink); font-weight: 700; }
.tagx.q { background: #fdf1d9; color: #7a5200; }
.tagx.bot { background: #e3eefc; color: #1e4e99; }
:root[data-theme="dark"] .tagx.q { background: rgba(245,158,11,.15); color: #fcd34d; }
:root[data-theme="dark"] .tagx.bot { background: rgba(83,189,235,.14); color: #93d6f5; }
.ib-empty { padding: 48px 24px; text-align: center; color: var(--muted); font-size: 14px; }

/* ------------------------------------------------------------ conversation */
.ib-chat { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--wa-bg); position: relative; }
.ib-chat::before { content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(var(--wa-pattern) 1.2px, transparent 1.3px), radial-gradient(var(--wa-pattern) 1.2px, transparent 1.3px);
  background-size: 26px 26px; background-position: 0 0, 13px 13px; }
.ib-chat-h { position: relative; z-index: 2; display: flex; align-items: center; gap: 12px; padding: 8px 16px; min-height: 60px; box-sizing: border-box; background: var(--wa-head); border-inline-start: 1px solid var(--line); }
.ib-chat-h .who { flex: 1; min-width: 0; cursor: pointer; }
.ib-chat-h .who b { display: block; font-size: 16px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-chat-h .who small { display: block; font-size: 13px; color: var(--wa-meta); }
.ib-chat-h .who small.typing { color: #25a35a; font-weight: 600; }
.ib-acts { display: flex; align-items: center; gap: 6px; }
.ib-acts .btn { min-height: 36px; padding: 0 12px; font-size: 13.5px; }
.ib-back { display: none !important; }
.ib-msgs { position: relative; z-index: 1; flex: 1; overflow-y: auto; padding: 16px 7% 10px; display: flex; flex-direction: column; gap: 2px; }
.ib-day { align-self: center; margin: 10px 0 6px; padding: 5px 12px; border-radius: 8px; background: var(--surface); color: var(--wa-meta); font-size: 12.5px; box-shadow: 0 1px .5px rgba(11,20,26,.13); }
.ib-evt { align-self: center; margin: 6px 0; max-width: 80%; padding: 5px 12px; border-radius: 8px; background: color-mix(in srgb, var(--surface) 85%, transparent); color: var(--wa-meta); font-size: 12.5px; text-align: center; box-shadow: 0 1px .5px rgba(11,20,26,.1); }
.bb { position: relative; max-width: min(65%, 560px); padding: 6px 9px 7px; border-radius: 8px; font-size: 14.5px; line-height: 1.55; box-shadow: 0 1px .5px rgba(11,20,26,.13); word-wrap: break-word; overflow-wrap: anywhere; margin-top: 2px; }
.bb.in { align-self: flex-start; background: var(--wa-in); }
.bb.out { align-self: flex-end; background: var(--wa-out); }
.bb.first.in { border-start-start-radius: 0; margin-top: 8px; }
.bb.first.out { border-start-end-radius: 0; margin-top: 8px; }
.bb.nt { align-self: stretch; max-width: none; margin: 8px 6%; background: var(--wa-note); border: 1px dashed var(--wa-note-line); }
.bb .by { display: block; font-size: 12.5px; font-weight: 700; color: var(--gold-ink); margin-bottom: 1px; }
.bb.nt .by { color: #8a6500; display: flex; align-items: center; gap: 5px; }
:root[data-theme="dark"] .bb.nt .by { color: #f0d48a; }
:root[data-theme="dark"] .bb.out .by { color: #8fe7c2; }
.bb .tx { white-space: pre-wrap; }
.bb .mt { float: inline-end; display: inline-flex; align-items: center; gap: 3px; margin: 6px 10px -4px 0; margin-inline-start: 10px; font-size: 11px; color: var(--wa-meta); position: relative; top: 4px; }
.bb .src { font-size: 10.5px; padding: 0 5px; border-radius: 4px; background: rgba(0,0,0,.06); }
:root[data-theme="dark"] .bb .src { background: rgba(255,255,255,.08); }
.tick { width: 16px; height: 11px; }
.tick.read { color: var(--wa-tick); }
.tick.fail { color: #d93025; width: 14px; height: 14px; }
.bb .img { display: block; margin: -2px -5px 4px; border-radius: 6px; overflow: hidden; max-width: 330px; background: rgba(0,0,0,.05); }
.bb .img img { display: block; width: 100%; max-height: 360px; object-fit: cover; }
.bb video { display: block; max-width: 330px; border-radius: 6px; margin: -2px -5px 4px; }
.bb audio { display: block; width: 260px; max-width: 100%; height: 40px; margin-bottom: 2px; }
.doc { display: flex; align-items: center; gap: 10px; margin: -2px -5px 4px; padding: 10px; border-radius: 6px; background: rgba(0,0,0,.05); color: inherit; text-decoration: none; min-width: 220px; }
:root[data-theme="dark"] .doc { background: rgba(255,255,255,.06); }
.doc i { font-style: normal; flex: none; width: 34px; height: 40px; border-radius: 5px; background: #e5484d; color: #fff; display: grid; place-items: center; font-size: 10px; font-weight: 700; }
.doc span { flex: 1; min-width: 0; }
.doc b { display: block; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc small { color: var(--wa-meta); font-size: 12px; }
.ib-older { align-self: center; margin-bottom: 8px; }
.ib-newpill { position: absolute; z-index: 3; bottom: 86px; inset-inline-end: 24px; width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--surface); color: var(--muted); box-shadow: 0 2px 6px rgba(0,0,0,.18); cursor: pointer; display: grid; place-items: center; }
.ib-newpill b { position: absolute; top: -6px; inset-inline-start: -4px; min-width: 20px; height: 20px; border-radius: 99px; background: #25d366; color: #fff; font-size: 11px; display: grid; place-items: center; }

/* ------------------------------------------------------------ composer */
.ib-comp { position: relative; z-index: 2; background: var(--wa-head); padding: 8px 14px 10px; display: grid; gap: 6px; }
.ib-mode { display: flex; gap: 4px; }
.ib-mode button { all: unset; cursor: pointer; padding: 3px 12px; border-radius: 99px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.ib-mode button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.ib-mode button.on.nt { background: var(--wa-note); color: #7a5a00; }
.ib-row { display: flex; align-items: flex-end; gap: 6px; }
.ib-row .ibtn { all: unset; cursor: pointer; flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.ib-row .ibtn:hover { background: var(--line); color: var(--text); }
.ib-row .ibtn.on { color: var(--gold-ink); }
.ib-input { flex: 1; min-width: 0; display: flex; align-items: flex-end; border-radius: 10px; background: var(--surface); padding: 9px 12px; }
.ib-input.nt { background: var(--wa-note); }
.ib-input textarea { all: unset; flex: 1; min-height: 24px; max-height: 140px; overflow-y: auto; font-size: 15px; line-height: 1.6; white-space: pre-wrap; color: var(--text); }
.ib-send { all: unset; cursor: pointer; flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--gold); color: #fff; }
.ib-send:disabled { opacity: .5; cursor: default; }
.ib-send.nt { background: #c99a1e; }
.ib-file { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 10px; background: var(--surface); font-size: 13px; }
.ib-file span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ib-lock { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px; font-size: 14px; color: var(--muted); }
.pop { position: absolute; z-index: 20; bottom: calc(100% + 6px); inset-inline-start: 14px; width: min(420px, calc(100% - 28px)); max-height: 320px; overflow-y: auto; border-radius: 12px; background: var(--surface); box-shadow: 0 8px 28px rgba(0,0,0,.18); border: 1px solid var(--line); }
.pop .pi { all: unset; box-sizing: border-box; cursor: pointer; display: block; width: 100%; padding: 9px 14px; border-bottom: 1px solid var(--line); }
.pop .pi:hover, .pop .pi.hl { background: var(--wa-hover); }
.pop .pi b { display: block; font-size: 14px; }
.pop .pi small { display: block; color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.emojis { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; padding: 8px; }
.emojis button { all: unset; cursor: pointer; text-align: center; font-size: 22px; line-height: 38px; border-radius: 8px; }
.emojis button:hover { background: var(--wa-hover); }

/* ------------------------------------------------------------ info panel */
.ib-info { width: 340px; flex: none; background: var(--surface); border-inline-start: 1px solid var(--line); display: flex; flex-direction: column; overflow-y: auto; }
.ib-info .hd { display: flex; align-items: center; gap: 10px; padding: 0 16px; min-height: 60px; background: var(--wa-head); font-weight: 600; }
.ib-info .sec { padding: 18px 20px; border-bottom: 8px solid var(--wa-sel); display: grid; gap: 10px; }
.ib-info .center { justify-items: center; text-align: center; }
.ib-info dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 14px; }
.ib-info dt { color: var(--muted); }
.ib-info dd { margin: 0; text-align: end; }
.team-row { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.team-row .grow { flex: 1; }
.dotx { width: 9px; height: 9px; border-radius: 50%; background: #9ca3af; }
.dotx.on { background: #25d366; } .dotx.busy { background: #f59e0b; }

/* ------------------------------------------------------------ welcome / auth */
.ib-welcome { flex: 1; display: grid; place-items: center; text-align: center; background: var(--wa-head); border-bottom: 6px solid var(--gold); padding: 24px; }
.ib-welcome img { width: 96px; height: 96px; }
.ib-welcome h2 { margin: 18px 0 6px; font-size: 28px; font-weight: 300; }
.ib-welcome p { margin: 0; color: var(--muted); max-width: 46ch; }
.ib-auth { min-height: 100dvh; display: grid; place-items: center; background: var(--deep); padding: 20px; }
.ib-auth .box { width: min(420px, 100%); background: var(--surface); border-radius: 20px; padding: 30px; display: grid; gap: 16px; box-shadow: 0 30px 60px -30px rgba(0,0,0,.5); }
.ib-auth .box img { width: 56px; height: 56px; }
.ib-auth h1 { margin: 0; font-size: 22px; }
.ib-auth p { margin: 0; color: var(--muted); }
.pick { display: grid; gap: 6px; max-height: 320px; overflow-y: auto; }
.pick button { all: unset; box-sizing: border-box; cursor: pointer; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); }
.pick button:hover { border-color: var(--gold); }
.pick button.on { border-color: var(--gold); background: var(--gold-soft); }
.pick button[disabled] { opacity: .45; cursor: not-allowed; }

@media (max-width: 1280px) { .ib-info { position: absolute; inset-block: 0; inset-inline-end: 0; z-index: 30; box-shadow: var(--shadow-lg); } }
@media (max-width: 900px) {
  .ib-rail { display: none; }
  .ib-list { width: 100%; border: 0; }
  .ib-app.has-chat .ib-list { display: none; }
  .ib-app:not(.has-chat) .ib-chat, .ib-app:not(.has-chat) .ib-welcome { display: none; }
  .ib-back { display: grid !important; }
  .ib-msgs { padding: 12px 10px 8px; }
  .bb { max-width: 85%; }
  .ib-acts .lbl { display: none; }
  .ib-info { width: 100%; }
}
/* bubbles size to their content and never shrink inside the scrolling column */
.ib-msgs .bb, .ib-msgs .ib-evt, .ib-msgs .ib-day, .ib-msgs .ib-older { flex-shrink: 0; }
.bb:not(.nt) { width: fit-content; }
.bb .img { width: min(300px, 100%); }
.bb .mt { float: left; }
[dir="ltr"] .bb .mt { float: right; }

/* dark ("B"): mint accents carry dark text */
:root[data-theme="dark"] .ib-rail .badge, :root[data-theme="dark"] .ib-tabs b, :root[data-theme="dark"] .ib-send { color: #04140d; }
:root[data-theme="dark"] .ib-send { box-shadow: 0 0 0 1px rgba(61,220,151,.4), 0 8px 22px -10px rgba(61,220,151,.6); }
:root[data-theme="dark"] .ib-rail { border-inline-end-color: rgba(255,255,255,.05); }
