/* ════════════════════════════════════════════════════════════
   AI WIDGET — floating ask-the-archive chat
   Loaded as a separate stylesheet. Reuses the host site's CSS
   custom properties (--gold, --purple, --ink, --paper, --display,
   --thai, --shadow-rgb, --radius) so it inherits the theme
   automatically. Falls back to sane defaults if a variable is
   missing (e.g. when testing this file in isolation).
   ════════════════════════════════════════════════════════════ */

:root {
  --aiw-gold:        var(--gold, #D6B46A);
  --aiw-gold-bright: var(--gold-bright, #F2E6B6);
  --aiw-purple:      var(--purple, #6D4AE0);
  --aiw-bg:          var(--ink, #0D0812);
  --aiw-surface:     var(--navy-deep, #1B1026);
  --aiw-text:        var(--paper, #D6B46A);
  --aiw-text-dim:    var(--paper-mid, #a89253);
  --aiw-display:     var(--display, 'Cinzel', serif);
  --aiw-body:        var(--thai, 'Sarabun', sans-serif);
  --aiw-radius:      14px;
  --aiw-shadow:      0 18px 44px -12px rgba(0,0,0,0.65);
  --aiw-z:           99990;
}

/* ── Floating button ── */
.aiw-fab {
  position: fixed;
  right: 1.4rem;
  bottom: 1.4rem;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--aiw-gold-bright), var(--aiw-gold));
  border: 1px solid rgba(var(--gold-rgb, 214,180,106), 0.5);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06), 0 10px 24px -6px rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: var(--aiw-z);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.aiw-fab:hover { transform: translateY(-2px); }
.aiw-fab svg { width: 24px; height: 24px; color: var(--aiw-bg); }
.aiw-fab.is-open { transform: scale(0.92); }

/* ── Panel ── */
.aiw-panel {
  position: fixed;
  right: 1.4rem;
  bottom: 5.2rem;
  width: min(380px, calc(100vw - 2.4rem));
  height: min(560px, calc(100vh - 7.5rem));
  background: var(--aiw-surface);
  border: 1px solid rgba(var(--gold-rgb, 214,180,106), 0.25);
  border-radius: var(--aiw-radius);
  box-shadow: var(--aiw-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: var(--aiw-z);
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.aiw-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

@media (max-width: 480px) {
  .aiw-panel {
    right: 0.6rem;
    left: 0.6rem;
    bottom: 5rem;
    width: auto;
    height: min(70vh, 560px);
  }
}

/* ── Header ── */
.aiw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid rgba(var(--gold-rgb, 214,180,106), 0.18);
  font-family: var(--aiw-display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: var(--aiw-gold-bright);
}
.aiw-close {
  background: none;
  border: none;
  color: var(--aiw-text-dim);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem;
}
.aiw-close:hover { color: var(--aiw-gold-bright); }

/* ── Messages ── */
.aiw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1rem 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  font-family: var(--aiw-body);
}
.aiw-msg {
  max-width: 88%;
  padding: 0.6rem 0.85rem;
  border-radius: 12px;
  font-size: 0.86rem;
  line-height: 1.5;
  white-space: pre-wrap;
}
.aiw-msg--user {
  align-self: flex-end;
  background: rgba(var(--gold-rgb, 214,180,106), 0.16);
  color: var(--aiw-gold-bright);
  border: 1px solid rgba(var(--gold-rgb, 214,180,106), 0.3);
}
.aiw-msg--assistant {
  align-self: flex-start;
  background: rgba(255,255,255,0.04);
  color: var(--aiw-text);
  border: 1px solid rgba(255,255,255,0.06);
}
.aiw-msg--typing { opacity: 0.6; font-style: italic; }
.aiw-empty {
  margin: auto;
  text-align: center;
  color: var(--aiw-text-dim);
  font-size: 0.82rem;
  padding: 1.5rem;
}

/* ── Input row ── */
.aiw-input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.8rem;
  border-top: 1px solid rgba(var(--gold-rgb, 214,180,106), 0.18);
}
.aiw-input {
  flex: 1;
  resize: none;
  max-height: 96px;
  min-height: 38px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(var(--gold-rgb, 214,180,106), 0.25);
  border-radius: 10px;
  color: var(--aiw-text);
  font-family: var(--aiw-body);
  font-size: 0.86rem;
  padding: 0.5rem 0.7rem;
  outline: none;
}
.aiw-input:focus { border-color: var(--aiw-gold); }
.aiw-send {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid rgba(var(--gold-rgb, 214,180,106), 0.4);
  background: var(--aiw-gold);
  color: var(--aiw-bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.aiw-send:disabled { opacity: 0.5; cursor: default; }
.aiw-send svg { width: 16px; height: 16px; }
