/* WA Broadcaster — visual system. Layout utilities come from Tailwind; everything that carries
   colour, type or component identity lives here so the look is defined in one place. */

:root {
  --ink-900: #10232b;   /* sidebar */
  --ink-800: #173039;
  --ink-700: #22414c;
  --ink-500: #6b8089;   /* muted sidebar text */
  --ink-300: #a9bcc3;

  --paper: #f5f7f8;     /* page background */
  --surface: #ffffff;
  --surface-2: #eef2f3; /* table head, subtle panels */
  --line: #dde4e6;
  --line-strong: #c3ced2;

  --text: #1b2a30;
  --text-2: #4a5c63;
  --text-3: #7d8d93;

  --primary: #0e7c66;
  --primary-700: #0a6251;
  --primary-100: #dcf1ea;
  --primary-050: #eef8f5;

  --ok: #1f7a4d;      --ok-bg: #e3f3ea;
  --warn: #9a6200;    --warn-bg: #fdf1d9;
  --danger: #b4302b;  --danger-bg: #fbe6e4;
  --info: #1f5f9a;    --info-bg: #e3eef9;
  --neutral: #55666d; --neutral-bg: #e9eef0;

  --radius: 6px;
  --radius-sm: 4px;
  --font: "IBM Plex Sans", "IBM Plex Sans Arabic", -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

html { font-family: var(--font); font-size: 13.5px; color: var(--text); background: var(--paper); }
body { -webkit-font-smoothing: antialiased; }
[x-cloak] { display: none !important; }
::selection { background: var(--primary-100); }
.scroll-thin::-webkit-scrollbar { width: 8px; height: 8px; }
.scroll-thin::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; border: 2px solid transparent; background-clip: padding-box; }
.cell, .bubble { direction: auto; unicode-bidi: plaintext; }
.bubble { white-space: pre-wrap; word-break: break-word; }
.num { font-family: var(--mono); font-size: 12px; letter-spacing: 0; }
h1 { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 600; }
code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 3px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

/* ---- sidebar ---- */
.sidebar { width: 216px; background: var(--ink-900); color: var(--ink-300); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 600; font-size: 15px; }
.sidebar .brand .mark { width: 28px; height: 28px; border-radius: 7px; background: var(--primary); display: grid; place-items: center; }
.sidebar .brand .mark svg { width: 16px; height: 16px; stroke: #fff; }
.sidebar nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius); color: var(--ink-300); text-decoration: none; }
.sidebar nav a svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.sidebar nav a:hover { background: var(--ink-800); color: #fff; }
.sidebar nav a.active { background: var(--ink-700); color: #fff; }
.sidebar .foot { margin-top: auto; padding: 12px 18px 16px; border-top: 1px solid var(--ink-800); font-size: 12px; color: var(--ink-500); }
.sidebar .foot .n { display: flex; align-items: center; gap: 8px; padding: 3px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- page chrome ---- */
.page { padding: 22px 26px; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 18px; background: var(--surface); border-bottom: 1px solid var(--line); }
.panel-side { background: var(--surface); border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; flex-shrink: 0; }
.panel-side .head { padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 600; display: flex; align-items: center; justify-content: space-between; }
.section-title { font-size: 12px; font-weight: 600; color: var(--text-3); margin-bottom: 6px; }

/* ---- cards & tables ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card > .head { padding: 11px 16px; border-bottom: 1px solid var(--line); font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card > .body { padding: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { font-size: 12px; color: var(--text-3); }
.stat .value { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: start; font-size: 11.5px; font-weight: 600; color: var(--text-3); padding: 8px 10px; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th.sortable { cursor: pointer; }
.table th.sortable:hover { color: var(--text); }
.table td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr.row:hover { background: var(--primary-050); }
.table tbody tr.row.selected { background: var(--primary-100); }
.table .muted { color: var(--text-3); }
.table-sticky thead th { position: sticky; top: 0; z-index: 1; }
.empty { padding: 44px 16px; text-align: center; color: var(--text-3); }

/* ---- controls ---- */
.input, .select, .textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: 6px 9px; line-height: 1.3; min-width: 0;
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-100); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); color: var(--text-2); }
.select { padding-right: 26px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237d8d93' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; }
.select[multiple] { background-image: none; padding-right: 9px; }
.input-sm, .select-sm { padding: 4px 7px; font-size: 12.5px; }
.select-sm { padding-right: 24px; }
input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--primary); }
label.field { display: block; font-size: 12px; color: var(--text-2); }
label.field > .input, label.field > .select, label.field > .textarea { display: block; width: 100%; margin-top: 4px; }
input[type=file] { font-size: 12.5px; }
input[type=file]::file-selector-button { font: inherit; font-size: 12.5px; border: 1px solid var(--line-strong); background: var(--surface); border-radius: var(--radius-sm); padding: 4px 9px; margin-right: 8px; cursor: pointer; }

