/* Buddy B · component layer
   Live components only where the element does not claim to be an app screen:
   KPI tiles, sparklines, rings, the area chart, the currency trio, the AI
   conversation and the support widget.

   Every app screen is a real capture. Nothing here rebuilds product UI. */

/* ---------------------------------------------------------------- KPI tile */
.kpi {
  position: relative; border-radius: 16px; padding: 20px;
  background: var(--paper); border: 1px solid var(--hairline);
  display: grid; gap: 10px; align-content: start; min-width: 0;
  transition: transform 200ms var(--ease), box-shadow 200ms var(--ease);
}
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow-card-hov); }
.band-dark .kpi, .kpi-inv {
  background: oklch(0.26 0.06 285); border-color: var(--hairline-inv); color: var(--ink-inv);
}
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.kpi-icon {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  display: grid; place-content: center;
  background: var(--accent-tint); color: var(--accent-press);
}
.band-dark .kpi-icon, .kpi-inv .kpi-icon { background: var(--accent-tint-inv); color: var(--accent-fg); }
.kpi-delta {
  font-family: var(--font-mono); font-size: 12px; font-weight: 500;
  font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; gap: 3px;
}
.kpi-delta[data-dir="up-good"]  { color: var(--success); }
.kpi-delta[data-dir="down-bad"] { color: var(--clay); }
.kpi-delta[data-dir="up-bad"]   { color: var(--clay); }
.kpi-delta[data-dir="flat"]     { color: var(--ink-50); }
.band-dark .kpi-delta[data-dir="flat"], .kpi-inv .kpi-delta[data-dir="flat"] { color: var(--ink-inv-50); }
.kpi-label { font-size: 13px; line-height: 1.35; color: var(--ink-50); }
.band-dark .kpi-label, .kpi-inv .kpi-label { color: var(--ink-inv-50); }
.kpi-value {
  font-family: var(--font-mono); font-weight: 500; font-size: 26px;
  letter-spacing: -0.025em; font-variant-numeric: tabular-nums; line-height: 1.1;
}
.kpi-spark { height: 28px; }

