/*
 * WP RAG Assistant widget (0.10.0).
 *
 * The look of the original widget (1.2 on pk.zp.edu.ua): the university
 * blues, the header gradient, square corners, thin grey borders and the row
 * of quick questions above the input; a faint coat of arms behind the chat.
 *
 * Every rule is scoped under #cw-launcher, #cw-window or #cw-widget-overlay.
 * The host themes style bare elements (zp.edu.ua: section margins of up to
 * 18rem, input borders and paddings, svg width/height 100% and fill;
 * pk.zp.edu.ua: section padding and content-visibility, p/h3/ul/li sizes and
 * margins), so the widget first reverts all author styles on its own elements
 * (specificity 1,0,0 beats any class or element selector of a theme), then
 * sets its own. The input paddings are !important only because zp.edu.ua sets
 * them that way.
 *
 * Motion: one spring-like curve (--cw-spring) on transform and opacity only.
 * CSS transitions restart from the current value, so closing a window or a
 * panel half-way through its opening reverses it smoothly.
 */

/* --- 1. Isolation from the theme ------------------------------------------------------ */

#cw-launcher,
#cw-window,
#cw-widget-overlay,
:is(#cw-launcher, #cw-window) :where(*:not(svg, svg *)) {
  all: revert;
}

:is(#cw-launcher, #cw-window) :where(*),
:is(#cw-launcher, #cw-window) :where(*)::before,
:is(#cw-launcher, #cw-window) :where(*)::after {
  box-sizing: border-box;
}

#cw-window :where(p, h1, h2, h3, h4, ul, ol, li, figure, blockquote, dl, dd) {
  margin: 0;
  padding: 0;
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
}

#cw-window :where(ul, ol) {
  list-style: none;
}

:is(#cw-launcher, #cw-window) :where(button, input, textarea, select) {
  margin: 0;
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  text-transform: none;
}

#cw-window :where(button) {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

#cw-window :where(a) {
  color: var(--cw-link);
  text-decoration: none;
  cursor: pointer;
}

#cw-window :where(img) {
  display: block;
  max-width: none;
  height: auto;
  border: 0;
}

/* Icons: themes set svg { width: 100%; height: 100%; fill: currentColor }. */
:is(#cw-launcher, #cw-window) svg {
  display: block;
  flex: none;
  fill: none;
  pointer-events: none;
  overflow: visible;
  transform-origin: center;
  max-width: none;
  max-height: none;
}

:is(#cw-launcher, #cw-window) svg[width="12"] { width: 12px; height: 12px; }
:is(#cw-launcher, #cw-window) svg[width="14"] { width: 14px; height: 14px; }
:is(#cw-launcher, #cw-window) svg[width="16"] { width: 16px; height: 16px; }
:is(#cw-launcher, #cw-window) svg[width="18"] { width: 18px; height: 18px; }
:is(#cw-launcher, #cw-window) svg[width="20"] { width: 20px; height: 20px; }
:is(#cw-launcher, #cw-window) svg[width="24"] { width: 24px; height: 24px; }

:is(#cw-launcher, #cw-window) svg.cw-i-fill {
  fill: currentColor;
}

#cw-window [hidden] {
  display: none !important;
}

#cw-window .cw-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --- 2. Tokens: the original widget's colours ------------------------------------------ */

/*
 * Two kinds of colour, as in the zp.edu.ua theme. The palette (blues, white,
 * green, red) is fixed: a blue button with white text on it stays that in
 * both themes. The paper tokens (backgrounds, surfaces, text, lines, the
 * blue used as text on the paper) are what the dark theme below changes.
 */
#cw-launcher,
#cw-window {
  --cw-blue-100: #265aa6;
  --cw-blue-200: #16295b;
  --cw-blue-300: #2271b1;
  --cw-blue-400: #0a4b78;
  --cw-grad-1: #1e3a8a;
  --cw-grad-2: #3b82f6;
  --cw-white: #ffffff;
  --cw-green: #4ade80;
  --cw-red: #ef4444;

  /* Paper: the chat area, the bars around it, cards and fields on it. */
  --cw-bg: #ffffff;
  --cw-chrome: #ffffff;
  --cw-surface: #ffffff;
  --cw-surface-soft: #f8f9fa;
  --cw-fill: #f0f0f0;
  --cw-frame: var(--cw-blue-200);

  --cw-text: #464646;
  --cw-text-body: #333333;
  --cw-text-strong: #1a1a1a;
  --cw-text-soft: #555555;
  --cw-text-dim: #666666;
  /* Meta text (times, counts, the footer) at 4.5:1 or more on white and
     on the soft surface; until 0.8.0 these were #999-#a0a0a0, about 2.7:1. */
  --cw-text-faint: #6e6e6e;
  --cw-text-muted: #6b7280;
  --cw-text-hint: #707070;
  --cw-warn: #b45309;

  --cw-line: #eaeaea;
  --cw-border: #e5e7eb;
  --cw-border-light: #e0e0e0;
  --cw-border-alt: #e1e8ed;
  --cw-scroll: #d1d5db;

  --cw-accent: var(--cw-blue-100);
  --cw-link: var(--cw-blue-300);
  --cw-link-hover: var(--cw-blue-400);
  --cw-focus: var(--cw-blue-300);
  --cw-select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23265aa6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");

  /* Channels for translucent washes: rgba(var(--cw-tint--rgb), 0.06). */
  --cw-ink--rgb: 0, 0, 0;
  --cw-tint--rgb: 38, 90, 166;

  --cw-fs: 14px;
  --cw-meta-h: 26px;
  --cw-font: "Roboto", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;

  /* Apple-like spring (critically damped feel) and its durations. */
  --cw-spring: cubic-bezier(0.32, 0.72, 0, 1);
  --cw-t-sheet: 380ms;
  --cw-t-panel: 320ms;
  --cw-t-fade: 200ms;
  --cw-t-small: 150ms;
}

/*
 * Dark theme: follows the switch of the zp.edu.ua theme (<html data-theme>,
 * set before the first paint), not the system setting, so the widget is
 * never dark on a light page. The paper takes the theme's own tokens (a cool
 * graphite, warm off-white text, a light blue for links), with the theme's
 * dark values as fallbacks; the brand blues go a step deeper, as they do on
 * the site. On a site without that switch nothing here applies.
 */
html[data-theme="dark"] #cw-launcher,
html[data-theme="dark"] #cw-window {
  color-scheme: dark;

  --cw-blue-100: var(--color-blue-100, #224f92);
  --cw-blue-200: var(--color-blue-200, #13234d);
  --cw-grad-1: #152a63;
  --cw-grad-2: #2a5ba8;

  --cw-bg: var(--color-bg-primary, #161b1f);
  --cw-chrome: var(--color-bg-secondary, #1a2025);
  --cw-surface: var(--color-surface-card, #1f262b);
  --cw-surface-soft: var(--color-bg-primary, #161b1f);
  --cw-fill: var(--color-bg-tertiary, #283036);
  --cw-frame: var(--color-border-strong, #4b565e);

  --cw-text: var(--color-text-primary, #ebe8e4);
  --cw-text-body: var(--color-text-primary, #ebe8e4);
  --cw-text-strong: var(--color-text-heading, #f6f3ef);
  --cw-text-soft: var(--color-text-secondary, #aeb8bd);
  --cw-text-dim: var(--color-text-secondary, #aeb8bd);
  --cw-text-faint: var(--color-text-muted, #86939b);
  --cw-text-muted: var(--color-text-muted, #86939b);
  --cw-text-hint: var(--color-text-muted, #86939b);
  --cw-warn: #f0ab16;

  --cw-line: var(--color-border, #2c353b);
  --cw-border: var(--color-border, #2c353b);
  --cw-border-light: var(--color-border-strong, #4b565e);
  --cw-border-alt: var(--color-border, #2c353b);
  --cw-scroll: #3a444b;

  --cw-accent: var(--color-accent, #3ea6ff);
  --cw-link: var(--color-link, #3ea6ff);
  --cw-link-hover: var(--color-link-hover, #7cc2ff);
  --cw-focus: var(--color-accent, #3ea6ff);
  --cw-select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%233ea6ff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");

  --cw-ink--rgb: 255, 255, 255;
  --cw-tint--rgb: 62, 166, 255;
}

html[data-theme="dark"] #cw-widget-overlay {
  --cw-overlay: rgba(0, 0, 0, 0.7);
}

#cw-window.cw-text-lg {
  --cw-fs: 16px;
}

#cw-window,
#cw-launcher {
  font-family: var(--cw-font);
  font-size: var(--cw-fs);
  line-height: 1.5;
  color: var(--cw-text);
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}

#cw-window :focus-visible,
#cw-launcher :focus-visible {
  outline: 2px solid var(--cw-focus) !important;
  outline-offset: 2px !important;
}

#cw-window:focus,
#cw-window:focus-visible {
  outline: none !important;
}

#cw-window .cw-header :focus-visible {
  outline-color: var(--cw-white) !important;
  outline-offset: 0 !important;
}

/* --- 3. Launcher (as in 1.2) ------------------------------------------------------------- */

/*
 * 52px (42px on phones): the sizes the zp.edu.ua theme sets inline when it
 * moves the button in and out of its hero navigation (".in-nav", all
 * !important). The class names stay for that integration.
 */
#cw-launcher {
  position: fixed;
  left: 15px;
  bottom: 15px;
  z-index: 99998;
  display: block;
}

#cw-launcher [hidden] {
  display: none !important;
}

#cw-launcher .cw-floating-btn {
  position: relative;
  display: flex;
  align-items: center;
  width: 52px;
  height: 52px;
  padding: 0;
  overflow: hidden;
  background: var(--cw-blue-200);
  color: var(--cw-white);
  border: 1px solid var(--cw-white);
  border-radius: 0;
  box-shadow: 0 5px 15px rgba(22, 41, 91, 0.15);
  cursor: pointer;
  white-space: nowrap;
  transition: width 0.3s var(--cw-spring), background-color 0.3s ease, box-shadow 0.3s ease, transform var(--cw-t-small) ease;
}

#cw-launcher .cw-floating-btn:active {
  transform: scale(0.96);
}

#cw-launcher .cw-floating-btn svg {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 26px;
  height: 26px;
  margin-top: -13px;
}

#cw-launcher .cw-icon-close,
#cw-launcher .cw-floating-btn.is-active .cw-icon-open {
  display: none;
}

#cw-launcher .cw-floating-btn.is-active .cw-icon-close {
  display: block;
  animation: cw-spin-in 0.25s var(--cw-spring);
}

#cw-launcher .cw-btn-text {
  margin-left: 52px;
  padding-right: 15px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.2s ease;
}

@media (hover: hover) {
  #cw-launcher .cw-floating-btn:hover {
    width: 175px;
    box-shadow: 0 10px 20px rgba(38, 90, 166, 0.2);
  }

  #cw-launcher .cw-floating-btn:hover .cw-btn-text {
    opacity: 1;
    transition-delay: 0.1s;
  }

  #cw-launcher .cw-floating-btn.is-active:hover {
    width: 52px;
  }
}

#cw-launcher .cw-floating-btn.is-active .cw-btn-text {
  display: none;
}

/*
 * The one-time invitation over the launcher on a page where it fits
 * ("Питання про вступ чи вартість?"), once per visitor (script.js).
 */
#cw-launcher .cw-invite {
  position: absolute;
  left: 0;
  bottom: calc(100% + 12px);
  display: flex;
  align-items: flex-start;
  gap: 2px;
  width: max-content;
  max-width: min(280px, calc(100vw - 30px));
  padding: 4px;
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
  border-radius: 12px 12px 12px 4px;
  box-shadow: 0 10px 28px rgba(22, 41, 91, 0.18), 0 2px 6px rgba(22, 41, 91, 0.08);
  color: var(--cw-text-strong);
  font-size: 14px;
  line-height: 1.4;
  white-space: normal;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 220ms ease, transform 320ms var(--cw-spring);
}

#cw-launcher .cw-invite.is-shown {
  opacity: 1;
  transform: none;
}

#cw-launcher .cw-invite-text {
  display: block;
  padding: 6px 4px 6px 8px;
  background: none;
  border: 0;
  color: inherit;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

#cw-launcher .cw-invite-text strong {
  display: block;
  margin-top: 2px;
  color: var(--cw-link);
  font-size: 13px;
  font-weight: 600;
}

#cw-launcher .cw-invite-close {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--cw-text-dim);
  cursor: pointer;
}

@media (hover: hover) {
  #cw-launcher .cw-invite-text:hover strong {
    text-decoration: underline;
  }

  #cw-launcher .cw-invite-close:hover {
    background: rgba(var(--cw-ink--rgb), 0.06);
    color: var(--cw-text-strong);
  }
}

#cw-widget-overlay {
  display: none;
}

/* --- 4. Window ----------------------------------------------------------------------------- */

#cw-window {
  position: fixed;
  left: 15px;
  bottom: 75px;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  /* --cw-w / --cw-h: the size the visitor dragged it to (script); the
     screen still caps it, so a size from a bigger monitor never spills off. */
  width: min(var(--cw-w, 420px), calc(100vw - 30px));
  height: min(var(--cw-h, 700px), calc(100vh - 95px));
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--cw-bg);
  border: 1px solid var(--cw-frame);
  border-radius: 0;
  box-shadow: 0 5px 40px rgba(0, 0, 0, 0.16);
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.96);
  transform-origin: 0 100%;
  transition: transform 240ms var(--cw-spring), opacity 180ms ease, visibility 0s linear 240ms;
  will-change: transform, opacity;
}

