:root {
  --bg: #f4f6f8; --card: #fff; --ink: #1c2430; --muted: #6b7684;
  --line: #e3e8ee; --brand: #128c7e; --brand-ink: #0b5c52; --accent: #2b6cb0;
  --ok: #1f9d55; --warn: #dd6b20;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* must win over .modal/.select-bar display:flex */
body { margin: 0; font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 0 22px; height: 56px;
  background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 5; }
.topbar .brand { font-weight: 700; letter-spacing: .2px; }
.topbar nav { display: flex; gap: 4px; margin-right: auto; }
.topbar nav a { color: #dff3ef; padding: 6px 12px; border-radius: 6px; }
.topbar nav a:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.topbar nav a.on { background: rgba(255,255,255,.22); color: #fff; }
.conn { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #eafaf6; }
.conn .dot { width: 9px; height: 9px; border-radius: 50%; background: #cbd5e0; }
.conn.ok .dot { background: #7ee2a8; } .conn.warn .dot { background: #ffd27a; }
.conn.bad .dot { background: #ff9b9b; }

main { max-width: 1040px; margin: 22px auto; padding: 0 18px; }
.rowhead h1 { margin: 0 0 2px; font-size: 22px; }
.rowhead { margin-bottom: 16px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin-top: 10px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 760px) { .grid { grid-template-columns: 1fr; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px; margin-bottom: 18px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.actions { display: flex; gap: 8px; align-items: center; }
.search { border: 1px solid var(--line); border-radius: 8px; padding: 7px 11px; font-size: 14px;
  min-width: 200px; background: #fff; color: var(--ink); }
.search:focus { outline: none; border-color: var(--brand); }

.form-grid { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 13px;
  color: var(--muted); font-weight: 600; }
.form-grid input { border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px;
  font-size: 14px; color: var(--ink); background: #fff; min-width: 220px; }
.form-grid input:focus { outline: none; border-color: var(--brand); }
.mobile-row { display: flex; gap: 6px; }
.mobile-row .cc { min-width: 54px; width: 54px; text-align: center; }
.otp-row { display: flex; gap: 8px; align-items: center; }
#onsite-status { margin-bottom: 4px; }

.btn { background: var(--brand); color: #fff; border: 0; border-radius: 8px; padding: 8px 14px;
  font-size: 14px; cursor: pointer; }
.btn:hover { background: var(--brand-ink); }
.btn.ghost { background: #eef2f6; color: var(--ink); }
.btn.ghost:hover { background: #e2e8f0; }
.btn:disabled { opacity: .5; cursor: default; }

.stats { display: flex; gap: 14px; flex-wrap: wrap; }
.stat { flex: 1; min-width: 90px; background: #f7f9fb; border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; text-align: center; }
.stat .num { display: block; font-size: 26px; font-weight: 700; color: var(--brand-ink); }
.stat .lbl { font-size: 12px; color: var(--muted); }

.qr { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.qr img { width: 260px; height: 260px; border: 1px solid var(--line); border-radius: 12px;
  background: #fff; padding: 8px; }
.qr-steps ol { margin: 8px 0 0; padding-left: 20px; }
.qr-steps li { margin: 3px 0; }
.qr-steps code, .muted code { background: #eef2f6; padding: 1px 6px; border-radius: 5px; font-size: 13px; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: #e3f6ec; color: var(--ok); }
.badge.warn { background: #fdf0e3; color: var(--warn); }
.badge.bad { background: #fdeaea; color: #c53030; }

.chips { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chips li { background: #eef2f6; border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px; font-size: 13px; }
.chips li .pid { color: var(--muted); font-size: 11px; }

table.chats { width: 100%; border-collapse: collapse; }
table.chats th, table.chats td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line);
  vertical-align: top; }
table.chats th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.chat-name { font-weight: 600; }
.chat-sub { font-size: 12px; color: var(--muted); }

.switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch input { display: none; }
.slider { position: absolute; inset: 0; background: #cbd5e0; border-radius: 999px; transition: .15s; }
.slider::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* Per-row project linker (searchable multi-select) */
.btn.small { padding: 5px 10px; font-size: 13px; }
.linked-wrap { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.ptag { display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
  background: #e8f5f2; color: var(--brand-ink); border: 1px solid #cfe9e3;
  border-radius: 999px; padding: 3px 6px 3px 10px; }
.ptag-x { cursor: pointer; color: var(--brand-ink); font-weight: 700; line-height: 1;
  background: #d3ece6; border-radius: 50%; width: 16px; height: 16px; text-align: center;
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px; }
.ptag-x:hover { background: #b8ddd4; text-decoration: none; }
.small { font-size: 12px; }
.ms { position: relative; display: inline-block; }
.ms-pop { margin-top: 6px; width: 300px; max-width: 78vw; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; box-shadow: 0 6px 20px rgba(20,40,60,.10); padding: 8px; }
.ms-input { width: 100%; border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px;
  font-size: 14px; margin-bottom: 6px; }
.ms-input:focus { outline: none; border-color: var(--brand); }
.ms-list { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; }
.ms-list li { padding: 7px 9px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.ms-list li:hover { background: #eef6f4; }
.ms-list li.none { color: var(--muted); cursor: default; }
.ms-list li.none:hover { background: transparent; }

.msg { display: flex; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.msg .avatar { width: 34px; height: 34px; border-radius: 50%; background: #dbe4ec; color: var(--brand-ink);
  font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 13px; flex: none; }
.msg .body { flex: 1; min-width: 0; }
.msg .meta { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.msg .meta b { color: var(--ink); }
.msg .text { white-space: pre-wrap; word-break: break-word; }
.msg .thumb { margin-top: 8px; }
.msg .thumb img { max-width: 240px; max-height: 240px; border-radius: 10px; border: 1px solid var(--line); }
.msg .tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: #eef2f6; color: var(--muted); margin-left: 6px; }
.empty { text-align: center; color: var(--muted); padding: 30px; }

/* ===================== Groups workspace ===================== */
main.wide { max-width: 1320px; }
.warn-text { color: var(--warn); }
.ok-text { color: var(--ok); }

.workspace { display: flex; gap: 14px; height: calc(100vh - 96px); min-height: 460px; }
.rail { width: 260px; flex: none; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.rail-head { display: flex; align-items: center; justify-content: space-between;
  padding: 12px; border-bottom: 1px solid var(--line); }
.rail-title { font-weight: 700; font-size: 14px; }
#group-rail { overflow-y: auto; flex: 1; }
.rail-item { padding: 11px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.rail-item:hover { background: #f4f8f7; }
.rail-item.on { background: #e8f5f2; box-shadow: inset 3px 0 0 var(--brand); }
.ri-name { font-weight: 600; font-size: 14px; }
.ri-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.convo { flex: 1; min-width: 0; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.convo-head { padding: 12px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.head-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.transcript { flex: 1; overflow-y: auto; padding: 16px; background: #f7f9fb; }
.bubble { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px;
  border-radius: 10px; cursor: pointer; margin-bottom: 6px; border: 1px solid transparent; }
.bubble:hover { background: #eef3f6; }
.bubble.sel { background: #e8f5f2; border-color: #cfe9e3; }
.bubble .msg-sel { margin-top: 4px; accent-color: var(--brand); }
.bubble-body { flex: 1; min-width: 0; }
.bubble-meta { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.bubble-meta b { color: var(--ink); }
.bubble-text { white-space: pre-wrap; word-break: break-word; }
.bubble .thumb { margin-top: 6px; }
.bubble .thumb img { max-width: 220px; max-height: 220px; border-radius: 10px;
  border: 1px solid var(--line); cursor: zoom-in; }
.pushed-badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: #e3f6ec; color: var(--ok); margin-left: 4px; }

.select-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  border-top: 1px solid var(--line); background: #fff; }
.select-bar .spacer { flex: 1; }

.compose { width: 330px; flex: none; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px; overflow-y: auto; }
.cmp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cmp-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .3px; margin: 14px 0 6px; }
.cmp-types { display: flex; gap: 14px; }
.cmp-types label { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.compose select, .cmp-fixed { width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 14px; background: #fff; }
.cmp-fixed { background: #f7f9fb; }
.cmp-actions { margin-top: 18px; display: flex; align-items: center; gap: 10px; }
.cmp-msg { font-size: 13px; }
#cmp-task-box .ms-list { border: 1px solid var(--line); border-radius: 8px; margin-top: 6px; padding: 4px; }
#cmp-task-sel { margin-top: 6px; }

/* ===================== Add-group modal ===================== */
.modal { position: fixed; inset: 0; background: rgba(15,25,35,.45); display: flex;
  align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 20; }
.modal-box { background: var(--card); border-radius: 14px; width: 640px; max-width: 96vw;
  max-height: 84vh; display: flex; flex-direction: column; padding: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; }
.modal-x { background: #eef2f6; border: 0; border-radius: 8px; width: 30px; height: 30px;
  font-size: 20px; line-height: 1; cursor: pointer; color: var(--ink); }
.modal-x:hover { background: #e2e8f0; }
.modal .search { margin: 10px 0; width: 100%; }
.ag-list { overflow-y: auto; }
.ag-row { display: grid; grid-template-columns: 46px 1fr 1.2fr; gap: 12px; align-items: start;
  padding: 12px 4px; border-bottom: 1px solid var(--line); }
.ag-name { font-weight: 600; }

/* ===================== Task picker tree ===================== */
.task-tree { max-height: 300px; overflow-y: auto; overflow-x: hidden; border: 1px solid var(--line);
  border-radius: 8px; padding: 4px; margin-top: 6px; }
.tnode-list, .tchildren { list-style: none; margin: 0; padding: 0; }
.tchildren { padding-left: 13px; border-left: 1px dashed var(--line); margin-left: 8px; }
.trow { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 6px;
  cursor: pointer; font-size: 13px; overflow: hidden; }
.trow:hover { background: #eef6f4; }
.trow.sel { background: #e8f5f2; box-shadow: inset 0 0 0 1px #cfe9e3; }
.tname { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trow.sel .tname { font-weight: 600; color: var(--brand-ink); }
.tcaret { flex: none; width: 12px; text-align: center; color: var(--muted); font-size: 11px; }
.tdot { flex: none; width: 12px; text-align: center; color: #b7c2cc; }
.tcount { flex: none; font-size: 11px; color: var(--muted); background: #eef2f6;
  border-radius: 999px; padding: 0 7px; }

/* ===================== Push history on a message ===================== */
.push-history { margin-top: 8px; display: flex; flex-direction: column; gap: 3px; }
.push-line { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted);
  background: #f1f8f5; border: 1px solid #dcefe8; border-radius: 7px; padding: 3px 9px; max-width: 460px; }
.pl-check { color: var(--ok); font-weight: 700; flex: none; }
.pl-dest { color: var(--brand-ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; min-width: 0; }
.pl-when { margin-left: auto; flex: none; color: #94a1ad; }

/* ===================== Push status dot + detail popup ===================== */
.pdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  vertical-align: middle; margin-left: 6px; }
.pdot.green { background: var(--ok); cursor: pointer; }
.pdot.green:hover { box-shadow: 0 0 0 4px rgba(31,157,85,.18); }
.pdot.orange { background: var(--warn); }
.modal-box.narrow { width: 480px; }
.pd-row { display: flex; align-items: center; gap: 10px; padding: 11px 6px;
  border-bottom: 1px solid var(--line); }
.pd-row:last-child { border-bottom: 0; }
.pd-type { flex: none; font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 999px; }
.pd-type.site { background: #e3f6ec; color: var(--ok); }
.pd-type.task { background: #e8eefb; color: var(--accent); }
.pd-detail { flex: 1; min-width: 0; font-size: 14px; color: var(--ink); word-break: break-word; }
.pd-when { flex: none; font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ===================== Onsite token-refresh banner ===================== */
.token-banner { display: flex; align-items: center; gap: 12px; cursor: pointer;
  background: #fff5e9; border-bottom: 1px solid #f4d9b0; color: #8a5a1c;
  padding: 10px 22px; font-size: 14px; }
.token-banner:hover { background: #fdeed7; }
.token-banner .tb-icon { font-size: 15px; }
.token-banner #token-banner-msg { flex: 1; font-weight: 600; }

/* ===================== Auth pages + header user box ===================== */
.auth-wrap { display: flex; justify-content: center; padding: 8vh 16px; }
.auth-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px; width: 420px; max-width: 96vw; box-shadow: 0 10px 40px rgba(20,40,60,.08); }
.auth-title { margin: 0 0 4px; font-size: 20px; }
.auth-msg { margin-top: 12px; font-size: 13px; }
.user-box { display: flex; align-items: center; gap: 12px; font-size: 13px; color: #eafaf6; }
.user-box .who { font-weight: 700; }
.user-box .logout { color: #dff3ef; text-decoration: underline; }

/* ===================== History back-fill (add-group popup) ===================== */
.ag-history { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.ag-history .hist-date { border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px;
  font-size: 12px; color: var(--ink); }
.ag-history label { display: inline-flex; align-items: center; gap: 5px; }
.hist-status { min-height: 14px; }
