:root {
  --hku-blue: #003366;
  --hku-gold: #996633;
  --bg-light: #f4f7f9;
  --text-dark: #333;
  --border-color: #e0e0e0;
}

body {
  font-family: "Roboto", sans-serif;
  background-color: var(--bg-light);
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  padding: 24px;
}

#chat-container {
  width: min(980px, 96vw);
  height: min(900px, 92vh);
  background: white;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  overflow: hidden;
  border-top: 6px solid var(--hku-blue);
}

@media (min-width: 1200px) {
  #chat-container {
    width: min(1100px, 94vw);
    height: min(940px, 90vh);
  }
}

header {
  background: white;
  padding: 20px;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  gap: 15px;
}

header img {
  height: 45px;
  margin-right: 0;
  flex-shrink: 0;
}

.logo-link {
  display: inline-flex;
  align-items: center;
  line-height: 0;
}

header .title {
  flex: 1;
  text-align: right;
  min-width: 0;
}

@media (max-width: 480px) {
  header {
    padding: 14px 14px;
    flex-wrap: wrap;
    gap: 10px;
  }

  header img {
    height: 34px;
  }

  header h1 {
    font-size: 16px;
    letter-spacing: 0.5px;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  header .title {
    flex: 1 1 100%;
    text-align: right;
  }
}

header h1 {
  font-size: 18px;
  margin: 0;
  color: var(--hku-blue);
  text-transform: uppercase;
  letter-spacing: 1px;
}

header p {
  font-size: 12px;
  margin: 0;
  color: #777;
}

#chat-window {
  flex: 1;
  padding: 25px;
  overflow-y: auto;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.msg {
  max-width: 90%;
  padding: 15px 20px;
  font-size: 14px;
  line-height: 1.6;
  border-radius: 18px;
}

.msg.bot {
  align-self: flex-start;
  background: #f8f9fa;
  border: 1px solid var(--border-color);
  color: var(--text-dark);
  border-bottom-left-radius: 4px;
}

.msg.user {
  align-self: flex-end;
  background: var(--hku-blue);
  color: white;
  border-bottom-right-radius: 4px;
}

/* --- BEAUTIFUL MARKDOWN STYLING --- */
.msg h2,
.msg h3 {
  margin-top: 10px;
  margin-bottom: 5px;
  color: var(--hku-blue);
}

.msg p {
  margin: 8px 0;
}

.msg ul,
.msg ol {
  padding-left: 20px;
}

/* Table Styling */
.msg table {
  border-collapse: collapse;
  width: 100%;
  margin: 15px 0;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  font-size: 13px;
}

.msg th {
  background: var(--hku-blue);
  color: white;
  padding: 10px;
  text-align: left;
}

.msg td {
  border: 1px solid var(--border-color);
  padding: 8px;
  color: #555;
}

.msg tr:nth-child(even) {
  background-color: #f2f2f2;
}

.msg img {
  display: block;
  width: min(100%, 720px);
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 12px auto;
  border: 1px solid #ddd;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
  cursor: zoom-in;
}

body.embedded .msg img {
  width: min(100%, 820px);
  margin: 14px auto;
}

@media (max-width: 768px) {
  .msg img,
  body.embedded .msg img {
    width: 100%;
    margin: 10px 0;
  }
}

.image-lightbox {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.86);
  padding: 24px;
  z-index: 10000;
}

.image-lightbox.open {
  display: flex;
}

.image-lightbox img {
  display: block;
  max-width: min(92vw, 1200px);
  max-height: 88vh;
  width: auto;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.45);
}

body.embedded .image-lightbox {
  padding: 14px;
}

body.embedded .image-lightbox img {
  max-width: 95vw;
  max-height: 90vh;
}

.msg a {
  color: var(--hku-gold);
  font-weight: bold;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.msg a:hover {
  border-bottom: 1px solid var(--hku-gold);
}

/* Input Area */
#input-area {
  padding: 20px;
  background: white;
  border-top: 1px solid #eee;
  display: flex;
  gap: 12px;
}

#chatInput {
  flex: 1;
  border: 1px solid #ddd;
  padding: 12px 15px;
  border-radius: 6px;
  outline: none;
  font-size: 14px;
}

#sendBtn {
  background: var(--hku-blue);
  color: white;
  border: none;
  padding: 0 25px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
}

#sendBtn:hover {
  background: #002244;
}

.typing {
  display: none;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #4a5f77;
  font-weight: 600;
  letter-spacing: 0.2px;
  margin: 0 0 10px 25px;
  width: fit-content;
  padding: 6px 0;
  border-radius: 0;
  background: transparent;
  border: none;
  animation: typing-row 1.8s ease-in-out infinite;
}

