/* ── Reset & Wrapper ─────────────────────────────────────── */
#jchat-wrapper *,
#jchat-wrapper *::before,
#jchat-wrapper *::after {
  box-sizing: border-box;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── Custom Properties ────────────────────────────────────── */
#jchat-wrapper {
  --jc-accent-1: #22d3ee;
  --jc-accent-2: #3b82f6;
  --jc-accent-3: #6366f1;
  --jc-surface-0: rgba(2, 6, 23, 0.97);
  --jc-surface-1: rgba(15, 23, 42, 0.94);
  --jc-surface-2: rgba(30, 41, 59, 0.80);
  --jc-surface-3: rgba(51, 65, 85, 0.50);
  --jc-text-primary: #f1f5f9;
  --jc-text-secondary: #94a3b8;
  --jc-text-muted: #475569;
  --jc-border: rgba(148, 163, 184, 0.14);
  --jc-border-hover: rgba(148, 163, 184, 0.28);
  --jc-glow: rgba(34, 211, 238, 0.15);
  --jc-radius: 20px;
  --jc-transition: cubic-bezier(0.22, 1, 0.36, 1);
  --jc-success: #22c55e;
  --jc-warning: #f59e0b;
}

/* ── Floating Bubble Button ───────────────────────────────── */
#jchat-bubble {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 62px;
  height: 62px;
  background: linear-gradient(135deg, var(--jc-accent-1) 0%, var(--jc-accent-2) 60%, var(--jc-accent-3) 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 99999;
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  margin: 0;
  padding: 0;
  box-shadow:
    0 14px 32px rgba(14, 116, 144, 0.35),
    0 4px 12px rgba(59, 130, 246, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transition:
    transform 0.35s var(--jc-transition),
    box-shadow 0.35s var(--jc-transition),
    filter 0.35s var(--jc-transition);
  animation: jchat-pulse-ring 3s ease-out infinite;
}

#jchat-bubble::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--jc-accent-1), var(--jc-accent-2));
  opacity: 0;
  z-index: -1;
  filter: blur(12px);
  transition: opacity 0.4s ease;
}

#jchat-bubble:hover::before { opacity: 0.5; }

#jchat-bubble:hover {
  transform: translateY(-3px) scale(1.08);
  filter: saturate(1.1) brightness(1.05);
}

#jchat-bubble:active {
  transform: scale(0.96);
  transition-duration: 0.1s;
}

@keyframes jchat-pulse-ring {
  0%   { box-shadow: 0 14px 32px rgba(14,116,144,0.35), 0 4px 12px rgba(59,130,246,0.3), 0 0 0 0 rgba(34,211,238,0.35); }
  70%  { box-shadow: 0 14px 32px rgba(14,116,144,0.35), 0 4px 12px rgba(59,130,246,0.3), 0 0 0 14px rgba(34,211,238,0); }
  100% { box-shadow: 0 14px 32px rgba(14,116,144,0.35), 0 4px 12px rgba(59,130,246,0.3), 0 0 0 0 rgba(34,211,238,0); }
}

#jchat-bubble svg {
  width: 26px;
  height: 26px;
  color: #ffffff;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
  transition: transform 0.3s var(--jc-transition);
  flex-shrink: 0;
}

#jchat-bubble:hover svg { transform: rotate(-8deg) scale(1.05); }

#jchat-bubble.jchat-hidden {
  opacity: 0;
  transform: scale(0.5) translateY(20px);
  pointer-events: none;
  transition: all 0.3s var(--jc-transition);
}

/* ── Chat Window ──────────────────────────────────────────── */
#jchat-window {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: min(410px, calc(100vw - 28px));
  height: min(620px, calc(100vh - 56px));
  background: var(--jc-surface-1);
  border: 1px solid var(--jc-border);
  border-radius: var(--jc-radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 99999;
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  box-shadow: 0 24px 60px rgba(0,0,0,0.55), 0 4px 20px rgba(0,0,0,0.35);
  opacity: 0;
  pointer-events: none;
  transform: translateY(24px) scale(0.95);
  transform-origin: bottom right;
  transition: opacity 0.35s var(--jc-transition), transform 0.35s var(--jc-transition);
}

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

#jchat-window::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 70%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--jc-accent-1) 30%, var(--jc-accent-2) 70%, transparent);
  opacity: 0.5;
  z-index: 1;
}

