/* ============================================================
   Otto's Reasoning — canonical primitive
   ============================================================
   Per UX_STANDARD §4 ("Otto's Reasoning — MISSING — build
   canonical — HIGHEST PRIORITY") and OTTO_RELATIONSHIP §4.
   A small Otto glyph (not a `?`) attached to any Otto decision,
   suggestion, generated element, score, or autonomous action.
   Clicked, it opens Otto's reasoning about THAT exact thing —
   contextual, store-specific, in Otto's voice.

   Tokens consumed (no literals — see packages/shared/global.css):
     --cyan / --cyan-bg-soft / --cyan-border / --cyan-text-action
     --text-primary / --text-secondary / --text-tertiary
     --bg-glass / --surface-soft / --surface-border
     --shadow-active-glow / --shadow-focus-ring
     --motion-base / --motion-ease
   ============================================================ */

/* ---------- Trigger glyph ---------- */
.ro-otto-reasoning-glyph {
  /* Inline-token, sits next to a label or value. Size matches
     surrounding text so it never out-shouts the thing it's
     explaining — the eye lands on the thing, the glyph is a
     quiet invitation. */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: 6px;
  vertical-align: -3px;
  padding: 0;
  border: 1px solid var(--cyan-border-faint);
  border-radius: 50%;
  background: var(--cyan-bg-faint);
  color: var(--cyan-text-action);
  cursor: pointer;
  font-family: inherit;
  font-size: 0;
  line-height: 0;
  transition: background var(--motion-fast) var(--motion-ease),
              border-color var(--motion-fast) var(--motion-ease),
              box-shadow var(--motion-base) var(--motion-ease);
  /* When attached after a number/badge, the glyph reads as a
     'tap-to-see-why' affordance — never decoration. */
}
.ro-otto-reasoning-glyph svg {
  width: 11px;
  height: 11px;
  display: block;
  pointer-events: none;
  fill: currentColor;
}
.ro-otto-reasoning-glyph:hover {
  background: var(--cyan-bg-soft);
  border-color: var(--cyan-border);
}
.ro-otto-reasoning-glyph:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus-ring);
  border-color: var(--cyan-border);
}
.ro-otto-reasoning-glyph.is-open {
  background: var(--cyan-bg-hover);
  border-color: var(--cyan-border-strong);
  box-shadow: var(--shadow-active-glow);
}
.ro-otto-reasoning-glyph[disabled],
.ro-otto-reasoning-glyph[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---------- Popover ---------- */
.ro-otto-reasoning-popover {
  /* Positioned by JS — left/top set inline. Renders as an
     elevated glass panel rising toward the light (UX_STANDARD
     §1.5 — surfaces stack by being slightly lighter, not by
     hard drop shadows on paper). */
  position: fixed;
  z-index: 9999;
  max-width: 360px;
  min-width: 240px;
  padding: 14px 16px 12px;
  background: var(--bg-glass);
  border: 1px solid var(--cyan-border-faint);
  border-radius: 12px;
  box-shadow: var(--shadow-card-hover);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  color: var(--text-primary);
  font-family: var(--font, 'Inter', system-ui, sans-serif);
  font-size: 13px;
  line-height: 1.55;
  /* Opening motion — settles into place, doesn't snap. */
  opacity: 0;
  transform: translateY(4px) scale(0.98);
  transition: opacity var(--motion-base) var(--motion-ease),
              transform var(--motion-base) var(--motion-ease);
  pointer-events: none;
}
.ro-otto-reasoning-popover.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
@media (prefers-reduced-motion: reduce) {
  .ro-otto-reasoning-popover {
    transition: opacity 1ms;
    transform: none;
  }
  .ro-otto-reasoning-popover.is-open { transform: none; }
}

/* ---------- Popover header ---------- */
.ro-otto-reasoning-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.ro-otto-reasoning-avatar {
  /* Subtle Otto glyph — the bioluminescent moment of life.
     Per UX_STANDARD §1.5 — one focal point of glow per view;
     when the popover is open, this is it. */
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--cyan-bg-hover);
  border: 1px solid var(--cyan-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cyan);
  flex-shrink: 0;
  box-shadow: var(--shadow-active-glow);
}
.ro-otto-reasoning-avatar svg {
  width: 13px;
  height: 13px;
  display: block;
  fill: currentColor;
}
.ro-otto-reasoning-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  flex: 1;
  min-width: 0;
}
.ro-otto-reasoning-close {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  margin: -4px -6px -4px 0;
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  transition: color var(--motion-fast) var(--motion-ease),
              background var(--motion-fast) var(--motion-ease);
}
.ro-otto-reasoning-close:hover {
  color: var(--text-primary);
  background: var(--surface-soft);
}
.ro-otto-reasoning-close:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus-ring);
}

/* ---------- Popover body ---------- */
.ro-otto-reasoning-body {
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.6;
  /* Otto's voice prose — generous line-height, no decoration. */
}
.ro-otto-reasoning-body p { margin: 0 0 8px; }
.ro-otto-reasoning-body p:last-child { margin-bottom: 0; }
.ro-otto-reasoning-body strong {
  color: var(--text-primary);
  font-weight: 600;
}
.ro-otto-reasoning-body em {
  color: var(--cyan-text-action);
  font-style: normal;
  font-weight: 500;
}
/* Optional "Why I picked this" structured list — used when reasoning
   has bullet factors (e.g., per-axis quality scores). */
.ro-otto-reasoning-body ul {
  margin: 8px 0 0;
  padding-left: 18px;
  list-style: disc;
}
.ro-otto-reasoning-body li {
  margin-bottom: 4px;
  color: var(--text-secondary);
}
.ro-otto-reasoning-body li strong { color: var(--text-primary); }

/* ---------- Popover arrow (visual hint of which thing it's about) ---------- */
.ro-otto-reasoning-popover::before {
  content: '';
  position: absolute;
  width: 10px;
  height: 10px;
  background: inherit;
  border: 1px solid var(--cyan-border-faint);
  border-bottom: 0;
  border-right: 0;
  transform: rotate(45deg);
  top: -6px;
  left: var(--ro-otto-arrow-x, 24px);
}
.ro-otto-reasoning-popover[data-placement="top"]::before {
  top: auto;
  bottom: -6px;
  border-top: 0;
  border-left: 0;
  border-right: 1px solid var(--cyan-border-faint);
  border-bottom: 1px solid var(--cyan-border-faint);
}

/* ---------- Mobile — full-width sheet from the bottom ---------- */
@media (max-width: 540px) {
  .ro-otto-reasoning-popover {
    /* On a phone the popover becomes an action sheet at the bottom
       of the viewport — readable + thumb-reachable. JS resets
       inline left/top when it adds the .is-sheet class. */
    left: 12px !important;
    right: 12px !important;
    top: auto !important;
    bottom: 12px !important;
    max-width: none;
    transform: translateY(8px) scale(1);
  }
  .ro-otto-reasoning-popover.is-open { transform: translateY(0) scale(1); }
  .ro-otto-reasoning-popover::before { display: none; }
}
