:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e3e5e9;
  --text: #1a1d23;
  --muted: #6b7280;
  --accent: #2f6fed;
  --accent-hover: #2559c4;
  --accent-soft: #e8f0fe;
  --bubble-user: #2f6fed;
  --bubble-user-text: #ffffff;
  --bubble-bot: #ffffff;
  --bubble-bot-text: #1a1d23;
  --bubble-bot-border: #e3e5e9;
  --danger: #c0392b;
  /* nhãn tình trạng hiệu lực văn bản (validity-badge) */
  --validity-het: #b42318;
  --validity-het-bg: #fdecea;
  --validity-warn: #9a5b00;
  --validity-warn-bg: #fdf3e1;
  --validity-info: #2559c4;
  --validity-info-bg: #e8f0fe;
  --chart-2: #c8741a; /* phần thứ hai của biểu đồ cơ cấu (mat-tran-so), đã kiểm tra tương phản + mù màu với --accent */
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
}

/* Mặc định là giao diện sáng (không theo hệ điều hành); chỉ tối khi người dùng bấm nút
   theme-toggle (js/theme.js đặt <html data-theme="dark">). */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16181d;
  --panel: #1e2127;
  --border: #2c303a;
  --text: #eceef1;
  --muted: #9aa0aa;
  --accent: #5b8def;
  --accent-hover: #7aa2f2;
  --accent-soft: #23304a;
  --bubble-user: #5b8def;
  --bubble-user-text: #0d1117;
  --bubble-bot: #262a32;
  --bubble-bot-text: #eceef1;
  --bubble-bot-border: #2c303a;
  --danger: #ff6b5e;
  --chart-2: #cf7d28;
  --validity-het: #ff8a80;
  --validity-het-bg: #3a1f1f;
  --validity-warn: #f0b24a;
  --validity-warn-bg: #3a2e18;
  --validity-info: #8fb3f5;
  --validity-info-bg: #23304a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

/* Thuộc tính hidden luôn thắng: các class đặt display (flex/grid...) sẽ đè hidden nếu thiếu dòng
   này — từng làm khách thấy menu người dùng/quản trị và nút Đăng xuất. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button {
  font-family: inherit;
}

.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: 272px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 10px;
  overflow-y: auto;
  transition: transform 0.2s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 4px 8px;
}

.sidebar-brand .brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-brand .brand-name {
  font-weight: 600;
  font-size: 15px;
}

.sidebar-close {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s ease;
}

.new-chat-btn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item .icon {
  width: 15px;
  height: 15px;
  color: var(--muted);
  flex-shrink: 0;
}

.conversation-item:hover {
  background: var(--bg);
}

.conversation-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.conversation-item.active .icon {
  color: var(--accent);
}

.conversation-empty {
  color: var(--muted);
  font-size: 12px;
  padding: 10px;
  text-align: center;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
  text-transform: uppercase;
}

#username-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
}

.logout-btn:hover {
  background: var(--bg);
  color: var(--danger);
}

.login-link {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
}

.login-link:hover {
  background: var(--accent-soft);
}

.sidebar-backdrop {
  display: none;
}

/* ---------- Chat main ---------- */

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.chat-topbar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.menu-toggle {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 6px;
  display: flex;
}

.chat-topbar .brand-name {
  font-weight: 600;
  font-size: 14px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.empty-state {
  margin: auto;
  text-align: center;
  max-width: 480px;
  color: var(--muted);
}

.empty-state .empty-icon {
  width: 44px;
  height: 44px;
  color: var(--accent);
  margin-bottom: 12px;
}

.empty-state h2 {
  color: var(--text);
  font-size: 18px;
  margin: 0 0 6px;
}

.empty-state p {
  margin: 0 0 18px;
  font-size: 13px;
}

.suggestion-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.suggestion-chip {
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.suggestion-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.message-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 78%;
}

.message-row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-row.assistant {
  align-self: flex-start;
}

.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}

.message-row.user .message-avatar {
  background: var(--bubble-user);
}

.message-row.assistant .message-avatar {
  background: var(--accent);
}

.message-avatar .icon {
  width: 15px;
  height: 15px;
}

.message-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.message-row.user .message-content {
  align-items: flex-end;
}

.message-row.assistant .message-content {
  align-items: flex-start;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.5;
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: var(--shadow);
}

.message-row.user .message-bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 4px;
}

.message-row.assistant .message-bubble {
  background: var(--bubble-bot);
  color: var(--bubble-bot-text);
  border: 1px solid var(--bubble-bot-border);
  border-bottom-left-radius: 4px;
}

