/* ============================================
   ARSKASOFT // CHAT WIDGET
   Pulls /chat/stream — same backend as full chat
   ============================================ */

#aw-widget,
#aw-widget * { box-sizing: border-box; }

#aw-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  color: #f5f0ff;
}

/* ── Floating launcher button ── */
.aw-launcher {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3d0852, #6b0a5a);
  border: 2px solid #ff2cb6;
  box-shadow:
    0 0 18px rgba(255, 44, 182, 0.6),
    0 0 40px rgba(107, 10, 90, 0.6),
    inset 0 0 14px rgba(255, 44, 182, 0.2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffb3df;
  transition: all 0.25s ease;
  position: relative;
}

.aw-launcher:hover {
  transform: scale(1.08);
  box-shadow:
    0 0 26px rgba(255, 44, 182, 0.9),
    0 0 60px rgba(138, 0, 138, 0.7);
}

.aw-launcher svg {
  width: 32px;
  height: 32px;
}

#aw-widget.open .aw-launcher {
  display: none;
}

/* ── Persistent greeting bubble next to the launcher ── */
.aw-greeting {
  position: absolute;
  bottom: 80px;        /* sits above the 68px launcher with a gap */
  right: 0;
  width: max-content;
  max-width: 280px;
  background: rgba(8, 0, 26, 0.96);
  border: 1px solid #00f0ff;
  color: #f5f0ff;
  padding: 10px 14px;
  border-radius: 12px;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  text-align: right;
  box-shadow:
    0 0 14px rgba(0, 0, 0, 0.65),
    0 0 18px rgba(0, 240, 255, 0.4);
  cursor: pointer;
  user-select: none;
  z-index: 9998;
  /* Reveal/hide: scale from the bubble's tail (bottom-right) so it pops in
     and out of the launcher with a snappy synthwave punch. */
  transform-origin: 100% 100%;
  opacity: 1;
  transform: scale(1);
  transition:
    opacity 0.3s ease,
    transform 0.38s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Hidden state — collapsed into the launcher corner, no interaction. */
.aw-greeting.aw-bubble-hidden {
  opacity: 0;
  transform: scale(0.35);
  pointer-events: none;
}

.aw-greeting:hover {
  border-color: #79f8ff;
  box-shadow:
    0 0 14px rgba(0, 0, 0, 0.65),
    0 0 22px rgba(0, 240, 255, 0.6);
}

.aw-greeting-text { white-space: normal; }

.aw-greeting-cursor {
  display: inline-block;
  margin-left: 2px;
  color: #00f0ff;
  animation: aw-cursor-blink 0.8s steps(2) infinite;
}
.aw-greeting-cursor.done {
  opacity: 0;
  transition: opacity 0.4s ease;
  animation: none;
}

@keyframes aw-cursor-blink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0; }
}

/* Speech-bubble tail pointing down at the launcher */
.aw-greeting::after {
  content: '';
  position: absolute;
  bottom: -8px;
  right: 26px;         /* aligns roughly with the launcher's centerline */
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid #00f0ff;
}
.aw-greeting::before {
  /* Inner-fill triangle on top of the border one to hide the seam */
  content: '';
  position: absolute;
  bottom: -6px;
  right: 27px;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 7px solid rgba(8, 0, 26, 0.96);
}

/* While the panel is open or animating closed, force the bubble fully hidden
   (overrides the transition state) so it never peeks through. */
#aw-widget.open .aw-greeting,
#aw-widget.closing .aw-greeting {
  opacity: 0 !important;
  transform: scale(0.35) !important;
  pointer-events: none !important;
}

/* Aggressive theme variant — pink border to match the angry palette */
#aw-widget.aw-aggressive .aw-greeting {
  border-color: #ff2cb6;
  box-shadow:
    0 0 14px rgba(0, 0, 0, 0.65),
    0 0 18px rgba(255, 44, 182, 0.45);
}
#aw-widget.aw-aggressive .aw-greeting::after { border-top-color: #ff2cb6; }

