/* ───────── AI assistant bubble + panel ───────── */

.ai-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 80;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--surface);
  cursor: pointer;
  box-shadow: 0 10px 30px oklch(0.20 0.012 80 / 0.30), 0 2px 6px oklch(0.20 0.012 80 / 0.20);
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 13px;
  transition: transform 140ms, box-shadow 140ms, background 140ms;
}
.ai-bubble:hover { transform: translateY(-1px); box-shadow: 0 14px 36px oklch(0.20 0.012 80 / 0.35), 0 2px 8px oklch(0.20 0.012 80 / 0.25); }
.ai-bubble:active { transform: translateY(0); }
.ai-bubble.is-open {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  padding: 12px;
}
.ai-bubble-label { letter-spacing: -0.01em; }
.ai-bubble svg { color: var(--acc); }
.ai-bubble.is-open svg { color: var(--ink-2); }

.ai-bubble.is-pulse {
  animation: ai-bubble-pulse 1.2s ease-out;
}
@keyframes ai-bubble-pulse {
  0%   { box-shadow: 0 10px 30px oklch(0.20 0.012 80 / 0.30), 0 0 0 0 oklch(0.52 0.18 285 / 0.45); }
  70%  { box-shadow: 0 14px 36px oklch(0.20 0.012 80 / 0.35), 0 0 0 10px oklch(0.52 0.18 285 / 0); }
  100% { box-shadow: 0 10px 30px oklch(0.20 0.012 80 / 0.30), 0 0 0 0 oklch(0.52 0.18 285 / 0); }
}

/* Stack above estimator drawer when both floaters are visible */
.app:has(.est-drawer-toggle) .ai-bubble {
  bottom: 88px;
}
.app:has(.est-drawer-toggle) .ai-panel {
  bottom: 152px;
}

@media (max-width: 600px) {
  .ai-bubble-label { display: none; }
  .ai-bubble { padding: 14px; }
  .app:has(.est-drawer-toggle) .ai-bubble { bottom: 76px; }
  .app:has(.est-drawer-toggle) .ai-panel { bottom: 140px; }
}

/* ─── Panel ─── */
.ai-panel {
  position: fixed;
  bottom: 88px;
  right: 24px;
  z-index: 79;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100vh - 120px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 20px 60px oklch(0.20 0.012 80 / 0.25), 0 4px 16px oklch(0.20 0.012 80 / 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: ai-pop 200ms cubic-bezier(0.2, 0.8, 0.25, 1);
  transform-origin: bottom right;
}
@keyframes ai-pop {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.ai-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}
.ai-panel-head-left { display: flex; align-items: center; gap: 10px; }
.ai-panel-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--acc);
  display: grid; place-items: center;
}
.ai-panel-title { font-weight: 600; font-size: 13px; color: var(--ink); letter-spacing: -0.01em; }
.ai-panel-sub { font-size: 11px; color: var(--ink-3); margin-top: 1px; }

.ai-panel-head-right { display: flex; gap: 4px; }
.ai-icon-btn {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: transparent;
  border: 0;
  color: var(--ink-3);
  cursor: pointer;
  display: grid; place-items: center;
  transition: background 120ms, color 120ms;
}
.ai-icon-btn:hover { background: var(--bg); color: var(--ink); }

.ai-model-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.ai-model-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-3);
  white-space: nowrap;
}
.ai-model-select {
  flex: 1;
  min-width: 0;
  height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--ink);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.ai-model-select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ─── Live context strip ─── */
.ai-context {
  padding: 10px 16px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.ai-context-label {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
  margin-bottom: 6px;
}
.ai-context-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.ai-context-grid > div {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 8px;
  background: var(--bg-soft);
  border-radius: 6px;
  border: 1px solid var(--line);
}
.ai-context-grid .k { font-size: 10px; color: var(--ink-3); text-transform: lowercase; }
.ai-context-grid .v { font-size: 12px; font-weight: 600; color: var(--ink); }
.ai-context-grid .v.accent { color: var(--acc-ink); }

/* ─── Scroll area ─── */
.ai-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.ai-scroll::-webkit-scrollbar { width: 6px; }
.ai-scroll::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }

