/* ─────────────────────────────────────
   CSS Variables
───────────────────────────────────── */
:root {
  --bg: #f5f3ef;
  --sidebar-bg: #faf8f4;
  --border: #e4e0d8;
  --text: #1a1a1a;
  --muted: #888;
  --accent: #8b1a2e;
  --accent2: #a82040;
  --chip-bg: #fff;
  --chip-border: #d8d4cc;
  --input-bg: #fff;
  --sidebar-w: 220px;
  --header-h: 52px;
}

/* ─────────────────────────────────────
   Reset
───────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ─────────────────────────────────────
   Body
───────────────────────────────────── */
body {
  font-family: 'Be Vietnam Pro', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─────────────────────────────────────
   HEADER — chỉ phần main (bên phải sidebar)
───────────────────────────────────── */
header {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  z-index: 100;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text);
  flex-shrink: 0;
}

.header-agent {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.header-agent-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.header-agent-avatar svg {
  color: #fff;
}

.header-agent-info .agent-name {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
}

.header-agent-info .agent-sub {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.online-dot {
  width: 7px;
  height: 7px;
  background: #22c55e;
  border-radius: 50%;
}

.header-title {
  flex: 1;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
}

/* ─────────────────────────────────────
   LAYOUT
───────────────────────────────────── */
.layout {
  display: flex;
  height: 100dvh;
}

/* ─────────────────────────────────────
   SIDEBAR
───────────────────────────────────── */
aside {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform .25s ease;
}

/* Sidebar top bar — logo + nút Mới */
.sidebar-header {
  height: var(--header-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 14px;
  border-bottom: 1px solid var(--border);
}

.logo-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
  white-space: nowrap;
}

.btn-new {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--text);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .18s;
  white-space: nowrap;
}

.btn-new:hover {
  background: #333;
}

.btn-new svg {
  flex-shrink: 0;
}

/* Sidebar scrollable body */
.sidebar-inner {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.search-box {
  position: relative;
  margin-bottom: 16px;
}

.search-box input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px 7px 32px;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}

.search-box input::placeholder {
  color: #b0a898;
}

.search-box input:focus {
  border-color: var(--accent);
}

.search-box .search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .7px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 4px;
  margin-bottom: 6px;
  margin-top: 4px;
}

.sessions-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 28px 12px 20px;
  color: var(--muted);
}

.sessions-empty svg {
  opacity: .35;
  margin-bottom: 2px;
}

.sessions-empty span {
  font-size: 12px;
  line-height: 1.5;
}

.sessions-load-more {
  text-align: center;
  padding: 8px 0 4px;
}

.load-more-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  padding: 5px 16px;
  cursor: pointer;
  width: 100%;
  transition: background .15s;
}

.load-more-btn:hover:not(:disabled) {
  background: var(--border);
  color: var(--text);
}

.load-more-btn:disabled {
  opacity: .5;
  cursor: default;
}

#attachmentPreview {
  max-width: 760px;
  margin: 0 auto 8px;
  padding: 0;
}

.attachment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  background: #f4efe6;
  border: 1px solid #ded5c7;
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 12px;
  color: var(--text);
  margin-bottom: 6px;
}

.attachment-item:last-child {
  margin-bottom: 0;
}

.attachment-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.attachment-icon {
  color: #9e9485;
  flex-shrink: 0;
}

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

.attachment-remove {
  background: none;
  border: none;
  color: #a39a8b;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  flex-shrink: 0;
}

.attachment-remove:hover {
  color: var(--accent);
}

.conv-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 7px;
  cursor: pointer;
  transition: background .15s;
  margin-bottom: 2px;
}

.conv-item:hover {
  background: rgba(139, 26, 46, .07);
}

.conv-item.active {
  background: rgba(139, 26, 46, .10);
}

.conv-actions {
  display: flex;
  align-items: center;
  margin-left: 6px;
  flex-shrink: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease;
}

.conv-item:hover .conv-actions,
.conv-item.active:hover .conv-actions {
  opacity: 1;
  pointer-events: auto;
}

.conv-delete-btn {
  background: none;
  border: none;
  color: #A8A29E;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 5px;
  border-radius: 5px;
  opacity: 0;
  transition: all .12s;
  flex-shrink: 0;
}

.conv-item:hover .conv-delete-btn {
  opacity: 1;
}

.conv-delete-btn:hover {
  background: rgba(139, 26, 46, .08);
  border-color: rgba(139, 26, 46, .18);
  color: var(--accent);
}

.conv-delete-btn:active {
  transform: translateY(0.5px);
}

.conv-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--muted);
  margin-top: 3px;
  flex-shrink: 0;
}

.conv-info {
  flex: 1;
  min-width: 0;
}

.conv-title {
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--accent);
}

.conv-date {
  font-size: 9px;
  color: var(--muted);
  margin-top: 1px;
}

/* Sidebar footer — user profile */
.sidebar-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background .15s;
}

.sidebar-footer:hover {
  background: rgba(139, 26, 46, .05);
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #7c6fa0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 4px;
  border-radius: 4px;
  display: flex;
  transition: color .15s, background .15s;
  flex-shrink: 0;
}

.user-menu-btn:hover {
  color: var(--text);
  background: rgba(0, 0, 0, .05);
}

