/* Wiser Wizard — floating glossary chat widget.
   Tokens used:
     ink         #000
     paper       #fff
     accent      rgb(0 131 255)
     accent2     rgb(0 102 204)
     rule        rgb(229 231 235)
     muted       rgb(107 114 128)
     font        Sora, system-ui, sans-serif
*/

/* -------- FAB (closed state) -------- */
.ww-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  background: rgb(0 131 255);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  z-index: 100;
  font-family: Sora, system-ui, sans-serif;
  box-shadow: 0 6px 20px rgba(0, 131, 255, 0.32), 0 2px 8px rgba(0, 0, 0, 0.12);
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.ww-fab:hover,
.ww-fab:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 131, 255, 0.4), 0 3px 10px rgba(0, 0, 0, 0.16);
  outline: none;
}

.ww-fab:focus-visible {
  outline: 2px solid rgb(0 131 255);
  outline-offset: 3px;
}

.ww-fab.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.85);
}

.ww-fab > svg {
  width: 30px;
  height: 30px;
}

.ww-fab-label {
  position: absolute;
  right: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: #000;
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  padding: 0.3125rem 0.5rem;
  border-radius: 2px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

.ww-fab:hover .ww-fab-label,
.ww-fab:focus-visible .ww-fab-label {
  opacity: 1;
}

/* -------- Panel (open state) -------- */
.ww-panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: min(640px, calc(100vh - 40px));
  background: #fff;
  border: 1px solid rgb(229 231 235);
  border-radius: 0;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.14), 0 4px 12px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  font-family: Sora, system-ui, sans-serif;
  color: #000;
  z-index: 101;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 0.18s ease, transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.ww-panel.is-open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* -------- Panel header -------- */
.ww-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0.875rem;
  border-bottom: 1px solid rgb(229 231 235);
  flex-shrink: 0;
}

.ww-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.ww-brand-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 0;
  background: rgb(0 131 255);
  color: #fff;
}

.ww-brand-icon svg {
  width: 22px;
  height: 22px;
}

.ww-name {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: #000;
  line-height: 1.2;
}

.ww-sub {
  margin: 0;
  font-size: 0.6875rem;
  color: rgb(107 114 128);
  line-height: 1.2;
}

.ww-close {
  border: 0;
  background: transparent;
  color: rgb(107 114 128);
  cursor: pointer;
  padding: 0.375rem;
  border-radius: 2px;
  display: grid;
  place-items: center;
}

.ww-close {
  border-radius: 0;
}

.ww-close:hover {
  color: #000;
  background: rgb(243 244 246);
  border-radius: 0;
}

.ww-close svg {
  width: 18px;
  height: 18px;
}

/* -------- Body (scrolling area) -------- */
.ww-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scrollbar-width: thin;
  scrollbar-color: rgb(209 213 219) transparent;
}

.ww-body::-webkit-scrollbar { width: 6px; }
.ww-body::-webkit-scrollbar-track { background: transparent; }
.ww-body::-webkit-scrollbar-thumb { background: rgb(209 213 219); border-radius: 3px; }

