/* Panel AI bên phải trong màn nghiệp vụ — spec 020 L10 (ui/ui-spec-l10.md, phác thảo l10-prototype.html v5).
   Token Fastdo Design System v0.1 (docs/design-system/DESIGN.md) + 5 token AI CỤC BỘ (BR-DE-032): khai dưới selector
   của panel, không khai ở :root, để không lan ra phần còn lại của hệ thống.
   .fd-ai-ui: cùng bộ token cho /ai, composer và modal Cài đặt AI dùng chung (yêu cầu user 2026-10-20: đồng bộ panel và /ai). */
.fd-ai-panel,
.fd-ai-panel-fab,
.fd-ai-ui {
  --ds-color-brand-primary: #346bda;
  --ds-color-brand-primary-subtle: #e8edf8;
  --ds-color-surface: #ffffff;
  --ds-color-page: #fafafa;
  --ds-color-text: #2b2b2b;
  --ds-color-text-muted: #5a5a5f;
  --ds-color-border: #ebebec;
  --ds-color-divider: #eeeff2;
  --ds-color-danger: #f24949;
  --ds-font-family-sans: "Inter", "Segoe UI", Arial, sans-serif;
  --ds-font-size-xs: 0.75rem;
  --ds-font-size-sm: 0.875rem;
  --ds-space-1: 0.25rem;
  --ds-space-2: 0.5rem;
  --ds-space-3: 0.75rem;
  --ds-space-4: 1rem;
  --ds-radius-sm: 0.25rem;
  --ds-radius-md: 0.375rem;
  --ds-radius-lg: 0.5rem;
  --ds-radius-xl: 0.75rem;
  --ds-radius-pill: 9999px;
  --ds-shadow-sm: 0 0 4px rgb(0 0 0 / 10%);
  --ds-duration-normal: 200ms;
  --ds-easing-standard: ease-out;
  /* Thang z-index thật của app: sidebar sticky 997, header 9999 — panel phải nằm giữa (token DS 500 thấp hơn sidebar). */
  --fd-ai-panel-z: 998;
  --ds-color-success-ink: #257953;
  --ds-color-warning-ink: #946c00;
  --ds-color-warning-95: #fffaeb;
  --ds-color-danger-ink: #cc0f0f;
  --ds-color-danger-95: #feecec;
  /* Lớp AI theo nhận diện Fastdo: vàng logo (logo_fastdo.svg #FCD42C/#FDE580) đánh dấu chỗ có AI, xanh primary cho hành động.
     --ds-ai-accent là màu CHỮ trên nền vàng nhạt (đủ tương phản); vàng tươi dùng --fd-yellow. */
  --fd-yellow: #fcd42c;
  --fd-yellow-strong: #f2b705;
  --ds-ai-accent: #7a5d00;
  --ds-ai-gradient: linear-gradient(135deg, #346bda 0%, #2c59b4 100%);
  --ds-ai-ring: linear-gradient(100deg, #346bda 0%, #346bda 55%, #fcd42c 100%);
  --ds-ai-subtle: #fff8d9;
  --ds-ai-border: #f3dc7c;
  --ds-ai-glow: 0 4px 18px rgb(252 212 44 / 30%);
  --fd-ai-warn-meter: #f59f00;
  /* Dấu AI: tia sét hình học 2 mảnh, full vàng. Nút nổi dùng bản tối trên nền vàng (.fd-ai-fab-icon). */
  --fd-ai-mark-top: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M14.5 1 4 14h8z' fill='%23FCD42C'/%3E%3C/svg%3E");
  --fd-ai-mark-bottom: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9.5 23 20 10h-8z' fill='%23FCD42C'/%3E%3C/svg%3E");
  font-family: var(--ds-font-family-sans);
}

/* Dấu AI (thay ký tự ✦ cũ). is-live: 2 mảnh tách nhẹ rồi khớp lại khi trợ lý đang trả lời. */
.fd-ai-mark {
  position: relative;
  display: inline-block;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
}
.fd-ai-mark::before,
.fd-ai-mark::after {
  content: "";
  position: absolute;
  inset: 0;
  background: center / contain no-repeat;
}
.fd-ai-mark::before { background-image: var(--fd-ai-mark-top); }
.fd-ai-mark::after { background-image: var(--fd-ai-mark-bottom); }
.fd-ai-mark.is-sm { width: 16px; height: 16px; }
.fd-ai-mark.is-md { width: 26px; height: 26px; }
.fd-ai-mark.is-lg { width: 52px; height: 52px; }
.fd-ai-mark.is-live::before { animation: fd-ai-bolt-a 1.2s ease-in-out infinite; }
.fd-ai-mark.is-live::after { animation: fd-ai-bolt-b 1.2s ease-in-out infinite; }
@keyframes fd-ai-bolt-a { 0%, 100% { transform: none; } 50% { transform: translate(-1.5px, -1.5px); } }
@keyframes fd-ai-bolt-b { 0%, 100% { transform: none; } 50% { transform: translate(1.5px, 1.5px); } }
@media (prefers-reduced-motion: reduce) {
  .fd-ai-mark.is-live::before, .fd-ai-mark.is-live::after { animation: none; }
}

/* Nút nổi góc phải dưới */
.fd-ai-panel-fab {
  position: fixed;
  right: var(--ds-space-4);
  /* Cao hơn nhãn phiên bản (.fastdo_version) ở góc phải dưới, thấp hơn nút .extension. */
  bottom: 2.5rem;
  z-index: var(--fd-ai-panel-z);
  display: inline-flex;
  align-items: center;
  gap: var(--ds-space-2);
  border: 0;
  border-radius: var(--ds-radius-pill);
  padding: var(--ds-space-2) var(--ds-space-4);
  background: linear-gradient(135deg, var(--fd-yellow) 0%, var(--fd-yellow-strong) 100%);
  color: #2b2b2b;
  font-size: var(--ds-font-size-xs);
  font-weight: 600;
  box-shadow: var(--ds-ai-glow);
  cursor: pointer;
  transition: transform var(--ds-duration-normal) var(--ds-easing-standard);
}
.fd-ai-panel-fab:hover { transform: translateY(-1px); }
.fd-ai-panel-fab { touch-action: none; user-select: none; }
.fd-ai-panel-fab.is-dragging { cursor: grabbing; transform: none; transition: none; }
.fd-ai-panel-fab:focus-visible { outline: 2px solid var(--ds-color-brand-primary); outline-offset: 2px; }
.fd-ai-fab-icon { position: relative; width: 16px; height: 16px; flex-shrink: 0; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M14.5 1 4 14h8z' fill='%232b2b2b'/%3E%3Cpath d='M9.5 23 20 10h-8z' fill='%232b2b2b'/%3E%3C/svg%3E") center / contain no-repeat; }
.fd-ai-panel-fab-dot {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ds-color-brand-primary);
  border: 2px solid var(--fd-yellow);
  animation: fd-ai-blink 1.2s infinite ease-in-out;
}

/* Panel */
.fd-ai-panel {
  position: fixed;
  /* Dưới header cố định của app (section.shadow-1, z-index 9999, cao --ds-header-height) để header vẫn dùng được. */
  top: 3.25rem;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 100vw;
  z-index: var(--fd-ai-panel-z);
  display: flex;
  flex-direction: column;
  background: var(--ds-color-surface);
  color: var(--ds-color-text);
  border-left: 1px solid var(--ds-color-border);
  box-shadow: -4px 0 32px rgb(0 0 0 / 14%);
  font-size: var(--ds-font-size-sm);
  animation: fd-ai-slide-in var(--ds-duration-normal) var(--ds-easing-standard);
}
.fd-ai-panel::before {
  content: "";
  height: 3px;
  flex-shrink: 0;
  background: linear-gradient(90deg, var(--ds-color-brand-primary) 0 70%, var(--fd-yellow) 70% 100%);
}
@keyframes fd-ai-slide-in {
  from { transform: translateX(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.fd-ai-panel-head {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
  padding: var(--ds-space-3) var(--ds-space-4);
  border-bottom: 1px solid var(--ds-color-border);
}
.fd-ai-pill {
  display: inline-flex;
  align-items: center;
  border-radius: var(--ds-radius-pill);
  padding: 2px 10px;
  font-size: var(--ds-font-size-xs);
  font-weight: 600;
  background: var(--ds-ai-subtle);
  color: var(--ds-ai-accent);
  border: 1px solid var(--ds-ai-border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}
.fd-ai-icon-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--ds-radius-md);
  background: transparent;
  color: var(--ds-color-text-muted);
  cursor: pointer;
}
.fd-ai-icon-btn .material-icons-outlined { font-size: 18px; }
.fd-ai-icon-btn:hover { background: var(--ds-color-divider); }
.fd-ai-icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }



/* Luồng tin nhắn */
.fd-ai-panel-thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--ds-space-4);
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-4);
}
.fd-ai-panel-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--ds-space-4);
}
.fd-ai-chips { display: flex; flex-direction: column; gap: var(--ds-space-2); margin-top: var(--ds-space-4); width: 100%; }
.fd-ai-chip {
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-pill);
  background: var(--ds-color-surface);
  padding: 6px 12px;
  font-size: var(--ds-font-size-xs);
  text-align: left;
  cursor: pointer;
  color: var(--ds-color-text);
}
.fd-ai-chip::before { content: ""; display: inline-block; width: 11px; height: 11px; margin-right: 6px; vertical-align: -1px; background: var(--fd-ai-mark-top) center / contain no-repeat, var(--fd-ai-mark-bottom) center / contain no-repeat; }
.fd-ai-chip:hover { border-color: var(--ds-ai-border); background: var(--ds-ai-subtle); }

