/* WhatsApp's look: its greens and neutrals, light and dark following the phone, the phone's own font. */
:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --header: #ffffff;
  --field: #ffffff;
  --ink: #111b21;
  --ink-2: #3b4a54;
  --muted: #667781;
  --line: #e9edef;
  --line-2: #f0f2f5;
  --primary: #00a884;
  --primary-hover: #008f72;
  --primary-ink: #008069;
  --primary-soft: #e7fce3;
  --on-primary: #ffffff;
  --link: #027eb5;
  --unread: #25d366;
  --on-unread: #ffffff;
  --tick-read: #53bdeb;
  --slate: #54656f;
  --success: #008069;
  --success-soft: #e7fce3;
  --warning: #a34d00;
  --warning-soft: #fff1e0;
  --notice: #fff5c4;
  --on-notice: #54656f;
  --danger: #d93025;
  --danger-soft: #fdecea;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --chat-bg: #efeae2;
  --radius: 12px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --shadow: 0 1px 2px rgba(11, 20, 26, 0.06);
  --shadow-lg: 0 18px 48px rgba(11, 20, 26, 0.22);
  --font: -apple-system, BlinkMacSystemFont, 'SF Arabic', 'Segoe UI', Roboto, 'Noto Sans Arabic', Tahoma, sans-serif;
  --font-display: var(--font);
  --nav-h: 64px;
  --top-h: 56px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b141a;
    --surface: #111b21;
    --surface-2: #202c33;
    --header: #202c33;
    --field: #2a3942;
    --ink: #e9edef;
    --ink-2: #d1d7db;
    --muted: #8696a0;
    --line: rgba(134, 150, 160, 0.2);
    --line-2: rgba(134, 150, 160, 0.12);
    --primary: #00a884;
    --primary-hover: #06cf9c;
    --primary-ink: #00a884;
    --primary-soft: rgba(0, 168, 132, 0.18);
    --on-primary: #111b21;
    --link: #53bdeb;
    --unread: #00a884;
    --on-unread: #111b21;
    --success: #00a884;
    --success-soft: rgba(0, 168, 132, 0.16);
    --warning: #f0a54a;
    --warning-soft: rgba(240, 165, 74, 0.14);
    --notice: #182229;
    --on-notice: #ffd279;
    --danger: #f15c6d;
    --danger-soft: rgba(241, 92, 109, 0.14);
    --bubble-in: #202c33;
    --bubble-out: #005c4b;
    --chat-bg: #0b141a;
    --shadow-sm: 0 1px 0.5px rgba(0, 0, 0, 0.3);
    --shadow: none;
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
/* app-like: no pinch / double-tap / focus zoom, never wider than the screen */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; touch-action: pan-x pan-y; overflow-x: clip; }
body { overflow-x: clip; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.3; font-family: var(--font-display); font-weight: 700; letter-spacing: 0; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.05rem; font-family: var(--font); font-weight: 600; }
/* the chats page is a plain list, like WhatsApp's */
html[data-view='chats'] body { background: var(--surface); }
p { margin: 0.2rem 0; }
a { color: var(--primary-ink); }
svg { flex: none; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.error { color: var(--danger); min-height: 1.3em; font-size: 0.9rem; margin: 0; }
.error:empty { min-height: 0; }
.hint { font-size: 0.82rem; color: var(--muted); margin: 0; }
code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; font-size: 0.85em; direction: ltr; display: inline-block; font-family: ui-monospace, Menlo, Consolas, monospace; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
/* app chrome behaves like buttons, not text: a long press doesn't select it or open link previews */
.btn, .icon-btn, .nav, .segmented, .switch, .chip, summary, .days span, .chat-list li, .to-bottom, .topbar, .lightbox .bar { -webkit-user-select: none; user-select: none; }
.nav a, .chat-list li, .lightbox img { -webkit-touch-callout: none; }

/* form controls: 16px keeps iOS from zooming on focus */
input, textarea, select {
  font: inherit;
  font-size: 16px;
  color: inherit;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  min-height: 46px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.8; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; line-height: 1.7; }
select { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: 18px 50%, 13px 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-left: 2.2rem; }
input[type='search']::-webkit-search-cancel-button { display: none; }
input[type='time'] { direction: ltr; text-align: right; }
label { display: grid; gap: 0.35rem; font-weight: 600; font-size: 0.92rem; }
.pw-field { position: relative; display: block; }
.pw-field input { padding-right: 2.9rem; }
.pw-field .pw-eye { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.pw-field .pw-eye[aria-pressed='true'] { color: var(--primary-ink); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 600; font-size: 0.92rem; margin-bottom: 0.4rem; padding: 0; }

/* buttons */
.btn {
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  min-height: 44px;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
}
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.btn:hover { border-color: color-mix(in srgb, var(--ink) 25%, transparent); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.lg { min-height: 50px; font-size: 1rem; }
.btn.sm { min-height: 36px; padding: 0.3rem 0.85rem; font-size: 0.86rem; }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 999px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; flex: none; padding: 0; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.row { display: flex; gap: 0.5rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }

/* switch */
.switch { display: inline-flex; align-items: center; gap: 0.55rem; cursor: pointer; font-weight: 700; flex: none; position: relative; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch > span { width: 46px; height: 28px; border-radius: 99px; background: color-mix(in srgb, var(--muted) 35%, transparent); position: relative; transition: background 0.2s; flex: none; }
.switch > span::after { content: ''; position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.2s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(-18px); }
.switch input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.switch em { font-style: normal; font-size: 0.92rem; }
.switch.labeled { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 0.35rem 0.5rem 0.35rem 0.9rem; box-shadow: var(--shadow-sm); min-height: 44px; }

/* lockup */
.lockup { display: inline-flex; align-items: center; gap: 0.5rem; }
.lockup .mark { width: 34px; height: 34px; border-radius: 9px; }
.lockup .word { font-family: var(--font-display); font-weight: 800; font-size: 1.35rem; line-height: 1; color: var(--ink); }
.lockup .tag { font-size: 0.72rem; font-weight: 700; color: var(--primary-ink); background: var(--primary-soft); border-radius: 999px; padding: 0.1rem 0.55rem; line-height: 1.6; }
.lockup.big { flex-direction: column; gap: 0.35rem; }
.lockup.big .mark { width: 64px; height: 64px; border-radius: 17px; box-shadow: 0 10px 30px rgba(51, 65, 85, 0.25); }
.lockup.big .word { font-size: 2rem; margin-top: 0.3rem; }

.status-chip { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.78rem; font-weight: 700; color: var(--warning); background: var(--warning-soft); border-radius: 999px; padding: 0.15rem 0.65rem; white-space: nowrap; }
.status-chip i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status-chip.ok { color: var(--success); background: var(--success-soft); }
.status-chip.bad { color: var(--danger); background: var(--danger-soft); }

/* ---------- login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); }
.login-card { width: min(400px, 100%); background: var(--surface); border-radius: 24px; padding: 2.2rem 1.5rem 1.6rem; display: grid; gap: 0.75rem; text-align: center; box-shadow: var(--shadow-lg); border: 1px solid var(--line); }
.login-card h1 { font-size: 1.3rem; margin-top: 0.6rem; }
.login-card p.muted { margin-bottom: 0.6rem; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.topbar { display: none; }
.sidebar { background: var(--surface); border-inline-end: 1px solid var(--line); padding: 1.1rem 0.8rem; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 1rem; }
.sidebar-head { display: grid; gap: 0.6rem; justify-items: start; padding: 0.2rem 0.5rem 0.4rem; }
.nav { display: grid; gap: 0.2rem; }
.nav a { display: flex; align-items: center; gap: 0.7rem; padding: 0.65rem 0.8rem; border-radius: 12px; color: var(--ink-2); text-decoration: none; font-weight: 600; position: relative; min-height: 44px; }
.nav a:hover { background: var(--surface-2); }
.nav a svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linejoin: round; stroke-linecap: round; }
.nav a.active { background: var(--primary-soft); color: var(--primary-ink); font-weight: 700; }
.badge { background: var(--unread); color: var(--on-unread); font-size: 0.72rem; font-weight: 700; min-width: 20px; height: 20px; border-radius: 99px; display: inline-grid; place-items: center; padding: 0 6px; margin-inline-start: auto; line-height: 1; }
.side-link { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; color: var(--muted); font-size: 0.86rem; font-weight: 600; text-decoration: none; padding: 0.7rem 0.8rem; border-radius: 12px; border: 1px dashed var(--line); }
.side-link:hover { color: var(--primary-ink); border-color: var(--primary); }
.side-link svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.main { padding: 1.6rem clamp(16px, 3vw, 2.4rem) 3rem; width: 100%; max-width: 1120px; margin-inline: auto; min-width: 0; }
.main.wide { max-width: 1480px; }
.view { display: none; }
.view.active { display: block; animation: fade 0.16s ease; }
/* opacity only: a transform here would trap the full-screen chat overlay inside the view */
.chats-view.active { animation: none; }
@keyframes fade { from { opacity: 0; } }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem 1rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.page-head > div { min-width: 0; }
.page-head p { margin-top: 0.15rem; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; margin: 1.6rem 0 0.8rem; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.15rem; margin-bottom: 1rem; box-shadow: var(--shadow); display: grid; gap: 0.75rem; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.75rem; }
.card-head > div { min-width: 0; }
.card-head .switch { margin-top: 0.15rem; }

/* ---------- home ---------- */
.conn { display: flex; gap: 0.9rem; align-items: center; flex-wrap: wrap; }
.conn-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--warning); flex: none; box-shadow: 0 0 0 5px var(--warning-soft); }
.conn-dot.ok { background: var(--success); box-shadow: 0 0 0 5px var(--success-soft); }
.conn-dot.bad { background: var(--danger); box-shadow: 0 0 0 5px var(--danger-soft); }
.conn-info { flex: 1; min-width: 180px; }
.pair { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 1.5rem; align-items: start; }
.pair img { width: 228px; height: 228px; border-radius: 14px; background: #fff; padding: 8px; border: 1px solid var(--line); display: block; }
.pair-steps { margin: 0.4rem 0 0.9rem; padding-inline-start: 1.2rem; color: var(--ink-2); }
.pair-steps li { margin-bottom: 0.2rem; }
.pair-form { display: flex; gap: 0.5rem; }
.pair-form input { flex: 1; min-width: 0; }
.pair-code { font-size: 1.9rem; font-weight: 800; letter-spacing: 0.12em; direction: ltr; text-align: center; background: var(--primary-soft); color: var(--primary-ink); border-radius: 14px; padding: 0.55rem; margin-top: 0.4rem; font-family: ui-monospace, Menlo, Consolas, monospace; }
.pair details { margin-top: 0.6rem; border-top: 1px solid var(--line-2); padding-top: 0.2rem; }
.pair summary { cursor: pointer; color: var(--primary-ink); font-weight: 700; min-height: 44px; display: flex; align-items: center; }
.pair details img { margin: 0.4rem auto 0; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.8rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem 1rem; display: grid; gap: 0.05rem; box-shadow: var(--shadow); min-width: 0; }
.tile small { color: var(--muted); font-size: 0.82rem; font-weight: 600; }
.tile strong { font-family: var(--font-display); font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.25; }
.tile em { font-style: normal; font-size: 0.78rem; color: var(--success); font-weight: 700; min-height: 1.2em; }
.tile.accent { background: linear-gradient(135deg, #00a884, #008069); color: #fff; border-color: transparent; }
.tile.accent small { color: inherit; opacity: 0.85; }

.attention { border-color: color-mix(in srgb, var(--warning) 45%, var(--line)); background: color-mix(in srgb, var(--warning-soft) 60%, var(--surface)); grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; }
.attention .icon { font-size: 1.6rem; line-height: 1; }

.chart { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0.5rem; height: 170px; align-items: end; }
.bar-col { display: grid; grid-template-rows: 1fr auto; height: 100%; gap: 0.35rem; text-align: center; min-width: 0; }
.bars { display: flex; gap: 3px; align-items: end; justify-content: center; height: 100%; }
.bars i { width: min(16px, 42%); border-radius: 5px 5px 2px 2px; min-height: 3px; display: block; transition: height 0.3s; }
.bars i.in, .legend i.in { background: color-mix(in srgb, var(--slate) 30%, transparent); }
.bars i.auto, .legend i.auto { background: var(--primary); }
.bar-col small { font-size: 0.72rem; color: var(--muted); font-weight: 600; }
.legend { display: flex; gap: 0.35rem; align-items: center; font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-inline-start: 0.5rem; }

.notify-card { grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; }
.notify-icon { width: 46px; height: 46px; border-radius: 14px; background: var(--primary-soft); color: var(--primary-ink); display: grid; place-items: center; }
.notify-icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linejoin: round; stroke-linecap: round; }

/* ---------- chats ---------- */
.chats-view.active { display: grid; grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); gap: 1rem; height: calc(100vh - 3.2rem); }
.chat-list-pane { display: flex; flex-direction: column; min-height: 0; gap: 0.6rem; }
.chat-list-pane .page-head { margin-bottom: 0.2rem; }
.list-tools { display: grid; gap: 0.6rem; }
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; top: 50%; right: 0.95rem; transform: translateY(-50%); width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.search { padding-right: 2.6rem; border-radius: 999px; background: var(--surface-2); border-color: transparent; min-height: 40px; }
.search:focus { background: var(--surface-2); border-color: transparent; box-shadow: none; }
/* filters as WhatsApp's chips: All, Unread, Important… */
.segmented { display: flex; gap: 0.45rem; overflow-x: auto; scrollbar-width: none; margin-inline: -2px; padding: 2px; }
.segmented::-webkit-scrollbar { display: none; }
.segmented button { flex: none; font: inherit; font-size: 0.88rem; font-weight: 500; border: 0; background: var(--surface-2); color: var(--muted); border-radius: 999px; min-height: 34px; padding: 0 0.95rem; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem; }
.segmented button.on { background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; }
.segmented b { background: var(--unread); color: var(--on-unread); border-radius: 99px; font-size: 0.7rem; min-width: 18px; height: 18px; display: inline-grid; place-items: center; padding: 0 5px; }
.segmented b:empty { display: none; }
.chat-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; background: var(--surface); overscroll-behavior: contain; }
.chat-list li { display: flex; gap: 0.8rem; padding: 0.55rem 0.9rem; cursor: pointer; align-items: center; min-height: 72px; position: relative; transition: background 0.12s; }
.chat-list li[data-jid]::after { content: ''; position: absolute; bottom: 0; inset-inline: calc(0.9rem + 49px + 0.8rem) 0; height: 1px; background: var(--line); }
.chat-list li:hover { background: var(--surface-2); }
.chat-list li.active { background: var(--surface-2); }
.chat-list li.pressed { background: var(--line); }
.avatar { --h: 218; width: 49px; height: 49px; border-radius: 50%; background: hsl(var(--h) 45% 88%); color: hsl(var(--h) 40% 30%); display: grid; place-items: center; font-weight: 600; flex: none; font-size: 1.15rem; }
@media (prefers-color-scheme: dark) { .avatar { background: hsl(var(--h) 20% 26%); color: hsl(var(--h) 45% 84%); } }
.chat-meta { flex: 1; min-width: 0; display: grid; gap: 0.1rem; }
.chat-meta .top { display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; }
.chat-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 1.05rem; line-height: 1.35; }
.chat-meta time { font-size: 0.78rem; color: var(--muted); flex: none; }
.chat-list li.unread .chat-meta time { color: var(--unread); font-weight: 600; }
.chat-meta .bottom { display: flex; align-items: center; gap: 0.35rem; min-width: 0; }
.chat-meta p { margin: 0; color: var(--muted); font-size: 0.92rem; white-space: nowrap; display: flex; gap: 0.35rem; align-items: center; min-width: 0; flex: 1; line-height: 1.4; }
.chat-meta p span { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.row-ico { display: inline-grid; color: var(--muted); flex: none; }
.row-ico svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.row-ico.star svg { fill: currentColor; stroke-width: 1.2; }
.chat-list li.unread .chat-meta p { color: var(--ink-2); }
.chat-list .badge { margin: 0; background: var(--unread); color: var(--on-unread); min-width: 21px; height: 21px; font-size: 0.75rem; }
.chat-list .empty { justify-content: center; color: var(--muted); cursor: default; padding: 2.5rem 1rem; text-align: center; min-height: 0; }
.chat-list .empty:hover { background: none; }
.chat-list li.more { justify-content: center; cursor: default; min-height: 0; padding: 0.5rem; }
.chat-list li.more:hover { background: none; }
.sync-note { margin: 0; display: flex; align-items: center; gap: 0.55rem; font-size: 0.84rem; font-weight: 700; color: var(--primary-ink); background: var(--primary-soft); border-radius: 12px; padding: 0.5rem 0.8rem; }
.sync-note::before { content: ''; width: 12px; height: 12px; flex: none; border-radius: 50%; border: 2px solid currentColor; border-inline-end-color: transparent; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.older-bar { align-self: center; font-size: 0.78rem; font-weight: 700; color: var(--muted); margin: 0 0 0.5rem; }
button.older-bar { font: inherit; font-size: 0.8rem; font-weight: 700; color: var(--primary-ink); background: var(--surface); border: 1px dashed var(--line); border-radius: 999px; padding: 0.25rem 0.95rem; min-height: 34px; cursor: pointer; }
button.older-bar:disabled { color: var(--muted); cursor: default; }
.pill { font-size: 0.7rem; font-weight: 800; border-radius: 999px; padding: 0 0.5rem; line-height: 1.7; white-space: nowrap; flex: none; }
.pill.human { background: var(--warning-soft); color: var(--warning); }

.chat-pane { background: var(--chat-bg); display: flex; flex-direction: column; min-height: 0; overflow: hidden; position: relative; }
.empty-chat { flex: 1; display: grid; place-content: center; justify-items: center; gap: 0.5rem; background: var(--surface-2); border-bottom: 6px solid var(--primary); }
.empty-chat svg { width: 46px; height: 46px; fill: none; stroke: var(--muted); stroke-width: 1.4; opacity: 0.6; }
.chat-head { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0.9rem; border-bottom: 1px solid var(--line); background: var(--header); min-height: 60px; z-index: 2; }
.chat-head .grow { flex: 1; min-width: 0; }
.chat-head .name-row { display: flex; align-items: center; gap: 0.3rem; min-width: 0; }
.chat-head strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 1.05rem; line-height: 1.35; }
.chat-head .star-mark { display: inline-grid; color: var(--muted); flex: none; }
.chat-head .star-mark svg { width: 15px; height: 15px; fill: currentColor; stroke: currentColor; stroke-width: 1.2; stroke-linejoin: round; }
.chat-head small { display: block; color: var(--muted); direction: ltr; text-align: right; font-size: 0.8rem; line-height: 1.35; }
.chat-head small.no-phone { direction: rtl; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .head-phone { display: block; width: fit-content; margin-inline-start: 0; color: var(--muted); direction: ltr; font-size: 0.8rem; line-height: 1.35; text-decoration: none; }
.chat-head .head-phone:hover { color: var(--primary-ink); text-decoration: underline; }
.chat-head .icon-btn { color: var(--ink-2); width: 42px; height: 42px; }
.chat-head .icon-btn svg { width: 22px; height: 22px; }
.chat-head #chatMenuBtn svg { fill: currentColor; stroke: none; }
.back { display: none; }
.messages-wrap { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.messages { flex: 1; overflow: auto; padding: 0.75rem clamp(0.9rem, 5vw, 4rem) 0.6rem; display: flex; flex-direction: column; gap: 2px; background: var(--chat-bg); overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.to-bottom { position: absolute; bottom: 12px; inset-inline-end: 12px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--header); color: var(--muted); box-shadow: 0 1px 3px rgba(11, 20, 26, 0.3); display: grid; place-items: center; cursor: pointer; z-index: 3; padding: 0; }
.to-bottom svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.to-bottom .badge { position: absolute; top: -7px; inset-inline-start: -5px; margin: 0; }
/* bubbles: incoming on the start side (right), ours on the end side (left), the first of a run with a tail */
.msg { position: relative; max-width: min(75%, 560px); padding: 0.35rem 0.6rem 0.4rem; border-radius: 8px; background: var(--bubble-in); align-self: flex-start; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: var(--shadow-sm); font-size: 0.97rem; line-height: 1.45; }
.msg.me { align-self: flex-end; background: var(--bubble-out); }
.msg.first { margin-top: 0.45rem; }
.msg.first::before { content: ''; position: absolute; top: 0; width: 8px; height: 13px; background: inherit; }
.msg.first:not(.me) { border-start-start-radius: 0; }
.msg.first:not(.me)::before { inset-inline-start: -8px; clip-path: polygon(0 0, 100% 0, 0 100%); }
.msg.first.me { border-start-end-radius: 0; }
.msg.first.me::before { inset-inline-end: -8px; clip-path: polygon(0 0, 100% 0, 100% 100%); }
/* time (and ticks) in the bubble's bottom corner; .msg-space is an invisible copy that keeps the room for it */
.msg footer, .msg .msg-space { font-size: 0.69rem; display: inline-flex; gap: 0.3rem; align-items: center; white-space: nowrap; line-height: 1; }
.msg footer { position: absolute; bottom: 0.38rem; inset-inline-end: 0.55rem; color: var(--muted); }
.msg.me footer { color: color-mix(in srgb, var(--ink) 55%, transparent); }
.msg .msg-space { visibility: hidden; padding-inline-start: 0.7rem; vertical-align: -0.1em; }
.msg .tag { background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--primary-ink); border-radius: 4px; padding: 0.15em 0.4em; font-weight: 600; }
.msg.pending { opacity: 0.65; }
.msg.failed { outline: 1.5px solid var(--danger); cursor: pointer; }
.msg.failed footer { color: var(--danger); }
.msg a { color: var(--link); overflow-wrap: anywhere; }
/* a phone number in a message: looks like a link, opens the message / call / copy sheet */
.msg .phone-link { font: inherit; color: var(--link); background: none; border: 0; padding: 0; margin: 0; cursor: pointer; text-decoration: none; unicode-bidi: isolate; white-space: nowrap; }
.msg .phone-link:hover { text-decoration: underline; }
.dialog-actions.stack { flex-direction: column; align-items: stretch; }
.msg .card-ask { display: block; margin: 0.4rem 0 0.1rem; font: inherit; font-size: 0.85rem; font-weight: 600; color: var(--link); background: none; border: 0; border-top: 1px solid var(--line); border-radius: 0; padding: 0.45rem 0.2rem 0.1rem; width: 100%; min-height: 34px; cursor: pointer; }
.msg .card-ask:disabled { color: var(--muted); cursor: default; }
.msg .tick { display: inline-grid; }
.msg .tick svg { height: 11px; width: auto; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.msg .tick.read { color: var(--tick-read); }
.msg .deleted { font-style: italic; color: var(--muted); }
.msg .edited { font-style: italic; }
/* attachments: the time goes on its own line under the photo, video or file */
.msg.has-media { padding: 0.2rem 0.2rem 0.3rem; width: min(300px, 75%); }
.msg.has-media footer { position: static; display: flex; justify-content: flex-end; padding: 0.3rem 0.4rem 0; }
.msg .caption { padding: 0.35rem 0.5rem 0; }
.media { display: block; border-radius: 12px; overflow: hidden; background: var(--surface-2); max-width: 100%; }
.media.image, .media.sticker { cursor: zoom-in; }
.media img, .media video { display: block; width: 100%; height: 100%; max-height: 380px; object-fit: cover; }
.media.image { min-height: 120px; max-height: 380px; }
.media.sticker { width: 150px; background: none; min-height: 0; }
.media.sticker img { object-fit: contain; }
.media.video { background: #000; max-height: 380px; }
.media.video video { object-fit: contain; }
.media.audio { background: none; border-radius: 999px; }
.media.audio audio { display: block; width: 100%; min-width: 210px; height: 44px; }
.media.doc { display: flex; align-items: center; gap: 0.65rem; padding: 0.6rem 0.7rem; color: inherit; text-decoration: none; background: color-mix(in srgb, var(--ink) 5%, transparent); }
.media.doc .doc-ext { flex: none; width: 40px; height: 46px; border-radius: 8px; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 0.66rem; font-weight: 800; letter-spacing: 0.02em; direction: ltr; }
.media.doc .doc-info { display: grid; min-width: 0; line-height: 1.4; }
.media.doc b { font-weight: 700; font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media.doc small { color: var(--muted); font-size: 0.74rem; }
.media.doc svg { flex: none; width: 20px; height: 20px; margin-inline-start: auto; fill: none; stroke: var(--primary-ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.media.broken { display: grid; place-items: center; min-height: 90px; color: var(--muted); font-size: 0.8rem; font-weight: 700; cursor: default; }
.media.broken::after { content: 'الملف غير متوفر'; }
.media.broken img, .media.broken video { display: none; }
.upload-bar { height: 4px; background: color-mix(in srgb, var(--primary) 20%, transparent); border-radius: 99px; margin: 0.35rem 0.45rem 0; overflow: hidden; }
.upload-bar span { display: block; height: 100%; background: var(--primary); width: 0; transition: width 0.2s; }
.chat-pane.drop::after { content: 'أفلت الملفات هنا للإرسال'; position: absolute; inset: 0.6rem; border: 2px dashed var(--primary); border-radius: var(--radius); background: color-mix(in srgb, var(--surface) 85%, transparent); display: grid; place-items: center; font-weight: 800; color: var(--primary-ink); z-index: 5; pointer-events: none; }
/* full-screen photo viewer */
.lightbox { --fade: 1; position: fixed; inset: 0; z-index: 70; background: rgba(4, 8, 16, calc(0.94 * var(--fade))); display: grid; grid-template-rows: auto minmax(0, 1fr); padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); overflow: hidden; animation: fade 0.15s ease; }
.lightbox .bar { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0.75rem; position: relative; z-index: 1; }
.lightbox .bar a, .lightbox .bar button { color: #fff; }
.lightbox img { max-width: 100%; max-height: 100%; margin: auto; object-fit: contain; touch-action: none; will-change: transform; }
/* "new version" offer */
.update-bar { position: fixed; z-index: 65; top: 14px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 0.75rem; background: var(--ink); color: var(--bg); border-radius: 999px; padding: 0.35rem 0.4rem 0.35rem 0.35rem; padding-inline-start: 1rem; font-size: 0.9rem; font-weight: 700; box-shadow: var(--shadow-lg); white-space: nowrap; max-width: calc(100vw - 24px); animation: fade 0.2s ease; }
/* pull-to-refresh spinner (installed app) */
.ptr { position: fixed; z-index: 19; top: calc(var(--top-h) + env(safe-area-inset-top) - 40px); left: 50%; margin-left: -19px; width: 38px; height: 38px; border-radius: 50%; background: var(--surface); color: var(--muted); box-shadow: 0 4px 14px rgba(16, 22, 31, 0.18); display: grid; place-items: center; opacity: 0; pointer-events: none; }
.ptr svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.ptr.ready { color: var(--primary); }
.ptr.spin svg { animation: spin 0.7s linear infinite; }
/* send-files sheet */
.file-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; max-height: 40vh; overflow: auto; }
.file-list li { display: flex; align-items: center; gap: 0.7rem; padding: 0.45rem; border: 1px solid var(--line); border-radius: 14px; }
.file-list .thumb { flex: none; width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: var(--surface-2); display: grid; place-items: center; font-size: 0.68rem; font-weight: 800; color: var(--primary-ink); direction: ltr; }
.file-list .info { display: grid; min-width: 0; flex: 1; line-height: 1.4; }
.file-list .info b { font-weight: 700; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-list .info small { color: var(--muted); font-size: 0.78rem; }
.file-list .info small.bad { color: var(--danger); font-weight: 700; }
/* message search results inside the chat list */
.chat-list li.section { min-height: 0; padding: 0.7rem 0.7rem 0.25rem; font-size: 0.78rem; font-weight: 800; color: var(--muted); cursor: default; }
.chat-list li.section:hover { background: none; }
.chat-list li.hit .chat-meta p span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list mark { background: var(--warning-soft); color: inherit; border-radius: 4px; padding: 0 2px; }
.day-sep { align-self: center; font-size: 0.78rem; font-weight: 500; color: var(--muted); background: var(--header); border-radius: 8px; padding: 0.3rem 0.75rem; margin: 0.7rem 0 0.3rem; box-shadow: var(--shadow-sm); line-height: 1.3; }
/* notices over the chat (customer wants a person, auto-replies off…), in WhatsApp's notice colours */
.chat-notes { display: grid; gap: 0.3rem; padding: 0.45rem 0.7rem 0; background: var(--chat-bg); }
.chat-notes:empty { display: none; }
.note { font-size: 0.84rem; font-weight: 500; border-radius: 8px; padding: 0.3rem 0.75rem; display: flex; gap: 0.5rem; align-items: center; justify-content: space-between; color: var(--on-notice); background: var(--notice); box-shadow: var(--shadow-sm); line-height: 1.4; }
.note svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.note span { flex: 1; }
.note button { font: inherit; font-size: 0.84rem; font-weight: 700; border: 0; background: none; color: var(--primary-ink); cursor: pointer; padding: 0.3rem 0.2rem; min-height: 32px; white-space: nowrap; }
/* WhatsApp's input: a rounded field over the chat background, with the green round send button beside it */
.composer { display: flex; gap: 0.4rem; padding: 0.4rem 0.5rem 0.5rem; align-items: flex-end; position: relative; background: var(--chat-bg); }
.composer-box { flex: 1; min-width: 0; display: flex; align-items: flex-end; background: var(--field); border-radius: 24px; box-shadow: var(--shadow-sm); padding: 0 0.15rem; }
.composer textarea { min-height: 46px; max-height: 160px; resize: none; overflow-y: auto; scrollbar-width: none; border-radius: 0; padding: 0.68rem 0.2rem; line-height: 1.45; background: none; border: 0; box-shadow: none; }
.composer textarea:focus, .composer textarea:focus-visible { background: none; box-shadow: none; outline: none; }
.composer textarea::-webkit-scrollbar { display: none; }
.send-btn { width: 48px; height: 48px; min-height: 48px; padding: 0; border-radius: 50%; flex: none; }
.send-btn svg { width: 21px; height: 21px; }
.composer .icon-btn { width: 42px; height: 46px; color: var(--muted); }
.slash { position: absolute; bottom: calc(100% + 6px); inset-inline: 0.55rem; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg); list-style: none; margin: 0; padding: 0.35rem; max-height: 260px; overflow: auto; z-index: 5; }
.slash li { padding: 0.55rem 0.7rem; border-radius: 10px; cursor: pointer; display: grid; gap: 0.05rem; }
.slash li b { font-weight: 700; }
.slash li small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slash li.sel, .slash li:hover { background: var(--primary-soft); }
.sim { display: grid; gap: 0.4rem; border: 1px dashed var(--line); border-radius: var(--radius); padding: 0.7rem; }
.sim .row input { min-width: 0; }

/* ---------- rules & templates ---------- */
.first-msg { border-color: color-mix(in srgb, var(--primary) 35%, var(--line)); }
.first-msg.off .first-msg-body { opacity: 0.55; }
.first-msg-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 360px); gap: 1rem; align-items: start; }
.edit-welcome, .cancel-welcome { display: none; }
.wa-preview { background: var(--chat-bg); border-radius: 14px; padding: 0.8rem; display: grid; gap: 0.4rem; }
.wa-preview small { color: var(--muted); font-weight: 600; font-size: 0.76rem; }
.wa-bubble { background: var(--bubble-out); border-radius: 14px; border-start-end-radius: 5px; padding: 0.6rem 0.85rem; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.92rem; line-height: 1.7; justify-self: end; max-width: 100%; box-shadow: 0 1px 1px rgba(16, 22, 31, 0.06); }
.tester .row input { flex: 1; min-width: 0; }
.test-out { background: var(--surface-2); border-radius: 12px; padding: 0.75rem 0.9rem; white-space: pre-wrap; font-size: 0.92rem; overflow-wrap: anywhere; }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(310px, 100%), 1fr)); gap: 0.85rem; }
.rule { margin: 0; align-content: start; }
.rule.off { opacity: 0.6; }
.chips { display: flex; flex-wrap: wrap; gap: 0.3rem; min-width: 0; }
.chip { background: var(--primary-soft); color: var(--primary-ink); border-radius: 99px; padding: 0.1rem 0.7rem; font-size: 0.82rem; font-weight: 700; overflow-wrap: anywhere; }
button.chip { border: 0; font: inherit; font-size: 0.84rem; font-weight: 700; cursor: pointer; min-height: 36px; }
.rule .reply { white-space: pre-wrap; background: var(--surface-2); border-radius: 12px; padding: 0.6rem 0.8rem; font-size: 0.88rem; max-height: 8.8em; overflow: hidden; overflow-wrap: anywhere; }
.rule .meta { display: flex; gap: 0.4rem; flex-wrap: wrap; font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.rule footer { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; font-size: 0.8rem; color: var(--muted); flex-wrap: wrap; }
.tpl h3 { display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; }
.tpl .used { font-size: 0.76rem; color: var(--primary-ink); font-weight: 700; white-space: nowrap; }

/* ---------- settings ---------- */
.days { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.days label { display: inline-flex; position: relative; }
.days input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.days span { border: 1px solid var(--line); border-radius: 99px; padding: 0 0.9rem; min-height: 38px; display: inline-flex; align-items: center; cursor: pointer; font-size: 0.86rem; font-weight: 700; color: var(--ink-2); }
.days input:checked + span { background: var(--primary); color: #fff; border-color: transparent; }
.days input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
label.line { display: flex; justify-content: space-between; align-items: center; gap: 1rem; font-weight: 600; min-height: 44px; }
label.line small { font-weight: 500; }
.save-bar { position: sticky; bottom: 1rem; margin-bottom: 1rem; z-index: 2; }
.account { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
.history-hint { margin: 0.75rem 0 0; font-size: 0.86rem; font-weight: 600; color: var(--primary-ink); background: var(--primary-soft); border-radius: 12px; padding: 0.6rem 0.8rem; }
.pw-change { grid-column: 1 / -1; border-top: 1px solid var(--line-2); padding-top: 0.6rem; }
.pw-change summary { cursor: pointer; font-weight: 700; color: var(--primary-ink); min-height: 40px; display: flex; align-items: center; list-style: none; }
.pw-change summary::-webkit-details-marker { display: none; }
.pw-change summary::after { content: '⌄'; margin-inline-start: 0.4rem; transition: transform 0.2s; }
.pw-change[open] summary::after { transform: rotate(180deg); }
.pw-change form { display: grid; gap: 0.75rem; margin-top: 0.5rem; max-width: 420px; }
.pw-change form .btn { justify-self: start; }

/* ---------- marketing ---------- */
.leads-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.6rem; }
.leads-stats div { background: var(--surface-2); border-radius: 12px; padding: 0.55rem 0.75rem; display: grid; gap: 0.05rem; min-width: 0; }
.leads-stats small { color: var(--muted); font-weight: 600; font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leads-stats strong { font-size: 1.4rem; font-family: var(--font-display); font-weight: 800; line-height: 1.25; }
.leads-stats strong span { font-size: 0.9rem; color: var(--muted); font-weight: 700; }
.leads-card .btn[data-act='fetch'] { justify-self: start; }
.leads-msg { display: grid; gap: 0.6rem; }
.leads-msg-head { display: flex; justify-content: space-between; align-items: center; gap: 0.4rem 0.75rem; flex-wrap: wrap; }
.leads-approve { display: grid; gap: 0.6rem; border-color: var(--primary); }
.approve-list { list-style: none; margin: 0; padding: 0; display: grid; max-height: 55vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 12px; }
.approve-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem; border-top: 1px solid var(--line-2); }
.approve-list li:first-child { border-top: 0; }
.approve-list li div { display: grid; min-width: 0; }
.approve-list strong, .approve-list small { overflow-wrap: anywhere; }
.approve-list small { color: var(--muted); font-size: 0.78rem; }
.approve-list a { font-size: 0.8rem; font-weight: 600; text-decoration: none; white-space: nowrap; }
.approve-actions .btn.primary { flex: 1; }
.leads-msg-head .row { flex-wrap: wrap; }
.leads-msg .wa-preview { padding: 0.75rem; }
.leads-cover { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.6rem; }
.leads-cover .hint { flex-basis: 100%; margin: 0; }
.wa-bubble.has-media { display: grid; gap: 0.45rem; padding: 0.3rem 0.3rem 0.6rem; width: min(100%, 300px); }
.wa-bubble.has-media > div { padding-inline: 0.55rem; }
.wa-bubble.has-media img { width: 100%; max-height: 300px; object-fit: cover; border-radius: 10px; display: block; }
.wa-bubble.has-media video, .leads-preview video { width: 100%; max-height: 380px; border-radius: 10px; display: block; background: #000; }
.leads-preview video { max-width: 260px; justify-self: end; }
.wa-bubble.has-media .file-chip { justify-self: stretch; }
.queue-line { margin: 0; font-size: 0.86rem; font-weight: 700; color: var(--primary-ink); background: var(--primary-soft); border-radius: 12px; padding: 0.5rem 0.8rem; }
.queue-line.hold { color: var(--warning); background: var(--warning-soft); }
.leads-setup { display: grid; gap: 0.6rem; justify-items: start; }
.checklist { margin: 0; padding: 0; list-style: none; display: grid; gap: 0.25rem; font-weight: 600; font-size: 0.92rem; }
.checklist li::before { content: '○'; display: inline-block; width: 1.3em; color: var(--muted); }
.checklist li.done { color: var(--muted); text-decoration: line-through; }
.checklist li.done::before { content: '✓'; color: var(--success); }
.leads-filter { margin-bottom: 0.6rem; }
.grid3 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.45fr); gap: 0.5rem; }
.grid3 input { min-width: 0; padding-inline: 0.65rem; }
.leads-sort { display: grid; gap: 0.5rem; margin-bottom: 0.75rem; }
.leads-sort select { min-height: 42px; padding-block: 0.4rem; min-width: 0; text-overflow: ellipsis; }
.cat-chips { display: flex; gap: 0.35rem; overflow-x: auto; scrollbar-width: none; margin-inline: -2px; padding: 2px; }
.cat-chips::-webkit-scrollbar { display: none; }
.cat-chip { flex: none; font: inherit; font-size: 0.84rem; font-weight: 700; color: var(--ink-2); background: var(--surface); border: 1px solid var(--line); border-radius: 99px; min-height: 36px; padding: 0 0.85rem; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 0.3rem; }
.cat-chip small { font-size: 0.74rem; color: var(--muted); font-weight: 600; }
.cat-chip.on { background: var(--primary); border-color: transparent; color: var(--on-primary); }
.cat-chip.on small { color: inherit; opacity: 0.8; }
.lead-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.15rem !important; }
.lead-tags span { font-size: 0.74rem; font-weight: 700; color: var(--ink-2); background: var(--surface-2); border-radius: 99px; padding: 0.05rem 0.55rem; }
.leads-filter small { font-size: 0.78rem; font-weight: 600; color: var(--muted); }
.leads-filter small:empty { display: none; }
.leads-bulk { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem 1rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.leads-bulk:empty { display: none; }
.leads-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.6rem; }
.leads-list .empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.lead { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 0.75rem 0.9rem; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.5rem 0.8rem; align-items: center; box-shadow: var(--shadow-sm); }
.lead-info { display: grid; gap: 0.15rem; min-width: 0; }
.lead-top { display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; }
.lead-top strong { overflow-wrap: anywhere; }
.lead p { margin: 0; font-size: 0.84rem; overflow-wrap: anywhere; }
.lead-meta { display: flex; flex-wrap: wrap; gap: 0.1rem 0.9rem; color: var(--ink-2); font-weight: 600; }
.lead-meta a { text-decoration: none; }
.lead-actions { display: flex; gap: 0.4rem; }
.pill.ok { background: var(--success-soft); color: var(--success); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.wait { background: var(--primary-soft); color: var(--primary-ink); }
.leads-buttons .btn { flex: 1 1 auto; }
.leads-list .more { display: flex; justify-content: center; }
.pill.hot { background: var(--warning-soft); color: var(--warning); }
.pill.soft { background: var(--surface-2); color: var(--ink-2); }
.lead .tick { letter-spacing: -0.2em; padding-inline-start: 0.15em; }
.lead .tick.read { color: #1d9bf0; }
.outcome { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 999px; padding: 2px; gap: 2px; }
.outcome button { font: inherit; font-size: 0.8rem; font-weight: 700; border: 0; background: none; color: var(--muted); border-radius: 999px; min-height: 32px; padding: 0 0.7rem; cursor: pointer; white-space: nowrap; }
.outcome button.on.won { background: var(--success-soft); color: var(--success); }
.outcome button.on.lost { background: var(--surface); color: var(--ink-2); box-shadow: var(--shadow-sm); }
/* results */
.results { gap: 0.6rem; }
.results summary { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; cursor: pointer; list-style: none; min-height: 32px; flex-wrap: wrap; }
.results summary::-webkit-details-marker { display: none; }
.results summary h3::after { content: ' ⌄'; color: var(--muted); }
.results[open] summary h3::after { content: ' ⌃'; }
.results summary .muted { font-size: 0.86rem; font-weight: 700; }
.results-body { display: grid; gap: 0.6rem; }
.results-body h4 { margin: 0.4rem 0 0; font-size: 0.92rem; }
.funnel { display: grid; gap: 0.35rem; }
.fun-row { display: grid; grid-template-columns: 6.6rem minmax(0, 1fr) 2.6rem 2.6rem; align-items: center; gap: 0.5rem; font-size: 0.86rem; }
.fun-row span { font-weight: 600; color: var(--ink-2); }
.fun-row i { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.fun-row i b { display: block; height: 100%; border-radius: inherit; background: var(--primary); min-width: 2px; }
.fun-row.bad i b { background: var(--danger); }
.fun-row strong { text-align: end; }
.fun-row small { color: var(--muted); text-align: end; }
.table-wrap { overflow-x: auto; margin-inline: -0.2rem; }
table.mini { width: 100%; border-collapse: collapse; font-size: 0.84rem; white-space: nowrap; }
table.mini th { text-align: start; color: var(--muted); font-weight: 600; font-size: 0.78rem; padding: 0.3rem 0.4rem; border-bottom: 1px solid var(--line); }
table.mini td { padding: 0.4rem; border-bottom: 1px solid var(--line-2); }
table.mini td:first-child { font-weight: 700; white-space: normal; }
/* campaign settings */
.form-sec { margin: 0.6rem 0 -0.2rem; padding-top: 0.8rem; border-top: 1px solid var(--line-2); font-size: 0.98rem; color: var(--primary-ink); }
.dialog-head + .form-sec { border-top: 0; padding-top: 0; margin-top: 0; }
.pick-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.variants { display: grid; gap: 0.7rem; }
.variant { display: grid; gap: 0.35rem; }
.variant b { font-size: 0.92rem; }
.add-variant { justify-self: start; }
.leads-preview img { max-width: 220px; max-height: 220px; border-radius: 12px; justify-self: end; object-fit: cover; }
.campaign-media-preview { display: grid; }
.campaign-media-preview:empty { display: none; }
.file-chip { justify-self: end; background: var(--surface); border-radius: 10px; padding: 0.4rem 0.7rem; font-size: 0.86rem; font-weight: 600; }
.campaign-media { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; }
.campaign-media .hint, .campaign-media .error { flex-basis: 100%; }
.test-row input { flex: 1; min-width: 0; }
.key-field { border: 1px solid var(--line); border-radius: 14px; padding: 0.7rem 0.9rem 0.9rem; display: grid; gap: 0.5rem; }
.key-field legend { padding: 0 0.3rem; margin: 0; }
.src-apify, .src-google { display: grid; gap: 0.5rem; }
.key-help summary { cursor: pointer; font-weight: 700; color: var(--primary-ink); font-size: 0.88rem; min-height: 36px; display: flex; align-items: center; }
.key-help ol { margin: 0.2rem 0 0.5rem; padding-inline-start: 1.2rem; font-size: 0.86rem; display: grid; gap: 0.25rem; }

/* ---------- dialogs ---------- */
dialog { border: 0; border-radius: 22px; padding: 0; width: min(540px, calc(100vw - 32px)); max-height: min(88vh, 860px); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); overflow: auto; overscroll-behavior: contain; }
dialog::backdrop { background: rgba(6, 11, 23, 0.5); }
dialog form, dialog .picker { padding: 1.1rem 1.3rem 1.3rem; display: grid; gap: 0.85rem; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-inline-end: -0.6rem; }
.dialog-head h3 { font-size: 1.15rem; font-family: var(--font-display); font-weight: 800; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; padding-top: 0.2rem; }
dialog .line.check { background: var(--surface-2); border-radius: 12px; padding: 0.5rem 0.8rem; }
/* one chat's menu */
.chat-menu { gap: 0.3rem !important; }
.chat-menu .dialog-head h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.menu-item { display: flex; align-items: center; gap: 0.9rem; width: 100%; min-height: 52px; padding: 0 0.4rem; font: inherit; font-size: 1rem; color: var(--ink); background: none; border: 0; border-radius: 10px; cursor: pointer; text-decoration: none; text-align: start; }
.menu-item:hover { background: var(--surface-2); }
.menu-item svg { width: 22px; height: 22px; flex: none; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.menu-item.on svg { fill: #f5b301; stroke: #f5b301; }
.menu-sec { margin: 0.6rem 0.4rem 0.1rem; font-size: 0.85rem; font-weight: 600; color: var(--primary-ink); }
.bot-modes { display: grid; gap: 0.15rem; }
.bot-modes button { display: grid; grid-template-columns: 22px minmax(0, 1fr); column-gap: 0.9rem; align-items: center; text-align: start; width: 100%; padding: 0.55rem 0.4rem; font: inherit; color: var(--ink); background: none; border: 0; border-radius: 10px; cursor: pointer; }
.bot-modes button:hover { background: var(--surface-2); }
/* radio dot */
.bot-modes button::before { content: ''; grid-row: 1 / span 2; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--muted); box-sizing: border-box; }
.bot-modes button[aria-checked='true']::before { border-color: var(--primary); background: radial-gradient(circle, var(--primary) 0 4.5px, transparent 5px); }
.bot-modes b { font-weight: 500; font-size: 1rem; }
.bot-modes small { color: var(--muted); font-size: 0.84rem; line-height: 1.4; }
.picker-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.picker-list li { border: 1px solid var(--line); border-radius: 14px; padding: 0.7rem 0.85rem; }
.picker-list li p { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.86rem; white-space: pre-wrap; max-height: 5.1em; overflow: hidden; }
.picker-list .acts { display: flex; gap: 0.4rem; margin-top: 0.55rem; flex-wrap: wrap; }
.picker-list .acts .btn { flex: 1; }

.toast { position: fixed; bottom: 1.4rem; left: 50%; transform: translate(-50%, 16px); opacity: 0; visibility: hidden; pointer-events: none; background: var(--ink); color: var(--bg); padding: 0.65rem 1.15rem; border-radius: 999px; transition: transform 0.25s, opacity 0.25s, visibility 0.25s; z-index: 60; max-width: calc(100vw - 32px); font-size: 0.9rem; font-weight: 600; box-shadow: var(--shadow-lg); text-align: center; }
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- small laptops & landscape tablets: icon rail ---------- */
@media (min-width: 861px) and (max-width: 1180px) {
  .app { grid-template-columns: 80px minmax(0, 1fr); }
  .sidebar { padding: 1rem 0.6rem; align-items: center; }
  .sidebar-head { justify-items: center; padding: 0; }
  .sidebar-head .word, .sidebar-head .tag, .status-chip#sideStatus span { display: none; }
  .status-chip#sideStatus { padding: 0.35rem; }
  .nav a { justify-content: center; padding: 0.6rem; width: 56px; }
  .nav a span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .nav a .badge { position: absolute; top: 4px; left: 4px; height: 18px; min-width: 18px; font-size: 0.66rem; }
  .side-link { font-size: 0; padding: 0.7rem; justify-content: center; }
  .side-link svg { width: 18px; height: 18px; }
  .chats-view.active { grid-template-columns: minmax(260px, 300px) minmax(0, 1fr); }
}

/* ---------- wide screens ---------- */
@media (min-width: 1400px) {
  .chats-view.active { grid-template-columns: 400px minmax(0, 1fr); }
}

/* ---------- computers: the chats page fills the window like WhatsApp Web (list beside the open chat) ---------- */
@media (min-width: 861px) {
  .main.wide { padding: 0; max-width: none; }
  .chats-view.active { gap: 0; height: 100vh; height: 100dvh; }
  .chat-list-pane { gap: 0; background: var(--surface); border-inline-end: 1px solid var(--line); min-width: 0; }
  .chat-list-pane > .page-head { margin: 0; padding: 0.8rem 1rem 0.4rem; }
  .chat-list-pane > .page-head h2 { font-size: 1.4rem; }
  .list-tools { padding: 0.2rem 0.75rem 0.6rem; }
  .sync-note { margin: 0 0.75rem 0.5rem; }
  .chat-head { background: var(--surface-2); border-bottom: 0; }
  @media (prefers-color-scheme: dark) { .chat-head { background: var(--header); } }
}

/* ---------- tablet & phone ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); align-content: start; }
  .topbar { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; position: sticky; top: 0; z-index: 20; padding: env(safe-area-inset-top) 16px 0; height: calc(var(--top-h) + env(safe-area-inset-top)); background: var(--surface); }
  .topbar .lockup .mark { width: 30px; height: 30px; border-radius: 8px; }
  .topbar .lockup .word { font-size: 1.35rem; font-weight: 700; color: var(--primary-ink); }
  @media (prefers-color-scheme: dark) { .topbar .lockup .word { color: var(--ink); } }
  .sidebar { position: fixed; bottom: 0; top: auto; inset-inline: 0; height: auto; padding: 0.3rem 0.4rem calc(0.3rem + env(safe-area-inset-bottom)); border: 0; border-top: 1px solid var(--line); z-index: 20; display: block; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); }
  .sidebar-head, .side-link { display: none; }
  .nav { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0; }
  .nav a { flex-direction: column; gap: 0.15rem; font-size: 0.7rem; padding: 0.3rem 0.1rem; min-height: 54px; justify-content: center; text-align: center; border-radius: 14px; }
  .nav a:hover { background: none; }
  .nav a svg { width: 24px; height: 24px; padding: 3px 12px; box-sizing: content-box; border-radius: 99px; transition: background 0.15s; }
  .nav a.active { background: none; color: var(--ink); font-weight: 700; }
  .nav a.active svg { background: var(--primary-soft); color: var(--primary-ink); }
  .nav a .badge { position: absolute; top: 0; left: calc(50% - 28px); height: 18px; min-width: 18px; font-size: 0.66rem; box-shadow: 0 0 0 2px var(--surface); }
  .main { padding: 1rem 16px calc(var(--nav-h) + 1.5rem + env(safe-area-inset-bottom)); }
  h2 { font-size: 1.35rem; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
  .tile strong { font-size: 1.65rem; }
  .pair { grid-template-columns: minmax(0, 1fr); }
  .notify-card { grid-template-columns: auto minmax(0, 1fr); }
  .notify-card .row { grid-column: 1 / -1; }
  .notify-card .row .btn { flex: 1; }
  .first-msg-body { grid-template-columns: minmax(0, 1fr); }
  /* the long first message shows as a short preview until "edit" is tapped */
  .first-msg:not(.editing) .first-msg-body textarea, .first-msg:not(.editing) .first-msg-save, .first-msg:not(.editing) .wa-preview small { display: none; }
  .first-msg:not(.editing) .wa-preview { padding: 0.6rem; }
  .first-msg:not(.editing) .wa-bubble { max-height: 9.5em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 60%, transparent); mask-image: linear-gradient(#000 60%, transparent); }
  .first-msg:not(.editing) .edit-welcome { display: inline-flex; justify-self: start; }
  .first-msg.editing .wa-preview { display: none; }
  .first-msg.editing .cancel-welcome { display: inline-flex; }
  .first-msg-save { flex-direction: column; align-items: stretch; }
  .first-msg-save .row .btn { flex: 1; }

  /* ----- chat list: the list gets the screen, search + filters stay reachable ----- */
  .chats-view.active { display: block; height: auto; }
  .chats-view .chat-list-pane { gap: 0; }
  .chats-view .chat-list-pane > .page-head { margin: 0; }
  .chats-view .chat-list-pane > .page-head h2 { display: none; } /* the bottom bar already says where you are */
  .list-tools { position: sticky; top: calc(var(--top-h) + env(safe-area-inset-top)); z-index: 6; margin: -1rem -16px 0; padding: 0.2rem 16px 0.55rem; gap: 0.6rem; background: var(--surface); }
  .btn.fab { position: fixed; z-index: 15; inset-inline-end: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); width: 56px; height: 56px; min-height: 56px; padding: 0; border-radius: 16px; border: 0; background: var(--primary); color: var(--on-primary); box-shadow: 0 3px 8px rgba(11, 20, 26, 0.25); }
  .btn.fab:hover { background: var(--primary-hover); }
  .btn.fab svg { width: 26px; height: 26px; stroke-width: 2.4; }
  .btn.fab span { display: none; }
  .chat-list { overflow: visible; background: none; padding: 0 0 84px; margin-inline: -16px; }
  .chat-list li { padding: 0.5rem 16px; min-height: 74px; }
  .chat-list li[data-jid]::after { inset-inline: calc(16px + 49px + 0.8rem) 0; }
  .chat-list li:hover, .chat-list li.active { background: none; }
  .chat-list li[data-jid]:active { background: var(--surface-2); }
  .chat-list li.pressed { background: var(--line); }
  .chat-list li.section { padding: 0.9rem 16px 0.3rem; }
  .chat-list .empty { padding: 3rem 1.5rem; }
  .sync-note { margin-top: 0.6rem; }
  .sim { margin-top: 1rem; }

  /* ----- open chat: full screen above everything, sized to what's visible above the keyboard ----- */
  html.chat-open, html.chat-open body { overflow: hidden; overscroll-behavior: none; }
  .chats-view .chat-pane { display: none; }
  .chats-view.open .chat-pane { display: flex; position: fixed; inset: var(--vv-top, 0px) 0 auto; height: 100vh; height: var(--vv-h, 100dvh); z-index: 40; border-radius: 0; border: 0; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); box-shadow: none; animation: push 0.22s cubic-bezier(0.2, 0.8, 0.2, 1); }
  html.typing .chats-view.open .chat-pane { padding-bottom: 0; }
  .chat-head { min-height: 58px; padding: 0.3rem 0.2rem; gap: 0.35rem; touch-action: none; }
  .chat-head .avatar { width: 40px; height: 40px; font-size: 1rem; }
  .chat-head .back { width: 36px; margin-inline-end: -0.3rem; }
  .chat-notes { touch-action: none; }
  .composer { padding: 0.35rem 0.4rem 0.45rem; gap: 0.3rem; }
  .composer textarea { max-height: min(160px, calc(var(--vv-h, 100vh) * 0.28)); }
  .composer .icon-btn { width: 40px; }
  .back { display: inline-grid; }
  .msg { max-width: 82%; font-size: 1.03rem; }
  .messages { padding-inline: 0.85rem; }

  .save-bar { bottom: calc(var(--nav-h) + 0.6rem + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(var(--nav-h) + 1rem + env(safe-area-inset-bottom)); }
  html.chat-open .toast { bottom: calc(7.5rem + env(safe-area-inset-bottom)); } /* above the reply box and any notice */
  .update-bar { top: calc(var(--top-h) + env(safe-area-inset-top) + 8px); }
  .attention { grid-template-columns: auto minmax(0, 1fr); }
  .attention .btn { grid-column: 1 / -1; }
  .section-head .btn, .page-head > .btn { min-height: 42px; }
  .lead { grid-template-columns: minmax(0, 1fr); }
  .lead-actions { flex-wrap: wrap; }
  .lead-actions .btn { flex: 1; min-height: 40px; }
  .lead-actions .outcome { flex: 1 1 100%; }
  .lead-actions .outcome button { flex: 1; min-height: 36px; }
  .leads-card .btn[data-act='fetch'], .leads-bulk .row, .leads-bulk .row .btn { justify-self: stretch; flex: 1; }
  .leads-bulk .btn { min-height: 42px; }

  /* keyboard up: give it all the room (no bottom bar, no floating button, no home-bar gap) */
  html.typing .sidebar, html.typing .btn.fab { display: none; }
  html.typing .save-bar { bottom: 0.6rem; }

  /* dialogs become bottom sheets that sit on top of the keyboard */
  dialog { width: 100%; max-width: 100%; max-height: min(92dvh, calc(var(--vv-h, 100dvh) - 12px)); margin: auto 0 var(--kb, 0px); border-radius: 22px 22px 0 0; padding-bottom: 0; }
  dialog::before { content: ''; display: block; width: 40px; height: 5px; border-radius: 99px; background: var(--line); margin: 8px auto 0; }
  dialog[open] { animation: sheet 0.24s cubic-bezier(0.2, 0.8, 0.2, 1); }
  dialog form, dialog .picker { padding-top: 0.5rem; }
  dialog form { padding-bottom: 0; }
  dialog .picker { padding-bottom: calc(1.3rem + env(safe-area-inset-bottom)); }
  .dialog-actions { position: sticky; bottom: 0; z-index: 2; background: var(--surface); margin: 0 -1.3rem; padding: 0.7rem 1.3rem calc(0.9rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--line-2); }
  html.typing .dialog-actions { padding-bottom: 0.7rem; }
  .dialog-actions .btn { flex: 1; }
}
@keyframes sheet { from { transform: translateY(100%); } }
@keyframes push { from { transform: translateX(-28%); opacity: 0.5; } }

@media (max-width: 380px) {
  .composer { gap: 0.25rem; padding-inline: 0.3rem; }
  .composer .icon-btn { width: 36px; }
  .main { padding-inline: 12px; }
  .topbar { padding-inline: 12px; }
  .list-tools { margin-inline: -12px; padding-inline: 12px; }
  .chat-list { margin-inline: -12px; }
  .chat-list li { padding-inline: 12px; }
  .btn.fab { inset-inline-end: 12px; }
  .card { padding: 0.95rem; }
  .tile { padding: 0.75rem 0.8rem; }
  .tile strong { font-size: 1.45rem; }
  .nav a { font-size: 0.64rem; }
  .nav a svg { padding-inline: 8px; }
  .pair img { width: 200px; height: 200px; }
  .segmented button { font-size: 0.84rem; padding: 0 0.8rem; }
  .chat-list li[data-jid]::after { inset-inline-start: calc(12px + 49px + 0.8rem); }
}
@media (max-width: 340px) {
  .switch.labeled em { display: none; }
  .switch.labeled { padding: 0.35rem; }
}

/* phones in landscape: keep the chat usable */
@media (max-width: 960px) and (max-height: 500px) and (orientation: landscape) {
  .chat-head { min-height: 50px; padding-block: 0.25rem; }
  .composer textarea { max-height: 84px; }
  .nav a { min-height: 44px; }
}

/* tablets in portrait: room for all four stats in one row */
@media (min-width: 600px) and (max-width: 860px) {
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