#cw-window.is-open {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: transform var(--cw-t-sheet) var(--cw-spring), opacity var(--cw-t-fade) ease, visibility 0s linear 0s;
}

/* Expanded: the whole screen (section 9b lays it out). */
#cw-window.is-expanded {
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: none;
  height: 100%;
  border: 0;
  box-shadow: none;
  transform: scale(0.985);
  transform-origin: 50% 50%;
}

#cw-window.is-expanded.is-open {
  transform: none;
}

/*
 * Resize handles (desktop with a mouse): thin strips along the top and right
 * edges and the top-right corner, above the header and an open panel. Not
 * shown when expanded, on touch screens or on phones (the phone block hides
 * them as well).
 */
#cw-window .cw-resize {
  display: none;
}

@media (pointer: fine) and (min-width: 601px) {
  #cw-window:not(.is-expanded) .cw-resize {
    position: absolute;
    z-index: 30;
    display: block;
  }

  #cw-window .cw-resize-n {
    top: 0;
    left: 0;
    right: 14px;
    height: 5px;
    cursor: ns-resize;
  }

  #cw-window .cw-resize-e {
    top: 14px;
    right: 0;
    bottom: 0;
    width: 5px;
    cursor: ew-resize;
  }

  #cw-window .cw-resize-ne {
    top: 0;
    right: 0;
    width: 14px;
    height: 14px;
    cursor: nesw-resize;
  }
}

/* While dragging, the page under the pointer must not select its text or
   show its own cursors. */
html.cw-resizing,
html.cw-resizing * {
  cursor: var(--cw-resize-cursor, default) !important;
  user-select: none !important;
}

/* --- 5. Header (the original gradient) -------------------------------------------------- */

#cw-window .cw-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: none;
  padding: 14px 14px 14px 18px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--cw-grad-1) 0%, var(--cw-grad-2) 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 15px rgba(37, 99, 235, 0.2);
  color: var(--cw-white);
  touch-action: none;
}

#cw-window .cw-header::before {
  content: "";
  position: absolute;
  top: -50%;
  right: -20%;
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0) 70%);
  pointer-events: none;
}

#cw-window .cw-grabber {
  display: none;
}

#cw-window .cw-header-left {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 auto;
  min-width: 0;
}

/* The coat of arms on the gradient itself, without a plate: its gold rim reads on the blue. */
#cw-window .cw-brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 40px;
  height: 40px;
}

#cw-window .cw-brand-icon img {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25));
}

#cw-window .cw-brand-icon.is-jumping img {
  animation: cw-bounce 0.6s ease-in-out;
}

#cw-window .cw-header-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 0;
}

#cw-window .cw-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

#cw-window .cw-title {
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  line-height: 18px;
  letter-spacing: 0.3px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  white-space: nowrap;
  text-overflow: ellipsis;
}

#cw-window .cw-badge {
  flex: none;
  padding: 0 5px;
  background: #28a745;
  font-size: 10px;
  font-weight: 700;
  line-height: 15px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

#cw-window .cw-status {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 16px;
  font-size: 11px;
  line-height: 16px;
  opacity: 0.9;
}

/*
 * An even size in the 16px line: a 7px dot was centred on a half pixel,
 * blurred and looked off the line of the text.
 */
#cw-window .cw-status-dot {
  position: relative;
  display: block;
  flex: none;
  width: 6px;
  height: 6px;
  background: var(--cw-green);
  border-radius: 50% !important;
}

/*
 * The pulse is a ring scaled by transform, so the compositor runs it without
 * the page; it used to animate box-shadow, which recalculated styles on every
 * frame of every page (a closed window is only visibility: hidden and its
 * animations keep going). It also runs only while the window is open.
 */
#cw-window .cw-status-dot::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(74, 222, 128, 0.7);
  border-radius: 50%;
  opacity: 0;
}

#cw-window.is-open .cw-status-dot::after {
  animation: cw-status-pulse 2s infinite;
}

#cw-window .cw-status-text {
  display: block;
  white-space: nowrap;
}

#cw-window .cw-header-actions {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}

#cw-window .cw-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  color: var(--cw-white);
  transition: background-color var(--cw-t-small) ease, transform var(--cw-t-small) ease;
}

@media (hover: hover) {
  #cw-window .cw-action-btn:hover {
    background: rgba(255, 255, 255, 0.16);
  }

  #cw-window .cw-close-btn:hover {
    background: rgba(239, 68, 68, 0.8);
  }
}

#cw-window .cw-action-btn:active {
  transform: scale(0.94);
}

#cw-window .cw-action-btn[aria-current="true"] {
  background: rgba(255, 255, 255, 0.2);
}

