/* Rastro Chat Widget */
#my-chat-widget {
  --rastro-chat-launcher-bottom-offset: 20px;
  --rastro-chat-launcher-mobile-bottom-offset: 18px;
  --rastro-chat-safe-area-bottom: env(safe-area-inset-bottom, 0px);
  position: fixed;
  bottom: var(--rastro-chat-launcher-bottom-offset);
  right: 20px;
  z-index: 2147483640;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #0f172a;
}

.rastro-chat {
  --rc-bg: #eef0f6;
  --rc-surface: #f8f9fd;
  --rc-text: #1a1f3a;
  --rc-muted: #5e6686;
  --rc-primary: #444c7a;
  --rc-primary-contrast: #f4f6ff;
  --rc-border: #c6cbda;
  --rc-shadow: 0 14px 34px rgba(26, 31, 58, 0.22);
  --rc-overlay: rgba(26, 31, 58, 0.55);
  --rc-input-bg: #eceff6;
  --rc-input-border: #b8bfd2;
  --rc-system: #ef4444;
  --rc-header-from: #1f2341;
  --rc-header-to: #434b79;
  --rc-header-text: #f4f6ff;
  --rc-header-subtext: #d7dcef;
  --rc-header-close: rgba(244, 246, 255, 0.86);
  --rc-header-close-hover: rgba(244, 246, 255, 0.16);
  --rc-header-avatar-border: rgba(244, 246, 255, 0.35);
  --rc-msg-gradient-start: #f3f5fb;
  --rc-link-hover-bg: rgba(68, 76, 122, 0.1);
  --rc-focus-ring: rgba(68, 76, 122, 0.25);
  --rc-typing-bg-from: rgba(68, 76, 122, 0.16);
  --rc-typing-bg-to: rgba(68, 76, 122, 0.04);
  --rc-disclaimer: #8a97ab;
  position: relative;
}

.rastro-chat[data-theme='dark'] {
  --rc-bg: #181d35;
  --rc-surface: #1f2643;
  --rc-text: #e5e8f4;
  --rc-muted: #aeb7d1;
  --rc-primary: #7782bd;
  --rc-primary-contrast: #13172b;
  --rc-border: #303958;
  --rc-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  --rc-overlay: rgba(0, 0, 0, 0.6);
  --rc-input-bg: #202845;
  --rc-input-border: #3b4465;
  --rc-system: #f87171;
  --rc-header-from: #14192d;
  --rc-header-to: #2a335b;
  --rc-header-text: #e8ecff;
  --rc-header-subtext: #c9d2ef;
  --rc-header-close: #dbe5ff;
  --rc-header-close-hover: rgba(219, 229, 255, 0.18);
  --rc-header-avatar-border: rgba(219, 229, 255, 0.3);
  --rc-msg-gradient-start: #222b4d;
  --rc-link-hover-bg: rgba(119, 130, 189, 0.16);
  --rc-focus-ring: rgba(119, 130, 189, 0.35);
  --rc-typing-bg-from: rgba(119, 130, 189, 0.28);
  --rc-typing-bg-to: rgba(119, 130, 189, 0.1);
  --rc-disclaimer: #8393ab;
}

.rastro-chat[data-theme='lahta-pro'] {
  --rc-bg: #eeeeee;
  --rc-surface: #fafafa;
  --rc-text: #111111;
  --rc-muted: #5f5f5f;
  --rc-primary: #117c0f;
  --rc-primary-contrast: #ffffff;
  --rc-border: #cfcfcf;
  --rc-shadow: 0 14px 34px rgba(0, 0, 0, 0.2);
  --rc-overlay: rgba(0, 0, 0, 0.58);
  --rc-input-bg: #f3f3f3;
  --rc-input-border: #bcbcbc;
  --rc-system: #dc2626;
  --rc-header-from: #118d10;
  --rc-header-to: #106f10;
  --rc-header-text: #f9f9f9;
  --rc-header-subtext: #d7d7d7;
  --rc-header-close: #f2f2f2;
  --rc-header-close-hover: rgba(255, 255, 255, 0.2);
  --rc-header-avatar-border: rgba(255, 255, 255, 0.4);
  --rc-msg-gradient-start: #f5f5f5;
  --rc-link-hover-bg: rgba(17, 124, 15, 0.12);
  --rc-focus-ring: rgba(17, 124, 15, 0.32);
  --rc-typing-bg-from: rgba(17, 124, 15, 0.2);
  --rc-typing-bg-to: rgba(17, 124, 15, 0.06);
  --rc-disclaimer: #707070;
}