.typing-shield-wrap {
  position: relative;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  overflow: hidden;
}

.typing-shield {
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.32;
  filter: grayscale(1) saturate(0.2) brightness(1.2);
  transform: scale(0.98);
  animation: shield-fill 1.4s ease-in-out infinite;
}

.typing-shield-wrap::after {
  content: "";
  position: absolute;
  inset: -2px;
  background: linear-gradient(
    120deg,
    rgba(0, 51, 102, 0) 0%,
    rgba(0, 51, 102, 0.45) 46%,
    rgba(153, 102, 51, 0.55) 58%,
    rgba(0, 51, 102, 0) 100%
  );
  transform: translateX(-150%) skewX(-15deg);
  animation: shield-sweep 1.4s linear infinite;
  pointer-events: none;
}

.typing-label {
  white-space: nowrap;
  animation: typing-label 1.8s ease-in-out infinite;
}

.typing-dots {
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
  min-width: 18px;
}

.typing-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--hku-blue);
  opacity: 0.35;
  animation: typing-dot 1.1s ease-in-out infinite;
}

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

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

@keyframes shield-fill {
  0%,
  30% {
    opacity: 0.3;
    filter: grayscale(1) saturate(0.2) brightness(1.2);
    transform: scale(0.98);
  }

  70%,
  100% {
    opacity: 1;
    filter: grayscale(0) saturate(1.08) brightness(1);
    transform: scale(1);
  }
}

@keyframes shield-sweep {
  from {
    transform: translateX(-150%) skewX(-15deg);
  }

  to {
    transform: translateX(280%) skewX(-15deg);
  }
}

@keyframes typing-dot {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }

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

@keyframes typing-row {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.9;
  }

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

@keyframes typing-label {
  0%,
  100% {
    color: #4a5f77;
    text-shadow: none;
  }

  50% {
    color: #003366;
    text-shadow: 0 0 8px rgba(0, 51, 102, 0.2);
  }
}

@media (prefers-reduced-motion: reduce) {
  .typing,
  .typing-label,
  .typing-shield,
  .typing-shield-wrap::after,
  .typing-dots span {
    animation: none;
  }
}

/* Feedback Buttons */
.feedback-container {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  margin-left: 0;
}

.feedback-btn {
  background: transparent;
  border: 1px solid #e0e0e0;
  padding: 6px 12px;
  border-radius: 16px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

.feedback-btn:hover {
  background: #f0f0f0;
  border-color: var(--hku-blue);
}

.feedback-btn.active {
  background: var(--hku-blue);
  color: white;
  border-color: var(--hku-blue);
}

body.embedded {
  height: auto;
  min-height: 100vh;
  padding: 8px;
  align-items: stretch;
}

body.embedded #chat-container {
  width: 100%;
  height: min(100vh - 16px, 100%);
  min-height: 640px;
}

body.embedded #chat-window {
  padding: 18px;
  gap: 16px;
}

body.embedded #input-area {
  padding: 14px;
}

body.embedded .msg {
  max-width: 95%;
}

@media (max-width: 768px) {
  body.embedded {
    padding: 0;
  }

  body.embedded #chat-container {
    width: 100%;
    height: 100vh;
    min-height: 0;
    border-radius: 0;
    border-top-width: 4px;
  }

  body.embedded header {
    padding: 14px;
    gap: 12px;
  }

  body.embedded header img {
    height: 36px;
  }

  body.embedded header h1 {
    font-size: 16px;
  }

  body.embedded #chat-window {
    padding: 14px;
    gap: 14px;
  }

  body.embedded .msg {
    max-width: 100%;
    padding: 12px 14px;
    font-size: 13px;
  }

  body.embedded #input-area {
    padding: 12px;
    gap: 10px;
  }

  body.embedded #chatInput {
    padding: 10px 12px;
  }

  body.embedded #sendBtn {
    padding: 0 18px;
  }

  body.embedded .typing {
    margin: 0 0 8px 14px;
  }
}

/* Disclaimer Modal */
.disclaimer-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}

.disclaimer-modal.hidden {
  display: none;
}

.disclaimer-card {
  width: min(760px, 95vw);
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
  border-top: 6px solid var(--hku-blue);
}

.disclaimer-card h2 {
  margin: 0 0 12px;
  color: var(--hku-blue);
  font-size: 24px;
}

.disclaimer-card p {
  margin: 0;
  color: #333;
  line-height: 1.6;
  font-size: 14px;
}

#agreeBtn {
  margin-top: 20px;
  background: var(--hku-blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 18px;
  font-weight: 700;
  cursor: pointer;
}

#agreeBtn:hover {
  background: #002244;
}

#sendBtn:disabled,
#chatInput:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}