#cw-window .cw-icon-collapse,
#cw-window.is-expanded .cw-icon-expand {
  display: none;
}

#cw-window.is-expanded .cw-icon-collapse {
  display: block;
}

/* --- 6. Section toolbar ----------------------------------------------------------------- */

#cw-window .cw-toolbar {
  display: flex;
  gap: 4px;
  flex: none;
  padding: 6px 10px;
  background: var(--cw-chrome);
  border-bottom: 1px solid var(--cw-line);
}

#cw-window .cw-tool {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1 1 0;
  min-width: 0;
  height: 36px;
  padding: 0 6px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--cw-accent);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  transition: background-color var(--cw-t-small) ease, border-color var(--cw-t-small) ease, transform var(--cw-t-small) ease;
}

#cw-window .cw-tool-label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

@media (hover: hover) {
  #cw-window .cw-tool:hover {
    background: rgba(var(--cw-tint--rgb), 0.06);
  }
}

#cw-window .cw-tool:active {
  transform: scale(0.97);
}

#cw-window .cw-tool[aria-current="true"] {
  background: rgba(var(--cw-tint--rgb), 0.08);
  border-color: rgba(var(--cw-tint--rgb), 0.25);
}

/* --- 7. Conversation ---------------------------------------------------------------------- */

#cw-window .cw-content-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--cw-bg);
  isolation: isolate;
}

/*
 * A barely visible coat of arms behind the conversation. On the wrapper, not
 * the scrolling list: it stays in place while the messages move over it.
 */
#cw-window .cw-content-wrapper::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: url("icons/logo.svg") 50% 50% / min(55%, 200px) auto no-repeat;
  filter: grayscale(1);
  opacity: 0.04;
  pointer-events: none;
}

html[data-theme="dark"] #cw-window .cw-content-wrapper::before {
  opacity: 0.05;
}

#cw-window .cw-content {
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px 15px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--cw-scroll) transparent;
}

#cw-window .cw-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/*
 * Back to the latest message, once the reader has scrolled up. While an
 * answer goes on below it turns blue. Hidden with visibility after the fade,
 * so it leaves the tab order too; the open panel covers it (z-index 20).
 */
#cw-window .cw-to-bottom {
  position: absolute;
  right: 18px;
  bottom: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
  box-shadow: 0 4px 12px rgba(var(--cw-tint--rgb), 0.12);
  color: var(--cw-text-dim);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 220ms var(--cw-spring), visibility 0s linear 220ms,
    background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

#cw-window .cw-to-bottom.is-visible {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition-delay: 0s;
}

#cw-window .cw-to-bottom.has-new {
  background: var(--cw-blue-100);
  border-color: var(--cw-blue-100);
  color: var(--cw-white);
}

@media (hover: hover) {
  #cw-window .cw-to-bottom:not(.has-new):hover {
    border-color: var(--cw-accent);
    color: var(--cw-accent);
  }
}

#cw-window .cw-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  animation: cw-msg-in 0.4s var(--cw-spring) both;
}

#cw-window .cw-msg-bot {
  align-self: flex-start;
  max-width: 92%;
}

#cw-window .cw-msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
  max-width: 88%;
}

#cw-window .cw-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 32px;
  height: 32px;
  margin-bottom: calc(var(--cw-meta-h) + 3px);
  overflow: hidden;
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

#cw-window .cw-greeting .cw-avatar {
  margin-bottom: 0;
}

#cw-window .cw-avatar img {
  width: 100%;
  height: 100%;
  padding: 5px;
  object-fit: contain;
}

#cw-window .cw-bubble-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

#cw-window .cw-msg-user .cw-bubble-group {
  align-items: flex-end;
}

/*
 * Messages are slightly rounded (the rest of the widget keeps the square
 * corners), with a sharper corner on the side the message comes from.
 */
#cw-window .cw-text,
#cw-window .cw-typing {
  border-radius: 12px 12px 12px 4px;
}

#cw-window .cw-msg-user .cw-text {
  border-radius: 12px 12px 4px 12px;
}

#cw-window .cw-text {
  position: relative;
  min-width: 60px;
  padding: 8px 14px;
  font-size: var(--cw-fs);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

#cw-window .cw-msg-bot .cw-text {
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  color: var(--cw-text);
}

#cw-window .cw-msg-user .cw-text {
  background: var(--cw-blue-100);
  box-shadow: 0 2px 5px rgba(38, 90, 166, 0.2);
  color: var(--cw-white);
}

#cw-window .cw-meta {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: var(--cw-meta-h);
  padding: 0 2px;
  color: var(--cw-text-faint);
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
}

/* While an answer streams its actions are hidden, also from the keyboard. */
#cw-window .cw-meta[style="opacity:0"] {
  visibility: hidden;
}

#cw-window .cw-time {
  margin-right: 4px;
  font-variant-numeric: tabular-nums;
}

#cw-window .cw-msg-user .cw-meta {
  justify-content: flex-end;
}

#cw-window .cw-checks {
  display: flex;
  color: var(--cw-green);
}

#cw-window .cw-meta-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  color: var(--cw-text-hint);
  transition: background-color var(--cw-t-small) ease, color var(--cw-t-small) ease;
}

@media (hover: hover) {
  #cw-window .cw-meta-btn:hover {
    background: rgba(var(--cw-ink--rgb), 0.05);
    color: var(--cw-accent);
  }
}

/*
 * "Відповідь допомогла? Так / Ні" at the foot of the latest answer (0.8.0;
 * the 14px grey thumbs got one vote in four weeks). "Ні" opens the reasons.
 */
#cw-window .cw-feedback {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--cw-border-alt);
  color: var(--cw-text-dim);
  font-size: 13px;
  line-height: 1.3;
}

#cw-window .cw-feedback:focus {
  outline: none;
}

#cw-window .cw-fb-q {
  margin-right: 2px;
}

#cw-window .cw-feedback.is-asking .cw-fb-q {
  flex-basis: 100%;
  color: var(--cw-text-strong);
  font-weight: 500;
}

#cw-window .cw-fb-btn,
#cw-window .cw-fb-reason,
#cw-window .cw-fb-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 30px;
  padding: 4px 12px;
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
  color: var(--cw-accent);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  transition: background-color var(--cw-t-small) ease, color var(--cw-t-small) ease,
    border-color var(--cw-t-small) ease, transform var(--cw-t-small) ease;
}

@media (hover: hover) {
  #cw-window .cw-fb-btn:hover,
  #cw-window .cw-fb-reason:hover,
  #cw-window .cw-fb-send:not(:disabled):hover {
    background: rgba(var(--cw-tint--rgb), 0.07);
    border-color: rgba(var(--cw-tint--rgb), 0.45);
  }
}

#cw-window .cw-fb-btn:active,
#cw-window .cw-fb-reason:active,
#cw-window .cw-fb-send:active {
  transform: scale(0.97);
}

#cw-window .cw-fb-reasons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#cw-window .cw-fb-reason[aria-pressed="true"] {
  background: var(--cw-blue-100);
  border-color: var(--cw-blue-100);
  color: var(--cw-white);
}

#cw-window .cw-fb-line {
  display: flex;
  gap: 6px;
  flex-basis: 100%;
  min-width: 0;
}

#cw-window .cw-fb-comment {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 34px;
  padding: 6px 10px;
  background: var(--cw-surface);
  border: 1px solid var(--cw-border-light);
  color: var(--cw-text-body);
  font-size: 13px;
}

#cw-window .cw-fb-comment:focus {
  border-color: var(--cw-accent);
  outline: none;
}

#cw-window .cw-fb-comment::placeholder {
  color: var(--cw-text-faint);
  opacity: 1;
}

#cw-window .cw-fb-send {
  flex: none;
  background: var(--cw-blue-100);
  border-color: var(--cw-blue-100);
  color: var(--cw-white);
}

#cw-window .cw-fb-send:disabled {
  background: var(--cw-fill);
  border-color: var(--cw-border);
  color: var(--cw-text-dim);
  cursor: not-allowed;
}

#cw-window .cw-feedback-thanks {
  color: var(--cw-text-dim);
  font-size: 13px;
}

#cw-window .cw-feedback .cw-contacts {
  flex-basis: 100%;
  margin-top: 4px;
}

/* Welcome card: greeting, what is searched, "who are you?" */
#cw-window .cw-welcome {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px 12px;
}

#cw-window .cw-welcome-hello {
  color: var(--cw-text-strong);
  font-weight: 600;
  line-height: 1.4;
}

#cw-window .cw-welcome-text {
  color: var(--cw-text);
  line-height: 1.6;
}

#cw-window .cw-welcome-scope {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  color: var(--cw-text-dim);
  font-size: 12px;
  line-height: 1.45;
}

#cw-window .cw-welcome-scope svg {
  margin-top: 1px;
  color: var(--cw-link);
}

#cw-window .cw-welcome-roles {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--cw-border-alt);
}

#cw-window .cw-welcome-label {
  color: var(--cw-text-strong);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
}

/* Four roles: a tidy 2x2 grid in the narrow window, one row when wider. */
#cw-window .cw-pills {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 6px;
}