/* -------- Empty state -------- */
.ww-empty {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ww-empty[hidden] { display: none; }

.ww-empty-text {
  font-size: 0.8125rem;
  color: rgba(0, 0, 0, 0.7);
  line-height: 1.5;
  margin: 0;
}

.ww-chips {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.ww-chip {
  border: 1px solid rgb(229 231 235);
  background: #fff;
  font-family: inherit;
  font-size: 0.8125rem;
  padding: 0.5rem 0.625rem;
  border-radius: 0;
  color: rgba(0, 0, 0, 0.8);
  cursor: pointer;
  text-align: left;
  line-height: 1.35;
  transition: border-color 0.15s, color 0.15s;
}

.ww-chip:hover {
  border-color: rgb(0 131 255);
  color: rgb(0 131 255);
}

.ww-chip:focus-visible {
  outline: 2px solid rgb(0 131 255);
  outline-offset: 1px;
}

/* -------- Messages -------- */
.ww-messages {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.ww-msg-user {
  align-self: flex-end;
  max-width: 88%;
  padding: 0.5rem 0.75rem;
  background: rgb(0 131 255);
  color: #fff;
  border-radius: 0;
  font-size: 0.875rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.ww-msg-assistant {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ww-msg-content {
  font-size: 0.875rem;
  line-height: 1.55;
  color: rgba(0, 0, 0, 0.85);
}

.ww-msg-content p { margin: 0 0 0.5rem; }
.ww-msg-content p:last-child { margin-bottom: 0; }
.ww-msg-content ul { list-style: disc; padding-left: 1.125rem; margin: 0.375rem 0; }
.ww-msg-content li { margin: 0.1875rem 0; }
.ww-msg-content strong { font-weight: 600; color: #000; }
.ww-msg-content em { font-style: italic; }
.ww-msg-content code {
  font-family: inherit;
  background: rgb(243 244 246);
  padding: 0.0625rem 0.25rem;
  border-radius: 0;
  font-size: 0.875em;
}

.ww-msg-content.is-error { color: rgb(160 30 30); }

.ww-thinking {
  display: inline-block;
  padding: 0.25rem 0;
  font-size: 0.875rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  background: linear-gradient(
    110deg,
    rgb(156 163 175) 35%,
    rgb(0 131 255) 50%,
    rgb(156 163 175) 65%
  );
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation: ww-shimmer 2s linear infinite;
}

@keyframes ww-shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* -------- Citations -------- */
.ww-cites {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
}

.ww-cites[hidden] { display: none; }

.ww-cites-label {
  font-size: 0.625rem;
  color: rgb(107 114 128);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 0.125rem;
}

.ww-cite-chip {
  display: inline-block;
  font-size: 0.6875rem;
  padding: 0.125rem 0.375rem;
  border-radius: 0;
  background: #fff;
  border: 1px solid rgb(229 231 235);
  color: rgb(0 102 204);
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}

.ww-cite-chip:hover {
  border-color: rgb(0 131 255);
  background: rgb(240 248 255);
}

/* -------- Footer (form + disclaimer) -------- */
.ww-footer {
  border-top: 1px solid rgb(229 231 235);
  padding: 0.625rem 0.875rem 0.625rem;
  flex-shrink: 0;
}

.ww-form {
  display: flex;
  gap: 0.375rem;
}

.ww-input {
  flex: 1;
  border: 1px solid rgb(229 231 235);
  background: #fff;
  font-family: inherit;
  font-size: 0.875rem;
  padding: 0.5rem 0.625rem;
  border-radius: 0;
  color: #000;
  min-width: 0;
}

.ww-input::placeholder { color: rgb(156 163 175); }
.ww-input:focus { outline: none; border-color: rgb(0 131 255); }
.ww-input:disabled { opacity: 0.5; }

.ww-submit {
  border: 1px solid #000;
  background: #000;
  color: #fff;
  font-family: inherit;
  padding: 0 0.75rem;
  border-radius: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: opacity 0.15s;
}

.ww-submit:hover:not(:disabled) { opacity: 0.85; }
.ww-submit:disabled { opacity: 0.4; cursor: default; }
.ww-submit svg { width: 16px; height: 16px; }

.ww-disclaimer {
  font-size: 0.6875rem;
  color: rgb(107 114 128);
  margin: 0.5rem 0 0;
  line-height: 1.45;
}

/* -------- Term flash when arrived via citation -------- */
dt.ww-flash {
  background-color: rgb(255 247 200);
  transition: background-color 1.2s ease-out;
}

/* -------- Mobile -------- */
@media (max-width: 640px) {
  .ww-fab {
    bottom: 16px;
    right: 16px;
  }
  .ww-panel {
    inset: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    border: 0;
    border-radius: 0;
    transform: translateY(20px);
  }
  .ww-panel.is-open {
    transform: none;
  }
  .ww-fab-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .ww-fab, .ww-panel, .ww-thinking {
    transition: none !important;
    animation: none !important;
  }
  .ww-thinking {
    background: none;
    color: rgb(107 114 128);
    -webkit-text-fill-color: rgb(107 114 128);
  }
}
