  :root {
    /* HUTECH identity — blue-dominant, orange/red accents.
       #0063cd chủ đạo; cam (#F7941D) = nút hành động + viền avatar; đỏ (#ED1B24) = cảnh báo. */
    --brand:       #0063CD;   /* màu chủ đạo */
    --brand-deep:  #034AA0;   /* nền gradient sâu / trạng thái nhấn */
    --brand-sky:   #EAF2FD;   /* nền bong bóng bot, chip */
    --brand-ink:   #FFFFFF;   /* chữ/icon trên nền xanh */
    --accent:      #F7941D;   /* Vàng Cam HUTECH — CTA + viền avatar */
    --accent-deep: #E07600;   /* cam đậm khi hover */
    --danger:      #ED1B24;   /* đỏ cảnh báo — huy hiệu, chặn quyền, deadline gấp */
    --bg:          #F2F6FC;
    --surface:     #FFFFFF;
    --ink:         #16243D;
    --muted:       #5C6B85;
    --line:        #E2E9F3;
    --radius: 16px;
    --shadow: 0 14px 34px -16px rgba(3, 74, 160, 0.40);
    --font: "Be Vietnam Pro", system-ui, "Segoe UI", Roboto, sans-serif;
    font-synthesis: none;
  }
  * { box-sizing: border-box; }
  body {
    margin: 0; background: var(--bg); color: var(--ink);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
    display: grid; place-items: center; padding: 24px;
    min-height: 100vh; min-height: 100dvh;   /* dvh: theo viewport THẬT trên mobile (trừ thanh URL) */
  }
  .app {
    width: min(calc(680px + 2em), 100%); background: var(--surface);
    border-radius: var(--radius); box-shadow: var(--shadow);
    overflow: hidden; display: flex; flex-direction: column;
    height: 92vh; height: 92dvh;                           /* dvh: không tính thanh URL mobile */
    max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px);   /* trừ padding body */
  }

  /* ── Mobile: card lấp đầy màn hình, không padding/bo góc — hết tràn chiều cao ── */
  @media (max-width: 600px) {
    body { padding: 0; }
    .app {
      width: 100%; height: 100vh; height: 100dvh;
      max-height: none; border-radius: 0; box-shadow: none;
    }
    .chat { padding: 14px 12px; }
    .row { max-width: 94%; }
    /* 16px trở lên để iOS không tự zoom khi chạm vào ô nhập */
    .composer input { font-size: 16px; }
  }

  /* ── Header: nền chuyển hoàn toàn sang #0063cd (Global Nav HUTECH) ──
     Gradient mảnh để có chiều sâu; gạch cam mỏng dưới chân = "sợi chỉ cam" thương hiệu. */
  header {
    position: relative;
    background: linear-gradient(150deg, #0A6FDB 0%, var(--brand) 46%, var(--brand-deep) 100%);
    color: var(--brand-ink); padding: 16px 20px;
    display: flex; align-items: center; gap: 13px;
    box-shadow: inset 0 -3px 0 0 var(--accent);   /* gạch nhấn Vàng Cam */
  }
  /* Logo HUTECH: ô trắng, chữ xanh chủ đạo + chấm spark cam → mảng nhận diện trên nền xanh mới. */
  header .logo {
    position: relative;
    width: 40px; height: 40px; border-radius: 12px; flex: none;
    display: grid; place-items: center;
    background: #FFFFFF; color: var(--brand);
    font-weight: 800; font-size: 19px; letter-spacing: -1px;
    box-shadow: 0 4px 10px -4px rgba(3, 74, 160, 0.55);
  }
  header .logo::after {           /* spark cam — đầu mối "sợi chỉ" thương hiệu */
    content: ""; position: absolute; right: -3px; top: -3px;
    width: 11px; height: 11px; border-radius: 50%;
    background: var(--accent); border: 2px solid #FFFFFF;
  }
  header h1 { font-size: 15.5px; margin: 0; font-weight: 700; letter-spacing: -.2px; }
  header p { margin: 2px 0 0; font-size: 12px; opacity: .9; }
  .badge {
    margin-left: auto; font-size: 11px; font-weight: 700; padding: 4px 10px;
    border-radius: 999px; background: var(--danger); color: #fff;   /* huy hiệu cảnh báo đỏ */
    box-shadow: 0 2px 6px -2px rgba(237, 27, 36, 0.6);
  }
  /* Nút đóng: chỉ hiện khi nhúng trong bong bóng (có panel để đóng); ghost trắng trên nền xanh. */
  .hdr-close {
    display: none; margin-left: auto; flex: none; padding: 0;
    width: 30px; height: 30px; border-radius: 9px;
    background: rgba(255, 255, 255, 0.16); color: #fff;
    align-items: center; justify-content: center;
  }
  .hdr-close svg { display: block; }
  .hdr-close:hover { background: rgba(255, 255, 255, 0.30); filter: none; }
  .hdr-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
  body.embed-bubble .hdr-close { display: grid; }

  .toolbar {
    display: flex; align-items: center; gap: 10px; padding: 10px 16px;
    border-bottom: 1px solid var(--line); font-size: 13px; flex-wrap: wrap;
    background: var(--surface);
  }
  .toolbar label { color: var(--muted); font-weight: 600; }
  select {
    border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px;
    font: inherit; font-weight: 500; background: var(--surface); color: var(--ink); cursor: pointer;
  }
  select:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
  .toolbar .hint { color: var(--muted); font-size: 12px; }

  .chat { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
  .row { display: flex; gap: 9px; max-width: 88%; }
  .row.user { align-self: flex-end; flex-direction: row-reverse; }
  .avatar {
    width: 32px; height: 32px; border-radius: 10px; flex: none; display: grid;
    place-items: center; font-size: 13px; font-weight: 800; color: var(--brand-ink);
  }
  /* Avatar HAIA: nền xanh chủ đạo + viền Vàng Cam rực rỡ (điểm nhấn nhận diện thương hiệu). */
  .row.bot .avatar {
    background: var(--brand);
    box-shadow: 0 0 0 2px var(--accent), 0 2px 6px -2px rgba(3, 74, 160, 0.5);
  }
  .row.user .avatar { background: var(--muted); border-radius: 10px; }
  .bubble {
    padding: 11px 14px; border-radius: 14px; line-height: 1.55; font-size: 14px;
    white-space: pre-wrap; word-wrap: break-word;
  }
  .row.bot .bubble {
    background: var(--brand-sky); color: var(--ink);
    border: 1px solid #D6E6FB; border-top-left-radius: 4px;
  }
  .row.user .bubble {
    background: var(--brand); color: var(--brand-ink); border-top-right-radius: 4px;
  }
  .meta { font-size: 11px; color: var(--muted); margin-top: 6px; font-weight: 500; }
  .meta.alert { color: var(--danger); font-weight: 700; }   /* đỏ — chặn quyền / lỗi gấp */
  .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
  /* Chip nguồn: tông xanh chủ đạo (như tiêu đề học phần "SOFTWARE ENGINEERING"). */
  .chip {
    font-size: 11px; padding: 3px 10px; border-radius: 999px;
    background: var(--brand-sky); color: var(--brand); font-weight: 600;
    border: 1px solid #D6E6FB;
  }

  /* Thẻ phê duyệt hành động ghi: cảnh báo cam (caution), tách bạch khỏi đỏ (urgent/blocked). */
  .approval {
    border: 1.5px solid var(--accent); border-radius: 13px; padding: 13px 15px;
    background: #FFF6EB;
  }
  .approval h3 { margin: 0 0 8px; font-size: 13px; font-weight: 700; color: var(--accent-deep); }
  .approval .diff { font-size: 13px; margin: 3px 0; }
  .approval .diff b { color: var(--ink); font-weight: 700; }
  .approval .actions { display: flex; gap: 8px; margin-top: 11px; }
  .approval-done { font-size: 13px; font-weight: 600; color: var(--muted); }

  button {
    font: inherit; font-weight: 700; border: none; border-radius: 10px;
    padding: 8px 14px; cursor: pointer; transition: transform .08s ease, filter .15s ease, box-shadow .15s ease;
  }
  button:hover { filter: brightness(1.03); }
  button:active { transform: translateY(1px); }
  button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
  /* CTA chính = Vàng Cam HUTECH: tương phản rực rỡ với nền xanh, dễ nhận diện thao tác. */
  .btn-approve {
    background: var(--accent); color: #fff;
    box-shadow: 0 6px 14px -6px rgba(247, 148, 29, 0.7);
  }
  .btn-approve:hover { background: var(--accent-deep); filter: none; }
  .btn-reject { background: #EEF1F6; color: var(--ink); }
  .btn-reject:hover { background: #E2E7EF; filter: none; }

  .composer { padding: 12px 16px; border-top: 1px solid var(--line); background: var(--surface); }
  .composer-inner {
    display: flex; align-items: center; gap: 0;
    background: var(--bg); border: 1.5px solid var(--line);
    border-radius: 24px; padding: 4px 6px 4px 16px;
    transition: border-color .2s ease, box-shadow .2s ease;
  }
  .composer-inner:focus-within {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(0, 99, 205, 0.10);
  }
  .composer input {
    flex: 1; border: none; background: transparent; padding: 10px 8px 10px 0;
    font: inherit; font-weight: 500; color: var(--ink); outline: none;
  }
  .composer input::placeholder { color: #9AA7BC; }
  /* Nút gửi: hình tròn icon mũi tên, nằm trong ô nhập — phong cách Gemini. */
  .btn-send {
    width: 36px; height: 36px; min-width: 36px; border-radius: 50%; padding: 0;
    display: grid; place-items: center;
    background: var(--brand); color: #fff;
    box-shadow: 0 2px 8px -3px rgba(0, 99, 205, 0.5);
    transition: opacity .18s ease, transform .12s ease, background .15s ease;
  }
  .btn-send:disabled {
    opacity: 0; pointer-events: none; transform: scale(0.7);
  }
  .btn-send:not(:disabled):hover {
    background: var(--brand-deep); filter: none; transform: scale(1.06);
  }
  .btn-send:not(:disabled):active { transform: scale(0.95); }
  .btn-send svg { display: block; }

  .quick { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 10px; }
  .quick button {
    background: var(--surface); color: var(--brand); font-size: 12px; font-weight: 600;
    padding: 6px 11px; border: 1px solid #CFE1F9;
  }
  .quick button:hover { background: var(--brand-sky); filter: none; }
  .btn-link { text-decoration: none; display: inline-block; }

  /* ── Typing indicator: ba chấm nảy khi bot đang xử lý ── */
  .typing-indicator {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 12px 16px; min-height: 20px;
  }
  .typing-indicator .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--brand);
    opacity: 0.35;
    animation: typing-bounce 1.4s ease-in-out infinite;
  }
  .typing-indicator .dot:nth-child(2) { animation-delay: 0.16s; }
  .typing-indicator .dot:nth-child(3) { animation-delay: 0.32s; }
  @keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
    30%            { transform: translateY(-6px); opacity: 1; }
  }

  /* Markdown render trong bong bóng bot */
  .bubble-md { white-space: normal; }
  .bubble-md > div { margin: 2px 0; }
  .bubble-md .md-h { font-weight: 700; margin: 8px 0 2px; color: var(--brand); }   /* tiêu đề tông xanh */
  .bubble-md ul, .bubble-md ol { margin: 4px 0; padding-left: 20px; }
  .bubble-md li { margin: 2px 0; }
  .bubble-md code {
    background: #DBE9FB; color: var(--brand-deep); padding: 1px 5px; border-radius: 5px;
    font-family: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, monospace; font-size: 0.9em;
  }
  .bubble-md strong { font-weight: 700; }
  .bubble-md a { color: var(--brand); font-weight: 600; }
  .bubble-progress { display: flex; flex-direction: column; gap: 4px; opacity: 0.85; font-size: 0.9em; }
  .progress-step { display: flex; align-items: center; gap: 6px; }
  .progress-step.active { font-weight: 600; }
  .progress-mark { width: 1.2em; text-align: center; }

  /* Chế độ nhúng trong bong bóng (iframe ~400x600): card lấp đầy khung. */
  body.embed-bubble { padding: 0; display: block; min-height: 0; background: transparent; }
  body.embed-bubble .app {
    width: 100%; height: 100vh; height: 100dvh; max-height: none;
    border-radius: 18px; background: var(--surface);
  }
  @media (max-width: 600px) {
    body.embed-bubble .app { border-radius: 0; }   /* panel mobile full màn → bỏ bo góc */
  }
  body.embed-bubble header {
    background: linear-gradient(150deg, #0A6FDB 0%, var(--brand) 46%, var(--brand-deep) 100%);
    border-bottom: none;
  }
  body.embed-bubble .row.bot .bubble {
    background: var(--brand-sky); border: 1px solid #D6E6FB;
    box-shadow: 0 2px 8px -5px rgba(3, 74, 160, 0.4);
  }
  body.embed-bubble .quick button {
    background: var(--surface); border-color: #CFE1F9;
  }
  body.embed-bubble .composer {
    border-top: 1px solid var(--line); background: var(--surface);
  }
  body.embed-bubble .composer-inner {
    background: var(--bg); border-color: var(--line);
  }