.message-row.pending .message-bubble {
  padding: 14px;
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.message-error {
  color: var(--danger);
}

.message-actions {
  display: flex;
  gap: 2px;
  margin-top: 4px;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.message-row:hover .message-actions,
.message-actions:focus-within {
  opacity: 1;
}

.message-row.pending .message-actions {
  display: none;
}

.message-action-btn {
  width: 26px;
  height: 26px;
  border: none;
  background: none;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.message-action-btn .icon {
  width: 14px;
  height: 14px;
}

.message-action-btn:hover:not(:disabled) {
  background: var(--bg);
  color: var(--text);
}

.message-action-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.message-action-btn.copied {
  color: #1a9e5c;
}

@media (hover: none) {
  .message-actions {
    opacity: 1;
  }
}

.message-sources {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.message-token-info {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

.message-row.user .message-token-info {
  color: rgba(255, 255, 255, 0.75);
}

.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}

.message-row.user .source-chip {
  background: rgba(255, 255, 255, 0.15);
  color: var(--bubble-user-text);
  border-color: transparent;
}

.source-chip .icon {
  width: 11px;
  height: 11px;
}

.validity-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 16px;
  white-space: nowrap;
  cursor: help;
}

.validity-het {
  color: var(--validity-het);
  background: var(--validity-het-bg);
}

.validity-mot_phan,
.validity-luu_y {
  color: var(--validity-warn);
  background: var(--validity-warn-bg);
}

.validity-chua {
  color: var(--validity-info);
  background: var(--validity-info-bg);
}

.cite-validity {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.5;
}

.cite-validity[hidden] {
  display: none;
}

.cite-validity .validity-badge {
  margin-left: 0;
  cursor: default;
}

.cite-validity-note {
  color: var(--text);
}

.source-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 2px;
  padding: 2px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.source-action-btn:hover {
  background: rgba(0, 0, 0, 0.08);
}

.message-row.user .source-action-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.source-action-btn .icon {
  width: 12px;
  height: 12px;
}

.model-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 24px 0;
  font-size: 12px;
  color: var(--muted);
}

.model-select {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 24px 18px;
  background: var(--bg);
}

.chat-form-inner {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow);
  max-width: 780px;
  margin: 0 auto;
  width: 100%;
}

.chat-form textarea {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  padding: 6px 0;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  max-height: 160px;
}

.chat-form textarea::placeholder {
  color: var(--muted);
}

.send-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.mic-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}

.mic-btn:hover:not(:disabled) {
  background: var(--bg);
  color: var(--text);
}

.mic-btn.recording {
  color: #fff;
  background: var(--danger);
  animation: mic-pulse 1.4s ease-in-out infinite;
}

.mic-btn.transcribing {
  opacity: 0.6;
  cursor: wait;
}

.mic-btn:disabled {
  cursor: wait;
}

@keyframes mic-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(192, 57, 43, 0.45);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(192, 57, 43, 0);
  }
}

/* ---------- Auth pages ---------- */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-wrap {
  width: 100%;
  max-width: 380px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.auth-brand .brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
}

.auth-wrap h1 {
  font-size: 17px;
  margin: 0;
  text-align: center;
}

.auth-wrap form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.auth-field label {
  font-size: 12px;
  color: var(--muted);
}

.auth-wrap input {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease;
}

.auth-wrap input:focus {
  border-color: var(--accent);
}

.auth-wrap button {
  padding: 11px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  margin-top: 4px;
  transition: background 0.15s ease;
}

.auth-wrap button:hover:not(:disabled) {
  background: var(--accent-hover);
}

.auth-wrap button:disabled {
  opacity: 0.6;
  cursor: default;
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
}

.auth-toggle {
  margin-top: 16px;
  font-size: 13px;
  text-align: center;
  color: var(--muted);
}

.auth-toggle a {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
}

.auth-toggle a:hover {
  text-decoration: underline;
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .chat-topbar {
    display: flex;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    transform: translateX(-100%);
    box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  }

  .layout.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.15);
  }

  .sidebar-close {
    display: flex;
  }

  .layout.sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 15;
  }

  .message-row {
    max-width: 92%;
  }

  .chat-form {
    padding: 10px 12px 14px;
  }
}

/* Sidebar: link Quản trị (chỉ hiện với admin) */
.admin-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  border-radius: 6px;
}

.admin-link:hover {
  background: var(--bg);
  color: var(--text);
}

/* Trang /admin.html — form nạp tài liệu */
.admin-page {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

.admin-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.admin-back {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}

.admin-back:hover {
  color: var(--accent);
}

.admin-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  padding: 32px 16px 60px;
}

.admin-form {
  width: 100%;
  max-width: 640px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.admin-tab {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.admin-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.admin-row {
  display: flex;
  gap: 16px;
}

.admin-row .admin-field {
  flex: 1;
  min-width: 0;
}

.admin-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.admin-field label {
  font-size: 13px;
  color: var(--muted);
}

.admin-field input,
.admin-field textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

.admin-field input:focus,
.admin-field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.admin-submit-btn {
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.admin-submit-btn:hover {
  background: var(--accent-hover);
}

.admin-submit-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.admin-message {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
}

.admin-message-success {
  background: var(--accent-soft);
  color: var(--accent);
}

.admin-message-error {
  background: rgba(192, 57, 43, 0.12);
  color: var(--danger);
}

@media (max-width: 640px) {
  .admin-row {
    flex-direction: column;
    gap: 16px;
  }
}

.admin-list-section {
  width: 100%;
  max-width: 1400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 20px 24px;
}

.admin-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.admin-list-header h2 {
  font-size: 16px;
  margin: 0;
}

.admin-refresh-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
}

.admin-refresh-btn:hover {
  background: var(--bg);
  color: var(--accent);
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th,
.admin-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  overflow-wrap: break-word;
}

/* ID, Nội bộ, Quyền, Số đoạn, Ngày nạp, actions: giá trị ngắn, giữ 1 dòng. Tiêu đề/Nguồn/License
   (nội dung dài, không kiểm soát được độ dài) được để mặc định wrap nhiều dòng thay vì ellipsis,
   để bảng luôn vừa chiều rộng màn hình máy tính, không cần cuộn ngang. */
.admin-doc-meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.admin-table th:nth-child(1),
.admin-table td:nth-child(1) {
  width: 5%;
  white-space: nowrap;
}

.admin-table th:nth-child(2),
.admin-table td:nth-child(2) {
  width: 19%;
}

.admin-table th:nth-child(3),
.admin-table td:nth-child(3) {
  width: 15%;
}

.admin-table th:nth-child(4),
.admin-table td:nth-child(4) {
  width: 18%;
}

.admin-table th:nth-child(5),
.admin-table td:nth-child(5) {
  width: 6%;
  white-space: nowrap;
}

.admin-table th:nth-child(6),
.admin-table td:nth-child(6) {
  width: 7%;
  white-space: nowrap;
}

.admin-table th:nth-child(7),
.admin-table td:nth-child(7) {
  width: 6%;
  white-space: nowrap;
}

.admin-table th:nth-child(8),
.admin-table td:nth-child(8) {
  width: 9%;
  white-space: nowrap;
}

.admin-table th:nth-child(9),
.admin-table td:nth-child(9) {
  width: 15%;
}

.admin-table th {
  color: var(--muted);
  font-weight: 600;
}

.admin-table-empty {
  text-align: center;
  color: var(--muted);
  white-space: normal;
}

.admin-delete-btn {
  padding: 5px 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--danger);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}

.admin-delete-btn:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.admin-table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.admin-edit-btn {
  padding: 5px 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--accent);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}

