/**
 * Chat Widget – Vilnius University (vu.lt)
 * Clean minimal style matching reference UI
 */

/* ─── Toggle Button (chevron-down style) ─── */
.chat-widget-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #7a1428;
  border: none;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999999;
  color: #fff;
}

/* Replace chat icon with a chevron-down arrow */
.chat-widget-toggle-icon { display: none; }

.chat-widget-toggle::after {
  content: '';
  display: block;
  width: 12px;
  height: 12px;
  border-right: 2.5px solid #fff;
  border-bottom: 2.5px solid #fff;
  transform: rotate(45deg) translate(-2px, -2px);
}

.chat-widget-toggle:hover { background: #5f0f1f; }
.chat-widget-toggle:active { opacity: 0.85; }
.chat-widget-toggle.chat-widget-hidden { opacity: 0; pointer-events: none; }

/* ─── Floating Close Button ─── */
.chat-widget-close-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #7a1428;
  border: none;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999999;
  color: #fff;
  opacity: 0;
  pointer-events: none;
}

/* Chevron-up when open */
.chat-widget-close-btn::after {
  content: '';
  display: block;
  width: 12px;
  height: 12px;
  border-right: 2.5px solid #fff;
  border-bottom: 2.5px solid #fff;
  transform: rotate(225deg) translate(-2px, -2px);
}

.chat-widget-close-btn svg { display: none; }

.chat-widget-close-btn.chat-widget-close-visible { opacity: 1; pointer-events: all; }
.chat-widget-close-btn:hover { background: #5f0f1f; }

/* ─── Container ─── */
.chat-widget-container {
  position: fixed;
  bottom: 86px;
  right: 24px;
  width: 340px;
  height: 580px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.14);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  z-index: 999998;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  transition: opacity 0.15s ease;
}

.chat-widget-container.chat-widget-open { opacity: 1; pointer-events: all; }

/* ─── Header – white, minimal ─── */
.chat-widget-header {
  background: #fff;
  color: #111;
  padding: 14px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  flex-shrink: 0;
  border-bottom: 1px solid #f0f0f0;
}

.chat-widget-header-content {
  display: flex;
  align-items: center;
  gap: 0;
  flex: 1;
}

/* Hide the icon circle in header */
.chat-widget-header-icon { display: none; }

.chat-widget-header-title { display: flex; flex-direction: column; }

.chat-widget-title {
  font-size: 15px;
  font-weight: 700;
  color: #111;
  line-height: 1.2;
}

.chat-widget-subtitle {
  font-size: 11px;
  color: #888;
  line-height: 1.3;
  margin-top: 1px;
}

