/* Trợ lý AI (app/js/ui/aipanel.mjs, ui/aiskills.mjs): nút ✦ AI trên thanh trên + panel phải đè cạnh phải, app co lại theo
   --ai-w. Màu chỉ lấy từ token chung --fl-* (qua alias --surface, --line, --accent…) nên sáng / tối tự theo. */
.aibtn { font-weight: 600; color: var(--accent); }
.aibtn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-line); }
.aibtn.locked { color: var(--faint); }
.topbar.tb-tight .aibtn { padding: 0 7px; }

body.has-aipanel { padding-right: var(--ai-w, 440px); }
.aipanel { position: fixed; top: 0; right: 0; bottom: 0; width: var(--ai-w, 440px); z-index: 20; display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow-lg); min-width: 0; font-size: 13px; color: var(--ink); }
.aipanel[hidden] { display: none; }
.aipanel textarea, .aipanel select, .aipanel input { font: inherit; }
.aipanel .grow { flex: 1; }
.ai-svg { display: block; flex: none; }
.ai-resize { position: absolute; left: -4px; top: 0; bottom: 0; width: 8px; cursor: ew-resize; z-index: 3; }
.ai-resize:hover { background: color-mix(in srgb, var(--accent) 25%, transparent); }

/* ---- nút biểu tượng */
.ai-ib { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; border: 1px solid transparent; background: transparent;
  color: var(--muted); cursor: pointer; flex: none; transition: background .15s var(--ease), color .15s var(--ease), opacity .15s var(--ease); }
.ai-ib:hover:not(:disabled), .ai-ib[aria-expanded=true] { background: var(--sunken); color: var(--ink); }
.ai-ib:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.ai-ib:disabled { opacity: .38; cursor: default; }
.ai-ib.danger:hover:not(:disabled) { color: var(--bad); background: var(--bad-soft); }
.ai-ib.sm { width: 26px; height: 26px; border-radius: 7px; }
.ai-ib.sm .ai-svg { width: 14px; height: 14px; }

/* ---- đầu panel (M15, kiểu Codex): tiêu đề hội thoại + nút biểu tượng, không viền nặng */
.ai-head { position: relative; display: flex; align-items: center; gap: 2px; padding: 8px 8px 4px 10px; background: var(--surface); min-width: 0; }
.ai-title { flex: 1; min-width: 0; display: flex; align-items: center; height: 30px; padding: 0 8px; border-radius: 8px; font-weight: 600; font-size: 13.5px; color: var(--ink);
  cursor: default; transition: background .15s var(--ease); }
.ai-title:hover { background: var(--sunken); }
.ai-title:focus-visible { outline: 2px solid var(--ring); }
.ai-title-t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.aipanel .ai-title-in { width: 100%; height: 26px; padding: 0 6px; border-radius: 6px; border: 1px solid var(--accent-line); background: var(--surface); color: var(--ink);
  font-weight: 600; outline: 0; box-shadow: 0 0 0 3px var(--ring); }
