/* BA Studio — giao diện. Màu định nghĩa bằng biến; tự đổi theo chế độ sáng/tối của máy.
   Không tải font/script từ CDN (server nội bộ): dùng font có sẵn trên máy. */
:root {
    --topbar-h: 64px;
    --radius: 12px;
    --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;

    --bg: #f5f5f1;
    --surface: #ffffff;
    --surface-2: #f1f0eb;
    --border: #e5e3dc;
    --border-strong: #d4d1c7;
    --hover: #efeee8;
    --text: #1c1c1c;
    --text-2: #3f3f3c;
    --muted: #6f6e69;
    --ink: #1c1c1c;
    --ink-hover: #333331;
    --ink-contrast: #ffffff;
    --accent: #1f4fc0;
    --accent-hover: #1a43a6;
    --accent-contrast: #ffffff;
    --accent-soft: #eaf0fc;
    --accent-border: #c9d7f5;
    --accent-text: #1f4fc0;
    --user-bubble: #1f4fc0;
    --user-text: #ffffff;
    --ok: #1f8a4c;
    --ok-bg: #e5f3ea;
    --ok-text: #17663a;
    --warn: #b46d06;
    --warn-bg: #fbf0dc;
    --warn-border: #efd9ad;
    --warn-text: #7f4a00;
    --err: #c93a3a;
    --err-bg: #fbeeee;
    --err-border: #f0c7c7;
    --err-text: #962323;
    --info-bg: #eaf0fc;
    --info-border: #c9d7f5;
    --info-text: #1c428f;
    --diff-add: #e6f5ea;
    --diff-add-text: #17602f;
    --diff-rm: #fcebeb;
    --diff-rm-text: #8d2020;
    --shadow: 0 1px 2px rgba(28, 28, 20, .04);
    --shadow-lg: 0 20px 40px rgba(28, 28, 20, .16);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #121212;
        --surface: #1b1b1a;
        --surface-2: #232321;
        --border: #2e2e2b;
        --border-strong: #3d3d39;
        --hover: #262624;
        --text: #ecebe6;
        --text-2: #c3c2bb;
        --muted: #8f8e87;
        --ink: #ecebe6;
        --ink-hover: #ffffff;
        --ink-contrast: #121212;
        --accent: #5b82e8;
        --accent-hover: #7596ee;
        --accent-contrast: #ffffff;
        --accent-soft: #1c2640;
        --accent-border: #2c3d66;
        --accent-text: #a9bdf5;
        --user-bubble: #2f59c4;
        --user-text: #ffffff;
        --ok: #3fbf74;
        --ok-bg: #13281b;
        --ok-text: #8fe0b0;
        --warn: #e9ad4c;
        --warn-bg: #2b2211;
        --warn-border: #574217;
        --warn-text: #f1cf8f;
        --err: #f06464;
        --err-bg: #2d1516;
        --err-border: #5c2a2d;
        --err-text: #ffabab;
        --info-bg: #17213a;
        --info-border: #2c3d66;
        --info-text: #a9bdf5;
        --diff-add: #12291b;
        --diff-add-text: #95e0b0;
        --diff-rm: #2e1517;
        --diff-rm-text: #ffb0b0;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow-lg: 0 20px 40px rgba(0, 0, 0, .5);
        color-scheme: dark;
    }
    /* thanh quản trị: giữ nền tối, chữ sáng */
    :root:not([data-theme="light"]) .topbar.dark { background: #000 !important; }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font); font-size: 15px; line-height: 1.5;
    background: var(--bg); color: var(--text);
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 16px; font-weight: 650; }
h1:focus { outline: none; }
a { color: var(--accent-text); }
code, .mono { font-family: var(--mono); font-size: .88em; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
code.plain { background: transparent; padding: 0; color: var(--text-2); }
pre { font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-word; margin: 6px 0 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.right { text-align: right; white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.dim { opacity: .6; }
.pad { padding: 14px 18px; margin: 0; }
.ok-text { color: var(--ok-text); margin-right: 8px; }
.warn-text { color: var(--warn-text); }
.err-text { color: var(--err-text); }

/* Trang đơn (Token, lỗi…) */
.page { width: 100%; max-width: 1040px; margin: 0 auto; padding: 32px 24px 60px; }
.page.narrow { max-width: 680px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head h1 { font-size: 26px; }
.page-head p { margin: 6px 0 0; }
.back-link { display: inline-block; font-size: 14px; text-decoration: none; margin-bottom: 12px; }
.back-link:hover { text-decoration: underline; }

/* Nút */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 40px; padding: 0 16px; border-radius: 10px;
    border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
    font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background .12s, border-color .12s, color .12s;
}
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .link:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, .who:focus-visible, .seg button:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ink { background: var(--ink); border-color: var(--ink); color: var(--ink-contrast); }
.btn.ink:hover:not(:disabled) { background: var(--ink-hover); border-color: var(--ink-hover); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.danger:hover:not(:disabled) { filter: brightness(.95); background: var(--err); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover:not(:disabled) { background: var(--hover); }
.btn.dashed { border-style: dashed; background: transparent; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn.lg { height: 52px; font-size: 16px; border-radius: 10px; }
.btn.block { display: flex; width: 100%; }
.btn.muted-btn { background: var(--surface-2); border-color: var(--border); color: var(--muted); }
.btn.muted-btn:disabled, .btn.primary:disabled.lg { opacity: 1; }
.btn.primary.lg:disabled { opacity: .55; }
.link { background: none; border: 0; padding: 0; color: var(--accent-text); cursor: pointer; font: inherit; text-align: left; }
.link:hover { text-decoration: underline; }

/* Nhãn "Sắp có": tính năng chưa làm, chỉ giữ chỗ trên giao diện */
.soon {
    display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 999px;
    font-size: 11px; font-weight: 600; letter-spacing: .01em; white-space: nowrap;
    background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.soon.on-dark { background: rgba(255, 255, 255, .18); color: inherit; border-color: transparent; }

/* Thẻ, nhãn */
.tag {
    display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px;
    background: var(--surface-2); color: var(--text-2); font-size: 12px; font-weight: 550; border: 1px solid var(--border);
}
.tag-accent { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.tag-warn { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }
.chip {
    display: inline-flex; align-items: center; height: 26px; padding: 0 11px; border-radius: 999px;
    font-size: 13px; font-weight: 550; white-space: nowrap; background: var(--surface-2); color: var(--text-2);
}
.chip-blue { background: var(--accent-soft); color: var(--accent-text); box-shadow: inset 0 0 0 1px var(--accent-border); }
.chip-green { background: var(--ok-bg); color: var(--ok-text); }
.chip-amber { background: var(--warn-bg); color: var(--warn-text); }
.chip-red { background: var(--err-bg); color: var(--err-text); }
.branch { display: block; font-family: var(--mono); font-size: 12.5px; color: var(--text-2); background: transparent; border: 0; padding: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pill {
    display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 12px; border-radius: 999px;
    font-size: 13px; font-weight: 550; background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill-ready { color: var(--ok-text); background: var(--ok-bg); }
.pill-busy { color: var(--accent-text); background: var(--accent-soft); }
.pill-starting { color: var(--warn-text); background: var(--warn-bg); }
.pill-stopped { color: var(--muted); }
.dot.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.8); } }

/* Phần tử trang điền lên thanh trên cùng (SectionContent) */
.app-pill { display: inline-flex; align-items: center; height: 34px; padding: 0 14px; border-radius: 8px; background: var(--surface-2); color: var(--text-2); font-size: 15px; white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.adm-tabs { display: flex; gap: 4px; margin-left: 24px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.adm-tabs button {
    display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px; border-radius: 8px; border: 0;
    background: transparent; color: rgba(255, 255, 255, .78); font: inherit; font-size: 15px; cursor: pointer; white-space: nowrap;
}
.adm-tabs button:hover:not(:disabled) { background: rgba(255, 255, 255, .1); color: #fff; }
.adm-tabs button.active { background: rgba(255, 255, 255, .14); color: #fff; font-weight: 550; }
.adm-tabs button:disabled { cursor: not-allowed; color: rgba(255, 255, 255, .45); }

/* Thông báo */
.banner {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
    padding: 12px 14px; border-radius: 10px; margin: 0 0 16px; border: 1px solid; font-size: 14px;
}
.banner > span { flex: 1; min-width: 200px; }
.banner.warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }
.banner.warn strong { width: 100%; }
.banner.error { background: var(--err-bg); border-color: var(--err-border); color: var(--err-text); }
.banner.info { background: var(--info-bg); border-color: var(--info-border); color: var(--info-text); }
.banner.ok { background: var(--ok-bg); border-color: transparent; color: var(--ok-text); }
.banner details { width: 100%; }
.dev-banner { font-size: 13px; padding: 8px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-text); margin: 18px 0 12px; }

/* Trống */
.empty { text-align: center; padding: 56px 20px; border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface); }
.empty h1, .empty h2 { margin-bottom: 6px; }
.empty p { margin: 0 auto 16px; max-width: 420px; }

/* ===== Màn hình BA: 3 cột (danh sách việc · trò chuyện · xem thử) ===== */
.wk {
    display: grid; grid-template-columns: 300px minmax(0, 1fr) 360px;
    height: calc(100dvh - var(--topbar-h)); min-height: 0;
}
.wk.wk-two { grid-template-columns: 300px minmax(0, 1fr); }
.wk-side { border-right: 1px solid var(--border); background: var(--bg); padding: 24px 20px; overflow-y: auto; overflow-x: hidden; min-height: 0; min-width: 0; }
.side-label { font-size: 13px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin: 24px 0 12px; }
.wk-side > .side-label:first-child, .adm-side > .side-label:first-child { margin-top: 0; }
.side-empty { margin: 0; }

.work-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.work-card {
    display: block; padding: 14px 16px; border-radius: var(--radius); background: var(--surface);
    border: 1px solid var(--border); text-decoration: none; color: var(--text);
    transition: border-color .12s, background .12s;
}
.work-card:hover { border-color: var(--border-strong); }
.work-card.sel { background: var(--accent-soft); border-color: var(--accent-border); }
.work-title { font-weight: 650; font-size: 15.5px; line-height: 1.35; margin-bottom: 4px; }
.work-card .branch { margin-bottom: 8px; }
.work-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; min-width: 0; }
.archived { margin-top: 24px; }
.archived summary { cursor: pointer; color: var(--muted); font-size: 14px; margin-bottom: 10px; }

/* Trang chủ BA (chưa mở việc nào) */
.wk-home { overflow-y: auto; min-height: 0; }
.wk-home-inner { max-width: 720px; margin: 0 auto; padding: 40px 24px; }
.hello-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 40px 28px; text-align: center; }
.hello-card h1 { margin: 14px 0 8px; }
.hello-card p { margin: 0 auto 8px; max-width: 460px; }
.hello-card .btn { margin-top: 12px; }

.ai-avatar {
    display: inline-grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%;
    background: var(--ink); color: var(--ink-contrast); font-size: 12.5px; font-weight: 700;
}
.ai-avatar.lg { width: 48px; height: 48px; font-size: 16px; }

/* Cột giữa */
.wk-center { min-width: 0; min-height: 0; container-type: inline-size; }
.chat { display: flex; flex-direction: column; min-height: 0; }
.chat-head {
    display: flex; align-items: center; gap: 14px; padding: 16px 24px;
    background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.chat-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.chat-head h1 { font-size: 21px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.branch-chip {
    display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px; border-radius: 8px;
    background: var(--surface-2); font-family: var(--mono); font-size: 13px; color: var(--text-2); max-width: 100%; min-width: 0;
}
.branch-chip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.branch-chip svg { flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; }
.chat-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-2); }
.seg button {
    display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border: 0; border-radius: 8px;
    background: transparent; color: var(--text-2); font: inherit; font-size: 13.5px; cursor: pointer;
}
.seg button.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.seg .count { font-size: 11px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent-soft); color: var(--accent-text); display: inline-grid; place-items: center; }

.chat-scroll { flex: 1; overflow-y: auto; min-height: 0; background: var(--bg); }
.chat-scroll[hidden] { display: none; }
.chat-body { max-width: 980px; margin: 0 auto; padding: 32px 24px 16px; display: flex; flex-direction: column; gap: 12px; }
.chat-hello { text-align: center; padding: 40px 12px; }
.chat-hello h2 { font-size: 21px; margin: 14px 0 6px; }
.examples { list-style: none; padding: 0; margin: 14px auto 0; display: grid; gap: 8px; max-width: 540px; }
.examples li { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 11px 14px; text-align: left; }
.examples li:hover { border-color: var(--border-strong); }
.examples .link { color: var(--text-2); }

.msg { display: flex; gap: 14px; align-items: flex-start; }
.msg .bubble { max-width: min(720px, 85%); padding: 12px 18px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; line-height: 1.55; }
.msg-user { justify-content: flex-end; margin: 4px 0; }
.msg-user .bubble { background: var(--user-bubble); color: var(--user-text); }
.msg-ai .bubble { background: var(--surface); border: 1px solid var(--border); padding: 14px 20px; }
.bubble.streaming::after { content: "▍"; color: var(--accent); animation: pulse 1s infinite; margin-left: 2px; }
/* các mục của AI nằm thẳng hàng với khung trả lời (bỏ chỗ avatar) */
.ai-follow { margin-left: 48px; max-width: min(760px, calc(100% - 48px)); }

.tool-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); padding: 0 4px; min-width: 0; }
.tool-line .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-line .ico { width: 18px; height: 18px; display: inline-grid; place-items: center; border-radius: 50%; background: var(--surface-2); font-size: 11px; flex: none; }
.tool-line.err { color: var(--err-text); }

.card { border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 11px 16px; font-size: 14px; min-width: 0; }
.card-head .grow { overflow: hidden; text-overflow: ellipsis; }
.card-head .ico { flex: none; }
.card .path { font-size: 12.5px; margin-left: 6px; word-break: break-all; }
.card .status { font-size: 12.5px; color: var(--muted); flex: none; }
.card .st-done { color: var(--ok-text); }
.card .st-error { color: var(--err-text); }
.card-err { border-color: var(--err-border); }
.card-err-text { padding: 8px 16px 12px; font-size: 13px; color: var(--err-text); white-space: pre-wrap; word-break: break-word; }
.card-block { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }
.card-block .ico { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.card-block .card-head strong { font-weight: 600; }
.card-block .card-sub { padding: 0 16px 11px 42px; font-size: 13px; color: var(--warn-text); opacity: .9; }
.card-block details { padding: 0 16px 12px 42px; font-size: 13px; }
.card-block summary { cursor: pointer; margin-bottom: 6px; }

/* Thẻ "N file thay đổi" (mỗi lượt lưu) */
.files-card { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); overflow: hidden; }
.files-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface-2); font-size: 14px; font-weight: 600; color: var(--text-2); min-width: 0; }
.files-head .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files-msg { font-weight: 450; color: var(--muted); }
.files-head .sha { font-size: 12px; font-weight: 450; background: transparent; color: var(--muted); padding: 0; }
.files-row { display: flex; align-items: center; gap: 10px; padding: 9px 16px; border-top: 1px solid var(--border); font-family: var(--mono); font-size: 13px; color: var(--text); min-width: 0; }
.files-row .path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files-row.more { font-family: var(--font); }
.files-card.revert .files-head { background: var(--surface-2); color: var(--muted); }

.diff { font-family: var(--mono); font-size: 12.5px; border-top: 1px solid var(--border); background: var(--surface-2); overflow-x: auto; }
.card-block .diff { border: 1px solid var(--warn-border); border-radius: 8px; }
.dl { display: flex; white-space: pre; padding: 0 12px 0 0; line-height: 1.6; min-width: max-content; }
.dl .sign { display: inline-block; width: 26px; text-align: center; flex: none; user-select: none; color: var(--muted); }
.dl.add { background: var(--diff-add); color: var(--diff-add-text); }
.dl.add .sign { color: var(--diff-add-text); }
.dl.rm { background: var(--diff-rm); color: var(--diff-rm-text); }
.dl.rm .sign { color: var(--diff-rm-text); }
.dl.gap { color: var(--muted); }

.turn-end { display: flex; align-items: center; gap: 8px; justify-content: center; font-size: 12px; color: var(--muted); margin: 4px 0 8px; }
.turn-end::before, .turn-end::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.turn-end.err { color: var(--err-text); }
.notice { font-size: 13px; text-align: center; color: var(--muted); }
.notice-error { color: var(--err-text); background: var(--err-bg); border-radius: 8px; padding: 6px 10px; }
.notice-warn { color: var(--warn-text); background: var(--warn-bg); border-radius: 8px; padding: 6px 10px; }
.stderr { font-size: 12px; }
.stderr code { display: block; white-space: pre-wrap; word-break: break-all; color: var(--muted); background: transparent; border: 0; }
.stderr-toggle { text-align: center; margin-top: 4px; }

.composer-wrap { border-top: 1px solid var(--border); background: var(--surface); padding: 16px 24px calc(16px + env(safe-area-inset-bottom)); }
.composer-banner { max-width: 980px; margin: 0 auto 10px; }
.composer { max-width: 980px; margin: 0 auto; display: flex; gap: 12px; align-items: flex-end; }
.composer textarea { resize: none; min-height: 50px; max-height: 220px; border-radius: 10px; padding: 13px 16px; line-height: 1.45; font-size: 15px; }
.composer .send { height: 50px; border-radius: 10px; padding: 0 24px; font-size: 15px; }

/* Lượt đã lưu, build */
.commit-line { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); padding: 6px 10px; border-radius: 8px; background: var(--ok-bg); min-width: 0; }
.card-build .status { display: inline-flex; align-items: center; gap: 6px; }
.card-build .spinner { width: 11px; height: 11px; }
.build-out { margin: 0; padding: 10px 16px; background: var(--surface-2); border-top: 1px solid var(--border); max-height: 320px; overflow: auto; white-space: pre; font-size: 12px; }
.build-out.err { color: var(--err-text); background: var(--err-bg); white-space: pre-wrap; word-break: break-word; }
.build-all { font-size: 13px; }
.build-all summary { cursor: pointer; padding: 8px 16px; color: var(--muted); border-top: 1px solid var(--border); }
.card-foot { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }
.add-text { color: var(--diff-add-text); }
.rm-text { color: var(--diff-rm-text); }