/* Header close button visible on mobile only */
.chat-widget-header-close {
  display: none;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: #555;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-widget-header-close:hover { background: #f5f5f5; }

/* ─── Wrapper ─── */
.chat-widget-wrapper {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: #fff;
}

/* ─── Messages ─── */
.chat-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.chat-widget-messages::-webkit-scrollbar { width: 4px; }
.chat-widget-messages::-webkit-scrollbar-track { background: transparent; }
.chat-widget-messages::-webkit-scrollbar-thumb { background: #e8e8e8; border-radius: 2px; }

/* ─── Hide role labels ─── */
.chat-widget-role { display: none; }

/* ─── Bubbles ─── */
.chat-widget-message {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 80%;
}

.chat-widget-user      { align-self: flex-end; }
.chat-widget-assistant { align-self: flex-start; }

.chat-widget-content {
  background: #f0f0f0;
  border: none;
  border-radius: 18px;
  padding: 10px 15px;
  color: #111;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-widget-content p { margin: 0 0 6px 0; }
.chat-widget-content p:last-child { margin-bottom: 0; }
.chat-widget-content ol,
.chat-widget-content ul { margin: 5px 0; padding-left: 18px; }
.chat-widget-content li { margin-bottom: 3px; }
.chat-widget-content strong { font-weight: 600; }
.chat-widget-content em { font-style: italic; }
.chat-widget-content code {
  background: rgba(0,0,0,0.07);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 12.5px;
  font-family: "SFMono-Regular", Consolas, monospace;
}

.chat-widget-user .chat-widget-content {
  background: #f0f0f0;
  color: #111;
}

/* ─── Powered by footer ─── */
.chat-widget-messages::after {
  content: '';
  display: block;
  text-align: center;
  font-size: 11px;
  color: #bbb;
  padding: 10px 0 4px;
  flex-shrink: 0;
}

/* ─── Thinking dots ─── */
.chat-widget-thinking {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 10px 15px;
}

.chat-widget-dot-pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #C4768A;
  animation: vu-pulse 1.4s ease-in-out infinite;
}

.chat-widget-dot-pulse:nth-child(2) { animation-delay: 0.2s; }
.chat-widget-dot-pulse:nth-child(3) { animation-delay: 0.4s; }

@keyframes vu-pulse {
  0%, 80%, 100% { opacity: 0.2; transform: scale(1); }
  40%           { opacity: 1;   transform: scale(1.2); }
}

/* ─── Citations ─── */
.chat-widget-citation {
  color: #7a1428;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.82em;
}
.chat-widget-citation:hover { text-decoration: underline; }

/* ─── Sources ─── */
.chat-widget-sources {
  margin-top: 8px;
  border-top: 1px solid #eee;
  padding-top: 8px;
}

.chat-widget-sources summary {
  cursor: pointer;
  list-style: none;
  color: #7a1428;
  font-weight: 600;
  font-size: 11.5px;
  display: flex;
  align-items: center;
  gap: 5px;
  user-select: none;
}

.chat-widget-sources summary::-webkit-details-marker { display: none; }
.chat-widget-chevron { font-size: 8px; transition: transform 0.15s; }
.chat-widget-sources[open] .chat-widget-chevron { transform: rotate(90deg); }

.chat-widget-source-list { margin: 8px 0 0; padding-left: 16px; display: flex; flex-direction: column; gap: 3px; }
.chat-widget-source-item { font-size: 12px; }
.chat-widget-source-link { color: #7a1428; text-decoration: none; font-size: 12px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-widget-source-link:hover { text-decoration: underline; }

/* ─── Input Area ─── */
.chat-widget-input-area {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 12px 14px;
  background: #fff;
  border-top: 1px solid #f0f0f0;
  flex-shrink: 0;
}

.chat-widget-input {
  flex: 1;
  padding: 9px 14px;
  border: 1px solid #e4e4e4;
  border-radius: 24px;
  font-size: 13.5px;
  font-family: inherit;
  color: #111;
  background: #fafafa;
  outline: none;
}

.chat-widget-input::placeholder { color: #aaa; }
.chat-widget-input:focus { border-color: #bbb; background: #fff; }
.chat-widget-input:disabled { background: #f5f5f5; cursor: not-allowed; }

.chat-widget-send {
  width: 34px;
  height: 34px;
  padding: 0;
  margin-left: 8px;
  background: #7a1428;
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-widget-send:hover:not(:disabled) { background: #5f0f1f; }
.chat-widget-send:disabled { background: #ddd; cursor: not-allowed; }

/* ─── Feedback ─── */
.chat-widget-feedback { display: flex; gap: 4px; margin-top: 5px; padding-left: 4px; }

.chat-widget-feedback-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  border: 1px solid #e0e0e0;
  border-radius: 5px;
  cursor: pointer;
  color: #ccc;
}
.chat-widget-feedback-btn:hover:not(:disabled) { border-color: #7a1428; color: #7a1428; background: #fdf5f6; }
.chat-widget-feedback-btn.chat-widget-feedback-selected { border-color: #7a1428; color: #7a1428; background: #fdf5f6; }
.chat-widget-feedback-btn.chat-widget-feedback-dimmed { opacity: 0.3; }

/* ─── Error ─── */
.chat-widget-error { display: none; padding: 8px 14px; background: #fdf0f1; border-top: 1px solid #f0d0d3; color: #7a1428; font-size: 12px; }
.chat-widget-error.chat-widget-error-visible { display: block; }

/* ─── Short screens ─── */
@media (max-height: 720px) and (min-width: 481px) { .chat-widget-container { height: 460px; } }
@media (max-height: 580px) and (min-width: 481px) { .chat-widget-container { height: 350px; bottom: 82px; } }

/* ─── Tablet ─── */
@media (max-width: 768px) and (min-width: 481px) { .chat-widget-container { width: 320px; height: 520px; right: 18px; } }

/* ─── Mobile ─── */
@media (max-width: 480px) {
  .chat-widget-toggle { bottom: 16px; right: 16px; width: 50px; height: 50px; }
  .chat-widget-close-btn { display: none !important; }
  .chat-widget-header-close { display: flex; }
  .chat-widget-container { position: fixed; inset: 0; width: 100%; height: 100%; border-radius: 0; }
  .chat-widget-message { max-width: 88%; }
}

/* ─── Dark mode ─── */
@media (prefers-color-scheme: dark) {
  .chat-widget-container  { background: #1a1a1a; box-shadow: 0 8px 32px rgba(0,0,0,0.4); }
  .chat-widget-header     { background: #1a1a1a; border-bottom-color: #2a2a2a; }
  .chat-widget-title      { color: #eee; }
  .chat-widget-subtitle   { color: #777; }
  .chat-widget-header-close { color: #999; }
  .chat-widget-wrapper    { background: #1a1a1a; }
  .chat-widget-content    { background: #2a2a2a; color: #eee; }
  .chat-widget-user .chat-widget-content { background: #2a2a2a; }
  .chat-widget-sources    { border-top-color: #333; }
  .chat-widget-source-link,
  .chat-widget-citation   { color: #e8909a; }
  .chat-widget-input-area { background: #1a1a1a; border-top-color: #2a2a2a; }
  .chat-widget-input      { background: #242424; border-color: #333; color: #eee; }
  .chat-widget-input:focus { border-color: #555; }
  .chat-widget-input::placeholder { color: #666; }
  .chat-widget-messages::after { color: #444; }
  .chat-widget-feedback-btn { border-color: #333; color: #555; }
  .chat-widget-feedback-btn:hover:not(:disabled),
  .chat-widget-feedback-btn.chat-widget-feedback-selected { border-color: #e8909a; color: #e8909a; background: #2a1a1c; }
  .chat-widget-error      { background: #2a1515; border-color: #3a2020; color: #f09090; }
  .chat-widget-messages::-webkit-scrollbar-thumb { background: #333; }
}