:root {
  --bg-1: #020617;
  --bg-2: #0b1120;
  --accent: #38bdf8;
  --accent-strong: #2563eb;
  --bubble-user: linear-gradient(135deg, #2563eb, #22c55e);
  --bubble-assistant: rgba(15, 23, 42, 0.86);
  --glass: rgba(15, 23, 42, 0.82);
}

/* ===== GLOBAL ===== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: #e5e7eb;
  background: radial-gradient(circle at 0% 0%, #1d4ed8, transparent 50%),
    radial-gradient(circle at 100% 100%, #22c55e, transparent 55%),
    linear-gradient(135deg, var(--bg-1), var(--bg-2));
  background-size: 140% 140%;
  animation: bgMove 25s ease-in-out infinite;
  overflow-x: hidden;
}

@keyframes bgMove {
  0% {
    background-position: 0% 0%, 100% 100%, 0% 0%;
  }
  50% {
    background-position: 100% 0%, 0% 100%, 100% 100%;
  }
  100% {
    background-position: 0% 0%, 100% 100%, 0% 0%;
  }
}

.bg-orbit {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 20% 10%, rgba(59, 130, 246, 0.35), transparent 55%),
    radial-gradient(circle at 80% 90%, rgba(34, 197, 94, 0.3), transparent 55%);
  mix-blend-mode: screen;
  opacity: 0.6;
  z-index: -1;
}

/* ===== HEADER ===== */

.header {
  padding: 18px 30px 8px;
}

.header-inner {
  max-width: 980px;
  margin: 0 auto;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 24px;
  font-weight: 700;
  color: #f9fafb;
  letter-spacing: 0.02em;
}

.logo-orb {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: conic-gradient(from 200deg, #22c55e, #38bdf8, #a855f7, #22c55e);
  box-shadow: 0 0 16px rgba(59, 130, 246, 0.9);
}

.logo-text {
  text-shadow: 0 0 16px rgba(15, 23, 42, 0.8);
}

.sub {
  font-size: 12px;
  color: #9ca3af;
  margin-top: 4px;
}

.main {
  display: flex;
  justify-content: center;
  padding: 10px 16px 26px;
}

/* ===== CHAT CARD ===== */

.chat-shell {
  width: 100%;
  max-width: 980px;
}

.chat-card {
  position: relative;
  border-radius: 22px;
  padding: 18px;
  background: radial-gradient(circle at 0% 0%, rgba(148, 163, 184, 0.14), transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(34, 197, 94, 0.06), transparent 55%),
    var(--glass);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.35);
  backdrop-filter: blur(22px);
  display: flex;
  flex-direction: column;
}

/* ===== CHAT BOX ===== */

.chat-box {
  height: 62vh;
  min-height: 420px;
  max-height: 70vh;
  overflow-y: auto;
  padding: 12px 14px 10px;
  border-radius: 14px;
  background: radial-gradient(circle at 0% 0%, rgba(15, 23, 42, 0.7), transparent 55%),
    radial-gradient(circle at 100% 100%, rgba(15, 23, 42, 0.7), transparent 55%),
    linear-gradient(160deg, rgba(15, 23, 42, 0.95), rgba(15, 23, 42, 0.85));
}

.chat-box::-webkit-scrollbar {
  width: 8px;
}
.chat-box::-webkit-scrollbar-track {
  background: transparent;
}
.chat-box::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.6);
  border-radius: 999px;
}
.chat-box:hover::-webkit-scrollbar-thumb {
  background: rgba(248, 250, 252, 0.7);
}

/* ===== MESSAGES ===== */

.msg {
  display: flex;
  margin-bottom: 14px;
}

.msg.user {
  justify-content: flex-end;
}

