.ai-widget-root {
  position: fixed;
  z-index: 9000;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  font-family: var(--font, "Plus Jakarta Sans", system-ui, sans-serif);
  pointer-events: none;
}

.ai-widget-root * {
  box-sizing: border-box;
}

.ai-widget-fab {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(34, 211, 238, 0.35);
  border-radius: 999px;
  padding: 12px 18px;
  background: linear-gradient(135deg, var(--accent, #22d3ee), var(--accent2, #0891b2));
  color: var(--bg, #0a0e14);
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  box-shadow: var(--shadow-sm, 0 8px 24px rgba(0, 0, 0, 0.25));
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.ai-widget-fab:hover {
  transform: translateY(-2px);
  border-color: rgba(34, 211, 238, 0.55);
  box-shadow: var(--shadow, 0 16px 48px rgba(0, 0, 0, 0.35));
}

.ai-widget-fab-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.ai-widget-panel {
  pointer-events: auto;
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  width: min(400px, calc(100vw - 32px));
  max-height: min(560px, calc(100vh - 120px));
  display: flex;
  flex-direction: column;
  background: var(--surface, #151d2b);
  border: 1px solid var(--line, #273246);
  border-radius: var(--radius, 14px);
  box-shadow: var(--shadow, 0 16px 48px rgba(0, 0, 0, 0.35));
  overflow: hidden;
}

.ai-widget-root.is-open .ai-widget-fab {
  opacity: 0.95;
}

.ai-widget-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.18), rgba(8, 145, 178, 0.12));
  border-bottom: 1px solid var(--line, #273246);
  color: var(--text, #e8edf4);
}

.ai-widget-title {
  display: block;
  font-size: 1rem;
  color: var(--accent, #22d3ee);
}

.ai-widget-sub {
  display: block;
  font-size: 0.78rem;
  color: var(--muted, #8b98ab);
  margin-top: 2px;
}

.ai-widget-head-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.ai-widget-icon-btn {
  border: 1px solid var(--line, #273246);
  background: var(--surface2, #1b2536);
  color: var(--ink2, #c5d0dc);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm, 10px);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  transition: border-color 0.15s, color 0.15s;
}

.ai-widget-icon-btn:hover {
  border-color: rgba(34, 211, 238, 0.35);
  color: var(--accent, #22d3ee);
}

.ai-widget-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 180px;
  background: var(--bg2, #101722);
}

.ai-widget-empty {
  margin: auto 0;
  text-align: center;
  color: var(--muted, #8b98ab);
  font-size: 0.88rem;
  line-height: 1.45;
}

.ai-widget-msg {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: var(--radius-sm, 10px);
  font-size: 0.88rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-widget-msg strong {
  font-weight: 700;
  color: inherit;
}

.ai-widget-msg-user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent, #22d3ee), var(--accent2, #0891b2));
  color: var(--bg, #0a0e14);
  border-bottom-right-radius: 4px;
}

.ai-widget-msg-assistant {
  align-self: flex-start;
  background: var(--surface, #151d2b);
  color: var(--text, #e8edf4);
  border: 1px solid var(--line, #273246);
  border-bottom-left-radius: 4px;
}

.ai-widget-msg-assistant.is-error {
  border-color: rgba(240, 113, 120, 0.45);
  background: var(--err-bg, rgba(240, 113, 120, 0.12));
  color: var(--err, #f07178);
}

.ai-widget-thinking {
  opacity: 0.65;
  font-style: italic;
  color: var(--muted, #8b98ab);
}

.ai-widget-msg a {
  color: var(--accent, #22d3ee);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-widget-msg a:hover {
  color: #67e8f9;
}

.ai-widget-msg-user a {
  color: var(--bg, #0a0e14);
  font-weight: 600;
  text-decoration: underline;
}

.ai-widget-ticket {
  padding: 10px 14px;
  border-top: 1px solid var(--line, #273246);
  background: rgba(212, 175, 55, 0.08);
}

.ai-widget-ticket p {
  margin: 0 0 8px;
  font-size: 0.82rem;
  color: var(--gold, #d4af37);
}

.ai-widget-ticket-btn {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: var(--radius-sm, 10px);
  background: linear-gradient(135deg, var(--accent, #22d3ee), var(--accent2, #0891b2));
  color: var(--bg, #0a0e14);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
}

.ai-widget-ticket-btn:hover {
  color: var(--bg, #0a0e14);
  opacity: 0.92;
}

.ai-widget-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line, #273246);
  background: var(--surface, #151d2b);
}

.ai-widget-form textarea {
  flex: 1;
  min-height: 42px;
  max-height: 120px;
  resize: none;
  border: 1px solid var(--line, #273246);
  border-radius: var(--radius-sm, 10px);
  padding: 10px 12px;
  font: inherit;
  font-size: 0.88rem;
  background: var(--bg2, #101722);
  color: var(--text, #e8edf4);
}

.ai-widget-form textarea::placeholder {
  color: var(--muted, #8b98ab);
}

.ai-widget-form textarea:focus {
  outline: none;
  border-color: var(--accent, #22d3ee);
  box-shadow: 0 0 0 3px var(--accent-soft, rgba(34, 211, 238, 0.14));
}

.ai-widget-send {
  flex-shrink: 0;
  border: 0;
  border-radius: var(--radius-sm, 10px);
  padding: 0 14px;
  background: linear-gradient(135deg, var(--accent, #22d3ee), var(--accent2, #0891b2));
  color: var(--bg, #0a0e14);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
}

.ai-widget-send:hover {
  opacity: 0.92;
}

.ai-widget-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 640px) {
  .ai-widget-root {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(72px, env(safe-area-inset-bottom));
  }

  .ai-widget-fab-label {
    display: none;
  }

  .ai-widget-fab {
    width: 52px;
    height: 52px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
  }

  .ai-widget-panel {
    width: calc(100vw - 24px);
    max-height: min(70vh, 520px);
    right: -4px;
  }
}