.admin-edit-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.admin-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
  font-size: 13px;
  color: var(--muted);
}

.admin-pagination button {
  padding: 6px 14px;
}

.admin-pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.admin-dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 640px;
}

.admin-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.admin-dialog-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  max-height: 85vh;
  overflow-y: auto;
}

.admin-dialog-form h3 {
  margin: 0;
  font-size: 16px;
}

.admin-dialog-subheading {
  margin: 8px 0 -8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 14px;
}

.admin-manual-flag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
  font-size: 11px;
  font-weight: normal;
  color: var(--muted);
}

.admin-manual-reset {
  padding: 1px 6px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.admin-manual-reset:hover {
  color: var(--text);
}

.admin-dialog-hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.admin-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.admin-dialog-actions .admin-submit-btn {
  padding: 10px 20px;
}

/* ---------- Logo MTTQ ---------- */

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-logo-sm {
  width: 28px;
  height: 28px;
}

.brand-logo-lg {
  width: 72px;
  height: 72px;
}

/* ---------- Câu trả lời: in đậm + chú thích bấm được ---------- */

.message-bubble strong {
  font-weight: 700;
}

.cite-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin: 0 2px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  vertical-align: 1px;
  cursor: pointer;
}

.cite-chip:hover {
  background: var(--accent);
  color: #fff;
}

.cite-demo {
  cursor: default;
}

.cite-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.cite-modal[hidden] {
  display: none;
}

.cite-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.cite-dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 640px;
  max-height: min(80vh, 640px);
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.cite-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.cite-badge {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.cite-head h3 {
  flex: 1;
  margin: 0;
  font-size: 15px;
  line-height: 1.4;
  font-weight: 600;
}

.cite-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 6px;
  display: flex;
}

.cite-close:hover {
  background: var(--bg);
  color: var(--text);
}

.cite-body {
  padding: 16px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.cite-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px;
}

.cite-actions:not(:empty) {
  padding: 12px 16px 14px;
  border-top: 1px solid var(--border);
}

.cite-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
}

.cite-action:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------- Xóa lịch sử hội thoại ---------- */

.conversation-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-delete {
  flex-shrink: 0;
  display: flex;
  padding: 3px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
}

.conversation-delete .icon {
  width: 14px;
  height: 14px;
  color: inherit;
}

.conversation-item:hover .conversation-delete,
.conversation-delete:focus-visible {
  opacity: 1;
}

.conversation-delete:hover {
  background: var(--panel);
  color: var(--danger);
}

@media (hover: none) {
  .conversation-delete {
    opacity: 1;
  }
}

.clear-all-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.clear-all-btn[hidden] {
  display: none;
}

.clear-all-btn:hover {
  background: var(--bg);
  color: var(--danger);
}

.guide-link {
  margin-top: auto;
}

.guide-link + .sidebar-footer {
  margin-top: 0;
}

/* ---------- Ghi chú dưới ô nhập ---------- */

.chat-disclaimer {
  max-width: 780px;
  width: 100%;
  margin: -6px auto 0;
  padding: 0 24px 12px;
  text-align: center;
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
}

.chat-disclaimer a {
  color: var(--muted);
  text-decoration: underline;
  white-space: nowrap;
}

.chat-disclaimer a:hover {
  color: var(--accent);
}

@media (max-width: 860px) {
  .chat-disclaimer {
    padding: 0 14px 10px;
  }
}

/* ---------- Trang hướng dẫn ---------- */

.guide-main {
  align-items: stretch;
  gap: 18px;
  max-width: 760px;
  margin: 0 auto;
}

.guide-main {
  counter-reset: guide-step;
}

.guide-section {
  counter-increment: guide-step;
  padding: 20px 22px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 14px;
  line-height: 1.65;
}

.guide-section h2 {
  margin: 0 0 10px;
  font-size: 16px;
}

.guide-section h2::before {
  content: counter(guide-step) ". ";
}

.guide-section[hidden] {
  display: none;
}

.guide-section p {
  margin: 0 0 10px;
}

.guide-section p:last-child,
.guide-section ul:last-child {
  margin-bottom: 0;
}

.guide-section ul {
  margin: 0;
  padding-left: 20px;
}

.guide-section li {
  margin-bottom: 6px;
}

.guide-section kbd {
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  font-size: 12px;
}

/* ---------- Quản lý người dùng ---------- */

.admin-topbar-link {
  margin-left: auto;
}

.users-heading {
  margin: 0;
  font-size: 16px;
}

.users-section {
  max-width: 900px;
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.users-table th,
.users-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
}

.users-table th {
  color: var(--muted);
  font-weight: 600;
}

.users-table th:nth-child(1),
.users-table td:nth-child(1),
.users-table th:nth-child(5),
.users-table td:nth-child(5) {
  white-space: nowrap;
}

.users-role {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}

