/* =============================================================================
   InnovaAgent AI — style.css
   Covers: floating chat widget (frontend) + admin settings page
   ============================================================================= */

/* ── Custom Properties ──────────────────────────────────────────────────────── */
:root {
  --iag-accent:        #6c47ff;
  --iag-accent-light:  #8a6aff;
  --iag-accent-dark:   #4f2fe0;
  --iag-surface:       #ffffff;
  --iag-surface-2:     #f5f4fa;
  --iag-text:          #1a1523;
  --iag-text-muted:    #6b7280;
  --iag-border:        #e5e2f0;
  --iag-user-bg:       #6c47ff;
  --iag-user-text:     #ffffff;
  --iag-bot-bg:        #f0eeff;
  --iag-bot-text:      #1a1523;
  --iag-shadow-sm:     0 2px 8px rgba(108, 71, 255, 0.12);
  --iag-shadow-lg:     0 12px 40px rgba(108, 71, 255, 0.22);
  --iag-radius:        16px;
  --iag-radius-sm:     10px;
  --iag-font:          'Segoe UI', system-ui, -apple-system, sans-serif;
  --iag-z:             999999;
  --iag-bubble-size:   58px;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   FRONTEND — Floating Bubble & Chat Window
   ═══════════════════════════════════════════════════════════════════════════════ */

#iag-chat-root *,
#iag-chat-root *::before,
#iag-chat-root *::after {
  box-sizing: border-box;
  font-family: var(--iag-font);
}

/* ── Bubble ─────────────────────────────────────────────────────────────────── */
.iag-bubble {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: var(--iag-z);
  width:  var(--iag-bubble-size);
  height: var(--iag-bubble-size);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--iag-accent) 0%, var(--iag-accent-light) 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 18px rgba(108, 71, 255, 0.45);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.2s ease;
  outline-offset: 3px;
}

.iag-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(108, 71, 255, 0.55);
}

.iag-bubble:focus-visible {
  outline: 3px solid var(--iag-accent-light);
}

.iag-bubble--active {
  transform: scale(0.92);
}

/* Ripple effect on bubble */
.iag-bubble::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(108, 71, 255, 0.3);
  animation: iag-ripple 2.4s ease-in-out infinite;
  pointer-events: none;
}

@keyframes iag-ripple {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50%       { opacity: 0;   transform: scale(1.25); }
}

.iag-bubble-icon {
  width: 24px;
  height: 24px;
  color: #fff;
  transition: opacity 0.15s ease, transform 0.2s ease;
  position: absolute;
}

.iag-bubble-icon--close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.7);
}

.iag-bubble--active .iag-bubble-icon--open  {
  opacity: 0;
  transform: rotate(90deg) scale(0.7);
}
.iag-bubble--active .iag-bubble-icon--close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* ── Chat Window ────────────────────────────────────────────────────────────── */
.iag-window {
  position: fixed;
  bottom: calc(var(--iag-bubble-size) + 44px);
  right: 28px;
  z-index: var(--iag-z);
  width:  380px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 120px);
  background: var(--iag-surface);
  border-radius: var(--iag-radius);
  border: 1px solid var(--iag-border);
  box-shadow: var(--iag-shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Hidden by default */
  opacity: 0;
  transform: translateY(20px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.34, 1.3, 0.64, 1);
}

.iag-window--open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
.iag-window-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: linear-gradient(135deg, var(--iag-accent-dark) 0%, var(--iag-accent) 100%);
  flex-shrink: 0;
}

.iag-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}

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

.iag-header-title {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.iag-header-status {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.75);
  display: flex;
  align-items: center;
  gap: 5px;
}

.iag-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
  animation: iag-pulse 2s ease-in-out infinite;
}

.iag-status-dot--thinking { background: #facc15; animation: iag-pulse 0.8s ease-in-out infinite; }
.iag-status-dot--error    { background: #f87171; animation: none; }

@keyframes iag-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.iag-header-close {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.iag-header-close:hover { background: rgba(255, 255, 255, 0.22); }

.iag-header-close svg {
  width: 16px;
  height: 16px;
  color: rgba(255, 255, 255, 0.9);
}

/* ── Messages ───────────────────────────────────────────────────────────────── */
.iag-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  background: var(--iag-surface-2);
}

.iag-messages::-webkit-scrollbar       { width: 4px; }
.iag-messages::-webkit-scrollbar-track { background: transparent; }
.iag-messages::-webkit-scrollbar-thumb { background: var(--iag-border); border-radius: 4px; }

.iag-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: iag-msg-in 0.2s ease;
}

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

.iag-msg--user {
  align-self: flex-end;
  align-items: flex-end;
}

.iag-msg--assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.iag-msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
}

