/* =========================================================================
   QuantumGate API — Design System
   Palette: light / clean
   ========================================================================= */

:root {
  --deep-blue: #0A0F2C;
  --graphite: #0B0B0B;
  --neon-cyan: #00E5FF;
  --violet: #6A00FF;
  --silver: #C9D1D9;
  --danger: #FF3B5C;
  --success: #00FFB2;
  --radius: 8px;
  --transition: 0.25s ease;
  /* Light theme variables */
  --bg-page: #f9fafb;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --border-color: #e5e7eb;
  --border-focus: #6366f1;
}

/* =========================================================================
   Global
   ========================================================================= */

html,
body {
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

code, pre, kbd, samp {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}

/* =========================================================================
   Fade-in entrance animation
   ========================================================================= */

.fade-in {
  opacity: 0;
  animation: qgFadeIn 0.6s forwards;
}

@keyframes qgFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =========================================================================
   Card glow on hover (applied via .qg-card)
   ========================================================================= */

.qg-card {
  transition: transform var(--transition), box-shadow var(--transition);
}

.qg-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

/* =========================================================================
   Form focus ring
   ========================================================================= */

input:focus,
select:focus,
textarea:focus {
  outline: none !important;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15) !important;
  border-color: var(--border-focus) !important;
}

/* =========================================================================
   Button hover
   ========================================================================= */

button,
.btn {
  transition: transform var(--transition), box-shadow var(--transition), background-color var(--transition);
}

button:hover:not(:disabled),
.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

/* =========================================================================
   Scrollbar
   ========================================================================= */

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: #f3f4f6;
}

::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: #d1d5db #f3f4f6;
}

/* =========================================================================
   Selection
   ========================================================================= */

::selection {
  background: rgba(99, 102, 241, 0.2);
  color: #111827;
}

/* =========================================================================
   Code blocks
   ========================================================================= */

pre, code.qg-code {
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: var(--radius);
  color: #374151;
  font-size: 0.85rem;
  padding: 12px 14px;
  overflow-x: auto;
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}

/* =========================================================================
   Chatbot widget — stays dark (floating widget)
   ========================================================================= */

#qg-chat-fab {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom, 20px));
  right: max(20px, env(safe-area-inset-right, 20px));
  z-index: 60;
  width: clamp(52px, 12vw, 64px);
  height: clamp(52px, 12vw, 64px);
  border-radius: 50%;
  background: radial-gradient(circle, #4f46e5, #7c3aed);
  border: 1px solid #4f46e5;
  color: #ffffff;
  font-size: clamp(1.2rem, 4vw, 1.5rem);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.3);
  transition: transform var(--transition), box-shadow var(--transition);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#qg-chat-fab:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 24px rgba(79, 70, 229, 0.4);
}

#qg-chat-fab:active {
  transform: scale(0.95);
}

#qg-chat-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 55;
  display: none;
  animation: qgFadeIn 0.2s forwards;
}

#qg-chat-backdrop.open {
  display: block;
}

#qg-chat-panel {
  position: fixed;
  bottom: max(88px, calc(env(safe-area-inset-bottom, 0px) + 88px));
  right: max(16px, env(safe-area-inset-right, 16px));
  z-index: 60;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100dvh - 120px));
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  display: none;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  font-family: 'Inter', sans-serif;
}

#qg-chat-panel.open {
  display: flex;
  animation: qgFadeIn 0.25s forwards;
}

.qg-chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #111827;
  font-weight: 600;
  font-family: 'Space Grotesk', sans-serif;
  flex-shrink: 0;
}

.qg-chat-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.qg-chat-header-left > span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.qg-logo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle, #4f46e5, #7c3aed);
  box-shadow: 0 0 8px rgba(79, 70, 229, 0.4);
  flex-shrink: 0;
}

