.portfolio-chat {
  --chat-ink: #111;
  --chat-muted: #666;
  --chat-line: #e7e7e7;
  font-family: 'Montserrat', sans-serif;
}

.chat-launcher,
.chat-panel button,
.chat-panel textarea {
  font: inherit;
}

/* Robot assistant launcher: a friendly robot with a speech bubble. White with
   dark outlines so it stands out on both the black hero and the white sections. */
.chat-launcher {
  position: fixed;
  right: 20px;
  bottom: 14px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: #111;
  cursor: pointer;
}

.chat-launcher-label {
  position: relative;
  padding: 7px 14px;
  border: 1.5px solid #111;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 6px 18px rgb(0 0 0 / 22%);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  transition: background-color 0.2s;
}

/* Speech-bubble tail pointing down at the robot. */
.chat-launcher-label::after {
  content: "";
  position: absolute;
  right: 30px;
  bottom: -6px;
  width: 10px;
  height: 10px;
  border-right: 1.5px solid #111;
  border-bottom: 1.5px solid #111;
  background: inherit;
  transform: rotate(45deg);
}

.chat-launcher:hover .chat-launcher-label {
  background: #f1f1f1;
}

/* White circle holding the black chatbot icon, so it shows on dark and light sections. */
.chat-bot-badge {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-right: 4px;
  border: 1.5px solid #111;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px rgb(255 255 255 / 25%), 0 8px 24px rgb(0 0 0 / 30%);
  animation: chat-bot-float 3.2s ease-in-out infinite;
  transition: background-color 0.2s;
}

.chat-bot-badge img {
  display: block;
  width: 40px;
  height: 40px;
}

.chat-launcher:hover .chat-bot-badge {
  background: #f1f1f1;
}

@keyframes chat-bot-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.chat-launcher:focus-visible {
  outline: 2px solid #111;
  outline-offset: 4px;
  border-radius: 14px;
  box-shadow: 0 0 0 7px #fff;
}

.chat-panel {
  position: fixed;
  right: 24px;
  bottom: 88px;
  z-index: 1001;
  display: flex;
  width: min(420px, calc(100vw - 32px));
  height: min(620px, calc(100dvh - 120px));
  min-height: min(380px, calc(100dvh - 120px));
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #dedede;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 18px 60px rgb(0 0 0 / 20%);
  color: var(--chat-ink);
}

.chat-panel[hidden],
.chat-launcher[hidden] {
  display: none;
}

.chat-panel button {
  color: inherit;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 17px 18px;
  border-bottom: 1px solid rgb(255 255 255 / 13%);
  background: #080808;
  color: #fff;
}

.chat-avatar {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border: 1px solid rgb(255 255 255 / 35%);
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.chat-heading {
  min-width: 0;
  flex: 1;
}

.chat-title {
  margin: 0;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
}

.chat-subtitle {
  margin: 2px 0 0;
  color: rgb(255 255 255 / 68%);
  font-size: 10px;
  line-height: 1.4;
}

.chat-header-actions {
  display: flex;
  gap: 4px;
}

.chat-icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.chat-icon-button:hover {
  border-color: rgb(255 255 255 / 30%);
}

.chat-icon-button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.chat-content {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  overflow-y: auto;
  padding: 18px 16px 10px;
  overscroll-behavior: contain;
}

.chat-welcome {
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--chat-line);
  border-radius: 8px;
  background: #fafafa;
  color: #333;
  font-size: 13px;
  line-height: 1.7;
}

.chat-welcome strong {
  color: #111;
  font-weight: 700;
}

.chat-suggestions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 16px;
}

.chat-suggestions[hidden] {
  display: none;
}

.chat-suggestion {
  max-width: 100%;
  padding: 9px 12px;
  border: 1px solid #d8d8d8;
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  font-size: 12px !important;
  line-height: 1.5;
  text-align: left;
  transition: border-color 0.15s, background-color 0.15s;
}

.chat-suggestion:hover {
  border-color: #111;
  background: #f7f7f7;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
}

.chat-message {
  max-width: 88%;
  padding: 10px 12px;
  border: 1px solid var(--chat-line);
  border-radius: 10px 10px 10px 3px;
  color: #222;
  font-size: 13px;
  line-height: 1.7;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.chat-message-user {
  align-self: flex-end;
  border-color: #111;
  border-radius: 10px 10px 3px 10px;
  background: #111;
  color: #fff;
}

.chat-message-assistant {
  align-self: flex-start;
  background: #f7f7f7;
}

.chat-source-list {
  display: grid;
  gap: 5px;
  align-self: flex-start;
  max-width: 92%;
  margin: -5px 0 2px 4px;
}

.chat-source-label {
  color: #666;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chat-source {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 8px;
  align-items: baseline;
  color: #555;
  font-size: 11px;
  line-height: 1.55;
}

.chat-source a {
  color: #222;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-typing {
  color: var(--chat-muted);
  font-size: 11px;
  font-style: italic;
}

.chat-status {
  min-height: 16px;
  margin: 0 0 8px;
  color: #9c2525;
  font-size: 11px;
  line-height: 1.5;
}

.chat-status:empty {
  display: none;
}

.chat-form {
  padding: 0 14px 12px;
}

.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 9px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-input-wrap:focus-within {
  border-color: #111;
  box-shadow: 0 0 0 2px rgb(0 0 0 / 8%);
}

.chat-input {
  width: 100%;
  min-height: 38px;
  max-height: 104px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: #111;
  font-size: 14px !important;
  line-height: 1.5;
}

.chat-input::placeholder {
  color: #777;
}

.chat-send {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: #000;
  color: #fff !important;
  cursor: pointer;
}

.chat-send:disabled {
  background: #aaa;
  cursor: not-allowed;
}

.chat-send svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.chat-disclosure {
  margin: 8px 2px 0;
  color: #777;
  font-size: 10px;
  line-height: 1.5;
}

.chat-disclosure a {
  color: #222;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Keep the fixed chatbot icon from covering the footer links
   (Google Scholar, LinkedIn) at the bottom of every page. */
@media (min-width: 769px) {
  body > footer {
    padding-right: 160px;
  }
}

@media (min-width: 481px) and (max-width: 768px) {
  body > footer {
    padding-bottom: 110px;
  }
}

@media (max-width: 480px) {
  /* On phones the icon is smaller and the speech bubble is hidden so it
     doesn't cover page buttons. */
  .chat-launcher {
    right: 14px;
    bottom: 14px;
  }

  .chat-bot-badge {
    width: 54px;
    height: 54px;
    margin-right: 0;
  }

  .chat-bot-badge img {
    width: 34px;
    height: 34px;
  }

  /* Hidden visually but still read by screen readers as the button's name. */
  .chat-launcher-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .chat-panel {
    right: 12px;
    bottom: 74px;
    width: calc(100vw - 24px);
    height: min(620px, calc(100dvh - 92px));
    min-height: min(340px, calc(100dvh - 92px));
  }

  .chat-input {
    font-size: 16px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-launcher-label,
  .chat-bot-badge {
    transition: none;
    animation: none;
  }
}
