:root {
  /* Light Mode */
  --bg-page: #f5f7fa;
  --bg-chat: #ffffff;
  --text-main: #1a202c;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --input-bg: #ffffff;
	--card: #f5f7fa;
  
  /* Bubble colors */
  --user-bg: #3b82f6;
  --user-text: #ffffff;
  --bot-bg: #334155;
  --bot-text: #f1f5f9;
  --bot-border: #e2e8f0;
  
  --highlight: #3b82f6;
  --modal-overlay: rgba(0, 0, 0, 0.5);
}

/* 2. CHẾ ĐỘ DARK MODE CHUẨN (Áp dụng khi body có class .dark-mode) */
body.iseoai-chatbot-page.dark-mode {
  --bg-page: #0f172a;       /* Xanh đen đậm */
  --bg-chat: #1e293b;       /* Xám xanh cho khung chat */
  --text-main: #f1f5f9;     /* Trắng mờ nhẹ */
  --text-muted: #94a3b8;
  --border-color: #334155;
  --input-bg: #0f172a;
  
  /* Bubble colors - Dark Mode */
  --user-bg: #2563eb;       /* Xanh dương đậm hơn */
  --user-text: #ffffff;
  --bot-bg: #334155;       /* Nền AI tối xám */
  --bot-text: #E1E1E1;
  --bot-border: #475569;
  
  --highlight: #60a5fa;     /* Màu nhấn sáng hơn cho nền tối */
  --modal-overlay: rgba(0, 0, 0, 0.8);
}

/* Code block trong darkmode (kết hợp với code cũ của bạn) */
body.iseoai-chatbot-page.dark-mode .page-body {
  background-color: #111;
  border: 1px solid #444;
	color: var(--text-main);
}
body.iseoai-chatbot-page.dark-mode {
  background-color: #333 !important;
}
/* CODE BLOCKS TRONG DARK MODE */
body.iseoai-chatbot-page.dark-mode .msg code {
  background-color: #0f172a;
  color: #fca5a5; /* Đỏ nhạt dễ đọc */
}

body.iseoai-chatbot-page.dark-mode .msg pre {
  background-color: #000000 !important;
  border: 1px solid #334155;
}

/* 3. ÁP DỤNG VÀO CÁC PHẦN TỬ CHÍNH */
body {
  margin: 0;
  background-color: var(--bg-page);
  color: var(--text-main);
  transition: all 0.3s ease;
  font-family: 'Inter', sans-serif; /* Gợi ý font chữ hiện đại */
}

    #chatbox {
		
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
      max-width: -webkit-fill-available;
      width: 90vw;
      margin: 0 auto;
     background: rgba(0, 0, 0, 0.75); 
      border-radius: 16px;
      display: flex;
      flex-direction: column;
     height: calc(100vh);
      position: relative;
    }
    #messages {
      padding: 10px;
      overflow-y: auto;
      flex-direction: column;
      gap: 16px;
	min-height: 50vh;
	height: -webkit-fill-available;
	box-shadow: 0 4px 40px -1px rgba(0, 0, 0, 0.1), 0 32px 22px -1px rgba(0, 0, 0, 0.06);
	color: #1da6cf;
	place-content: center;
    }
    .msg {
      max-width: 95%;
	width: fit-content;
      position: relative;
      padding: 10px 10px;
      border-radius: 15px;
      line-height: 1.5;
      word-wrap: break-word;
		margin: 5px 0px;
    }
