/* ============================================================
   NLQueries Chat Widget — chat.css
   All classes prefixed nlq- to avoid global conflicts.
   ============================================================ */

:root {
  --nlq-accent:         #166534;
  --nlq-accent-hover:   #14532d;
  --nlq-bubble-bg:      #6b7280;
  --nlq-bubble-border:  #166534;
  --nlq-bg:             #ffffff;
  --nlq-surface:        #f3f4f6;
  --nlq-border:         #e5e7eb;
  --nlq-text:           #111827;
  --nlq-text-muted:     #6b7280;
  --nlq-user-bg:        #166534;
  --nlq-user-text:      #ffffff;
  --nlq-assistant-bg:   #ffffff;
  --nlq-assistant-text: #111827;
  --nlq-error-bg:       #fef2f2;
  --nlq-error-text:     #b91c1c;
  --nlq-badge-bg:       #d1fae5;
  --nlq-badge-text:     #065f46;
  --nlq-shadow:         0 8px 32px rgba(0, 0, 0, 0.14);
  --nlq-radius:         16px;
  --nlq-radius-sm:      8px;
  --nlq-font:           -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --nlq-mono:           "JetBrains Mono", "Menlo", "Monaco", "Consolas", monospace;
}

/* ── Container ─────────────────────────────────────────────── */
.nlq-container {
  position: fixed;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  font-family: var(--nlq-font);
}
.nlq-pos-bottom-right { bottom: 24px; right: 24px; }
.nlq-pos-bottom-left  { bottom: 24px; left: 24px; align-items: flex-start; }

/* ── Bubble button ─────────────────────────────────────────── */
.nlq-bubble {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--nlq-bubble-bg);
  color: #ffffff;
  border: 2.5px solid var(--nlq-bubble-border);
  cursor: pointer;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.22);
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  outline: none;
  flex-shrink: 0;
}
.nlq-bubble:hover {
  background: #4b5563;
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(0,0,0,0.28);
}
.nlq-bubble:focus-visible {
  outline: 2px solid var(--nlq-bubble-border);
  outline-offset: 3px;
}

/* ── Panel ─────────────────────────────────────────────────── */
.nlq-panel {
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 540px;
  max-height: calc(100vh - 100px);
  min-height: 320px;
  background: var(--nlq-bg);
  border: 1px solid var(--nlq-border);
  border-radius: var(--nlq-radius);
  box-shadow: var(--nlq-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: nlq-slide-up 0.2s ease;
}
@keyframes nlq-slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.nlq-hidden { display: none !important; }

/* ── Resize handle ─────────────────────────────────────────── */
.nlq-resize-handle {
  height: 22px;
  cursor: ns-resize;
  background: transparent;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  user-select: none;
  touch-action: none;
}
.nlq-resize-handle::before,
.nlq-resize-handle::after {
  content: "";
  width: 36px;
  height: 3px;
  background: #d1d5db;
  border-radius: 2px;
  transition: background 0.2s, transform 0.15s;
}
.nlq-resize-handle:hover::before,
.nlq-resize-handle:hover::after { background: #166534; }

/* ── Header ────────────────────────────────────────────────── */
.nlq-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, #374151 0%, #166534 100%);
  color: #ffffff;
  flex-shrink: 0;
}
.nlq-header-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.nlq-header-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
  margin-right: 8px;
  box-shadow: 0 0 0 2px rgba(74,222,128,0.3);
}
.nlq-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  font-size: 16px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--nlq-radius-sm);
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.nlq-close:hover { background: rgba(255,255,255,0.15); color: #fff; }

/* ── Messages ──────────────────────────────────────────────── */
.nlq-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--nlq-surface);
  scroll-behavior: smooth;
}
.nlq-messages::-webkit-scrollbar       { width: 4px; }
.nlq-messages::-webkit-scrollbar-track { background: transparent; }
.nlq-messages::-webkit-scrollbar-thumb { background: var(--nlq-border); border-radius: 2px; }