.fd-ai-msg { display: flex; gap: var(--ds-space-2); }
.fd-ai-msg.is-user { justify-content: flex-end; }
.fd-ai-bubble {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 14px 14px 4px 14px;
  background: var(--ds-color-brand-primary);
  color: #fff;
  white-space: pre-wrap;
  word-break: break-word;
}
.fd-ai-body { flex: 1; min-width: 0; }
.fd-ai-text { line-height: 1.6; word-break: break-word; }
.fd-ai-text table { font-size: var(--ds-font-size-xs); display: block; overflow-x: auto; }
.fd-ai-card {
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-lg);
  overflow: hidden;
  margin-top: var(--ds-space-2);
}
.fd-ai-card.fd-ai-ask { padding: var(--ds-space-3); border-top: 3px solid var(--fd-yellow); }
.fd-ai-actions { display: flex; align-items: center; gap: var(--ds-space-2); margin-top: var(--ds-space-3); }
.fd-ai-actions.is-wrap { flex-wrap: wrap; }

.fd-ai-think { display: flex; align-items: center; gap: var(--ds-space-2); font-size: var(--ds-font-size-xs); color: var(--ds-color-text-muted); }
.fd-ai-dots i {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 3px;
  border-radius: 50%;
  background: var(--fd-yellow-strong);
  animation: fd-ai-bounce 1.2s infinite ease-in-out;
}
.fd-ai-dots i:nth-child(2) { animation-delay: 0.15s; }
.fd-ai-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes fd-ai-bounce { 0%, 80%, 100% { opacity: 0.25; transform: none; } 40% { opacity: 1; transform: translateY(-3px); } }
@keyframes fd-ai-blink { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }

/* Ô nhập */
.fd-ai-compose { padding: 0 var(--ds-space-4) var(--ds-space-3); }

/* Mở panel thì trang thu hẹp sang trái, không bị che (user 2026-10-19). Chỉ desktop — mobile panel phủ toàn màn.
   Nút nổi cố định ở góc phải của app (.extension, .fastdo_version) dời theo để không nằm dưới panel. */
@media (min-width: 769px) {
  body:has(.fd-ai-panel) { padding-right: 380px; }
  body:has(.fd-ai-panel) .extension,
  body:has(.fd-ai-panel) .fastdo_version { margin-right: 380px; }
  /* Drawer dùng chung của app (.slider, fixed right:0, vd "Tạo đơn từ") trượt ra cạnh panel, không nằm dưới — nút Gửi/Lưu ở mép phải. */
  body:has(.fd-ai-panel) .slider.is-active { right: 380px; width: calc(100vw - 380px); }
}
@media (max-width: 768px) {
  .fd-ai-panel { width: 100vw; border-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .fd-ai-panel, .fd-ai-dots i, .fd-ai-panel-fab-dot { animation: none; }
}

/* Chú thích khi bấm link trỏ đúng trang đang mở (ai-panel.js). */
.fd-ai-link-hint {
  display: inline-block;
  margin-left: var(--ds-space-2);
  padding: 0 var(--ds-space-2);
  border-radius: var(--ds-radius-pill);
  background: var(--ds-ai-subtle);
  color: var(--ds-ai-accent);
  font-size: var(--ds-font-size-xs);
}

/* Chọn agent theo vị trí (P6) — dòng ngay dưới đầu panel. */
.fd-ai-agent-bar {
  display: flex;
  align-items: center;
  gap: var(--ds-space-2);
  padding: var(--ds-space-2) var(--ds-space-4);
  border-bottom: 1px solid var(--ds-color-border);
  font-size: var(--ds-font-size-xs);
}
.fd-ai-agent-label { color: var(--ds-color-text-muted); white-space: nowrap; }
.fd-ai-agent-select {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-md);
  background: var(--ds-color-surface);
  color: var(--ds-color-text);
  padding: 4px 8px;
  font-size: var(--ds-font-size-xs);
}
/* Agent không có module của màn — cùng kiểu notice viền trái dày (blazor-page-layout §4). */
.fd-ai-agent-notice {
  display: flex;
  gap: var(--ds-space-2);
  margin: var(--ds-space-2) var(--ds-space-4) 0;
  padding: var(--ds-space-2) var(--ds-space-3);
  background: var(--bulma-warning-95);
  border: 1px solid var(--ds-color-border);
  border-left: 3px solid var(--bulma-warning);
  border-radius: var(--ds-radius-md);
  font-size: var(--ds-font-size-xs);
  color: var(--ds-color-text);
}
.fd-ai-agent-notice .material-icons-outlined { font-size: 16px; color: var(--bulma-warning-30); }
.fd-ai-agent-reset {
  background: none;
  border: none;
  padding: 0;
  margin-top: 2px;
  color: #346BDA;
  text-decoration: underline;
  cursor: pointer;
  font-size: inherit;
}