.msg h1, .msg  h2, .msg h3, .msg  h4{color:var(--bot-text)}
	.you{
    background: rgba(255, 255, 255, 0.1);
    margin-left: auto;
    border-right: 3px solid #888;
    color: white;
	}
    .bot {
      background: var(--bot-bg);
      align-self: flex-start;
      color: var(--bot-text);;
   	border-left: 3px solid #00ffd5;
    }
    .user {
      background: var(--user-bg);
      color: white;
      align-self: flex-end;
      border-radius: 12px 12px 0 12px;
    }
    .msg img {
      max-width: 100%;
      height: auto;
      border-radius: 8px;
      margin-top: 8px;
      display: block;
      max-height: 200px;
      object-fit: contain;
    }
    .input-container {
      padding: 5px 10px;
      border-top: 1px solid var(--border);
      border-radius: 0 0 16px 16px;
    }
    textarea {
      width: 100%;
      padding: 12px;
      border: 1px solid var(--border);
      border-radius: 8px;
      font-size: 1rem;
      background: var(--input-bg);
      color: var(--text-main);
      margin: 5px;
      transition: border-color 0.2s ease;
      resize: vertical;
    }
    textarea:focus {
      outline: none;
      border-color: var(--highlight);
    }
    #controls {
      display: flex;
      gap: 8px;
      align-items: center;
      flex-wrap: wrap;
    }
    button, .file-upload {
      padding: 5px 5px;
      border: none;
      border-radius: 8px;
      font-size: 1rem;
      cursor: pointer;
      background: #555555;
      color: white;
      transition: background 0.2s ease;
      text-align: center;
    }
    button:hover, .file-upload:hover {
      background: #2563eb;
    }
    .file-upload {
      position: relative;
      display: inline-flex;
      align-items: center;
      justify-content: center;
    }
    .file-upload input[type="file"] {
      position: absolute;
      opacity: 0;
      width: 100%;
      height: 100%;
      cursor: pointer;
    }
    .file-name {
      font-size: 0.9rem;
      color: var(--text);
      margin-left: 8px;
      max-width: 200px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .copy-btn {
      position: absolute;
      top: -10px;
      right: 8px;
      background: rgba(0,0,0,0.1);
      font-size: 0.8rem;
      padding: 4px 5px;
      border-radius: 4px;
    }
    .copy-btn:hover {
      background: rgba(0,0,0,0.2);
    }
    #to-bottom-btn {
      display: none;
      position: absolute;
      bottom: 175px;
      right: 5px;
      background: var(--highlight);
      color: white;
      border-radius: 50%;
      width: 25px;
      height: 25px;
      line-height: 50px;
      font-size: 35px;
      padding: 0;
    }
    #history-modal {
      display: none;
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(0,0,0,0.5);
      z-index: 1000;
    }
    #history-modal > div {
      max-width: 900px;
      margin: 50px auto;
      background: var(--card);
      border-radius: 16px;
      max-height: 90vh;
      overflow-y: auto;
    }
    #history-content .msg {
      margin-bottom: 16px;
    }
    #history-content {
        padding: 10px;
		background: #000000;
    }
    .modal-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      position: sticky;
      top: 0;
      background: var(--card);
      z-index: 10;
      padding: 0 10px;
    }
    .modal-close-btn {
      padding: 5px 10px;
      border: none;
      border-radius: 8px;
      font-size: 1rem;
      cursor: pointer;
      background: var(--highlight);
      color: white;
      transition: background 0.2s ease;
    }
    .modal-close-btn:hover {
      background: #2563eb;
    }
    #messages::-webkit-scrollbar {
      width: 8px;
    }
    #messages::-webkit-scrollbar-track {
      background: var(--card);
    }
    #messages::-webkit-scrollbar-thumb {
      background: var(--border);
      border-radius: 4px;
    }

body {
  font-family: Arial, sans-serif;
  line-height: 1.6;
  padding: 20px;
  background: #f9f9f9;
}

p {
  margin: 1em 0;
}

/* Style cho Inline Code (code ngắn trong dòng) */
.msg code {
  background-color: #f3f4f6; /* Màu nền cho inline */
  color: #c7254e;
  padding: 2px 5px;
  border-radius: 4px;
  font-family: monospace;
}

/* Style cho Block Code (Khối lệnh lớn) */
.msg pre {
  background-color: #2d2d2d !important; /* Nền tối cho cả khối */
  padding: 15px;
  border-radius: 8px;
  overflow-x: auto; /* Cho phép cuộn ngang */
  margin: 10px 0;
}

/* Quan trọng: Reset lại style code khi nó nằm trong pre */
.msg pre code {
  background-color: transparent !important; /* Bỏ màu nền riêng */
  color: #f8f8f2; /* Màu chữ sáng cho nền tối */
  padding: 0;
  border: none;
  font-size: 14px;
}

blockquote {
  border-left: 4px solid #ccc;
  padding-left: 1em;
  color: #666;
  margin: 1em 0;
  font-style: italic;
}

ul {
  padding-left: 1.5em;
}

strong {
  font-weight: bold;
}

em {
  font-style: italic;
}

