/* Main chat area */

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  position: relative;
}

/* Plugin page view */
.chat-page-view {
  display: none;
  flex: 1;
  overflow: hidden;
  position: relative;
}

.chat-page-view.active {
  display: flex;
}

.chat-page-iframe {
  width: 100%;
  height: 100%;
  border: none;
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Chat body: messages col + shop panel sit side-by-side */
.chat-body {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  min-height: 0;
}

/* Left column: messages + input stacked */
.chat-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  position: relative;
}

.chat-col > .chat-messages {
  flex: 1;
  min-width: 0;
}

/* Hide the chat body (messages + input) when a page view is open */
.chat-main.page-mode .chat-body {
  display: none;
}

/* Script panel resize handle */
.cs-script-resize-handle {
  position: absolute;
  left: -4px;
  top: 0;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 20;
  background: transparent;
}

.cs-script-resize-handle::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 0;
  width: 1px;
  height: 100%;
  background: transparent;
  transition: background 0.15s;
}

.cs-script-resize-handle:hover::after,
.cs-script-panel.resizing .cs-script-resize-handle::after {
  background: var(--color-text-faint);
}

/* Resize handle tooltip — left-side, uses ui-tooltip tokens */
.cs-script-resize-tooltip {
  position: absolute;
  right: calc(100% + 8px);
  top: 50%; /* fallback; overridden by JS on mousemove */
  transform: translateX(4px) translateY(-50%);
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 0.5rem;
  padding: 0.4rem 0.75rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition:
    opacity 0.15s,
    transform 0.15s;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.cs-script-resize-handle:hover .cs-script-resize-tooltip {
  opacity: 1;
  transform: translateX(0) translateY(-50%);
}

.cs-script-panel.resizing .cs-script-resize-tooltip {
  opacity: 0 !important;
}

.cs-script-resize-tooltip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.cs-script-resize-tooltip-label {
  font-weight: 500;
  min-width: 46px;
}

.cs-script-resize-tooltip-hint {
  opacity: 0.55;
}

.cs-script-panel.resizing {
  transition: none;
  user-select: none;
}

/* Script panel — inline column that pushes the iframe left */
.cs-script-panel {
  position: relative;
  width: 0;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--color-bg);
  border-left: none;
  display: flex;
  flex-direction: column;
  transition:
    width 0.48s cubic-bezier(0.4, 0, 0.2, 1),
    border-color 0.48s;
}

.cs-script-panel.open {
  width: 400px;
  border-left: 1px solid var(--color-border);
  overflow: visible;
}

.cs-script-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0 1rem 0.75rem;
  flex-shrink: 0;
  white-space: nowrap;
}

/* cs-script-header tabs — fill available width inside the script panel
   so all three triggers share width equally. Visual styles inherited from
   .ui-tabs-* base in design-system.css. */
.cs-script-header .ui-tabs {
  flex: 1;
  min-width: 0;
}

.cs-script-header .ui-tabs-list {
  width: 100%;
}

.cs-script-header .ui-tab-trigger {
  flex: 1;
}

.cs-script-header .ui-tabs-slider {
  transition:
    transform 0.22s cubic-bezier(0.4, 0, 0.2, 1),
    width 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Close button — matches chat-page-back-btn-wrap style */
.cs-script-close-wrap {
  display: flex;
  align-items: center;
  background: var(--chat-surface-hover);
  border-radius: var(--radius-full);
  border: var(--border-width-1) solid var(--chat-border);
  padding: 0.2rem;
  flex-shrink: 0;
}

html[data-theme="light"] .cs-script-close-wrap {
  background: var(--color-white);
}

.cs-script-close {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--chat-text);
  transition:
    background 0.15s,
    color 0.15s;
  flex-shrink: 0;
}

html[data-theme="light"] .cs-script-close {
  color: var(--chat-text-muted);
}

.cs-script-close:hover {
  background: var(--chat-surface-hover-dark);
  color: var(--chat-text);
}

.cs-script-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  white-space: normal;
}

.cs-script-tab-panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.5rem 1.25rem;
  scrollbar-width: thin;
}

.cs-script-tab-panel.active {
  display: flex;
  flex-direction: column;
}

.cs-script-embed-panel {
  padding: 0;
}

.cs-script-embed-panel.active {
  display: flex;
}

.cs-script-figma-embed {
  flex: 1;
  width: 100%;
  border: none;
  min-height: 0;
}

.cs-figma-fallback {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex: 1;
  padding: 2rem 1.5rem;
  text-align: center;
}

.cs-figma-fallback-copy {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  line-height: 1.6;
  max-width: 260px;
  margin: 0;
}

