/* ============================================
   Tai Chat Widget — Bottom-right dashboard AI
   z-index: 15000 (above modals, below critical)
   ============================================ */

/* ── Toggle Button ────────────────────────── */

.tai-widget-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 15000;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-brand, #1E3A5F);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  font-size: 0;
}

.tai-widget-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.tai-widget-toggle:active {
  transform: scale(0.96);
}

.tai-widget-toggle .tai-icon {
  width: 26px;
  height: 26px;
  fill: currentColor;
}

.tai-widget-toggle .tai-close-icon {
  display: none;
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.tai-widget-toggle.open .tai-icon {
  display: none;
}

.tai-widget-toggle.open .tai-close-icon {
  display: block;
}

/* Pulse animation for first-time attention */
.tai-widget-toggle.pulse::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--color-brand, #1E3A5F);
  animation: tai-pulse 2s ease-out infinite;
}

@keyframes tai-pulse {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.4); opacity: 0; }
}

/* ── Chat Panel ───────────────────────────── */

.tai-widget-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: 15001;
  width: 380px;
  max-height: 560px;
  border-radius: var(--radius-xl, 12px);
  background: var(--color-surface, #ffffff);
  border: 1px solid var(--color-border, #e1e5e9);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.tai-widget-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ── Header ───────────────────────────────── */

.tai-widget-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border, #e1e5e9);
  background: var(--color-bg, #fafafa);
  flex-shrink: 0;
}

.tai-widget-header .tai-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-brand, #1E3A5F);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tai-widget-header .tai-avatar svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

.tai-widget-header .tai-info {
  flex: 1;
  min-width: 0;
}

.tai-widget-header .tai-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-primary, #0d1117);
  line-height: 1.2;
}

.tai-widget-header .tai-status {
  font-size: 11px;
  color: var(--color-text-secondary, #656d76);
  display: flex;
  align-items: center;
  gap: 4px;
}

.tai-widget-header .tai-status .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #2da44e;
  flex-shrink: 0;
}

.tai-widget-header .tai-clear-btn {
  padding: 4px 8px;
  border: 1px solid var(--color-border, #e1e5e9);
  border-radius: var(--radius, 6px);
  background: transparent;
  color: var(--color-text-secondary, #656d76);
  font-size: 11px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tai-widget-header .tai-clear-btn:hover {
  background: var(--color-bg, #fafafa);
  color: var(--color-text-primary, #0d1117);
}

/* ── Messages ─────────────────────────────── */

.tai-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 200px;
  max-height: 360px;
}

.tai-widget-messages::-webkit-scrollbar {
  width: 4px;
}

.tai-widget-messages::-webkit-scrollbar-thumb {
  background: var(--color-border, #e1e5e9);
  border-radius: 2px;
}

/* Message bubbles */
.tai-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: tai-msg-in 0.2s ease;
}

@keyframes tai-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.tai-msg.user {
  align-self: flex-end;
  background: var(--color-brand, #1E3A5F);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.tai-msg.tai {
  align-self: flex-start;
  background: var(--color-bg, #fafafa);
  color: var(--color-text-primary, #0d1117);
  border: 1px solid var(--color-border, #e1e5e9);
  border-bottom-left-radius: 4px;
}

.tai-msg.tai code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}

.tai-msg.tai strong {
  font-weight: 600;
}

/* Typing indicator */
.tai-msg.typing {
  display: flex;
  gap: 4px;
  padding: 12px 18px;
}

.tai-msg.typing .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-secondary, #656d76);
  animation: tai-typing 1.2s ease-in-out infinite;
}

.tai-msg.typing .dot:nth-child(2) { animation-delay: 0.15s; }
.tai-msg.typing .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes tai-typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* Welcome state */
.tai-widget-welcome {
  text-align: center;
  padding: 24px 16px;
  color: var(--color-text-secondary, #656d76);
}

.tai-widget-welcome .tai-welcome-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--color-brand, #1E3A5F);
  display: flex;
  align-items: center;
  justify-content: center;
}

.tai-widget-welcome .tai-welcome-icon svg {
  width: 24px;
  height: 24px;
  fill: #fff;
}

.tai-widget-welcome h4 {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-primary, #0d1117);
  margin: 0 0 4px;
}

.tai-widget-welcome p {
  font-size: 12px;
  margin: 0 0 16px;
}

/* Quick action chips */
.tai-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.tai-quick-action {
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--color-border, #e1e5e9);
  background: var(--color-surface, #ffffff);
  color: var(--color-text-primary, #0d1117);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.tai-quick-action:hover {
  background: var(--color-bg, #fafafa);
  border-color: var(--color-brand, #1E3A5F);
}

/* ── Input ────────────────────────────────── */

.tai-widget-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--color-border, #e1e5e9);
  background: var(--color-surface, #ffffff);
  flex-shrink: 0;
}

.tai-widget-input textarea {
  flex: 1;
  border: 1px solid var(--color-border, #e1e5e9);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  background: var(--color-bg, #fafafa);
  color: var(--color-text-primary, #0d1117);
  resize: none;
  outline: none;
  max-height: 80px;
  line-height: 1.4;
  transition: border-color 0.15s;
}

.tai-widget-input textarea:focus {
  border-color: var(--color-brand, #1E3A5F);
}

.tai-widget-input textarea::placeholder {
  color: var(--color-text-secondary, #656d76);
}

.tai-widget-input .tai-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--color-brand, #1E3A5F);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
}

.tai-widget-input .tai-send-btn:hover {
  opacity: 0.9;
  transform: scale(1.05);
}

.tai-widget-input .tai-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.tai-widget-input .tai-send-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* ── Domain badge ─────────────────────────── */

.tai-domain-badge {
  display: inline-block;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--color-brand, #1E3A5F);
  color: #fff;
  opacity: 0.7;
  margin-top: 4px;
}

/* ── Maximize Mode ────────────────────────── */

.tai-widget-panel.maximized {
  width: 560px;
  max-height: 80vh;
  bottom: 50%;
  right: 50%;
  transform: translate(50%, 50%) scale(1);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.tai-widget-panel.maximized .tai-widget-messages {
  max-height: calc(80vh - 140px);
}

.tai-widget-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 14999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.tai-widget-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

/* ── Responsive ───────────────────────────── */

@media (max-width: 480px) {
  .tai-widget-panel,
  .tai-widget-panel.maximized {
    width: 100%;
    max-width: 100%;
    height: 100vh;
    max-height: 100vh;
    bottom: 0;
    right: 0;
    border-radius: 0;
    transform: none;
  }

  .tai-widget-toggle {
    bottom: 16px;
    right: 16px;
    width: 50px;
    height: 50px;
  }
}