/* ===== Ô nhập dùng chung /ai + panel (_AiComposer.razor) ===== */
.fd-ai-cmp-wrap { display: flex; flex-direction: column; gap: var(--ds-space-2); width: 100%; max-width: 760px; margin: 0 auto; }
.fd-ai-cmp-notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 12px;
  border: 1px solid var(--ds-color-border);
  border-left: 3px solid var(--bulma-warning, #ffdd57);
  background: var(--ds-color-warning-95);
  border-radius: var(--ds-radius-lg);
  font-size: var(--ds-font-size-xs);
  color: var(--ds-color-text);
}
.fd-ai-cmp-notice p { margin: 0; }
.fd-ai-cmp-notice .material-icons-outlined { font-size: 17px; color: var(--ds-color-warning-ink); }
.fd-ai-cmp-notice.is-danger { border-left-color: var(--ds-color-danger); background: var(--ds-color-danger-95); }
.fd-ai-cmp-notice.is-danger .material-icons-outlined { color: var(--ds-color-danger-ink); }
.fd-ai-cmp-notice.is-info { border-left-color: var(--fd-yellow); background: var(--ds-ai-subtle); }
.fd-ai-cmp-notice.is-info .material-icons-outlined { color: var(--ds-ai-accent); }
.fd-ai-cmp {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  border-radius: var(--ds-radius-xl);
  border: 1.5px solid transparent;
  background: linear-gradient(var(--ds-color-surface), var(--ds-color-surface)) padding-box, var(--ds-ai-ring) border-box;
  box-shadow: var(--ds-ai-glow);
}
.fd-ai-cmp.is-drag-over { background: linear-gradient(var(--ds-ai-subtle), var(--ds-ai-subtle)) padding-box, var(--ds-ai-ring) border-box; }
.fd-ai-cmp-input {
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  font: inherit;
  font-size: var(--ds-font-size-sm);
  line-height: 1.5;
  color: var(--ds-color-text);
  padding: 6px 8px;
  min-height: 40px;
  max-height: 220px;
}
.fd-ai-cmp-input::placeholder { color: #8a8a90; }
.fd-ai-cmp-bar { display: flex; align-items: center; gap: 2px; }
.fd-ai-cmp-grow { flex: 1; }
.fd-ai-cmp-btn {
  position: relative;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--ds-radius-md);
  background: transparent;
  color: var(--ds-color-text-muted);
  cursor: pointer;
}
.fd-ai-cmp-btn .material-icons-outlined { font-size: 18px; }
.fd-ai-cmp-btn:hover { background: var(--ds-color-divider); color: var(--ds-color-text); }
.fd-ai-cmp-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.fd-ai-cmp-badge {
  position: absolute;
  top: 1px;
  right: 0;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: var(--ds-radius-pill);
  background: var(--fd-yellow);
  color: #2b2b2b;
  font-size: 9.5px;
  font-weight: 600;
  line-height: 14px;
  text-align: center;
}
.fd-ai-cmp-mode {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 26px;
  padding: 0 6px 0 9px;
  margin-left: 2px;
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-pill);
  font-size: 11.5px;
  color: var(--ds-color-text-muted);
  white-space: nowrap;
  cursor: pointer;
}
.fd-ai-cmp-mode .material-icons-outlined { font-size: 16px; }
.fd-ai-cmp-mode:hover { border-color: var(--ds-ai-border); color: var(--ds-color-text); }
.fd-ai-cmp-mode.is-auto { background: var(--ds-ai-subtle); border-color: var(--ds-ai-border); color: var(--ds-ai-accent); }
.fd-ai-cmp-send {
  width: 32px;
  height: 32px;
  margin-left: 2px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--ds-radius-md);
  background: var(--ds-color-brand-primary);
  color: #fff;
  cursor: pointer;
}
.fd-ai-cmp-send .material-icons-outlined { font-size: 18px; }
.fd-ai-cmp-send:hover { background: #2c59b4; }
.fd-ai-cmp-send:disabled { opacity: 0.4; cursor: not-allowed; }
.fd-ai-cmp-send.is-stop { background: var(--ds-color-text-muted); }
.fd-ai-cmp-disclaimer { font-size: 11px; color: var(--ds-color-text-muted); text-align: center; }
.fd-ai-cmp-wrap.is-compact .fd-ai-cmp-mode { padding: 0 4px 0 7px; }

/* Vòng hạn mức */
.fd-ai-ring {
  --p: 0;
  --c: var(--ds-color-brand-primary);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--ds-color-divider) 0);
  display: inline-grid;
  place-items: center;
}
.fd-ai-ring::after { content: ""; width: 13px; height: 13px; border-radius: 50%; background: var(--ds-color-surface); }
.fd-ai-ring.is-warn { --c: var(--fd-ai-warn-meter); }
.fd-ai-ring.is-over { --c: var(--ds-color-danger); }