/* ── Panel ── */
.aw-panel {
  display: none;
  width: 460px;
  height: 640px;
  max-height: 85vh;
  background: linear-gradient(180deg, #14002b 0%, #2a0044 100%);
  border: 2px solid #ff2cb6;
  border-radius: 14px;
  box-shadow:
    0 0 30px rgba(255, 44, 182, 0.5),
    0 0 60px rgba(0, 240, 255, 0.25),
    inset 0 0 30px rgba(0, 0, 0, 0.4);
  flex-direction: column;
  overflow: hidden;
  position: relative;
  transform-origin: bottom right;
}

#aw-widget.open .aw-panel {
  display: flex;
  animation: aw-pixelate-in 260ms cubic-bezier(0.2, 0.9, 0.3, 1) forwards;
}

#aw-widget.closing .aw-panel {
  animation: aw-pixelate-out 180ms cubic-bezier(0.5, 0, 0.8, 0.2) forwards;
}

/* Pixel-grid wave overlay — pixelated mosaic that ticks across the reveal */
.aw-panel::before {
  content: '';
  position: absolute;
  inset: -10%;
  pointer-events: none;
  background:
    /* Vertical pixel-grid lines (cyan) */
    repeating-linear-gradient(
      90deg,
      rgba(0, 240, 255, 0.55) 0 1px,
      transparent 1px 8px
    ),
    /* Horizontal pixel-grid lines (yellow) */
    repeating-linear-gradient(
      0deg,
      rgba(255, 230, 41, 0.45) 0 1px,
      transparent 1px 8px
    ),
    /* Color wave — yellow / cyan / pink, no white blowout */
    linear-gradient(
      -45deg,
      transparent 20%,
      rgba(0, 240, 255, 0.45) 38%,
      rgba(255, 230, 41, 0.75) 50%,
      rgba(255, 44, 182, 0.55) 62%,
      transparent 80%
    );
  background-size: 8px 8px, 8px 8px, 260% 260%;
  background-position: 0 0, 0 0, 100% 100%;
  background-blend-mode: screen;
  mix-blend-mode: screen;
  opacity: 0;
  z-index: 100;
  border-radius: inherit;
}

/* Wave overlay uses stepped timing (10 ticks) for actual pixelation feel,
   while the main panel transform stays smooth. */
#aw-widget.open .aw-panel::before {
  animation: aw-wave-sweep 320ms steps(10, end) forwards;
}

#aw-widget.closing .aw-panel::before {
  animation: aw-wave-sweep-out 220ms steps(7, end) forwards;
}

@keyframes aw-pixelate-in {
  0% {
    clip-path: polygon(100% 100%, 100% 100%, 100% 100%, 100% 100%);
    transform: scale(0.35);
    opacity: 0.5;
  }
  100% {
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes aw-pixelate-out {
  0% {
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
    transform: scale(1);
    opacity: 1;
  }
  100% {
    clip-path: polygon(100% 100%, 100% 100%, 100% 100%, 100% 100%);
    transform: scale(0.35);
    opacity: 0;
  }
}

@keyframes aw-wave-sweep {
  0% {
    background-position: 0 0, 100% 100%;
    opacity: 1;
  }
  50% {
    opacity: 1;
  }
  100% {
    background-position: 0 0, 0% 0%;
    opacity: 0;
  }
}

@keyframes aw-wave-sweep-out {
  0% {
    background-position: 0 0, 0% 0%;
    opacity: 0;
  }
  30% {
    opacity: 1;
  }
  100% {
    background-position: 0 0, 100% 100%;
    opacity: 1;
  }
}

/* Launcher pop animation — only fires when explicitly closed (not on initial load) */
#aw-widget.just-closed .aw-launcher {
  animation: aw-launcher-pop 280ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes aw-launcher-pop {
  0% {
    transform: scale(0.1);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ════════════════════════════════════════════════════════════════
   AGGRESSIVE MODE THEME — red & menacing
   ═══════════════════════════════════════════════════════════════ */

#aw-widget.aw-aggressive .aw-launcher {
  background: linear-gradient(135deg, #2a0008, #6b0014);
  border-color: #ff1744;
  box-shadow:
    0 0 20px rgba(255, 23, 68, 0.75),
    0 0 42px rgba(139, 0, 0, 0.6),
    inset 0 0 14px rgba(255, 23, 68, 0.3);
  color: #ffb3b3;
}

#aw-widget.aw-aggressive .aw-launcher:hover {
  box-shadow:
    0 0 30px rgba(255, 23, 68, 1),
    0 0 60px rgba(139, 0, 0, 0.8);
}

#aw-widget.aw-aggressive .aw-panel {
  background: linear-gradient(180deg, #14000a 0%, #2a000f 100%);
  border-color: #ff1744;
  box-shadow:
    0 0 30px rgba(255, 23, 68, 0.55),
    0 0 60px rgba(139, 0, 0, 0.5),
    inset 0 0 30px rgba(40, 0, 0, 0.5);
}

#aw-widget.aw-aggressive .aw-header {
  background: linear-gradient(90deg, rgba(255, 23, 68, 0.35), rgba(139, 0, 0, 0.3));
  border-bottom-color: rgba(255, 23, 68, 0.7);
}

#aw-widget.aw-aggressive .aw-title {
  color: #ff5060;
  text-shadow: 0 0 10px rgba(255, 23, 68, 0.85);
  animation: aw-aggressive-flicker 4s ease-in-out infinite;
}

@keyframes aw-aggressive-flicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.78; }
  52% { opacity: 1; }
  54% { opacity: 0.85; }
}