.markdown-body {
  font-family: sans-serif;
  line-height: 1.6;
}
.markdown-body pre {
  background: #f4f4f4;
  padding: 10px;
  border-radius: 5px;
  overflow-x: auto; /* Cuộn ngang nếu code dài */
}
.markdown-body code {
  font-family: monospace;
  background: #eee;
  padding: 2px 4px;
  border-radius: 3px;
}
.markdown-body pre code {
  background: none; /* Code trong block không cần nền riêng */
  padding: 0;
}
.markdown-body blockquote {
  border-left: 4px solid #ddd;
  padding-left: 10px;
  color: #666;
  margin-left: 0;
}

/* Persona Modal Styling */
.custom-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--modal-overlay);
  z-index: 1001;
  justify-content: center;
  align-items: center;
}

.modal-content-wrapper {
  width: 90%;
  max-width: 450px;
  background: var(--bg-chat); /* Đồng bộ với màu nền chat */
  border-radius: 16px;
  padding: 20px;
  border: 1px solid var(--border-color);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
}

.modal-body textarea {
  width: 100%;
  margin: 0;
  box-sizing: border-box;
  background: var(--input-bg);
  color: var(--text-main);
}

/* Nút đặc biệt cho Persona */
.persona-btn {
  background: #8b5cf6 !important; /* Màu tím để phân biệt với các nút khác */
}
.persona-btn:hover {
  background: #7c3aed !important;
}

/* Hiệu ứng nút gửi khi đang xử lý */
/* Hiệu ứng cho nút submitbtn khi có class .is-loading */
.submitbtn.is-loading {
  position: relative;
  color: transparent !important; /* Ẩn chữ Send */
  pointer-events: none;
}

.submitbtn.is-loading::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  top: 50%;
  left: 50%;
  margin: -9px 0 0 -9px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Làm mờ nhẹ input khi bận */
input:disabled, textarea:disabled {
    background-color: var(--bg-secondary);
    cursor: not-allowed;
}

/* Đảm bảo KaTeX không bị biến thành object khó copy */
.katex {
    font-size: 1.1em !important;
    user-select: text !important;
}

.katex-html {
    user-select: text !important;
}

/* Xử lý tràn khung cho công thức dài trên mobile/TOR */
.katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 0;
}

/* --- STYLE CHO LIÊN KẾT (LINKS) TRONG CHAT --- */

/* 1. Thiết lập chung cho liên kết trong tin nhắn */
.msg a {
    color: var(--highlight);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
    border-bottom: 1px dashed transparent;
    word-break: break-all; /* Tránh tràn khung khi link quá dài */
}

.msg a:hover {
    color: var(--user-bg);
    border-bottom-color: var(--highlight);
    opacity: 0.8;
}

/* 2. Style riêng cho phần Sources (Nguồn dẫn chứng) */
/* Thường nằm cuối câu trả lời của Bot */
.bot hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 15px 0 10px 0;
    opacity: 0.5;
}

.bot .sources-container, 
.bot [href*="vertexaisearch"], 
.bot a[href^="http"] {
    display: inline-flex;
    align-items: center;
    background: rgba(59, 130, 246, 0.1); /* Màu highlight mờ */
    padding: 2px 8px;
    border-radius: 6px;
    margin: 2px 0;
    font-size: 0.9em;
}

/* Thêm biểu tượng link nhỏ trước link (tùy chọn) */
.bot a[href^="http"]::before {
    content: "🔗";
    font-size: 10px;
    margin-right: 5px;
    filter: grayscale(1);
}

/* 3. Điều chỉnh liên kết trong Dark Mode để dễ đọc hơn */
body.iseoai-chatbot-page.dark-mode .msg a {
    color: var(--highlight); /* Sử dụng #60a5fa sáng hơn trong darkmode */
    text-shadow: 0 0 10px rgba(96, 165, 250, 0.2);
}

body.iseoai-chatbot-page.dark-mode .bot a[href^="http"] {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
}

body.iseoai-chatbot-page.dark-mode .bot a:hover {
    background: rgba(96, 165, 250, 0.2);
    color: #ffffff;
}

/* 4. Trình bày danh sách nguồn (Nếu bạn dùng thẻ <ul> cho Sources) */
.msg ul li a {
    display: inline-block;
    margin-bottom: 4px;
}

/* Style cho các link dạng nút bấm (nếu có) */
.msg .link-button {
    display: block;
    text-align: center;
    background: var(--highlight);
    color: #ffffff !important;
    padding: 8px;
    border-radius: 8px;
    margin-top: 10px;
    font-weight: bold;
    border: none;
}

.msg .link-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}