.ai-tabs { display: flex; gap: 2px; padding: 0 10px 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
.ai-tabs [role=tab] { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border: 0; border-radius: 12px; background: none; color: var(--muted);
  font-size: 12px; font-weight: 500; cursor: pointer; white-space: nowrap; transition: background .15s var(--ease), color .15s var(--ease); }
.ai-tabs [role=tab]:hover { color: var(--ink); }
.ai-tabs [role=tab][aria-selected=true] { color: var(--ink); background: var(--sunken); }
.ai-tabs [role=tab]:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
.ai-count { font-size: 10.5px; line-height: 15px; min-width: 15px; padding: 0 4px; border-radius: 8px; background: var(--line); color: var(--muted); text-align: center; }
.ai-count:empty { display: none; }
.ai-lock { margin: 8px 10px 0; }

/* ---- tin nhắn: trả lời AI = chữ trần toàn chiều rộng; tin người dùng = khối bo mềm bên phải */
.ai-msgwrap { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; background: var(--surface); }
.ai-msgs { flex: 1; overflow: auto; padding: 18px 16px 10px; display: flex; flex-direction: column; gap: 18px; min-height: 0; }
.ai-msg { max-width: 100%; min-width: 0; }
.ai-msg.user { align-self: flex-end; max-width: 86%; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.ai-bubble { background: color-mix(in srgb, var(--ink) 7%, var(--surface)); color: var(--ink); border-radius: 18px; padding: 8px 14px;
  white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; font-size: 13.5px; }
.ai-msg-atts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.ai-msg.bot { display: block; }
.ai-body { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.ai-md { overflow-wrap: anywhere; line-height: 1.6; color: var(--ink); font-size: 13.5px; }
.ai-md p { margin: 0 0 10px; }
.ai-md p:last-child { margin-bottom: 0; }
.ai-md h4, .ai-md h5, .ai-md h6 { margin: 14px 0 4px; font-size: 14px; font-weight: 600; }
.ai-md ul, .ai-md ol { margin: 0 0 10px; padding-left: 22px; }
.ai-md li { margin: 3px 0; }
.ai-md li::marker { color: var(--faint); }
.ai-md hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.ai-md code { background: color-mix(in srgb, var(--ink) 8%, transparent); border-radius: 6px; padding: 1px 5px; font-family: var(--mono); font-size: 12px; }
.ai-md .aicode { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin: 6px 0 10px; background: var(--sunken); }
.aicode-h { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 4px 12px; font-size: 11.5px; color: var(--muted);
  background: color-mix(in srgb, var(--ink) 5%, var(--sunken)); font-family: var(--mono); }
.aicopy { border: 0; background: transparent; color: var(--muted); font: inherit; cursor: pointer; padding: 2px 8px; border-radius: 6px; transition: background .15s var(--ease), color .15s var(--ease); }
.aicopy:hover { color: var(--ink); background: var(--surface); }
.aicopy:focus-visible { outline: 2px solid var(--ring); }
.aicopy.done { color: var(--ok); }
.ai-md .aicode pre { margin: 0; padding: 10px 12px; overflow: auto; font-size: 12px; line-height: 1.5; max-height: 360px; }
.ai-md .aicode code { background: none; border: 0; padding: 0; }
.aitbl { overflow: auto; margin: 6px 0 10px; border: 1px solid var(--line); border-radius: 10px; }
.aitbl table { border-collapse: collapse; font-size: 12.5px; width: 100%; }
.aitbl th { background: var(--surface-2); font-weight: 600; }
.aitbl th, .aitbl td { border-bottom: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.aitbl tr:last-child td { border-bottom: 0; }

/* hành động dưới tin nhắn: hiện khi rê chuột / focus */
.ai-acts { display: flex; align-items: center; gap: 8px; min-height: 26px; }
.ai-msg.user .ai-acts { justify-content: flex-end; }
.ai-acts-b { display: inline-flex; gap: 0; opacity: 0; transition: opacity .15s var(--ease); }
.ai-msg:hover .ai-acts-b, .ai-acts-b:focus-within { opacity: 1; }
@media (hover: none) { .ai-acts-b { opacity: 1; } }
.ai-meta { font-variant-numeric: tabular-nums; font-size: 11px; color: var(--faint); }

/* đang nghĩ / con trỏ khi stream / ánh sáng chạy ngang */
.shimmer { color: var(--muted); }
.ai-think.shimmer > span, .ai-work-t.shimmer { background: linear-gradient(90deg, var(--muted) 0%, var(--muted) 35%, var(--ink) 50%, var(--muted) 65%, var(--muted) 100%);
  background-size: 250% 100%; -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent; animation: ai-shim 1.8s linear infinite; }
@keyframes ai-shim { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.ai-think { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.ai-think .ai-svg { width: 14px; height: 14px; color: var(--accent); }
.ai-caret { display: inline-block; width: 7px; height: 1.05em; margin-left: 2px; vertical-align: -.18em; border-radius: 1.5px; background: var(--ink); animation: ai-blink 1.05s steps(2, start) infinite; }
@keyframes ai-blink { to { visibility: hidden; } }

/* nhóm bước + bước tool (kiểu Codex): hàng mờ một dòng, mở ra thấy chi tiết */
.ai-work > summary, .ai-step > summary { display: flex; align-items: center; gap: 7px; cursor: pointer; list-style: none; min-width: 0; color: var(--muted); border-radius: 7px; transition: background .15s var(--ease), color .15s var(--ease); }
.ai-work > summary::-webkit-details-marker, .ai-step > summary::-webkit-details-marker { display: none; }
.ai-work > summary { padding: 3px 6px 3px 0; font-size: 12.5px; }
.ai-work > summary:hover, .ai-step > summary:hover { color: var(--ink); }
.ai-work > summary:focus-visible, .ai-step > summary:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.ai-work > summary small { color: var(--faint); font-size: 11.5px; }
.ai-work > summary small.bad { color: var(--bad); }
.ai-work > summary .spin, .ai-step .spin { width: 11px; height: 11px; border-width: 1.5px; }
.ai-chev { display: inline-grid; place-items: center; margin-left: -2px; color: var(--faint); transition: transform .15s var(--ease); }
.ai-chev .ai-svg { width: 13px; height: 13px; }
.ai-work[open] > summary .ai-chev, .ai-step[open] > summary .ai-chev { transform: rotate(90deg); }
.ai-steps { display: flex; flex-direction: column; gap: 1px; margin: 3px 0 2px 5px; padding-left: 10px; border-left: 1px solid var(--line); }
.ai-step { font-size: 12.5px; }
.ai-step > summary { padding: 3px 6px 3px 2px; }
.ai-step-ic { display: grid; place-items: center; width: 14px; height: 14px; flex: none; }
.ai-step-ic .ai-svg { width: 12px; height: 12px; stroke-width: 2.4; }
.ai-step.ok .ai-step-ic { color: var(--ok); }
.ai-step.bad .ai-step-ic, .ai-step.bad > summary { color: var(--bad); }
.ai-step-t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-step-d { padding: 2px 6px 6px 23px; color: var(--muted); font-size: 11.5px; overflow-wrap: anywhere; user-select: text; }
.ai-step-e { padding: 0 6px 4px 23px; color: var(--bad); font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; user-select: text; }

/* thẻ đề xuất kiểu review card của Codex */
.ai-prop { border: 1px solid var(--line-2); border-radius: 12px; padding: 10px 12px; background: var(--surface); display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow-xs); }
.ai-prop.destructive { border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); }
.ai-prop.st-applied { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.ai-prop.st-rejected { opacity: .7; }
.ai-prop-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.ai-prop-head b { min-width: 0; overflow-wrap: anywhere; font-weight: 600; }
.ai-prop-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.ai-fchip { font-size: 11px; line-height: 18px; padding: 0 7px; border-radius: 6px; background: var(--sunken); color: var(--ink-2); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-cnt { display: inline-flex; gap: 6px; font-family: var(--mono); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.ai-cnt .add { color: var(--ok); } .ai-cnt .del { color: var(--bad); }
.ai-prop .ok { color: var(--ok); } .ai-prop .bad { color: var(--bad); } .ai-prop .warn { color: var(--warn); }
.ai-prop-st { display: flex; align-items: center; gap: 5px; font-weight: 500; }
.ai-prop-st .ai-svg { width: 14px; height: 14px; }
.ai-prop-act { gap: 6px; }
.aipanel .btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); }
.aipanel .btn.ghost:hover { background: var(--sunken); color: var(--ink); }
.ai-changes { margin: 0; padding-left: 18px; }
.ai-diffbox summary { cursor: pointer; color: var(--muted); }
.ai-diff { margin: 6px 0 0; max-height: 280px; overflow: auto; font-size: 11px; line-height: 1.45; background: var(--sunken); border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.ai-diff .add { color: var(--ok); background: var(--ok-soft); display: inline-block; min-width: 100%; }
.ai-diff .del { color: var(--bad); background: var(--bad-soft); display: inline-block; min-width: 100%; }
.ai-diff .hunk { color: var(--muted); }
.ai-note { color: var(--accent); font-size: 12px; }
.ai-gal { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 2px; }
.ai-gimg { padding: 0; border: 1px solid var(--line, #3d444b); border-radius: 10px; overflow: hidden; background: color-mix(in srgb, var(--muted, #888) 14%, transparent); cursor: zoom-in; width: 168px; min-height: 96px; display: flex; }
.ai-gimg img { display: block; width: 100%; height: auto; max-height: 220px; object-fit: contain; }
.ai-gimg.bad { cursor: default; opacity: .5; }
.ai-gtile { display: flex; flex-direction: column; gap: 4px; align-items: stretch; width: 168px; }
.ai-gacc { justify-content: center; }
.ai-gacc.ok { color: var(--ok, #2fb36d); font-size: 12px; text-align: center; }
.ai-err { margin: 0; }

/* nút "↓" khi cuộn lên */
.ai-tobottom { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); box-shadow: var(--shadow-sm); cursor: pointer; transition: background .15s var(--ease); }
.ai-tobottom[hidden] { display: none; }
.ai-tobottom:hover { background: var(--sunken); color: var(--ink); }
.ai-tobottom:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* trạng thái trống kiểu trang chủ ChatGPT */
.ai-empty { margin: auto 0; width: 100%; max-width: 440px; align-self: center; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 12px 4px; color: var(--ink-2); }
.ai-hero { display: grid; place-items: center; color: var(--accent); }
.ai-hero .ai-svg { width: 40px; height: 40px; stroke-width: 1.5; }
.ai-empty h3 { margin: 6px 0 4px; font-size: 19px; font-weight: 600; line-height: 1.3; color: var(--ink); }
.ai-empty p { margin: 6px 0 0; max-width: 360px; font-size: 12px; line-height: 1.55; color: var(--faint); }
.ai-sugg { display: flex; flex-direction: column; width: 100%; margin-top: 12px; text-align: left; }
.ai-sugg-it { display: flex; align-items: center; gap: 10px; text-align: left; padding: 10px 8px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0;
  background: none; color: var(--ink-2); cursor: pointer; font: inherit; line-height: 1.4; transition: background .15s var(--ease), color .15s var(--ease); }
.ai-sugg-it:last-child { border-bottom: 0; }
.ai-sugg-it:hover { background: var(--sunken); color: var(--ink); border-radius: 10px; }
.ai-sugg-it:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; border-radius: 10px; }
.ai-sugg-ic { color: var(--muted); flex: none; display: grid; }
.ai-empty-ctx { font-size: 11.5px; color: var(--faint); margin-top: 2px; }

/* ---- ô soạn kiểu Codex / ChatGPT */
.ai-foot { padding: 6px 12px 10px; display: flex; flex-direction: column; gap: 6px; background: var(--surface); }
.ai-box { position: relative; display: flex; flex-direction: column; border: 1px solid var(--line-2); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow-sm);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease); }
.ai-box:focus-within { border-color: var(--accent-line); box-shadow: var(--shadow-sm), 0 0 0 3px var(--ring); }
.aipanel .ai-box textarea { border: 0; outline: 0; background: transparent; color: var(--ink); resize: none; padding: 12px 14px 4px; min-height: 44px; max-height: 260px;
  line-height: 1.5; box-shadow: none; width: 100%; border-radius: 16px 16px 0 0; }
.ai-box textarea::placeholder { color: var(--faint); }
.ai-ctxrow { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 10px 0; min-width: 0; }
.ai-ctxrow[hidden] { display: none; }
.ai-ctxchip { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; min-width: 0; height: 24px; padding: 0 5px 0 8px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink-2); font: inherit; font-size: 12px; cursor: pointer; transition: background .15s var(--ease), border-color .15s var(--ease); }
.ai-ctxchip:hover { background: var(--sunken); border-color: var(--line-2); }
.ai-ctxchip:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.ai-ctxchip > .ai-svg { width: 13px; height: 13px; color: var(--muted); flex: none; }
.ai-ctxchip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ai-ctxchip small { color: var(--faint); font-size: 11px; flex: none; }
.ai-ctxchip i { display: grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; color: var(--faint); flex: none; }
.ai-ctxchip i .ai-svg { width: 11px; height: 11px; stroke-width: 2.4; }
.ai-ctxchip:hover i { color: var(--ink); background: var(--line); }
.ai-ctxchip.off { opacity: .7; border-style: dashed; }
.ai-ctxchip.off span { text-decoration: line-through; }
.ai-bar { display: flex; align-items: flex-end; gap: 6px; padding: 4px 6px 6px; min-width: 0; }
.ai-pills { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; }
.ai-pills > * { flex: none; }
.ai-plus { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line-2); background: var(--surface);
  color: var(--ink-2); cursor: pointer; flex: none; transition: background .15s var(--ease), color .15s var(--ease); }
.ai-plus:hover:not(:disabled), .ai-plus[aria-expanded=true] { background: var(--sunken); color: var(--ink); }
.ai-plus:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.ai-plus:disabled { opacity: .4; cursor: default; }
.ai-plus .ai-svg { width: 18px; height: 18px; }
.ai-pillw { position: relative; display: inline-flex; align-items: center; }
.ai-pillw > .ai-svg { position: absolute; left: 8px; width: 13px; height: 13px; color: var(--muted); pointer-events: none; }
.ai-pillw .ai-pill { padding-left: 26px; }
.aipanel .ai-pill { appearance: none; -webkit-appearance: none; field-sizing: content; width: auto; height: 26px; max-width: 170px; min-width: 0; padding: 0 22px 0 9px; border-radius: 13px; border: 1px solid transparent;
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2398a3ae' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 7px center;
  color: var(--muted); font-size: 12px; cursor: pointer; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; box-shadow: none; transition: background-color .15s var(--ease), color .15s var(--ease); }
.aipanel .ai-pillw .ai-pill { padding-left: 26px; }
.aipanel .ai-pill:hover { background-color: var(--sunken); color: var(--ink); }
.aipanel .ai-pill:focus-visible { outline: 2px solid var(--ring); }
.ai-pill option { color: var(--ink); background: var(--surface); }
.aipanel .ai-skpill { display: inline-flex; align-items: center; gap: 5px; padding: 0 10px; background-image: none; }
.ai-skpill .ai-svg { width: 13px; height: 13px; }
.ai-skpill[hidden] { display: none !important; }
.ai-send { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; border: 0; flex: none; cursor: pointer;
  background: var(--ink); color: var(--surface); transition: opacity .15s var(--ease), background .15s var(--ease); }
.ai-send:hover:not(:disabled) { opacity: .85; }
.ai-send:disabled { background: var(--sunken); color: var(--faint); cursor: default; box-shadow: inset 0 0 0 1px var(--line); }
.ai-send:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.ai-usage { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; min-height: 14px; }
.ai-meter { width: 46px; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; flex: none; }
.ai-meter i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.ai-meter.warm i { background: var(--fl-amber); } .ai-meter.hot i { background: var(--bad); }

/* chip đính kèm */
.ai-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 10px 0; }
.ai-chips[hidden] { display: none; }
.ai-chip { position: relative; display: inline-flex; align-items: center; gap: 8px; max-width: 220px; min-width: 0; padding: 5px 26px 5px 6px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); }
.ai-chip-ic { display: grid; place-items: center; width: 30px; height: 30px; flex: none; border-radius: 8px; background: var(--accent-soft); color: var(--accent); }
.ai-chip-t { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.ai-chip-t b { font-weight: 500; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-chip-t small { color: var(--muted); font-size: 11px; }
.ai-chip.img { padding: 0; border-radius: 10px; overflow: hidden; }
.ai-thumb { display: block; padding: 0; border: 0; background: var(--sunken); cursor: zoom-in; }
.ai-thumb img { display: block; width: 58px; height: 58px; object-fit: cover; }
.ai-msg-atts .ai-thumb img { width: 92px; height: 92px; }
.ai-msg-atts .ai-chip:not(.img) { padding-right: 10px; }
.ai-chip-x { position: absolute; top: 3px; right: 3px; display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; border: 0; cursor: pointer;
  background: color-mix(in srgb, var(--ink) 70%, transparent); color: var(--surface); }
.ai-chip-x .ai-svg { width: 11px; height: 11px; stroke-width: 2.6; }
.ai-chip-x:hover { background: var(--bad); color: #fff; }
.ai-imgview { display: grid; place-items: center; }
.ai-imgview img { max-width: 100%; max-height: 72vh; border-radius: 8px; }
.ai-dropover { position: absolute; inset: 0; border-radius: 16px; border: 2px dashed var(--accent); background: color-mix(in srgb, var(--accent-soft) 88%, transparent);
  display: none; align-items: center; justify-content: center; gap: 8px; color: var(--accent); font-weight: 600; pointer-events: none; z-index: 2; }
.aipanel.ai-dragging .ai-dropover { display: flex; }

/* menu "+", menu kỹ năng, popover lịch sử và ⋯ */
.ai-menu { position: absolute; left: 6px; bottom: calc(100% + 6px); z-index: 5; width: min(320px, calc(100% - 12px)); max-height: 60vh; overflow: auto;
  padding: 6px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-lg); animation: ai-pop .15s var(--ease); }
@keyframes ai-pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.ai-menu-it { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 9px; background: none; color: var(--ink);
  font: inherit; text-align: left; cursor: pointer; transition: background .15s var(--ease); }
.ai-menu-it:disabled { opacity: .4; cursor: default; }
.ai-menu-it > .ai-svg { color: var(--muted); width: 18px; height: 18px; flex: none; }
.ai-menu-it span, .ai-menu-chk span { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.ai-menu-it b, .ai-menu-chk b { font-weight: 500; }
.ai-menu-it small, .ai-menu-chk small { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-menu-it:hover:not(:disabled), .ai-menu-it:focus-visible { background: var(--sunken); outline: none; }
.ai-menu-it.danger:hover:not(:disabled), .ai-menu-it.danger:hover:not(:disabled) > .ai-svg { color: var(--bad); }
.ai-menu-h { padding: 6px 10px 4px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.ai-menu-chk { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 9px; cursor: pointer; }
.ai-menu-chk:hover, .ai-menu-chk:focus-within { background: var(--sunken); }
.ai-menu-chk input { accent-color: var(--accent); width: 15px; height: 15px; flex: none; }
.ai-menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.ai-menu-empty { padding: 8px 10px; color: var(--muted); font-size: 12px; }
.ai-pop { left: auto; right: 8px; bottom: auto; top: calc(100% - 2px); width: min(300px, calc(100% - 16px)); }
.ai-hist { width: min(340px, calc(100% - 16px)); padding: 0 6px 6px; }
.ai-hist-search { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px; padding: 10px 8px 8px; background: var(--surface); border-bottom: 1px solid var(--line); margin-bottom: 4px; color: var(--muted); }
.ai-hist-search .ai-svg { width: 15px; height: 15px; flex: none; }
.aipanel .ai-hist-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); box-shadow: none; padding: 0; height: 22px; }
.ai-hist-list { max-height: min(52vh, 360px); overflow: auto; }
.ai-hist-it { display: flex; align-items: center; border-radius: 9px; transition: background .15s var(--ease); }
.ai-hist-it:hover, .ai-hist-it:focus-within { background: var(--sunken); }
.ai-hist-open { flex: 1; min-width: 0; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 7px 8px 7px 10px; border: 0; background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer; border-radius: 9px; }
.ai-hist-open:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
.ai-hist-t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-hist-it.cur .ai-hist-t { font-weight: 600; }
.ai-hist-open small { color: var(--faint); font-size: 11px; flex: none; font-variant-numeric: tabular-nums; }
.ai-hist-del { opacity: 0; margin-right: 2px; }
.ai-hist-it:hover .ai-hist-del, .ai-hist-it:focus-within .ai-hist-del { opacity: 1; }
@media (hover: none) { .ai-hist-del { opacity: 1; } }

/* ---- Ngữ cảnh & kỹ năng */
.ai-ctx { flex: 1; overflow: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.ai-card { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); padding: 12px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow-xs); }
.ai-card h4 { display: flex; align-items: center; gap: 7px; margin: 0; font-size: 13px; }
.ai-card h4 > .ai-svg { color: var(--accent); }
.ai-card-sub { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.ai-card textarea { width: 100%; resize: vertical; border-radius: 10px; min-height: 64px; }
.ai-card-foot { display: flex; justify-content: flex-end; gap: 6px; }
.ai-ctx-note { margin: 0 4px; }
.ai-drop { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 10px; border: 1.5px dashed var(--line-2); border-radius: 12px;
  background: var(--surface-2); text-align: center; transition: border-color .12s, background .12s; }
.ai-drop.over { border-color: var(--accent); background: var(--accent-soft); }
.ai-drop-ic { color: var(--accent); }
.ai-drop-ic .ai-svg { width: 22px; height: 22px; }
.ai-drop-txt { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; }
.ai-drop-txt > span { color: var(--muted); }
.ai-drop-txt .btn .ai-svg { width: 13px; height: 13px; display: inline-block; vertical-align: -2px; }
.ai-drop-to { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.ai-drop-hint { font-size: 11px; color: var(--faint); }
.ai-sgroup h5 { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 10px 0 6px; font-size: 12px; color: var(--ink-2); }
.ai-sub { font-weight: 400; color: var(--faint); font-size: 11px; }
.ai-none { color: var(--faint); font-size: 12px; padding: 2px 0 4px; }
.ai-skills { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ai-skill { display: flex; align-items: flex-start; gap: 10px; padding: 8px 8px 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); min-width: 0; }
.ai-skill.off .ai-skill-main { opacity: .55; }
.ai-skill-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ai-skill-name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.ai-skill-name b { font-weight: 600; overflow-wrap: anywhere; }
.ai-skill-desc { color: var(--ink-2); font-size: 12px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ai-skill-meta { color: var(--faint); font-size: 11px; }
.ai-skill-act { display: flex; gap: 0; flex: none; }
.ai-skill-act .ai-ib { width: 26px; height: 26px; }
.ai-skill-act .ai-svg { width: 14px; height: 14px; }
.ai-tag { font-size: 10.5px; line-height: 16px; padding: 0 6px; border-radius: 8px; font-weight: 500; }
.ai-tag.always { background: var(--accent-soft); color: var(--accent); }
.ai-tag.auto { background: var(--sunken); color: var(--muted); }
.ai-switch { position: relative; display: inline-block; width: 30px; height: 18px; flex: none; margin-top: 1px; }
.ai-switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; width: 100%; height: 100%; }
.ai-switch span { position: absolute; inset: 0; border-radius: 9px; background: var(--line-2); transition: background .15s; }
.ai-switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-xs); transition: transform .15s var(--ease); }
.ai-switch input:checked + span { background: var(--accent); }
.ai-switch input:checked + span::after { transform: translateX(12px); }
.ai-switch input:focus-visible + span { outline: 2px solid var(--ring); outline-offset: 1px; }
.ai-switch input:disabled { cursor: default; }
.ai-switch input:disabled + span { opacity: .5; }
.ai-skill-editor { border: 1px solid var(--accent-line); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); margin-top: 10px; }
.ai-ed-head { display: flex; align-items: center; gap: 6px; }
.ai-ed-foot { display: flex; align-items: center; gap: 6px; }
.ai-fld { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); min-width: 0; }
.ai-fld > span { display: flex; align-items: center; gap: 4px; }
.ai-fld input, .ai-fld select, .ai-fld textarea { width: 100%; color: var(--ink); }
.ai-fld textarea { resize: vertical; font-family: var(--mono); font-size: 12px; line-height: 1.45; }
.ai-dlg { display: flex; flex-direction: column; gap: 10px; }
.ai-loading { display: grid; place-items: center; padding: 16px; }

/* điện thoại / cửa sổ hẹp: panel phủ toàn màn, app không co */
@media (max-width: 760px) {
  body.has-aipanel { padding-right: 0; }
  .aipanel { width: 100vw; }
  .ai-resize { display: none; }
}
@media (max-width: 420px) {
  .ai-tabs [role=tab] { padding: 0 6px; }
  .aipanel .ai-pill { max-width: 110px; }
}
.aipanel-embed { max-width: 860px; }

/* ---- FORK (M14): kế hoạch nhiều bước, thông báo giới hạn, chip "Việc tiếp theo", thẻ Quyền AI */
.ai-plan { border: 1px solid var(--accent-line); border-radius: 12px; padding: 10px 12px; background: var(--surface); display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow-xs); }
.ai-plan.st-done { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.ai-plan.st-stopped, .ai-plan.st-cancelled { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); opacity: .9; }
.ai-plan-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ai-plan-head b { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.ai-plan-prog { font-variant-numeric: tabular-nums; }
.ai-plan-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.ai-plan-step { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); font-size: 12.5px; min-width: 0; }
.ai-plan-ic { display: grid; place-items: center; width: 16px; height: 16px; flex: none; color: var(--faint); font-size: 11px; }
.ai-plan-ic .ai-svg { width: 12px; height: 12px; stroke-width: 2.6; }
.ai-plan-ic .spin { width: 11px; height: 11px; }
.ai-plan-step.s-done .ai-plan-ic { color: var(--ok); }
.ai-plan-step.s-failed .ai-plan-ic { color: var(--bad); }
.ai-plan-step.s-running { border-color: var(--accent-line); background: var(--accent-soft, var(--surface-2)); }
.ai-plan-step.s-running .ai-plan-ic { color: var(--accent); }
.ai-plan-step.s-skipped { opacity: .6; }
.ai-plan-step.s-skipped .ai-plan-title { text-decoration: line-through; }
.ai-plan-title { flex: 1 1 140px; min-width: 0; overflow-wrap: anywhere; color: var(--ink); }
input.ai-plan-title { font: inherit; padding: 2px 6px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--surface); }
.ai-plan-run { display: inline-flex; align-items: center; cursor: pointer; }
.ai-plan-run input { margin: 0; accent-color: var(--accent); }
.ai-plan-g { font-family: var(--mono); font-size: 10.5px; color: var(--faint); }
.ai-plan-note { flex-basis: 100%; padding-left: 22px; }
.ai-plan-act { gap: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ai-guard { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 0; }
.ai-guard > div { flex: 1 1 200px; min-width: 0; overflow-wrap: anywhere; }
.ai-follow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 6px 0 2px; }
.ai-follow-h { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; flex-basis: 100%; }
.ai-follow-chip { border: 1px solid var(--accent-line); background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: 4px 11px; font: inherit; font-size: 12px; cursor: pointer; text-align: left; line-height: 1.35; max-width: 100%; }
.ai-follow-chip:hover { background: var(--surface-2); color: var(--ink); border-color: var(--accent); }
.ai-follow-chip:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.ai-perm-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.ai-perm { display: flex; align-items: flex-start; gap: 8px; padding: 5px 8px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); }
.ai-perm-ic { display: grid; place-items: center; width: 16px; height: 16px; flex: none; margin-top: 1px; border-radius: 50%; }
.ai-perm-ic .ai-svg { width: 11px; height: 11px; stroke-width: 2.6; }
.ai-perm.ok .ai-perm-ic { color: var(--ok); background: var(--ok-soft); }
.ai-perm.blocked .ai-perm-ic { color: var(--warn); }
.ai-perm.no { opacity: .7; } .ai-perm.no .ai-perm-ic { color: var(--faint); }
.ai-perm-t { display: flex; flex-direction: column; min-width: 0; font-size: 12.5px; }
.ai-perm-t small { color: var(--muted); font-size: 11.5px; overflow-wrap: anywhere; }
.ai-perm-lim { margin: 0; }