#aw-widget.aw-aggressive .aw-mode-btn {
  border-color: rgba(255, 23, 68, 0.45);
}
#aw-widget.aw-aggressive .aw-mode-btn:hover {
  border-color: #ff1744;
  color: #ffb3b3;
}
#aw-widget.aw-aggressive .aw-mode-btn.active {
  background: rgba(255, 100, 100, 0.25);
  border-color: #ff8888;
  color: #ffcccc;
}
#aw-widget.aw-aggressive .aw-mode-btn.active-danger {
  background: rgba(255, 23, 68, 0.4);
  border-color: #ff1744;
  color: #ff7080;
}

#aw-widget.aw-aggressive .aw-close,
#aw-widget.aw-aggressive .aw-clear {
  color: #ffb3b3;
}
#aw-widget.aw-aggressive .aw-close:hover,
#aw-widget.aw-aggressive .aw-clear:hover {
  color: #ff1744;
}

#aw-widget.aw-aggressive .aw-msg.assistant {
  background: rgba(255, 23, 68, 0.08);
  border-color: rgba(255, 23, 68, 0.4);
  color: #ffd5d5;
}

#aw-widget.aw-aggressive .aw-msg.assistant::before {
  content: 'ARSKA.AI 😈';
  color: #ff5060;
  text-shadow: 0 0 6px rgba(255, 23, 68, 0.8);
}

#aw-widget.aw-aggressive .aw-msg.user {
  background: linear-gradient(135deg, rgba(139, 0, 30, 0.4), rgba(255, 23, 68, 0.3));
  border: 1px solid rgba(255, 23, 68, 0.5);
}

#aw-widget.aw-aggressive .aw-msg pre,
#aw-widget.aw-aggressive .aw-msg code {
  border-color: rgba(255, 23, 68, 0.3);
}

#aw-widget.aw-aggressive .aw-think {
  background: rgba(139, 0, 0, 0.15);
  border-color: rgba(255, 23, 68, 0.4);
}

#aw-widget.aw-aggressive .aw-input {
  border-color: rgba(255, 23, 68, 0.4);
}
#aw-widget.aw-aggressive .aw-input:focus {
  border-color: #ff1744;
}

#aw-widget.aw-aggressive .aw-input-row {
  border-top-color: rgba(255, 23, 68, 0.45);
}

#aw-widget.aw-aggressive .aw-send {
  background: linear-gradient(135deg, #ff1744, #8b0000);
}
#aw-widget.aw-aggressive .aw-send:hover {
  box-shadow: 0 0 14px rgba(255, 23, 68, 0.9);
}

