/**
 * Invoice Axis — Floating chat / enquiry widget
 * Mounted on homepage + dashboard (SPA shell).
 */

:root {
  --ia-chat-primary: #4f46e5;
  --ia-chat-primary-2: #6366f1;
  --ia-chat-dark: #111827;
  --ia-chat-muted: #6b7280;
  --ia-chat-border: #e5e7eb;
  --ia-chat-bg: #ffffff;
  --ia-chat-shadow: 0 18px 50px rgba(15, 23, 42, 0.22);
  --ia-chat-z: 2147483000;
}

#ia-chat-root {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: var(--ia-chat-z);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4;
  color: var(--ia-chat-dark);
  -webkit-font-smoothing: antialiased;
}

#ia-chat-root *,
#ia-chat-root *::before,
#ia-chat-root *::after {
  box-sizing: border-box;
}

.ia-chat-launcher {
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, var(--ia-chat-primary), var(--ia-chat-primary-2));
  color: #fff;
  box-shadow: 0 10px 30px rgba(79, 70, 229, 0.45);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ia-chat-launcher:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 14px 34px rgba(79, 70, 229, 0.55);
}

.ia-chat-launcher:focus-visible {
  outline: 3px solid rgba(99, 102, 241, 0.45);
  outline-offset: 3px;
}

.ia-chat-launcher svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}

.ia-chat-launcher[aria-expanded="true"] .ia-icon-chat {
  display: none;
}

.ia-chat-launcher[aria-expanded="false"] .ia-icon-close {
  display: none;
}

.ia-chat-panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: min(380px, calc(100vw - 28px));
  max-height: min(640px, calc(100vh - 110px));
  background: var(--ia-chat-bg);
  border-radius: 18px;
  box-shadow: var(--ia-chat-shadow);
  border: 1px solid var(--ia-chat-border);
  overflow: hidden;
  display: none;
  flex-direction: column;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.ia-chat-panel.is-open {
  display: flex;
  opacity: 1;
  transform: translateY(0) scale(1);
}

.ia-chat-header {
  background: linear-gradient(135deg, #4f46e5, #6366f1 55%, #818cf8);
  color: #fff;
  padding: 16px 16px 14px;
  display: flex;
  gap: 12px;
  align-items: center;
}

.ia-chat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.ia-chat-header-text {
  min-width: 0;
  flex: 1;
}

.ia-chat-header-text strong {
  display: block;
  font-size: 15px;
}

.ia-chat-header-text span {
  display: block;
  font-size: 12.5px;
  opacity: 0.9;
  margin-top: 2px;
}

.ia-chat-online {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 11px;
  opacity: 0.95;
}

.ia-chat-online::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.25);
}

.ia-chat-close-btn {
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}

.ia-chat-body {
  padding: 14px 16px 8px;
  overflow-y: auto;
  flex: 1;
  background: #f8fafc;
}

.ia-chat-bubble {
  background: #fff;
  border: 1px solid var(--ia-chat-border);
  border-radius: 12px 12px 12px 4px;
  padding: 10px 12px;
  font-size: 13px;
  color: #374151;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.ia-chat-form {
  display: grid;
  gap: 10px;
}

.ia-chat-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 4px;
}

.ia-chat-field label .req {
  color: #ef4444;
}

.ia-chat-field label .opt {
  color: var(--ia-chat-muted);
  font-weight: 500;
}

.ia-chat-field input,
.ia-chat-field textarea {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--ia-chat-dark);
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ia-chat-field textarea {
  min-height: 96px;
  resize: vertical;
}

.ia-chat-field input:focus,
.ia-chat-field textarea:focus {
  outline: none;
  border-color: var(--ia-chat-primary-2);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}

.ia-chat-field input.is-invalid,
.ia-chat-field textarea.is-invalid {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

.ia-chat-field .ia-error {
  display: none;
  margin-top: 4px;
  font-size: 12px;
  color: #dc2626;
}

.ia-chat-field .ia-error.is-visible {
  display: block;
}

/* Paid customer service option card */
.ia-chat-paid-option {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  border-radius: 12px;
  border: 1.5px solid #fcd34d;
  background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 55%, #fff7ed 100%);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
  user-select: none;
}

.ia-chat-paid-option:hover {
  border-color: #f59e0b;
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.18);
  transform: translateY(-1px);
}

.ia-chat-paid-option:has(input:checked),
.ia-chat-paid-option.is-checked {
  border-color: #d97706;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
  background: linear-gradient(135deg, #fef3c7, #fde68a);
}

.ia-chat-paid-check {
  flex-shrink: 0;
  margin-top: 2px;
}

.ia-chat-paid-check input {
  width: 18px;
  height: 18px;
  accent-color: #d97706;
  cursor: pointer;
}

.ia-chat-paid-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.ia-chat-paid-badge {
  display: inline-flex;
  align-self: flex-start;
  padding: 2px 8px;
  border-radius: 999px;
  background: linear-gradient(135deg, #f59e0b, #ea580c);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.ia-chat-paid-copy strong {
  font-size: 13.5px;
  color: #92400e;
  line-height: 1.3;
}

.ia-chat-paid-desc {
  font-size: 12px;
  color: #a16207;
  line-height: 1.4;
}

.ia-chat-footer {
  padding: 8px 16px 16px;
  background: #f8fafc;
  border-top: 1px solid transparent;
}

.ia-chat-submit {
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(135deg, var(--ia-chat-primary), var(--ia-chat-primary-2));
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.28);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.ia-chat-submit:hover:not(:disabled) {
  transform: translateY(-1px);
}

.ia-chat-submit:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.ia-chat-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: ia-spin 0.7s linear infinite;
  display: none;
}

.ia-chat-submit.is-loading .ia-chat-spinner {
  display: inline-block;
}

.ia-chat-submit.is-loading .ia-submit-label {
  opacity: 0.9;
}

@keyframes ia-spin {
  to {
    transform: rotate(360deg);
  }
}

.ia-chat-alert {
  display: none;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 10px;
}

.ia-chat-alert.is-visible {
  display: block;
}

.ia-chat-alert.is-success {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.ia-chat-alert.is-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.ia-chat-powered {
  text-align: center;
  font-size: 11px;
  color: #9ca3af;
  margin-top: 8px;
}

/* Mobile: fit panel between top safe-area and launcher (above bottom nav) */
@media (max-width: 480px) {
  #ia-chat-root {
    right: 12px;
    bottom: 90px;
  }

  .ia-chat-panel {
    position: fixed;
    left: 12px;
    right: 12px;
    width: auto;
    top: max(12px, env(safe-area-inset-top, 0px));
    bottom: calc(90px + 56px + 12px);
    max-height: none;
    height: auto;
    border-radius: 16px;
  }

  .ia-chat-body {
    min-height: 0;
    -webkit-overflow-scrolling: touch;
  }

  .ia-chat-launcher {
    width: 56px;
    height: 56px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ia-chat-panel,
  .ia-chat-launcher,
  .ia-chat-submit {
    transition: none;
  }
}