/* ── Header ───────────────────────────────────────────────── */
#jchat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 12px;
  margin: 0;
  background: linear-gradient(180deg, rgba(30,41,59,0.9) 0%, rgba(15,23,42,0.6) 100%);
  border-bottom: 1px solid var(--jc-border);
  border-radius: var(--jc-radius) var(--jc-radius) 0 0;
  flex-shrink: 0;
  position: relative;
}

#jchat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

#jchat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#jchat-header-avatar {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--jc-accent-1) 0%, var(--jc-accent-2) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid rgba(255,255,255,0.15);
  box-shadow: 0 4px 12px rgba(34,211,238,0.2);
  position: relative;
  flex-shrink: 0;
  padding: 0;
  margin: 0;
}

#jchat-header-avatar svg {
  width: 18px;
  height: 18px;
  color: #fff;
  flex-shrink: 0;
}

#jchat-header-avatar::after {
  content: '';
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 11px;
  height: 11px;
  background: #22c55e;
  border-radius: 50%;
  border: 2.5px solid rgba(15,23,42,0.95);
  animation: jchat-status-pulse 2s ease-in-out infinite;
}

@keyframes jchat-status-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.4); }
  50%      { box-shadow: 0 0 0 4px rgba(34,197,94,0); }
}

#jchat-header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

#jchat-header-title {
  color: var(--jc-text-primary);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.15px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  margin: 0;
  padding: 0;
}

#jchat-header-subtitle {
  color: #22c55e;
  font-size: 11px;
  font-weight: 500;
  display: block;
  margin: 0;
  padding: 0;
}

#jchat-close {
  width: 30px;
  height: 30px;
  min-width: 30px;
  background: var(--jc-surface-3);
  border: 1px solid var(--jc-border);
  border-radius: 8px;
  color: var(--jc-text-secondary);
  font-size: 15px;
  cursor: pointer;
  padding: 0;
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex-shrink: 0;
  transition: all 0.25s var(--jc-transition);
}

#jchat-close:hover {
  color: var(--jc-text-primary);
  background: rgba(239,68,68,0.15);
  border-color: rgba(239,68,68,0.3);
  transform: rotate(90deg);
}

#jchat-new {
  width: 30px;
  height: 30px;
  min-width: 30px;
  background: var(--jc-surface-3);
  border: 1px solid var(--jc-border);
  border-radius: 8px;
  color: var(--jc-text-secondary);
  cursor: pointer;
  padding: 0;
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.25s var(--jc-transition);
}

#jchat-new svg {
  width: 14px;
  height: 14px;
}

#jchat-new:hover {
  color: var(--jc-accent-1);
  background: rgba(34, 211, 238, 0.15);
  border-color: var(--jc-accent-1);
}

/* ── Messages Container ───────────────────────────────────── */
#jchat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 16px 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: rgba(51,65,85,0.6) transparent;
}

#jchat-messages::-webkit-scrollbar { width: 4px; }
#jchat-messages::-webkit-scrollbar-track { background: transparent; }
#jchat-messages::-webkit-scrollbar-thumb {
  background: rgba(51,65,85,0.5);
  border-radius: 10px;
}

/* ── Message Wrapper ──────────────────────────────────────── */
#jchat-messages .jchat-msg-wrapper {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 78%;
  width: auto;
  animation: jchat-fadein 0.25s ease;
}

#jchat-messages .jchat-user-wrapper {
  align-self: flex-end;
  align-items: flex-end;
}

#jchat-messages .jchat-bot-wrapper {
  align-self: flex-start;
  align-items: flex-start;
}

/* ── Message Meta (time + copy) ───────────────────────────── */
#jchat-messages .jchat-msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

#jchat-messages .jchat-msg-wrapper:hover .jchat-msg-meta,
#jchat-messages .jchat-msg-wrapper:focus-within .jchat-msg-meta {
  opacity: 1;
}

#jchat-messages .jchat-msg-time {
  font-size: 10px;
  color: var(--jc-text-muted);
  font-weight: 500;
}

#jchat-messages .jchat-copy-btn {
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  color: var(--jc-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s ease;
}

#jchat-messages .jchat-copy-btn:hover {
  color: var(--jc-accent-1);
  background: rgba(34, 211, 238, 0.1);
}

#jchat-messages .jchat-copy-btn.jchat-copied {
  color: var(--jc-success);
}

#jchat-messages .jchat-copy-btn.jchat-copy-failed {
  color: var(--jc-warning);
}