/* Quick questions and every other chip: the original canned-answer buttons. */
#cw-window .cw-chip,
#cw-window .cw-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-height: 34px;
  padding: 7px 14px;
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  color: var(--cw-accent);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  user-select: none;
  transition: background-color var(--cw-t-small) ease, color var(--cw-t-small) ease,
    border-color var(--cw-t-small) ease, transform var(--cw-t-small) ease;
}

@media (hover: hover) {
  #cw-window .cw-chip:hover,
  #cw-window .cw-pill:hover {
    background: var(--cw-blue-100);
    border-color: var(--cw-blue-100);
    color: var(--cw-white);
  }
}

#cw-window .cw-chip:active,
#cw-window .cw-pill:active {
  transform: scale(0.97);
}

/*
 * The quick questions and the ready answers under a reply: a thin outline,
 * no fill and no shadow; under the pointer a light wash, not the solid blue.
 * The red retry keeps its own look.
 */
#cw-window .cw-chip:not(.cw-retry) {
  min-height: 32px;
  padding: 6px 12px;
  background: transparent;
  border-color: var(--cw-border);
  box-shadow: none;
}

@media (hover: hover) {
  #cw-window .cw-chip:not(.cw-retry):hover {
    background: rgba(var(--cw-tint--rgb), 0.06);
    border-color: rgba(var(--cw-tint--rgb), 0.45);
    color: var(--cw-accent);
  }
}

#cw-window .cw-suggestions-wrap,
#cw-window .cw-ask-ai-wrap,
#cw-window .cw-retry-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

#cw-window .cw-suggestions-wrap .cw-chip,
#cw-window .cw-ask-ai {
  justify-content: flex-start;
  text-align: left;
  white-space: normal;
}

#cw-window .cw-restyle-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

#cw-window .cw-restyle-wrap .cw-chip {
  min-height: 28px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--cw-text-muted);
  background: transparent;
  box-shadow: none;
}

#cw-window .cw-retry {
  background: var(--cw-red);
  border-color: var(--cw-red);
  color: var(--cw-white);
}

/* The row of quick questions above the input (as in 1.2), per role. */
#cw-window .cw-suggestions {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  flex: none;
  padding: 10px 15px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--cw-bg);
  cursor: grab;
  scrollbar-width: thin;
  scrollbar-color: var(--cw-scroll) transparent;
  touch-action: pan-x;
}

#cw-window .cw-suggestions::-webkit-scrollbar {
  height: 6px;
}

#cw-window .cw-suggestions::-webkit-scrollbar-thumb {
  background-color: var(--cw-scroll);
}

#cw-window .cw-suggestions.is-dragging {
  cursor: grabbing;
}

/* A fade on the side where more chips are: on a phone the row was simply cut off. */
#cw-window .cw-suggestions.has-more-right {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent);
}

#cw-window .cw-suggestions.has-more-left {
  -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 40px), transparent);
  mask-image: linear-gradient(to left, #000 calc(100% - 40px), transparent);
}

#cw-window .cw-suggestions.has-more-left.has-more-right {
  -webkit-mask-image: linear-gradient(to right, transparent, #000 40px, #000 calc(100% - 40px), transparent);
  mask-image: linear-gradient(to right, transparent, #000 40px, #000 calc(100% - 40px), transparent);
}

/* The answers to a clarifying question: one tap asks with that text. */
#cw-window .cw-options-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

#cw-window .cw-option {
  min-height: 36px;
  background: rgba(var(--cw-tint--rgb), 0.07);
  border-color: rgba(var(--cw-tint--rgb), 0.35);
  white-space: normal;
  text-align: left;
}

/* Typing indicator */
#cw-window .cw-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 14px;
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

#cw-window .cw-typing-wrapper .cw-avatar {
  margin-bottom: 0;
}

#cw-window .cw-typing-dots {
  display: inline-flex;
  gap: 3px;
}

#cw-window .cw-typing-dots i {
  display: block;
  width: 5px;
  height: 5px;
  background: var(--cw-accent);
  border-radius: 50% !important;
  animation: cw-typing-bounce 1.4s infinite ease-in-out both;
}

#cw-window .cw-typing-dots i:nth-child(1) { animation-delay: -0.32s; }
#cw-window .cw-typing-dots i:nth-child(2) { animation-delay: -0.16s; }

#cw-window .cw-typing-text {
  color: var(--cw-text-hint);
  font-size: 13px;
  font-style: italic;
  font-weight: 500;
  line-height: 1.3;
  transition: opacity 0.2s ease;
}

/* Answer text */
#cw-window .cw-formatted-text {
  color: var(--cw-text-body);
  font-size: var(--cw-fs);
  line-height: 1.65;
}

#cw-window .cw-formatted-text strong,
#cw-window .cw-label {
  color: var(--cw-text-strong);
  font-weight: 600;
}

#cw-window .cw-label {
  margin-right: 5px;
}

#cw-window .cw-formatted-text ul.cw-list,
#cw-window .cw-formatted-text ol.cw-list {
  margin: 8px 0;
  padding-left: 20px;
}

#cw-window .cw-formatted-text ul.cw-list {
  list-style: disc;
}

#cw-window .cw-formatted-text ol.cw-list {
  list-style: decimal;
}

#cw-window .cw-list-item {
  display: list-item;
  margin-bottom: 4px;
  line-height: 1.6;
}

#cw-window .cw-list-item::marker {
  color: var(--cw-link);
  font-weight: 600;
}

#cw-window .cw-spacer {
  height: 4px;
}

#cw-window .cw-link {
  color: var(--cw-link);
  font-weight: 500;
  overflow-wrap: anywhere;
  transition: color 0.2s ease;
}

@media (hover: hover) {
  #cw-window .cw-link:hover {
    color: var(--cw-link-hover);
    text-decoration: underline;
  }
}

#cw-window .cw-link-icon {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 3px;
  vertical-align: -1px;
  opacity: 0.7;
}

#cw-window .cw-stopped {
  color: var(--cw-text-muted);
  font-size: 12px;
  font-style: italic;
}

/*
 * Sources: one quiet line under the answer, "ДЖЕРЕЛА 3", that opens into a
 * list of one line per source, the title and then a document's type and
 * page or a web page's host. As cards with icons they took half the answer.
 */
#cw-window .cw-sources-block {
  display: block;
  margin-top: 10px;
  border-top: 1px solid var(--cw-border-alt);
}

#cw-window .cw-sources-title {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding-top: 2px;
  color: var(--cw-text-dim);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  list-style: none;
  cursor: pointer;
  user-select: none;
}

#cw-window .cw-sources-title::-webkit-details-marker {
  display: none;
}

#cw-window .cw-sources-count {
  color: var(--cw-text-muted);
  font-weight: 500;
}

#cw-window .cw-sources-title svg {
  color: var(--cw-text-muted);
  transition: transform var(--cw-t-panel) var(--cw-spring);
}

#cw-window .cw-sources-block[open] > .cw-sources-title svg {
  transform: rotate(180deg);
}

@media (hover: hover) {
  #cw-window .cw-sources-title:hover,
  #cw-window .cw-sources-title:hover svg {
    color: var(--cw-text-strong);
  }
}

#cw-window .cw-sources {
  display: flex;
  flex-direction: column;
  padding-bottom: 2px;
}

#cw-window .cw-sources-block[open] > .cw-sources {
  animation: cw-drop-in 280ms var(--cw-spring) both;
}

#cw-window .cw-source {
  display: block;
  min-width: 0;
}

#cw-window .cw-source-link {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  padding: 4px 0;
  color: var(--cw-link);
  font-size: 13px;
  line-height: 1.35;
  text-decoration: none;
}

#cw-window .cw-source-title {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#cw-window .cw-source-meta {
  flex: none;
  color: var(--cw-text-muted);
  font-size: 11.5px;
  white-space: nowrap;
}

/* The date of a cited document ("від 16.04.2026", or the year). */
#cw-window .cw-source-date {
  flex: none;
  padding: 1px 6px;
  background: rgba(var(--cw-tint--rgb), 0.08);
  color: var(--cw-text-soft);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
  white-space: nowrap;
}

@media (hover: hover) {
  #cw-window .cw-source-link:hover .cw-source-title {
    color: var(--cw-link-hover);
    text-decoration: underline;
  }
}

/* "New conversation": the line where an idle conversation was left behind. */
#cw-window .cw-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  align-self: stretch;
  max-width: none;
  color: var(--cw-text-dim);
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
}

#cw-window .cw-divider::before,
#cw-window .cw-divider::after {
  content: "";
  flex: 1 1 0;
  height: 1px;
  background: var(--cw-border);
}

#cw-window .cw-divider span {
  flex: 0 1 auto;
  max-width: 75%;
}

/* Contacts of the department that can help */
#cw-window .cw-contacts {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 10px;
  padding: 8px 10px;
  background: rgba(var(--cw-tint--rgb), 0.05);
  border-left: 3px solid var(--cw-accent);
  font-size: 0.92em;
  line-height: 1.45;
}

#cw-window .cw-contacts-title {
  color: var(--cw-text-dim);
  font-size: 12px;
}

#cw-window .cw-contacts-name {
  color: var(--cw-text-strong);
  font-weight: 600;
}