.iag-msg--user     .iag-msg-bubble {
  background: var(--iag-user-bg);
  color:      var(--iag-user-text);
  border-bottom-right-radius: 4px;
}

.iag-msg--assistant .iag-msg-bubble {
  background: var(--iag-bot-bg);
  color:      var(--iag-bot-text);
  border-bottom-left-radius: 4px;
}

.iag-msg-time {
  font-size: 10.5px;
  color: var(--iag-text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

/* ── Typing indicator ───────────────────────────────────────────────────────── */
.iag-typing-bubble {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 12px 16px !important;
}

.iag-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--iag-accent);
  display: inline-block;
  animation: iag-typing 1.2s ease-in-out infinite;
}

.iag-dot:nth-child(2) { animation-delay: 0.2s; }
.iag-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes iag-typing {
  0%, 60%, 100% { transform: translateY(0);   opacity: 0.4; }
  30%           { transform: translateY(-6px); opacity: 1; }
}

/* ── Input area ─────────────────────────────────────────────────────────────── */
.iag-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px 14px;
  background: var(--iag-surface);
  border-top: 1px solid var(--iag-border);
  flex-shrink: 0;
}

.iag-user-input {
  flex: 1;
  border: 1.5px solid var(--iag-border);
  border-radius: var(--iag-radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  color: var(--iag-text);
  background: var(--iag-surface-2);
  transition: border-color 0.15s;
  max-height: 120px;
  overflow-y: auto;
  font-family: var(--iag-font);
}

.iag-user-input:focus {
  border-color: var(--iag-accent);
  background: var(--iag-surface);
}

.iag-user-input::placeholder { color: var(--iag-text-muted); }

.iag-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--iag-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.15s;
}

.iag-send-btn:hover:not(:disabled) {
  background: var(--iag-accent-dark);
  transform: scale(1.05);
}

