/* CSS Variables - scoped to chatbot container */
.atcb-container { --atc-primary:#1b365d; --atc-border:#e5e7eb; --atc-bg:#f7f8fa; --atc-text:#222; }
/* Isolated box-sizing only for chatbot elements */
.atcb-container, .atcb-container *, .atcb-container *::before, .atcb-container *::after { box-sizing:border-box; }

  .atcb-container { font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; color: var(--atc-text); }
  .atcb-btn {
    position: fixed; right: 20px; bottom: 20px; z-index: 9999;
    width: 56px; height: 56px; border-radius: 50%;
    border: none; cursor: pointer; font-size: 24px;
    box-shadow: 0 6px 20px rgba(0,0,0,.15); background: var(--atc-primary); color: #fff;
    font-family: inherit;
  }
  .atcb-window {
    position: fixed; right: 20px; bottom: 90px; z-index: 9999;
    width: 420px; height: 520px; display: none; flex-direction: column;
    box-shadow: 0 10px 30px rgba(0,0,0,.2); border-radius: 12px; overflow: hidden;
    border: 1px solid #1b365d;
    background: #fff; resize: both; min-width: 320px; min-height: 380px; max-width: 90vw; max-height: 85vh;
    font-family: inherit;
    color: var(--atc-text);
    font-size: 16px;
    line-height: 1.5;
  }
  /* Resizable handles on all edges/corners */
  .atcb-window .atcb-resize-handle { position:absolute; z-index:1; user-select:none; }
  .atcb-window .atcb-resize-handle.n { top:-3px; left:50%; transform:translateX(-50%); height:6px; width:48px; cursor:n-resize; }
  .atcb-window .atcb-resize-handle.s { bottom:-3px; left:50%; transform:translateX(-50%); height:6px; width:48px; cursor:s-resize; }
  .atcb-window .atcb-resize-handle.e { right:-3px; top:50%; transform:translateY(-50%); width:6px; height:48px; cursor:e-resize; }
  .atcb-window .atcb-resize-handle.w { left:-3px; top:50%; transform:translateY(-50%); width:6px; height:48px; cursor:w-resize; }
  .atcb-window .atcb-resize-handle.nw { left:-3px; top:-3px; width:10px; height:10px; cursor:nwse-resize; }
  .atcb-window .atcb-resize-handle.ne { right:-3px; top:-3px; width:10px; height:10px; cursor:nesw-resize; }
  .atcb-window .atcb-resize-handle.sw { left:-3px; bottom:-3px; width:10px; height:10px; cursor:nesw-resize; }
  .atcb-window .atcb-resize-handle.se { right:-3px; bottom:-3px; width:10px; height:10px; cursor:nwse-resize; }
  .atcb-header { display:flex; align-items:center; justify-content:space-between; padding:4px 8px; background:var(--atc-primary); color:#fff; font-weight:600; font-size:14px; cursor:move; user-select:none; }
  .atcb-header .actions { display:flex; gap:8px; }
  .atcb-header button { background: rgba(255,255,255,.15); border:none; color:#fff; padding:2px 4px; border-radius:6px; cursor:pointer; }
  .atcb-header button, .atcb-header .actions { cursor:pointer; }
  .atcb-header button:hover { background: rgba(255,255,255,.25); }
  .atcb-header button.active { background: rgba(255,255,255,.35); }
  .atcb-header button svg { width: 20px; height: 20px; }
  .atcb-examples { padding:10px; border-bottom:1px solid #e6ecf0; background:#fafbfc; display:flex; flex-wrap:wrap; gap:8px; }
  /* Filter Popup Dialog - Combobox Style */
  .atcb-filter-overlay { position:fixed; top:0; left:0; right:0; bottom:0; background:transparent; z-index:10000; display:none; }
  .atcb-filter-overlay.show { display:block; }
  .atcb-filter-popup { position:absolute; background:#fff; border-radius:8px; box-shadow:0 4px 12px rgba(0,0,0,.15), 0 0 0 1px rgba(0,0,0,.1); padding:8px 0; min-width:240px; max-width:90vw; max-height:300px; overflow-y:auto; overflow-x:hidden; }
  .atcb-filter-popup::before { content:''; position:absolute; top:-6px; right:16px; width:0; height:0; border-left:6px solid transparent; border-right:6px solid transparent; border-bottom:6px solid #fff; z-index:1; }
  .atcb-filter-popup::after { content:''; position:absolute; top:-7px; right:16px; width:0; height:0; border-left:6px solid transparent; border-right:6px solid transparent; border-bottom:6px solid rgba(0,0,0,.1); z-index:0; }
  .atcb-filter-popup.above::before { top:auto; bottom:-6px; border-bottom:none; border-top:6px solid #fff; }
  .atcb-filter-popup.above::after { top:auto; bottom:-7px; border-bottom:none; border-top:6px solid rgba(0,0,0,.1); }
  .atcb-filter-popup label { display:flex; align-items:center; font-size:12px; margin:0; cursor:pointer; padding:4px 16px; transition:background .15s ease; color:#222; }
  .atcb-filter-popup label:hover { background:#f3f4f6; }
  .atcb-filter-popup input[type="checkbox"] { margin-right:10px; width:18px; height:18px; cursor:pointer; flex-shrink:0; }
  .atcb-chip { border:1px solid var(--atc-border); background:#fff; border-radius:999px; padding:6px 10px; font-size:12px; cursor:pointer; transition: box-shadow .15s ease; }
  .atcb-chip:hover { box-shadow:0 2px 8px rgba(0,0,0,.06); }
  .atcb-body { padding:12px; overflow:auto; flex:1; background:var(--atc-bg); font-size:16px; line-height:1.5; }
  .atcb-input { display:flex; gap:8px; padding:12px; background:#fff; border-top:1px solid #eee; }
  .atcb-input textarea { flex:1; resize:none; height:60px; padding:8px; border:1px solid #ddd; border-radius:8px; font-size:14px; line-height:1.5; font-family: inherit; }
  .atcb-input button.send { width:44px; height:44px; align-self:flex-end; border-radius:50%; border:none; background:transparent; color:var(--atc-primary); cursor:pointer; display:flex; align-items:center; justify-content:center; }
  .send svg { width:40px; height:40px; transform: translateY(-1px); }
  .atcb-msg { margin-bottom:10px; display:flex; gap:8px; }
  .atcb-msg.user { justify-content:flex-end; }
  .atcb-bubble { max-width:80%; padding:10px 12px; border-radius:10px; background:#fff; border:1px solid #eee; font-size:16px; line-height:1.5; }
  .atcb-msg.assistant .atcb-bubble { max-width:100%; flex:1 1 auto; }
  .atcb-msg.user .atcb-bubble { background:#e8f0fe; border-color:#d2e3fc; }
  .atcb-msg.user .atcb-bubble { font-size:14px; line-height:1.5; }
  .atcb-toolbar { display:flex; gap:6px; margin-top:6px; }
  .atcb-toolbar button { font-size:12px; border:none; background:#f1f3f4; padding:4px 6px; border-radius:6px; cursor:pointer; }
  .atcb-toolbar .atcb-trace { align-self:center; color:#6b7280; font-size:12px; }
  .atcb-toolbar .atcb-copy-trace { width:28px; height:28px; padding:0; display:flex; align-items:center; justify-content:center; background:#fff; border:1px solid #e5e7eb; border-radius:6px; color:#6b7280; }
  /* Rating buttons (thumbs) in gray/white like ChatGPT */
  .atcb-toolbar .atcb-rate-btn {
    width:28px; height:28px; padding:0;
    display:flex; align-items:center; justify-content:center;
    background:#fff; border:1px solid #e5e7eb; border-radius:6px;
    color:#6b7280; /* gray icon via currentColor */
  }
  .atcb-toolbar .atcb-rate-btn:hover { background:#f3f4f6; }
  .atcb-toolbar .atcb-rate-btn.active { background:#6b7280; color:#fff; border-color:#6b7280; }
  .atcb-toolbar .atcb-rate-btn svg, .atcb-toolbar .atcb-rate-btn img { width:18px; height:18px; display:block; }
  .atcb-toolbar .atcb-copy { width:28px; height:28px; padding:0; display:flex; align-items:center; justify-content:center; background:#fff; border:1px solid #e5e7eb; border-radius:6px; color:#6b7280; }
  .atcb-toolbar .atcb-copy:hover { background:#f3f4f6; }
  .atcb-toolbar .atcb-copy img, .atcb-toolbar .atcb-copy svg { width:18px; height:18px; display:block; }
  .atcb-md { font-size:14px; line-height:1.5; }
  .atcb-md pre code { display:block; padding:12px; border-radius:8px; overflow:auto; font-size:13px; line-height:1.5; }
  /* Per-code-block copy button */
  .atcb-codeblock { position: relative; }
  .atcb-code-copy {
    position: absolute; top: 8px; right: 8px;
    display:flex; align-items:center; justify-content:center;
    width:28px; height:28px; border:none; border-radius:6px;
    background:#ffffffcc; color:#6b7280; cursor:pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
  }
  .atcb-code-copy:hover { background:#fff; }
  .atcb-code-copy svg { width:16px; height:16px; display:block; }
  .atcb-md table { border-collapse:collapse; width:100%; }
  .atcb-md th, .atcb-md td { border:1px solid #e5e7eb; padding:6px 8px; }
  .atcb-md blockquote { border-left:4px solid #e5e7eb; margin:8px 0; padding:4px 12px; color:#4b5563;}
  .atcb-md ul, .atcb-md ol { padding-left:20px; }
  .atcb-md h1, .atcb-md h2, .atcb-md h3, .atcb-md h4, .atcb-md h5, .atcb-md h6 { margin:8px 0 4px; }
  /* Normalize heading sizes inside Markdown to match smaller base text */
  .atcb-window .atcb-md h1 { font-size:1.25em; line-height:1.3; }
  .atcb-window .atcb-md h2 { font-size:1.15em; line-height:1.3; }
  .atcb-window .atcb-md h3 { font-size:1.08em; line-height:1.3; }
  .atcb-window .atcb-md h4 { font-size:1.00em; line-height:1.3; }
  .atcb-window .atcb-md h5 { font-size:0.95em; line-height:1.3; }
  .atcb-window .atcb-md h6 { font-size:0.90em; line-height:1.3; }
  .typing { opacity:.6; font-style:italic; }
  /* Animated typing indicator (three bouncing dots) */
  .typing-indicator { display:inline-flex; gap:4px; margin-left:6px; vertical-align:middle; }
  .typing-indicator span { width:6px; height:6px; background:#9ca3af; border-radius:50%; display:inline-block; animation: atcb-bounce 1s infinite ease-in-out; }
  .typing-indicator span:nth-child(2){ animation-delay:.2s; }
  .typing-indicator span:nth-child(3){ animation-delay:.4s; }
  @keyframes atcb-bounce { 0%, 80%, 100% { transform: scale(0.4); opacity:.5; } 40% { transform: scale(1); opacity:1; } }
  /* KaTeX tweaks */
  .atcb-md .katex-display {
    margin:8px 0;
    overflow-x:auto;
    overflow-y:hidden;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
  }
  .atcb-md .katex-display::-webkit-scrollbar { display:none; width:0; height:0; }
  .atcb-md .katex { font-size:1em; }
  
  /* Embed mode: inline styling for content area */
  .atcb-container.atcb-embed .atcb-btn {
    position: relative;
    right: auto;
    bottom: auto;
    margin: 0 auto 20px;
    display: block;
  }
  .atcb-container.atcb-embed .atcb-window {
    position: relative;
    right: auto;
    bottom: auto;
    width: 100%;
    max-width: 100%;
    height: 600px;
    max-height: 80vh;
    margin: 0 auto;
  }
