/* ============================================================
   AI assistant floating widget
   ============================================================ */

.crm-ai-fab {
  position: relative;
  width: 100%;
  min-height: 44px;
  margin-bottom: 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 32%, transparent);
  border-radius: var(--control-radius,8px);
  background: #282828;
  color: #fff;
  box-shadow: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .16s ease, box-shadow .16s ease, opacity .16s ease;
}

.crm-ai-fab:hover {
  transform: translateY(-2px);
  background: #3a3a3a;
}

.crm-ai-fab:active {
  transform: translateY(0) scale(.98);
}

.crm-ai-fab span {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: .05em;
}

.crm-ai-panel-bg {
  position: fixed;
  inset: 0;
  z-index: 260;
  display: none;
  pointer-events: none;
}

.crm-ai-panel-bg.open {
  display: block;
}

.crm-ai-panel {
  position: absolute;
  right: 22px;
  bottom: 88px;
  width: min(460px, calc(100vw - 44px));
  max-height: min(720px, calc(100dvh - 120px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  pointer-events: auto;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--bg-surface);
  box-shadow: 0 22px 60px rgba(23, 23, 23, .25);
}

.crm-ai-panel-head {
  padding: 16px 18px 14px;
  background: linear-gradient(135deg, #1f1f1f, #5b5b5b);
  color: #fff;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.crm-ai-title {
  font-size: 15px;
  font-weight: 850;
  margin-bottom: 3px;
}

.crm-ai-subtitle {
  font-size: 12px;
  line-height: 1.35;
  color: rgba(255, 255, 255, .72);
}

.crm-ai-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 11px;
  background: rgba(255, 255, 255, .12);
  color: rgba(255, 255, 255, .8);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.crm-ai-close:hover {
  background: rgba(255, 255, 255, .18);
  color: #fff;
}

.crm-ai-panel-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.crm-ai-status {
  align-self: flex-start;
  font-size: 11px;
  font-weight: 750;
  color: var(--text-muted);
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
}

.crm-ai-status[data-state="ready"] {
  color: #166534;
  background: #ecfdf3;
  border-color: #bbf7d0;
}

.crm-ai-status[data-state="missing-key"],
.crm-ai-status[data-state="offline"] {
  color: #92400e;
  background: #fffbeb;
  border-color: #fde68a;
}

.crm-ai-mode-hint {
  margin-top: -5px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.4;
}

.crm-ai-quick {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.crm-ai-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.crm-ai-input {
  resize: vertical;
  min-height: 86px;
}

.crm-ai-submit {
  height: 40px;
  white-space: nowrap;
}

.crm-ai-answer {
  min-height: 90px;
  max-height: 310px;
  overflow-y: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  font-size: 13px;
}

body.crm-ai-open .crm-ai-fab {
  opacity: .86;
}

@media (max-width: 640px) {
  .crm-ai-panel {
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
    max-height: calc(100dvh - 20px);
    border-radius: 18px;
  }

  .crm-ai-form {
    grid-template-columns: 1fr;
  }

  .crm-ai-submit {
    width: 100%;
  }
}