/* ---- FORK (M15): kế hoạch dạng checklist, tiến độ mảnh, thu nhỏ khung hẹp, tôn trọng reduced-motion */
.ai-plan { border-color: var(--line-2); }
.ai-plan-head b { font-weight: 600; }
.ai-plan-bar { height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.ai-plan-bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width .3s var(--ease); }
.ai-plan.st-done .ai-plan-bar i { background: var(--ok); }
.ai-plan-steps { gap: 0; }
.ai-plan-step { border: 0; background: none; padding: 5px 4px; border-radius: 8px; }
.ai-plan-step.s-running { background: var(--accent-soft); }
.ai-plan-ic { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--line-2); font-size: 0; }
.ai-plan-step.s-done .ai-plan-ic { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.ai-plan-step.s-failed .ai-plan-ic { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.ai-plan-step.s-running .ai-plan-ic { border-color: var(--accent); }
.ai-plan-step.s-skipped .ai-plan-ic { font-size: 11px; }
.ai-plan-step.s-pending .ai-plan-ic { color: transparent; }
.ai-plan-ic .ai-svg { width: 11px; height: 11px; }
@media (max-width: 420px) {
  .ai-msgs { padding: 14px 12px 8px; }
  .ai-foot { padding: 6px 8px 8px; }
  .ai-title { padding: 0 6px; }
  .ai-pop, .ai-hist { right: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  .aipanel *, .aipanel *::before, .aipanel *::after { animation: none !important; transition: none !important; }
  .ai-think.shimmer > span, .ai-work-t.shimmer { -webkit-text-fill-color: currentColor; color: var(--muted); background: none; }
  .ai-caret { animation: none; }
}

/* ---------- M16: trạng thái rõ ràng — đang chạy / chờ bạn / xong ---------- */
.ai-status { display: flex; align-items: center; gap: 8px; min-height: 26px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 500;
  color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); align-self: flex-start; max-width: 100%; }
.ai-status[hidden] { display: none; }
.ai-status > span:not(.spin):not(.ai-dot) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ai-status svg { width: 14px; height: 14px; flex: none; }
.ai-status .btn { margin-left: 4px; flex: none; }
.ai-status.run { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }
.ai-status.done { color: var(--ok); }
.ai-status.err { color: var(--bad); }
.ai-status.wait { color: var(--warn-ink, #8a5a00); background: var(--warn-soft, #fff4d6); border-color: var(--warn-line, #f0d28a); }
.ai-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; animation: ai-pulse 1.4s ease-in-out infinite; }
@keyframes ai-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.7); } }
/* thanh chạy dưới đầu panel khi AI đang làm việc */
.ai-head::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: transparent; overflow: hidden; }
.is-running .ai-head::after { background: linear-gradient(90deg, transparent 0, var(--accent) 40%, transparent 80%); background-size: 40% 100%; background-repeat: no-repeat; animation: ai-run 1.3s linear infinite; }
@keyframes ai-run { from { background-position: -40% 0; } to { background-position: 140% 0; } }
.ai-pill-live { display: inline-flex; align-items: center; gap: 5px; }
.ai-plan-hint { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; padding: 8px 10px; border-radius: 10px; font-size: 12px;
  color: var(--warn-ink, #8a5a00); background: var(--warn-soft, #fff4d6); border: 1px solid var(--warn-line, #f0d28a); }
@media (prefers-reduced-motion: reduce) { .ai-dot, .is-running .ai-head::after { animation: none; } }