#cw-window .cw-contacts-line {
  display: block;
}

/* «Зв'язатися з людиною»: the same cards as a list in a panel. */
#cw-window .cw-contacts-panel {
  margin: 0 0 10px;
  padding: 10px 12px;
}

#cw-window .cw-contacts-panel .cw-link {
  display: inline-block;
  padding: 2px 0;
}

#cw-window .cw-contacts-group {
  margin: 16px 0 8px;
  color: var(--cw-text-dim);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

/* --- 8. Footer: input, one line of fine print, the author ------------------------------- */

#cw-window .cw-footer {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: none;
  padding: 12px 15px 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--cw-chrome);
  border-top: 1px solid var(--cw-line);
}

#cw-window .cw-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

/*
 * While the server does not answer (script.js, setServerDown) a note takes
 * the place of the input, so there is nothing to type a question into; the
 * quick questions and the sections that need the server go too, and the
 * header says "unavailable". The conversation so far stays readable.
 */
#cw-window .cw-offline {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 10px 12px;
  background: var(--cw-surface-soft);
  border: 1px solid var(--cw-border);
  border-left: 3px solid var(--cw-red);
}

#cw-window .cw-offline-title {
  margin: 0;
  color: var(--cw-text-strong);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

#cw-window .cw-offline-text {
  margin: 0 0 4px;
  color: var(--cw-text-dim);
  font-size: 13px;
  line-height: 1.45;
}

#cw-window.is-offline .cw-input-row {
  display: none;
}

#cw-window.is-offline .cw-status-dot {
  background: var(--cw-text-muted);
}

#cw-window.is-offline .cw-status-dot::after {
  animation: none;
}

/* Buttons in the conversation that would ask the server again. */
#cw-window.is-offline .js-retry-ai,
#cw-window.is-offline .js-suggestion-btn,
#cw-window.is-offline .js-option-btn,
#cw-window.is-offline .js-ask-ai {
  opacity: 0.45;
  pointer-events: none;
}

#cw-window .cw-tool:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

#cw-window .cw-tool:disabled:hover {
  background: transparent;
}

#cw-window .cw-cut {
  display: block;
  margin-top: 10px;
}

/*
 * Clear the chat: the bin left of the input (as in 1.2, where it sat above
 * it), with "Clear the chat? No / Yes" popping up over it. Disabled while
 * there is nothing to clear and while an answer is coming.
 */
#cw-window .cw-clear {
  position: relative;
  flex: none;
}

#cw-window .cw-clear-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 40px;
  color: var(--cw-text-muted);
  transition: background-color var(--cw-t-small) ease, color var(--cw-t-small) ease, transform var(--cw-t-small) ease;
}

@media (hover: hover) {
  #cw-window .cw-clear-btn:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.1);
    color: var(--cw-red);
  }
}

#cw-window .cw-clear-btn:active:not(:disabled) {
  transform: scale(0.94);
}

#cw-window .cw-clear-btn[aria-expanded="true"] {
  background: rgba(239, 68, 68, 0.1);
  color: var(--cw-red);
}

#cw-window .cw-clear-btn:disabled {
  cursor: default;
  opacity: 0.4;
}

#cw-window .cw-clear-confirm {
  position: absolute;
  left: -4px;
  bottom: calc(100% + 10px);
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.12);
  animation: cw-drop-in 200ms var(--cw-spring) both;
}

/* The little arrow pointing at the bin. */
#cw-window .cw-clear-confirm::after {
  content: "";
  position: absolute;
  left: 15px;
  bottom: -6px;
  width: 10px;
  height: 10px;
  background: var(--cw-surface);
  border-right: 1px solid var(--cw-border);
  border-bottom: 1px solid var(--cw-border);
  transform: rotate(45deg);
}

#cw-window .cw-clear-question {
  color: var(--cw-text-strong);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
}

#cw-window .cw-clear-actions {
  display: flex;
  gap: 6px;
}

#cw-window .cw-clear-actions .cw-btn {
  flex: 1 1 0;
  align-self: auto;
}

#cw-window .cw-input-group {
  position: relative;
  display: flex;
  align-items: flex-end;
  flex: 1 1 auto;
  min-width: 0;
  background: var(--cw-surface);
  border: 1px solid var(--cw-border-light);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#cw-window .cw-input-group:focus-within {
  border-color: var(--cw-accent);
  box-shadow: 0 0 0 3px rgba(var(--cw-tint--rgb), 0.1);
}

#cw-window .cw-input {
  display: block;
  width: 100%;
  min-height: 40px;
  max-height: 120px;
  /* Grows with its text up to max-height; script.js does it by hand where this is missing. */
  field-sizing: content;
  margin: 0;
  padding: 10px 44px 10px 14px !important;
  overflow-y: auto;
  background: transparent;
  border: 0 !important;
  border-radius: 0;
  box-shadow: none;
  color: var(--cw-text-body);
  font-size: 14px;
  line-height: 20px;
  resize: none;
  outline: none;
}

#cw-window .cw-input:focus,
#cw-window .cw-input:focus-visible {
  outline: none !important;
}

#cw-window .cw-input::placeholder {
  color: var(--cw-text-faint);
  font-size: 12px;
  font-weight: 400;
  opacity: 1;
}

/* The hint stays on one line instead of wrapping under the field. */
#cw-window .cw-input:placeholder-shown {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  /* keep the one-line hint clear of the microphone button */
  clip-path: inset(0 44px 0 0);
}

#cw-window .cw-input:disabled {
  background: var(--cw-surface-soft);
  cursor: not-allowed;
  opacity: 0.7;
}

#cw-window .cw-input-action-btn {
  position: absolute;
  right: 4px;
  bottom: 4px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: var(--cw-text-muted);
  transition: background-color 0.2s ease, color 0.2s ease;
}

@media (hover: hover) {
  #cw-window .cw-input-action-btn:hover {
    background: rgba(var(--cw-tint--rgb), 0.05);
    color: var(--cw-accent);
  }
}

#cw-window .cw-input-action-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: rgba(239, 68, 68, 0.15);
  border-radius: 50% !important;
  opacity: 0;
  transform: scale(var(--mic-scale, 0));
  transition: transform 0.05s linear;
}

#cw-window .cw-input-action-btn.is-recording {
  color: var(--cw-red);
}

#cw-window .cw-input-action-btn.is-recording::before {
  opacity: 1;
}

#cw-window .cw-input-action-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

#cw-window .cw-send-btn,
#cw-window .cw-stop-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 40px;
  height: 40px;
  transition: background-color 0.2s ease, color 0.2s ease, transform var(--cw-t-small) ease;
}

#cw-window .cw-send-btn {
  background: var(--cw-blue-100);
  color: var(--cw-white);
}

/* An arrow up, as in the chat apps people know; a firmer line than the other icons. */
#cw-window .cw-send-btn svg {
  stroke-width: 2.25;
}

@media (hover: hover) {
  #cw-window .cw-send-btn:hover {
    background: var(--cw-blue-200);
  }
}

#cw-window .cw-send-btn:active,
#cw-window .cw-stop-btn:active {
  transform: scale(0.94);
}

#cw-window .cw-send-btn:disabled {
  cursor: not-allowed;
  filter: grayscale(1);
  opacity: 0.5;
}

#cw-window .cw-stop-btn {
  background: var(--cw-line);
  color: var(--cw-text-soft);
}

@media (hover: hover) {
  #cw-window .cw-stop-btn:hover {
    background: var(--cw-red);
    color: var(--cw-white);
  }
}

/* "AI can make mistakes · Privacy", then the author: the original footer lines. */
#cw-window .cw-footer-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  color: var(--cw-text-hint);
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
}

#cw-window .cw-footnote {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

/* A 24px target for 11px text: padding the line around it absorbs. */
#cw-window .cw-footnote-link {
  margin: -5px 0;
  padding: 5px 2px;
  color: inherit;
  font-size: inherit;
  line-height: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* The input's length near its 300-character limit. */
#cw-window .cw-counter {
  position: absolute;
  right: 0;
  bottom: calc(100% + 3px);
  padding: 1px 6px;
  background: var(--cw-chrome);
  color: var(--cw-text-dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
  pointer-events: none;
}

#cw-window .cw-counter.is-full {
  color: var(--cw-warn);
  font-weight: 600;
}

@media (hover: hover) {
  #cw-window .cw-footnote-link:hover {
    color: var(--cw-accent);
  }
}

#cw-window .cw-author {
  display: block;
}

/* --- 9. Panels (news, events, FAQ, settings) ---------------------------------- */

/*
 * A panel grows out of the button that opened it (--cw-origin, set by the
 * script) and shrinks back into it; on a phone it is a sheet that slides up.
 * "is-open" drives both ways, so a panel closed mid-opening turns back from
 * where it is.
 */
#cw-window .cw-panel {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: var(--cw-surface-soft);
  opacity: 0;
  transform: translateY(-8px) scale(0.97);
  transform-origin: var(--cw-origin, 50% 0);
  transition: transform 220ms var(--cw-spring), opacity 160ms ease;
  will-change: transform, opacity;
  pointer-events: none;
}