/* Devil emoji badge on the launcher when in aggressive mode */
.aw-devil {
  display: none;
  position: absolute;
  bottom: -6px;
  right: -6px;
  font-size: 22px;
  pointer-events: none;
  filter: drop-shadow(0 0 6px rgba(255, 23, 68, 0.9));
  animation: aw-devil-bob 2.4s ease-in-out infinite;
  transform-origin: center;
}

#aw-widget.aw-aggressive .aw-devil { display: block; }

@keyframes aw-devil-bob {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50% { transform: translateY(-2px) rotate(5deg); }
}

@media (max-width: 480px) {
  .aw-panel { width: calc(100vw - 24px); height: calc(100vh - 100px); }
}

/* ── Fullscreen mode ─────────────────────────────────────────────────── */
/* Desktop: triggered by clicking the fullscreen button (.aw-fullscreen class
   on the widget root). Mobile: forced on whenever the panel is open via the
   media query below — the button itself is hidden on mobile. */

/* Hide the host page's scrollbar while the widget is open in fullscreen so
   it doesn't overlap the widget chrome. :has() handles this without JS. */
html:has(#aw-widget.aw-fullscreen.open),
body:has(#aw-widget.aw-fullscreen.open) {
  overflow: hidden;
}

#aw-widget.aw-fullscreen.open .aw-panel {
  position: fixed;
  inset: 0;
  width: 100dvw;
  height: 100dvh; /* dynamic viewport — accounts for mobile address bar */
  max-width: none;
  max-height: none;
  border-radius: 0;
  transform-origin: center center;
}

/* Two icons in the fullscreen button toggle based on state */
.aw-fs-icon-contract { display: none; }
#aw-widget.aw-fullscreen .aw-fs-icon-expand { display: none; }
#aw-widget.aw-fullscreen .aw-fs-icon-contract { display: inline; }

/* Active state coloring matches other mode buttons */
#aw-fullscreen-btn.active {
  background: rgba(0, 240, 255, 0.2);
  border-color: rgba(0, 240, 255, 0.8);
  color: #00f0ff;
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.4);
}

/* ── Mobile / phone ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Force the launcher to the bottom-right corner regardless of any inline
     drag styles from a prior desktop session. */
  #aw-widget {
    right: 16px !important;
    bottom: 16px !important;
    left: auto !important;
    top: auto !important;
  }
  /* The fullscreen toggle is irrelevant on mobile (always fullscreen). */
  #aw-fullscreen-btn { display: none; }
  /* When opened on mobile, the panel always takes the entire visible viewport.
     Using dvh/dvw (dynamic) so the address bar / on-screen keyboard collapsing
     and expanding keeps the input row visible instead of pushing it off-screen. */
  #aw-widget.open .aw-panel {
    position: fixed;
    inset: 0;
    width: 100dvw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border-radius: 0;
    padding-bottom: env(safe-area-inset-bottom, 0); /* iOS home indicator */
  }
  /* Header isn't a drag handle on touch devices */
  .aw-header { cursor: default; }
}

/* ── Header ── */
.aw-header {
  padding: 12px 16px;
  background: linear-gradient(90deg, rgba(255, 44, 182, 0.3), rgba(0, 240, 255, 0.15));
  border-bottom: 1px solid rgba(255, 44, 182, 0.6);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: move;
  user-select: none;
}

.aw-launcher { cursor: grab; }
#aw-widget.dragging .aw-launcher,
#aw-widget.dragging .aw-header { cursor: grabbing; }

.aw-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  letter-spacing: 1px;
  color: #00f0ff;
  text-shadow: 0 0 8px rgba(0, 240, 255, 0.7);
  flex: 1;
}

.aw-mode-btn {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(0, 240, 255, 0.4);
  color: #b8a8d6;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: all 0.2s;
  position: relative;
}

.aw-mode-btn svg { width: 16px; height: 16px; }

