/**
 * Document Chatbot — chatbot.css
 * Version: 1.0.0
 *
 * Uses WordPress/theme CSS custom properties wherever possible so the
 * chatbot inherits the active theme's colors automatically.
 *
 * Theme compatibility:
 *   --wp--preset--color--* variables are standard in block themes (Twenty Twenty-*).
 *   Fallback values ensure the widget looks good even without a block theme.
 *
 * To fully match your theme: override any variable in your theme's
 * Additional CSS (Appearance → Customize → Additional CSS).
 *
 * Example override:
 *   .docchat-wrap { --dc-accent: #your-brand-color; }
 */

/* ── Design tokens ─────────────────────────────────────────────────────────── */

.docchat-wrap {
  /* Accent — tries theme primary color, falls back to a neutral blue */
  --dc-accent:       var(--wp--preset--color--primary,       #4f8ef7);
  --dc-accent-hover: var(--wp--preset--color--primary-light, #6ba3ff);

  /* Surfaces */
  --dc-header-bg:    var(--wp--preset--color--contrast,      #1a1d27);
  --dc-header-text:  var(--wp--preset--color--base,          #ffffff);
  --dc-body-bg:      var(--wp--preset--color--base,          #f9f9fb);
  --dc-input-bg:     var(--wp--preset--color--base,          #ffffff);
  --dc-border:       var(--wp--preset--color--contrast-2,    #e0e0e0);

  /* Message bubbles */
  --dc-user-bg:      #e8f0fe;
  --dc-user-border:  #c5d8fc;
  --dc-ai-bg:        #ffffff;
  --dc-ai-border:    var(--dc-border);

  /* Text */
  --dc-text:         var(--wp--preset--color--contrast,      #1a1d27);
  --dc-text-dim:     #555;
  --dc-text-muted:   #888;

  /* Status colors */
  --dc-success:      #3ecf8e;
  --dc-error:        #e05c5c;
  --dc-warning:      #f59e0b;

  /* Typography — tries theme font stack */
  --dc-font:         var(--wp--preset--font-family--body,
                     -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
  --dc-font-mono:    var(--wp--preset--font-family--mono,
                     "SFMono-Regular", Consolas, monospace);
  --dc-font-size:    var(--wp--preset--font-size--medium,    16px);

  /* Layout */
  --dc-radius:       10px;
  --dc-radius-sm:    6px;
}

/* ── Wrapper ───────────────────────────────────────────────────────────────── */

.docchat-wrap {
  border: 1px solid var(--dc-border);
  border-radius: var(--dc-radius);
  overflow: hidden;
  font-family: var(--dc-font);
  font-size: var(--dc-font-size);
  margin: 1.5em 0;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
}

/* ── Header ────────────────────────────────────────────────────────────────── */

.docchat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--dc-header-bg);
  color: var(--dc-header-text);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.docchat-icon {
  font-size: 18px;
  line-height: 1;
}

.docchat-title {
  font-weight: 600;
  flex: 1;
  font-size: 14px;
  letter-spacing: -0.01em;
}

.docchat-status {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  transition: color 0.2s;
}

.docchat-status[data-state="ready"]     { color: var(--dc-success); }
.docchat-status[data-state="thinking"]  { color: var(--dc-accent);  }
.docchat-status[data-state="error"]     { color: var(--dc-error);   }
.docchat-status[data-state="connecting"]{ color: rgba(255,255,255,0.5); }

/* ── Message area ──────────────────────────────────────────────────────────── */

.docchat-messages {
  overflow-y: auto;
  padding: 16px;
  background: var(--dc-body-bg);
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}

.docchat-init-msg {
  text-align: center;
  color: var(--dc-text-muted);
  padding: 20px;
  font-size: var(--dc-font-size);
}

/* ── Individual messages ───────────────────────────────────────────────────── */

.docchat-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: dcFadeIn 0.18s ease;
}

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

.docchat-role {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0 4px;
  color: var(--dc-text-muted);
}

.docchat-user .docchat-role     { color: var(--dc-accent); }
.docchat-assistant .docchat-role { color: var(--dc-success); }
.docchat-error .docchat-role    { color: var(--dc-error);   }

.docchat-bubble {
  padding: 10px 14px;
  border-radius: var(--dc-radius-sm);
  line-height: 1.65;
  font-size: var(--dc-font-size);
  color: var(--dc-text);
  max-width: 92%;
  word-wrap: break-word;
}

.docchat-user .docchat-bubble {
  background: var(--dc-user-bg);
  border: 1px solid var(--dc-user-border);
  align-self: flex-end;
}

.docchat-assistant .docchat-bubble {
  background: var(--dc-ai-bg);
  border: 1px solid var(--dc-ai-border);
}

.docchat-error .docchat-bubble {
  background: rgba(224, 92, 92, 0.08);
  border: 1px solid rgba(224, 92, 92, 0.25);
  color: var(--dc-error);
}

/* Inline formatting */
.docchat-bubble strong { font-weight: 600; }
.docchat-bubble em     { font-style: italic; color: var(--dc-text-dim); }

.docchat-bubble code {
  font-family: var(--dc-font-mono);
  font-size: 12px;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
}

/* Block formatting — headings, lists, code blocks, paragraphs */
.docchat-bubble p:first-child { margin-top: 0; }
.docchat-bubble p:last-child  { margin-bottom: 0; }
.docchat-bubble p             { margin: 0.5em 0; }

.docchat-bubble h2,
.docchat-bubble h3,
.docchat-bubble h4 {
  font-weight: 600;
  line-height: 1.3;
  margin: 0.8em 0 0.4em;
}
.docchat-bubble h2 { font-size: 1.15em; }
.docchat-bubble h3 { font-size: 1.05em; }
.docchat-bubble h4 { font-size: 1em; color: var(--dc-text-dim); }
.docchat-bubble h2:first-child,
.docchat-bubble h3:first-child,
.docchat-bubble h4:first-child { margin-top: 0; }

.docchat-bubble ul,
.docchat-bubble ol {
  margin: 0.5em 0;
  padding-left: 1.5em;
}
.docchat-bubble li {
  margin: 0.2em 0;
  line-height: 1.55;
}

/* Nested sub-lists (genuine 2-level outlines, e.g. a bolded "By type"
   bullet with indented children beneath it in the source) — tighter
   vertical margin since they're already visually grouped under their
   parent item, and a hollow bullet to distinguish the level at a glance. */
.docchat-bubble li > ul,
.docchat-bubble li > ol {
  margin: 0.2em 0;
}
.docchat-bubble li > ul {
  list-style-type: circle;
}

.docchat-bubble pre {
  background: rgba(0, 0, 0, 0.06);
  padding: 10px 12px;
  border-radius: var(--dc-radius-sm);
  overflow-x: auto;
  margin: 0.6em 0;
  font-size: 12px;
  line-height: 1.45;
}
.docchat-bubble pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
  white-space: pre;
}

.docchat-error-inline { color: var(--dc-error); }

/* Streaming cursor */
.docchat-cursor {
  display: inline-block;
  animation: dcBlink 0.9s infinite;
  color: var(--dc-accent);
}

@keyframes dcBlink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Input area ────────────────────────────────────────────────────────────── */

.docchat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--dc-input-bg);
  border-top: 1px solid var(--dc-border);
  flex-shrink: 0;
}

.docchat-input {
  flex: 1;
  border: 1px solid var(--dc-border);
  border-radius: var(--dc-radius-sm);
  padding: 9px 12px;
  font-size: var(--dc-font-size);
  font-family: var(--dc-font);
  color: var(--dc-text);
  background: var(--dc-body-bg);
  resize: none;
  min-height: 40px;
  max-height: 120px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s;
  box-sizing: border-box;
}

.docchat-input:focus {
  border-color: var(--dc-accent);
  box-shadow: 0 0 0 2px rgba(79, 142, 247, 0.15);
}

.docchat-input::placeholder { color: var(--dc-text-muted); }
.docchat-input:disabled     { opacity: 0.5; cursor: not-allowed; }

.docchat-send {
  background: var(--dc-accent);
  color: #fff;
  border: none;
  border-radius: var(--dc-radius-sm);
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--dc-font);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
  align-self: flex-end;
}

.docchat-send:hover:not(:disabled) {
  background: var(--dc-accent-hover);
  transform: translateY(-1px);
}

.docchat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ── Footer ────────────────────────────────────────────────────────────────── */

.docchat-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 16px;
  background: var(--dc-input-bg);
  border-top: 1px solid var(--dc-border);
  flex-shrink: 0;
}

.docchat-powered {
  font-size: 10px;
  color: var(--dc-text-muted);
}

.docchat-clear {
  font-size: var(--dc-font-size);
  color: var(--dc-text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--dc-font);
  transition: color 0.15s, background 0.15s;
}

.docchat-clear:hover {
  color: var(--dc-text);
  background: var(--dc-border);
}

/* ── Admin notices (visible to admins only) ────────────────────────────────── */

.docchat-admin-notice {
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: var(--dc-radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  margin: 1em 0;
}

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */

.docchat-messages::-webkit-scrollbar       { width: 5px; }
.docchat-messages::-webkit-scrollbar-track { background: transparent; }
.docchat-messages::-webkit-scrollbar-thumb {
  background: var(--dc-border);
  border-radius: 3px;
}

/* ── Screen reader only ────────────────────────────────────────────────────── */

.screen-reader-text {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  .docchat-send { padding: 9px 12px; }
  .docchat-bubble { max-width: 100%; }
}
