:root {
  --app-bg: #e4ddd6;
  --app-bg-pattern:
    radial-gradient(circle at 22% 24%, rgba(255, 255, 255, 0.2) 0, rgba(255, 255, 255, 0) 40%),
    radial-gradient(circle at 78% 4%, rgba(0, 0, 0, 0.035) 0, rgba(0, 0, 0, 0) 34%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0));
  --surface: #f0f2f5;
  --surface-soft: #efeae2;
  --line: #d4d8dc;
  --line-strong: #bcc5cf;
  --text: #111b21;
  --muted: #667781;
  --brand: #008069;
  --brand-strong: #005c4b;
  --bubble-user: #d9fdd3;
  --bubble-bot: #ffffff;
  --avatar-user: #d4f4ea;
  --avatar-bot: #e8f4ff;
  --shadow-shell: 0 10px 26px rgba(17, 27, 33, 0.13);
  --shadow-bubble: 0 1px 1px rgba(0, 0, 0, 0.08);
  --radius-shell: 14px;
  --radius-bubble: 9px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background-color: var(--app-bg);
  background-image: var(--app-bg-pattern);
  font-family: "Manrope", "Segoe UI", sans-serif;
  color: var(--text);
}

.chat-app {
  height: 100vh;
  height: 100dvh;
  padding: 0;
  overflow: hidden;
}

.chat-shell {
  width: 100%;
  height: 100%;
  margin: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--surface-soft);
  border: none;
  border-radius: 0;
  overflow: hidden;
}

.chat-header {
  padding: 14px 14px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(135deg, #0b5f73 0%, #0a4f62 55%, #083f50 100%);
}

.chat-header-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.chat-header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chat-header-copy {
  min-width: 0;
}

.chat-header-title {
  margin: 0;
}

.chat-header-bot-icon {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.36);
  overflow: hidden;
  flex-shrink: 0;
}

.chat-header-bot-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chat-header h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.chat-header p {
  margin: 5px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.chat-header-clear {
  border: 1px solid #c7d3dc;
  border-radius: 999px;
  background: #ffffff;
  color: #355063;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 6px 10px;
}

.chat-header-clear:hover {
  background: #f4f8fb;
}


.chat-header h1 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #f3fbff;
}

.chat-header p {
  margin: 4px 0 0;
  font-size: 0.8rem;
  line-height: 1.45;
  color: rgba(244, 255, 251, 0.92);
}

.chat-thread {
  overflow-y: auto;
  padding: 12px 10px 14px;
  display: grid;
  align-content: start;
  gap: 10px;
}

.chat-message {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 100%;
}

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

.chat-message--bot {
  align-items: flex-start;
}

.chat-bubble {
  position: relative;
  width: fit-content;
  max-width: min(84vw, 640px);
  border: 1px solid var(--line);
  border-radius: var(--radius-bubble);
  padding: 9px 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  box-shadow: var(--shadow-bubble);
}

.chat-bubble a {
  color: #0b6fb8;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.chat-bubble a:hover {
  color: #095e9b;
}

.chat-bot-line,
.chat-bot-heading {
  margin: 0;
}

.chat-bot-line + .chat-bot-line,
.chat-bot-line + .chat-bot-heading,
.chat-bot-heading + .chat-bot-line,
.chat-bot-heading + .chat-bot-heading,
.chat-bot-list + .chat-bot-line,
.chat-bot-list + .chat-bot-heading,
.chat-bot-line + .chat-bot-list,
.chat-bot-heading + .chat-bot-list {
  margin-top: 7px;
}

.chat-bot-heading {
  font-weight: 800;
  color: #1a2f41;
}

.chat-bot-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 5px;
}

.chat-bot-list li {
  margin: 0;
}

.chat-info-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
}

.chat-info-chip--new {
  background: #e8f9f0;
  color: #0a6b45;
  border-color: #a6e4c5;
}

.chat-info-chip--update {
  background: #e9f4ff;
  color: #0d4f80;
  border-color: #b6d8f5;
}

.chat-info-chip--change {
  background: #fff4e7;
  color: #8a4e12;
  border-color: #f0c998;
}

.chat-message--user .chat-bubble {
  background: var(--bubble-user);
  border-top-right-radius: 4px;
}

.chat-message--user .chat-bubble::after {
  content: '';
  position: absolute;
  top: 0;
  right: -7px;
  border-top: 8px solid var(--bubble-user);
  border-left: 8px solid transparent;
}

.chat-message--bot .chat-bubble {
  background: var(--bubble-bot);
  border-top-left-radius: 4px;
}

.chat-message--bot .chat-bubble::after {
  content: '';
  position: absolute;
  top: 0;
  left: -7px;
  border-top: 8px solid var(--bubble-bot);
  border-right: 8px solid transparent;
}

.chat-bubble--image {
  padding: 6px;
}

.chat-upload-preview {
  display: block;
  max-width: min(260px, 66vw);
  width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  object-fit: cover;
}

.chat-upload-preview--zoomable {
  cursor: zoom-in;
}

.chat-extra {
  display: grid;
  gap: 8px;
  width: fit-content;
  max-width: min(82vw, 620px);
}

.chat-extra-title {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  color: #2f4858;
}

.chat-extra-hint {
  margin: 0;
  font-size: 0.76rem;
  color: #4a6577;
}