.rastro-chat[data-theme='lahta-pro'] .rastro-chat__header {
  background: linear-gradient(105deg, #118d10 0%, #117f10 52%, #106f10 100%);
}

.rastro-chat[data-theme='smolapena'] {
  --rc-bg: #2f2e2e;
  --rc-surface: #343339;
  --rc-text: #f1f2f5;
  --rc-muted: #b6bbc4;
  --rc-primary: #f1b52a;
  --rc-primary-contrast: #1f2126;
  --rc-border: #4c4f57;
  --rc-shadow: 0 14px 34px rgba(0, 0, 0, 0.35);
  --rc-overlay: rgba(0, 0, 0, 0.62);
  --rc-input-bg: #2a292f;
  --rc-input-border: #636772;
  --rc-system: #dc2626;
  --rc-header-from: #3a393e;
  --rc-header-to: #2d2d32;
  --rc-header-text: #f4f5f7;
  --rc-header-subtext: #d4d7dd;
  --rc-header-close: #f0f2f5;
  --rc-header-close-hover: rgba(240, 242, 245, 0.14);
  --rc-header-avatar-border: rgba(240, 242, 245, 0.36);
  --rc-msg-gradient-start: #3a3940;
  --rc-link-hover-bg: rgba(241, 181, 42, 0.16);
  --rc-focus-ring: rgba(241, 181, 42, 0.35);
  --rc-typing-bg-from: rgba(241, 181, 42, 0.24);
  --rc-typing-bg-to: rgba(241, 181, 42, 0.08);
  --rc-disclaimer: #a7adb7;
}

#my-chat-widget .rastro-chat__launcher {
  width: 56px;
  height: 56px;
  min-width: 56px;
  min-height: 56px;
  max-width: 56px;
  max-height: 56px;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  aspect-ratio: 1 / 1;
  line-height: 1;
  flex: 0 0 56px;
  border-radius: 50%;
  border: none;
  appearance: none;
  -webkit-appearance: none;
  background: var(--rc-primary);
  color: var(--rc-primary-contrast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  text-transform: none;
  cursor: pointer;
  box-shadow: var(--rc-shadow);
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.rastro-chat__launcher-icon {
  width: 24px;
  height: 24px;
  display: block;
  flex: 0 0 auto;
}

.rastro-chat__launcher:focus-visible {
  outline: 2px solid var(--rc-primary);
  outline-offset: 3px;
}

.rastro-chat__launcher:active {
  transform: scale(0.96);
}

.rastro-chat__launcher[aria-expanded='true'] {
  box-shadow: 0 0 0 3px var(--rc-focus-ring), var(--rc-shadow);
}

.rastro-chat__window {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 340px;
  height: 520px;
  max-height: calc(100vh - 100px);
  background: var(--rc-surface);
  color: var(--rc-text);
  border-radius: 16px;
  border: 1px solid var(--rc-border);
  box-shadow: var(--rc-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.rastro-chat__window[data-open='true'] {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.rastro-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--rc-border);
  background: linear-gradient(135deg, var(--rc-header-from) 0%, var(--rc-header-to) 100%);
  color: var(--rc-header-text);
}

.rastro-chat__title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rastro-chat__title-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.rastro-chat__title-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rastro-chat__title-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--rc-header-avatar-border);
  background: #ffffff;
  object-fit: cover;
  flex: 0 0 auto;
}

.rastro-chat__title-main {
  font-weight: 700;
  font-size: 15px;
}

.rastro-chat__title-sub {
  font-size: 12px;
  color: var(--rc-header-subtext);
}

.rastro-chat__close {
  border: none;
  background: transparent;
  color: var(--rc-header-close);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: background 120ms ease;
}

.rastro-chat__close:hover {
  background: var(--rc-header-close-hover);
}

.rastro-chat__close:focus-visible {
  outline: 2px solid var(--rc-primary);
  outline-offset: 2px;
}

.rastro-chat__messages {
  flex: 1;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  background: linear-gradient(180deg, var(--rc-msg-gradient-start) 0%, var(--rc-bg) 100%);
  scroll-behavior: smooth;
}

.rastro-chat__empty {
  color: var(--rc-muted);
  text-align: center;
  font-size: 13px;
  width: 100%;
  padding: 16px;
  margin: 0 auto;
  white-space: pre-line;
  word-break: break-word;
  box-sizing: border-box;
}

.rastro-chat__msg {
  display: flex;
  gap: 8px;
}

.rastro-chat__msg--user {
  justify-content: flex-end;
}

.rastro-chat__bubble {
  max-width: 80%;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.35;
  background: var(--rc-input-bg);
  border: 1px solid var(--rc-border);
  color: var(--rc-text);
}

.rastro-chat__bubble-text {
  white-space: pre-wrap;
  word-break: break-word;
}

/* Comparison table */
.rastro-chat__comparison-wrapper {
  margin-bottom: 8px;
}
.rastro-chat__comparison-heading {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
}
.rastro-chat__comparison-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.rastro-chat__comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.rastro-chat__comparison-table th,
.rastro-chat__comparison-table td {
  border: 1px solid var(--rc-border);
  padding: 4px 6px;
  text-align: left;
  vertical-align: top;
}
.rastro-chat__comparison-table th {
  background: var(--rc-primary);
  color: var(--rc-primary-contrast);
  font-weight: 600;
  white-space: nowrap;
}
.rastro-chat__comparison-param {
  font-weight: 500;
  white-space: nowrap;
}

.rastro-chat__links {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.rastro-chat__link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--rc-primary);
  color: var(--rc-primary);
  background: transparent;
  text-decoration: none;
  font-size: 13px;
  line-height: 1.2;
}

