:root{
    --primary: #15a9e1;        /* your brand color */
    --primary-600: #1294c7;    /* darker hover */
    --bg: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --shadow: 0 10px 30px rgba(0,0,0,.15);
  }
  
  *, *::before, *::after { box-sizing: border-box; }
  body { margin: 0; font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }
  
  .chat-toggle {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 56px; height: 56px;
    border: none; border-radius: 50%;
    background: var(--primary); color: #fff;
    box-shadow: var(--shadow);
    display: grid; place-items: center;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, background .2s ease;
    z-index: 2147483647;
  }
  .chat-toggle:hover { transform: translateY(-1px); background: var(--primary-600); }
  .chat-toggle:active { transform: translateY(0); }
  .chat-toggle:focus-visible { outline: 3px solid rgba(21,169,225,.35); outline-offset: 3px; }
  
  .chat {
    position: fixed;
    right: 20px;
    bottom: 86px;
    width: 340px;
    max-height: min(70vh, 560px);
    background: var(--bg); color: var(--text);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    display: grid; grid-template-rows: auto 1fr auto;
    overflow: hidden;
    visibility: hidden; opacity: 0;
    transform: translateY(8px) scale(.98);
    transition: opacity .18s ease, transform .18s ease, visibility 0s linear .18s;
    z-index: 2147483646;
  }
  .chat.open { visibility: visible; opacity: 1; transform: translateY(0) scale(1); transition-delay: 0s; }
  
  .chat__header {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px;
    background: var(--primary); color: #fff;
  }
  .chat__avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: rgba(255,255,255,.25);
    display: grid; place-items: center;
    font-size: 18px; user-select: none;
  }
  .chat__title { font-weight: 600; }
  .chat__spacer { flex: 1; }
  .chat__close {
    background: transparent; border: 0; color: #fff;
    width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
  }
  .chat__close:focus-visible { outline: 3px solid rgba(255,255,255,.65); outline-offset: 2px; }
  
  .chat__log {
    padding: 12px;
    overflow: auto;
    background: #fafafa;
  }
  .msg { display: grid; gap: 6px; margin: 10px 0; max-width: 85%; }
  .msg--agent { justify-items: start; }
  .msg--user  { justify-items: end; margin-left: auto; }
  .bubble {
    padding: 10px 12px; border-radius: 12px;
    border: 1px solid var(--border);
    background: #fff;
    box-shadow: 0 1px 0 rgba(0,0,0,.04);
    word-wrap: break-word; white-space: pre-wrap;
  }
  .msg--user .bubble { background: #e8f7fd; border-color: #cbeefb; }
  .meta { font-size: 12px; color: var(--muted); }
  
  .chat__input {
    border-top: 1px solid var(--border);
    padding: 10px; background: #fff;
    display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end;
  }
  .field { position: relative; display: grid; }
  .field textarea {
    width: 100%;
    min-height: 44px; max-height: 140px;
    resize: none; padding: 10px 12px 28px 12px;
    border-radius: 10px; border: 1px solid var(--border);
    font: inherit; line-height: 1.35;
    background: #000;
    color: #FFF;
  
  }
  .hint {
    position: absolute; right: 10px; bottom: 6px;
    font-size: 12px; color: var(--muted); pointer-events: none;
  }
  .send-btn {
    border: 0; border-radius: 10px; padding: 10px 12px;
    background: var(--primary); color: #fff; cursor: pointer;
  }
  .send-btn:hover { background: var(--primary-600); }
  .send-btn:focus-visible { outline: 3px solid rgba(21,169,225,.35); outline-offset: 2px; }
  .send-btn[disabled] { opacity: .6; cursor: not-allowed; }
  
  @media (max-width: 480px) {
    .chat { right: 10px; left: 10px; width: auto; bottom: 84px; max-height: calc(100vh - 110px); }
    .chat-toggle { right: 16px; bottom: 16px; }
  }
  
  @media (prefers-reduced-motion: reduce) {
    .chat, .chat-toggle { transition: none !important; }
  }
  
  /* resource preview cards inside chat bubbles */
.bubble .res-card {
    margin: 8px 0;
    border: 1px solid #eee;
    border-radius: 6px;
    background: #fafafa;
    overflow: hidden;
  }
  .bubble .res-card--img .res-thumb {
    display: block;
    max-width: 100%;
    max-height: 220px;
    width: auto;
    height: auto;
    object-fit: cover;
  }
  .bubble .res-card .res-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    font-size: 12px;
    color: #666;
    background: #fff;
    border-top: 1px solid #eee;
  }
  .bubble .res-badge {
    display: inline-block;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    background: #eef4ff;
    color: #335;
  }
  .bubble .res-badge--pdf { background: #fdeeee; color: #833; }
  
  .bubble .res-card--pdf .res-pdf {
    width: 100%;
    height: 360px; /* overridden by PREVIEW.pdfHeight */
    border: 0;
    display: block;
  }
  .bubble .res-card--pdf .res-fallback {
    padding: 12px;
    display: flex;
    gap: 8px;
    align-items: center;
    color: #555;
  }
  