/* ── Message bubbles ───────────────────────────────────────── */
.nlq-msg {
  max-width: 92%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.6;
  word-break: break-word;
  overflow-wrap: break-word;
}
.nlq-msg-user {
  align-self: flex-end;
  background: var(--nlq-user-bg);
  color: var(--nlq-user-text);
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.nlq-msg-assistant {
  align-self: flex-start;
  background: var(--nlq-assistant-bg);
  color: var(--nlq-assistant-text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.07);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.nlq-msg-error {
  background: var(--nlq-error-bg);
  color: var(--nlq-error-text);
}

/* ── Assistant content elements ─────────────────────────────── */
.nlq-msg-assistant .nlq-p {
  margin: 0 0 4px;
  line-height: 1.6;
}
.nlq-msg-assistant .nlq-spacer { height: 6px; }

/* Headings */
.nlq-msg-assistant .nlq-heading {
  font-weight: 700;
  color: var(--nlq-text);
  margin: 8px 0 4px;
  padding-bottom: 4px;
  line-height: 1.3;
}
.nlq-msg-assistant .nlq-h1 {
  font-size: 15px;
  border-bottom: 2px solid #166534;
}
.nlq-msg-assistant .nlq-h2 {
  font-size: 14px;
  border-bottom: 1px solid var(--nlq-border);
}
.nlq-msg-assistant .nlq-h3 {
  font-size: 13.5px;
  color: #374151;
}

/* Lists */
.nlq-msg-assistant .nlq-ul,
.nlq-msg-assistant .nlq-ol {
  margin: 4px 0 6px 16px;
  padding: 0;
}
.nlq-msg-assistant .nlq-ul li,
.nlq-msg-assistant .nlq-ol li {
  margin: 2px 0;
  line-height: 1.55;
}

/* Tables */
.nlq-msg-assistant .nlq-table-wrap {
  overflow-x: auto;
  margin: 8px 0;
  border-radius: 6px;
  border: 1px solid var(--nlq-border);
}
.nlq-msg-assistant .nlq-table {
  border-collapse: collapse;
  font-size: 12px;
  width: 100%;
  min-width: 200px;
}
.nlq-msg-assistant .nlq-table th,
.nlq-msg-assistant .nlq-table td {
  border: 1px solid var(--nlq-border);
  padding: 5px 10px;
  text-align: left;
  white-space: nowrap;
}
.nlq-msg-assistant .nlq-table th {
  background: #e5e7eb;
  font-weight: 600;
  color: #1f2937;
}
.nlq-msg-assistant .nlq-table tr:nth-child(even) td {
  background: #f9fafb;
}

/* ── Inline code ───────────────────────────────────────────── */
.nlq-msg-assistant .nlq-inline-code {
  font-family: var(--nlq-mono);
  font-size: 12px;
  background: #e8f5e9;
  color: #166534;
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid #c8e6c9;
}

/* ── Code blocks ───────────────────────────────────────────── */
.nlq-code-block {
  background: #1e2b22;
  border-radius: 8px;
  margin: 8px 0;
  overflow: hidden;
  border: 1px solid #2d4a38;
  font-size: 0;
}
.nlq-code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 12px;
  background: #253322;
  border-bottom: 1px solid #2d4a38;
}
.nlq-code-lang {
  font-family: var(--nlq-mono);
  font-size: 11px;
  color: #86efac;
  text-transform: lowercase;
  letter-spacing: 0.03em;
}
.nlq-copy-code-btn {
  background: none;
  border: 1px solid #3d6b4a;
  border-radius: 4px;
  color: #86efac;
  font-size: 11px;
  font-family: var(--nlq-font);
  padding: 2px 9px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  line-height: 1.6;
}
.nlq-copy-code-btn:hover  { background: #2d4a38; color: #fff; }
.nlq-copy-code-btn.copied { color: #4ade80; border-color: #4ade80; }
.nlq-code-block pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 13px;
}
.nlq-code-block code {
  font-family: var(--nlq-mono);
  font-size: 13px;
  color: #d1fae5;
  line-height: 1.65;
  white-space: pre;
}

/* ── Typing cursor ─────────────────────────────────────────── */
.nlq-cursor {
  display: inline-block;
  animation: nlq-blink 0.8s step-end infinite;
  color: var(--nlq-accent);
  font-size: 12px;
  vertical-align: middle;
  margin-left: 1px;
}
@keyframes nlq-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Cached badge ──────────────────────────────────────────── */
.nlq-cached-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: var(--nlq-badge-bg);
  color: var(--nlq-badge-text);
  border-radius: 100px;
  vertical-align: middle;
}

/* ── Input area ────────────────────────────────────────────── */
.nlq-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px 14px;
  border-top: 1px solid var(--nlq-border);
  background: var(--nlq-bg);
  flex-shrink: 0;
}
.nlq-textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--nlq-border);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 14px;
  font-family: var(--nlq-font);
  line-height: 1.4;
  outline: none;
  background: var(--nlq-surface);
  color: var(--nlq-text);
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.2s;
}
.nlq-textarea::placeholder { color: var(--nlq-text-muted); }
.nlq-textarea:focus         { border-color: var(--nlq-accent); }
.nlq-textarea:disabled      { opacity: 0.5; cursor: not-allowed; }

/* ── Send button ───────────────────────────────────────────── */
.nlq-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--nlq-accent);
  color: #ffffff;
  border: none;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
  outline: none;
}
.nlq-send:hover:not(:disabled) { background: var(--nlq-accent-hover); transform: scale(1.05); }
.nlq-send:focus-visible         { outline: 2px solid var(--nlq-accent); outline-offset: 2px; }
.nlq-send:disabled              { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ── Mobile ────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .nlq-container.nlq-pos-bottom-right,
  .nlq-container.nlq-pos-bottom-left {
    bottom: 16px; right: 12px; left: 12px; align-items: flex-end;
  }
  .nlq-panel {
    width: 100%; max-width: 100%;
    height: 75vh;
    border-radius: var(--nlq-radius) var(--nlq-radius) 0 0;
  }
  .nlq-resize-handle { display: none; }
}