/* ─────────────────────────────────────
   MAIN
───────────────────────────────────── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  padding-top: var(--header-h);
}

/* ─────────────────────────────────────
   CHAT AREA
───────────────────────────────────── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px 130px;
  overflow-y: auto;
  transition: justify-content .2s;
}

.chat-area.has-messages {
  justify-content: flex-start;
}

/* Welcome screen */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: fadeUp .45s ease both;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(18px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.welcome-icon {
  width: 72px;
  height: 72px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  box-shadow: 0 8px 24px rgba(139, 26, 46, .25);
}

.welcome-icon svg {
  color: #fff;
}

.welcome h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.4px;
}

.welcome p {
  font-size: 13.5px;
  color: #666;
  max-width: 575px;
  line-height: 1.65;
  margin-bottom: 26px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 620px;
}

.chip {
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  border-radius: 20px;
  padding: 7px 15px;
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, background .15s, box-shadow .15s;
  white-space: nowrap;
}

.chip:hover {
  border-color: var(--accent);
  background: rgba(139, 26, 46, .05);
  box-shadow: 0 2px 8px rgba(139, 26, 46, .12);
}

/* ─────────────────────────────────────
   MESSAGES
───────────────────────────────────── */
.messages {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  max-width: 760px;
  padding: 20px 0 10px;
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  animation: fadeUp .3s ease both;
}

.msg-row.user {
  flex-direction: row;
  justify-content: flex-end;
}

.msg-row.user .msg-bubble {
  order: 1;
}

.msg-row.user .msg-avatar {
  order: 2;
}

.msg-row.bot {
  flex-direction: row;
}

.msg-row.bot .msg-bubble {
  order: 2;
}

.msg-row.bot .msg-avatar {
  order: 1;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.msg-avatar.user-av {
  background: #7c6fa0;
  color: #fff;
}

.msg-avatar.bot-av {
  background: var(--accent);
  color: #fff;
}

.msg-avatar.bot-av svg {
  color: #fff;
}

.msg-bubble {
  max-width: min(72%, 520px);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bubble-text {
  padding: 11px 15px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.6;
  word-break: break-word;
}

.msg-row.user .bubble-text {
  background: #1a1a1a;
  color: #fff;
  border-radius: 18px 18px 4px 18px;
}

.msg-row.bot .bubble-text {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 18px 4px 18px 18px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .06);
}

/* Kết quả check trục — HTML từ API (parseMarkdown không escape khối này) */
.msg-row.bot .bubble-text .fh-axis-body {
  margin: 0;
  font-size: inherit;
  line-height: inherit;
}

/* Source chips */
.source-chips {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  padding-left: 2px;
}

.source-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #eef4ff;
  border: 1px solid #c8d8f8;
  border-radius: 14px;
  padding: 4px 10px;
  font-size: 11.5px;
  color: #3b6cbf;
  cursor: pointer;
  transition: background .15s;
  text-decoration: none;
}

.source-chip:hover {
  background: #ddeaff;
}

.source-chip svg {
  flex-shrink: 0;
  opacity: .7;
}

/* Typing indicator */
.typing-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.typing-bubble {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 5px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .06);
}

.typing-dot {
  width: 7px;
  height: 7px;
  background: var(--muted);
  border-radius: 50%;
  animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: .2s;
}

.typing-dot:nth-child(3) {
  animation-delay: .4s;
}

@keyframes typingBounce {

  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: .4;
  }

  40% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* ─────────────────────────────────────
   INPUT BAR
───────────────────────────────────── */
.input-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 14px 20px 18px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.input-wrap {
  display: flex;
  align-items: center;
  background: var(--input-bg);
  border: 1.5px solid var(--chip-border);
  border-radius: 28px;
  padding: 6px 8px 6px 14px;
  gap: 4px;
  max-width: 760px;
  margin: 0 auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .07);
  transition: border-color .2s, box-shadow .2s;
}

.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 4px 20px rgba(139, 26, 46, .13);
}

.input-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 50%;
  transition: color .15s, background .15s;
  flex-shrink: 0;
}

.input-icon-btn:hover {
  color: var(--accent);
  background: rgba(139, 26, 46, .06);
}

.input-wrap input {
  flex: 1;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: transparent;
}

.input-wrap input::placeholder {
  color: #b0a898;
}

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

.send-btn:hover {
  background: var(--accent2);
  transform: scale(1.05);
}

.send-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
}

.input-hint {
  text-align: center;
  font-size: 10.5px;
  color: #b0a898;
  margin-top: 8px;
}

.input-hint kbd {
  background: #e8e4dc;
  border-radius: 3px;
  padding: 1px 4px;
  font-family: inherit;
  font-size: 10px;
}

/* ─────────────────────────────────────
   OVERLAY
───────────────────────────────────── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .35);
  z-index: 90;
}

/* ─────────────────────────────────────
   RESPONSIVE
───────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --sidebar-w: 240px;
  }

  header {
    left: 0;
  }

  .hamburger {
    display: flex;
  }

  aside {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    z-index: 95;
  }

  aside.open {
    transform: translateX(0);
  }

  .overlay.open {
    display: block;
  }

  .chat-area {
    padding-bottom: 130px;
  }

  .welcome h1 {
    font-size: 18px;
  }

  .welcome p {
    font-size: 12.5px;
  }

  .chip {
    font-size: 12px;
    padding: 6px 13px;
  }

  .input-bar {
    padding: 10px 12px 14px;
  }
}

@media (max-width: 420px) {
  .chips {
    gap: 6px;
  }

  .chip {
    font-size: 11.5px;
    padding: 5px 11px;
  }

  .welcome h1 {
    font-size: 16px;
  }
}