#cw-window .cw-panel.is-open {
  opacity: 1;
  transform: none;
  transition: transform var(--cw-t-panel) var(--cw-spring), opacity var(--cw-t-fade) ease;
  pointer-events: auto;
}

/* The next screen inside a panel (a faculty, a group) slides in. */
#cw-window .cw-panel-body.is-entering > * {
  animation: cw-screen-in 260ms var(--cw-spring) both;
}

#cw-window.cw-panel-open .cw-footer,
#cw-window.cw-panel-open .cw-suggestions {
  display: none;
}

#cw-window .cw-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  padding: 8px 10px;
  background: var(--cw-chrome);
  border-bottom: 1px solid var(--cw-border-light);
  touch-action: none;
}

#cw-window .cw-panel-title {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0 4px;
  overflow: hidden;
  color: var(--cw-text-strong);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  text-overflow: ellipsis;
}

#cw-window .cw-panel-title:focus {
  outline: none !important;
}

#cw-window .cw-panel-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 36px;
  height: 36px;
  color: var(--cw-text-soft);
  transition: background-color var(--cw-t-small) ease, color var(--cw-t-small) ease, transform var(--cw-t-small) ease;
}

@media (hover: hover) {
  #cw-window .cw-panel-btn:hover {
    background: var(--cw-fill);
    color: var(--cw-text-strong);
  }
}

#cw-window .cw-panel-btn:active {
  transform: scale(0.94);
}

#cw-window .cw-panel-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px 14px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  color: var(--cw-text-body);
  font-size: var(--cw-fs);
  line-height: 1.45;
  scrollbar-width: thin;
  scrollbar-color: var(--cw-scroll) transparent;
}

#cw-window .cw-panel-body > * {
  flex: none;
}

#cw-window .cw-panel-status {
  margin: 4px 0;
  color: var(--cw-text-dim);
  font-size: 13px;
}

#cw-window .cw-panel-status.is-error {
  color: var(--cw-red);
}

#cw-window .cw-panel-hint {
  color: var(--cw-text-dim);
  font-size: 13px;
  line-height: 1.45;
}

#cw-window .cw-panel-foot {
  margin-top: 2px;
  font-size: 13px;
  text-align: center;
}

/* Buttons */
#cw-window .cw-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  align-self: flex-start;
  min-height: 36px;
  padding: 6px 14px;
  background: var(--cw-blue-100);
  border: 1px solid var(--cw-blue-100);
  color: var(--cw-white);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform var(--cw-t-small) ease;
}

#cw-window .cw-btn:active {
  transform: scale(0.97);
}

#cw-window .cw-btn-sm {
  min-height: 30px;
  padding: 4px 10px;
  font-size: 12.5px;
}

#cw-window .cw-btn-ghost {
  background: var(--cw-surface);
  border-color: var(--cw-border);
  color: var(--cw-accent);
}

#cw-window .cw-btn-danger {
  background: var(--cw-red);
  border-color: var(--cw-red);
  color: var(--cw-white);
}

#cw-window .cw-btn-danger-text {
  color: var(--cw-red);
}

@media (hover: hover) {
  #cw-window .cw-btn:hover {
    background: var(--cw-blue-200);
    border-color: var(--cw-blue-200);
    color: var(--cw-white);
  }

  #cw-window .cw-btn-danger:hover,
  #cw-window .cw-btn-danger-text:hover {
    background: var(--cw-red);
    border-color: var(--cw-red);
    color: var(--cw-white);
  }
}

/* Segmented control: the original choice buttons, the chosen one filled. */
#cw-window .cw-segmented {
  display: inline-flex;
  align-self: flex-start;
  gap: 4px;
  flex: none;
}

#cw-window .cw-seg-btn {
  flex: 1 1 auto;
  min-height: 32px;
  padding: 4px 12px;
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
  color: var(--cw-text-body);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

@media (hover: hover) {
  #cw-window .cw-seg-btn:hover {
    border-color: var(--cw-accent);
  }
}

#cw-window .cw-seg-btn[aria-checked="true"] {
  background: var(--cw-blue-100);
  border-color: var(--cw-blue-100);
  color: var(--cw-white);
}

/* Select */
#cw-window .cw-select {
  min-height: 32px;
  max-width: 180px;
  padding: 4px 30px 4px 10px;
  background-color: var(--cw-surface);
  background-image: var(--cw-select-arrow);
  background-position: right 8px center;
  background-repeat: no-repeat;
  background-size: 14px 14px;
  border: 1px solid var(--cw-border);
  border-radius: 0;
  color: var(--cw-text-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

/* Settings */
#cw-window .cw-set-group {
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
  transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

#cw-window .cw-set-group.is-highlighted {
  border-color: var(--cw-accent);
  box-shadow: 0 0 0 3px rgba(var(--cw-tint--rgb), 0.1);
}

#cw-window .cw-set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  min-height: 48px;
  padding: 8px 12px;
}

#cw-window .cw-set-row + .cw-set-row {
  border-top: 1px solid var(--cw-line);
}

#cw-window .cw-set-row.is-stacked {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

#cw-window .cw-set-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
  color: var(--cw-text-strong);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.3;
}

#cw-window .cw-set-value {
  color: var(--cw-text-dim);
  font-size: 12.5px;
  font-weight: 400;
  line-height: 1.3;
}

#cw-window .cw-set-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

#cw-window .cw-confirm-text {
  color: var(--cw-text-soft);
  font-size: 12.5px;
}

#cw-window .cw-set-note {
  color: var(--cw-text-soft);
  font-size: 12.5px;
  line-height: 1.5;
}

#cw-window .cw-set-row .cw-link {
  font-size: 12.5px;
}

#cw-window .cw-set-foot {
  padding: 2px 8px 4px;
  color: var(--cw-text-muted);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

#cw-window .cw-pick {
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
}

#cw-window .cw-pick > li + li {
  border-top: 1px solid var(--cw-line);
}

#cw-window .cw-pick-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px 8px 12px;
  color: var(--cw-text-body);
  text-align: left;
  transition: background-color var(--cw-t-small) ease;
}

@media (hover: hover) {
  #cw-window .cw-pick-btn:hover {
    background: rgba(var(--cw-tint--rgb), 0.04);
  }
}

#cw-window .cw-pick-btn:active {
  background: rgba(var(--cw-tint--rgb), 0.08);
}

#cw-window .cw-pick-btn svg {
  color: var(--cw-text-muted);
}

#cw-window .cw-pick-name {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--cw-accent);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.35;
}

/* News and events */
#cw-window .cw-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#cw-window .cw-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
}

#cw-window .cw-card-meta {
  color: var(--cw-text-dim);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
}

#cw-window .cw-card-title {
  color: var(--cw-accent);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

@media (hover: hover) {
  #cw-window a.cw-card-title:hover {
    text-decoration: underline;
  }
}

#cw-window .cw-card-text {
  display: -webkit-box;
  overflow: hidden;
  color: var(--cw-text-soft);
  font-size: 13px;
  line-height: 1.45;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

#cw-window .cw-card-place {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--cw-text-soft);
  font-size: 12.5px;
  line-height: 1.35;
}

#cw-window .cw-card-place svg {
  color: var(--cw-link);
}

#cw-window .cw-ics-btn {
  margin-top: 4px;
}

/* FAQ */
#cw-window .cw-faq {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#cw-window .cw-faq-section {
  display: block;
  background: var(--cw-surface);
  border: 1px solid var(--cw-border);
}

#cw-window .cw-faq-section > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--cw-text-strong);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
  list-style: none;
  cursor: pointer;
}

#cw-window .cw-faq-section > summary::-webkit-details-marker {
  display: none;
}

#cw-window .cw-faq-section > summary svg {
  color: var(--cw-accent);
  transition: transform var(--cw-t-panel) var(--cw-spring);
}

#cw-window .cw-faq-section[open] > summary svg {
  transform: rotate(180deg);
}

#cw-window .cw-faq-section[open] > .cw-faq-items {
  animation: cw-drop-in 280ms var(--cw-spring) both;
}

@media (hover: hover) {
  #cw-window .cw-faq-section > summary:hover {
    background: rgba(var(--cw-tint--rgb), 0.04);
  }
}

#cw-window .cw-faq-items {
  border: 0;
  border-top: 1px solid var(--cw-line);
}

#cw-window .cw-faq-items .cw-pick-name {
  font-weight: 400;
}

/* --- 9b. Expanded view: chats and sections in a sidebar, a centred column ------------- */

/*
 * The full-screen window, like a chat assistant's own page: on a wide screen
 * the sidebar (built by the script) holds a new chat, this browser's chats
 * and the sections; the conversation, the quick questions and the input keep
 * to one readable column in the middle. Narrower, the toolbar stays and only
 * the column is centred.
 */
html.cw-expanded-lock,
html.cw-expanded-lock body {
  overflow: hidden !important;
}

#cw-window .cw-side {
  display: none;
}

#cw-window.is-expanded {
  --cw-col: 820px;
  --cw-col-pad: max(24px, calc((100% - var(--cw-col)) / 2));
}

#cw-window.is-expanded .cw-content {
  padding: 24px 24px 16px;
}

#cw-window.is-expanded .cw-content-wrapper::before {
  background-size: 240px auto;
}