.aw-mode-btn:hover { color: #f5f0ff; border-color: #00f0ff; }
.aw-mode-btn.active { background: rgba(0, 240, 255, 0.25); border-color: #00f0ff; color: #00f0ff; }
.aw-mode-btn.active-danger { background: rgba(255, 44, 182, 0.3); border-color: #ff2cb6; color: #ff4dd9; }

.aw-close, .aw-clear {
  background: transparent;
  border: none;
  color: #b8a8d6;
  cursor: pointer;
  font-size: 22px;
  padding: 0 6px;
  transition: color 0.2s;
  position: relative;
}
.aw-close:hover, .aw-clear:hover { color: #ff2cb6; }

/* ── Custom tooltips ── */
/* Tooltips are rendered as floating elements appended to document.body so
   they can escape the panel's overflow:hidden clip. JS in chat-widget.js
   manages mount/position/teardown via mouseenter/leave + focus/blur. */
.aw-floating-tip {
  position: fixed;
  background: rgba(8, 0, 26, 0.96);
  border: 1px solid var(--tip-color, #00f0ff);
  color: #f5f0ff;
  padding: 10px 14px;
  border-radius: 8px;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.45;
  max-width: 280px;
  text-align: left;
  box-shadow:
    0 0 14px rgba(0, 0, 0, 0.65),
    0 0 18px color-mix(in srgb, var(--tip-color, #00f0ff) 40%, transparent);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 2147483646; /* above the widget (9999) and any other page content */
}
.aw-floating-tip.aw-tip-danger { --tip-color: #ff2cb6; }
.aw-floating-tip.aw-tip-above { transform: translateY(4px); }
.aw-floating-tip.show {
  opacity: 1;
  transform: translateY(0);
}

/* ── Messages ── */
.aw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 15px;
  line-height: 1.55;
}

.aw-messages::-webkit-scrollbar { width: 6px; }
.aw-messages::-webkit-scrollbar-track { background: transparent; }
.aw-messages::-webkit-scrollbar-thumb { background: rgba(255, 44, 182, 0.4); border-radius: 3px; }

.aw-msg {
  padding: 10px 14px;
  border-radius: 10px;
  max-width: 92%;
  word-wrap: break-word;
  overflow-wrap: break-word;
  animation: aw-fade 0.25s ease;
}

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

.aw-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(255, 44, 182, 0.4), rgba(214, 0, 255, 0.3));
  border: 1px solid rgba(255, 44, 182, 0.5);
  color: #fff;
}

.aw-msg.assistant {
  align-self: flex-start;
  background: rgba(0, 240, 255, 0.08);
  border: 1px solid rgba(0, 240, 255, 0.3);
  color: #e8e0ff;
}

.aw-msg.assistant::before {
  content: 'ARSKA.AI';
  display: block;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  letter-spacing: 1.5px;
  color: #00f0ff;
  text-shadow: 0 0 6px rgba(0, 240, 255, 0.6);
  margin-bottom: 6px;
}

.aw-msg.system {
  align-self: center;
  background: rgba(255, 230, 41, 0.1);
  border: 1px solid rgba(255, 230, 41, 0.3);
  color: #ffe629;
  font-size: 13px;
  font-style: italic;
  max-width: 95%;
}

.aw-msg pre {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(0, 240, 255, 0.2);
  border-radius: 6px;
  padding: 10px;
  overflow-x: auto;
  font-family: 'VT323', monospace;
  font-size: 16px;
  margin: 8px 0;
}

.aw-msg code {
  background: rgba(0, 0, 0, 0.5);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'VT323', monospace;
  font-size: 16px;
}

.aw-msg a {
  color: #00f0ff;
  text-decoration: underline;
}

/* ── Markdown structure inside assistant bubbles ── */
.aw-msg p {
  margin: 0 0 8px 0;
}
.aw-msg p:last-child { margin-bottom: 0; }

.aw-msg h3,
.aw-msg h4,
.aw-msg h5 {
  margin: 12px 0 6px 0;
  color: #ffb3df;
  font-family: 'Press Start 2P', monospace;
  letter-spacing: 1px;
  line-height: 1.3;
}
.aw-msg h3 { font-size: 13px; }
.aw-msg h4 { font-size: 12px; }
.aw-msg h5 { font-size: 11px; }
.aw-msg h3:first-child,
.aw-msg h4:first-child,
.aw-msg h5:first-child { margin-top: 0; }

.aw-msg ul,
.aw-msg ol {
  margin: 6px 0 8px 0;
  padding-left: 22px;
}
.aw-msg li {
  margin-bottom: 4px;
  line-height: 1.5;
}
.aw-msg li:last-child { margin-bottom: 0; }
.aw-msg ul li { list-style: disc; }
.aw-msg ol li { list-style: decimal; }

.aw-msg strong { color: #ffd5f0; }
.aw-msg em     { color: #d5b3ff; font-style: italic; }

.aw-msg hr {
  border: 0;
  border-top: 1px dashed rgba(255, 44, 182, 0.4);
  margin: 10px 0;
}

/* Aggressive theme variants */
#aw-widget.aw-aggressive .aw-msg h3,
#aw-widget.aw-aggressive .aw-msg h4,
#aw-widget.aw-aggressive .aw-msg h5 { color: #ff5060; }
#aw-widget.aw-aggressive .aw-msg strong { color: #ffb3b3; }
#aw-widget.aw-aggressive .aw-msg hr { border-top-color: rgba(255, 23, 68, 0.4); }

/* ── Sources block (web search citations) ── */
.aw-sources {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed rgba(0, 240, 255, 0.4);
}

.aw-sources-header {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  letter-spacing: 1.5px;
  color: #00f0ff;
  text-shadow: 0 0 6px rgba(0, 240, 255, 0.5);
  user-select: none;
  padding: 4px 0;
}

.aw-sources-header:hover { color: #7afcff; }

.aw-sources-icon {
  display: inline-block;
  transition: transform 0.2s ease;
  font-family: inherit;
  font-size: 10px;
}

.aw-sources-header.open .aw-sources-icon { transform: rotate(90deg); }

.aw-sources-list {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, margin-top 0.3s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.aw-sources-list.open {
  max-height: 400px;
  overflow-y: auto;
  margin-top: 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 240, 255, 0.5) transparent;
}

.aw-sources-list::-webkit-scrollbar { width: 6px; }
.aw-sources-list::-webkit-scrollbar-track { background: transparent; }
.aw-sources-list::-webkit-scrollbar-thumb {
  background: rgba(0, 240, 255, 0.5);
  border-radius: 3px;
}

.aw-source-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 8px;
  background: rgba(0, 240, 255, 0.06);
  border: 1px solid rgba(0, 240, 255, 0.2);
  border-left: 2px solid #00f0ff;
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
  transition: all 0.15s ease;
  font-size: 12px;
  line-height: 1.35;
}

.aw-source-item:hover {
  background: rgba(0, 240, 255, 0.14);
  border-color: rgba(0, 240, 255, 0.55);
  transform: translateX(2px);
}

.aw-source-num {
  flex-shrink: 0;
  color: #00f0ff;
  font-family: 'VT323', monospace;
  font-size: 15px;
  font-weight: bold;
  line-height: 1;
  background: rgba(0, 240, 255, 0.15);
  border-radius: 4px;
  padding: 2px 6px;
  min-width: 22px;
  text-align: center;
}

.aw-source-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.aw-source-title {
  color: #d9f0ff;
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.aw-source-host {
  color: #7afcff;
  font-size: 11px;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Aggressive theme — red sources */
#aw-widget.aw-aggressive .aw-sources { border-top-color: rgba(255, 23, 68, 0.4); }
#aw-widget.aw-aggressive .aw-sources-header { color: #ff5060; text-shadow: 0 0 6px rgba(255, 23, 68, 0.6); }
#aw-widget.aw-aggressive .aw-sources-header:hover { color: #ff8a90; }
#aw-widget.aw-aggressive .aw-sources-list.open { scrollbar-color: rgba(255, 23, 68, 0.5) transparent; }
#aw-widget.aw-aggressive .aw-sources-list::-webkit-scrollbar-thumb { background: rgba(255, 23, 68, 0.5); }
#aw-widget.aw-aggressive .aw-source-item {
  background: rgba(255, 23, 68, 0.06);
  border-color: rgba(255, 23, 68, 0.25);
  border-left-color: #ff1744;
}
#aw-widget.aw-aggressive .aw-source-item:hover {
  background: rgba(255, 23, 68, 0.14);
  border-color: rgba(255, 23, 68, 0.55);
}
#aw-widget.aw-aggressive .aw-source-num {
  color: #ff5060;
  background: rgba(255, 23, 68, 0.18);
}
#aw-widget.aw-aggressive .aw-source-title { color: #ffd5d5; }
#aw-widget.aw-aggressive .aw-source-host { color: #ff8a90; }

/* Thinking block */
.aw-think {
  background: rgba(138, 43, 226, 0.12);
  border: 1px solid rgba(138, 43, 226, 0.4);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: #b8a8d6;
  margin: 4px 0;
  max-width: 95%;
  align-self: flex-start;
}
.aw-think-header {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
.aw-think-header .aw-think-icon { transition: transform 0.2s; }
.aw-think-header.open .aw-think-icon { transform: rotate(90deg); }
.aw-think-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  white-space: pre-wrap;
}
.aw-think-body.open {
  max-height: 200px;
  overflow-y: auto;
  margin-top: 6px;
  padding-top: 4px;
  border-top: 1px dashed rgba(138, 43, 226, 0.3);
  scrollbar-width: thin;
  scrollbar-color: rgba(138, 43, 226, 0.6) transparent;
}

.aw-think-body::-webkit-scrollbar { width: 6px; }
.aw-think-body::-webkit-scrollbar-track { background: transparent; }
.aw-think-body::-webkit-scrollbar-thumb {
  background: rgba(138, 43, 226, 0.5);
  border-radius: 3px;
}
.aw-think-body::-webkit-scrollbar-thumb:hover { background: rgba(138, 43, 226, 0.8); }

#aw-widget.aw-aggressive .aw-think-body.open {
  scrollbar-color: rgba(255, 23, 68, 0.5) transparent;
}
#aw-widget.aw-aggressive .aw-think-body::-webkit-scrollbar-thumb {
  background: rgba(255, 23, 68, 0.5);
}
#aw-widget.aw-aggressive .aw-think-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 23, 68, 0.85);
}

/* Tool / status indicator */
.aw-status {
  align-self: center;
  font-size: 13px;
  color: #ffae00;
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 8px;
}
.aw-status::before {
  content: '';
  width: 10px;
  height: 10px;
  border: 2px solid rgba(255, 174, 0, 0.3);
  border-top-color: #ffae00;
  border-radius: 50%;
  animation: aw-spin 0.8s linear infinite;
}
@keyframes aw-spin { to { transform: rotate(360deg); } }

/* ── Input ── */
.aw-input-row {
  padding: 12px;
  display: flex;
  gap: 10px;
  border-top: 1px solid rgba(255, 44, 182, 0.4);
  background: rgba(0, 0, 0, 0.3);
}

/* Wrap that holds the textarea + the mirror layer used to position our
   custom blinking block cursor on top of where the native caret would be. */
.aw-input-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}
.aw-input {
  display: block;
  width: 100%;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(0, 240, 255, 0.3);
  border-radius: 8px;
  color: #f5f0ff;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.35;
  resize: none;
  outline: none;
  min-height: 44px;
  max-height: 120px;
  transition: border-color 0.2s;
  caret-color: transparent;        /* hide native caret — we draw our own */
  position: relative;
  z-index: 2;
  background-clip: padding-box;
}
.aw-input:focus { border-color: #ff2cb6; }

/* Slim cyan scrollbar inside the chat input when it grows past max-height */
.aw-input {
  scrollbar-width: thin;
  scrollbar-color: rgba(0,240,255,0.55) transparent;
}
.aw-input::-webkit-scrollbar { width: 5px; }
.aw-input::-webkit-scrollbar-track { background: transparent; }
.aw-input::-webkit-scrollbar-thumb {
  background: rgba(0,240,255,0.5);
  border-radius: 3px;
  box-shadow: 0 0 4px rgba(0,240,255,0.4);
}
.aw-input::-webkit-scrollbar-thumb:hover { background: #00f0ff; box-shadow: 0 0 6px #00f0ff; }
#aw-widget.aw-aggressive .aw-input {
  scrollbar-color: rgba(255,23,68,0.55) transparent;
}
#aw-widget.aw-aggressive .aw-input::-webkit-scrollbar-thumb {
  background: rgba(255,23,68,0.5);
  box-shadow: 0 0 4px rgba(255,23,68,0.4);
}

/* Mirror layer: invisible text identical to the textarea content followed by
   our visible cursor block. Same box-sizing/padding/font as .aw-input so the
   cursor lands exactly where the native caret would be. */
.aw-input-mirror {
  position: absolute;
  inset: 0;
  z-index: 3;                       /* above the textarea so the cursor is visible */
  pointer-events: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.35;
  padding: 10px 12px;
  border: 1px solid transparent;    /* keep the inner box width identical */
  border-radius: 8px;
  box-sizing: border-box;
  color: transparent;               /* mirror text is invisible — only positions the cursor */
  white-space: pre-wrap;
  word-wrap: break-word;
  word-break: break-word;
  overflow: hidden;
}

/* The block-cursor glyph */
.aw-input-cursor {
  display: inline-block;
  width: 0.5em;
  height: 0.95em;
  background: #00f0ff;
  vertical-align: -0.05em;    /* sit so the block roughly spans baseline → cap height */
  margin-left: 2px;            /* small gap from the preceding character */
  box-shadow: 0 0 8px #00f0ff, 0 0 14px rgba(0,240,255,0.5);
  animation: aw-caret-blink 1.05s steps(2, start) infinite;
}
@keyframes aw-caret-blink { to { opacity: 0; } }

/* Hide the cursor when the input isn't focused (so it doesn't overlap the placeholder) */
.aw-input-wrap:not(.is-focused) .aw-input-cursor { display: none; }
/* While actively typing, hold the cursor solid bright — the blink rate stays the
   same (1.05s) whenever it does blink, only the visibility is forced ON here. */
.aw-input-wrap.is-typing .aw-input-cursor { animation: none; opacity: 1; }

/* In aggressive mode the cursor turns pink to match the angry theme */
#aw-widget.aw-aggressive .aw-input-cursor {
  background: #ff2cb6;
  box-shadow: 0 0 8px #ff2cb6, 0 0 14px rgba(255,44,182,0.5);
}

.aw-send {
  background: linear-gradient(135deg, #ff2cb6, #d600ff);
  border: none;
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.aw-send:hover { box-shadow: 0 0 12px rgba(255, 44, 182, 0.8); }
.aw-send:disabled { opacity: 0.4; cursor: not-allowed; }
.aw-send svg { width: 20px; height: 20px; }

/* ── Image attachment ──────────────────────────────────────── */
.aw-attach {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(0, 240, 255, 0.4);
  color: #b8a8d6;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}
.aw-attach:hover {
  color: #00f0ff;
  border-color: rgba(0, 240, 255, 0.8);
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.4);
}
.aw-attach svg { width: 20px; height: 20px; }

#aw-widget.aw-aggressive .aw-attach {
  border-color: rgba(255, 23, 68, 0.4);
}
#aw-widget.aw-aggressive .aw-attach:hover {
  color: #ff1744;
  border-color: #ff1744;
  box-shadow: 0 0 8px rgba(255, 23, 68, 0.5);
}

/* Preview row above the input — only visible when there are staged images */
.aw-preview-row {
  display: none;
  padding: 8px 12px 0 12px;
  gap: 8px;
  flex-wrap: wrap;
}
.aw-preview-row.has-items { display: flex; }

.aw-preview-thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(0, 240, 255, 0.5);
  background: rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}
.aw-preview-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.aw-preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid rgba(255, 44, 182, 0.7);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.aw-preview-remove:hover {
  background: #ff2cb6;
  box-shadow: 0 0 6px rgba(255, 44, 182, 0.8);
}

/* User-message images (shown inside a user bubble after sending) */
.aw-user-image {
  display: block;
  max-width: 100%;
  max-height: 240px;
  border-radius: 8px;
  margin-bottom: 6px;
  border: 1px solid rgba(255, 44, 182, 0.4);
}
.aw-user-text { margin-top: 2px; }