.qg-chat-close {
  background: transparent;
  border: none;
  color: #6b7280;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 6px 8px;
  margin: -6px -8px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

.qg-chat-close:hover {
  color: #4f46e5;
}

.qg-chat-messages {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f9fafb;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.qg-msg {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.qg-msg.user {
  align-self: flex-end;
  background: #4f46e5;
  color: #fff;
  border: 1px solid #4f46e5;
}

.qg-msg.bot {
  align-self: flex-start;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  color: #111827;
}

.qg-msg.bot code,
.qg-msg.user code {
  display: block;
  margin-top: 6px;
  font-size: 0.78rem;
}

.qg-msg-typing {
  align-self: flex-start;
  padding: 10px 12px;
  border-radius: 10px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  color: #6b7280;
  font-size: 0.85rem;
  font-style: italic;
}

.qg-chat-input {
  padding: 10px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  gap: 8px;
  background: #ffffff;
  flex-shrink: 0;
  padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
}

.qg-chat-input textarea {
  flex: 1;
  min-width: 0;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  color: #111827;
  padding: 8px 10px;
  font-size: max(0.95rem, 16px);
  font-family: inherit;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  line-height: 1.4;
}

.qg-chat-input textarea:focus {
  outline: none;
  border-color: #4f46e5;
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}

.qg-chat-send {
  background: #4f46e5;
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 0 14px;
  min-height: 40px;
  min-width: 64px;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.88rem;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  flex-shrink: 0;
}

.qg-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.qg-chat-send:hover:not(:disabled) {
  box-shadow: 0 0 12px rgba(79, 70, 229, 0.3);
}

.qg-chat-send:active:not(:disabled) {
  transform: scale(0.96);
}

.qg-chat-error {
  align-self: center;
  padding: 8px 12px;
  border-radius: 8px;
  background: #fef2f2;
  border: 1px solid #ef4444;
  color: #dc2626;
  font-size: 0.82rem;
  text-align: center;
  max-width: 90%;
}

/* =========================================================================
   Chatbot widget — responsive breakpoints
   ========================================================================= */

/* Mobile: panel becomes a full-screen sheet */
@media (max-width: 640px) {
  #qg-chat-fab {
    bottom: max(16px, env(safe-area-inset-bottom, 16px));
    right: max(16px, env(safe-area-inset-right, 16px));
  }

  #qg-chat-panel {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border-radius: 0;
    border: none;
    animation: qgSlideUp 0.3s forwards;
  }

  #qg-chat-panel.open {
    animation: qgSlideUp 0.3s forwards;
  }

  .qg-chat-header {
    padding: max(16px, env(safe-area-inset-top, 16px)) 16px 12px;
  }

  .qg-chat-input {
    padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
  }

  .qg-msg {
    max-width: 88%;
    font-size: 0.95rem;
  }

  .qg-chat-input textarea {
    font-size: 16px;
  }
}

/* Tablet: panel slightly larger */
@media (min-width: 641px) and (max-width: 1024px) {
  #qg-chat-panel {
    width: min(420px, calc(100vw - 32px));
    height: min(600px, calc(100dvh - 120px));
  }
}

/* Landscape phone: keep panel full-height, narrower */
@media (max-width: 900px) and (orientation: landscape) {
  #qg-chat-panel {
    height: 100dvh;
    border-radius: 0;
  }
}

/* Very small screens (<360px): tighter padding */
@media (max-width: 360px) {
  .qg-chat-header {
    padding: 10px 12px;
    font-size: 0.9rem;
  }

  .qg-chat-messages {
    padding: 8px;
  }

  .qg-chat-input {
    padding: 8px;
    gap: 6px;
  }

  .qg-chat-send {
    min-width: 56px;
    padding: 0 10px;
  }
}

/* Print: hide widget */
@media print {
  #qg-chat-fab,
  #qg-chat-panel,
  #qg-chat-backdrop {
    display: none !important;
  }
}

@keyframes qgSlideUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}