/* ─── Welcome ─── */
.ai-welcome { display: flex; flex-direction: column; gap: 12px; padding: 4px 0; }
.ai-welcome-text {
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.55;
  background: var(--acc-soft);
  border-radius: 12px;
  padding: 12px 14px;
  border: 1px solid oklch(0.92 0.05 285);
}
.ai-suggestions { display: flex; flex-direction: column; gap: 6px; }
.ai-suggestion {
  font-family: var(--font-sans);
  text-align: left;
  font-size: 12px;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  cursor: pointer;
  transition: border-color 120ms, background 120ms, color 120ms;
}
.ai-suggestion:hover {
  border-color: var(--acc);
  background: var(--acc-soft);
  color: var(--acc-ink);
}

/* ─── Messages ─── */
.ai-msg {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 13px;
  line-height: 1.5;
}
.ai-msg-user { flex-direction: row-reverse; }
.ai-msg-avatar {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  padding: 4px 6px;
  background: var(--bg-soft);
  border-radius: 4px;
  border: 1px solid var(--line);
  flex-shrink: 0;
  text-transform: uppercase;
  margin-top: 2px;
}
.ai-msg-user .ai-msg-avatar { background: var(--ink); color: var(--surface); border-color: var(--ink); }

.ai-msg-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 88%;
}
.ai-msg-user .ai-msg-body { align-items: flex-end; }

.ai-msg-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--bg-soft);
  color: var(--ink);
  border: 1px solid var(--line);
  font-size: 13px;
}
.ai-msg-user .ai-msg-bubble {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}

.ai-thinking {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 12px 16px;
}
.ai-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ink-3);
  animation: ai-bounce 1s infinite;
}
.ai-dot:nth-child(2) { animation-delay: 0.15s; }
.ai-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes ai-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ─── Apply price card ─── */
.ai-price-card {
  background: var(--surface);
  border: 1px solid var(--acc);
  box-shadow: 0 0 0 3px oklch(0.52 0.18 285 / 0.10);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-price-card-row { display: flex; justify-content: space-between; align-items: center; }
.ai-price-card-label {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
}
.ai-price-card-value {
  font-size: 22px;
  font-weight: 600;
  color: var(--acc-ink);
  letter-spacing: -0.02em;
}
.ai-apply-btn {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--acc);
  color: white;
  border: 0;
  cursor: pointer;
  transition: background 120ms;
}
.ai-apply-btn:hover { background: var(--acc-ink); }
.ai-apply-btn.is-applied { background: var(--good); cursor: default; }
.ai-apply-btn:disabled { opacity: 0.85; }

/* ─── Input row ─── */
.ai-input-row {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  align-items: flex-end;
}
.ai-input {
  flex: 1;
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.4;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--ink);
  outline: none;
  resize: none;
  max-height: 120px;
  min-height: 38px;
  transition: border-color 120ms, box-shadow 120ms, background 120ms;
}
.ai-input:focus { border-color: var(--acc); background: var(--surface); box-shadow: 0 0 0 3px oklch(0.52 0.18 285 / 0.12); }
.ai-input:disabled { opacity: 0.6; }

.ai-send {
  width: 38px; height: 38px;
  border-radius: 8px;
  background: var(--acc);
  color: white;
  border: 0;
  cursor: pointer;
  display: grid; place-items: center;
  transition: background 120ms, transform 80ms;
}
.ai-send:hover:not(:disabled) { background: var(--acc-ink); }
.ai-send:active:not(:disabled) { transform: scale(0.95); }
.ai-send:disabled { background: var(--line-strong); cursor: not-allowed; }

/* ─── Briefly highlight final price when AI applies ─── */
@keyframes ai-applied-pulse {
  0%   { box-shadow: 0 0 0 0 oklch(0.52 0.18 285 / 0.40); }
  100% { box-shadow: 0 0 0 14px oklch(0.52 0.18 285 / 0); }
}
.decider.is-ai-applied {
  animation: ai-applied-pulse 1.2s ease-out;
}

/* ─── Mobile fullscreen-ish ─── */
@media (max-width: 600px) {
  .ai-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 80px;
    height: calc(100vh - 100px);
  }
  .ai-bubble { right: 12px; bottom: 12px; }
}
