.chat-widget {
  --chat-navy: #102846;
  --chat-primary: #1a365d;
  --chat-secondary: #2a4a7f;
  --chat-accent: #4a6fa5;
  --chat-accent-soft: #dbe7f7;
  --chat-surface: rgba(255, 255, 255, 0.98);
  --chat-surface-soft: rgba(244, 248, 252, 0.96);
  --chat-surface-muted: rgba(237, 244, 252, 0.92);
  --chat-border: rgba(26, 54, 93, 0.14);
  --chat-border-strong: rgba(26, 54, 93, 0.22);
  --chat-text: #17324d;
  --chat-text-soft: rgba(23, 50, 77, 0.68);
  --chat-text-inverse: #f6faff;
  --chat-shadow: 0 24px 60px rgba(16, 40, 70, 0.18);
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 1200;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 14px;
  pointer-events: none;
}

.chat-widget * {
  box-sizing: border-box;
}

.chat-widget__panel,
.chat-widget__bubble {
  pointer-events: auto;
}

.chat-widget__panel {
  width: min(420px, calc(100vw - 28px));
  height: min(680px, calc(100vh - 120px));
  display: flex;
  flex-direction: column;
  border-radius: 28px;
  overflow: hidden;
  background:
    radial-gradient(circle at top right, rgba(74, 111, 165, 0.18), transparent 34%),
    linear-gradient(180deg, var(--chat-surface), var(--chat-surface-soft));
  box-shadow: var(--chat-shadow);
  border: 1px solid var(--chat-border);
  backdrop-filter: blur(14px);
  transform-origin: bottom right;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.chat-widget:not(.chat-widget--open) .chat-widget__panel {
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  visibility: hidden;
}

.chat-widget__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 14px;
  background:
    radial-gradient(circle at top right, rgba(111, 143, 189, 0.24), transparent 38%),
    linear-gradient(135deg, var(--chat-navy), var(--chat-primary));
  color: var(--chat-text-inverse);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-widget__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.chat-widget__brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #6d8fbe, var(--chat-accent));
  color: var(--chat-text-inverse);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 10px 22px rgba(10, 26, 43, 0.22);
}

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

.chat-widget__brand-copy h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.chat-widget__brand-copy p {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: rgba(246, 250, 255, 0.76);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-widget__header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-widget__icon-button {
  appearance: none;
  border: 0;
  width: 38px;
  height: 38px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.1);
  color: var(--chat-text-inverse);
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease;
}

.chat-widget__icon-button:hover,
.chat-widget__icon-button:focus-visible {
  background: rgba(255, 255, 255, 0.18);
  transform: translateY(-1px);
  outline: none;
}

.chat-widget__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-widget__session-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--chat-border);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(10px);
}

.chat-widget__session-strip::-webkit-scrollbar {
  height: 6px;
}

.chat-widget__session-strip::-webkit-scrollbar-thumb {
  background: rgba(26, 54, 93, 0.18);
  border-radius: 999px;
}

.chat-widget__session-chip,
.chat-widget__session-new {
  appearance: none;
  border: 1px solid var(--chat-border);
  background: rgba(255, 255, 255, 0.96);
  color: var(--chat-text);
  border-radius: 18px;
  padding: 10px 12px;
  min-width: 0;
  cursor: pointer;
  transition:
    border-color 0.18s ease,
    background 0.18s ease,
    transform 0.18s ease,
    box-shadow 0.18s ease;
}

.chat-widget__session-chip {
  min-width: 168px;
  max-width: 210px;
  text-align: left;
}

.chat-widget__session-chip:hover,
.chat-widget__session-chip:focus-visible,
.chat-widget__session-new:hover,
.chat-widget__session-new:focus-visible {
  border-color: rgba(74, 111, 165, 0.56);
  background: var(--chat-surface-soft);
  box-shadow: 0 10px 18px rgba(26, 54, 93, 0.08);
  transform: translateY(-1px);
  outline: none;
}

.chat-widget__session-chip--active {
  border-color: rgba(74, 111, 165, 0.7);
  background: linear-gradient(135deg, rgba(219, 231, 247, 0.92), rgba(240, 246, 253, 0.98));
}

.chat-widget__session-chip-title {
  display: block;
  font-size: 0.83rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-widget__session-chip-meta {
  display: block;
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--chat-text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-widget__messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(243, 248, 252, 0.95)),
    linear-gradient(45deg, rgba(26, 54, 93, 0.025) 25%, transparent 25%, transparent 50%, rgba(26, 54, 93, 0.025) 50%, rgba(26, 54, 93, 0.025) 75%, transparent 75%, transparent);
  background-size: auto, 18px 18px;
}

.chat-widget__messages::-webkit-scrollbar {
  width: 8px;
}

.chat-widget__messages::-webkit-scrollbar-thumb {
  background: rgba(26, 54, 93, 0.18);
  border-radius: 999px;
}

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