#cw-window.is-expanded .cw-messages {
  width: 100%;
  max-width: var(--cw-col);
  margin: 0 auto;
  gap: 16px;
}

#cw-window.is-expanded .cw-msg-bot {
  max-width: 100%;
}

#cw-window.is-expanded .cw-msg-user {
  max-width: 80%;
}

#cw-window.is-expanded .cw-text {
  padding: 10px 16px;
  font-size: calc(var(--cw-fs) + 1px);
}

/*
 * The quick questions (shown before the first question): one centred line of
 * compact pills, wrapped when they do not fit; the full question is the
 * title. Cards with the question under the topic took three rows (25.10).
 */
#cw-window .cw-chip-q {
  display: none;
}

#cw-window.is-expanded .cw-suggestions {
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 10px var(--cw-col-pad) 2px;
  overflow: visible;
  background: transparent;
  border-top: 0;
  cursor: default;
  touch-action: auto;
}

#cw-window.is-expanded .cw-suggestions .cw-chip {
  min-height: 34px;
  padding: 6px 16px;
  font-size: 13.5px;
  cursor: pointer;
}

#cw-window.is-expanded .cw-suggestions.has-more-left,
#cw-window.is-expanded .cw-suggestions.has-more-right {
  -webkit-mask-image: none;
  mask-image: none;
}

#cw-window.is-expanded .cw-footer {
  gap: 10px;
  padding: 12px var(--cw-col-pad) max(14px, env(safe-area-inset-bottom));
  background: var(--cw-bg);
  border-top: 0;
}

/* The input: one wide field with a soft shadow, at a size for a desk. */
#cw-window.is-expanded .cw-input-row {
  gap: 8px;
}

#cw-window.is-expanded .cw-input-group {
  border-color: var(--cw-border);
  box-shadow: 0 2px 10px rgba(var(--cw-tint--rgb), 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
}

#cw-window.is-expanded .cw-input-group:focus-within {
  border-color: var(--cw-accent);
  box-shadow: 0 2px 14px rgba(var(--cw-tint--rgb), 0.14), 0 0 0 3px rgba(var(--cw-tint--rgb), 0.1);
}

#cw-window.is-expanded .cw-input {
  min-height: 56px;
  max-height: 200px;
  padding: 17px 56px 17px 18px !important;
  font-size: 15px;
  line-height: 22px;
}

#cw-window.is-expanded .cw-input::placeholder {
  font-size: 15px;
}

#cw-window.is-expanded .cw-input-action-btn {
  right: 10px;
  bottom: 12px;
}

#cw-window.is-expanded .cw-send-btn,
#cw-window.is-expanded .cw-stop-btn {
  width: 56px;
  height: 56px;
}

#cw-window.is-expanded .cw-clear-btn {
  height: 56px;
}

#cw-window.is-expanded .cw-footer-bottom {
  font-size: 11.5px;
}

#cw-window.is-expanded .cw-panel-header,
#cw-window.is-expanded .cw-panel-body {
  padding-left: var(--cw-col-pad);
  padding-right: var(--cw-col-pad);
}

@media (min-width: 900px) {
  #cw-window.is-expanded {
    display: grid;
    grid-template-columns: 288px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "head head"
      "side main"
      "side chips"
      "side foot";
  }

  #cw-window.is-expanded > .cw-header {
    grid-area: head;
  }

  #cw-window.is-expanded > .cw-toolbar {
    display: none;
  }

  #cw-window.is-expanded > .cw-side {
    grid-area: side;
    display: flex;
  }

  #cw-window.is-expanded > .cw-content-wrapper {
    grid-area: main;
  }

  #cw-window.is-expanded > .cw-suggestions {
    grid-area: chips;
  }

  #cw-window.is-expanded > .cw-footer {
    grid-area: foot;
  }

  /* Before the first question the greeting sits over the cards, by the input. */
  #cw-window.is-expanded:not(:has(.cw-msg-user)) .cw-content {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
  }
}

#cw-window .cw-side {
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  padding: 14px 12px 10px;
  overflow: hidden;
  background: var(--cw-surface-soft);
  border-right: 1px solid var(--cw-line);
}

#cw-window .cw-side-new {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  height: 42px;
  padding: 0 14px;
  background: var(--cw-blue-100);
  color: var(--cw-white);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--cw-t-small) ease, transform var(--cw-t-small) ease;
}

@media (hover: hover) {
  #cw-window .cw-side-new:not(:disabled):hover {
    background: var(--cw-blue-400);
  }
}

#cw-window .cw-side-new:active {
  transform: scale(0.98);
}

#cw-window .cw-side-new:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* The theme styles search fields (padding, a large placeholder): reset here. */
#cw-window .cw-side-search {
  flex: none;
  width: 100%;
  height: 36px;
  margin: 8px 0 0;
  padding: 0 10px !important;
  background: var(--cw-surface);
  border: 1px solid var(--cw-border) !important;
  border-radius: 0;
  box-shadow: none;
  color: var(--cw-text-strong);
  font-size: 13px;
  line-height: 34px;
  -webkit-appearance: none;
  appearance: none;
}

#cw-window .cw-side-search::placeholder {
  color: var(--cw-text-hint);
  font-size: 13px;
  opacity: 1;
}

#cw-window .cw-side-search:focus {
  border-color: var(--cw-focus);
  outline: 2px solid rgba(var(--cw-tint--rgb), 0.18);
  outline-offset: 0;
}

#cw-window .cw-side-title {
  flex: none;
  margin: 12px 6px 2px;
  color: var(--cw-text-faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#cw-window .cw-side-chats {
  flex: 1 1 auto;
  min-height: 60px;
  margin: 0 -4px;
  padding: 0 4px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--cw-scroll) transparent;
}

#cw-window .cw-side-group {
  margin: 8px 6px 2px;
  color: var(--cw-text-faint);
  font-size: 12px;
}

#cw-window .cw-side-group:first-child {
  margin-top: 2px;
}

#cw-window .cw-side-empty {
  padding: 6px;
  color: var(--cw-text-dim);
  font-size: 13px;
  line-height: 1.45;
}

#cw-window .cw-side-item {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 36px;
}

#cw-window .cw-side-chat {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 34px 8px 10px;
  overflow: hidden;
  border-radius: 4px;
  color: var(--cw-text-body);
  font-size: 13.5px;
  line-height: 1.35;
  text-align: left;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: background-color var(--cw-t-small) ease;
}

@media (hover: hover) {
  #cw-window .cw-side-chat:not(:disabled):hover {
    background: rgba(var(--cw-tint--rgb), 0.06);
  }
}

#cw-window .cw-side-chat[aria-current="true"] {
  background: rgba(var(--cw-tint--rgb), 0.1);
  color: var(--cw-text-strong);
  font-weight: 500;
}

#cw-window .cw-side-chat:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

#cw-window .cw-side-del {
  position: absolute;
  top: 50%;
  right: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  color: var(--cw-text-faint);
  cursor: pointer;
  opacity: 0;
  transform: translateY(-50%);
  transition: opacity var(--cw-t-small) ease, color var(--cw-t-small) ease;
}

#cw-window .cw-side-item:hover .cw-side-del,
#cw-window .cw-side-item:focus-within .cw-side-del,
#cw-window .cw-side-item.is-current .cw-side-del {
  opacity: 1;
}

@media (hover: none) {
  #cw-window .cw-side-del {
    opacity: 1;
  }
}

@media (hover: hover) {
  #cw-window .cw-side-del:not(:disabled):hover {
    color: var(--cw-red);
  }
}

#cw-window .cw-side-del:disabled {
  visibility: hidden;
}

#cw-window .cw-side-item.is-confirm {
  gap: 6px;
  padding: 4px 6px 4px 10px;
  background: rgba(239, 68, 68, 0.07);
  border-radius: 4px;
}

#cw-window .cw-side-confirm {
  flex: 1 1 auto;
  color: var(--cw-text-strong);
  font-size: 13px;
}

#cw-window .cw-side-note {
  flex: none;
  padding: 6px 6px 2px;
  color: var(--cw-text-faint);
  font-size: 11.5px;
  line-height: 1.4;
}

#cw-window .cw-side-nav {
  display: flex;
  flex-direction: column;
  flex: none;
  margin-top: 6px;
  padding-top: 2px;
  border-top: 1px solid var(--cw-line);
}

#cw-window .cw-side-nav .cw-side-title {
  margin-top: 10px;
}

#cw-window .cw-side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 36px;
  padding: 0 10px;
  border-radius: 4px;
  color: var(--cw-accent);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--cw-t-small) ease;
}

#cw-window .cw-side-link .cw-i {
  flex: none;
  width: 18px;
  height: 18px;
}

@media (hover: hover) {
  #cw-window .cw-side-link:hover {
    background: rgba(var(--cw-tint--rgb), 0.06);
  }
}

#cw-window .cw-side-link[aria-current="true"] {
  background: rgba(var(--cw-tint--rgb), 0.1);
}

#cw-window .cw-side-link:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- 10. Phones: a full-screen sheet ------------------------------------------------------ */