.users-role-admin {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.users-select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

.users-dialog {
  max-width: 480px;
}

.admin-delete-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.admin-delete-btn:disabled:hover {
  background: var(--bg);
  color: var(--danger);
  border-color: var(--border);
}

/* ---------- Tra cứu văn bản (/tra-cuu.html) ---------- */

.search-main {
  gap: 20px;
  padding-top: 24px;
}

.search-form,
.search-answer,
.search-results {
  max-width: 1100px;
}

.search-user {
  font-size: 13px;
  color: var(--muted);
}

.search-ask {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.search-ask label {
  font-size: 14px;
  font-weight: 600;
}

.search-optional {
  font-weight: 400;
  color: var(--muted);
  font-size: 13px;
}

.search-ask textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  min-height: 48px;
}

.search-ask textarea:focus,
.search-grid select:focus {
  outline: none;
  border-color: var(--accent);
}

.search-hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.search-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.search-span-2 {
  grid-column: span 2;
}

.search-grid .users-select {
  width: 100%;
}

.search-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.search-model {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
  font-size: 13px;
  color: var(--muted);
}

.search-reset-btn {
  padding: 11px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.search-reset-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.search-submit-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 28px;
}

.search-answer-head,
.search-results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.search-answer-head h2,
.search-summary {
  margin: 0;
  font-size: 16px;
}

.search-answer-body {
  margin-top: 12px;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.search-thinking {
  color: var(--muted);
  font-style: italic;
}

.search-answer-sources-label {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
}

.search-sort {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.search-sort .users-select {
  padding: 7px 10px;
  font-size: 13px;
}

.search-results.loading .search-list {
  opacity: 0.5;
}

.search-empty {
  background: var(--bg);
  color: var(--muted);
}

.search-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

.search-item {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.search-item:last-child {
  border-bottom: none;
}

.search-item-title {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.search-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.search-meta {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  line-height: 1.6;
  text-align: left;
  overflow-wrap: anywhere;
}

button.search-meta {
  cursor: pointer;
}

button.search-meta:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.search-meta-label {
  color: var(--muted);
}

.search-item-snippet {
  margin: 8px 0 0;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 6px 6px 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  overflow-wrap: anywhere;
}

.search-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.search-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
}

.search-action .icon {
  width: 14px;
  height: 14px;
}

.search-action:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.search-score {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
}

.search-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 16px;
}

.search-pagination button {
  min-width: 36px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.search-pagination button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.search-pagination button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.search-pagination button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.search-page-gap,
.search-page-info {
  font-size: 13px;
  color: var(--muted);
}

.search-page-info {
  margin-left: 8px;
}

@media (max-width: 860px) {
  .search-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .search-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .search-span-2 {
    grid-column: auto;
  }

  .search-model {
    width: 100%;
  }

  .search-submit-btn {
    flex: 1;
    justify-content: center;
  }

  .search-user {
    display: none;
  }
}

/* Ô chọn nhiều giá trị (loại văn bản, nguồn) trên trang tra cứu */
.multi-select-label {
  font-size: 13px;
  color: var(--muted);
}

.multi-select {
  position: relative;
}

.multi-select-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.multi-select.has-value .multi-select-btn {
  color: var(--text);
  border-color: var(--accent);
}

.multi-select-btn:focus-visible,
.multi-select-btn[aria-expanded="true"] {
  outline: none;
  border-color: var(--accent);
}

.multi-select-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.multi-select-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  width: max(100%, 280px);
  max-width: calc(100vw - 32px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.16);
  display: flex;
  flex-direction: column;
}

.multi-select-panel[hidden] {
  display: none;
}

.multi-select-filter {
  margin: 8px 8px 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}

.multi-select-filter:focus {
  outline: none;
  border-color: var(--accent);
}

.multi-select-options {
  max-height: 280px;
  overflow-y: auto;
  padding: 6px 0;
}

.multi-select-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}

.multi-select-option[hidden] {
  display: none;
}

.multi-select-option:hover {
  background: var(--bg);
}

.multi-select-option input {
  margin: 0;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.multi-select-option span:first-of-type {
  flex: 1;
  min-width: 0;
}

.multi-select-count {
  color: var(--muted);
  font-size: 12px;
}

.multi-select-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid var(--border);
}

.multi-select-foot button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.multi-select-foot .multi-select-done {
  margin-left: auto;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.admin-field textarea {
  resize: vertical;
  line-height: 1.4;
}

/* ---------- Quản lý người dùng (tài khoản dùng chung mttquser) ---------- */
.users-shared-note {
  max-width: 900px;
  background: var(--accent-soft);
  color: var(--text);
}

.users-create {
  max-width: 900px;
}

.users-create summary {
  cursor: pointer;
}

.users-create-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 16px;
}

.users-label {
  font-size: 13px;
  font-weight: 500;
}

.users-roles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.users-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

.users-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.users-filters input[type="search"] {
  flex: 1 1 220px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

.users-filters .users-select {
  flex: 0 1 200px;
  min-width: 0;
}

.users-total {
  color: var(--muted);
  font-weight: 400;
  font-size: 14px;
}

.users-name {
  font-weight: 500;
}

.users-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.users-table .users-role {
  margin: 0 4px 4px 0;
}

.users-status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}

.users-status-on {
  background: var(--accent-soft);
  color: var(--accent);
}

.users-status-off {
  background: rgba(192, 57, 43, 0.12);
  color: var(--danger);
}

.users-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}

.users-pager button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.users-temp-password {
  display: block;
  padding: 12px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 18px;
  letter-spacing: 1px;
  text-align: center;
  user-select: all;
}

.users-dialog .admin-field select:disabled {
  opacity: 0.6;
}

.auth-note {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  margin: 0 0 16px;
}

.users-section,
.users-shared-note,
.users-create {
  max-width: 1100px;
}

.users-table td:nth-child(1) {
  white-space: normal;
}

.users-table .admin-table-actions {
  flex-wrap: wrap;
}

/* ---------- Thống kê theo đơn vị (thong-ke.html) ---------- */
.stats-main {
  align-items: stretch;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  gap: 20px;
}

.stats-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.stats-presets {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.stats-preset {
  padding: 9px 12px;
  border: 0;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.stats-preset + .stats-preset {
  border-left: 1px solid var(--border);
}

.stats-preset.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.stats-date {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.stats-date input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.stats-filters .users-select {
  flex: 1 1 220px;
  max-width: 360px;
  min-width: 0;
}

.stats-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
  transition: opacity 0.15s;
}

.stats-loading {
  opacity: 0.5;
}

.stats-scope {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

.stats-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.stats-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.stats-tile[hidden] {
  display: none;
}

.stats-tile-label {
  font-size: 13px;
  color: var(--muted);
}

.stats-tile-value {
  font-size: 28px;
  font-weight: 600;
  color: var(--text);
}

.stats-tile-note {
  font-size: 12px;
  color: var(--muted);
}

.stats-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
}

.stats-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.stats-card-head .stats-card-title {
  margin: 0 auto 0 0;
}

.stats-card-title {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
}

.stats-chart {
  width: 100%;
  overflow: hidden;
}

.stats-chart svg {
  display: block;
  max-width: 100%;
}

.stats-grid {
  stroke: var(--border);
  stroke-width: 1;
}

.stats-baseline {
  stroke: var(--muted);
  stroke-width: 1;
}

.stats-axis {
  fill: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.stats-peak {
  fill: var(--text);
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
}

.stats-bar {
  fill: var(--accent);
}

.stats-bar.hover {
  fill: var(--accent-hover);
}

.stats-hit {
  fill: transparent;
  cursor: default;
  outline: none;
}

.stats-hit:focus-visible {
  stroke: var(--accent);
  stroke-width: 1;
}

.stats-tooltip {
  position: absolute;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(16, 24, 40, 0.12);
  pointer-events: none;
  white-space: nowrap;
}

.stats-tooltip[hidden] {
  display: none;
}

.stats-tip-value {
  font-size: 14px;
  color: var(--text);
}

.stats-tip-label {
  font-size: 12px;
  color: var(--muted);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.stats-table th,
.stats-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.stats-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stats-sort {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}

.stats-sort.active {
  color: var(--text);
}

.stats-link {
  color: var(--accent);
  text-decoration: none;
}

.stats-link:hover {
  text-decoration: underline;
}

.stats-special {
  font-style: italic;
}

.stats-nowrap {
  white-space: nowrap;
  color: var(--muted);
}

.stats-bar-cell {
  min-width: 140px;
}

.stats-inline-value {
  display: inline-block;
  min-width: 36px;
}

.stats-inline-track {
  display: inline-block;
  vertical-align: middle;
  width: 90px;
  height: 8px;
  margin-left: 8px;
  border-radius: 4px;
  background: var(--accent-soft);
}

.stats-inline-bar {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: var(--accent);
}

.stats-back {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.stats-footnote {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 640px) {
  .stats-card {
    padding: 14px;
  }
  .stats-tile-value {
    font-size: 24px;
  }
}

/* ---------- Quyền dùng model (cau-hinh-model.html) ---------- */
.modelperm-table th.modelperm-col,
.modelperm-table td.modelperm-cell {
  text-align: center;
  white-space: nowrap;
}

.modelperm-table td.modelperm-cell input {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.modelperm-table td.modelperm-cell input:disabled {
  cursor: not-allowed;
}

.modelperm-table tr.modelperm-sep td {
  border-bottom-width: 2px;
}

.modelperm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ---------- Lịch sử chat của người dùng (lich-su-chat.html) ---------- */
.history-search {
  flex: 1 1 220px;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.history-layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.history-list-card,
.history-view-card {
  padding: 16px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: calc(100vh - 290px);
  min-height: 200px;
  overflow-y: auto;
  transition: opacity 0.15s;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.history-item:hover {
  border-color: var(--accent);
}

.history-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.history-item-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}

.history-item-user {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item-time,
.history-item-meta {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.history-item-meta {
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-title {
  font-size: 13px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.history-empty {
  margin: 12px 0;
  font-size: 14px;
  color: var(--muted);
}

.history-error {
  color: var(--danger);
}

.history-view-card {
  max-height: calc(100vh - 190px);
  min-height: 300px;
  overflow-y: auto;
}

.history-back {
  display: none;
  margin-bottom: 12px;
}

.history-view-head {
  padding-bottom: 12px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.history-view-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 600;
}

.history-view-meta {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.history-thread {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.history-thread .message-row {
  max-width: 90%;
}

.history-thread a.source-chip {
  color: var(--accent);
  text-decoration: none;
}

.history-message-time {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

.history-citations {
  margin-top: 6px;
  max-width: 100%;
  font-size: 12px;
  color: var(--muted);
}

.history-citations summary {
  cursor: pointer;
}

.history-citation {
  margin-top: 8px;
  padding: 8px 10px;
  border-left: 3px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
}

.history-citation strong {
  color: var(--text);
}

.history-citation p {
  margin: 4px 0 0;
  white-space: pre-wrap;
  max-height: 160px;
  overflow-y: auto;
}

@media (max-width: 860px) {
  .history-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .history-layout .history-view-card,
  .history-layout.viewing .history-list-card {
    display: none;
  }

  .history-layout.viewing .history-view-card {
    display: block;
    max-height: none;
  }

  .history-back {
    display: inline-flex;
  }

  .history-list {
    max-height: none;
  }
}

.history-link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

/* ---------- Tra cứu tin bài (tin-bai.html) — dùng lại bố cục lịch sử chat ---------- */
.news-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}

.stats-filters .news-sort {
  flex: 0 1 190px;
}

.news-item-title {
  font-weight: 600;
}

.news-item-snippet {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.news-view-title {
  font-size: 18px;
  line-height: 1.4;
}

.news-links {
  margin-top: 8px;
}

.news-source-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.news-source-link:hover {
  text-decoration: underline;
}

.news-body {
  max-width: 760px;
  font-size: 15px;
  line-height: 1.65;
}

.news-image {
  display: block;
  max-width: 100%;
  max-height: 360px;
  margin: 0 0 14px;
  border-radius: 8px;
  object-fit: cover;
}

.news-summary {
  margin: 0 0 14px;
  font-weight: 600;
}

.news-paragraph {
  margin: 0 0 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.news-mark {
  background: #fde68a;
  color: #1f2937;
  border-radius: 2px;
}

.news-info {
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.news-info-list {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 14px;
  margin: 10px 0 0;
}

.news-info-list dt {
  color: var(--muted);
}

.news-info-list dd {
  margin: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

/* ---------- Hỏi đáp mẫu (hoi-dap.html) ---------- */
.faq-test {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  margin-bottom: 12px;
}

.faq-test-label {
  font-size: 13px;
  font-weight: 600;
}

.faq-test-row {
  display: flex;
  gap: 8px;
}

.faq-btn {
  padding: 8px 16px;
  font-size: 13px;
}

.faq-status-select {
  flex: 0 1 170px !important;
}

.faq-test-result {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.faq-test-result .admin-edit-btn {
  align-self: flex-start;
}

.faq-test-summary {
  margin: 4px 0;
  font-weight: 600;
}

.faq-test-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
}

.faq-test-meta {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.faq-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.faq-badge-direct {
  background: var(--accent);
  color: #fff;
}

.faq-badge-context {
  background: var(--accent-soft);
  color: var(--accent);
}

.faq-badge-none {
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}

.faq-item-off {
  opacity: 0.6;
}

.faq-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 760px;
}

.faq-form .history-view-title {
  margin-bottom: 0;
}

.faq-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.faq-actions .admin-delete-btn {
  margin-left: auto;
}

@media (max-width: 640px) {
  .faq-form .admin-row {
    flex-direction: column;
  }
}

.history-faq-btn,
.history-faq-link {
  align-self: flex-start;
  margin-top: 6px;
  font-size: 12px;
  text-decoration: none;
}

.news-faq-btn {
  margin-left: 12px;
  text-decoration: none;
}

/* Biểu đồ thời gian trả lời theo ngày (thong-ke.html) */
.stats-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  pointer-events: none;
}

.stats-dot {
  fill: var(--accent);
  stroke: var(--panel);
  stroke-width: 2;
  pointer-events: none;
}

.stats-dot.hover {
  fill: var(--accent-hover);
  r: 5;
}

.stats-crosshair {
  stroke: var(--muted);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  pointer-events: none;
}

.stats-axis-strong {
  fill: var(--text);
  font-size: 12px;
}

.stats-group-row {
  padding-top: 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* Nhiều biểu đồ nhỏ: số bài mới theo ngày của từng nguồn (thong-ke.html) */
.stats-multiples {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.stats-multiple {
  min-width: 0;
  padding: 10px 12px 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.stats-multiple svg {
  display: block;
  max-width: 100%;
}

.stats-multiple-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 13px;
}

.stats-multiple-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-multiple-total {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stats-idle-sources {
  margin-top: 12px;
  font-size: 13px;
}

/* ---------- Tra cứu: tab Văn bản | Sách (tra-cuu.html, tra-cuu-sach.html) ---------- */
.search-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
}

.search-tab {
  padding: 8px 14px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.search-tab:hover {
  color: var(--text);
}

.search-tab[aria-current="page"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---------- Tra cứu sách ---------- */
.book-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.book-chip {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.book-chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.book-chip-count {
  margin-left: 4px;
  color: var(--muted);
  font-size: 12px;
}

.book-item {
  display: flex;
  gap: 14px;
}

.book-cover {
  flex: 0 0 auto;
  width: 64px;
  height: 96px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  object-fit: cover;
}

.book-body {
  flex: 1;
  min-width: 0;
}

.book-snippet-where {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.book-detail {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
  line-height: 1.6;
}

.book-detail h4 {
  margin: 8px 0 4px;
  font-size: 13px;
}

.book-detail h4:first-child {
  margin-top: 0;
}

.book-detail-text {
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-line;
}

.book-parts {
  margin: 0;
  padding-left: 18px;
}

.book-parts a {
  color: var(--accent);
}

.book-license {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 600px) {
  .book-cover {
    width: 48px;
    height: 72px;
  }
}

/* ---------- "Câu hỏi của tôi" (câu hỏi người dùng tự lưu) ---------- */
.chat-form {
  position: relative;
}

.saved-btn.has-saved {
  color: var(--accent);
}

.save-question-btn.saved {
  color: var(--accent);
}

.save-question-btn.saved svg {
  fill: currentColor;
}

.message-row.user .message-actions:has(.save-question-btn.saved) {
  opacity: 1;
}

.saved-section {
  width: 100%;
  max-width: 680px;
  margin: 0 auto 16px;
}

.saved-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 8px;
}

.saved-title .icon {
  width: 15px;
  height: 15px;
}

.saved-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.saved-chip {
  display: flex;
  align-items: center;
  max-width: 100%;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.saved-chip-text {
  border: none;
  background: none;
  color: var(--text);
  font-size: 13px;
  padding: 8px 4px 8px 14px;
  cursor: pointer;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 520px;
}

.saved-chip-text:hover {
  color: var(--accent);
}

.saved-chip-del,
.saved-pop-item-del {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  margin-right: 4px;
  border: none;
  background: none;
  color: var(--muted);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.saved-chip-del .icon,
.saved-pop-item-del .icon {
  width: 14px;
  height: 14px;
}

.saved-chip-del:hover,
.saved-pop-item-del:hover {
  color: var(--danger);
  background: rgba(192, 57, 43, 0.08);
}

.saved-popover {
  position: absolute;
  bottom: calc(100% - 6px);
  left: 50%;
  transform: translateX(-50%);
  width: min(780px, calc(100% - 32px));
  max-height: 320px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.14);
  padding: 6px;
  z-index: 20;
}

.saved-pop-head {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 10px 4px;
}

.saved-pop-empty {
  margin: 0;
  padding: 8px 10px 10px;
  font-size: 13px;
  color: var(--muted);
}

.saved-pop-item {
  display: flex;
  align-items: center;
  border-radius: 8px;
}

.saved-pop-item:hover {
  background: var(--accent-soft);
}

.saved-pop-item-text {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  padding: 9px 10px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 640px) {
  .saved-chip-text {
    max-width: calc(100vw - 90px);
  }

  .saved-popover {
    width: calc(100% - 24px);
  }
}

.empty-state .saved-hint {
  max-width: 560px;
  margin: 0 auto;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  background: var(--accent-soft);
  border: 1px dashed var(--accent);
  border-radius: 10px;
}

.empty-state .saved-hint.small {
  margin-top: 8px;
  padding: 0;
  font-size: 12px;
  color: var(--muted);
  background: none;
  border: none;
}

.saved-hint-icon {
  display: inline-flex;
  vertical-align: -3px;
  color: var(--accent);
}

.saved-hint-icon .icon {
  width: 15px;
  height: 15px;
}

/* Nút xuất Word / Excel dưới câu trả lời */
.message-action-btn.export-btn {
  width: auto;
  padding: 0 7px;
  gap: 3px;
  font-size: 11.5px;
  font-weight: 600;
}

.message-action-btn.export-btn .icon {
  width: 13px;
  height: 13px;
}

.message-action-btn.export-docx:hover {
  color: #2b579a;
}

.message-action-btn.export-xlsx:hover {
  color: #217346;
}

.message-action-btn.export-btn:disabled {
  opacity: 0.5;
  cursor: progress;
}

/* ---------- Mặt trận số (mat-tran-so.html) ---------- */
.mts-programs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.mts-programs[hidden] {
  display: none;
}

.mts-program {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
}

.mts-program:hover,
.mts-program:focus-visible {
  border-color: var(--accent);
}

.mts-program-short {
  font-size: 16px;
  font-weight: 600;
}

.mts-program-name {
  font-size: 12px;
  color: var(--muted);
}

.mts-program-figs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}

.mts-program-fig {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mts-program-value {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.mts-program-more {
  margin-top: auto;
  padding-top: 6px;
  font-size: 13px;
  color: var(--accent);
}

#mts-detail {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

#mts-detail[hidden] {
  display: none;
}

.mts-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 20px;
}

.mts-charts .mts-wide {
  grid-column: 1 / -1;
}

.mts-bar-other {
  fill: var(--muted);
  opacity: 0.6;
}

.mts-split-0 {
  fill: var(--accent);
  background: var(--accent);
}

.mts-split-1 {
  fill: var(--chart-2);
  background: var(--chart-2);
}

.stats-bar.mts-split-0.hover,
.stats-bar.mts-split-1.hover {
  opacity: 0.85;
}

.mts-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
}

.mts-legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mts-legend-label {
  color: var(--muted);
}

.mts-legend strong {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.mts-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.mts-progress-track {
  height: 14px;
  border-radius: 7px;
  background: var(--accent-soft);
  overflow: hidden;
}

.mts-progress-bar {
  height: 100%;
  border-radius: 7px;
  background: var(--accent);
}

.mts-progress-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 16px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

.mts-progress-legend strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.mts-unit-filter {
  min-width: 220px;
}

@media (max-width: 640px) {
  .mts-charts {
    grid-template-columns: 1fr;
  }
  .mts-unit-filter {
    min-width: 0;
    flex: 1;
  }
}

/* ---------- Lịch sử chat: menu trái gọn + trang riêng (lich-su-hoi-thoai.html) ---------- */
.recent-list {
  flex-shrink: 0;
  margin-left: 12px;
  padding-left: 6px;
  border-left: 1px solid var(--border);
}

.recent-list .conversation-item {
  padding: 6px 8px;
}

.history-all-link {
  margin: 2px 0 4px 18px;
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}

.history-all-link:hover {
  text-decoration: underline;
}

.history-all-link[hidden] {
  display: none;
}

.hist-main {
  align-items: stretch;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
  gap: 16px;
}

.hist-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
}

.hist-search {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  font-size: 14px;
}

.hist-new {
  padding: 10px 14px;
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
}

.hist-bulk {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
}

.hist-bulk[hidden] {
  display: none;
}

.hist-count {
  margin-right: auto;
  font-size: 13px;
  color: var(--muted);
}

.hist-danger:not(:disabled) {
  color: var(--danger);
}

.hist-danger:not(:disabled):hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.hist-danger:disabled {
  color: var(--muted);
  cursor: default;
}

.hist-danger[hidden] {
  display: none;
}

.hist-group-title {
  margin: 8px 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.hist-group {
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.hist-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
}

.hist-item + .hist-item {
  border-top: 1px solid var(--border);
}

.hist-item:hover {
  background: var(--bg);
}

.hist-check {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
}

.hist-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--text);
  text-decoration: none;
}

.hist-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 500;
}

.hist-body:hover .hist-title {
  color: var(--accent);
}

.hist-snippet {
  font-size: 13px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.hist-meta {
  font-size: 12px;
  color: var(--muted);
}

.hist-mark {
  background: var(--accent-soft);
  color: inherit;
  border-radius: 2px;
}

.hist-delete {
  flex-shrink: 0;
  display: flex;
  padding: 6px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.hist-delete .icon {
  width: 16px;
  height: 16px;
}

.hist-delete:hover,
.hist-delete:focus-visible {
  background: var(--panel);
  color: var(--danger);
}

.hist-empty {
  padding: 24px 0;
  text-align: center;
}

@media (max-width: 640px) {
  .hist-toolbar {
    flex-wrap: wrap;
  }
  .hist-new {
    flex: 1;
    text-align: center;
  }
}

/* ---------- Lấy tin theo link (/lay-tin-theo-link.html) ---------- */
.link-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.link-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.link-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.link-form-actions .admin-submit-btn {
  padding: 10px 20px;
}

.link-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: -6px;
}

.link-preset {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.link-preset.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.link-preview {
  margin-top: 16px;
  padding: 14px 16px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--bg);
}

.link-preview-title {
  margin: 0 0 4px;
  font-size: 16px;
}

.link-preview-warn {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--accent);
}

.link-preview-content {
  margin-top: 10px;
  max-height: 360px;
  overflow-y: auto;
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.55;
}

.link-note {
  margin: 0 0 10px;
}

.link-search {
  max-width: 260px;
}

.link-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.link-table th,
.link-table td {
  text-align: left;
  vertical-align: top;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
}

.link-table th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.link-cell-main {
  min-width: 260px;
}

.link-strong {
  font-weight: 600;
}

.link-url {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--accent);
  word-break: break-all;
}

.link-interval {
  width: 84px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.link-badge {
  display: inline-block;
  margin: 0 4px 4px 0;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}

.link-badge-ok,
.link-badge-busy {
  background: var(--accent-soft);
  color: var(--accent);
}

.link-badge-muted {
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}

.link-badge-error {
  background: rgba(192, 57, 43, 0.12);
  color: var(--danger);
}

.link-error {
  font-size: 12px;
  color: var(--danger);
}

/* ---------- Nguồn thu thập (/nguon-thu-thap.html) ---------- */
.src-table tr.src-paused td {
  opacity: 0.6;
}

.src-table tr.src-same-site td {
  border-top-style: dashed;
}

.src-site {
  color: var(--text);
  text-decoration: none;
}

.src-site:hover {
  color: var(--accent);
  text-decoration: underline;
}

.src-cron {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.src-days {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.src-log-dialog {
  max-width: 960px;
}

.src-log {
  margin: 0;
  max-height: 60vh;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---------- Link trang nội bộ trong câu trả lời chat (chat.js formatAnswer) ---------- */
.message-bubble .answer-link {
  color: var(--accent);
  text-decoration: underline;
  word-break: break-all;
}

/* ---------- Trang tổng hợp Báo cáo hoạt động Thành Đoàn (/bao-cao-hoat-dong-thanh-doan.html) ---------- */
.tdb-section-title {
  margin: 8px 0 0;
  font-size: 16px;
}

.tdb-criteria-bar {
  display: inline-block;
  width: 72px;
  height: 8px;
  margin-right: 6px;
  border-radius: 4px;
  background: var(--accent-soft);
  overflow: hidden;
  vertical-align: middle;
}

.tdb-criteria-bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.stats-table tr.tdb-row-link {
  cursor: pointer;
}

.stats-table tr.tdb-row-link:hover td,
.stats-table tr.tdb-row-link:focus-visible td {
  background: var(--accent-soft);
}

.tdb-list-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.tdb-list-tools .users-select {
  flex: 1 1 220px;
  min-width: 0;
}

.tdb-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
}

.tdb-chip button {
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0;
}

.tdb-items {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.tdb-item {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
}

.tdb-item.no-thumb {
  grid-template-columns: 1fr;
}

.tdb-thumb {
  width: 96px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--accent-soft);
}

.tdb-item-title {
  margin: 0 0 4px;
  font-size: 15px;
  line-height: 1.35;
}

.tdb-item-title a {
  color: var(--text);
  text-decoration: none;
}

.tdb-item-title a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.tdb-item-meta {
  font-size: 13px;
  color: var(--muted);
}

.tdb-item-excerpt {
  margin: 6px 0 0;
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.tdb-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
  font-size: 14px;
}

@media (max-width: 560px) {
  .tdb-item {
    grid-template-columns: 64px 1fr;
  }
  .tdb-thumb {
    width: 64px;
    height: 52px;
  }
}

/* Bảng trong câu trả lời (chat.js markdownTables — vd. bảng tính tổng tiền) */
.answer-table-wrap {
  overflow-x: auto;
  margin: 6px 0;
}
.answer-table {
  border-collapse: collapse;
  white-space: normal;
  font-size: 0.95em;
}
.answer-table th,
.answer-table td {
  border: 1px solid var(--border, #d0d7de);
  padding: 4px 10px;
  text-align: left;
}
.answer-table th {
  background: rgba(127, 127, 127, 0.1);
  font-weight: 600;
}
.answer-table .num {
  text-align: right;
  white-space: nowrap;
}

/* ---------- Nút chuyển giao diện sáng/tối (js/theme.js chèn vào) ---------- */

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  margin-left: auto;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
}

.theme-toggle:hover {
  color: var(--text);
  background: var(--accent-soft);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.theme-toggle + .sidebar-close,
.admin-topbar-link:not([hidden]) ~ .theme-toggle {
  margin-left: 0;
}

.theme-toggle-floating {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 50;
}