/* ── Message Bubbles ──────────────────────────────────────── */
#jchat-messages .jchat-msg {
  max-width: 100%;
  width: auto;
  padding: 11px 15px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.65;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  border: 1px solid transparent;
  flex-shrink: 0;
  margin: 0;
}

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

/* BOT — left */
#jchat-messages .jchat-bot {
  background: rgba(51, 65, 85, 0.50);
  color: #e2e8f0;
  border-bottom-left-radius: 5px;
  border-color: rgba(148,163,184,0.18);
}

/* USER — right */
#jchat-messages .jchat-user {
  background: linear-gradient(135deg, var(--jc-accent-1) 0%, var(--jc-accent-2) 60%, var(--jc-accent-3) 100%);
  color: #ffffff;
  border-bottom-right-radius: 5px;
  border-color: rgba(147,197,253,0.3);
  font-weight: 500;
  box-shadow: 0 4px 14px rgba(14,116,144,0.25);
  text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* ── Markdown Styles in Messages ──────────────────────────── */
#jchat-messages .jchat-bot strong {
  font-weight: 600;
  color: var(--jc-text-primary);
}

#jchat-messages .jchat-bot em {
  font-style: italic;
}

#jchat-messages .jchat-bot .jchat-inline-code {
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  color: var(--jc-accent-1);
}

#jchat-messages .jchat-bot .jchat-code-block {
  background: rgba(0, 0, 0, 0.4);
  padding: 10px 12px;
  border-radius: 8px;
  margin: 8px 0;
  overflow-x: auto;
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.5;
  border: 1px solid rgba(148, 163, 184, 0.15);
}

#jchat-messages .jchat-bot .jchat-code-block code {
  color: var(--jc-text-primary);
}

#jchat-messages .jchat-bot .jchat-link {
  color: var(--jc-accent-1);
  text-decoration: none;
  border-bottom: 1px dotted var(--jc-accent-1);
  transition: all 0.2s ease;
}

#jchat-messages .jchat-bot .jchat-link:hover {
  color: var(--jc-accent-2);
  border-bottom-color: var(--jc-accent-2);
}

#jchat-messages .jchat-bot .jchat-list {
  margin: 8px 0;
  padding-left: 18px;
  list-style: none;
}

#jchat-messages .jchat-bot .jchat-list li {
  position: relative;
  margin: 4px 0;
  padding-left: 4px;
}

#jchat-messages .jchat-bot .jchat-list li::before {
  content: '→';
  position: absolute;
  left: -16px;
  color: var(--jc-accent-1);
  font-size: 11px;
}

#jchat-messages .jchat-bot + .jchat-bot   { border-top-left-radius: 5px;  margin-top: -4px; }
#jchat-messages .jchat-user + .jchat-user  { border-top-right-radius: 5px; margin-top: -4px; }

/* ── Typing Indicator ─────────────────────────────────────── */
#jchat-messages .jchat-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 13px 16px;
  align-self: flex-start;
  background: rgba(51,65,85,0.50);
  border-radius: 14px;
  border-bottom-left-radius: 5px;
  border: 1px solid rgba(148,163,184,0.18);
  width: auto;
  min-width: 64px;
  max-width: 80px;
  margin: 0;
}

#jchat-messages .jchat-typing span {
  width: 7px;
  height: 7px;
  min-width: 7px;
  background: var(--jc-accent-1);
  border-radius: 50%;
  animation: jchat-bounce 1.2s infinite ease-in-out;
  box-shadow: 0 0 6px rgba(34,211,238,0.3);
  display: block;
  padding: 0;
  margin: 0;
}

#jchat-messages .jchat-typing span:nth-child(1) { animation-delay: 0s; }
#jchat-messages .jchat-typing span:nth-child(2) { animation-delay: 0.2s; }
#jchat-messages .jchat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes jchat-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%           { transform: scale(1);   opacity: 1; }
}

/* ── Suggestions Container ────────────────────────────────── */
#jchat-suggestions {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 14px 12px;
  background: transparent;
  border-top: 1px solid var(--jc-border);
}

#jchat-suggestions:empty {
  display: none;
}

.jchat-suggestion-chip {
  background: var(--jc-surface-2);
  border: 1px solid var(--jc-border);
  border-radius: 16px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--jc-text-secondary);
  cursor: pointer;
  transition: all 0.2s var(--jc-transition);
  white-space: nowrap;
  flex-shrink: 0;
}