.rastro-chat__link:hover {
  background: var(--rc-link-hover-bg);
}

.rastro-chat__msg--user .rastro-chat__bubble {
  background: var(--rc-primary);
  color: var(--rc-primary-contrast);
  border-color: var(--rc-primary);
  border-bottom-right-radius: 4px;
}

.rastro-chat__msg--bot .rastro-chat__bubble {
  border-bottom-left-radius: 4px;
}

.rastro-chat__msg--system .rastro-chat__bubble {
  background: #fef2f2;
  border-color: #fecdd3;
  color: #b91c1c;
}

.rastro-chat[data-theme='dark'] .rastro-chat__msg--system .rastro-chat__bubble {
  background: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.3);
  color: #fecaca;
}

.rastro-chat[data-theme='smolapena'] .rastro-chat__msg--system .rastro-chat__bubble {
  background: rgba(241, 181, 42, 0.12);
  border-color: rgba(241, 181, 42, 0.38);
  color: #f7cd72;
}

.rastro-chat__typing {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  color: var(--rc-muted);
  font-size: 13px;
  background: linear-gradient(
    90deg,
    var(--rc-typing-bg-from),
    var(--rc-typing-bg-to)
  );
  border-top: 1px solid var(--rc-border);
}

.rastro-chat__typing[data-visible='true'] {
  display: flex;
}

.rastro-chat__dots {
  display: inline-flex;
  gap: 4px;
}

.rastro-chat__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--rc-muted);
  animation: rastro-chat-bounce 1s infinite ease-in-out;
}

.rastro-chat__dot:nth-child(2) {
  animation-delay: 0.15s;
}