.cs-figma-fallback-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: 0.5rem 1rem;
  text-decoration: none;
  transition:
    background 0.15s,
    border-color 0.15s;
}

.cs-figma-fallback-btn:hover {
  background: var(--color-surface-hover);
  border-color: var(--color-text-muted);
}

.cs-script-placeholder {
  font-size: 0.9375rem;
  color: var(--color-text-muted);
  line-height: 1.6;
  margin: 0;
}

/* Script content typography */
.cs-script-content {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  width: 100%;
}

.cs-script-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.cs-script-section-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
}

.cs-script-p {
  font-size: 0.9375rem;
  color: var(--color-text);
  line-height: 1.65;
  margin: 0;
}

.cs-script-list {
  margin: 0;
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.cs-script-list li {
  font-size: 0.9375rem;
  color: var(--color-text);
  line-height: 1.65;
}

.cs-script-callout-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.cs-script-callout-list li {
  font-size: 0.9375rem;
  color: var(--color-text);
  line-height: 1.65;
  padding: 0.75rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.cs-script-mission {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.875rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  margin-top: 0.5rem;
}

.cs-script-mission-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.cs-script-meta-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin: 0.35rem 0 0;
}

/* ---- Shop preview panel ---- */
.shop-panel {
  position: relative;
  width: 0;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--color-bg);
  border-left: none;
  display: flex;
  flex-direction: column;
  transition:
    width 0.48s cubic-bezier(0.4, 0, 0.2, 1),
    border-color 0.48s;
}

.shop-panel.open {
  width: 400px;
  border-left: 1px solid var(--color-border);
  overflow: visible;
}

.shop-panel.resizing {
  transition: none;
  user-select: none;
}

/* Full-screen invisible overlay that captures mouse events during resize,
   so drag stays smooth even when the cursor passes over the iframe. */
.shop-panel-drag-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  cursor: col-resize;
  background: transparent;
}

.shop-panel-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  width: 4px;
  height: 100%;
  cursor: col-resize;
  z-index: 20;
  background: transparent;
}

.shop-panel-resize-handle::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 100%;
  background: transparent;
  transition: background 0.15s;
}

.shop-panel-resize-handle:hover::after,
.shop-panel.resizing .shop-panel-resize-handle::after {
  background: var(--color-text-faint);
}

.shop-panel-resize-tooltip {
  position: absolute;
  right: calc(100% + 8px);
  top: 50%;
  transform: translateX(4px) translateY(-50%);
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 0.5rem;
  padding: 0.4rem 0.75rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition:
    opacity 0.15s,
    transform 0.15s;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.shop-panel-resize-handle:hover .shop-panel-resize-tooltip {
  opacity: 1;
  transform: translateX(0) translateY(-50%);
}

.shop-panel.resizing .shop-panel-resize-tooltip {
  opacity: 0 !important;
}

.shop-panel-resize-tooltip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.shop-panel-resize-tooltip-label {
  font-weight: 500;
  min-width: 46px;
}

.shop-panel-resize-tooltip-hint {
  opacity: 0.55;
}

.shop-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0 1rem 0.75rem;
  flex-shrink: 0;
  white-space: nowrap;
  min-height: 56px;
}

.shop-panel-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--chat-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.shop-panel-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
}

.shop-panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.25rem 2rem;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
  background: var(--color-bg);
}

/* App panel variant — iframe fills body, no footer */
.shop-panel--app .shop-panel-footer {
  display: none;
}

.shop-panel--app .shop-panel-body {
  overflow: hidden;
  padding: 0;
}

.shop-panel--app .shop-panel-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* ---- Product detail view ---- */
.spd-carousel {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--chat-surface);
  overflow: hidden;
  flex-shrink: 0;
}

/* Sliding track — all slides side-by-side; transform translates to the active slide */
.spd-carousel-track {
  display: flex;
  width: 100%;
  height: 100%;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}

.spd-slide {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
}

.spd-slide img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Carousel controls — scoped to shop panel to avoid conflicts */
.spd-carousel .cs-carousel-controls {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  z-index: 2;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 100px;
  padding: 0.25rem 0.375rem 0.25rem 1rem;
}

.spd-carousel .cs-carousel-dots {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.spd-carousel .cs-carousel-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  border: none;
  padding: 0;
  cursor: pointer;
  transition:
    background 0.2s,
    transform 0.2s;
}

.spd-carousel .cs-carousel-dot.active {
  background: #fff;
  transform: scale(1.3);
}