/* Cột phải: Xem thử */
.wk-right { border-left: 1px solid var(--border); background: var(--bg); padding: 28px 24px; overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 14px; }
.wk-right > h2 { font-size: 19px; }
.wk-right > p { margin: 0; }
.build-line { display: flex; align-items: center; gap: 9px; font-size: 15px; color: var(--muted); }
.build-line .b-ico { flex: none; width: 16px; text-align: center; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.build-line.ok { color: var(--ok-text); }
.build-line.failed { color: var(--err-text); }
.build-line.running { color: var(--accent-text); }
.preview-frame { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.pf-bar { display: flex; align-items: center; gap: 6px; padding: 9px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.pf-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); }
.pf-url { margin-left: 8px; font-family: var(--mono); font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pf-body { padding: 16px 18px 20px; }
.pf-body p { margin: 8px 0 14px; }
.pf-sk { height: 10px; border-radius: 5px; background: var(--surface-2); margin-top: 8px; }
.pf-sk.short { width: 60%; }
.side-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 18px 20px; }
.side-card-head, .soon-field-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.side-card p { margin: 6px 0 0; }
.wk-right .btn.lg { margin-top: 4px; }

/* Thay đổi (tab) */
.changes { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; max-width: 1200px; margin: 0 auto; padding: 24px; align-items: start; }
.commits { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; position: sticky; top: 12px; }
.commits-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.commits .banner { margin: 10px; }
.commit-list { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow-y: auto; }
.commit-list li { padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.commit-list li:hover { background: var(--hover); }
.commit-list li.sel { background: var(--accent-soft); }
.c-subj { font-size: 14px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.diff-view { min-width: 0; }
.diff-summary { margin-bottom: 8px; }
.ud-file { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.ud-file summary { display: flex; align-items: center; gap: 8px; padding: 10px 14px; cursor: pointer; background: var(--surface-2); border-bottom: 1px solid var(--border); min-width: 0; }
.ud-file summary .path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; background: transparent; }
.ud { font-family: var(--mono); font-size: 12.5px; overflow-x: auto; }
.ul { display: flex; min-width: max-content; line-height: 1.6; }
.ul .no { width: 44px; flex: none; text-align: right; padding-right: 8px; color: var(--muted); user-select: none; font-size: 11.5px; }
.ul .tx { white-space: pre; padding: 0 12px 0 6px; }
.ul.add { background: var(--diff-add); color: var(--diff-add-text); }
.ul.rm { background: var(--diff-rm); color: var(--diff-rm-text); }
.ul.hunk { background: var(--info-bg); color: var(--info-text); }
.ul.meta { color: var(--muted); }
@container (max-width: 760px) {
    .changes { grid-template-columns: 1fr; padding: 16px; }
    .commits { position: static; }
    .commit-list { max-height: 220px; }
}

/* Hộp thoại */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 20, 16, .45); z-index: 40; animation: fade .15s; }
.modal {
    position: fixed; z-index: 41; left: 50%; top: 12vh; transform: translateX(-50%);
    width: min(520px, calc(100vw - 32px)); background: var(--surface); border-radius: 16px; border: 1px solid var(--border);
    box-shadow: var(--shadow-lg); padding: 24px; animation: pop .15s;
}
.modal h2 { margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateX(-50%) translateY(8px); } }

