/* ================================================================
   NexusAI Chat Widget — Scoped CSS
   All rules prefixed with .nexus-wrap to avoid theme conflicts
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=DM+Sans:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

/* ---- CSS Variables ---- */
.nexus-wrap {
  --na: var(--nexus-accent, #3ecf8e);
  --na2: color-mix(in srgb, var(--na) 80%, #000);
  --na-dim: color-mix(in srgb, var(--na) 12%, transparent);
  --na-glow: color-mix(in srgb, var(--na) 6%, transparent);
  --radius: 14px;
  --sans: 'DM Sans', system-ui, sans-serif;
  --serif: 'Instrument Serif', Georgia, serif;
  --mono: 'JetBrains Mono', 'Courier New', monospace;
  --ease: cubic-bezier(.4,0,.2,1);
}

/* ---- Dark theme (default) ---- */
.nexus-wrap.nexus-theme-dark {
  --bg:     #0e100f;
  --bg2:    #141714;
  --bg3:    #1c1f1d;
  --border: #252925;
  --bd2:    #2e332e;
  --text:   #e6ebe7;
  --text2:  #95a096;
  --text3:  #576058;
  --danger: #e05252;
  --warn:   #e8a84a;
}

/* ---- Light theme ---- */
.nexus-wrap.nexus-theme-light {
  --bg:     #f8faf9;
  --bg2:    #ffffff;
  --bg3:    #f0f4f1;
  --border: #dde4de;
  --bd2:    #c8d4c9;
  --text:   #111b12;
  --text2:  #4a5e4b;
  --text3:  #7a9a7b;
  --danger: #dc2626;
  --warn:   #d97706;
}

/* ================================================================
   WIDGET SHELL
   ================================================================ */
.nexus-wrap {
  display: flex;
  flex-direction: column;
  height: var(--nexus-height, 520px);
  min-height: 320px;
  max-height: 90vh;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  box-shadow: 0 4px 24px rgba(0,0,0,.12), 0 1px 4px rgba(0,0,0,.08);
  position: relative;
  -webkit-font-smoothing: antialiased;
}

/* ================================================================
   HEADER
   ================================================================ */
.nexus-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.nexus-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nexus-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--na);
  box-shadow: 0 0 8px color-mix(in srgb, var(--na) 60%, transparent);
  flex-shrink: 0;
}

.nexus-title {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--text);
  letter-spacing: -.2px;
}

.nexus-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nexus-pro-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--na-dim);
  border: 1px solid color-mix(in srgb, var(--na) 25%, transparent);
  color: var(--na);
  text-decoration: none;
  letter-spacing: .04em;
  transition: background .2s;
}
.nexus-pro-badge:hover { background: color-mix(in srgb, var(--na) 20%, transparent); }
.nexus-pro-badge.nexus-pro-active { cursor: default; }

.nexus-btn-clear {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color .15s, background .15s;
}
.nexus-btn-clear:hover { color: var(--text); background: var(--bg3); }

/* ================================================================
   MESSAGES AREA
   ================================================================ */
.nexus-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

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

/* Welcome state */
.nexus-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 24px 16px;
  min-height: 120px;
}

.nexus-welcome-icon {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #1e4d37 0%, #0f2a1f 100%);
  border: 1px solid color-mix(in srgb, var(--na) 20%, transparent);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  color: var(--na);
}
.nexus-theme-light .nexus-welcome-icon {
  background: linear-gradient(135deg, #d4f5e7 0%, #a8eacd 100%);
}

.nexus-welcome-text {
  font-size: 15px;
  color: var(--text2);
  margin: 0;
  line-height: 1.5;
}

/* ---- Message rows ---- */
.nexus-msg {
  display: flex;
  gap: 10px;
  animation: nexusFadeUp .25s var(--ease) both;
}

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

.nexus-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  margin-top: 1px;
}

.nexus-msg.nexus-user .nexus-msg-avatar {
  background: linear-gradient(135deg, #2bb07a, #1a6b4a);
  color: #fff;
}

.nexus-msg.nexus-assistant .nexus-msg-avatar {
  background: linear-gradient(135deg, #1e3d2f, #0f2a1f);
  border: 1px solid color-mix(in srgb, var(--na) 25%, transparent);
  color: var(--na);
}
.nexus-theme-light .nexus-msg.nexus-assistant .nexus-msg-avatar {
  background: linear-gradient(135deg, #d4f5e7, #a8eacd);
  border-color: color-mix(in srgb, var(--na) 30%, transparent);
}

.nexus-msg-body { flex: 1; min-width: 0; }

.nexus-msg-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 4px;
}
.nexus-msg.nexus-assistant .nexus-msg-name {
  color: var(--na);
  opacity: .75;
}

.nexus-msg-content {
  font-size: 14px;
  color: var(--text);
  line-height: 1.75;
  word-break: break-word;
}

/* Markdown inside messages */
.nexus-msg-content p { margin: 0 0 .7em; }
.nexus-msg-content p:last-child { margin-bottom: 0; }
.nexus-msg-content h1,.nexus-msg-content h2,.nexus-msg-content h3 {
  font-family: var(--serif);
  font-weight: normal;
  color: var(--text);
  margin: 1em 0 .4em;
  line-height: 1.3;
}
.nexus-msg-content h1 { font-size: 20px; }
.nexus-msg-content h2 { font-size: 17px; }
.nexus-msg-content h3 { font-size: 15px; }
.nexus-msg-content ul,.nexus-msg-content ol { padding-left: 1.3em; margin-bottom: .7em; }
.nexus-msg-content li { margin-bottom: .2em; }
.nexus-msg-content strong { font-weight: 600; }
.nexus-msg-content em { font-style: italic; color: var(--text2); }
.nexus-msg-content a { color: var(--na); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--na) 40%, transparent); }
.nexus-msg-content blockquote { border-left: 3px solid var(--bd2); padding: 6px 14px; margin: .7em 0; color: var(--text2); font-style: italic; }
.nexus-msg-content hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }

/* Tables */
.nexus-msg-content table { width: 100%; border-collapse: collapse; margin-bottom: .7em; font-size: 13px; }
.nexus-msg-content th { background: var(--bg3); padding: 6px 10px; text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .05em; color: var(--text3); text-transform: uppercase; border-bottom: 1px solid var(--bd2); }
.nexus-msg-content td { padding: 6px 10px; border-bottom: 1px solid var(--border); }

/* Inline code */
.nexus-msg-content code:not(pre code) {
  font-family: var(--mono);
  font-size: .85em;
  background: var(--bg3);
  border: 1px solid var(--bd2);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--na);
}

/* Code blocks */
.nexus-msg-content pre {
  background: #0d1117 !important;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  margin: .7em 0;
  font-size: 12px;
}
.nexus-theme-light .nexus-msg-content pre { background: #f6f8fa !important; }

.nexus-code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
}
.nexus-code-lang { font-family: var(--mono); font-size: 10px; font-weight: 600; color: var(--text3); letter-spacing: .08em; text-transform: uppercase; }
.nexus-code-copy { font-size: 11px; font-family: var(--sans); font-weight: 600; padding: 2px 9px; background: var(--bg); border: 1px solid var(--bd2); border-radius: 4px; color: var(--text3); cursor: pointer; transition: all .15s; }
.nexus-code-copy:hover { color: var(--text); }
.nexus-code-copy.copied { color: var(--na); border-color: color-mix(in srgb, var(--na) 30%, transparent); }

.nexus-msg-content pre code { display: block; padding: 12px 14px; overflow-x: auto; font-family: var(--mono); line-height: 1.6; background: transparent !important; }

/* Typing cursor */
.nexus-cursor {
  display: inline-block;
  width: 2px;
  height: .9em;
  background: var(--na);
  margin-left: 1px;
  vertical-align: text-bottom;
  animation: nexusBlink .8s step-end infinite;
}
@keyframes nexusBlink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

/* ================================================================
   USAGE BAR
   ================================================================ */
.nexus-usage-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.nexus-usage-track {
  flex: 1;
  height: 3px;
  background: var(--bg3);
  border-radius: 2px;
  overflow: hidden;
}

.nexus-usage-fill {
  height: 100%;
  background: var(--na);
  border-radius: 2px;
  transition: width .5s var(--ease);
}
.nexus-usage-fill.warn { background: var(--warn); }
.nexus-usage-fill.danger { background: var(--danger); }

.nexus-usage-label {
  font-size: 11px;
  color: var(--text3);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ================================================================
   INPUT AREA
   ================================================================ */
.nexus-input-area {
  padding: 10px 12px 12px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.nexus-input-box {
  display: flex;
  gap: 8px;
  background: var(--bg3);
  border: 1px solid var(--bd2);
  border-radius: 10px;
  padding: 8px 8px 8px 13px;
  align-items: flex-end;
  transition: border-color .2s, box-shadow .2s;
}
.nexus-input-box:focus-within {
  border-color: color-mix(in srgb, var(--na) 40%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--na) 8%, transparent);
}

.nexus-textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  resize: none;
  min-height: 22px;
  max-height: 140px;
  overflow-y: auto;
  padding: 1px 0;
}
.nexus-textarea::placeholder { color: var(--text3); }

.nexus-send-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--na);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #0d1a14;
  transition: background .2s, transform .15s;
}
.nexus-send-btn:hover { background: var(--na2); transform: scale(1.06); }
.nexus-send-btn:disabled { background: var(--bg3); cursor: not-allowed; transform: none; opacity: .5; }

.nexus-hint {
  font-size: 10px;
  color: var(--text3);
  margin: 5px 2px 0;
  line-height: 1;
}

/* Limit message */
.nexus-limit-msg {
  text-align: center;
  padding: 12px;
  font-size: 13px;
  color: var(--warn);
  line-height: 1.5;
}
.nexus-limit-msg a {
  display: inline-block;
  margin-top: 6px;
  padding: 7px 16px;
  background: var(--na);
  color: #0d1a14;
  border-radius: 7px;
  font-weight: 700;
  font-size: 13px;
  text-decoration: none;
  transition: background .2s;
}
.nexus-limit-msg a:hover { background: var(--na2); }

/* ================================================================
   LOGIN PROMPT
   ================================================================ */
.nexus-login-prompt p { margin: 0; }