/* -------------------------------------------------------------- sparkline */
.spark { display: block; width: 100%; height: 100%; overflow: hidden; }
.spark path {
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.spark .area { stroke: none; fill: url(#sparkFade); opacity: 0.12; }
.spark.is-draw path.line { stroke-dasharray: var(--len, 300); stroke-dashoffset: var(--len, 300); }
.spark.is-draw.is-in path.line { stroke-dashoffset: 0; transition: stroke-dashoffset 900ms var(--ease-out); }
.spark-up   { color: var(--success); }
.spark-down { color: var(--clay); }
.spark-accent { color: var(--accent); }
.band-dark .spark-accent { color: var(--accent-fg); }

/* ------------------------------------------------------- concentric rings */
.rings { position: relative; width: 100%; max-width: 260px; aspect-ratio: 1; }
.rings svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.rings circle { fill: none; stroke-linecap: round; }
.rings .trk { stroke: var(--hairline); }
.band-dark .rings .trk { stroke: var(--hairline-inv); }
.rings .inc { stroke: var(--accent); }
.rings .exp { stroke: #E0A23A; }
.rings .inc, .rings .exp {
  stroke-dasharray: var(--c); stroke-dashoffset: var(--c);
  transition: stroke-dashoffset 1100ms var(--ease-out);
}
.rings.is-in .inc { stroke-dashoffset: calc(var(--c) - var(--c) * var(--p-inc, 1)); }
.rings.is-in .exp { stroke-dashoffset: calc(var(--c) - var(--c) * var(--p-exp, 0)); }
.rings-centre { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 6px; }
.rings-centre b { font-family: var(--font-mono); font-size: 34px; font-weight: 500; letter-spacing: -0.03em; }
.rings-centre span { font-size: 13px; color: var(--ink-50); line-height: 1.35; }

/* --------------------------------------------------- area chart, gradient */
.areachart { width: 100%; }
.areachart svg { width: 100%; height: 100%; display: block; }
.areachart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke;
  stroke-dasharray: var(--len, 600); stroke-dashoffset: var(--len, 600); }
.areachart .fill { stroke: none; fill: url(#smoke); opacity: 0; }
.areachart.is-in .line { stroke-dashoffset: 0; transition: stroke-dashoffset 1100ms var(--ease-out); }
.areachart.is-in .fill { opacity: 1; transition: opacity 900ms var(--ease) 300ms; }
.chart-cap { display: flex; justify-content: space-between; gap: 16px; margin-top: 14px; flex-wrap: wrap; }

/* -------------------------------------------------------- currency trio */
.trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 40px; }
.trio .kpi-value { font-size: 22px; }
.trio-note { margin-top: 16px; }

/* -------------------------------------------------------- metric strip */
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

/* --------------------------------------------------- AI live conversation */
.ai-live { display: grid; gap: 24px; }
.bubble {
  border-radius: 12px; padding: 16px; max-width: 520px;
  border: 1px solid var(--hairline-inv); background: oklch(0.225 0.055 292);
}
.bubble-you { border-bottom-left-radius: 6px; }
.bubble p.bubble-said { font-size: 15px; font-weight: 500; letter-spacing: -0.01em; line-height: 1.45; }
.bubble-said .caret {
  display: inline-block; width: 2px; height: 1em; background: var(--accent-fg);
  margin-left: 2px; vertical-align: -0.12em; animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.bubble p { font-size: var(--step-body); line-height: 1.55; margin: 0; max-width: none; }
.bubble-ai { background: var(--accent-tint-inv); border-color: oklch(0.711 0.148 294.9 / 0.24); border-bottom-right-radius: 6px; }
.txn {
  border-radius: 14px; border: 1px solid var(--hairline-inv); background: oklch(0.26 0.06 285);
  padding: 16px 20px; display: flex; align-items: center; gap: 16px; max-width: 440px;
}
.txn-icon { width: 36px; height: 36px; border-radius: 10px; flex: none; display: grid; place-content: center;
  background: var(--accent-tint-inv); color: var(--accent-fg); }
.txn-meta { flex: 1; min-width: 0; }
.txn-meta b { display: block; font-size: 16px; font-weight: 600; }
.txn-meta span { font-size: 13px; color: var(--ink-inv-50); }
.txn-amt { font-family: var(--font-mono); font-size: 19px; font-weight: 500; font-variant-numeric: tabular-nums; }
.beat-tile { max-width: 320px; }

/* --------------------------------------- support widget · page UI scale */
.support-launcher {
  position: fixed; right: 24px; bottom: 24px; z-index: 80;
  width: 58px; height: 58px; border-radius: 50%;
  background: oklch(0.20 0.075 292 / 0.88);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 0 0 1px oklch(0.58 0.22 285 / 0.24), 0 16px 40px -14px oklch(0.20 0.075 292 / 0.5);
  color: var(--ink-inv); display: grid; place-content: center; cursor: pointer;
  border: 0; transition: transform 220ms var(--ease-out);
  animation: breathe 4s var(--ease) infinite;
}
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 1px oklch(0.58 0.22 285 / 0.24), 0 16px 40px -14px oklch(0.20 0.075 292 / 0.5); }
  50%      { box-shadow: 0 0 0 5px oklch(0.58 0.22 285 / 0.14), 0 16px 40px -14px oklch(0.20 0.075 292 / 0.5); }
}
.support-launcher:hover { transform: translateY(-2px); animation-play-state: paused; }
.support-launcher.is-lifted { transform: translateY(-104px); }
.support-launcher.is-lifted:hover { transform: translateY(-106px); }

.support-panel {
  position: fixed; right: 24px; bottom: 24px; z-index: 90;
  width: min(380px, calc(100vw - 32px)); min-height: min(520px, calc(100vh - 48px));
  border-radius: 20px; overflow: hidden;
  background: oklch(0.20 0.075 292 / 0.92);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 0 0 1px oklch(0.95 0.02 292 / 0.10), 0 24px 64px rgba(25, 18, 61, 0.24);
  color: var(--ink-inv);
  display: grid; grid-template-rows: auto 1fr auto; grid-template-columns: minmax(0, 1fr);
  opacity: 0; transform: translateY(12px) scale(0.98); pointer-events: none;
  transition: opacity 240ms var(--ease), transform 260ms var(--ease-out);
}
.support-panel[data-open="true"] { opacity: 1; transform: none; pointer-events: auto; }
.support-panel[data-open="true"].is-lifted { transform: translateY(-104px); }
.support-head { padding: 24px 24px 16px; display: flex; justify-content: space-between; align-items: start; gap: 16px; }
/* flex items default to min-width:auto, so at 320 the head and the body push
   the panel wider than the viewport unless they are told they may shrink */
.support-head > div { min-width: 0; }
.support-panel { overflow: hidden; }
.support-body { min-width: 0; }
.support-head h4 { font-size: 17px; font-weight: 600; letter-spacing: -0.015em; }
.support-head p { font-size: 14px; color: var(--ink-inv-66); margin-top: 6px; max-width: 30ch; line-height: 1.45; }
.support-head .close { border: 0; background: transparent; color: var(--ink-inv-50); font-size: 22px; line-height: 1; padding: 4px; cursor: pointer; }
.support-body { padding: 0 24px 16px; display: grid; gap: 8px; align-content: start; overflow-y: auto; }
.support-body button {
  text-align: left; border: 1px solid oklch(0.95 0.02 292 / 0.12); border-radius: 12px;
  background: transparent; color: var(--ink-inv-66); padding: 14px 16px; cursor: pointer;
  font-size: 14px; line-height: 1.45; min-height: 44px;
  transition: transform 200ms var(--ease-out), border-color 200ms var(--ease), color 200ms var(--ease);
}
.support-body button:hover { transform: translateY(-2px); border-color: var(--accent-fg); color: var(--ink-inv); }
.support-foot { padding: 16px 24px 24px; display: flex; gap: 8px; align-items: center; }
.support-foot input {
  flex: 1; min-width: 0; min-height: 46px; border-radius: 23px; padding: 0 18px;
  border: 1px solid oklch(0.95 0.02 292 / 0.14); background: oklch(0.95 0.02 292 / 0.06);
  color: var(--ink-inv); font: inherit; font-size: 15px;
}
.support-foot input::placeholder { color: var(--ink-inv-50); }
.support-send {
  width: 46px; height: 46px; border-radius: 50%; border: 0; flex: none;
  background: var(--accent); color: #fff; cursor: pointer; display: grid; place-content: center;
  transition: background-color 200ms var(--ease), transform 180ms var(--ease);
}
.support-send:hover { background: var(--accent-hover); }
.support-send:active { transform: translateY(1px); }

@media (max-width: 640px) {
  .support-panel {
    right: 0; left: 0; bottom: 0; width: 100%; min-height: 0; max-height: 80vh;
    border-radius: 20px 20px 0 0; padding-bottom: env(safe-area-inset-bottom);
  }
  .support-panel[data-open="true"].is-lifted { transform: none; }
  .support-head p { max-width: 100%; }
  .support-launcher { right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); }
  .metrics, .trio { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .support-launcher { animation: none; }
  .spark.is-draw path.line, .areachart .line { stroke-dashoffset: 0 !important; }
  .areachart .fill { opacity: 1 !important; }
  .rings .inc { stroke-dashoffset: calc(var(--c) - var(--c) * var(--p-inc, 1)) !important; }
  .rings .exp { stroke-dashoffset: calc(var(--c) - var(--c) * var(--p-exp, 0)) !important; }
  .bubble-said .caret { display: none; }
}
