:root {
  color-scheme: dark;
  --widget-bg: #050505;
  --widget-panel: rgba(255, 255, 255, 0.03);
  --widget-border: rgba(255, 255, 255, 0.12);
  --widget-text: #f5f5f5;
  --widget-muted: rgba(245, 245, 245, 0.64);
  --widget-accent: #ffffff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: transparent;
  font-family: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
}

body {
  padding: 0;
  color: var(--widget-text);
  overflow: hidden;
}

.widget-launcher {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 5;
  width: 62px;
  height: 62px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  background:
    radial-gradient(circle at top right, rgba(155, 194, 255, 0.18), transparent 38%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.04)),
    rgba(8, 8, 8, 0.96);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.34);
  color: #fff;
  cursor: pointer;
}

.widget-launcher__icon {
  font-size: 24px;
  line-height: 1;
}

.widget-shell {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 6;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  width: min(420px, calc(100vw - 24px));
  height: min(700px, calc(100dvh - 24px));
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.06), transparent 42%),
    var(--widget-bg);
  border: 1px solid var(--widget-border);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.widget-shell[hidden] {
  display: none;
}

.widget-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--widget-border);
  background: rgba(255, 255, 255, 0.02);
}

.widget-head__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.widget-brand {
  font-size: 18px;
  font-weight: 700;
}

.widget-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--widget-muted);
}

.widget-badge {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--widget-border);
  color: var(--widget-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.widget-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--widget-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--widget-text);
  cursor: pointer;
}

.widget-log {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 10px;
  min-height: 0;
  padding: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.widget-intents {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-content: flex-start;
  width: 100%;
  padding: 8px 14px 10px;
}

.widget-intent {
  max-width: min(100%, 260px);
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
  color: #fff;
  font: inherit;
  line-height: 1.25;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, transform 140ms ease;
}


.widget-intent:hover,
.widget-intent:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.22);
  transform: translateY(-1px);
  outline: none;
}

@media (max-width: 768px) {
  .widget-log {
    overscroll-behavior-x: contain;
    overscroll-behavior-y: auto;
  }
}

.widget-bubble {
  max-width: 84%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--widget-border);
  line-height: 1.5;
  font-size: 13px;
}

.widget-bubble--bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.05);
}

.widget-bubble--user {
  align-self: flex-end;
  background: rgba(255, 255, 255, 0.15);
}

.widget-bubble__body {
  word-break: break-word;
}

.widget-bubble__body a {
  color: #9bc2ff;
}

.widget-bubble__time {
  display: block;
  margin-top: 6px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.48);
}

.widget-footer {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--widget-border);
  background: rgba(255, 255, 255, 0.02);
}

.widget-footer textarea {
  grid-column: 1;
  min-height: 42px;
  max-height: 240px;
  resize: none;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--widget-border);
  background: var(--widget-panel);
  color: var(--widget-text);
  line-height: 1.45;
  overflow-y: hidden;
  -webkit-appearance: none;
}

.widget-footer button {
  width: 36px;
  min-width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--widget-border);
  background: #fff;
  color: #000;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  align-self: center;
}

.widget-footer button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.widget-footer button:not(.chat-mic-btn) {
  grid-column: 2;
  font-size: 0;
  line-height: 1;
}
  
.widget-footer button:not(.chat-mic-btn)::before {
  content: "";
  display: block;
  width: 16px;
  height: 16px;
  margin: auto;
  flex: 0 0 16px;
  background: center / contain no-repeat url("../img/chat-send.svg");
}

.widget-footer .chat-mic-btn {
  grid-column: 3;
  background: transparent;
  color: rgba(245, 245, 245, 0.82);
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 140ms ease, color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
  user-select: none;
  -webkit-user-select: none;
}

.widget-footer .chat-mic-btn svg {
  display: block;
  width: 18px;
  height: 18px;
}

.widget-footer .chat-mic-btn.is-listening {
  background: #ffffff;
  color: #000000;
  border-color: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 26px rgba(255, 255, 255, 0.18), 0 0 0 5px rgba(255, 255, 255, 0.08);
  animation: widget-mic-pulse 1s ease-in-out infinite;
  transform: scale(1.06);
}

.widget-footer .chat-mic-btn.is-processing {
  background: rgba(255, 255, 255, 0.16);
  color: rgba(255, 255, 255, 0.98);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06);
}

.widget-footer .chat-mic-btn.is-speaking {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}

.widget-footer .chat-mic-btn.is-held {
  transform: scale(1.08);
  box-shadow: 0 14px 30px rgba(255, 255, 255, 0.22), 0 0 0 8px rgba(255, 255, 255, 0.1);
}

.widget-footer .chat-mic-btn.is-pressing {
  transform: scale(0.94);
  background: rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.98);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.06);
}

.widget-footer .chat-mic-btn.is-error {
  background: rgba(183, 76, 76, 0.18);
  color: #ffb0b0;
  box-shadow: 0 0 0 2px rgba(183, 76, 76, 0.12);
}

.widget-footer .chat-mic-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.widget-footer[data-voice-state="listening"] {
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  }

.chat-mic-hint {
  position: absolute;
  right: 14px;
  bottom: calc(100% + 10px);
  max-width: min(220px, calc(100vw - 48px));
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  color: #000;
  font-size: 12px;
  line-height: 1.1;
  letter-spacing: 0.01em;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.26);
  opacity: 0;
  transform: translateY(6px) scale(0.96);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  white-space: nowrap;
}

.chat-mic-hint.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

@supports (-webkit-touch-callout: none) {
  .widget-footer textarea {
    font-size: 16px;
  }

  .chat-mic-hint {
    max-width: min(180px, calc(100vw - 40px));
    font-size: 11px;
  }
}

@keyframes widget-mic-pulse {
  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.06);
  }
}

.widget-status {
  min-height: 20px;
  padding: 0 14px 14px;
  color: var(--widget-muted);
  font-size: 12px;
}

.widget-status.is-error {
  color: #ffb0b0;
}

.widget-status.is-ok {
  color: #97f1b5;
}

.widget-leave-modal[hidden] {
  display: none;
}

.widget-leave-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
}

.widget-leave-modal__backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(0, 0, 0, 0.58);
}

.widget-leave-modal__panel {
  position: relative;
  z-index: 1;
  width: min(100%, 320px);
  padding: 18px;
  border-radius: 18px;
  border: 1px solid var(--widget-border);
  background: #0a0a0a;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

.widget-leave-modal__panel h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.widget-leave-modal__panel p {
  margin: 0;
  color: var(--widget-muted);
  line-height: 1.55;
}

.widget-leave-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.widget-leave-modal__btn {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--widget-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--widget-text);
  cursor: pointer;
}

.widget-leave-modal__btn--primary {
  background: #fff;
  color: #000;
}

.widget-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--widget-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--widget-muted);
  font-size: 12px;
}

.widget-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.72);
  animation: widgetPulse 1s infinite ease-in-out;
}

.widget-dot:nth-child(2) {
  animation-delay: 0.12s;
}

.widget-dot:nth-child(3) {
  animation-delay: 0.24s;
}

@keyframes widgetPulse {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.55;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

@media (max-width: 640px) {
  .widget-launcher,
  .widget-shell {
    right: 12px;
    bottom: 12px;
  }

  .widget-shell {
    width: calc(100vw - 24px);
    height: min(72dvh, 700px);
  }
}