/* Chip tệp đính kèm */
.fd-ai-cmp-atts { display: flex; gap: 6px; overflow-x: auto; padding: 4px 4px 2px; }
.fd-ai-att {
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  max-width: 200px;
  padding: 6px 24px 6px 6px;
  border: 1px solid var(--ds-color-border);
  border-radius: var(--ds-radius-lg);
  background: #f7f8fa;
  color: var(--ds-color-text);
  text-decoration: none;
}
.fd-ai-att:hover { border-color: var(--ds-ai-border); color: var(--ds-color-text); }
.fd-ai-att.is-img { width: 48px; padding: 0; overflow: hidden; }
.fd-ai-att.is-img img { width: 100%; height: 100%; object-fit: cover; }
.fd-ai-att.is-paste { flex-direction: column; align-items: flex-start; justify-content: center; gap: 1px; padding: 6px 22px 6px 10px; }
.fd-ai-att.is-uploading { width: 48px; padding: 0; justify-content: center; }
.fd-ai-att.is-sent { height: 40px; padding-right: 10px; background: var(--ds-color-surface); }
.fd-ai-att.is-sent.is-img { width: 40px; padding: 0; }
.fd-ai-att-type {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--ds-radius-md);
  color: #fff;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.fd-ai-att.is-sent .fd-ai-att-type { width: 26px; height: 26px; font-size: 8.5px; }
.fd-ai-att-name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fd-ai-att-tag { font-size: 9px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ds-ai-accent); }
.fd-ai-att-sub { font-size: 10.5px; color: #8a8a90; white-space: nowrap; }
.fd-ai-att-x {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 17px;
  height: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: var(--ds-color-text-muted);
  color: #fff;
  cursor: pointer;
}
.fd-ai-att-x .material-icons-outlined { font-size: 12px; }
.fd-ai-att-spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--ds-color-divider);
  border-top-color: var(--ds-color-brand-primary);
  animation: fd-ai-spin 0.8s linear infinite;
}
@keyframes fd-ai-spin { to { transform: rotate(360deg); } }
.fd-ai-msg-atts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 4px; }