.chat-widget__message--assistant {
  align-self: flex-start;
}

.chat-widget__message--user {
  align-self: flex-end;
}

.chat-widget__message-bubble {
  padding: 14px 15px;
  border-radius: 22px;
  font-size: 0.92rem;
  line-height: 1.55;
  box-shadow: 0 10px 22px rgba(16, 40, 70, 0.08);
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-widget__message--assistant .chat-widget__message-bubble {
  background: rgba(255, 255, 255, 0.98);
  color: var(--chat-text);
  border: 1px solid rgba(26, 54, 93, 0.08);
  border-top-left-radius: 10px;
}

.chat-widget__message--user .chat-widget__message-bubble {
  background: linear-gradient(135deg, var(--chat-secondary), var(--chat-primary));
  color: var(--chat-text-inverse);
  border-top-right-radius: 10px;
}

.chat-widget__message-meta {
  font-size: 0.72rem;
  color: var(--chat-text-soft);
  padding: 0 8px;
}

.chat-widget__message-references {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 8px;
}

.chat-widget__reference {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(26, 54, 93, 0.12);
  color: var(--chat-secondary);
  text-decoration: none;
  font-size: 0.74rem;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.chat-widget__reference:hover,
.chat-widget__reference:focus-visible {
  background: var(--chat-accent-soft);
  border-color: rgba(74, 111, 165, 0.3);
  transform: translateY(-1px);
  outline: none;
}

.chat-widget__empty,
.chat-widget__status {
  margin: auto 0;
  padding: 18px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--chat-border);
  color: var(--chat-text);
  font-size: 0.9rem;
  line-height: 1.6;
}

.chat-widget__status--error {
  color: #8f3545;
  background: rgba(255, 243, 245, 0.96);
  border-color: rgba(143, 53, 69, 0.18);
}

.chat-widget__composer {
  border-top: 1px solid var(--chat-border);
  padding: 16px 18px 18px;
  background: rgba(255, 255, 255, 0.9);
}

.chat-widget__composer-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-widget__textarea {
  flex: 1;
  min-height: 54px;
  max-height: 152px;
  resize: none;
  border-radius: 18px;
  border: 1px solid var(--chat-border);
  background: rgba(255, 255, 255, 0.98);
  padding: 14px 16px;
  font: inherit;
  color: var(--chat-text);
  line-height: 1.45;
  box-shadow: inset 0 1px 2px rgba(16, 40, 70, 0.04);
}

.chat-widget__textarea::placeholder {
  color: rgba(23, 50, 77, 0.45);
}

.chat-widget__textarea:focus-visible {
  outline: 2px solid rgba(74, 111, 165, 0.26);
  border-color: rgba(74, 111, 165, 0.56);
}

.chat-widget__send {
  appearance: none;
  border: 0;
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--chat-secondary), var(--chat-primary));
  color: var(--chat-text-inverse);
  cursor: pointer;
  box-shadow: 0 12px 20px rgba(26, 54, 93, 0.24);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.chat-widget__send:hover,
.chat-widget__send:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 16px 26px rgba(26, 54, 93, 0.26);
  outline: none;
}

.chat-widget__send[disabled] {
  opacity: 0.62;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.chat-widget__composer-note {
  margin-top: 10px;
  font-size: 0.72rem;
  color: var(--chat-text-soft);
}

.chat-widget__bubble {
  appearance: none;
  border: 0;
  width: 68px;
  height: 68px;
  border-radius: 24px;
  background:
    radial-gradient(circle at top right, rgba(111, 143, 189, 0.3), transparent 45%),
    linear-gradient(135deg, var(--chat-secondary), var(--chat-primary));
  color: var(--chat-text-inverse);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 16px 32px rgba(16, 40, 70, 0.34);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.chat-widget__bubble i {
  font-size: 1.16rem;
}

.chat-widget__bubble:hover,
.chat-widget__bubble:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 22px 40px rgba(16, 40, 70, 0.38);
  outline: none;
}

.chat-widget__bubble-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 999px;
  background: #0f2239;
  color: var(--chat-text-inverse);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.chat-widget__bubble-wrap {
  position: relative;
}

.chat-widget__bubble-badge.is-visible {
  display: inline-flex;
}

.chat-widget__typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.chat-widget__typing span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: rgba(42, 74, 127, 0.42);
  animation: chat-widget-typing 1.1s infinite ease-in-out;
}

.chat-widget__typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-widget__typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes chat-widget-typing {
  0%,
  80%,
  100% {
    opacity: 0.36;
    transform: translateY(0);
  }

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

@media (max-width: 768px) {
  .chat-widget {
    right: 14px;
    bottom: 14px;
    left: 14px;
    align-items: stretch;
  }

  .chat-widget__panel {
    width: 100%;
    height: min(74vh, 680px);
    border-radius: 24px;
  }

  .chat-widget__message {
    max-width: 94%;
  }
}