.iag-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.iag-send-btn svg {
  width: 17px;
  height: 17px;
  color: #fff;
  transform: translateX(1px);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   ADMIN SETTINGS PAGE
   ═══════════════════════════════════════════════════════════════════════════════ */

.iag-admin-wrap {
  max-width: 860px;
  padding: 28px 0 60px;
  font-family: var(--iag-font);
}

.iag-admin-title {
  font-size: 24px !important;
  font-weight: 800 !important;
  color: var(--iag-accent-dark) !important;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px !important;
  letter-spacing: -0.3px;
}

.iag-logo-icon {
  color: var(--iag-accent);
  font-size: 20px;
}

.iag-notice {
  border-left-color: var(--iag-accent) !important;
}

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.iag-card {
  background: #fff;
  border: 1px solid var(--iag-border);
  border-radius: 14px;
  padding: 26px 28px;
  margin-bottom: 22px;
  box-shadow: 0 1px 4px rgba(108, 71, 255, 0.06);
}

.iag-card-title {
  font-size: 15.5px !important;
  font-weight: 700 !important;
  color: var(--iag-text) !important;
  margin: 0 0 20px !important;
  padding: 0 0 14px !important;
  border-bottom: 1px solid var(--iag-border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.iag-card-icon { font-size: 17px; }

/* ── Field Rows ─────────────────────────────────────────────────────────────── */
.iag-field-row {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 14px 20px;
  align-items: start;
  margin-bottom: 18px;
}

.iag-field-row:last-child { margin-bottom: 0; }

.iag-field-row--full {
  grid-template-columns: 1fr;
}

.iag-label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--iag-text);
  padding-top: 10px;
}

.iag-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ── Inputs ─────────────────────────────────────────────────────────────────── */
.iag-input,
.iag-select,
.iag-textarea {
  font-family: var(--iag-font) !important;
  font-size: 14px !important;
  border: 1.5px solid var(--iag-border) !important;
  border-radius: var(--iag-radius-sm) !important;
  padding: 9px 13px !important;
  color: var(--iag-text) !important;
  background: var(--iag-surface-2) !important;
  width: 100%;
  box-shadow: none !important;
  transition: border-color 0.15s !important;
  outline: none !important;
}

.iag-input:focus,
.iag-select:focus,
.iag-textarea:focus {
  border-color: var(--iag-accent) !important;
  background: #fff !important;
  box-shadow: 0 0 0 3px rgba(108, 71, 255, 0.08) !important;
}

.iag-textarea {
  resize: vertical !important;
  min-height: 90px;
  line-height: 1.6 !important;
}

.iag-textarea--sm { min-height: 60px; }

/* ── API Key Row ────────────────────────────────────────────────────────────── */
.iag-key-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.iag-key-row .iag-input {
  flex: 1;
}

.iag-toggle-visibility {
  background: var(--iag-surface-2);
  border: 1.5px solid var(--iag-border);
  border-radius: var(--iag-radius-sm);
  cursor: pointer;
  padding: 8px 10px;
  font-size: 15px;
  line-height: 1;
  transition: background 0.15s;
  flex-shrink: 0;
  color: var(--iag-text-muted);
}

.iag-toggle-visibility:hover { background: #ede9ff; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.iag-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: var(--iag-radius-sm);
  cursor: pointer;
  transition: background 0.15s, transform 0.12s;
  border: none;
  white-space: nowrap;
  outline-offset: 3px;
  text-decoration: none;
}

.iag-btn:focus-visible {
  outline: 3px solid var(--iag-accent-light);
}

.iag-btn-test {
  background: var(--iag-surface-2);
  border: 1.5px solid var(--iag-border);
  color: var(--iag-accent-dark);
  padding: 8px 14px;
  flex-shrink: 0;
}

.iag-btn-test:hover:not(:disabled) {
  background: #ede9ff;
  border-color: var(--iag-accent-light);
}

.iag-btn-test:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.iag-btn-primary {
  background: linear-gradient(135deg, var(--iag-accent) 0%, var(--iag-accent-dark) 100%);
  color: #fff;
  padding: 12px 28px;
  font-size: 14.5px;
  box-shadow: 0 3px 12px rgba(108, 71, 255, 0.3);
}

.iag-btn-primary:hover {
  background: linear-gradient(135deg, var(--iag-accent-light) 0%, var(--iag-accent) 100%);
  box-shadow: 0 4px 16px rgba(108, 71, 255, 0.4);
  transform: translateY(-1px);
}

.iag-btn-icon { font-size: 14px; }

/* ── Test Result Banner ─────────────────────────────────────────────────────── */
.iag-test-result {
  font-size: 13px;
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease, padding 0.2s ease;
}

.iag-test-result:not(:empty) {
  max-height: 100px;
  padding: 8px 12px;
}

.iag-test-result--loading {
  background: #f0eeff;
  color: var(--iag-accent-dark);
}

.iag-test-result--success {
  background: #dcfce7;
  color: #15803d;
}

.iag-test-result--error {
  background: #fee2e2;
  color: #b91c1c;
}

/* ── Description text ───────────────────────────────────────────────────────── */
.iag-description {
  font-size: 12.5px !important;
  color: var(--iag-text-muted) !important;
  margin: 0 !important;
}

.iag-description a {
  color: var(--iag-accent) !important;
  text-decoration: none !important;
}

.iag-description a:hover { text-decoration: underline !important; }

/* ── Save row ───────────────────────────────────────────────────────────────── */
.iag-save-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .iag-field-row {
    grid-template-columns: 1fr;
  }

  .iag-label {
    padding-top: 0;
  }

  .iag-key-row {
    flex-wrap: wrap;
  }

  .iag-key-row .iag-btn-test {
    width: 100%;
    justify-content: center;
  }

  /* Widget on mobile */
  .iag-window {
    right: 12px;
    bottom: calc(var(--iag-bubble-size) + 16px);
    width: calc(100vw - 24px);
  }

  .iag-bubble {
    right: 16px;
    bottom: 16px;
  }
}

/* ── Custom agent icon (frontend) ────────────────────────────────────────────── */
.iag-bubble-custom-icon {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: center;
  position: absolute;
  inset: 0;
  transition: opacity 0.15s ease, transform 0.2s ease;
}

/* Suppress purple gradient when a custom icon is present */
.iag-bubble:has(.iag-bubble-custom-icon) {
  background: transparent;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
}
.iag-bubble:has(.iag-bubble-custom-icon):hover {
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
.iag-bubble:has(.iag-bubble-custom-icon)::before {
  border-color: rgba(0, 0, 0, 0.15);
}

.iag-header-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