@media (max-width: 600px) {
  #cw-launcher {
    left: max(10px, env(safe-area-inset-left));
    bottom: max(10px, env(safe-area-inset-bottom));
  }

  #cw-launcher .cw-floating-btn,
  #cw-launcher .cw-floating-btn.is-active {
    width: 42px;
    height: 42px;
  }

  #cw-launcher .cw-floating-btn svg {
    left: 8px;
    width: 24px;
    height: 24px;
    margin-top: -12px;
  }

  #cw-launcher .cw-btn-text {
    display: none;
  }

  #cw-widget-overlay {
    position: fixed;
    inset: 0;
    z-index: 99998;
    display: block;
    background: var(--cw-overlay, rgba(22, 41, 91, 0.6));
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--cw-t-sheet, 380ms) ease, visibility 0s linear 380ms;
    touch-action: none;
  }

  #cw-widget-overlay.is-active {
    opacity: 1;
    visibility: visible;
    transition: opacity 380ms ease, visibility 0s linear 0s;
  }

  html.cw-scroll-lock,
  html.cw-scroll-lock body {
    overflow: hidden !important;
    overscroll-behavior: none !important;
  }

  /*
   * The sheet follows the visual viewport (--cw-vv-h / --cw-vv-top, set by
   * the script), so the on-screen keyboard never covers the input.
   */
  #cw-window,
  #cw-window.is-expanded {
    top: var(--cw-vv-top, 0px);
    left: 0;
    right: 0;
    bottom: auto;
    width: 100%;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    height: var(--cw-vv-h, 100dvh);
    border: 0;
    box-shadow: 0 -5px 25px rgba(22, 41, 91, 0.15);
    opacity: 1;
    transform: translateY(100%);
    transform-origin: 50% 100%;
    transition: transform 300ms var(--cw-spring), visibility 0s linear 300ms;
  }

  #cw-window.is-open,
  #cw-window.is-open.is-expanded {
    transform: none;
    transition: transform var(--cw-t-sheet) var(--cw-spring), visibility 0s linear 0s;
  }

  #cw-window .js-expand-cw {
    display: none !important;
  }

  #cw-window .cw-header {
    padding-top: max(14px, calc(env(safe-area-inset-top) + 10px));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
    padding-bottom: 8px;
  }

  /* A phone sees more of the conversation (25.10): smaller chrome, targets
     of 34-40px, still above what a finger hits reliably. */
  #cw-window .cw-brand-icon {
    width: 32px;
    height: 32px;
  }

  #cw-window .cw-title {
    font-size: 13.5px;
  }

  /* Grabber: swipe the header down to close. */
  #cw-window .cw-grabber {
    position: absolute;
    top: max(7px, calc(env(safe-area-inset-top) + 2px));
    left: 50%;
    display: block;
    width: 36px;
    height: 4px;
    margin-left: -18px;
    background: rgba(255, 255, 255, 0.45);
    border-radius: 2px !important;
  }

  #cw-window .cw-header-actions {
    gap: 3px;
  }

  #cw-window .cw-action-btn {
    width: 38px;
    height: 38px;
  }

  #cw-window .cw-toolbar {
    gap: 2px;
    padding: 4px max(6px, env(safe-area-inset-right)) 4px max(6px, env(safe-area-inset-left));
  }

  #cw-window .cw-tool {
    gap: 5px;
    height: 36px;
    padding: 0 3px;
    font-size: 12px;
  }

  #cw-window .cw-tool svg {
    width: 16px;
    height: 16px;
  }

  #cw-window .cw-content {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  /* A smaller avatar, the answer in tighter lines. */
  #cw-window .cw-avatar {
    width: 26px;
    height: 26px;
    border-radius: 7px;
  }

  #cw-window .cw-msg-bot {
    max-width: 100%;
  }

  #cw-window .cw-messages {
    gap: 10px;
  }

  #cw-window .cw-text {
    padding: 8px 12px;
    line-height: 1.5;
  }

  #cw-window .cw-suggestions {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  #cw-window .cw-chip,
  #cw-window .cw-pill,
  #cw-window .cw-fb-btn,
  #cw-window .cw-fb-reason,
  #cw-window .cw-fb-send {
    min-height: 34px;
  }

  #cw-window .cw-chip:not(.cw-retry) {
    padding: 5px 11px;
    font-size: 12.5px;
  }

  #cw-window .cw-fb-comment {
    min-height: 40px;
    font-size: 16px;
  }

  #cw-window {
    --cw-meta-h: 36px;
  }

  #cw-window .cw-meta-btn {
    width: 36px;
    height: 36px;
  }

  #cw-window .cw-footer {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  #cw-window .cw-send-btn,
  #cw-window .cw-stop-btn {
    width: 40px;
    height: 40px;
  }

  #cw-window .cw-clear-btn {
    width: 32px;
    height: 40px;
  }

  #cw-window .cw-input {
    min-height: 40px;
    padding-top: 9px !important;
    padding-bottom: 9px !important;
  }

  #cw-window .cw-input-action-btn {
    width: 36px;
    height: 36px;
  }

  /* A finger needs taller rows than a pointer; still one line each. */
  #cw-window .cw-sources-title {
    min-height: 40px;
  }

  #cw-window .cw-source-link {
    padding: 8px 0;
  }

  #cw-window .cw-to-bottom {
    width: 44px;
    height: 44px;
  }

  #cw-window .cw-footnote-link {
    padding: 6px 2px;
    margin: -6px 0;
  }

  /* 16px keeps iOS from zooming into a field; the chat input reads at 14px,
     its zoom held off by maximum-scale while it has the focus (script.js,
     setupMobileViewport). */
  #cw-window .cw-select {
    font-size: 16px;
  }

  /* !important: the zp.edu.ua theme sets 16px !important on every field
     below 900px, for the same zoom. */
  #cw-window .cw-input {
    font-size: 14px !important;
  }

  #cw-window .cw-input::placeholder {
    font-size: 14px;
  }

  /* Panels are sheets over the chat that slide up from the bottom. */
  #cw-window .cw-panel {
    opacity: 1;
    transform: translateY(100%);
    transition: transform 260ms var(--cw-spring);
    box-shadow: 0 -8px 24px rgba(22, 41, 91, 0.12);
  }

  #cw-window .cw-panel.is-open {
    transform: none;
    transition: transform var(--cw-t-sheet) var(--cw-spring);
  }

  #cw-window .cw-panel-header {
    padding: 4px 6px;
  }

  #cw-window .cw-panel-btn {
    width: 44px;
    height: 44px;
  }

  #cw-window .cw-seg-btn,
  #cw-window .cw-select {
    min-height: 40px;
  }

  #cw-window .cw-btn-sm {
    min-height: 36px;
  }

  #cw-window .cw-pick-btn {
    min-height: 48px;
  }
}

@media (max-width: 374px) {
  #cw-window .cw-tool {
    flex-direction: column;
    gap: 2px;
    font-size: 11px;
  }

  #cw-window .cw-tool svg {
    width: 18px;
    height: 18px;
  }

  #cw-window .cw-title {
    font-size: 13px;
    letter-spacing: 0;
  }

  #cw-window .cw-header-left {
    gap: 9px;
  }

  #cw-window .cw-brand-icon {
    width: 36px;
    height: 36px;
  }

  #cw-window .cw-action-btn {
    width: 40px;
  }
}

/* --- 11. Motion ----------------------------------------------------------------------------- */

@keyframes cw-msg-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@keyframes cw-screen-in {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: none; }
}

@keyframes cw-drop-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

/* 6px dot + 5px on each side = 16px: the spread of the former box-shadow. */
@keyframes cw-status-pulse {
  0% { transform: scale(1); opacity: 1; }
  70% { transform: scale(2.667); opacity: 0; }
  100% { transform: scale(1); opacity: 0; }
}

@keyframes cw-typing-bounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

@keyframes cw-spin-in {
  from { opacity: 0; transform: rotate(-90deg); }
  to { opacity: 1; transform: rotate(0); }
}

@keyframes cw-bounce {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  30% { transform: translateY(-10px) scale(0.9, 1.1); }
  50% { transform: translateY(0) scale(1.1, 0.9); }
  75% { transform: translateY(-3px) scale(0.95, 1.05); }
}

/* Reduced motion: no slides or scaling, only short cross-fades. */
@media (prefers-reduced-motion: reduce) {
  #cw-window,
  #cw-window.is-open,
  #cw-window .cw-panel,
  #cw-window .cw-panel.is-open {
    transform: none !important;
    transition: opacity 150ms ease, visibility 0s linear 150ms !important;
  }

  #cw-window.is-open,
  #cw-window .cw-panel.is-open {
    transition: opacity 150ms ease, visibility 0s linear 0s !important;
  }

  #cw-window:not(.is-open),
  #cw-window .cw-panel:not(.is-open) {
    opacity: 0 !important;
  }

  #cw-window *,
  #cw-launcher *,
  #cw-widget-overlay {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }

  #cw-launcher .cw-floating-btn,
  #cw-launcher .cw-invite,
  #cw-window .cw-chip,
  #cw-window .cw-pill,
  #cw-window .cw-btn,
  #cw-window .cw-tool {
    transform: none !important;
  }
}
