/* ─── AI Input Widget ─────────────────────────────────────────────────────── */

/* ColorOrb — brand palette (teal #2DB84B + amber #F5A623) */
@property --ai-orb-angle {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}

.ai-color-orb {
  /* 24 px orb. scale(1.1) → 26.4 px rendered.
     Container is 28 px so the panel's overflow:hidden never clips it. */
  width: 24px;
  height: 24px;
  display: grid;
  grid-template-areas: "stack";
  overflow: hidden;
  border-radius: 50%;
  position: relative;
  transform: scale(1.1);
  flex-shrink: 0;
  isolation: isolate;
}

.ai-color-orb::before,
.ai-color-orb::after {
  content: "";
  display: block;
  grid-area: stack;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  transform: translateZ(0);
}

/* Brand-colour conic gradients: teal greens + amber gold */
.ai-color-orb::before {
  background:
    conic-gradient(from calc(var(--ai-orb-angle) *  2) at 25% 70%,
      oklch(65% 0.18 142), transparent 20% 80%, oklch(65% 0.18 142)),
    conic-gradient(from calc(var(--ai-orb-angle) *  2) at 45% 75%,
      oklch(76% 0.17 66),  transparent 30% 60%, oklch(76% 0.17 66)),
    conic-gradient(from calc(var(--ai-orb-angle) * -3) at 80% 20%,
      oklch(55% 0.15 142), transparent 40% 60%, oklch(55% 0.15 142)),
    conic-gradient(from calc(var(--ai-orb-angle) *  2) at 15%  5%,
      oklch(76% 0.17 66),  transparent 10% 90%, oklch(76% 0.17 66)),
    conic-gradient(from calc(var(--ai-orb-angle) *  1) at 20% 80%,
      oklch(65% 0.18 142), transparent 10% 90%, oklch(65% 0.18 142)),
    conic-gradient(from calc(var(--ai-orb-angle) * -2) at 85% 10%,
      oklch(55% 0.15 142), transparent 20% 80%, oklch(55% 0.15 142));
  box-shadow: inset oklch(20% 0.02 142 / 0.28) 0 0 0.5px 0.1px;
  filter: contrast(1.08) saturate(1.02);
  animation: ai-orb-spin 18s linear infinite;
}

.ai-color-orb::after {
  background:
    radial-gradient(circle at 30% 30%, rgba(255,255,255,.22), transparent 38%),
    radial-gradient(circle at 72% 70%, rgba(255,255,255,.12), transparent 42%);
  opacity: .9;
}

@keyframes ai-orb-spin {
  to { --ai-orb-angle: 360deg; }
}

@media (prefers-reduced-motion: reduce) {
  .ai-color-orb::before { animation: none; }
}

@media (hover: none), (pointer: coarse) {
  .ai-color-orb {
    transform: none;
  }

  .ai-color-orb::before {
    box-shadow: none;
    filter: none;
  }

  .ai-color-orb::after {
    opacity: .45;
  }
}

/* ── Widget root ─────────────────────────────────────────────────────────── */
#ai-widget {
  position: fixed;
  z-index: 9000;
  pointer-events: none;
  bottom: 24px;
  right: 24px;
}

