:root {
  --brand-blue: #3b82f6;
  --page-bg: #f8fafc;
  --student-bubble-bg: #f1f5f9;
  --student-bubble-text: #1e293b;
  --input-bg: #ffffff;
  --input-border: #e2e8f0;
  --header-height: 58px;
  --composer-height: 210px;
  --keyboard-offset: 0px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--page-bg);
  color: #0f172a;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.chat-page {
  min-height: 100dvh;
  background: var(--page-bg);
}

.chat-shell {
  width: min(100%, 680px);
  margin: 0 auto;
  padding: 0 14px;
}

.chat-header {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  height: var(--header-height);
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  z-index: 20;
}

.chat-header .chat-shell {
  height: 100%;
  display: flex;
  align-items: center;
}

.brand-title {
  font-size: 16px;
  font-weight: 600;
  color: #0f172a;
  line-height: 1.2;
}

.chat-main {
  position: fixed;
  top: var(--header-height);
  right: 0;
  bottom: calc(var(--composer-height) + var(--keyboard-offset));
  left: 0;
}

.chat-main-shell {
  height: 100%;
}

.message-list {
  height: 100%;
  overflow-y: auto;
  padding: 14px 0 18px;
  scroll-behavior: smooth;
}

.message-row {
  display: flex;
  margin-bottom: 12px;
}

.message-row.student {
  justify-content: flex-start;
}

.message-row.ai {
  justify-content: flex-end;
}

.message-row.system {
  justify-content: center;
}

.message-bubble {
  max-width: min(86%, 520px);
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.6;
  word-break: break-word;
}

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

.message-row.ai .message-bubble {
  background: var(--brand-blue);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.message-bubble p {
  margin: 0 0 8px;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble ul,
.message-bubble ol {
  margin: 0 0 8px 1.25em;
  padding: 0;
}

.message-bubble ul:last-child,
.message-bubble ol:last-child {
  margin-bottom: 0;
}

.message-bubble li + li {
  margin-top: 4px;
}

.message-row.ai .message-bubble a {
  color: #dbeafe;
  text-decoration: underline;
}

.message-row.student .message-bubble a {
  color: #1d4ed8;
}

.system-note {
  max-width: min(90%, 520px);
  border-radius: 10px;
  padding: 8px 12px;
  background: #e0ecff;
  color: #1d4ed8;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.typing-label {
  font-size: 14px;
  opacity: 0.95;
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
  transform: translateY(1px);
}

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

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

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

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

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

.chat-composer {
  position: fixed;
  right: 0;
  bottom: var(--keyboard-offset);
  left: 0;
  z-index: 30;
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(226, 232, 240, 0.95);
  background: var(--page-bg);
}

.composer-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

#chatInput {
  flex: 1;
  min-height: 48px;
  max-height: 150px;
  margin: 0;
  padding: 12px 16px;
  border: 1px solid var(--input-border);
  border-radius: 24px;
  background: var(--input-bg);
  color: #0f172a;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  outline: none;
}

#chatInput:focus {
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.14);
}

#chatInput:disabled {
  color: #64748b;
  background: #f1f5f9;
}

#sendButton {
  width: 48px;
  height: 48px;
  min-width: 48px;
  border: none;
  border-radius: 24px;
  background: var(--brand-blue);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

#sendButton svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

#sendButton:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.quick-questions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.quick-question {
  border: 1px solid var(--input-border);
  border-radius: 999px;
  background: #ffffff;
  color: #334155;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.3;
  cursor: pointer;
}

.quick-question:hover {
  border-color: #93c5fd;
  color: #1d4ed8;
}

.quick-question:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.privacy-line {
  margin: 10px 2px 0;
  color: #64748b;
  font-size: 12px;
  line-height: 1.4;
}

.privacy-line a {
  color: inherit;
  text-decoration: underline;
}

.privacy-line a:hover {
  color: #334155;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 768px) {
  :root {
    --header-height: 54px;
  }

  .chat-shell {
    padding: 0 10px;
  }

  .message-bubble {
    max-width: 90%;
  }

  #chatInput {
    min-height: 50px;
  }

  #sendButton {
    width: 50px;
    height: 50px;
    min-width: 50px;
  }

  .quick-question {
    font-size: 12.5px;
    padding: 8px 11px;
  }
}
