/*
 * message-viz-inline.css — styling for live ```viz components rendered inline in
 * the conversation by message-viz-inline.js. Kept minimal and theme-aware (uses
 * LibreChat surface/border tokens) so it blends with chat bubbles in light/dark.
 */

.viz-inline-hidden {
  display: none !important;
}

.viz-inline-card {
  position: relative; /* anchor for the absolutely-positioned expand button */
  width: 100%;
  margin: 0.5rem 0 0.75rem;
  border: 1px solid var(--border-light, #e5e7eb);
  border-radius: 0.75rem;
  overflow: hidden;
  background: var(--surface-primary, #fff);
}

/* "expand" button pinned INSIDE the inner content card (#viz-capture) of the
   chart — inset past the iframe's 20px body padding so it sits fully on the white
   surface (not straddling the gray padding / outer edge), with a contrasting
   light-slate fill so it stands apart from that white. Opens the fitted modal.
   The viz inner card is the design-style surface (light) regardless of the chat
   theme, so this is a single light treatment (no .dark override). It is hidden
   until the viz reports a height — and removed for dashboards, which supply their
   own per-component buttons (see message-viz-inline.js). */
.viz-inline-expand {
  position: absolute;
  top: 28px;
  left: 28px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(15, 23, 42, 0.14);
  border-radius: 9px;
  background: rgba(233, 238, 246, 0.96);
  color: var(--brand-medium, #25408f);
  cursor: pointer;
  box-shadow: 0 2px 7px rgba(15, 23, 42, 0.16);
  transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}

/* shown only once the viz reports its height (see resolveExpandButton) */
.viz-inline-expand-pending {
  display: none;
}

.viz-inline-expand:hover {
  background: var(--brand-medium, #25408f);
  color: #fff;
  box-shadow: 0 4px 12px rgba(37, 64, 143, 0.34);
  transform: translateY(-1px);
}

.viz-inline-expand:active {
  transform: translateY(0);
}

.viz-inline-expand svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

/* The card stays at the text-column width. The chart is RENDERED wide (DESIGN_WIDTH,
   set per-card in JS — a width where legends/labels have room and never overlap) on
   the .viz-inline-scaler, which is then transform-scaled DOWN so the *visible* box
   equals the column. The .viz-inline-sizer carries that SCALED height (also set in
   JS), so the card flows correctly (e.g. a dashboard actions bar sits right below)
   and NOTHING ever scrolls horizontally. Users click the expand button for a larger,
   full-resolution view. Mirrors the fitted-modal scaler pattern below. */
.viz-inline-sizer {
  position: relative;
  width: 100%;
  overflow: hidden;
  min-height: 120px;
}

.viz-inline-scaler {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: top left;
  /* width / height / transform are assigned per-card in JS (applyScale) */
}

.viz-inline-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
}

.viz-inline-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 12px;
  border-top: 1px solid var(--border-light, #e5e7eb);
  direction: rtl;
}

/* "הורד" button + "פתח בלשונית חדשה" link share the same subtle, secondary look. */
.viz-inline-actions .viz-inline-newtab,
.viz-inline-actions .viz-inline-download {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  font-family: inherit;
  line-height: 1.4;
  color: var(--text-secondary, #6b7280);
  text-decoration: none;
  background: none;
  border: 0;
  padding: 2px 4px;
  border-radius: 6px;
  cursor: pointer;
}

.viz-inline-actions .viz-inline-newtab:hover,
.viz-inline-actions .viz-inline-download:hover {
  color: var(--text-primary, #111827);
  text-decoration: underline;
}

.viz-inline-actions .viz-inline-download.viz-inline-download-busy {
  cursor: default;
  opacity: 0.7;
  text-decoration: none;
}

.viz-inline-download svg {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
}

.viz-inline-spin {
  animation: viz-inline-spin 1s linear infinite;
}

@keyframes viz-inline-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* transient feedback toast (errors / auth) */
.viz-inline-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #25408f;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  z-index: 99999;
  direction: rtl;
  font-size: 14px;
  font-family: inherit;
  max-width: 320px;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.viz-inline-toast.viz-inline-toast-error {
  background: #b91c1c;
}

.viz-inline-toast.viz-inline-toast-show {
  opacity: 1;
}

/* ── Fitted modal (expand-to-fill-page) ─────────────────────────────────────── */

.viz-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.62);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.viz-modal-overlay.viz-modal-overlay-show {
  opacity: 1;
}

/* centered loading spinner shown until the viz reports its height */
.viz-modal-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255, 255, 255, 0.9);
  pointer-events: none;
}

.viz-modal-overlay.viz-modal-loaded .viz-modal-spinner {
  display: none;
}

/* the white window — sized in JS to the fitted content (matches the chart ratio) */
.viz-modal-card {
  position: relative;
  overflow: hidden;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.42);
  width: 60vw;
  height: 40vh;
  opacity: 0;
  transition: opacity 0.2s ease, width 0.16s ease, height 0.16s ease;
}

.viz-modal-card.viz-modal-card-ready {
  opacity: 1;
}

/* holds the iframe at its natural render box; transform-scaled to fit */
.viz-modal-scaler {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: top left;
}

.viz-modal-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.viz-modal-close {
  position: fixed;
  top: 16px;
  right: 18px;
  z-index: 100001;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  color: #16213f;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  transition: background 0.15s ease, transform 0.12s ease;
}

.viz-modal-close:hover {
  background: #fff;
  transform: scale(1.06);
}

.viz-modal-close svg {
  width: 22px;
  height: 22px;
}
