/* In-chat Chart.js cards — layout only; drawing is Chart.js */

.sw-widget-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 14px 0 4px;
  width: 100%;
  min-width: 0;
}

.sw-widget {
  border: 1px solid var(--sw-border, rgba(255, 255, 255, 0.08));
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.035);
  padding: 10px 16px 14px;
  min-width: 0;
  overflow: visible;
}

/* Bar: modest bottom pocket under x-axis labels. */
.sw-widget--bar {
  padding-bottom: 12px;
}

.sw-widget--enter {
  opacity: 0;
  transform: translate3d(0, 8px, 0);
  transition:
    opacity 0.38s var(--sw-motion-soft, ease),
    transform 0.38s var(--sw-motion-spring, cubic-bezier(0.22, 1, 0.36, 1));
  will-change: opacity, transform;
}

.sw-widget--enter.is-ready {
  opacity: 1;
  transform: none;
  will-change: auto;
}

.sw-widget__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  min-width: 0;
}

.sw-widget__title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--sw-text-main, var(--glass-text, #f2f2f2));
  opacity: 0.95;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
}

.sw-widget__download {
  appearance: none;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--sw-text-muted, rgba(255, 255, 255, 0.55));
  cursor: pointer;
  transition:
    color 0.18s ease,
    background 0.18s ease;
}

.sw-widget__download:hover {
  color: var(--sw-text-main, #fff);
  background: rgba(255, 255, 255, 0.08);
}

.sw-widget__download:active {
  background: rgba(255, 255, 255, 0.06);
}

.sw-widget__download:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.28);
  outline-offset: 2px;
}

.sw-widget__download.is-error {
  color: #e89090;
}

/* Message export icon is 22px — chart uses a slightly smaller glyph. */
.sw-widget__download-icon {
  width: 16px;
  height: 16px;
  display: block;
  overflow: visible;
  color: inherit;
}

/* Type caption removed from UI — keep rule so stale DOM never shows it. */
.sw-widget__kind {
  display: none !important;
}

.sw-widget__note {
  margin: 8px 0 0;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--sw-text-muted, rgba(255, 255, 255, 0.45));
}

.sw-widget__chart-frame {
  position: relative;
  width: 100%;
  height: 220px;
  min-height: 180px;
  overflow: visible;
}

.sw-widget--donut .sw-widget__chart-frame {
  height: 200px;
}

.sw-widget__body {
  display: block;
  min-width: 0;
}

/* Desktop donut keeps Chart.js legend — hide the mobile ref list. */
.sw-widget__ref {
  display: none;
  list-style: none;
  margin: 0;
  padding: 0;
}

.sw-widget__canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  image-rendering: auto;
}

body.is-mobile .sw-widget__canvas {
  filter: none !important;
}

/*
 * Hover tip: soft opacity fade only.
 * Transform stays a fixed anchor — never animate Y/scale (that caused the jerk).
 */
.sw-widget__tip {
  --tip-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  position: absolute;
  left: 0;
  top: 0;
  z-index: 6;
  width: max-content;
  min-width: 132px;
  /* Final max-width set in placeTip() from .sw-widget width — avoid frame clamp. */
  max-width: 440px;
  padding: 10px 12px 11px;
  box-sizing: border-box;
  border-radius: 12px;
  border: 1px solid var(--sw-border-strong, rgba(255, 255, 255, 0.08));
  background: var(--sw-bg-main, #191919);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
  pointer-events: none;
  overflow: visible;
  opacity: 0;
  visibility: hidden;
  transform: translate3d(-50%, calc(-100% - 12px), 0);
  transform-origin: 50% 100%;
  transition:
    opacity 0.48s var(--tip-ease),
    visibility 0s linear 0.48s;
  will-change: opacity;
}

.sw-widget__tip.is-below {
  transform: translate3d(-50%, 12px, 0);
  transform-origin: 50% 0%;
}

.sw-widget__tip.is-open {
  opacity: 1;
  visibility: visible;
  transition:
    opacity 0.42s var(--tip-ease),
    visibility 0s linear 0s;
}

.sw-widget__tip.is-open.is-below {
  transform: translate3d(-50%, 12px, 0);
}

.sw-widget__tip.is-instant {
  transition: none !important;
}

/* Legacy kicker (chart title) — never show. */
.sw-widget__tip-kicker {
  display: none !important;
}

.sw-widget__tip-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--sw-text-muted, rgba(255, 255, 255, 0.62));
  line-height: 1.4;
  margin: 0 0 4px;
  white-space: normal;
  overflow: visible;
  overflow-wrap: break-word;
  word-break: normal;
  hyphens: auto;
}