.msg.assistant {
  justify-content: flex-start;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: radial-gradient(circle at 28% 20%, #bfdbfe, #1d4ed8);
  color: #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  margin-right: 8px;
  box-shadow: 0 14px 35px rgba(37, 99, 235, 0.6);
}

/* ===== BUBBLES ===== */

.bubble {
  max-width: 72%;
  padding: 11px 15px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
  border: 1px solid rgba(148, 163, 184, 0.35);
}

.user-bubble {
  background-image: var(--bubble-user);
  color: #f9fafb;
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 18px 36px rgba(37, 99, 235, 0.6);
}

.assistant-bubble {
  background: rgba(15, 23, 42, 0.96);
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 16px 34px rgba(15, 23, 42, 0.9);
}

/* markdown inside */
.bubble h1,
.bubble h2,
.bubble h3 {
  margin: 4px 0 6px;
  font-weight: 700;
}
.bubble h1 {
  font-size: 18px;
}
.bubble h2 {
  font-size: 16px;
}
.bubble h3 {
  font-size: 15px;
}
.bubble p {
  margin: 0 0 6px;
}
.bubble p:last-child {
  margin-bottom: 0;
}
.bubble ul,
.bubble ol {
  margin: 4px 0 6px 20px;
  padding: 0;
}
.bubble li {
  margin-bottom: 3px;
}
.bubble table {
  border-collapse: collapse;
  width: 100%;
  margin-top: 8px;
  font-size: 12px;
}
.bubble th,
.bubble td {
  border: 1px solid rgba(148, 163, 184, 0.6);
  padding: 4px 6px;
}
.bubble th {
  background: rgba(30, 64, 175, 0.7);
}

/* ===== INPUT AREA ===== */

.input-row {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  align-items: center;
}

.chat-input {
  display: flex;
  gap: 10px;
  flex: 1;
  align-items: stretch;
}

.chat-input input {
  flex: 1;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.8);
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
  font-size: 14px;
  outline: none;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.8);
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}

.chat-input input::placeholder {
  color: #6b7280;
}

.chat-input input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.9),
    0 0 20px rgba(37, 99, 235, 0.6);
  background: rgba(15, 23, 42, 0.98);
}

/* send button */
.btn-send {
  position: relative;
  padding: 11px 22px;
  border-radius: 999px;
  border: none;
  background: radial-gradient(circle at 0% 0%, #22c55e, transparent 55%),
    linear-gradient(135deg, #2563eb, #7c3aed);
  color: #f9fafb;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 16px 40px rgba(56, 189, 248, 0.6);
  overflow: hidden;
  transform-origin: center;
  transition: transform 0.12s ease-out, box-shadow 0.16s ease-out,
    filter 0.12s ease-out;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-send span {
  position: relative;
  z-index: 2;
}

.btn-send::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 0 0, rgba(248, 250, 252, 0.9), transparent 60%);
  opacity: 0;
  transition: opacity 0.18s ease-out;
}

.btn-send:hover {
  transform: translateY(-1px) scale(1.02);
  box-shadow: 0 22px 50px rgba(56, 189, 248, 0.9);
  filter: brightness(1.03);
}
.btn-send:hover::before {
  opacity: 0.4;
}

.btn-send:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 14px 30px rgba(56, 189, 248, 0.75);
}

/* reset button – đồng bộ chiều cao & style với send */
.btn-reset {
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.8);
  background: radial-gradient(circle at 100% 0, rgba(148, 163, 184, 0.2), transparent 60%),
    rgba(15, 23, 42, 0.92);
  color: #e5e7eb;
  font-size: 13px;
  cursor: pointer;
  min-width: 80px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.9);
  transition: transform 0.12s ease-out, box-shadow 0.16s ease-out,
    border-color 0.16s ease-out, background 0.16s ease-out;
}

.btn-reset:hover {
  transform: translateY(-1px);
  border-color: rgba(209, 213, 219, 0.9);
  background: rgba(15, 23, 42, 0.98);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 1);
}

.btn-reset:active {
  transform: translateY(0);
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.9);
}

/* ===== TYPING INDICATOR ===== */

.typing-indicator {
  display: none;
  margin-top: 4px;
}

#typing-indicator.htmx-request {
  display: block;
}

.typing-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.7);
  font-size: 11px;
  color: #9ca3af;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #9ca3af;
  animation: dotPulse 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}
.typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

.typing-text {
  letter-spacing: 0.03em;
}

@keyframes dotPulse {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.3;
  }
  40% {
    transform: translateY(-2px);
    opacity: 1;
  }
}

/* ===== ATTACHMENT ===== */

.attach {
  margin-top: 8px;
  font-size: 13px;
}
.attach-link {
  color: #38bdf8;
  text-decoration: none;
}
.attach-link:hover {
  text-decoration: underline;
}

/* ===== BUBBLE ANIMATIONS ===== */

.animate-in-right {
  animation: bubbleInRight 0.3s ease-out;
}
.animate-in-left {
  animation: bubbleInLeft 0.3s ease-out;
}

@keyframes bubbleInRight {
  0% {
    opacity: 0;
    transform: translateX(16px) scale(0.96);
  }
  100% {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}
@keyframes bubbleInLeft {
  0% {
    opacity: 0;
    transform: translateX(-16px) scale(0.96);
  }
  100% {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

/* ===== GLOW CURSOR – FIX LỆCH ===== */

#cursor-dot {
  position: fixed;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.85), transparent 70%);
  pointer-events: none;
  mix-blend-mode: screen;
  left: -999px;
  top: -999px;
  z-index: 9999;
}