/* Form */
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; min-width: 0; }
.field > span { font-size: 14px; font-weight: 600; color: var(--text); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
input:not([type=checkbox]), select, textarea {
    font: inherit; font-size: 15px; color: var(--text); background: var(--surface);
    border: 1px solid var(--border-strong); border-radius: 9px; padding: 9px 13px; min-height: 44px; width: 100%;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:disabled, select:disabled { background: var(--surface-2); color: var(--muted); }
input.mono { font-family: var(--mono); font-size: 14px; }
.field-err { color: var(--err-text); font-size: 12px; margin-top: 4px; white-space: normal; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; margin-bottom: 16px; cursor: pointer; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; }
.row-start { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.help { margin: -6px 0 16px; }
.spinner { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong); cursor: pointer; transition: background .15s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Panel */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px 26px; margin-bottom: 18px; }
.panel.flush { padding: 0; overflow: hidden; }
.panel h2 { margin-bottom: 16px; }
.panel-soon h2 { margin-bottom: 0; }
.panel-soon > p { margin: 10px 0 0; }
.steps { padding-left: 20px; margin: 0 0 16px; color: var(--text-2); }
.steps li { margin-bottom: 6px; }
.token-status { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

/* ===== Quản trị ===== */
.adm { display: grid; grid-template-columns: 280px minmax(0, 1fr) 340px; min-height: calc(100dvh - var(--topbar-h)); }
.adm.adm-two { grid-template-columns: 280px minmax(0, 1fr); }
.adm-side { border-right: 1px solid var(--border); padding: 24px 20px; background: var(--bg); }
.adm-main { padding: 32px 32px 60px; min-width: 0; max-width: 1000px; }
.adm-right { padding: 32px 28px 32px 0; }
.adm-right .panel { padding: 22px 24px; }
.adm-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.adm-head h1 { font-size: 28px; }
.adm-head code { font-size: 14px; }
.who-list { list-style: none; margin: 0 0 14px; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.who {
    display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; border-radius: var(--radius);
    border: 1px solid transparent; background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.who:hover { background: var(--hover); }
.who.sel { background: var(--accent-soft); border-color: var(--accent-border); }
.who strong { display: block; font-size: 15px; font-weight: 600; }
.who small { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dashed-note { border: 1px dashed var(--border-strong); border-radius: var(--radius); padding: 14px; font-size: 13px; color: var(--muted); text-align: center; }
.branch-table { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 18px; }
.bt-row { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 12px; padding: 11px 14px; border-top: 1px solid var(--border); font-size: 14px; align-items: center; }
.bt-row:first-child { border-top: 0; }
.bt-head { background: var(--surface-2); font-size: 13px; font-weight: 600; color: var(--text-2); }
.bt-row code { font-size: 13.5px; }
.soon-field { padding: 14px 16px; border-radius: 10px; background: var(--surface-2); margin-top: 10px; }
.soon-field strong { font-size: 14px; }
.soon-field p { margin: 6px 0 0; }
.deploy-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-radius: 10px; background: var(--surface-2); margin-top: 12px; }
.deploy-row strong { font-size: 15px; }
.deploy-row .chip, .soon-field .soon { background: var(--surface); }

/* Đăng nhập */
.auth-shell { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); }
.auth-card { width: min(440px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 36px 30px; box-shadow: var(--shadow-lg); text-align: center; }
.auth-card h1 { margin: 14px 0 6px; font-size: 24px; }
.auth-card > p { margin: 0 0 20px; }
.auth-card .btn.block { margin-top: 10px; }
.logo-lg { display: inline-grid; place-items: center; width: 54px; height: 54px; border-radius: 12px; background: var(--ink); color: var(--ink-contrast); font-weight: 750; font-size: 19px; }
.user-pick { display: grid; gap: 8px; text-align: left; }
.user-row {
    display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; border-radius: 12px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; text-align: left;
}
.user-row:hover { border-color: var(--accent-border); background: var(--accent-soft); }
.user-row strong { display: block; font-size: 14px; }
.user-row small { display: block; }
.avatar-sm { display: inline-grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); font-weight: 650; }

/* ===== Màn hẹp ===== */
@media (max-width: 1280px) {
    .wk { grid-template-columns: 260px minmax(0, 1fr) 320px; }
    .wk.wk-two { grid-template-columns: 260px minmax(0, 1fr); }
    .wk-side { padding: 20px 16px; }
    .wk-right { padding: 24px 18px; }
    .adm { grid-template-columns: 250px minmax(0, 1fr) 300px; }
    .adm-main { padding: 28px 24px 60px; }
    .adm-right { padding: 28px 20px 28px 0; }
}
@media (max-width: 1100px) {
    .adm { grid-template-columns: 240px minmax(0, 1fr); }
    .adm-right { grid-column: 2; padding: 0 24px 40px; }
}
@media (max-width: 1024px) {
    /* xếp chồng: danh sách việc → trò chuyện → xem thử */
    .wk, .wk.wk-two { grid-template-columns: 1fr; height: auto; }
    .wk-side { border-right: 0; border-bottom: 1px solid var(--border); max-height: 40dvh; }
    .wk-center.chat { height: calc(100dvh - var(--topbar-h)); }
    .wk-right { border-left: 0; border-top: 1px solid var(--border); }
}
@media (max-width: 720px) {
    .app-pill { display: none; }
    .page { padding: 20px 16px 48px; }
    .page-head { flex-direction: column; align-items: stretch; }
    .page-head .btn { align-self: flex-start; }
    .field-row { grid-template-columns: 1fr; }
    .chat-head { padding: 12px; gap: 8px; }
    .chat-body { padding: 16px 12px 8px; }
    .composer-wrap { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
    .msg .bubble { max-width: 92%; }
    .ai-follow { margin-left: 0; max-width: 100%; }
    .msg-ai .ai-avatar { display: none; }
    .modal { top: 8vh; padding: 18px; }
    .adm, .adm.adm-two { grid-template-columns: 1fr; }
    .adm-side { border-right: 0; border-bottom: 1px solid var(--border); }
    .adm-main { padding: 20px 16px 24px; }
    .adm-right { grid-column: 1; padding: 0 16px 40px; }
    .adm-tabs { margin-left: 0; }
    .bt-row { grid-template-columns: 1fr; gap: 2px; }
    .bt-head { display: none; }
}

/* Lỗi Blazor */
.blazor-error-boundary { background: var(--err-bg); color: var(--err-text); padding: 1rem; border-radius: 8px; }
.blazor-error-boundary::after { content: "Có lỗi xảy ra."; }
