/* WhatsApp Team Inbox. Same palette as crm.css so the two read as one product. */
:root {
  --brand: #c40808; --brand-dark: #9e0606; --brand-tint: #fdecec;
  --ink: #1c2330; --muted: #6b7280; --faint: #98a1b1;
  --line: #e5e7eb; --line-strong: #d5dae3;
  --bg: #f4f5f7; --card: #ffffff; --panel-2: #f7f8fb;
  --ok: #148f4b; --ok-tint: #e7f4ec;
  --warn: #bd6a06; --warn-tint: #fbefdd;
  --ready: #2563eb; --ready-tint: #e8effc;
  --out: #e9f6ee; --note: #fff7dc; --note-line: #f0d98a;
}
* { box-sizing: border-box; }
html, body { height: 100%; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", system-ui, sans-serif; font-size: 14px; display: flex; flex-direction: column; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }
button { cursor: pointer; }
.ico { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Buttons */
.primary { background: var(--brand); color: #fff; border: none; border-radius: 8px; padding: 8px 14px; font-weight: 600; }
.primary:hover { background: var(--brand-dark); }
.primary:disabled { background: #d9a0a0; cursor: not-allowed; }
.secondary { background: var(--card); color: var(--ink); border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 12px; font-weight: 600; }
.secondary:hover { background: var(--panel-2); }
.ghost { background: none; border: none; color: var(--muted); padding: 7px 10px; border-radius: 8px; font-weight: 600; text-decoration: none; }
.ghost:hover { background: var(--panel-2); color: var(--ink); }
.danger { background: var(--card); color: var(--brand); border: 1px solid #efb3b3; border-radius: 8px; padding: 7px 12px; font-weight: 600; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 18px; padding: 0 18px; height: 56px; background: var(--card); border-bottom: 1px solid var(--line); flex: none; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand img { height: 24px; }
.brand-tag { font-size: 11px; font-weight: 800; letter-spacing: .06em; color: var(--brand); }
.numbers { display: flex; gap: 8px; }
.pill { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); margin-right: 6px; vertical-align: 1px; }
.pill.on { color: var(--ok); background: var(--ok-tint); border-color: #bfe3cc; }
.pill.on::before { background: var(--ok); }
.pill.warn { color: var(--warn); background: var(--warn-tint); border-color: #f1d3a6; }
.pill.warn::before { background: var(--warn); }
.who { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.me { color: var(--muted); font-size: 13px; padding: 0 6px; }

.noaccess { margin: 80px auto; text-align: center; color: var(--muted); }

/* Three panes */
.app { flex: 1; display: grid; grid-template-columns: 340px 1fr; min-height: 0; }
.app.with-ctx { grid-template-columns: 340px 1fr 300px; }
.list-pane { background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.list-head { padding: 12px 12px 8px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.views { display: flex; flex-wrap: wrap; gap: 2px; }
.views button { border: none; background: none; padding: 6px 9px; border-radius: 8px; color: var(--muted); font-weight: 600; font-size: 13px; }
.views button:hover { background: var(--panel-2); color: var(--ink); }
.views button.active { background: var(--brand-tint); color: var(--brand); }
.count:not(:empty) { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--brand); color: #fff; font-size: 11px; line-height: 18px; text-align: center; margin-left: 2px; }
.count.zero { background: var(--line-strong); color: var(--muted); }
.list-tools { display: flex; gap: 6px; }
.list-tools input, .list-tools select { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.list-tools select { flex: 0 0 120px; }
.list-actions { display: flex; gap: 6px; }
.list-actions .primary, .list-actions .secondary { flex: 1; }

.convos { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.convo { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--line); cursor: pointer; align-items: start; }
.convo:hover { background: var(--panel-2); }
.convo.active { background: var(--brand-tint); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: #e8eaef; color: var(--muted); display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.avatar.group { background: var(--ready-tint); color: var(--ready); }
.c-main { min-width: 0; }
.c-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.c-meta { display: flex; gap: 4px; margin-top: 5px; flex-wrap: wrap; }
.chip { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.chip.sales { color: var(--ready); background: var(--ready-tint); border-color: #c9d8f7; }
.chip.student_affairs { color: #7a3fb0; background: #f3ebfa; border-color: #dcc8ef; }
.chip.warn { color: var(--warn); background: var(--warn-tint); border-color: #f1d3a6; }
.c-side { text-align: right; font-size: 12px; color: var(--faint); white-space: nowrap; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--ok); margin-top: 8px; }
.convo.unread .c-title { font-weight: 800; }
.empty { padding: 30px 20px; color: var(--muted); text-align: center; }

/* Thread */
.thread-pane { display: flex; min-height: 0; min-width: 0; }
.placeholder { margin: auto; color: var(--faint); }
.thread { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.back { display: none; border: none; background: none; font-size: 26px; line-height: 1; color: var(--muted); padding: 0 6px; }
.thread-title { min-width: 0; flex: 1; }
.t-name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.thread-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.owner { font-size: 12px; color: var(--muted); }
.owner b { color: var(--ink); }
.window-bar { padding: 6px 16px; font-size: 12px; background: var(--ok-tint); color: var(--ok); border-bottom: 1px solid #cfe9d9; }
.window-bar.warn { background: var(--warn-tint); color: var(--warn); border-color: #f1d3a6; }

.messages { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; background: #efeae2; }
.more { align-self: center; margin-bottom: 8px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: #fff; border-radius: 8px; padding: 3px 10px; margin: 8px 0 4px; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.msg { max-width: min(560px, 78%); padding: 7px 10px 5px; border-radius: 10px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.08); position: relative; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.in { align-self: flex-start; border-top-left-radius: 3px; }
.msg.out { align-self: flex-end; background: var(--out); border-top-right-radius: 3px; }
.msg.out.failed { background: #fdecec; }
.msg.note { align-self: center; background: var(--note); border: 1px dashed var(--note-line); max-width: 80%; }
.msg.event { align-self: center; background: rgba(255,255,255,.75); color: var(--muted); font-size: 12px; box-shadow: none; padding: 4px 10px; text-align: center; }
.m-author { font-size: 12px; font-weight: 700; color: #7a3fb0; margin-bottom: 2px; }
.m-label { font-size: 11px; font-weight: 700; color: var(--warn); margin-bottom: 2px; text-transform: uppercase; letter-spacing: .03em; }
.m-body { white-space: pre-wrap; line-height: 1.45; }
.m-body a { color: var(--ready); }
.m-foot { display: flex; gap: 6px; justify-content: flex-end; align-items: center; font-size: 11px; color: var(--faint); margin-top: 3px; }
.m-by { color: var(--muted); }
.ticks { font-weight: 700; letter-spacing: -2px; }
.ticks.read { color: #34b7f1; }
.m-error { color: var(--brand); font-size: 12px; margin-top: 4px; }
.m-quote { border-left: 3px solid var(--ok); background: rgba(0,0,0,.04); border-radius: 4px; padding: 4px 8px; font-size: 12px; color: var(--muted); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-tpl { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.m-media img, .m-media video { max-width: 280px; max-height: 320px; border-radius: 6px; display: block; cursor: zoom-in; }
.m-media audio { width: 260px; }
.m-doc { display: inline-flex; gap: 8px; align-items: center; padding: 8px 10px; background: rgba(0,0,0,.04); border-radius: 6px; color: var(--ink); text-decoration: none; font-weight: 600; }
.m-reply { position: absolute; top: 4px; right: -54px; opacity: 0; font-size: 12px; border: none; background: #fff; border-radius: 6px; padding: 2px 6px; color: var(--muted); box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.msg.out .m-reply { right: auto; left: -54px; }
.msg:hover .m-reply { opacity: 1; }

/* Composer */
.composer { background: var(--card); border-top: 1px solid var(--line); padding: 8px 12px 10px; }
.composer.note-mode { background: var(--note); }
.mode { display: flex; gap: 4px; margin-bottom: 6px; }
.mode button { border: none; background: none; padding: 4px 9px; border-radius: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.mode button.active { background: var(--panel-2); color: var(--ink); }
.composer.note-mode .mode button.active { background: #fbe9a8; }
.compose-row { display: flex; align-items: flex-end; gap: 6px; }
.compose-row textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; max-height: 160px; line-height: 1.4; background: #fff; }
.icon { border: none; background: none; color: var(--muted); padding: 8px; border-radius: 8px; }
.icon:hover { background: var(--panel-2); color: var(--ink); }
.quote, .file-chip { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; background: var(--panel-2); border-left: 3px solid var(--ok); border-radius: 6px; padding: 5px 8px; margin-bottom: 6px; color: var(--muted); }
.quote span, .file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote button, .file-chip button { border: none; background: none; color: var(--brand); font-weight: 600; font-size: 12px; }
.closed-bar { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--warn-tint); color: var(--warn); border-top: 1px solid #f1d3a6; font-size: 13px; }

/* Context */
.ctx-pane { background: var(--card); border-left: 1px solid var(--line); overflow-y: auto; min-height: 0; }
.ctx-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.ctx-sec { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.ctx-sec h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 4px 8px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.muted { color: var(--muted); font-size: 13px; }
.hist { list-style: none; margin: 0; padding: 0; font-size: 12px; color: var(--muted); }
.hist li { padding: 3px 0; }

/* Dialogs */
.modal-back { position: fixed; inset: 0; background: rgba(20,24,33,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: var(--card); border-radius: 14px; width: 520px; max-width: 100%; max-height: 90vh; overflow-y: auto; padding: 20px 22px 16px; box-shadow: 0 18px 50px rgba(0,0,0,.25); }
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.modal label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; font-weight: 600; }
.modal input, .modal select, .modal textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; }
.modal textarea { resize: vertical; min-height: 70px; }
.modal-msg { color: var(--brand); font-size: 13px; min-height: 18px; margin-top: 10px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.tpl-preview { white-space: pre-wrap; background: var(--out); border-radius: 8px; padding: 10px; font-size: 13px; margin-top: 10px; }
.pick-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 10px; max-height: 340px; overflow-y: auto; }
.pick-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.pick-list li:last-child { border-bottom: none; }
.pick-list .grp { background: var(--panel-2); font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pick-list button { flex: none; }
.qr { display: block; margin: 10px auto; width: 260px; height: 260px; image-rendering: pixelated; }
.warnbox { background: var(--warn-tint); color: var(--warn); border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 60; max-width: 90vw; }
.toast.err { background: var(--brand); }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 70; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 94vh; }

/* Role gating (cosmetic — the server enforces every rule) */
body:not(.is-sup) .sup-only { display: none !important; }
body:not(.is-admin) .admin-only { display: none !important; }
body:not(.can-groups) .groups-only { display: none !important; }

/* Narrow screens: one pane at a time */
@media (max-width: 1100px) {
  .app.with-ctx { grid-template-columns: 300px 1fr; }
  .ctx-pane { position: fixed; right: 0; top: 56px; bottom: 0; width: min(340px, 92vw); z-index: 30; box-shadow: -8px 0 24px rgba(0,0,0,.12); }
}
@media (max-width: 760px) {
  .topbar { padding: 0 10px; gap: 8px; }
  .brand-tag, .numbers, .me, #btnCrm, #btnReplies { display: none; }
  .app, .app.with-ctx { grid-template-columns: 1fr; }
  .app.thread-open .list-pane { display: none; }
  .app:not(.thread-open) .thread-pane { display: none; }
  .back { display: block; }
  .thread-head { padding: 8px 10px; gap: 6px; }
  .owner { display: none; }
  .msg { max-width: 88%; }
  .m-reply { display: none; }
  .ctx-pane { top: 0; width: 100vw; }
  .row2 { grid-template-columns: 1fr; }
}

/* Top-bar page tabs (Chats / Team) — the CRM's nav style: brand text + a thin underline. */
.topnav { display: flex; gap: 2px; }
.topnav button { position: relative; border: none; background: none; padding: 9px 13px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.topnav button:hover { background: var(--panel-2); color: var(--ink); }
.topnav button.active { color: var(--brand); }
.topnav button.active::after { content: ""; position: absolute; left: 13px; right: 13px; bottom: -9px; height: 2.5px; border-radius: 2px; background: var(--brand); }

/* Team page — mirrors crm.css's Team management (team-add / team-form / team-toolbar / table). */
.team-view { flex: 1; overflow-y: auto; padding: 18px 20px 40px; }
.team-add { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.section-h { font-weight: 700; margin-bottom: 10px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 9px; overflow: hidden; margin-bottom: 10px; }
.seg button { border: none; background: #fff; padding: 7px 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--brand-tint); color: var(--brand); }
.team-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.team-form input, .team-form select { height: 38px; padding: 0 11px; border: 1px solid var(--line); border-radius: 9px; font-size: 13px; background: #fff; color: var(--ink); }
.team-form input:focus, .team-form select:focus { outline: none; border-color: var(--brand); }
.team-form .primary { height: 38px; }
.pick { position: relative; flex: 1 1 320px; }
.pick input { width: 100%; }
.pick-results { position: absolute; z-index: 5; left: 0; right: 0; top: 42px; list-style: none; margin: 0; padding: 4px; background: #fff; border: 1px solid var(--line-strong); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.08); max-height: 260px; overflow-y: auto; }
.pick-results li { padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.pick-results li[data-pick]:hover { background: var(--panel-2); }
.new-wrap { display: contents; }
.new-wrap input { flex: 1 1 200px; }
.tm-note { color: var(--muted); font-size: 12px; margin-top: 10px; }
.tm-msg { color: #b91c1c; font-size: 12px; margin-top: 6px; min-height: 16px; }
.section-head { display: flex; align-items: baseline; gap: 10px; margin: 6px 0 10px; }
.section-head h2 { font-size: 16px; margin: 0; }
.section-head .meta { color: var(--muted); font-size: 13px; }
.team-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.team-toolbar input, .team-toolbar select { padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 9px; font-size: 13px; background: #fff; color: var(--ink); }
.team-toolbar input { flex: 1 1 240px; min-width: 180px; }
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
table.members { width: 100%; border-collapse: collapse; font-size: 13px; }
table.members th { text-align: left; padding: 10px 14px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--panel-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
table.members td { padding: 10px 14px; border-bottom: 1px solid #f1f2f4; vertical-align: middle; }
table.members tr:last-child td { border-bottom: none; }
table.members tr.row-off td { color: var(--faint); }
table.members select { height: 32px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 13px; }
table.members td.act { text-align: right; white-space: nowrap; }
.state { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.state.on { color: var(--ok); background: var(--ok-tint); }
.state.off { color: var(--muted); background: var(--panel-2); }
button.sm { padding: 5px 10px; font-size: 12px; }
@media (max-width: 760px) {
  .topnav button { padding: 8px 9px; }
  .team-view { padding: 12px; }
  .team-form > *, .pick, .new-wrap input { flex: 1 1 100%; width: 100%; }
}

/* Reports page (4 Oct 2026) */
.rp-toolbar { align-items: center; }
.rp-toolbar .seg { margin-bottom: 0; }
.rp-date { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.rp-date input { padding: 7px 9px; border: 1px solid var(--line-strong); border-radius: 9px; font-size: 13px; background: #fff; color: var(--ink); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.kpi .k-v { font-size: 22px; font-weight: 700; line-height: 1.2; }
.kpi .k-l { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.good .k-v { color: var(--ok); }
.kpi.bad .k-v { color: var(--brand); }
.kpi.warn .k-v { color: var(--warn); }
table.members th.n, table.members td.n { text-align: right; white-space: nowrap; }
table.members tr.rp-queue td { background: var(--panel-2); font-style: italic; }
table.members tfoot td { font-weight: 700; border-top: 1px solid var(--line-strong); background: var(--panel-2); }
.v-good { color: var(--ok); font-weight: 600; }
.v-bad { color: var(--brand); font-weight: 700; }
.v-warn { color: var(--warn); font-weight: 600; }
.v-none { color: var(--faint); }
.rp-gap { margin-top: 22px; }
.rp-help { margin-top: 18px; color: var(--muted); font-size: 13px; }
.rp-help summary { cursor: pointer; font-weight: 600; color: var(--ink); }
.rp-help li { margin: 4px 0; }
@media (max-width: 760px) {
  .rp-toolbar .seg { flex-wrap: wrap; }
}