.rastro-chat__dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes rastro-chat-bounce {

  0%,
  80%,
  100% {
    transform: scale(0);
    opacity: 0.4;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.rastro-chat__form {
  padding: 10px 12px;
  border-top: 1px solid var(--rc-border);
  background: var(--rc-bg);
  display: flex;
  gap: 8px;
}

.rastro-chat__input {
  flex: 1;
  border-radius: 12px;
  border: 1px solid var(--rc-input-border);
  padding: 10px 12px;
  background: var(--rc-input-bg);
  color: var(--rc-text);
  font-size: 14px;
}

.rastro-chat__input:focus-visible {
  outline: 2px solid var(--rc-primary);
  outline-offset: 0;
}

.rastro-chat__send {
  min-width: 44px;
  border-radius: 12px;
  border: none;
  background: var(--rc-primary);
  color: var(--rc-primary-contrast);
  cursor: pointer;
  padding: 0 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 120ms ease, opacity 120ms ease;
}

.rastro-chat__send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.rastro-chat__send:active {
  transform: translateY(1px);
}

.rastro-chat__disclaimer {
  padding: 4px 12px 12px;
  font-size: 11px;
  line-height: 1.1;
  color: var(--rc-disclaimer);
  background: transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rastro-chat__error {
  display: none;
  padding: 8px 12px;
  background: rgba(239, 68, 68, 0.1);
  color: #b91c1c;
  font-size: 13px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.rastro-chat[data-theme='dark'] .rastro-chat__error {
  background: rgba(248, 113, 113, 0.15);
  color: #fecaca;
}

.rastro-chat[data-theme='smolapena'] .rastro-chat__error {
  background: rgba(241, 181, 42, 0.14);
  color: #f7cd72;
}

.rastro-chat__error[data-visible='true'] {
  display: flex;
}

.rastro-chat__retry {
  border: none;
  background: transparent;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  font-weight: 600;
}

/* File attach button */
.rastro-chat__attach {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  min-width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--rc-input-border);
  background: var(--rc-input-bg);
  color: var(--rc-muted);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: color 120ms ease, border-color 120ms ease;
}

.rastro-chat__attach:hover {
  color: var(--rc-primary);
  border-color: var(--rc-primary);
}

.rastro-chat__attach:focus-visible {
  outline: 2px solid var(--rc-primary);
  outline-offset: 0;
}

/* File preview chip */
.rastro-chat__file-preview {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--rc-bg);
  border-top: 1px solid var(--rc-border);
  font-size: 12px;
  color: var(--rc-muted);
}

.rastro-chat__file-preview[data-visible='true'] {
  display: flex;
}

.rastro-chat__file-preview-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rastro-chat__file-preview-remove {
  border: none;
  background: transparent;
  color: var(--rc-muted);
  cursor: pointer;
  padding: 2px 4px;
  font-size: 12px;
  line-height: 1;
  border-radius: 4px;
}

.rastro-chat__file-preview-remove:hover {
  color: var(--rc-system);
}

/* File badge in user bubble */
.rastro-chat__file-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  opacity: 0.8;
  margin-bottom: 4px;
  word-break: break-all;
}

.rastro-chat__file-badge svg {
  flex-shrink: 0;
}

/* Fullscreen mode */
#my-chat-widget:has(.rastro-chat[data-mode='fullscreen']) {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  bottom: 0;
  right: 0;
}

.rastro-chat[data-mode='fullscreen'] {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

.rastro-chat[data-mode='fullscreen'] .rastro-chat__window {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-height: 100%;
  border-radius: 0;
  border: none;
  box-shadow: none;
  transform: none;
  opacity: 1;
  pointer-events: auto;
}

.rastro-chat[data-mode='fullscreen'] .rastro-chat__window[data-open='true'] {
  transform: none;
}

.rastro-chat[data-mode='fullscreen'] .rastro-chat__messages {
  padding: 16px 24px;
}

.rastro-chat[data-mode='fullscreen'] .rastro-chat__bubble {
  max-width: 680px;
}

.rastro-chat[data-mode='fullscreen'] .rastro-chat__form {
  padding: 12px 24px;
}

.rastro-chat[data-mode='fullscreen'] .rastro-chat__header {
  padding: 14px 24px;
}

@media (max-width: 480px) {
  #my-chat-widget {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
  }

  #my-chat-widget .rastro-chat__launcher {
    position: fixed;
    bottom: calc(
      var(--rastro-chat-launcher-mobile-bottom-offset) +
      var(--rastro-chat-safe-area-bottom)
    );
    right: 18px;
  }

  .rastro-chat__window {
    position: fixed;
    inset: 0;
    width: 100vw;
    max-height: var(--rastro-chat-mobile-vh, 100dvh);
    height: var(--rastro-chat-mobile-vh, 100dvh);
    border-radius: 0;
    border: none;
    transform: translateY(8px);
  }
}
