/* MLMP docs assistant. Colors come from the Material theme so it follows the palette and dark mode. */
#chat-root {
  --cb-accent: var(--md-primary-fg-color);
  --cb-on-accent: var(--md-primary-bg-color);
  --cb-bg: var(--md-default-bg-color);
  --cb-fg: var(--md-default-fg-color);
  --cb-muted: var(--md-default-fg-color--light);
  --cb-line: var(--md-default-fg-color--lightest);
  --cb-soft: var(--md-code-bg-color);
  --cb-link: var(--md-typeset-a-color);
  --cb-radius: .8rem;
  --cb-ease: cubic-bezier(.2, .8, .2, 1);
  position: fixed; right: 1rem; bottom: 1rem;
  z-index: 4; /* above content, below Material's drawer and cookie consent */
  font-size: .7rem; line-height: 1.5; color: var(--cb-fg);
}
#chat-root svg { width: 1.1em; height: 1.1em; flex: none; }
#chat-root button { font: inherit; color: inherit; cursor: pointer; }
#chat-root :focus-visible { outline: 2px solid var(--md-accent-fg-color); outline-offset: 2px; }

/* launcher */
#chat-toggle {
  display: grid; place-items: center; width: 2.8rem; height: 2.8rem; padding: 0;
  border: 0; border-radius: 50%; background: var(--cb-accent); color: var(--cb-on-accent);
  /* ring keeps it visible on top of the (same-colored) Material footer */
  box-shadow: 0 0 0 2px var(--cb-bg), 0 6px 20px rgb(0 0 0 / .25); font-size: 1.05rem;
  transition: transform .2s var(--cb-ease), box-shadow .2s;
}
#chat-root #chat-toggle { color: var(--cb-on-accent); }
#chat-toggle:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 0 0 2px var(--cb-bg), 0 10px 26px rgb(0 0 0 / .3); }
#chat-toggle > span { grid-area: 1 / 1; display: flex; transition: transform .25s var(--cb-ease), opacity .2s; }
#chat-toggle .cb-ic-close, .open #chat-toggle .cb-ic-chat { opacity: 0; transform: rotate(-90deg) scale(.6); }
.open #chat-toggle .cb-ic-close { opacity: 1; transform: none; }

/* panel */
#chat-box {
  position: absolute; right: 0; bottom: 3.5rem;
  display: flex; flex-direction: column; overflow: hidden;
  width: min(22rem, calc(100vw - 2rem));
  height: min(32rem, calc(100vh - 6rem)); height: min(32rem, calc(100dvh - 6rem));
  background: var(--cb-bg); border: 1px solid var(--cb-line); border-radius: var(--cb-radius);
  box-shadow: 0 18px 50px rgb(0 0 0 / .2), 0 2px 8px rgb(0 0 0 / .08);
  transform-origin: bottom right;
  opacity: 0; visibility: hidden; transform: translateY(.5rem) scale(.97);
  transition: opacity .18s, transform .22s var(--cb-ease), visibility 0s .22s;
}
.open #chat-box { opacity: 1; visibility: visible; transform: none; transition: opacity .18s, transform .22s var(--cb-ease); }

.cb-head {
  display: flex; align-items: center; gap: .5rem; padding: .55rem .5rem .55rem .7rem;
  background: var(--cb-accent); color: var(--cb-on-accent);
}
.cb-avatar {
  display: grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%;
  background: rgb(255 255 255 / .16); font-size: .8rem;
}
.cb-title { flex: 1; display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.cb-title strong { font-size: .75rem; }
.cb-title small { opacity: .75; font-size: .6rem; }
#chat-root .cb-icon {
  display: grid; place-items: center; width: 1.6rem; height: 1.6rem; padding: 0;
  border: 0; border-radius: .4rem; background: none; color: var(--cb-on-accent); opacity: .8;
}
.cb-icon:hover { opacity: 1; background: rgb(255 255 255 / .14); }