/* Menu thả xuống của ô nhập (render qua Dropdown dùng chung) */
.fd-ai-cmp-menu { min-width: 260px; padding: 6px !important; font-size: var(--ds-font-size-sm); }
.fd-ai-cmp-menu.is-wide { width: 300px; }
.fd-ai-cmp-menu.is-usage { width: 320px; padding: 14px !important; }
.fd-ai-cmp-menu-h { padding: 6px 9px 3px; font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; color: #8a8a90; font-weight: 600; }
.fd-ai-cmp-row { display: flex; align-items: center; gap: 10px; padding: 6px 9px; border-radius: var(--ds-radius-md); }
.fd-ai-cmp-row-meta { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.fd-ai-cmp-row-meta b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fd-ai-cmp-row-meta small { font-size: 11px; color: #8a8a90; }
.fd-ai-cmp-row-meta small.is-warn { color: var(--ds-color-warning-ink); }
.fd-ai-cmp-hint { font-size: 11px; color: #8a8a90; white-space: nowrap; }
.fd-ai-cmp-logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--ds-radius-md);
  background: var(--ds-color-brand-primary-subtle);
  color: var(--ds-color-brand-primary);
  font-weight: 700;
  font-size: 12px;
}
.fd-ai-cmp-error { margin: 4px 9px; font-size: 11.5px; color: var(--ds-color-danger-ink); }
.fd-ai-cmp-sep { margin: 4px 2px; height: 1px; border: 0; background: var(--ds-color-divider); }
.fd-ai-cmp-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 9px;
  border: 0;
  border-radius: var(--ds-radius-md);
  background: none;
  color: var(--ds-color-text);
  text-align: left;
  cursor: pointer;
}
.fd-ai-cmp-item small { display: block; font-size: 11px; color: #8a8a90; }
.fd-ai-cmp-item .material-icons-outlined { font-size: 18px; color: var(--ds-color-text-muted); }
.fd-ai-cmp-item:hover { background: var(--ds-color-divider); }
.fd-ai-cmp-item.is-active { background: var(--ds-ai-subtle); }
.fd-ai-cmp-item.is-active .material-icons-outlined { color: var(--ds-ai-accent); }
.fd-ai-cmp-usage-foot {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--ds-color-divider);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
  color: var(--ds-color-text-muted);
}
.fd-ai-link { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; padding: 0; color: #346bda; font-weight: 500; font-size: inherit; cursor: pointer; }
.fd-ai-link:hover { text-decoration: underline; }
.fd-ai-link .material-icons-outlined { font-size: 16px; }
/* Toggle bật/tắt: icon toggle_on/off theo blazor-page-layout §6 */
.fd-ai-toggle { display: inline-flex; align-items: center; border: 0; background: none; padding: 0; color: #b5b5b5; cursor: pointer; }
.fd-ai-toggle .material-icons-outlined { font-size: 30px; }
.fd-ai-toggle .material-icons-outlined.is-on { color: var(--ds-color-brand-primary); }
.fd-ai-toggle:disabled { opacity: 0.5; cursor: not-allowed; }

/* Hạn mức (_AiUsageSummary) */
.fd-ai-usage { display: flex; flex-direction: column; gap: 14px; }
.fd-ai-usage-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.fd-ai-usage-head b { font-weight: 600; }
.fd-ai-usage-head span { font-size: 11px; color: #8a8a90; }
.fd-ai-usage-sec { display: flex; flex-direction: column; gap: 10px; }
.fd-ai-usage-sec h5 { margin: 0; font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; color: #8a8a90; font-weight: 600; }
.fd-ai-usage-row { display: flex; flex-direction: column; gap: 4px; }
.fd-ai-usage-top { display: flex; justify-content: space-between; gap: 8px; }
.fd-ai-usage-top b { font-weight: 600; font-variant-numeric: tabular-nums; }
.fd-ai-usage-reset { font-size: 11px; color: #8a8a90; font-variant-numeric: tabular-nums; }
.fd-ai-usage-empty { margin: 0; font-size: var(--ds-font-size-xs); color: var(--ds-color-text-muted); }
.fd-ai-meter { height: 6px; background: var(--ds-color-divider); border-radius: 3px; overflow: hidden; }
.fd-ai-meter i { display: block; height: 100%; background: var(--ds-color-brand-primary); border-radius: 3px; }
.fd-ai-meter.is-warn i { background: var(--fd-ai-warn-meter); }
.fd-ai-meter.is-over i { background: var(--ds-color-danger); }

/* ===== Modal (dán văn bản, Cài đặt AI) — trên header app (z 9999) và panel ===== */
.modal.fd-ai-modal { z-index: 10001; }
.fd-ai-modal-card {
  width: min(880px, calc(100vw - 32px));
  height: min(640px, 90vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--ds-radius-xl);
  background: var(--ds-color-surface);
  box-shadow: 0 4px 32px rgb(0 0 0 / 14%);
}
.fd-ai-modal-card.is-sm { width: min(620px, calc(100vw - 32px)); height: auto; max-height: 90vh; }
.fd-ai-modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--ds-color-border); }
.fd-ai-modal-head h3 { margin: 0; flex: 1; min-width: 0; font-size: 1rem; font-weight: 600; }
.fd-ai-modal-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; overflow: auto; }
.fd-ai-modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--ds-color-border); }
.fd-ai-paste-area { min-height: 200px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.fd-ai-settings { flex: 1; min-height: 0; display: flex; }
.fd-ai-settings-nav { width: 200px; flex-shrink: 0; display: flex; flex-direction: column; gap: 2px; padding: 10px 8px; border-right: 1px solid var(--ds-color-border); background: #f7f8fa; }
.fd-ai-settings-nav button {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--ds-radius-md);
  background: none;
  color: var(--ds-color-text-muted);
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}
.fd-ai-settings-nav button .material-icons-outlined { font-size: 18px; }
.fd-ai-settings-nav button:hover { background: var(--ds-color-divider); color: var(--ds-color-text); }
.fd-ai-settings-nav button.is-active { background: var(--ds-color-brand-primary-subtle); color: var(--ds-color-brand-primary); font-weight: 500; }
.fd-ai-settings-body { flex: 1; min-width: 0; overflow: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 20px; }
.fd-ai-settings-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.fd-ai-settings-head h4 { margin: 0; font-size: var(--ds-font-size-sm); font-weight: 600; }
.fd-ai-settings-head p { margin: 2px 0 0; font-size: var(--ds-font-size-xs); color: var(--ds-color-text-muted); }
.fd-ai-settings-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.fd-ai-settings-actions .material-icons-outlined, .fd-ai-settings-body .button .material-icons-outlined { font-size: 16px; margin-right: 4px; }
.fd-ai-list { border: 1px solid var(--ds-color-border); border-radius: var(--ds-radius-xl); overflow: hidden; }
.fd-ai-list-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--ds-color-divider); }
.fd-ai-list-row:last-child { border-bottom: 0; }
.fd-ai-list-icon { color: var(--fd-yellow-strong); }
.fd-ai-wrap { white-space: normal; overflow-wrap: anywhere; }
.fd-ai-stat { border: 1px solid var(--ds-color-border); border-radius: var(--ds-radius-xl); padding: 14px; }
.fd-ai-status { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 500; color: #8a8a90; }
.fd-ai-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.fd-ai-status.is-ok { color: var(--ds-color-success-ink); }
.fd-ai-status.is-warn { color: var(--ds-color-warning-ink); }
.fd-ai-status.is-danger { color: var(--ds-color-danger-ink); }
.fd-ai-search { display: flex; align-items: center; gap: 6px; max-width: 360px; padding: 5px 9px; border: 1px solid #dbdbdb; border-radius: var(--ds-radius-md); color: #8a8a90; }
.fd-ai-search input { border: 0; outline: 0; background: transparent; width: 100%; font: inherit; color: var(--ds-color-text); }
.fd-ai-catalog { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.fd-ai-catalog-card { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--ds-color-border); border-radius: var(--ds-radius-lg); }
.fd-ai-catalog-card .fd-ai-cmp-row-meta small { white-space: normal; }
.fd-ai-catalog-act { margin-top: 8px; display: flex; gap: 6px; align-items: center; }
@media (max-width: 768px) {
  .fd-ai-settings { flex-direction: column; }
  .fd-ai-settings-nav { width: auto; flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--ds-color-border); }
}

/* Tin nhắn người dùng có tệp trong panel: chip trên, bong bóng dưới */
.fd-ai-user-msg { display: flex; flex-direction: column; align-items: flex-end; max-width: 85%; }
.fd-ai-user-msg .fd-ai-bubble { max-width: 100%; }
/* /ai: dấu AI cạnh tên trang, khung đang suy nghĩ */
.ai-brand-row .fd-ai-mark { margin-right: 2px; }
.ai-chat-shell .ai-composer-wrap .fd-ai-cmp-wrap { max-width: 760px; }