.btn { font: inherit; font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; line-height: 1.3; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-700); border-color: var(--primary-700); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); border-color: #e4b3b0; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 4px 9px; font-size: 12.5px; }
.btn-xs { padding: 2px 7px; font-size: 12px; }
.btn-block { width: 100%; }
.link { color: var(--primary); cursor: pointer; background: none; border: 0; padding: 0; font: inherit; font-size: inherit; }
.link:hover { text-decoration: underline; }
.link-danger { color: var(--danger); }
.icon-btn { background: none; border: 0; padding: 2px 4px; cursor: pointer; color: var(--text-3); border-radius: 3px; font: inherit; line-height: 1; }
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-bg); }

/* ---- pills & status ---- */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 500; padding: 2px 8px; border-radius: 999px; background: var(--neutral-bg); color: var(--neutral); white-space: nowrap; text-transform: capitalize; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.pill.plain::before { display: none; }
.pill[data-status="connected"], .pill[data-status="running"], .pill[data-status="sent"] { background: var(--ok-bg); color: var(--ok); }
.pill[data-status="qr"], .pill[data-status="paused"], .pill[data-status="skipped"], .pill[data-status="scheduled"] { background: var(--warn-bg); color: var(--warn); }
.pill[data-status="connecting"], .pill[data-status="sending"] { background: var(--info-bg); color: var(--info); }
.pill[data-status="banned"], .pill[data-status="logged_out"], .pill[data-status="failed"], .pill[data-status="cancelled"] { background: var(--danger-bg); color: var(--danger); }
.pill[data-status="completed"] { background: var(--primary-100); color: var(--primary-700); }
.tag { display: inline-block; font-size: 11px; font-weight: 500; color: #fff; padding: 1px 7px; border-radius: 4px; margin-right: 4px; }
.txt-ok { color: var(--ok); } .txt-warn { color: var(--warn); } .txt-danger { color: var(--danger); } .txt-muted { color: var(--text-3); } .txt-2 { color: var(--text-2); }

/* ---- folders tree ---- */
.tree-item { display: flex; align-items: center; border-radius: var(--radius-sm); margin: 0 6px; }
.tree-item:hover { background: var(--surface-2); }
.tree-item.active { background: var(--primary-100); color: var(--primary-700); font-weight: 500; }
.tree-item.drop { background: var(--primary-100); box-shadow: inset 0 0 0 1.5px var(--primary); }
.tree-item > button.name { flex: 1; text-align: start; padding: 6px 8px; background: none; border: 0; font: inherit; color: inherit; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-item .count { color: var(--text-3); font-size: 11.5px; margin-left: 4px; }
.tree-item .acts { display: none; gap: 2px; padding-right: 6px; }
.tree-item:hover .acts { display: flex; }

/* ---- chat ---- */
.chat-list-item { width: 100%; text-align: start; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--line); background: var(--surface); cursor: pointer; font: inherit; color: inherit; }
.chat-list-item:hover { background: var(--primary-050); }
.chat-list-item.active { background: var(--primary-100); }
.thread { background: #e9e3da; }
.bubble-wrap { max-width: 70%; padding: 6px 10px 4px; border-radius: 8px; box-shadow: 0 1px 1px rgba(0,0,0,.06); background: #fff; }
.bubble-wrap.me { background: #d9fdd3; }
.bubble-wrap .who { display: block; font-size: 11.5px; font-weight: 600; color: var(--primary-700); margin-bottom: 2px; text-align: start; }
.bubble-wrap .who:disabled { color: var(--text-3); cursor: default; text-decoration: none; }
.bubble-wrap .when { font-size: 10.5px; color: var(--text-3); text-align: end; margin-top: 2px; }
.day-sep { text-align: center; margin: 10px 0; }
.day-sep span { font-size: 11px; color: var(--text-2); background: rgba(255,255,255,.85); padding: 2px 9px; border-radius: 999px; }

/* ---- warning box ---- */
.warning { background: var(--warn-bg); border: 1px solid #ecd39a; border-left: 4px solid var(--warn); border-radius: var(--radius); padding: 10px 14px; font-size: 12.5px; color: #5b3d00; }
.warning p + p { margin-top: 4px; }
.warning.danger { background: var(--danger-bg); border-color: #e8b4b4; border-left-color: var(--danger); color: #7a1f1f; }

/* ---- chat composer ---- */
.composer { background: var(--surface); border-top: 1px solid var(--line); padding: 10px 14px; }

/* ---- misc ---- */
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); }
.banner { padding: 9px 18px; border-bottom: 1px solid var(--line); background: var(--primary-050); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12.5px; }
.filter-panel { padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.modal-backdrop { position: fixed; inset: 0; background: rgba(16,35,43,.45); z-index: 40; display: flex; align-items: center; justify-content: center; }
.modal { background: var(--surface); border-radius: 8px; width: 720px; max-height: 90vh; overflow: auto; padding: 20px 22px; box-shadow: 0 20px 60px rgba(16,35,43,.25); }
.toast { position: fixed; bottom: 18px; right: 18px; z-index: 50; padding: 9px 14px; border-radius: var(--radius); color: #fff; background: var(--ink-800); font-size: 13px; box-shadow: 0 8px 24px rgba(16,35,43,.25); }
.toast.error { background: var(--danger); }
.qr-box { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: inline-block; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 12.5px; color: var(--text-2); }
.kv b { color: var(--text); font-weight: 600; }
.divider { border-top: 1px solid var(--line); }
@media (prefers-reduced-motion: no-preference) { .btn, .tree-item, .chat-list-item, .table tbody tr.row { transition: background-color .12s ease; } }

/* ---- layout ---- */
.shell { display: flex; height: 100vh; height: 100dvh; }
.content { flex: 1; min-width: 0; overflow: auto; }
.split { display: flex; height: 100%; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }

/* ---- badges, topbar, mobile, RTL ---- */
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 600; margin-inline-start: auto; }
.topbar { display: none; align-items: center; gap: 10px; padding: 0 12px; height: 48px; background: var(--ink-900); color: #fff; flex-shrink: 0; }
.scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 29; }
.mobile-only { display: none !important; }
.select.dark { background-color: var(--ink-800); color: var(--ink-300); border-color: var(--ink-700); }
.detail-drawer { border-inline-end: 0; border-inline-start: 1px solid var(--line); }
.pager { border-top: 1px solid var(--line); border-bottom: 0; padding: 8px 18px; font-size: 12.5px; }
.title-input { font-size: 18px; font-weight: 600; background: transparent; border-color: transparent; padding-inline-start: 0; }
.title-input:focus { background: var(--surface); border-color: var(--primary); padding-inline-start: 9px; }
.dot-danger { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); display: inline-block; }
[dir="rtl"] .bubble-wrap .who { text-align: right; }
[dir="rtl"] .sidebar nav a svg { transform: scaleX(-1); }
@media (max-width: 768px) {
  .shell { flex-direction: column; }
  .topbar { display: flex; }
  .mobile-only { display: inline-flex !important; }
  .sidebar { position: fixed; top: 0; bottom: 0; inset-inline-start: 0; z-index: 30; transform: translateX(-100%); transition: transform .18s ease; }
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: none; }
  .scrim { display: block; }
  .content { height: auto; flex: 1; min-height: 0; }
  .page { padding: 14px; }
  .split { flex-direction: column; }
  .split > .panel-side, .split > .pane-list { width: 100% !important; flex: 1; min-height: 0; border-inline-end: 0; }
  .split > .pane-main { flex: 1; min-height: 0; }
  .hidden-mobile { display: none !important; }
  .side-drawer { position: fixed; top: 0; bottom: 0; inset-inline-start: 0; width: 80% !important; max-width: 320px; z-index: 31; transform: translateX(-100%); transition: transform .18s ease; box-shadow: var(--shadow-lg); }
  [dir="rtl"] .side-drawer { transform: translateX(100%); }
  .side-drawer.open { transform: none; }
  .detail-drawer { position: fixed; inset: 0; width: 100% !important; z-index: 32; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .bubble-wrap { max-width: 88%; }
  .modal { width: 94vw !important; max-height: 90vh; overflow: auto; }
  .toolbar h1 { font-size: 16px; }
}

/* ---- lead stages ---- */
.stage-select { min-width: 120px; font-weight: 500; }
.stage-select[data-stage="new"] { color: var(--ink-700); }
.stage-select[data-stage="contacted"] { color: #1d4ed8; }
.stage-select[data-stage="interested"] { color: #b45309; }
.stage-select[data-stage="not_interested"] { color: var(--danger); }
.stage-select[data-stage="purchased"] { color: var(--primary-700); }

.member-row { padding: 6px 10px; border-bottom: 1px solid var(--line); }
.member-row.team { background: var(--primary-050); }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.seg button { padding: 5px 10px; font-size: 12.5px; background: var(--surface); border: 0; cursor: pointer; color: var(--text-2); }
.seg button + button { border-inline-start: 1px solid var(--line-strong); }
.seg button.on { background: var(--ink-800); color: #fff; }
.table td.muted span:first-child { opacity: .55; }

/* ---------- settings page ---------- */
.settings-page { max-width: 1100px; }
.settings-search { width: 260px; max-width: 100%; }
.settings-layout { display: grid; grid-template-columns: 200px 1fr; gap: 20px; align-items: start; }
.settings-nav { position: sticky; top: 70px; display: flex; flex-direction: column; gap: 2px; }
.settings-tab { display: flex; align-items: center; gap: 8px; text-align: start; padding: 8px 12px; border-radius: var(--radius); border: 0; background: transparent; color: var(--text-2); font: inherit; font-size: 13.5px; cursor: pointer; }
.settings-tab:hover { background: var(--surface-2); color: var(--text); }
.settings-tab.active { background: var(--primary-100); color: var(--primary-700); font-weight: 600; }
.settings-tab .badge { margin-inline-start: auto; background: var(--primary); }
.settings-content .card .body { padding-top: 4px; padding-bottom: 4px; }
.srow { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.srow:last-of-type { border-bottom: 0; }
.srow-label { font-size: 13.5px; color: var(--text); display: flex; flex-direction: column; gap: 2px; }
.srow-hint { font-size: 11.5px; color: var(--text-3); }
.srow-default { font-size: 11px; color: var(--text-3); font-family: var(--mono, ui-monospace, monospace); }
.srow-control { display: flex; justify-content: flex-end; }
.srow-wide { grid-template-columns: 1fr; } .srow-wide .srow-control { justify-content: stretch; }
[dir="rtl"] .srow-control { justify-content: flex-start; }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line-strong); border-radius: 11px; cursor: pointer; transition: background .15s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(18px); }
[dir="rtl"] .switch input:checked + span::before { transform: translateX(-18px); }
[dir="rtl"] .switch span::before { left: auto; right: 3px; }
.savebar { position: sticky; bottom: 12px; display: flex; align-items: center; gap: 12px; margin-top: 16px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(16,35,43,.18); font-size: 13px; }
.desktop-only { display: flex; }
@media (max-width: 800px) {
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { position: static; }
  .desktop-only { display: none; }
  .srow { grid-template-columns: 1fr; gap: 6px; }
  .srow-control { justify-content: flex-start; }
}