/* messages */
#chat-log {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: .6rem; padding: .8rem .7rem;
  scrollbar-width: thin;
}
.cb-msg { display: flex; animation: cb-in .25s var(--cb-ease); }
.cb-msg.user { justify-content: flex-end; }
.cb-bubble {
  max-width: 88%; padding: .45rem .7rem; border-radius: var(--cb-radius);
  overflow-wrap: anywhere; white-space: normal;
}
.user .cb-bubble {
  background: var(--cb-accent); color: var(--cb-on-accent);
  border-bottom-right-radius: .2rem; white-space: pre-wrap;
}
.bot .cb-bubble { max-width: 100%; background: var(--cb-soft); border-bottom-left-radius: .2rem; }
.bot.error .cb-bubble { border: 1px solid var(--md-typeset-del-color, #e5484d55); }

.cb-bubble > :first-child { margin-top: 0; }
.cb-bubble > :last-child { margin-bottom: 0; }
.cb-bubble p, .cb-bubble ul, .cb-bubble ol, .cb-bubble blockquote { margin: .4rem 0; }
.cb-bubble ul, .cb-bubble ol { padding-left: 1.1rem; }
.cb-bubble li + li { margin-top: .15rem; }
.cb-bubble .cb-h { font-weight: 700; margin-top: .6rem; }
.cb-bubble blockquote { padding-left: .6rem; border-left: 3px solid var(--cb-line); color: var(--cb-muted); }
.cb-bubble a { color: var(--cb-link); text-decoration: underline; text-underline-offset: 2px; }
.cb-bubble code {
  padding: .05rem .3rem; border-radius: .25rem; font-size: .9em;
  font-family: var(--md-code-font-family, ui-monospace, monospace);
  background: var(--cb-bg); border: 1px solid var(--cb-line);
}

.cb-bubble hr { margin: .7rem 0; border: 0; border-top: 1px solid var(--cb-line); }
.cb-bubble .cb-cellcode { display: block; margin: .2rem 0; padding: .3rem .4rem; white-space: pre-wrap; }

.cb-code { margin: .5rem 0; border-radius: .5rem; overflow: hidden; border: 1px solid var(--cb-line); background: var(--cb-bg); }
.cb-code-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: .15rem .3rem .15rem .6rem; font-size: .6rem; color: var(--cb-muted);
  border-bottom: 1px solid var(--cb-line);
}
#chat-root .cb-copy { border: 0; background: none; padding: .15rem .4rem; border-radius: .3rem; color: var(--cb-muted); font-size: .6rem; }
.cb-copy:hover { background: var(--cb-soft); }
.cb-code pre { margin: 0; padding: .55rem .65rem; overflow-x: auto; font-size: .62rem; line-height: 1.55; }
.cb-code pre code { padding: 0; border: 0; background: none; font-size: inherit; }

.cb-table { overflow-x: auto; margin: .5rem 0; }
.cb-table table { border-collapse: collapse; font-size: .62rem; }
.cb-table th, .cb-table td { padding: .25rem .5rem; border: 1px solid var(--cb-line); text-align: left; vertical-align: top; }
.cb-table th { background: var(--cb-bg); white-space: nowrap; }

/* sources */
.cb-src { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .6rem; padding-top: .5rem; border-top: 1px dashed var(--cb-line); }
.cb-src > span { width: 100%; font-size: .55rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--cb-muted); }
.cb-bubble .cb-src a {
  display: inline-flex; align-items: center; gap: .25rem; max-width: 100%;
  padding: .15rem .5rem; border-radius: 1rem; font-size: .6rem; text-decoration: none;
  color: var(--cb-fg); background: var(--cb-bg); border: 1px solid var(--cb-line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: border-color .15s, color .15s;
}
.cb-bubble .cb-src a:hover { border-color: var(--cb-link); color: var(--cb-link); }

/* welcome + suggestions */
.cb-welcome { margin: auto 0 0; color: var(--cb-muted); }
.cb-welcome p { margin: 0 0 .6rem; }
.cb-welcome strong { color: var(--cb-fg); }
.cb-chips { display: flex; flex-direction: column; align-items: flex-start; gap: .35rem; }
#chat-root .cb-chip, #chat-root .cb-retry {
  padding: .35rem .7rem; border-radius: 1rem; text-align: left;
  border: 1px solid var(--cb-line); background: var(--cb-bg); color: var(--cb-fg);
  transition: border-color .15s, background .15s;
}
#chat-root .cb-retry { display: block; margin-top: .4rem; font-size: .65rem; }
.cb-chip:hover, .cb-retry:hover { border-color: var(--cb-accent); background: var(--cb-soft); }

/* typing indicator */
.cb-typing { display: inline-flex; gap: .2rem; padding: .25rem 0; }
.cb-typing i { width: .35rem; height: .35rem; border-radius: 50%; background: var(--cb-muted); animation: cb-dot 1.2s infinite ease-in-out; }
.cb-typing i:nth-child(2) { animation-delay: .15s; }
.cb-typing i:nth-child(3) { animation-delay: .3s; }

/* composer */
#chat-form {
  display: flex; align-items: flex-end; gap: .4rem; margin: 0 .6rem; padding: .35rem .35rem .35rem .7rem;
  border: 1px solid var(--cb-line); border-radius: 1.2rem; background: var(--cb-bg);
  transition: border-color .15s, box-shadow .15s;
}
#chat-form:focus-within { border-color: var(--cb-accent); box-shadow: 0 0 0 3px var(--md-default-fg-color--lightest); }
#chat-input {
  flex: 1; resize: none; border: 0; outline: 0; padding: .3rem 0; max-height: 7rem;
  background: transparent; color: inherit; font: inherit; line-height: 1.4;
}
#chat-root #chat-input:focus-visible { outline: 0; }
#chat-input::placeholder { color: var(--cb-muted); }
#chat-root .cb-send {
  display: grid; place-items: center; width: 1.6rem; height: 1.6rem; padding: 0; flex: none;
  border: 0; border-radius: 50%; background: var(--cb-accent); color: var(--cb-on-accent);
  transition: transform .15s, opacity .15s;
}
.cb-send:hover { transform: scale(1.06); }
#chat-input:placeholder-shown + .cb-send { opacity: .45; }
.busy #chat-input + .cb-send { opacity: 1; }
.cb-foot { margin: .35rem .8rem .5rem; text-align: center; font-size: .55rem; color: var(--cb-muted); }

/* phones: full screen */
@media (max-width: 37.5em) {
  .open #chat-box { position: fixed; inset: 0; width: auto; height: auto; border: 0; border-radius: 0; }
  .open #chat-toggle { display: none; }
  #chat-box { font-size: .75rem; }
}

@keyframes cb-in { from { opacity: 0; transform: translateY(.3rem); } }
@keyframes cb-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-.2rem); } }

@media (prefers-reduced-motion: reduce) {
  #chat-root *, #chat-root { animation: none !important; transition: none !important; }
}