.spd-carousel .cs-carousel-btn {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.spd-carousel .cs-carousel-btn:hover {
  opacity: 1;
}
.spd-carousel .cs-carousel-btn[disabled] {
  opacity: 0.25;
  pointer-events: none;
}

.spd-content {
  padding: 1.25rem 1.25rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.spd-description {
  font-size: 0.875rem;
  color: var(--chat-text);
  line-height: 1.65;
  margin: 0;
  /* Preserve newlines from the admin editor (Enter key creates a line break) */
  white-space: pre-line;
}

/* Markdown-rendered links inside store description / features */
.spd-description a,
.spd-features a {
  color: var(--chat-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-word;
}

.spd-description a:hover,
.spd-features a:hover {
  color: var(--chat-accent-hover);
}

/* Markdown inline code + code blocks inside store description / features */
.spd-description .md-code,
.spd-features .md-code {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.85em;
  background: var(--chat-surface);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  color: var(--chat-text);
}

.spd-description .md-pre,
.spd-features .md-pre {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.8125rem;
  background: var(--chat-surface);
  padding: 0.75rem 1rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0.5rem 0;
  white-space: pre;
}

.spd-features {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.spd-features li {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  line-height: 1.5;
  padding-left: 1.25rem;
  position: relative;
}

.spd-features li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--chat-accent);
  font-weight: 700;
}

.spd-price-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.spd-price {
  font-size: 1rem;
  font-weight: 700;
  color: var(--chat-text);
}

.spd-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--chat-text-muted);
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  border-radius: var(--radius-full);
  padding: 0.15rem 0.5rem;
}

.spd-buy-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--chat-send-icon);
  background: var(--chat-accent);
  border: none;
  border-radius: var(--radius-full);
  padding: 0.5rem 1.125rem;
  text-decoration: none;
  transition: background 0.15s;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
}

.spd-buy-btn .icon {
  --chat-icon-color: var(--chat-send-icon);
}

.spd-buy-btn:hover {
  background: var(--chat-accent-hover);
}

@media (max-width: 768px) {
  .shop-panel {
    position: fixed;
    top: 66px;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: calc(100dvh - 58px);
    z-index: 202;
    border-left: none;
    border-radius: 0;
    transform: translateY(100%);
    overflow: hidden;
    transition: none;
  }

  .shop-panel.open {
    width: 100vw;
    border-left: none;
    /* transform reset by GSAP */
    overflow: hidden;
  }

  .shop-panel-resize-handle {
    display: none;
  }

  .shop-panel-header {
    padding: 0 1rem 0.75rem;
  }
}

@media (max-width: 768px) {
  .cs-script-panel {
    position: fixed;
    top: 66px;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: calc(100dvh - 66px);
    z-index: 202;
    border-left: none;
    border-radius: 0;
    transform: translateY(100%);
    overflow: hidden;
    transition: none;
  }

  .cs-script-panel.open {
    width: 100vw;
    border-left: none;
    overflow: hidden;
    /* transform driven by GSAP */
  }

  .cs-script-resize-handle {
    display: none;
  }

  .cs-script-header {
    padding: 0 1rem 0.5rem;
  }

  .cs-script-header .ui-tabs {
    width: 100%;
  }

  .cs-script-header .ui-tabs-list {
    width: 100%;
  }

  .cs-script-header .ui-tab-trigger {
    flex: 1;
  }
}

/* Page mode header states */
.chat-page-back {
  display: none;
  align-items: center;
  gap: var(--space-4);
  min-width: 0;
  flex: 1;
}

.chat-main.page-mode .chat-page-back {
  display: flex;
}

.chat-main.page-mode .collapsed-header-actions,
.chat-main.page-mode .chat-header-logogram-link {
  display: none !important;
}

.chat-page-back-btn-wrap {
  display: flex;
  align-items: center;
  background: var(--chat-surface-hover);
  border-radius: var(--radius-full);
  border: var(--border-width-1) solid var(--chat-border);
  padding: 0.2rem;
  flex-shrink: 0;
}

html[data-theme="light"] .chat-page-back-btn-wrap {
  background: var(--color-white);
  border: var(--border-width-1) solid var(--chat-border);
}

.chat-page-back-btn {
  width: 34px;
  height: 34px;
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--chat-text);
  transition:
    background 0.15s,
    color 0.15s;
  flex-shrink: 0;
}

html[data-theme="light"] .chat-page-back-btn {
  color: var(--chat-text-muted);
}

.chat-page-back-btn:hover {
  background: var(--chat-surface-hover-dark);
  color: var(--chat-text);
}

.chat-page-back-btn svg {
  width: 16px;
  height: 16px;
}

.chat-page-title-wrap {
  overflow: hidden;
  display: flex;
  align-items: center;
  min-width: 0;
}

.chat-page-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--chat-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transform: translateY(10px);
  will-change: transform, opacity;
}