.jchat-suggestion-chip:hover {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.15) 0%, rgba(59, 130, 246, 0.15) 100%);
  border-color: var(--jc-accent-1);
  color: var(--jc-accent-1);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(34, 211, 238, 0.15);
}

.jchat-suggestion-chip:active {
  transform: scale(0.97);
}

/* ── Input Area ───────────────────────────────────────────── */
#jchat-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  margin: 0;
  border-top: 1px solid var(--jc-border);
  background: var(--jc-surface-0);
  border-radius: 0 0 var(--jc-radius) var(--jc-radius);
  flex-shrink: 0;
  position: relative;
}

#jchat-input-area::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 16px;
  right: 16px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(34,211,238,0.15), rgba(59,130,246,0.15), transparent);
}

#jchat-input {
  flex: 1;
  min-width: 0;
  background: var(--jc-surface-2);
  border: 1.5px solid var(--jc-border);
  border-radius: 10px;
  color: var(--jc-text-primary);
  font-size: 13px;
  font-family: inherit;
  padding: 10px 13px;
  margin: 0;
  outline: none;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

#jchat-input:hover  { border-color: var(--jc-border-hover); }
#jchat-input:focus  {
  border-color: var(--jc-accent-1);
  background: rgba(30,41,59,0.95);
  box-shadow: 0 0 0 3px var(--jc-glow);
}
#jchat-input::placeholder { color: var(--jc-text-muted); }
#jchat-input:disabled { opacity: 0.45; cursor: not-allowed; }

#jchat-send {
  width: 40px;
  height: 40px;
  min-width: 40px;
  background: linear-gradient(135deg, var(--jc-accent-1) 0%, var(--jc-accent-2) 60%, var(--jc-accent-3) 100%);
  border: 1.5px solid rgba(255,255,255,0.2);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  margin: 0;
  box-shadow: 0 6px 18px rgba(14,116,144,0.3);
  transition: all 0.25s var(--jc-transition);
  overflow: hidden;
  position: relative;
}

#jchat-send::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(45deg, transparent 30%, rgba(255,255,255,0.12) 50%, transparent 70%);
  transform: translateX(-100%);
  transition: transform 0.5s;
}

#jchat-send:hover::before  { transform: translateX(100%); }
#jchat-send:hover          { transform: translateY(-2px) scale(1.05); box-shadow: 0 10px 24px rgba(14,116,144,0.4); }
#jchat-send:active         { transform: scale(0.93); transition-duration: 0.1s; }
#jchat-send:disabled       { opacity: 0.35; cursor: not-allowed; transform: none; box-shadow: none; }
#jchat-send:disabled::before { display: none; }

#jchat-send svg {
  width: 16px;
  height: 16px;
  color: #ffffff;
  flex-shrink: 0;
  transition: transform 0.25s var(--jc-transition);
}

#jchat-send:hover svg { transform: translateX(1px); }

/* ── Reduced Motion ───────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #jchat-bubble,
  #jchat-window,
  #jchat-messages .jchat-msg,
  #jchat-messages .jchat-typing span {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  #jchat-bubble { animation: none; }
  #jchat-header-avatar::after { animation: none; }
}

/* ── Mobile ───────────────────────────────────────────────── */
@media (max-width: 480px) {
  #jchat-window {
    width: 100vw;
    height: 72vh;
    bottom: 0;
    right: 0;
    border-radius: 18px 18px 0 0;
    transform-origin: bottom center;
  }
  #jchat-window.jchat-open { border-radius: 18px 18px 0 0; }
  #jchat-bubble { bottom: 20px; right: 20px; width: 56px; height: 56px; }
  #jchat-header { border-radius: 18px 18px 0 0; padding-top: max(14px, env(safe-area-inset-top)); }
  #jchat-input-area { border-radius: 0; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  #jchat-messages .jchat-msg { max-width: 100%; font-size: 14px; }
  #jchat-messages .jchat-msg-wrapper { max-width: 88%; }
  #jchat-messages { padding: 14px 13px 8px; }
  #jchat-suggestions { padding: 6px 12px 10px; gap: 6px; }
  .jchat-suggestion-chip { font-size: 11px; padding: 5px 12px; }
}

/* ── Tablet ───────────────────────────────────────────────── */
@media (min-width: 481px) and (max-width: 768px) {
  #jchat-window {
    width: min(400px, calc(100vw - 32px));
    height: min(580px, calc(100vh - 56px));
  }
}