:root {
  --bg: #f3f5f9; --panel: #fff; --line: #e4e8ef; --text: #17202e; --muted: #6b7686; --brand: #1456d8; --brand-weak: #e8f0fe;
  --in: #fff; --out: #dcebff; --danger: #d93025; --warn: #e37400; --ok: #188038; --tg: #229ed9; --zalo: #0068ff; --kl: #e5285f;
  --rail: 68px; --list: 340px; --info: 300px; --r: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text); background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; -webkit-tap-highlight-color: transparent; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
#app { height: 100dvh; display: flex; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 9px; background: var(--brand-weak); color: var(--brand); font-weight: 600; white-space: nowrap; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.danger { background: #fde8e7; color: var(--danger); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { width: 36px; height: 36px; border-radius: 9px; display: inline-grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--bg); color: var(--text); }
svg.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
input.f, textarea.f, select.f { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; background: #fff; outline: none; }
input.f:focus, textarea.f:focus, select.f:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-weak); }
label.fl { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }
.badge.soft { background: #c7cdd6; }
.pill { display: inline-flex; align-items: center; height: 18px; padding: 0 6px; border-radius: 5px; font-size: 11px; font-weight: 700; color: #fff !important; letter-spacing: .2px; }
.pill.tg { background: var(--tg); } .pill.zalo { background: var(--zalo); } .pill.kl { background: var(--kl); } .pill.mock { background: #888; }
.item .meta .pill { height: 15px; font-size: 10px; padding: 0 4px; vertical-align: 1px; }
.plist { max-height: 34dvh; overflow: auto; border: 1px solid var(--line); border-radius: 9px; padding: 4px; margin-top: 6px; }
.plist .pick { gap: 8px; }
.tag { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 11px; background: var(--brand-weak); color: var(--brand); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: #c0c6cf; }
.dot.on { background: var(--ok); } .dot.err { background: var(--danger); } .dot.warn { background: var(--warn); }

/* login */
.login { margin: auto; width: min(380px, 92vw); background: var(--panel); border-radius: 18px; padding: 30px 26px; box-shadow: 0 10px 40px rgba(20, 40, 80, .1); }
.login h1 { margin: 0 0 4px; font-size: 22px; }
.login .err { color: var(--danger); min-height: 20px; font-size: 13px; margin-top: 10px; }
.logo { width: 44px; height: 44px; border-radius: 12px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; margin-bottom: 14px; }

/* shell */
.rail { width: var(--rail); background: #0f1f3d; color: #b9c4d6; display: flex; flex-direction: column; align-items: center; padding: 12px 0; gap: 4px; flex: none; }
.rail .logo { width: 40px; height: 40px; margin-bottom: 10px; font-size: 13px; }
.rail button { position: relative; width: 52px; padding: 8px 0 6px; border-radius: 10px; color: inherit; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; }
.rail button:hover { background: rgba(255,255,255,.07); color: #fff; }
.rail button.on { background: rgba(255,255,255,.13); color: #fff; }
.rail button .badge { position: absolute; top: 2px; right: 4px; }
.rail .sp { flex: 1; }
.list { width: var(--list); background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; flex: none; min-width: 0; }
.list-h { padding: 14px 14px 8px; border-bottom: 1px solid var(--line); }
.list-h h2 { font-size: 17px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.chips { display: flex; gap: 6px; margin-top: 8px; }
.chip { height: 26px; padding: 0 10px; border-radius: 13px; background: var(--bg); font-size: 12.5px; color: var(--muted); }
.chip.on { background: var(--brand); color: #fff; }
.items { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.item { display: flex; gap: 10px; padding: 11px 14px; border-bottom: 1px solid #f1f3f7; cursor: pointer; position: relative; }
.item:hover { background: #f8fafc; }
.item.on { background: var(--brand-weak); }
.item.waiting-long::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--danger); }
.av { width: 42px; height: 42px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; position: relative; }
.av .pl { position: absolute; right: -3px; bottom: -3px; width: 17px; height: 17px; border-radius: 50%; border: 2px solid #fff; display: grid; place-items: center; font-size: 8px; font-weight: 800; }
.av .pl.tg { background: var(--tg); } .av .pl.zalo { background: var(--zalo); } .av .pl.kl { background: var(--kl); } .av .pl.mock { background: #888; }
.item .mid { flex: 1; min-width: 0; }
.item .row { display: flex; align-items: center; gap: 6px; }
.item .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.item .tm { font-size: 11.5px; color: var(--muted); flex: none; }
.item .lt { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; margin-top: 3px; }
.item .meta { font-size: 11.5px; color: var(--muted); margin-top: 3px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.item .wait { color: var(--danger); font-weight: 600; }
.item .mention { color: var(--brand); font-weight: 700; }
.empty { padding: 50px 20px; text-align: center; color: var(--muted); }

.main { flex: 1; display: flex; min-width: 0; background: #eef2f8; }
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-h { height: 62px; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; padding: 0 12px 0 16px; flex: none; padding-top: 0; }
.chat-h .av { width: 38px; height: 38px; font-size: 14px; }
.chat-h .tt { flex: 1; min-width: 0; }
.chat-h .tt b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-h .tt span { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; white-space: nowrap; overflow: hidden; }
.chat-h .acts { display: flex; gap: 6px; align-items: center; }
.banner { background: #fff7e0; color: #7a5300; font-size: 13px; padding: 8px 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid #f3e3b5; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 18px 8px; overscroll-behavior: contain; }
.day { text-align: center; margin: 12px 0; } .day span { background: rgba(0,0,0,.06); color: var(--muted); font-size: 12px; padding: 3px 10px; border-radius: 10px; }
.m { display: flex; margin: 3px 0; gap: 8px; }
.m.out { justify-content: flex-end; }
.m .bub { max-width: min(560px, 78%); background: var(--in); border-radius: 14px; padding: 7px 11px 6px; box-shadow: 0 1px 1px rgba(0,0,0,.05); position: relative; word-wrap: break-word; line-height: 1.42; font-size: 14.5px; }
.m.out .bub { background: var(--out); }
.m .tx { white-space: pre-wrap; }
.m.mention .bub { box-shadow: 0 0 0 2px var(--brand) inset; }
.m .who { font-size: 12px; font-weight: 700; color: var(--brand); margin-bottom: 2px; }
.m .ft { font-size: 11px; color: var(--muted); margin-top: 3px; text-align: right; display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.m .ft .st-failed { color: var(--danger); font-weight: 700; }
.m .quote { border-left: 3px solid var(--brand); background: rgba(20,86,216,.06); padding: 4px 8px; border-radius: 6px; margin-bottom: 5px; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.m img.media { max-width: 100%; max-height: 320px; border-radius: 10px; display: block; margin: 2px 0; cursor: zoom-in; }
.m .file { display: inline-flex; gap: 6px; align-items: center; color: var(--brand); text-decoration: none; }
.m .tools { position: absolute; top: -12px; right: 6px; display: none; background: #fff; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.14); }
.m .bub:hover .tools { display: flex; }
.m .tools button { padding: 4px 8px; font-size: 12px; color: var(--muted); }
.m .tools button:hover { color: var(--brand); }
.m.sys { justify-content: center; } .m.sys .bub { background: transparent; box-shadow: none; color: var(--muted); font-size: 12.5px; }
.m.recalled .bub { opacity: .55; text-decoration: line-through; }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 10px calc(8px + var(--safe-b)); flex: none; }
.composer .replying { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); padding: 4px 6px 8px; }
.composer .replying div { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; border-left: 3px solid var(--brand); padding-left: 8px; }
.composer .row { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; max-height: 160px; min-height: 40px; outline: none; line-height: 1.4; }
.composer textarea:focus { border-color: var(--brand); }
.composer .btn.primary { height: 40px; border-radius: 12px; }
.qpop { position: absolute; bottom: 100%; left: 10px; right: 10px; max-height: 300px; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.12); margin-bottom: 6px; z-index: 5; }
.qpop .qi { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid #f1f3f7; }
.qpop .qi:hover, .qpop .qi.on { background: var(--brand-weak); }
.qpop .qi b { font-size: 13px; } .qpop .qi div { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.info { width: var(--info); background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 16px; flex: none; }
.info h3 { margin: 18px 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.info .kv { display: grid; grid-template-columns: 90px 1fr; gap: 6px 8px; font-size: 13.5px; }
.info .kv span:nth-child(odd) { color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags .tag button { color: inherit; font-size: 14px; line-height: 1; }
.placeholder { margin: auto; color: var(--muted); text-align: center; }
.placeholder svg { width: 64px; height: 64px; stroke-width: 1.2; opacity: .5; }

/* pages */
.page { flex: 1; overflow-y: auto; padding: 20px 24px calc(80px + var(--safe-b)); }
.page h2 { margin: 0 0 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.card { background: var(--panel); border-radius: var(--r); padding: 16px; margin-bottom: 14px; border: 1px solid var(--line); }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.t th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 9px 8px; border-bottom: 1px solid #f1f3f7; vertical-align: middle; }
.twrap { overflow-x: auto; }
.al { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid #f1f3f7; align-items: flex-start; }
.al .lv { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--warn); }
.al .lv.high { background: var(--danger); }
.al .bd { flex: 1; min-width: 0; } .al .bd b { margin-right: 6px; } .al .bd p { margin: 4px 0 0; color: var(--muted); font-size: 13px; word-break: break-word; }
.al.done { opacity: .55; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; } .kpi b { font-size: 24px; display: block; } .kpi span { color: var(--muted); font-size: 12.5px; }

/* modal + toast + lightbox */
.modal-bg { position: fixed; inset: 0; background: rgba(15,25,45,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 16px; width: min(460px, 100%); max-height: 90dvh; overflow-y: auto; padding: 20px; }
.modal h3 { margin: 0 0 6px; }
.modal .acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.pick { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; cursor: pointer; }
.pick:hover { background: var(--bg); }
#toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); background: #1d2433; color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; max-width: 90vw; }
#toast.on { opacity: 1; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; z-index: 70; }
.lightbox img { max-width: 94vw; max-height: 92dvh; }
.conn { position: fixed; top: calc(8px + var(--safe-t)); left: 50%; transform: translateX(-50%); background: var(--warn); color: #fff; padding: 6px 14px; border-radius: 16px; font-size: 13px; z-index: 40; }
#watermark { position: fixed; inset: 0; pointer-events: none; z-index: 30; opacity: .06; background-repeat: repeat; }
.qr { width: 240px; height: 240px; display: block; margin: 12px auto; image-rendering: pixelated; }

/* mobile */
.tabbar { display: none; }
@media (max-width: 900px) {
  :root { --list: 100%; }
  .rail { display: none; }
  #app { flex-direction: column; }
  .shell { flex: 1; display: flex; min-height: 0; position: relative; }
  .list { width: 100%; border: 0; }
  .main { position: absolute; inset: 0; z-index: 5; }
  .shell:not(.in-chat) .main.chatmain { display: none; }
  .shell.in-chat .list { display: none; }
  .info { position: fixed; inset: 0; width: 100%; z-index: 20; padding-top: calc(16px + var(--safe-t)); }
  .chat-h { height: calc(56px + var(--safe-t)); padding-top: var(--safe-t); padding-left: 4px; }
  .chat-h .acts .wide { display: none; }
  .msgs { padding: 10px 10px 6px; }
  .m .bub { max-width: 86%; }
  .tabbar { display: flex; background: #fff; border-top: 1px solid var(--line); padding-bottom: var(--safe-b); flex: none; }
  .tabbar button { flex: 1; height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); position: relative; }
  .tabbar button.on { color: var(--brand); }
  .tabbar .badge { position: absolute; top: 5px; left: calc(50% + 6px); }
  .shell.in-chat ~ .tabbar { display: none; }
  .list-h { padding-top: calc(12px + var(--safe-t)); }
  .page { padding: calc(16px + var(--safe-t)) 14px calc(24px + var(--safe-b)); }
  .m .tools { display: none !important; }
}
@media (min-width: 901px) { .shell { flex: 1; display: flex; min-width: 0; } .back-btn { display: none; } }
@media (min-width: 901px) and (max-width: 1250px) { .info { position: fixed; right: 0; top: 0; bottom: 0; z-index: 20; box-shadow: -8px 0 30px rgba(0,0,0,.12); } }

/* on-duty / resting switch */
.duty{display:inline-flex;align-items:center;gap:6px;border:1px solid var(--line,#d9dde5);background:var(--panel,#fff);color:var(--muted,#6b7280);border-radius:999px;padding:6px 12px;font-size:13px;font-weight:600;cursor:pointer;white-space:nowrap}
.duty.on-duty{background:#16a34a;border-color:#16a34a;color:#fff}
.duty .dot{width:8px;height:8px;border-radius:50%;background:#9ca3af;display:inline-block}
.duty.on-duty .dot{background:#fff}
.duty.sm{padding:3px 10px;font-size:12px;margin-left:8px;vertical-align:middle}
.rail .duty{margin:8px 6px;padding:6px 4px;font-size:11px;justify-content:center;flex-direction:column;gap:3px;border-radius:10px}
.sound-hint{cursor:pointer;background:#f59e0b !important}
.rail button.duty.on-duty{background:#16a34a;border-color:#16a34a;color:#fff}
.rail button.duty{color:#cbd5e1;background:transparent;border:1px solid rgba(255,255,255,.25)}
.ringbar{position:fixed;left:50%;transform:translateX(-50%);top:calc(44px + var(--safe-t));z-index:41;background:#dc2626;color:#fff;font-weight:700;font-size:15px;padding:10px 22px;border-radius:22px;cursor:pointer;box-shadow:0 6px 24px rgba(220,38,38,.55);animation:ringbar 1s infinite}
@keyframes ringbar{0%,100%{background:#dc2626}50%{background:#f59e0b}}
/* 2026-11-24 transfer reminder */
.handtag{color:#dc2626;font-weight:700}
.pick .tst{margin-left:auto;font-size:12px;padding:2px 8px;border-radius:10px;background:rgba(22,163,74,.14);color:#16a34a;white-space:nowrap}
.pick .tst.s1{background:rgba(217,119,6,.14);color:#d97706}
.pick .tst.s2{background:rgba(120,120,120,.16);color:#888}
.pick.away{opacity:.72}