.ai-mobile-nudge {
  position: absolute;
  right: 58px;
  bottom: 4px;
  display: block;
  min-width: max-content;
  padding: 9px 12px;
  border-radius: 999px;
  background: var(--surface, #fff);
  border: 1px solid var(--bone, #e8e4dc);
  box-shadow:
    0 12px 28px rgba(31, 36, 32, 0.14),
    0 2px 8px rgba(31, 36, 32, 0.08);
  color: var(--charcoal, #27211e);
  font-family: var(--body, inherit);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  transform: translateX(8px) scale(0.96);
  transition: opacity 0.22s ease, transform 0.22s ease;
  isolation: isolate;
}

.ai-panel.ai-nudge-visible:not(.ai-open) .ai-mobile-nudge {
  opacity: 1;
  transform: translateX(0) scale(1);
}

.ai-panel.ai-nudge-visible:not(.ai-open) {
  overflow: visible;
}

@media (max-width: 600px) {
  /* Mobile: anchored to bottom-right */
  #ai-widget {
    bottom: 20px;
    right: 16px;
    left: auto;
    transform: none;
  }
}

/* ── Morphing panel ──────────────────────────────────────────────────────── */
.ai-panel {
  pointer-events: all;
  background: var(--surface, #f9f7f3);
  border: 1px solid var(--bone, #e8e4dc);
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  position: relative;

  width: 48px;
  height: 48px;
  border-radius: 50%;

  /* Smooth morph between dock and chat card. */
  transition:
    width         0.34s cubic-bezier(0.22, 1, 0.36, 1),
    height        0.34s cubic-bezier(0.22, 1, 0.36, 1),
    border-radius 0.28s ease,
    box-shadow    0.28s ease;

  box-shadow:
    0 4px 24px rgba(31, 36, 32, 0.12),
    0 1px 4px  rgba(31, 36, 32, 0.06);
}

/* Desktop open */
.ai-panel.ai-open {
  width: 360px;
  height: 268px;
  border-radius: 14px;
  overflow: hidden;
  transition:
    width         0.34s cubic-bezier(0.22, 1, 0.36, 1),
    height        0.34s cubic-bezier(0.22, 1, 0.36, 1),
    border-radius 0.28s ease,
    box-shadow    0.28s ease;
}

@media (max-width: 600px) {
  .ai-panel.ai-open {
    width: calc(100vw - 32px);
    max-width: 400px;
    height: 290px;
    border-radius: 16px;
    transition:
      width         0.34s cubic-bezier(0.22, 1, 0.36, 1),
      height        0.34s cubic-bezier(0.22, 1, 0.36, 1),
      border-radius 0.28s ease,
      box-shadow    0.28s ease;
  }
}

/* ── Dock bar ────────────────────────────────────────────────────────────── */
.ai-dock {
  margin-top: auto;
  display: flex;
  height: 44px;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  user-select: none;
  gap: 8px;
  padding: 0 12px;
  flex-shrink: 0;
  width: 100%;
  box-sizing: border-box;
}

/* On mobile the closed panel is exactly 48 px — centre the orb */
@media (max-width: 600px) {
  .ai-dock {
    margin-top: 0;
    height: 48px;
    padding: 0;
    justify-content: center;
  }
}

/* Orb container — 28 px gives 0.8 px clearance for scale(1.1) on each side */
.ai-dock-orb {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  opacity: 1;
  transition: opacity 0.18s ease;
}

/* Hide the dock orb when panel is open (the form-header orb takes over) */
.ai-panel.ai-open .ai-dock-orb {
  opacity: 0;
  pointer-events: none;
}

.ai-panel.ai-open .ai-dock {
  opacity: 0;
  pointer-events: none;
}

/* Text label is only for accessibility; the closed widget is icon-only. */
.ai-trigger-label {
  display: none;
}

.ai-trigger-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 999px;
  transition: background 0.15s;
  /* On mobile the button fills the whole 48 px circle */
  -webkit-tap-highlight-color: transparent;
  tap-highlight-color: transparent;
}

@media (max-width: 600px) {
  .ai-trigger-btn {
    width: 48px;
    height: 48px;
  }
}

.ai-trigger-btn {
  width: 48px;
  height: 48px;
  padding: 0;
  justify-content: center;
}

.ai-trigger-btn:hover {
  background: oklch(92% 0.01 100);
}

@media (max-width: 600px) {
  .ai-trigger-btn:hover { background: none; }
}

/* ── Form ────────────────────────────────────────────────────────────────── */
.ai-form {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 268px;
  display: flex;
  flex-direction: column;
  padding: 4px;
  box-sizing: border-box;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease;
}

.ai-panel.ai-open .ai-form {
  opacity: 1;
  pointer-events: all;
  transition: opacity 0.16s ease 0.16s;
}

@media (max-width: 600px) {
  .ai-form { height: 290px; }
}

/* ── Form header ─────────────────────────────────────────────────────────── */
.ai-form-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 6px 6px 0;
  flex-shrink: 0;
}

.ai-form-orb {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.ai-form-title {
  font-size: 14px;
  color: var(--charcoal, #27211e);
  font-weight: 600;
  user-select: none;
  flex: 1;
  font-family: var(--head, inherit);
}

/* Close / back button */
.ai-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 8px;
  color: var(--stone, #6b6560);
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.ai-close-btn:hover {
  background: var(--bone, #e8e4dc);
  color: var(--charcoal, #27211e);
}

/* Keyboard hint — desktop only */
.ai-kbd-hint {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-right: 2px;
}

@media (max-width: 600px) {
  .ai-kbd-hint { display: none; }
}

.ai-kbd-hint kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  min-width: 22px;
  padding: 0 5px;
  border-radius: 4px;
  border: 1px solid var(--bone, #e8e4dc);
  font-family: var(--body, inherit);
  font-size: 11px;
  color: var(--stone, #6b6560);
  background: var(--surface, #f9f7f3);
  line-height: 1;
}

/* ── Greeting bubble ─────────────────────────────────────────────────────── */
.ai-greeting {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px 4px;
  flex-shrink: 0;

  /* hidden until panel opens */
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  /* delay so it appears after the morph finishes */
  transition-delay: 0.22s;
  pointer-events: none;
}

.ai-panel.ai-open .ai-greeting {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.ai-greeting-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 4px;
  overflow: hidden;
  padding: 2px;
  box-sizing: border-box;
}

.ai-greeting-bubble {
  background: var(--bone, #e8e4dc);
  border-radius: 4px 14px 14px 14px;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--charcoal, #27211e);
  max-width: calc(100% - 44px);
  max-height: 122px;
  overflow-y: auto;
}

/* ── Textarea wrapper + send button ─────────────────────────────────────── */
.ai-textarea-wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  position: relative;
  margin: 0 4px 4px;
  background: transparent;
  border-radius: 10px;
  overflow: hidden;
}

.ai-textarea {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  padding: 8px 44px 8px 12px;
  font-family: var(--body, inherit);
  font-size: 14px;
  color: var(--charcoal, #27211e);
  background: transparent;
  line-height: 1.6;
  scroll-padding-block: 8px;
  min-height: 36px;
  max-height: 120px;
}

.ai-textarea::placeholder {
  color: var(--pebble, #a09a93);
}

.ai-send-btn {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: oklch(65% 0.18 142);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.ai-send-btn:hover {
  background: oklch(55% 0.15 142);
}

.ai-send-btn:disabled,
.ai-textarea:disabled {
  cursor: wait;
}

.ai-send-btn:disabled {
  opacity: 0.72;
  transform: none;
}

.ai-send-btn:active {
  transform: scale(0.92);
}

.ai-disclaimer {
  margin: 0 12px 10px;
  color: var(--pebble, #8c857e);
  font-size: 11px;
  line-height: 1.45;
}

.ai-panel.ai-loading .ai-greeting-bubble::after {
  content: "";
  display: inline-block;
  width: 1.2em;
  margin-left: 2px;
  animation: ai-loading-dots 1.2s steps(4, end) infinite;
}

/* ── Response message ────────────────────────────────────────────────────── */
.ai-response {
  padding: 6px 14px 8px;
  font-size: 13px;
  color: var(--stone, #6b6560);
  line-height: 1.6;
  border-top: 1px solid var(--bone, #e8e4dc);
  animation: ai-fade-in 0.2s ease;
}

.ai-response a {
  color: var(--teal-d, #239040);
  text-decoration: underline;
}

@keyframes ai-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes ai-loading-dots {
  0%   { content: ""; }
  25%  { content: "."; }
  50%  { content: ".."; }
  75%,
  100% { content: "..."; }
}