.course-chip {
  display: block;
  width: 100%;
  margin: 0;
  border: 1px solid #c8dae6;
  border-radius: 9px;
  padding: 8px 10px;
  text-align: left;
  background: #f1f8fc;
  color: #0f3650;
  font-size: 0.79rem;
  font-weight: 700;
}

.course-chip:hover {
  background: #e7f2f8;
}

.course-chip--eligible {
  border-color: #a9ddb6;
  background: #eaf8ee;
  color: #1f5c2a;
}

.course-chip--not-eligible {
  border-color: #e1c6c6;
  background: #fff2f2;
  color: #7a2a2a;
}

.chat-inline-course-link {
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  color: #0a6fb3;
  text-decoration: underline;
  text-underline-offset: 2px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}

.chat-inline-course-link:hover {
  color: #085b93;
}

.course-chip:focus-visible,
button:focus-visible,
.chat-composer input[type="text"]:focus-visible,
.chat-subject-row input:focus-visible,
.chat-subject-row select:focus-visible {
  outline: 2px solid #1f9fdb;
  outline-offset: 1px;
}

.chat-detail-title {
  margin: 0;
  font-weight: 800;
}

.chat-detail-label {
  margin: 10px 0 4px;
  font-weight: 700;
  color: #2f4858;
}

.chat-detail-content {
  margin: 0;
}

.chat-detail-institutions {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
}

.chat-composer {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 10px;
  background: linear-gradient(180deg, #eaf3f8 0%, #e3edf3 100%);
  border-top: 1px solid #bfd0db;
  padding-top: 8px;
}

.chat-bubble--subject-editor {
  width: min(100%, 640px);
  display: grid;
  gap: 10px;
}

.chat-subject-title {
  margin: 0;
  font-weight: 800;
}

.chat-subject-intro {
  margin: 0;
  color: var(--muted);
}

.chat-subject-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.chat-subject-actions button {
  min-height: 40px;
}

.chat-composer-shell {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #ffffff;
  padding: 4px 6px;
}

.chat-composer input[type="text"] {
  width: 100%;
  border: 0;
  border-radius: 0;
  padding: 8px 6px;
  font: inherit;
  background: transparent;
}

.chat-composer input[type="text"]:focus {
  outline: none;
}

.chat-icon-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #54656f;
  background: transparent;
  cursor: pointer;
}

.chat-icon-button svg,
.chat-send-button svg {
  width: 20px;
  height: 20px;
}

.chat-icon-button:hover {
  background: rgba(0, 0, 0, 0.05);
}

.chat-send-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  cursor: pointer;
}

.chat-send-button:hover {
  filter: brightness(1.05);
}

button {
  border: 0;
  border-radius: 9px;
  padding: 9px 12px;
  font: inherit;
  font-weight: 700;
  color: #ffffff;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  cursor: pointer;
}

button:hover {
  filter: brightness(1.03);
}

.chat-header .chat-header-clear {
  border: 1px solid #c7d3dc;
  border-radius: 999px;
  background: #ffffff;
  color: #355063;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 6px 10px;
}

.chat-header .chat-header-clear:hover {
  background: #f4f8fb;
  filter: none;
}

button:disabled,
.chat-icon-button:disabled,
.chat-send-button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.chat-typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 18px;
}

.chat-typing-bubble span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7d8f9c;
  animation: chatTypingPulse 1.1s infinite ease-in-out;
}

.chat-typing-bubble span:nth-child(2) { animation-delay: 0.12s; }
.chat-typing-bubble span:nth-child(3) { animation-delay: 0.24s; }

@keyframes chatTypingPulse {
  0%, 80%, 100% { transform: scale(0.75); opacity: 0.45; }
  40% { transform: scale(1); opacity: 1; }
}


.chat-subject-rows {
  display: grid;
  gap: 8px;
}

.chat-subject-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.chat-subject-row input,
.chat-subject-row select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
}

.chat-subject-row input:disabled,
.chat-subject-row select:disabled {
  background: #f4f7f9;
  color: #4d5f6b;
}

.chat-subject-remove {
  background: linear-gradient(135deg, #ca3d3d, #a92222);
}

.chat-image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1400;
  background: rgba(0, 0, 0, 0.78);
  display: grid;
  place-items: center;
  padding: 18px;
}

.chat-image-lightbox[hidden] {
  display: none !important;
}

.chat-image-lightbox__close {
  position: absolute;
  top: 12px;
  right: 12px;
  min-width: 40px;
  min-height: 40px;
  border-radius: 999px;
  padding: 0;
  background: rgba(17, 27, 33, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.28);
}

.chat-image-lightbox__image {
  max-width: min(100%, 980px);
  max-height: min(84vh, 860px);
  width: auto;
  height: auto;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

@media (min-width: 900px) {
  .chat-app {
    height: 100vh;
    height: 100dvh;
    padding: 24px;
    display: grid;
    place-items: center;
  }

  .chat-shell {
    width: min(1100px, 100%);
    height: calc(100dvh - 48px);
    max-height: calc(100dvh - 48px);
    margin: 0 auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-shell);
    box-shadow: var(--shadow-shell);
  }

  .chat-thread {
    padding: 14px 16px;
  }

  .chat-bubble,
  .chat-extra {
    max-width: min(70%, 680px);
  }

  .chat-composer {
    grid-template-columns: 1fr;
    align-items: center;
  }

  .chat-composer-shell {
    max-width: 780px;
    margin: 0 auto;
    width: 100%;
  }

  .chat-subject-row {
    grid-template-columns: minmax(0, 1fr) 130px auto;
  }

  .chat-subject-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
