/* Board Next — làm lại theo unslop (github.com/heydamir/unslop, CC BY 4.0, Damir Sokolovsky).
   Hướng: xưởng giao việc cho agent. Khung im lặng (xám trung tính), màu nằm ở ảnh sản phẩm trên thẻ.
   Một màu nhấn cam đất cho nút chính + lựa chọn. Dấu riêng: chấm xanh «đang làm» — chỉ chỗ nào agent đang chạy thật. */
:root {
  --bg: #fafafa; --panel: #ffffff; --raised: #f4f4f5; --colbg: #f1f1f2; --deep: #ffffff;
  --line: rgba(23, 23, 23, .08); --line2: rgba(23, 23, 23, .14);
  --text: #171717; --sec: #525252; --muted: #6b6b70;
  --accent: #c2410c; --accent-hover: #a8380a; --accent-ink: #c2410c; --accentbg: #fff1e8; --on-accent: #ffffff;
  --primary: var(--accent); --primary-hover: var(--accent-hover); --on-primary: #ffffff;
  --green: #166534; --greenbg: #ecf7f0; --amber: #a35a00; --amberbg: #fdf4e4; --red: #c42a2a; --redbg: #fdeeee; --live: #16a34a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05);
  --shadow2: 0 8px 24px rgba(0, 0, 0, .08);
  --ease: cubic-bezier(.22, 1, .36, 1);
  color-scheme: light;
}
:root.dark {
    --bg: #141415; --panel: #19191b; --raised: #232325; --colbg: #19191b; --deep: #0f0f10;
    --line: rgba(237, 237, 237, .08); --line2: rgba(237, 237, 237, .14);
    --text: #ededed; --sec: #a1a1a6; --muted: #8b8b91;
    --accent: #fb923c; --accent-hover: #fdba74; --accent-ink: #fb923c; --accentbg: #2a1d14; --on-accent: #141415;
    --primary: #ededed; --primary-hover: #ffffff; --on-primary: #141415;
    --green: #4cc38a; --greenbg: #16271f; --amber: #e6a23c; --amberbg: #2a2215; --red: #f0777b; --redbg: #2e1819; --live: #4cc38a;
    --shadow: none; --shadow2: 0 16px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/20px "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
b, strong { font-weight: 600; }
a { color: var(--accent-ink); text-decoration: none; } a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-variant-numeric: tabular-nums; }
code { font-size: 12px; background: var(--raised); border-radius: 4px; padding: 0 4px; }
svg.i { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
input, textarea, select { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line2); border-radius: 8px; padding: 8px 12px; width: 100%; outline: none; transition: border-color .15s var(--ease); }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--muted); }
textarea { resize: vertical; min-height: 72px; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
label.f { display: block; margin: 12px 0; }
label.f > span { display: block; font-size: 13px; color: var(--sec); margin-bottom: 4px; }

.btn { display: inline-flex; align-items: center; gap: 8px; height: 32px; border: 1px solid var(--line2); background: var(--panel); border-radius: 8px; padding: 0 12px; font-weight: 500; white-space: nowrap; transition: background-color .15s var(--ease), border-color .15s var(--ease); }
.btn svg.i { color: var(--muted); }
.btn:hover { background: var(--raised); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary svg.i { color: inherit; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { color: var(--red); }
.btn.on { background: var(--raised); border-color: var(--line2); }
.btn:disabled { opacity: .5; cursor: default; }
.icon { display: inline-flex; align-items: center; gap: 8px; height: 32px; border: 0; background: transparent; padding: 0 8px; border-radius: 8px; color: var(--sec); transition: background-color .15s var(--ease), color .15s var(--ease); }
.icon[hidden] { display: none; }
.icon:hover { background: var(--raised); color: var(--text); }
.icon:disabled { opacity: .4; cursor: default; }

header.top { display: flex; align-items: center; gap: 4px; height: 56px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--deep); position: sticky; top: 0; z-index: 5; }
header.top h1 { font-size: 15px; font-weight: 500; margin: 0 0 0 4px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo { display: inline-flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 600; }
.logo::before { content: ''; width: 12px; height: 12px; border-radius: 3px; background: var(--accent); }
/* Cài thành app (viewport-fit=cover): chừa tai thỏ / mép bo khi xoay ngang, vạch home ở đáy. */
body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); box-sizing: border-box; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 32px 24px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* Trạng thái: chữ lặng + chấm, không viên thuốc màu. Chấm nhịp chỉ khi agent đang chạy thật. */
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; line-height: 16px; white-space: nowrap; color: var(--sec); }
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.st-idle { color: var(--muted); }
.st-queued { color: var(--amber); }
.st-running { color: var(--green); }
.st-running::before { background: var(--live); box-shadow: 0 0 0 3px var(--greenbg); animation: live 1.6s var(--ease) infinite; }
.st-error { color: var(--red); }
@keyframes live { 50% { opacity: .35; } }
/* Nhãn: nền trung tính + chấm màu của nhãn; chữ màu chính → đọc rõ ở cả hai nền. */
.lb { display: inline-flex; align-items: center; gap: 6px; height: 20px; padding: 0 8px; border-radius: 4px; background: var(--raised); color: var(--text); font-size: 12px; white-space: nowrap; }
.lb::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--lc, var(--muted)); }
.list > * + * { margin-top: 12px; }
.err { background: var(--redbg); color: var(--red); border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.ok { background: var(--greenbg); color: var(--green); border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.ava { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; color: #fff; font-size: 10px; font-weight: 500; flex-shrink: 0; box-shadow: 0 0 0 2px var(--panel); }
.avas { display: inline-flex; } .avas .ava + .ava { margin-left: -6px; }

/* Đăng nhập */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.login .card { width: 100%; max-width: 400px; padding: 32px; box-shadow: var(--shadow2); }
.login h2 { margin: 24px 0 4px; font-size: 24px; line-height: 32px; font-weight: 500; }

/* Danh sách board */
.pagehead { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.pagehead h2 { margin: 0; font-size: 28px; line-height: 32px; font-weight: 500; flex: 1; }
.boardgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.btile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; box-shadow: var(--shadow); transition: border-color .15s var(--ease); }
.btile:hover { border-color: var(--line2); }
.btile:hover .bname { color: var(--accent-ink); }
.covers { display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: 104px; gap: 2px; height: 104px; overflow: hidden; background: var(--raised); }
.covers img { width: 100%; height: 104px; min-width: 0; object-fit: contain; display: block; background: var(--deep); }
.covers.n1 { grid-template-columns: 1fr; } .covers.n2 { grid-template-columns: 1fr 1fr; } .covers.n3 { grid-template-columns: 1fr 1fr 1fr; }
.btile .body { padding: 16px 20px 20px; }
.bname { font-size: 15px; font-weight: 500; margin-bottom: 8px; transition: color .15s var(--ease); }
.stat { display: flex; gap: 16px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.stat b { font-weight: 500; color: var(--text); font-variant-numeric: tabular-nums; margin-right: 4px; }

/* Board */
.boardpage { display: flex; height: calc(100vh - 56px); }
/* Trang board không cuộn dọc: chỉ cột cuộn bên trong, bảng cuộn ngang. */
.boardmain { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; padding: 16px 24px 0; }
.chatside { width: 360px; flex-shrink: 0; border-left: 1px solid var(--line); display: flex; flex-direction: column; background: var(--deep); }
.boardpage.nochat .chatside, .boardpage.nochat .chatgrip { display: none; }
.chatgrip { width: 6px; margin-right: -6px; position: relative; z-index: 2; cursor: col-resize; flex-shrink: 0; background: transparent; transition: background-color .15s; }
.chatgrip:hover, .chatgrip.on { background: var(--accent, #c2410c); opacity: .6; }
.chatside .pastebox { padding: 8px 12px 0; }
.composer .attbtn { width: 44px; padding: 0; flex-shrink: 0; justify-content: center; }
@media (max-width: 900px) { .boardpage { display: block; height: auto; } .boardmain { padding: 16px 16px 0; height: calc(100vh - 56px); } .chatside { width: auto !important; border-left: 0; border-top: 1px solid var(--line); height: 70vh; } .chatgrip { display: none; } }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
/* Dòng thông tin: một dòng, thiếu chỗ thì cắt … hoặc xuống hàng — không bị bóp thành cột hẹp. Nhóm nút luôn dính nhau, dồn phải. */
.toolbar .info { flex: 1 1 220px; min-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar .tbr { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-left: auto; }
.seg { display: inline-flex; background: var(--raised); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; height: 28px; padding: 0 12px; border-radius: 6px; color: var(--sec); font-weight: 500; transition: background-color .15s var(--ease), color .15s var(--ease); }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 0 0 1px var(--line2); }
.kanban { flex: 1; min-height: 0; display: flex; gap: 12px; align-items: flex-start; overflow-x: auto; overflow-y: hidden; padding-bottom: 12px; }
.kanban.dragging { cursor: grabbing; user-select: none; }
.kanban.dragging .tcard { pointer-events: none; }
.listview { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: 12px; }
.kanban, .colbody, .listview, .log, .tasklog { scrollbar-width: thin; scrollbar-color: var(--line2) transparent; }
.col { width: 288px; flex-shrink: 0; background: var(--colbg); border-radius: 12px; display: flex; flex-direction: column; max-height: 100%; }
.col.over { box-shadow: inset 0 0 0 2px var(--accent); }
.col { border: 1px solid color-mix(in srgb, var(--cc) 45%, transparent); border-top: 3px solid var(--cc); }
.colhead { padding: 12px 12px 8px; }
.colhead b { font-size: 14px; font-weight: 500; display: inline-flex; align-items: center; gap: 8px; }
.colhead b::before { content: ''; width: 8px; height: 8px; border-radius: 2px; background: var(--cc, var(--muted)); flex-shrink: 0; }
.colhead .small { display: flex; align-items: center; gap: 4px; margin-top: 2px; padding-left: 16px; }
.colhead .small svg.i { width: 14px; height: 14px; }
.colhead .coladd { width: 26px; height: 26px; padding: 0; justify-content: center; margin: -4px -6px -4px 2px; }
.count { color: var(--muted); font-size: 12px; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-variant-numeric: tabular-nums; }
.colbody { padding: 0 8px 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.listview .col { width: auto; max-height: none; margin-bottom: 12px; }
.tcard { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 10px; cursor: pointer; box-shadow: var(--shadow); transition: border-color .15s var(--ease); overflow: hidden; flex-shrink: 0; }
.dark .tcard { background: var(--raised); } .dark .col .lb { background: #2e2e31; }
.tcard:hover { border-color: var(--line2); }
.tcard:hover .ttl { color: var(--accent-ink); }
.tcard .ttl { font-size: 14px; line-height: 20px; word-break: break-word; transition: color .15s var(--ease); }
.tcard .lbls { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.tcard .foot { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.tcard .foot:not(:has(.chip, .small, .ava)) { display: none; }
.tcard .foot:empty { display: none; }
.tcard .foot .small { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-variant-numeric: tabular-nums; }
.tcard .foot svg.i { width: 14px; height: 14px; }
.coverbox { position: relative; height: 220px; overflow: hidden; margin: -8px -12px 8px; background: var(--deep); border-bottom: 1px solid var(--line); }
/* Ảnh luôn đứng (không xoay), nằm trọn trong khung cố định: không cắt, không kéo méo. */
.coverbox img.cover { width: 100%; height: 100%; object-fit: contain; display: block; }
.who { color: var(--accent-ink); font-size: 12px; font-weight: 500; }
.more { display: flex; align-items: center; gap: 8px; height: 32px; border: 0; background: transparent; border-radius: 8px; padding: 0 8px; color: var(--sec); width: 100%; text-align: left; transition: background-color .15s var(--ease), color .15s var(--ease); }
.more svg.i { color: var(--muted); }
.more:hover { background: var(--raised); color: var(--text); }
.dark .more:hover { background: #232325; }

/* Chat + log */
.chathead { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chathead b { font-size: 14px; font-weight: 500; margin-right: 8px; }
.chathead .small { margin-top: 2px; }
.log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.bubble { max-width: 92%; border-radius: 12px; padding: 8px 12px; border: 1px solid var(--line); background: var(--panel); white-space: pre-wrap; word-break: break-word; }
.bubble.me { align-self: flex-end; background: var(--raised); border-color: transparent; }
.bubble.sys { background: transparent; border: 0; color: var(--muted); font-size: 12px; padding: 0 4px; align-self: center; text-align: center; }
.bubble .by { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.bubble img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; margin: 4px 4px 0 0; cursor: zoom-in; }
.bubble pre { background: var(--raised); border-radius: 6px; padding: 8px; overflow-x: auto; }
.composer { border-top: 1px solid var(--line); padding: 12px 12px max(12px, env(safe-area-inset-bottom)); display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 160px; }
.composer .btn { height: 44px; }

/* Modal */
#modal:empty { display: none; }
.overlay { position: fixed; inset: 0; background: rgba(10, 10, 12, .5); z-index: 20; display: flex; align-items: flex-start; justify-content: center; padding: 48px 12px; overflow-y: auto; animation: fade .2s var(--ease); }
.dialog { width: 100%; max-width: 760px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow2); animation: rise .3s var(--ease); }
@keyframes fade { from { opacity: 0; } } @keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.dialog > .dh { display: flex; align-items: center; gap: 8px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dialog > .dh h2 { font-size: 16px; line-height: 24px; font-weight: 500; margin: 0; flex: 1; min-width: 0; }
.dialog > .db { padding: 16px 20px 20px; }
.taskgrid { display: grid; grid-template-columns: 1fr; gap: 16px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.thumbs img { width: 92px; height: 92px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; background: var(--raised); }
.tasklog { max-height: 46vh; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.sect { border-top: 1px solid var(--line); padding: 16px 0 4px; margin: 16px 0 0; }
.sect:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.sect > h3 { margin: 0 0 8px; font-size: 14px; font-weight: 500; }
.groupedit { background: var(--raised); border-radius: 10px; padding: 12px; margin-bottom: 8px; }
#viewer { position: fixed; inset: 0; background: rgba(8, 8, 10, .96); z-index: 40; display: flex; align-items: center; justify-content: center; }
#viewer[hidden] { display: none; }
#viewer img { max-width: 96vw; max-height: 92vh; }
table.users { width: 100%; border-collapse: collapse; }
table.users td, table.users th { padding: 12px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.users th { font-size: 12px; color: var(--muted); font-weight: 500; }
table.users tr:hover td { background: var(--raised); }
.pwbox { background: var(--greenbg); color: var(--text); border-radius: 8px; padding: 12px; margin: 8px 0; }
.pwbox code { font-size: 15px; user-select: all; background: var(--panel); }
.agentrow { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.agentrow:last-child { border-bottom: 0; }
@media (max-width: 600px) { .agentrow { flex-wrap: wrap; } .agentrow > .grow { flex: 1 1 calc(100% - 24px); min-width: 0; } .connrow { flex-direction: column; align-items: stretch !important; } .connrow .btn { align-self: stretch !important; justify-content: center; } }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.on { background: var(--live); } .dot.off { background: var(--red); }
.howto { background: var(--raised); color: var(--text); border-radius: 12px; padding: 16px 20px; }
.howto ol { margin: 8px 0 0 20px; padding: 0; }
.manual summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.manual[open] summary { margin-bottom: 8px; }
.desc { background: var(--raised); border-radius: 10px; padding: 12px; white-space: pre-wrap; word-break: break-word; font-size: 14px; margin-top: 8px; max-height: 260px; overflow-y: auto; }
@media (max-width: 600px) {
  header.top { gap: 0; padding: 0 8px; } header.top .lbl { display: none; } header.top .icon svg.i { width: 18px; height: 18px; }
  .wrap { padding: 20px 16px; } .pagehead h2 { font-size: 22px; } .toolbar .info { display: none; } .toolbar .btn .lbl { display: none; }
  .dialog > .dh, .dialog > .db { padding-left: 16px; padding-right: 16px; } .overlay { padding: 12px 8px; }
}

/* Popup cả group */
.colhead { cursor: pointer; border-radius: 12px 12px 0 0; transition: background-color .15s var(--ease); }
.colhead:hover { background: var(--raised); }
.colhead:hover b { color: var(--accent-ink); }
.colgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; align-items: start; }
.dialog > .dh h2 .count { margin-left: 8px; }

/* Bảng */
.tablewrap { flex: 1; min-height: 0; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 16px; scrollbar-width: thin; }
table.tasktable { width: 100%; border-collapse: collapse; font-size: 13px; }
.tasktable th { position: sticky; top: 0; z-index: 1; background: var(--panel); text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line2); white-space: nowrap; cursor: pointer; user-select: none; }
.tasktable th:hover, .tasktable th.on { color: var(--text); }
.tasktable td { padding: 6px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tasktable tbody tr { cursor: pointer; transition: background-color .15s var(--ease); }
.tasktable tbody tr:hover td { background: var(--raised); }
.tasktable tbody tr:hover .tname { color: var(--accent-ink); }
.tasktable .tthumb { width: 64px; padding-right: 0; }
.tasktable .tthumb img { width: 36px; height: 48px; object-fit: contain; border-radius: 4px; display: block; background: var(--raised); }
.tasktable .tname { min-width: 220px; }
.tasktable .lbls { display: flex; gap: 4px; flex-wrap: wrap; }
.tasktable td .ava + .ava { margin-left: -6px; }

/* Canvas */
.canvas { position: relative; flex: 1; min-height: 0; overflow: hidden; margin-bottom: 16px; border: 1px solid var(--line); border-radius: 12px; cursor: grab;
  background-color: var(--bg); background-image: radial-gradient(var(--line2) 1px, transparent 1px); background-size: 24px 24px; }
.canvas.dragging { cursor: grabbing; }
.plane { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.cvcol { position: absolute; width: 248px; display: flex; align-items: center; gap: 8px; font-size: 15px; white-space: nowrap; }
.cvcol b { font-weight: 500; display: inline-flex; align-items: center; gap: 8px; }
.cvcol b::before { content: ''; width: 10px; height: 10px; border-radius: 3px; background: var(--cc); }
.cvcard { position: absolute; width: 248px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); cursor: pointer; user-select: none; }
.dark .cvcard { background: var(--raised); }
.cvcard:hover { border-color: var(--line2); }
.cvcard.lift { box-shadow: var(--shadow2); z-index: 2; cursor: grabbing; }
.cvcard .coverbox { margin: 0; height: 180px; pointer-events: none; }
.cvcard .ttl { padding: 8px 12px; font-size: 14px; line-height: 20px; }
.cvhint { position: absolute; left: 12px; bottom: 12px; display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 0 4px 0 12px; height: 36px; }

/* Ảnh trong popup task */
.thumbs .tb { width: 150px; height: 200px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--deep); cursor: zoom-in; position: relative; }
.thumbs .tb img { width: 100%; height: 100%; object-fit: contain; display: block; }

/* Xem ảnh phóng to */
#viewer { overflow: hidden; cursor: zoom-out; user-select: none; }
#viewer img { transform-origin: center; transition: transform .12s var(--ease); cursor: zoom-in; }
#viewer.zoomed, #viewer.zoomed img { cursor: grab; }
#viewer.zoomed:active img { cursor: grabbing; transition: none; }
.vhint { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); color: #d4d4d8; background: rgba(0, 0, 0, .6); border-radius: 8px; padding: 6px 12px; font-size: 12px; pointer-events: none; white-space: nowrap; }
.vclose { position: absolute; right: 16px; top: 16px; color: #ededed; background: rgba(0, 0, 0, .5); }
.vclose:hover { background: rgba(255, 255, 255, .15); color: #fff; }
@media (max-width: 600px) { .vhint { display: none; } .toolbar .seg button { padding: 0 8px; } }

/* Màn che kín trang (cài đặt, popup group) */
.overlay:has(.dialog.page) { padding: 16px; }
.dialog.page { max-width: none; height: calc(100vh - 32px); display: flex; flex-direction: column; }
.dialog.page > .db { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0; }
.dialog > .dh h2 .sw, .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--cc, var(--muted)); flex-shrink: 0; margin-right: 8px; vertical-align: 1px; }
.settings { flex: 1; min-height: 0; display: flex; }
.stabs { width: 200px; flex-shrink: 0; border-right: 1px solid var(--line); padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.stabs button { text-align: left; border: 0; background: transparent; height: 36px; padding: 0 12px; border-radius: 8px; color: var(--sec); transition: background-color .15s var(--ease), color .15s var(--ease); }
.stabs button:hover { background: var(--raised); color: var(--text); }
.stabs button.on { background: var(--raised); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.spanes { flex: 1; min-width: 0; overflow-y: auto; padding: 20px 32px 32px; }
.spanes > section { max-width: 960px; }
.spanes section[data-pane="info"] > label.small { display: block; margin-top: 12px; line-height: 20px; }
.spanes h3 { font-size: 20px; line-height: 28px; font-weight: 500; margin: 0 0 12px; }
.bigrule { min-height: calc(100vh - 300px); font: 13px/20px ui-monospace, "Cascadia Mono", Consolas, monospace; margin-top: 12px; }
.labelrow { margin-bottom: 8px; }
.swwrap { position: relative; flex-shrink: 0; }
.swpick { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px 0 8px; border-radius: 8px; border: 1px solid var(--line2); background: var(--panel); color: var(--text); font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; min-width: 140px; }
.swpick:hover { border-color: var(--muted); }
.swpop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; background: var(--panel); border: 1px solid var(--line2); border-radius: 10px; padding: 10px; box-shadow: 0 12px 32px rgba(0, 0, 0, .35); }
.swpop.up { top: auto; bottom: calc(100% + 6px); }
.swgrid { display: grid; grid-template-columns: repeat(8, 24px); gap: 6px; }
.swmore { display: flex; gap: 6px; margin-top: 10px; } .swmore .btn { flex: 1; justify-content: center; gap: 6px; height: 30px; font-size: 12px; cursor: pointer; }
.swmore input[type=color] { width: 18px; height: 18px; padding: 0; border: 0; border-radius: 4px; background: none; cursor: pointer; }
.swc { display: inline-block; width: 24px; height: 24px; padding: 0; border-radius: 50%; border: 0; background: var(--sc); cursor: pointer; flex-shrink: 0; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .25); transition: transform .1s var(--ease); }
.swpick .swc, .swmore .swc { width: 18px; height: 18px; }
.swgrid .swc:hover { transform: scale(1.15); }
.swc.on { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--text); }
.swc.auto { background: transparent; border: 2px dashed var(--sc); }
.ggrip { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 32px; color: var(--muted); cursor: grab; touch-action: none; flex-shrink: 0; border-radius: 6px; }
.ggrip:hover { color: var(--text); background: var(--line); } .ggrip svg { width: 18px; height: 18px; fill: currentColor; }
.groupedit.dragging { opacity: .5; }
.groupedit.insb { box-shadow: 0 -4px 0 0 var(--accent); } .groupedit.insa { box-shadow: 0 4px 0 0 var(--accent); }
.groupedit .row { margin-bottom: 8px; } .groupedit textarea, .groupedit input[data-gg] { margin-bottom: 8px; }
.groupedit { border: 1px solid color-mix(in srgb, var(--cc) 55%, transparent); border-left: 4px solid var(--cc); background: color-mix(in srgb, var(--cc) 6%, var(--raised)); }
.danger-zone { margin-top: 32px; border: 1px solid var(--line2); border-radius: 12px; padding: 16px; display: grid; gap: 8px; justify-items: start; }
.undozone { margin-top: 8px; border: 1px solid var(--line2); border-radius: 12px; padding: 12px 16px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.undozone > div { flex-basis: 100%; }
.savebar { display: flex; align-items: center; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); }
.savebar .err { margin: 0; }
@media (max-width: 700px) { .settings { flex-direction: column; } .stabs { width: auto; flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); } .stabs button { white-space: nowrap; } .spanes { padding: 16px; } }

/* Danh sách: group thu gọn, mỗi group một màu */
.listview { display: flex; flex-direction: column; gap: 8px; }
.lgroup { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--cc); border-radius: 10px; overflow: hidden; flex-shrink: 0; }
.lgroup.over { box-shadow: inset 0 0 0 2px var(--accent); }
.lhead { display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 8px 0 12px; cursor: pointer; background: color-mix(in srgb, var(--cc) 7%, var(--panel)); user-select: none; transition: background-color .15s var(--ease); }
.lhead:hover { background: color-mix(in srgb, var(--cc) 13%, var(--panel)); }
.lhead > svg.i { color: var(--muted); }
.lhead .sw { margin-right: 0; }
.lhead b { font-weight: 500; }
.lhead .lagents { margin-left: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lrows { border-top: 1px solid var(--line); }
.lrow { display: grid; grid-template-columns: 40px minmax(160px, 1fr) auto 112px 64px 96px; align-items: center; gap: 12px; padding: 6px 12px; border-bottom: 1px solid var(--line); cursor: pointer; transition: background-color .15s var(--ease); }
.lrow:last-child { border-bottom: 0; }
.lrow:hover { background: var(--raised); }
.lrow:hover .lttl { color: var(--accent-ink); }
.lthumb { width: 40px; height: 40px; border-radius: 6px; overflow: hidden; background: var(--raised); }
.lthumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.lttl { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transition: color .15s var(--ease); }
.lrow .lbls { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.lrow .avas { justify-content: flex-end; }
.ltime { text-align: right; }
.lrows .more { margin: 4px 8px 8px; width: auto; }
@media (max-width: 700px) { .lrow { grid-template-columns: 40px 1fr auto; } .lrow .lbls, .lrow .ltime, .lrow .lstate { display: none; } .lhead .lagents { display: none; } }

/* Canvas: khung group */
.cvframe { position: absolute; background: var(--colbg); border: 1px solid var(--line2); border-top: 3px solid var(--cc); border-radius: 12px; }
.dark .cvframe { background: #1b1b1d; }
.cvframe.over { box-shadow: 0 0 0 2px var(--accent); }
.cvhead { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 12px; cursor: grab; user-select: none; border-radius: 12px 12px 0 0; font-size: 15px; }
.cvhead:hover { background: color-mix(in srgb, var(--cc) 10%, transparent); }
.cvhead .sw { margin-right: 0; } .cvhead b { font-weight: 500; white-space: nowrap; }
.cvhead .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%; }
.canvas.dragging .cvhead { cursor: grabbing; }
.cvgrid { display: grid; grid-template-columns: repeat(auto-fill, 176px); gap: 12px; padding: 0 12px 12px; align-items: start; }
.cvframe > .more { margin: 0 12px 12px; width: calc(100% - 24px); }
.cvresize { position: absolute; right: -4px; top: 44px; bottom: 12px; width: 8px; cursor: ew-resize; border-radius: 4px; }
.cvresize:hover { background: var(--accent); opacity: .5; }
.cvcard { position: relative; width: 176px; }
.cvcard.lift { z-index: 5; box-shadow: var(--shadow2); opacity: .92; }
.cvcard .coverbox { height: 160px; }
.cvfoot { display: flex; align-items: center; gap: 8px; padding: 0 12px 8px; }
.cvbar { position: absolute; left: 12px; bottom: 12px; display: flex; align-items: center; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 0 4px 0 12px; height: 36px; max-width: calc(100% - 24px); }
.cvbar .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.canvas.pop { margin: 0; border: 0; border-radius: 0 0 16px 16px; }

/* Popup group: canvas tự do */
.cvcard.free { position: absolute; }
.cvcard.free.lift { z-index: 5; }
/* Canvas mượt hơn: tách lớp vẽ, khung ngoài màn hình không vẽ lại */
.plane { will-change: transform; }
.cvframe, .cvcard { contain: layout paint; }
.canvas.dragging .cvcard.lift { pointer-events: none; }
/* Danh sách: task không ảnh thì bỏ ô ảnh */
.lthumb.none { background: transparent; }

/* Chọn nhiều thẻ trên canvas */
.marquee { position: absolute; z-index: 6; pointer-events: none; border: 1px solid var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 4px; }
.cvcard.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
/* Board/Danh sách: chỗ thả thẻ, đổi chỗ group */
.colhead { cursor: grab; }
.col.insl { box-shadow: -5px 0 0 0 var(--accent); }
.col.insr { box-shadow: 5px 0 0 0 var(--accent); }

/* Chỗ thả thẻ: ô trống viền đứt cao bằng thẻ đang kéo */
.dropph { flex-shrink: 0; border: 2px dashed var(--accent); border-radius: 10px; background: color-mix(in srgb, var(--accent) 10%, transparent); }
.dropph.row { border-radius: 6px; margin: 2px 8px; }
.cvph { width: 176px; border: 2px dashed var(--accent); border-radius: 10px; background: color-mix(in srgb, var(--accent) 10%, transparent); }
.dragsrc { display: none !important; }
/* Công tắc board */
.runseg button { display: inline-flex; align-items: center; gap: 6px; }
.runseg button:disabled { cursor: not-allowed; }
.runseg .rdot { width: 8px; height: 8px; border-radius: 50%; background: var(--line2); }
.runseg button[data-run=run].on .rdot { background: #16a34a; }
.runseg button[data-run=noassign].on .rdot { background: #d97706; }
.runseg button[data-run=pause].on .rdot { background: #dc2626; }
.runseg.st-noassign button.on { box-shadow: 0 0 0 1px #d97706; }
.runseg.st-pause button.on { box-shadow: 0 0 0 1px #dc2626; }
/* Chat riêng với agent */
.achat { display: flex; flex-direction: column; gap: 12px; height: calc(100vh - 56px); padding-bottom: 16px; }
.achatlog { flex: 1; min-height: 200px; border: 1px solid var(--line); border-radius: 12px; background: var(--deep); }
.achat .composer { border: 1px solid var(--line); border-radius: 12px; }
/* Ảnh dán/kéo vào ô chat, chờ gửi */
.pastebox { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 0 4px; }
.pastebox[hidden] { display: none; }
.pastebox .pb { position: relative; width: 72px; height: 72px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--deep); }
.pastebox .pb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.pastebox .pb button { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; min-height: 0; padding: 0; border-radius: 6px; background: rgba(0, 0, 0, .65); color: #fff; }
.composer textarea.drop { outline: 2px dashed var(--accent, #c2410c); outline-offset: 2px; }
/* Ảnh trong tin chat: đứng nguyên trong khung, không cắt */
.bubble img { width: auto; height: auto; max-width: 220px; max-height: 160px; object-fit: contain; background: var(--deep); }

/* Popup group ở dạng Board/Danh sách/Bảng: lưới cứng theo thứ tự group, cuộn dọc */
.ggrid { flex: 1; min-height: 0; overflow: auto; padding: 16px; }
.ggrid .cvgrid { padding: 0; grid-template-columns: repeat(auto-fill, 176px); }
.ggrid.dragging, .ggrid.dragging .cvcard { cursor: grabbing; }
.ggrid.dragging .cvcard.lift { pointer-events: none; }
.ggbar { padding: 8px 16px; border-top: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip.sandbox { background: color-mix(in srgb, #d4a017 22%, transparent); color: var(--ink, inherit); border: 1px solid #d4a017; margin-right: 6px; font-weight: 600; }

/* Thanh lọc thẻ theo nhãn / agent (board và popup group) */
.filterbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 12px; }
.dialog.page .filterbar { flex-shrink: 0; margin: 0; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.filterbar .fsum { font-size: 13px; color: var(--sec); white-space: nowrap; } .filterbar .fsum b { color: var(--text); font-weight: 600; }
.filterbar .fgrp { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.fchip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 8px 0 4px; border: 1px solid var(--line2); background: var(--panel); border-radius: 14px; color: var(--text); cursor: pointer; transition: background-color .15s var(--ease), border-color .15s var(--ease); }
.fchip:hover { border-color: var(--sec); }
.fchip .lb { background: transparent; padding: 0 4px; }
.fchip .ava { width: 20px; height: 20px; font-size: 9px; box-shadow: none; }
.fchip:not(:has(.lb, .ava)) { padding-left: 10px; }
.fchip.on { border-color: #3b6fd8; background: rgba(59, 111, 216, .14); box-shadow: 0 0 0 1px #3b6fd8 inset; }
.fchip.on .count { color: var(--text); }
.fclear { height: 28px; }
.fsearch { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border: 1px solid var(--line2); background: var(--panel); border-radius: 15px; color: var(--sec); flex: 0 1 300px; min-width: 180px; }
.fsearch:focus-within { border-color: #3b6fd8; box-shadow: 0 0 0 1px #3b6fd8 inset; }
.fsearch input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 13px; padding: 0; }
.fsearch input::placeholder { color: var(--sec); }
.fsearch .i { width: 15px; height: 15px; flex-shrink: 0; }
.hit { margin-top: 4px; color: var(--sec); line-height: 1.35; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; font-weight: 400; }
.hit b { color: var(--text); font-weight: 600; }
@media (max-width: 700px) { .fsearch { flex: 1 1 100%; } }
/* Nút «Lọc»: chỉ hiện trên màn hẹp, gập/mở nhóm nút Nhãn · Agent */
.ftoggle { display: none; height: 28px; gap: 4px; }
.ftoggle .i { width: 15px; height: 15px; }
.ftoggle.on { border-color: #3b6fd8; box-shadow: 0 0 0 1px #3b6fd8 inset; }
.ftoggle .count { color: var(--text); font-weight: 600; }
@media (max-width: 700px) {
  .ftoggle { display: inline-flex; margin-left: auto; }
  .filterbar:not(.open) .fgrp { display: none; }
  .filterbar { gap: 8px 12px; }
  /* Popup group: thẻ giãn kín bề ngang màn, ảnh cao theo tỉ lệ thay vì khung 176px cố định */
  .ggrid { padding: 12px; }
  .ggrid .cvgrid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .ggrid .cvcard { width: auto; }
  .ggrid .cvcard .coverbox { height: auto; aspect-ratio: 3 / 4; }
}
/* Board trên mobile kiểu Trello: phần trên gọn còn 2 dòng (thanh nút cuộn ngang · tìm + Lọc),
   mỗi group gần rộng bằng màn, vuốt ngang thì group tự dừng đúng giữa, hai bên ló mép group kế. */
@media (max-width: 700px) {
  .boardmain { padding: 8px 0 0; }
  .boardmain > .toolbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 8px; margin-bottom: 8px; padding: 0 12px; }
  .boardmain > .toolbar::-webkit-scrollbar { display: none; }
  .boardmain > .toolbar > *, .boardmain > .toolbar .tbr { flex-shrink: 0; flex-wrap: nowrap; }
  .boardmain > .toolbar .info { display: none; }
  .boardmain > .toolbar .seg button { white-space: nowrap; }
  .boardmain > .filterbar { padding: 0 12px; margin-bottom: 8px; flex-wrap: wrap; gap: 8px; }
  .boardmain > .filterbar .fsearch { flex: 1 1 0; min-width: 0; order: 0; }
  .boardmain > .filterbar .ftoggle { margin-left: 0; }
  .kanban { gap: 8px; padding: 0 24px 12px; scroll-snap-type: x mandatory; scroll-padding: 0 24px; overscroll-behavior-x: contain; }
  .kanban .col { width: calc(100vw - 64px); scroll-snap-align: center; scroll-snap-stop: always; }
  .kanban.dragging { scroll-snap-type: none; }
  .listview, .tablewrap, .canvas:not(.pop) { margin-left: 12px; margin-right: 12px; }
}

/* Trao đổi trên task: dòng thời gian người · agent · thao tác (tin chép từ Trello đi chung một dòng) */
.tasklog { max-height: none; height: min(72vh, 900px); min-height: 360px; resize: vertical; }
.tasklog .bubble { max-width: min(860px, 88%); }
.bubble .by { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.bubble .by b { font-weight: 500; color: var(--text); }
.bubble .by .ava { width: 20px; height: 20px; font-size: 9px; }
.bubble .by .at { margin-left: auto; padding-left: 12px; }
.bubble .by .src { font-size: 11px; border: 1px solid var(--line2); border-radius: 6px; padding: 0 6px; color: var(--muted); }
.bubble.human { align-self: flex-end; background: var(--accentbg); border-color: transparent; }
.bubble.agent { align-self: flex-start; }
.bubble.sys.act { color: var(--sec); }
.bubble.sys.act b { font-weight: 500; }
.bubble .tx { white-space: pre-wrap; }
.bubble .bimgs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.bubble .bimgs img { width: auto; height: auto; max-width: min(360px, 100%); max-height: 300px; margin: 0; object-fit: contain; border-radius: 8px; border: 1px solid var(--line); background: var(--deep); cursor: zoom-in; }
.logtg { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.logtg input { width: auto; }
/* Ngăn «Đã cất» */
.archbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.archbar .fsearch { flex: 1; min-width: 200px; }
.cvcard.arch { cursor: pointer; }
.cvcard.arch .ameta { padding: 0 10px 6px; line-height: 18px; }
.cvcard.arch .cvfoot .btn { height: 28px; min-height: 0; padding: 0 10px; font-size: 12px; }
.ggbar .ggarch { margin-left: 12px; height: 28px; min-height: 0; padding: 0 10px; font-size: 12px; }
.ggbar:has(.ggarch) { display: flex; align-items: center; }
@media (max-width: 600px) { .tasklog { height: 62vh; } .tasklog .bubble { max-width: 96%; } .bubble .bimgs img { max-width: 100%; } }

.bubble details.more { margin-top: 4px; color: var(--sec); }
.bubble details.more summary { cursor: pointer; font-size: 12px; }

/* Popup task 2 cột: trái ảnh cuối (ảnh khác gấp lại), phải mô tả + trao đổi */
.taskgrid.two { grid-template-columns: minmax(240px, 360px) minmax(0, 1fr); align-items: start; gap: 16px 20px; }
.taskgrid.two > .thead { grid-column: 1 / -1; }
.taskgrid.two > .tpics { position: sticky; top: 0; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.taskgrid.two > .tmain { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.tpics .final { background: var(--deep); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; cursor: zoom-in; display: flex; justify-content: center; }
.tpics .final img { max-width: 100%; max-height: min(68vh, 760px); object-fit: contain; display: block; }
.tpics .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpics .morepics summary { cursor: pointer; color: var(--sec); padding: 4px 0; }
.tpics .morepics .thumbs .tb { width: 96px; height: 128px; }
.thumbs .tb .tbtag { position: absolute; left: 4px; bottom: 4px; font-size: 10px; padding: 1px 5px; border-radius: 4px; background: rgba(0,0,0,.7); color: #fff; }
.tmain .tasklog { height: min(64vh, 860px); }
.gseg { margin-left: 12px; vertical-align: middle; font-size: 13px; }
.gseg button { height: 26px; padding: 0 10px; display: inline-flex; align-items: center; gap: 4px; }
.gseg .count { margin-left: 2px; }
@media (max-width: 860px) { .taskgrid.two { grid-template-columns: 1fr; } .taskgrid.two > .tpics { position: static; } .tpics .final img { max-height: 46vh; } }

/* Popup task vừa khung màn hình: không cuộn cả popup, chỉ cuộn trong khung trao đổi (và cột ảnh nếu dài) */
.overlay:has(.dialog.fit) { padding: 16px 12px; }
.dialog.fit { height: calc(100vh - 32px); height: calc(100dvh - 32px); display: flex; flex-direction: column; }
.dialog.fit > .dh { flex-shrink: 0; padding-top: 12px; padding-bottom: 12px; }
.dialog.fit > .db { flex: 1; min-height: 0; overflow: hidden; padding-top: 12px; padding-bottom: 14px; }
.dialog.fit .taskgrid.two { height: 100%; grid-template-rows: auto minmax(0, 1fr); gap: 12px 20px; }
.dialog.fit .taskgrid.two > .tpics { position: static; height: 100%; overflow-y: auto; }
.dialog.fit .tpics .final { flex: 1 1 auto; min-height: 0; }
.dialog.fit .tpics .final img { max-height: 100%; }
.dialog.fit .taskgrid.two > .tmain { height: 100%; min-height: 0; gap: 10px; }
.dialog.fit .tmain > div:has(> #tlog) { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.dialog.fit .tmain .tasklog { flex: 1; height: auto; min-height: 160px; resize: none; }
.dialog.fit .tmain .desc { max-height: 22vh; }
@media (max-width: 860px) {
  .dialog.fit { height: auto; } .dialog.fit > .db { overflow: visible; }
  .dialog.fit .taskgrid.two { height: auto; grid-template-rows: none; } .dialog.fit .taskgrid.two > .tpics, .dialog.fit .taskgrid.two > .tmain { height: auto; }
  .dialog.fit .tpics .final img { max-height: 46vh; } .dialog.fit .tmain .tasklog { flex: none; height: 62vh; }
}

/* Chuẩn chạm trên máy cảm ứng (skill chuan-giao-dien-web, bài D2/D3/M2) — kiểm bằng test/uicheck.json */
.desc a, .bubble a { text-decoration: underline; text-underline-offset: 2px; }
@media (pointer: coarse) {
  .btn, .icon, .more { min-height: 40px; } .icon { min-width: 40px; justify-content: center; }
  input:not([type=checkbox]):not([type=radio]), textarea, select { font-size: 16px; min-height: 40px; }
  input[type=checkbox] { width: 24px !important; height: 24px; }
  .seg button, .fchip { height: 36px; } .src { font-size: 12px; }
  summary { min-height: 32px; display: flex; align-items: center; }
  .ava { font-size: 11px; }
}

/* Bảng kết quả của task (lệnh panel) + nút phóng trao đổi / toàn màn hình */
.taskgrid.two.haspanel { grid-template-columns: minmax(360px, 1.1fr) minmax(400px, 1fr); }
.tpics .ltabs { align-self: flex-start; flex-shrink: 0; }
.tpics .lpane { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.dialog.fit .tpics .lpane { flex: 1; }
.tpics .lpane[hidden] { display: none; }
.tpanel { font-size: 14px; line-height: 1.5; color: var(--text); word-break: break-word; display: flex; flex-direction: column; gap: 10px; }
.tpanel > * { margin: 0; }
.tpanel h1, .tpanel h2, .tpanel h3, .tpanel h4 { font-size: 15px; line-height: 22px; font-weight: 600; margin: 4px 0 0; }
.tpanel h1, .tpanel h2 { font-size: 16px; }
.tpanel p { margin: 0; }
.tpanel a { text-decoration: underline; text-underline-offset: 2px; }
.tpanel img { max-width: 100%; height: auto; border-radius: 8px; background: var(--deep); cursor: zoom-in; display: block; }
.tpanel .muted { color: var(--muted); } .tpanel .small { font-size: 12px; }
.tpanel .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tpanel .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.tpanel .grid.big { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.tpanel .card { background: var(--raised); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.tpanel .badge { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 10px; font-size: 12px; background: var(--raised); color: var(--sec); border: 1px solid var(--line2); }
.tpanel .badge.ok { color: var(--green); } .tpanel .badge.warn { color: var(--amber); } .tpanel .badge.bad { color: var(--red); }
.tpanel table { width: 100%; border-collapse: collapse; font-size: 13px; }
.tpanel th, .tpanel td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tpanel th { color: var(--muted); font-weight: 500; font-size: 12px; }
.tpanel details summary { cursor: pointer; color: var(--sec); }
.tpanel pre, .tpanel code { white-space: pre-wrap; }
.pcard { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; cursor: pointer; transition: border-color .15s var(--ease); min-width: 0; }
.pcard:hover { border-color: var(--line2); } .pcard:hover .pttl { color: var(--accent-ink); }
.pcard.gone { cursor: default; padding: 10px; border-style: dashed; }
.pcard .pcov { position: relative; overflow: hidden; min-height: 0; aspect-ratio: 3 / 4; background: var(--deep); display: flex; align-items: center; justify-content: center; cursor: zoom-in; }
.pcard .pcov img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; border-radius: 0; }
.pcard .pttl { font-size: 12px; line-height: 16px; padding: 6px 8px 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pcard .pmeta { display: flex; gap: 8px; align-items: center; padding: 4px 8px 8px; flex-wrap: wrap; }
.pcard .pmeta .chip { font-size: 11px; }
.tvbtn { height: 26px; padding: 0 8px; font-size: 12px; }
.tvbtn.on { background: var(--raised); color: var(--text); }
.taskgrid.chatfocus > .tmain > #fields, .taskgrid.chatfocus > .tmain > #sess, .taskgrid.chatfocus > .tmain > .meta, .taskgrid.chatfocus > .tmain > .desc { display: none; }
.overlay:has(.dialog.fit.max) { padding: 0; }
.dialog.fit.max { max-width: none !important; height: 100vh; height: 100dvh; border-radius: 0; border: 0; }
.dialog.fit.max .taskgrid.two:not(.haspanel) { grid-template-columns: minmax(300px, 34%) minmax(0, 1fr); }
@media (max-width: 860px) {
  .taskgrid.two.haspanel { grid-template-columns: 1fr; }
  .tvbtn[data-tv="max"] { display: none; } .tvbtn span { display: none; }
  .tpanel .grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
}

/* Tab Luật: trang con chỉ hiện tên, bấm mở popup sửa */
.spanes h4.rsub { font-size: 15px; line-height: 22px; font-weight: 600; margin: 20px 0 4px; }
.spanes section[data-pane="rule"] > h3 + h4.rsub { margin-top: 0; }
.pglist { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.pgrow { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 40px; padding: 8px 12px; text-align: left; border: 1px solid var(--line); border-radius: 8px; background: var(--raised); color: var(--text); cursor: pointer; transition: background-color .15s var(--ease), border-color .15s var(--ease); }
.pgrow:hover { border-color: var(--accent); }
.pgrow .small { flex-shrink: 0; }
.overlay.pgover { z-index: 30; padding: 16px; align-items: stretch; }
.pgdlg { max-width: 1100px; display: flex; flex-direction: column; height: calc(100vh - 32px); height: calc(100dvh - 32px); }
.pgdlg > .db { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.pgdlg .pgtext { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.pgdlg .pgtext textarea { flex: 1; min-height: 200px; margin-top: 6px; resize: none; }
@media (max-width: 600px) { .overlay.pgover { padding: 8px; } }


/* Editor markdown (Milkdown Crepe) — màu theo board, cỡ chữ như app */
.mded { border: 1px solid var(--line2); border-radius: 8px; background: var(--panel); overflow: hidden; display: flex; flex-direction: column; margin-top: 6px; }
.mded.big { min-height: calc(100vh - 300px); }
.pgdlg .mded { flex: 1; min-height: 0; }
.mdbar { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-bottom: 1px solid var(--line); }
.mdbar .btn { height: 28px; padding: 0 10px; font-size: 13px; }
.mdbody { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
.mdbody > textarea { flex: 1; border: 0; border-radius: 0; margin: 0; min-height: 160px; font: 13px/20px ui-monospace, "Cascadia Mono", Consolas, monospace; }
.mded.big .mdbody > textarea, .pgdlg .mdbody > textarea { resize: none; }
.mdhost { flex: 1; min-height: 140px; }
.mded .milkdown {
  --crepe-color-background: var(--panel); --crepe-color-on-background: var(--text);
  --crepe-color-surface: var(--panel); --crepe-color-surface-low: var(--raised);
  --crepe-color-on-surface: var(--text); --crepe-color-on-surface-variant: var(--sec);
  --crepe-color-outline: var(--muted); --crepe-color-primary: var(--accent-ink);
  --crepe-color-secondary: var(--raised); --crepe-color-on-secondary: var(--text);
  --crepe-color-inverse: var(--text); --crepe-color-on-inverse: var(--panel);
  --crepe-color-inline-code: var(--accent-ink); --crepe-color-error: var(--red);
  --crepe-color-hover: var(--raised); --crepe-color-selected: var(--accentbg); --crepe-color-inline-area: var(--raised);
  --crepe-base-font-size: 14px;
  --crepe-font-title: inherit; --crepe-font-default: inherit;
  --crepe-font-code: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --crepe-shadow-1: var(--shadow2); --crepe-shadow-2: var(--shadow2);
  height: 100%;
}
.mded .milkdown .ProseMirror { padding: 12px 16px 40px 48px; line-height: 22px; }
.mded .milkdown .ProseMirror h1 { font-size: 20px; line-height: 28px; margin: 16px 0 8px; }
.mded .milkdown .ProseMirror h2 { font-size: 17px; line-height: 24px; margin: 14px 0 6px; }
.mded .milkdown .ProseMirror h3, .mded .milkdown .ProseMirror h4, .mded .milkdown .ProseMirror h5 { font-size: 15px; line-height: 22px; margin: 12px 0 4px; }
.mded .milkdown .ProseMirror p { margin: 4px 0; font-size: 14px; line-height: 22px; }
.mded .milkdown .ProseMirror li p { margin: 2px 0; }
.mded .milkdown .ProseMirror code { font-size: 13px; }
@media (max-width: 600px) { .mded .milkdown .ProseMirror { padding: 10px 10px 40px 36px; } }
/* Danh sách tên khi gõ @ */
.atmenu { position: fixed; z-index: 60; min-width: 180px; max-width: 280px; padding: 4px; border: 1px solid var(--line2); border-radius: 8px; background: var(--panel); box-shadow: var(--shadow2); display: flex; flex-direction: column; }
.atmenu[hidden] { display: none; }
.atmenu button { text-align: left; border: 0; background: none; padding: 8px 10px; min-height: 36px; border-radius: 6px; color: var(--text); }
.atmenu button.on, .atmenu button:hover { background: var(--accentbg); color: var(--accent-ink); }
/* Cài đặt → Agent: mỗi agent một thẻ có viền, đầu thẻ nền khác, phần dặn riêng thụt vào có vạch màu bên trái — nhìn là biết mục nào của ai. */
.aggroup { margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.aggroup:first-child { margin-top: 0; }
.agcard { border: 1px solid var(--line2); border-radius: 10px; background: var(--panel); margin-bottom: 10px; overflow: hidden; }
.agcard.off { opacity: .75; }

.aghead { display: flex; gap: 10px; align-items: center; padding: 10px 12px; background: var(--raised); flex-wrap: wrap; }
.aghead > .grow { min-width: 0; }
.aghead[data-agt] { cursor: pointer; }
.aghead[data-agt]:hover { background: var(--line2); }
.aghead[data-agt]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.agcard:not(.open) .aghead { background: transparent; }
.agcaret { width: 12px; color: var(--sec); font-size: 12px; }
.agcard.chatting { border-color: var(--text); }
.agbody { padding: 8px 12px 4px; }
.agbar { align-items: center; gap: 12px; }
.agbody .crew { margin: 8px 0 12px; }
/* Khung chat với thợ: cột phải, dính khi cuộn; điện thoại thì phủ cả màn. */
.spanes > section[data-pane="agents"]:has(.withchat) { max-width: none; }
.agwrap.withchat { display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 440px); gap: 16px; align-items: start; }
.agchat[hidden] { display: none; }
.agchat { position: sticky; top: 0; height: max(360px, calc(100vh - 280px)); display: flex; flex-direction: column; border: 1px solid var(--line2); border-radius: 10px; background: var(--panel); overflow: hidden; }
.agchead { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 12px; background: var(--raised); border-bottom: 1px solid var(--line); }
.agchint { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.agclog { flex: 1; min-height: 0; padding: 12px; background: var(--deep); }
.agchat .composer textarea { min-height: 44px; max-height: 160px; }
.agcpick { align-self: flex-start; }
@media (max-width: 900px) { .agwrap.withchat { display: block; } .agchat { position: fixed; inset: 0; height: auto; z-index: 60; border-radius: 0; } }
.agname { font-size: 15px; }
.agrole { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--accentbg); color: var(--accent-ink); margin-left: 4px; }
.agdesc { padding: 8px 12px 0; }
.agcard > .agdesc:last-child { padding-bottom: 10px; }
.agcard .crew { margin: 8px 12px 12px; }
.warnchip { background: var(--accent); color: var(--on-accent); font-weight: 600; }
/* Thợ mới chờ duyệt: các bước đánh số xếp dọc, ngăn bằng đường kẻ mảnh; không lồng khung trong khung. */
.crewnew { display: grid; gap: 0; }
.cstep { padding: 12px 0; border-top: 1px solid var(--line); }
.cstep:first-of-type { border-top: 0; padding-top: 4px; }
.cstephead { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.cstepn { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--raised); border: 1px solid var(--line2); display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; }
.crewnew .crewintro { background: var(--deep); border-color: var(--line); margin-top: 0; height: 360px; max-height: none; min-height: 120px; resize: vertical; }
.crewnew .diffs { gap: 0; margin: 0; }
.crewnew .diffrow { border: 0; border-top: 1px solid var(--line); border-radius: 0; padding: 10px 0; align-items: flex-start; }
.crewnew .diffrow:first-child { border-top: 0; padding-top: 0; }
.dlab { display: inline-block; min-width: 110px; color: var(--sec); }
.dpick { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.crewnew .seg button.on { background: var(--accent); color: var(--on-accent); box-shadow: none; }
.crewnew textarea { margin: 0; min-height: 120px; height: 320px; resize: vertical; }
.cok { display: flex; align-items: center; gap: 6px; min-height: 32px; }
@media (max-width: 600px) { .dlab { display: block; min-width: 0; } .dpick { align-items: flex-start; } }
.crew { margin-top: 6px; }
.crew summary { cursor: pointer; min-height: 32px; display: flex; align-items: center; gap: 4px; }
.crew textarea { width: 100%; min-height: 90px; margin: 6px 0; }
.crew .warn { color: var(--accent-ink); }
.crewintro { white-space: pre-wrap; max-height: 180px; overflow: auto; padding: 6px 8px; margin-top: 4px; border: 1px solid var(--line); border-radius: 6px; }
.askmark { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; font-weight: 600; color: var(--amber); white-space: nowrap; margin-right: 6px; }
.diffs { display: grid; gap: 6px; margin: 6px 0; }
.diffrow { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; flex-wrap: wrap; }
.diffrow .seg button { min-height: 32px; }
.ditem { font-weight: 600; margin-bottom: 2px; }
.dkhop, .dunchk { align-items: center; }
.crew textarea.lackbox, .crewnew textarea.lackbox { min-height: 56px; height: 64px; }

/* Chọn người phụ trách trong form task: dùng lại nút .fchip của thanh lọc */
.whopick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.whopick .fchip:disabled { opacity: .55; cursor: not-allowed; }
@media (pointer: coarse) { .whopick .fchip { height: 40px; } }
/* Chọn nhãn kiểu Trello (labelPop / labelField) */
.btn.sm { height: 24px; padding: 0 8px; gap: 4px; font-size: 12px; border-radius: 6px; }
.btn.sm .i { width: 14px; height: 14px; }
.lquick { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; cursor: pointer; }
.lquick .lb:hover { outline: 1px solid var(--line2); }
.lfield { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-top: 4px; }
.lpop { position: fixed; z-index: 70; width: 260px; max-width: calc(100vw - 16px); padding: 8px; border: 1px solid var(--line2); border-radius: 10px; background: var(--panel); box-shadow: var(--shadow2); display: flex; flex-direction: column; gap: 6px; }
.lpop input { width: 100%; }
.lpl { display: flex; flex-direction: column; max-height: 280px; overflow: auto; }
.lpi { display: flex; align-items: center; gap: 8px; border: 0; background: none; padding: 6px 8px; min-height: 36px; border-radius: 6px; color: var(--text); text-align: left; cursor: pointer; }
.lpi:hover, .lpi.on { background: var(--accentbg); }
.lpk { width: 14px; font-weight: 700; color: var(--accent-ink); }
.lpnew { color: var(--accent-ink); }
.btn.sm.ladd { min-width: 36px; min-height: 36px; justify-content: center; } @media (min-width: 900px) { .btn.sm.ladd { min-height: 24px; min-width: 24px; } }