.sw-widget__tip-value {
  display: block;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.03em;
  color: var(--sw-text-main, #f4f6fb);
  line-height: 1.2;
  overflow: visible;
  white-space: normal;
  overflow-wrap: break-word;
}

.sw-widget__tip-meta {
  margin-top: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--sw-text-muted, rgba(255, 255, 255, 0.5));
  line-height: 1.3;
}

.sw-widget__tip-meta[hidden] {
  display: none;
}

@media (max-width: 640px) {
  .sw-widget__chart-frame {
    height: 200px;
  }

  .sw-widget__head {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .sw-widget__tip {
    min-width: 120px;
    max-width: 440px;
    padding: 10px 12px 11px;
  }

  .sw-widget__tip-value {
    font-size: 16px;
  }
}

/* —— Mobile dashboards: wide card, centered title, calm chart —— */
body.is-mobile .sw-widget-stack {
  gap: 8px;
  margin: 8px 0 2px;
  width: 100%;
}

/*
 * Stay inside the chat column — never bleed past the viewport edges.
 * (Previous calc(100% + 36px) / -18px pulled cards off-screen.)
 */
body.is-mobile .msg.assistant .sw-widget-stack {
  width: 100% !important;
  max-width: 100% !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  box-sizing: border-box;
  min-width: 0;
}

body.is-mobile .sw-widget {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box;
  min-width: 0;
  border-radius: 12px;
  border: 0 !important;
  box-shadow: none !important;
  padding: 6px 10px 8px;
  background: rgba(255, 255, 255, 0.035);
}

body.is-mobile .sw-widget--bar {
  padding-bottom: 6px;
}

body.is-mobile .sw-widget__head {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  margin-bottom: 2px;
  gap: 0;
  padding: 0 34px;
  min-height: 26px;
}

body.is-mobile .sw-widget__title {
  flex: 1 1 auto;
  margin: 0;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.is-mobile .sw-widget__download {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
}

body.is-mobile .sw-widget__chart-frame {
  height: 168px;
  min-height: 148px;
}

/* Mobile donut: smaller circle on the left, compact ref on the right. */
body.is-mobile .sw-widget--donut .sw-widget__body {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

body.is-mobile .sw-widget--donut .sw-widget__chart-frame {
  flex: 0 0 168px;
  width: 168px;
  height: 168px;
  min-height: 168px;
  max-width: 168px;
}

body.is-mobile .sw-widget--donut .sw-widget__ref {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  max-height: 168px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

body.is-mobile .sw-widget--donut .sw-widget__ref::-webkit-scrollbar {
  display: none;
}

body.is-mobile .sw-widget--donut .sw-widget__ref-item {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  min-width: 0;
}

body.is-mobile .sw-widget--donut .sw-widget__ref-swatch {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-top: 4px;
  border-radius: 2px;
}

body.is-mobile .sw-widget--donut .sw-widget__ref-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

body.is-mobile .sw-widget--donut .sw-widget__ref-label {
  font-size: 11px;
  font-weight: 500;
  line-height: 1.25;
  color: rgba(255, 255, 255, 0.78);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.is-mobile .sw-widget--donut .sw-widget__ref-value {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  color: rgba(255, 255, 255, 0.92);
  font-variant-numeric: tabular-nums;
}

body.is-mobile .sw-widget__data {
  display: none !important;
}

body.is-mobile .sw-widget__note {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .sw-widget--enter {
    opacity: 1;
    transform: none;
    transition: none;
  }

  .sw-widget__tip {
    transition: none;
  }
}
