/* AA-CHAT-DELTA: estate-wide Anthony Latest bubble chat (corner button + panel).
   One shared component, skinned per surface via [data-aa-theme] variables.
   Remove the two aa-chat lines from a page's HTML + this file + aa-chat.js to revert. */

.aa-chat-root {
  --aa-accent: #ff2233;
  --aa-accent-2: #ff5a3c;
  --aa-glow: rgba(255, 34, 51, .55);
  --aa-panel-bg: #0d0d11;
  --aa-panel-edge: rgba(255, 255, 255, .14);
  --aa-bubble-bot: #1b1b21;
  --aa-bubble-bot-edge: rgba(255, 255, 255, .10);
  --aa-text: #f5f5f7;
  --aa-dim: #a7a7b3;
  --aa-offset: 20px;
  position: fixed;
  right: 18px;
  bottom: var(--aa-offset);
  z-index: 2147483000;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--aa-text);
}
.aa-chat-root[data-aa-theme="town"]      { --aa-accent: #3ddc4e; --aa-accent-2: #17b978; --aa-glow: rgba(61, 220, 78, .45); }
.aa-chat-root[data-aa-theme="willow"]    { --aa-accent: #d4af37; --aa-accent-2: #b8912a; --aa-glow: rgba(212, 175, 55, .45); }
.aa-chat-root[data-aa-theme="anttv"]     { --aa-accent: #e50914; --aa-accent-2: #ff3d47; --aa-glow: rgba(229, 9, 20, .5); }
.aa-chat-root[data-aa-theme="bookstore"] { --aa-accent: #7ec8f7; --aa-accent-2: #3d9be9; --aa-glow: rgba(126, 200, 247, .45); --aa-panel-bg: #0b2a4a; }
.aa-chat-root[data-aa-theme="flik"]      { --aa-accent: #c084fc; --aa-accent-2: #ec4899; --aa-glow: rgba(192, 132, 252, .5); }
.aa-chat-root[data-aa-theme="shield"]    { --aa-accent: #22d3ee; --aa-accent-2: #a78bfa; --aa-glow: rgba(34, 211, 238, .5); }

/* ---------- corner button ---------- */
.aa-chat-btn {
  width: 58px; height: 58px; border-radius: 50%;
  border: 2px solid var(--aa-accent);
  background: radial-gradient(circle at 32% 28%, #2a2a33, #0a0a0d 70%);
  box-shadow: 0 0 18px var(--aa-glow), 0 8px 22px rgba(0, 0, 0, .5);
  cursor: pointer; padding: 0; position: relative;
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s ease, box-shadow .15s ease;
}
.aa-chat-btn:hover { transform: translateY(-2px) scale(1.04); }
.aa-chat-btn:focus-visible { outline: 3px solid var(--aa-accent-2); outline-offset: 3px; }
.aa-chat-btn svg { width: 34px; height: 34px; display: block; }
.aa-chat-btn .aa-chat-badge {
  position: absolute; right: -3px; bottom: -3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: linear-gradient(135deg, var(--aa-accent), var(--aa-accent-2));
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .45);
}
.aa-chat-btn .aa-chat-badge svg { width: 12px; height: 12px; }
.aa-chat-root.aa-open .aa-chat-btn { display: none; }

/* host gate (AAChatGate): button + panel fully hidden while gated —
   e.g. Obsidian Pay keeps chat behind the login, never in front of it */
.aa-chat-root.aa-gated { display: none !important; }

/* rail / menu mode (TV face): the button renders inline in a host container */
.aa-chat-rail-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--aa-accent);
  background: rgba(0, 0, 0, .35); color: var(--aa-text);
  font: inherit; font-size: 15px; cursor: pointer; text-align: left;
}
.aa-chat-rail-btn svg { width: 26px; height: 26px; flex: none; }
.aa-chat-rail-btn:hover { box-shadow: 0 0 14px var(--aa-glow); }

/* ---------- panel ---------- */
.aa-chat-panel {
  position: fixed; right: 18px; bottom: var(--aa-offset);
  width: min(384px, calc(100vw - 24px));
  height: min(560px, calc(100dvh - var(--aa-offset) - 24px));
  background: var(--aa-panel-bg);
  border: 1px solid var(--aa-panel-edge);
  border-radius: 22px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .4), 0 0 26px var(--aa-glow), 0 24px 60px rgba(0, 0, 0, .6);
  display: none; flex-direction: column; overflow: hidden;
  z-index: 2147483001;
}
.aa-chat-root.aa-open .aa-chat-panel { display: flex; }
@media (max-width: 520px) {
  .aa-chat-panel { right: 12px; left: 12px; width: auto; }
}

.aa-chat-head {
  display: flex; align-items: center; gap: 11px;
  padding: 13px 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .06), rgba(255, 255, 255, 0));
  border-bottom: 1px solid var(--aa-panel-edge);
  flex: none;
}
.aa-chat-avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  border: 2px solid var(--aa-accent);
  background: radial-gradient(circle at 32% 28%, #2a2a33, #0a0a0d 70%);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 12px var(--aa-glow);
}
.aa-chat-avatar svg { width: 26px; height: 26px; }
.aa-chat-head .aa-chat-id { flex: 1; min-width: 0; }
.aa-chat-head .aa-chat-name { font-weight: 700; font-size: 16px; line-height: 1.15; }
.aa-chat-head .aa-chat-sub { font-size: 12.5px; color: var(--aa-dim); line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aa-chat-lang {
  flex: none; border: 1px solid var(--aa-panel-edge); background: transparent;
  color: var(--aa-dim); border-radius: 999px; padding: 4px 9px;
  font-size: 11.5px; font-weight: 700; cursor: pointer; letter-spacing: .04em;
}
.aa-chat-lang:hover { color: var(--aa-text); border-color: var(--aa-accent); }
.aa-chat-close {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--aa-panel-edge); background: transparent;
  color: var(--aa-text); font-size: 17px; line-height: 1; cursor: pointer;
}
.aa-chat-close:hover { border-color: var(--aa-accent); }

.aa-chat-thread {
  flex: 1; overflow-y: auto; padding: 14px 12px 8px;
  display: flex; flex-direction: column; gap: 9px;
  overscroll-behavior: contain;
}
.aa-row { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
.aa-row.user { justify-content: flex-end; }
.aa-row .aa-mini { width: 26px; height: 26px; flex: none; border-radius: 50%; border: 1.5px solid var(--aa-accent); background: #101014; display: flex; align-items: center; justify-content: center; }
.aa-row .aa-mini svg { width: 16px; height: 16px; }
.aa-bubble {
  max-width: 82%; padding: 10px 13px; border-radius: 18px;
  font-size: 14.5px; line-height: 1.45; white-space: pre-wrap; word-break: break-word;
}
.aa-row.bot .aa-bubble { background: var(--aa-bubble-bot); border: 1px solid var(--aa-bubble-bot-edge); border-bottom-left-radius: 6px; }
.aa-row.user .aa-bubble { background: linear-gradient(135deg, var(--aa-accent), var(--aa-accent-2)); color: #fff; border-bottom-right-radius: 6px; }
.aa-row.sys .aa-bubble { background: transparent; border: 1px dashed var(--aa-panel-edge); color: var(--aa-dim); font-size: 13.5px; }
.aa-bubble .aa-retry {
  margin-top: 8px; display: inline-block;
  border: 1px solid var(--aa-accent); color: var(--aa-text); background: transparent;
  border-radius: 999px; padding: 5px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}

/* typing dots — shown only while a real request is in flight */
.aa-typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.aa-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--aa-dim); animation: aa-blink 1.2s infinite; }
.aa-typing i:nth-child(2) { animation-delay: .18s; }
.aa-typing i:nth-child(3) { animation-delay: .36s; }
@keyframes aa-blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }
.aa-status { font-size: 12.5px; color: var(--aa-dim); padding: 0 4px; }

/* quick-question chips */
.aa-chat-chips { flex: none; display: flex; gap: 7px; flex-wrap: wrap; padding: 8px 12px 2px; }
.aa-chip {
  border: 1px solid var(--aa-accent); color: var(--aa-text);
  background: rgba(255, 255, 255, .04); border-radius: 999px;
  padding: 7px 12px; font-size: 13px; cursor: pointer;
}
.aa-chip:hover { box-shadow: 0 0 10px var(--aa-glow); }

/* composer docked at the bottom of the panel */
.aa-chat-form {
  flex: none; display: flex; gap: 8px; align-items: center;
  padding: 11px 12px calc(11px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--aa-panel-edge);
}
.aa-chat-input {
  flex: 1; border-radius: 999px; border: 1px solid var(--aa-panel-edge);
  background: rgba(255, 255, 255, .06); color: var(--aa-text);
  padding: 11px 15px; font-size: 14.5px; font-family: inherit; outline: none;
}
.aa-chat-input:focus { border-color: var(--aa-accent); }
.aa-chat-input::placeholder { color: var(--aa-dim); }
.aa-chat-send {
  flex: none; width: 42px; height: 42px; border-radius: 50%; border: none;
  background: linear-gradient(135deg, var(--aa-accent), var(--aa-accent-2));
  color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 12px var(--aa-glow);
}
.aa-chat-send:disabled { opacity: .45; box-shadow: none; cursor: default; }
.aa-chat-send svg { width: 19px; height: 19px; }
