/* chat.css — AI chat page */

/* Theme variables */
html {
  /* Dark mode (default) */
  --chat-send-icon: #0f0f0f;
  --chat-icon-color: #888;
  --chat-bg: #0f0f0f;
  --chat-sidebar-bg: #171717;
  --chat-sidebar-border: #1e1e1e;
  --chat-surface: #2a2a2a;
  --chat-surface-hover: #242424;
  --chat-surface-hover-dark: #0f0f0f;
  --chat-border: #2e2e2e;
  --chat-border-subtle: #1e1e1e;
  --chat-text: #f0f0f0;
  --chat-text-muted: #666;
  --chat-text-faint: #444;
  --chat-text-dim: #717171;
  --chat-link: #999;
  --chat-link-hover: #f0f0f0;
  --chat-accent: #e8e8e8;
  --chat-accent-hover: #ffffff;
  --chat-user-text: #fff;
  --chat-assistant-bg: #1a1a1a;
  --chat-assistant-text: #e8e8e8;
  --chat-assistant-border: #2a2a2a;
  --chat-input-bg: #242424;
  --chat-scrollbar: #2a2a2a;
  --chat-typing-dot: #555;
  --chat-error-bg: #2a1515;
  --chat-error-border: #5a2020;
  --chat-error-text: #f08080;
  --chat-starter-bg: #1a1a1a;
  --chat-starter-text: #bbb;
}

html[data-theme="light"] {
  --chat-send-icon: #ffffff;
  --chat-icon-color: #555;
  --chat-bg: #ffffff;
  --chat-sidebar-bg: #f5f5f5;
  --chat-sidebar-border: #e8e8e8;
  --chat-surface: #ebebeb;
  --chat-surface-hover: #e2e2e2;
  --chat-surface-hover-dark: #e2e2e2;
  --chat-border: #e0e0e0;
  --chat-border-subtle: #ebebeb;
  --chat-text: #1a1a1a;
  --chat-text-muted: #6b6b6b;
  --chat-text-faint: #b0b0b0;
  --chat-text-dim: #717171;
  --chat-link: #555;
  --chat-link-hover: #1a1a1a;
  --chat-accent: #1a1a1a;
  --chat-accent-hover: #333333;
  --chat-user-text: #fff;
  --chat-assistant-bg: #f0f0f0;
  --chat-assistant-text: #1a1a1a;
  --chat-assistant-border: #e0e0e0;
  --chat-input-bg: #ffffff;
  --chat-scrollbar: #d0d0d0;
  --chat-typing-dot: #aaa;
  --chat-error-bg: #fff0f0;
  --chat-error-border: #ffcdd2;
  --chat-error-text: #c62828;
  --chat-starter-bg: #f0f0f0;
  --chat-starter-text: #555;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body.chat-page {
  font-family: var(--font-sans);
  background-color: var(--chat-bg);
  background-image: none;
  color: var(--chat-text);
  display: flex;
  flex-direction: row;
  height: 100dvh;
  overflow: hidden;
  transition:
    background-color 0.2s,
    color 0.2s;
}

/* Sidebar */

.chat-sidebar {
  width: 260px;
  background: var(--chat-sidebar-bg);
  border-right: var(--border-width-1) solid var(--chat-sidebar-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition:
    background 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-sidebar.collapsed {
  width: 0;
  opacity: 0;
  border-right: none;
}

/* Container for sidebar toggle + new-chat — hidden by default, shown when collapsed */
.collapsed-header-actions {
  display: none;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
  background: var(--chat-surface-hover);
  border-radius: var(--radius-full);
  border: var(--border-width-1) solid var(--chat-border);
  padding: 0.2rem;
}

html[data-theme="light"] .collapsed-header-actions {
  background: var(--color-white);
  border: var(--border-width-1) solid var(--chat-border);
}

.chat-sidebar.collapsed ~ .chat-main .collapsed-header-actions {
  display: flex;
}

/* Logogram link wrapper in header */
.chat-header-logogram-link {
  display: none;
  align-items: center;
  flex-shrink: 0;
}
.chat-sidebar.collapsed ~ .chat-main .chat-header-logogram-link {
  display: flex;
}

/* Logogram in header — only when sidebar is collapsed */
.chat-header-logogram {
  height: 24px;
  width: auto;
  display: block;
  flex-shrink: 0;
}
html[data-theme="dark"] .chat-header-logogram {
  filter: invert(1) brightness(0.85);
}

/* New chat button in header — visibility controlled by .collapsed-header-actions wrapper */
.header-newchat-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-muted);
  transition:
    background 0.15s,
    color 0.15s;
  flex-shrink: 0;
}
.header-newchat-btn:hover {
  background: var(--chat-surface-hover-dark);
  color: var(--chat-text);
}

/* Session history list */
.sessions-list {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  margin-top: 0;
}

.session-item {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 0.375rem var(--space-2);
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--chat-link);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s;
  position: relative;
}

.session-item-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  border-radius: 0.25rem;
  outline: none;
  padding: 0;
  box-sizing: border-box;
}

.session-item-label[contenteditable="true"] {
  white-space: nowrap;
  overflow: hidden;
  cursor: text;
  background: var(--chat-surface-hover);
  outline: none;
  border-radius: 0.25rem;
  text-overflow: clip;
  display: block;
  width: 100%;
}

.session-item-label[contenteditable="true"]::selection {
  background: var(--chat-accent);
  color: var(--chat-bg);
}

.session-more-btn {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  background: transparent;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--chat-text-muted);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.15s,
    background 0.15s;
  flex-shrink: 0;
}

.session-item:hover .session-more-btn,
.session-item.active .session-more-btn {
  opacity: 1;
  pointer-events: auto;
}

.session-more-btn:hover {
  background: var(--chat-surface-hover);
}

.session-item:hover {
  background: var(--chat-surface-hover);
  color: var(--chat-link-hover);
}

.session-item.active {
  background: var(--chat-surface);
  color: var(--chat-text);
}

.session-item.pinned .session-item-label::before {
  display: none;
}

.session-pinned-icon {
  margin-right: 0.4rem;
  opacity: 0.6;
}

.session-menu-pin-icon,
.session-menu-icon {
  background-color: var(--chat-link);
  transition: background-color 0.12s;
}

.session-menu-item:hover .session-menu-icon,
.session-menu-item:hover .session-menu-pin-icon {
  background-color: var(--chat-link-hover);
}

.session-menu-item.danger .session-menu-icon {
  background-color: var(--chat-error-text);
}

/* Session context menu */
.session-menu {
  z-index: 260;
  background: var(--chat-input-bg);
  border: var(--border-width-1) solid var(--chat-border);
  border-radius: var(--radius-lg);
  padding: var(--space-1);
  min-width: 150px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.session-menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: 0.45rem 0.65rem;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--chat-text);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition:
    background 0.12s,
    color 0.12s;
}

.session-menu-item:hover {
  background: var(--chat-surface-hover);
}

.session-menu-item.danger {
  color: var(--chat-error-text);
}

.session-menu-item.danger:hover {
  background: var(--chat-error-bg);
}

.sidebar-top {
  padding: 1.125rem var(--space-2) var(--space-3) var(--space-3);
  flex-shrink: 0;
}

.sidebar-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0;
}

.sidebar-collapse-btn {
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--chat-text-muted);
  transition:
    background 0.15s,
    color 0.15s;
  flex-shrink: 0;
}

.sidebar-collapse-btn:hover {
  background: var(--chat-surface-hover-dark);
  color: var(--chat-text);
  cursor: w-resize;
}

.sidebar-collapse-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

#collapseTooltip {
  z-index: 30;
}

.sidebar-logogram {
  display: none;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.sidebar-logo {
  height: 20px;
  width: auto;
  display: block;
  padding: 0;
}

.sidebar-new-chat-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  background: transparent;
  border: none;
  border-radius: 0.6rem;
  color: var(--chat-link);
  font-family: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s;
  white-space: nowrap;
  width: 100%;
}

.sidebar-new-chat-btn:hover {
  background: var(--chat-surface-hover);
  color: var(--chat-link-hover);
}

.sidebar-new-chat-btn img,
.sidebar-new-chat-btn .icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.sidebar-new-chat-btn .icon {
  background-color: currentColor;
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--space-2) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.sidebar-section-label {
  font-size: 0.75rem;
  color: var(--chat-text-muted);
  letter-spacing: 0.04em;
  /* text-transform: uppercase; */
  margin-bottom: 0.35rem;
  white-space: nowrap;
  padding: 0 var(--space-1);
}

.sessions-recents-label {
  margin-bottom: 0;
  margin-top: var(--space-3);
}

.sidebar-links {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--chat-link);
  text-decoration: none;
  font-size: 0.875rem;
  transition:
    background 0.15s,
    color 0.15s;
  white-space: nowrap;
}

.sidebar-link:hover {
  background: var(--chat-surface-hover);
  color: var(--chat-link-hover);
}

.sidebar-link svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
  flex-shrink: 0;
}

/* Sidebar primary nav */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  background: transparent;
  border: none;
  border-radius: 0.6rem;
  color: var(--chat-link);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  width: 100%;
  text-align: left;
  white-space: nowrap;
  transition:
    background 0.15s,
    color 0.15s;
}

.sidebar-nav-item:hover {
  background: var(--chat-surface-hover);
  color: var(--chat-link-hover);
}

.sidebar-nav-item.active {
  background: var(--chat-surface);
  color: var(--chat-text);
}

.sidebar-nav-item.active:hover {
  background: var(--chat-surface-hover);
  color: var(--chat-link-hover);
}

.sidebar-nav-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.local-storage-banner {
  margin: 0 var(--space-2) var(--space-2);
  border-radius: var(--radius-sm);
  border: var(--border-width-1) solid var(--chat-border-subtle);
  overflow: hidden;
  flex-shrink: 0;
}

.local-storage-banner-text {
  font-size: 0.75rem;
  color: var(--chat-text-muted);
  line-height: 1.45;
  padding: 0.6rem var(--space-3) var(--space-2);
  margin: 0;
}

.local-storage-banner-bar {
  height: 2px;
  background: var(--chat-border-subtle);
}

.local-storage-banner-progress {
  height: 100%;
  width: 100%;
  background: var(--chat-text-muted);
  transform-origin: right;
}

.sidebar-footer {
  padding: var(--space-3);
  border-top: var(--border-width-1) solid var(--chat-border-subtle);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.shortcuts-footer-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  color: var(--chat-text-dim);
  opacity: 0.8;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 0.875rem;
  line-height: 1;
  transition:
    background 0.15s,
    color 0.15s;
}
.shortcuts-footer-btn:hover {
  background: var(--chat-surface-hover);
  color: var(--chat-text);
}

/* Nav shortcut badges */
.nav-shortcut {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--chat-text-dim);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
body.show-shortcuts .nav-shortcut {
  opacity: 1;
}

/* Keyboard shortcuts modal */
.shortcuts-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s;
}
.shortcuts-modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.shortcuts-modal {
  background: var(--chat-sidebar-bg);
  border: var(--border-width-1) solid var(--chat-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 380px;
  margin: var(--space-4);
  transform: translateY(8px) scale(0.97);
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}
.shortcuts-modal-backdrop.open .shortcuts-modal {
  transform: translateY(0) scale(1);
}

.shortcuts-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: var(--border-width-1) solid var(--chat-border-subtle);
}
.shortcuts-modal-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--chat-text);
}
.shortcuts-modal-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  color: var(--chat-text-muted);
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s;
}
.shortcuts-modal-close:hover {
  background: var(--chat-surface-hover);
  color: var(--chat-text);
}

.shortcuts-modal-body {
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.shortcuts-group {
  padding: var(--space-1) 0;
}
.shortcuts-group + .shortcuts-group {
  border-top: var(--border-width-1) solid var(--chat-border-subtle);
  padding-top: var(--space-2);
  margin-top: var(--space-1);
}
.shortcuts-group-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--chat-text-dim);
  padding: 0 var(--space-1) var(--space-2);
}

.shortcuts-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-1) var(--space-1);
  border-radius: var(--radius-sm);
}
.shortcuts-label {
  font-size: 0.875rem;
  color: var(--chat-text-muted);
}
html[data-theme="dark"] .shortcuts-label {
  color: #999999;
}
html[data-theme="dark"] .shortcuts-keys kbd {
  color: #999999;
}
.shortcuts-keys {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 var(--space-1);
  background: var(--chat-surface);
  border: var(--border-width-1) solid var(--chat-border);
  border-radius: 0.3rem;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--chat-text-muted);
  line-height: 1;
}

/* Coming soon section */
.section-coming-soon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-8) var(--space-4) var(--space-10);
  text-align: center;
}

.section-coming-soon-img {
  width: 100%;
  max-width: 360px;
  border-radius: var(--radius-lg);
  object-fit: cover;
  margin-bottom: var(--space-2);
}

/* Show dark image by default, light image in light mode */
.section-coming-soon-img--light {
  display: none;
}

html[data-theme="light"] .section-coming-soon-img--dark {
  display: none;
}

html[data-theme="light"] .section-coming-soon-img--light {
  display: block;
}

.section-coming-soon-badge {
  display: inline-block;
  padding: 0.3rem 0.85rem;
  border-radius: var(--radius-full);
  background: var(--chat-surface);
  border: var(--border-width-1) solid var(--chat-border);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--chat-text-muted);
  text-transform: uppercase;
}

.section-coming-soon-text {
  font-size: 0.925rem;
  color: var(--chat-text-muted);
  max-width: 28ch;
  line-height: 1.55;
}

.sidebar-footer-name {
  font-size: 0.78rem;
  color: var(--chat-text-dim);
  white-space: nowrap;
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 245;
  transition: opacity 0.2s;
}

.sidebar-overlay.visible {
  display: block;
}

/* Welcome section */

.chat-section-welcome {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-6) 0 var(--space-2);
}

.section-header-top {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.section-title-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.section-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--chat-text);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.section-title-badge {
  font-size: 0.68rem;
  padding: var(--space-1) 0.7rem;
  letter-spacing: 0.07em;
  align-self: center;
}

.section-subtitle {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.9375rem;
  color: var(--chat-text-muted);
  line-height: 1.55;
}

.section-subtitle-link {
  display: inline-flex;
  align-items: center;
  gap: 0.2em;
  margin-left: var(--space-2);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--chat-accent);
  text-decoration: none;
  white-space: nowrap;
  opacity: 0.85;
  transition: opacity 0.15s;
}

.section-subtitle-link:hover {
  opacity: 1;
  text-decoration: underline;
}

@media (max-width: 480px) {
  .section-subtitle {
    flex-direction: column;
    gap: var(--space-1);
  }
  .section-subtitle-link {
    margin-left: 0;
  }
}

/* Shop section */
.shop-tabs-wrap {
  --ds-surface: var(--color-surface);
  --ds-border: var(--color-border);
  --ds-bg: var(--color-bg);
  --ds-text-muted: var(--color-text-muted);
  --ds-text: var(--color-text);
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--chat-bg);
  padding: var(--space-2) 0;
  margin-bottom: var(--space-1);
  transition: background 0.2s;
}

.shop-tabs-wrap .ui-tabs-list {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--ds-surface);
  border: var(--border-width-1) solid var(--ds-border);
  border-radius: var(--radius-full);
  padding: 3px;
  width: fit-content;
}

.shop-tabs-wrap .ui-tabs-slider {
  position: absolute;
  top: 2px;
  left: 2px;
  height: calc(100% - 4px);
  background: var(--ds-bg);
  border-radius: var(--radius-full);
  pointer-events: none;
  z-index: 0;
}

.shop-tabs-wrap .ui-tab-trigger {
  position: relative;
  z-index: 1;
  padding: 0.375rem 0.875rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ds-text-muted);
  background: none;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: color 0.15s;
  flex-shrink: 0;
}

.shop-tabs-wrap .ui-tab-trigger:hover {
  color: var(--ds-text);
}

.shop-tabs-wrap .ui-tab-trigger.active,
.shop-tabs-wrap .ui-tab-trigger[aria-selected="true"] {
  color: var(--ds-text);
}

.shop-product-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.shop-product-card {
  display: flex;
  flex-direction: column;
  border: var(--border-width-1) solid var(--chat-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition:
    border-color 0.15s,
    transform 0.12s;
  text-decoration: none;
  color: inherit;
}

.shop-product-card:hover {
  border-color: var(--chat-text-muted);
  transform: translateY(-2px);
}

.spc-image-wrap {
  aspect-ratio: 4 / 3;
  background: var(--chat-surface);
  overflow: hidden;
  position: relative;
}

.spc-shimmer {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    var(--chat-surface) 25%,
    var(--chat-surface-hover) 50%,
    var(--chat-surface) 75%
  );
  background-size: 200% 100%;
  will-change: background-position;
  animation: shimmer-sweep 1.4s infinite;
  z-index: 1;
}

@keyframes shimmer-sweep {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.spc-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  position: relative;
  z-index: 2;
}

.spc-badge {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 3;
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--chat-accent);
  color: var(--chat-bg);
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
}

.spc-body {
  padding: var(--space-3) var(--space-3) var(--space-5);
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.spc-name {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--chat-text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.spc-price {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--chat-accent);
}

.shop-products-empty {
  color: var(--chat-text-muted);
  font-size: 0.875rem;
  padding: var(--space-4) 0;
  grid-column: 1 / -1;
}

.section-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.625rem;
}

.section-card {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem var(--space-4);
  background: var(--chat-surface);
  border: var(--border-width-1) solid var(--chat-border);
  border-radius: 0.875rem;
  text-decoration: none;
  color: var(--chat-text);
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    transform 0.1s;
}

.section-card:hover {
  background: var(--chat-surface-hover);
  border-color: var(--chat-text-dim);
}

.section-card:active {
  transform: scale(0.985);
}

.section-card-logo {
  width: 36px;
  height: 36px;
  border-radius: 0.625rem;
  flex-shrink: 0;
  object-fit: contain;
}
html[data-theme="dark"] .section-card-logo:not([data-brand]) {
  filter: invert(1) brightness(0.85);
}

.section-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 0.625rem;
  background: var(--chat-input-bg);
  border: var(--border-width-1) solid var(--chat-border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--chat-text-muted);
}

.section-card-icon svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.section-card-body {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  flex: 1;
}

.section-card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
  color: var(--chat-text);
}

.section-card-desc {
  font-size: 0.8125rem;
  color: var(--chat-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
}

.section-starters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.section-starters .chat-starter-btn {
  font-size: 0.875rem;
  padding: var(--space-2) var(--space-3);
  color: var(--chat-text-dim);
  border-color: var(--chat-border-subtle);
}

/* 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;
}

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

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

/* 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 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--chat-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  flex-shrink: 0;
  position: relative;
  z-index: 11;
  background: var(--chat-bg);
  transition: background 0.2s;
}

/* While the connect pill is morphing/open, drop the header's stacking
   context so the pill (position:fixed, z:201) escapes and renders above
   the backdrop (z:200). The rest of the header content stays underneath
   the blur. */
.chat-header:has(.connect-pinning) {
  z-index: auto;
}

.chat-header-toggle {
  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-muted);
  transition:
    background 0.15s,
    color 0.15s;
  flex-shrink: 0;
}

.chat-header-toggle:hover {
  background: var(--chat-surface-hover-dark);
  color: var(--chat-text);
  cursor: e-resize;
}

.chat-header-toggle svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.chat-header-label {
  display: none;
}

/* Right-side header actions pill (share + theme) */
.header-right-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin-left: auto;
  background: var(--chat-surface-hover);
  border-radius: var(--radius-full);
  border: var(--border-width-1) solid var(--chat-border);
  padding: 0.2rem;
  width: auto;
  transition:
    width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    padding 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    background 0.2s,
    top 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html[data-theme="light"] .header-right-actions {
  background: var(--color-white);
  border: var(--border-width-1) solid var(--chat-border);
}

/* While transitioning: pill is fixed-positioned at its captured rect */
.header-right-actions.connect-pinning {
  position: fixed;
  z-index: 215;
}

.header-actions-row {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  justify-content: flex-end;
  flex-shrink: 0;
}

/* expanded state: pill anchors top-right of viewport (uses .connect-pinning's position:fixed) */
.header-right-actions.connect-open {
  top: 1rem;
  right: 1rem;
  width: 340px;
  border-radius: 24px;
  padding: 0.2rem 0.2rem var(--space-4);
  background: var(--chat-sidebar-bg);
  box-shadow: var(--shadow-lg);
  align-items: stretch;
}

html[data-theme="light"] .header-right-actions.connect-open {
  background: var(--color-white);
}

/* Suppress button tooltips while pill is expanded */
.header-right-actions.connect-open .header-actions-row .ui-tooltip {
  display: none;
}

/* Mobile: pill stays anchored top-right but width fits viewport with equal-ish margins */
@media (max-width: 480px) {
  .header-right-actions.connect-open {
    width: calc(100vw - 2rem);
    max-width: 340px;
  }
}

/* connect body — display:none until JS toggles `.connect-body-visible` after
   the pill finishes morphing open. Removed from layout entirely while the
   pill animates, so no text ever shows during the morph. */
.connect-body {
  display: none;
  width: 100%;
  opacity: 0;
  transform: translateY(-4px);
  padding: var(--space-2) var(--space-4) 0;
  transition:
    opacity 0.28s ease,
    transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.connect-body.connect-body-visible {
  opacity: 1;
  transform: translateY(0);
}

.connect-body-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--chat-text);
  margin: var(--space-2) 0 var(--space-1);
  line-height: 1.3;
}

.connect-body-subtitle {
  font-size: 0.9375rem;
  color: var(--chat-text-muted);
  margin: 0 0 var(--space-4);
  line-height: 1.5;
}

.connect-body-links {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.connect-body-links .ui-tooltip-wrap {
  flex: 1;
  display: flex;
  overflow: visible;
}

.connect-body-links .ui-tooltip {
  z-index: 220;
}

/* circular icon buttons */
.connect-link {
  flex: 1;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--chat-surface);
  border: var(--border-width-1) solid var(--chat-border);
  text-decoration: none;
  color: var(--chat-link);
  cursor: pointer;
  padding: 0;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
}

.connect-link:hover {
  background: var(--chat-surface-hover-dark);
  color: var(--color-white);
}

html[data-theme="light"] .connect-link {
  background: var(--chat-bg);
  color: var(--chat-text-muted);
}

html[data-theme="light"] .connect-link:hover {
  background: var(--chat-surface);
  color: var(--chat-text);
}

/* copy-link button: swap icons on success */
.connect-link .connect-copy-success {
  display: none;
}
.connect-link.copied .connect-copy-default {
  display: none;
}
.connect-link.copied .connect-copy-success {
  display: block;
  color: var(--color-success);
}

/* connect backdrop */
.connect-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 205;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.connect-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.header-share-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-muted);
  transition:
    background 0.15s,
    color 0.15s;
  flex-shrink: 0;
}

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

/* Face icon eye animations */
@keyframes face-blink {
  0%,
  92%,
  100% {
    transform: scaleY(1);
  }
  95%,
  97% {
    transform: scaleY(0.08);
  }
}

@keyframes face-wink-left {
  0%,
  100% {
    transform: scaleY(1);
  }
  30%,
  70% {
    transform: scaleY(0.08);
  }
}

.face-eye {
  transform-box: fill-box;
  transform-origin: center;
  will-change: transform;
}

.face-eyebrow {
  transform-box: fill-box;
  transform-origin: bottom center;
}

@keyframes face-eyebrow-raise {
  0%,
  100% {
    transform: translateY(0);
  }
  30%,
  70% {
    transform: translateY(-0.7px);
  }
}

#headerShareBtn.winking .face-eye--left {
  animation: face-wink-left 0.5s ease-in-out forwards;
}

#headerShareBtn.winking .face-eyebrow {
  animation: face-eyebrow-raise 0.5s ease-in-out forwards;
}

#headerShareBtn.winking .face-eye--right {
  animation: face-roam 9s ease-in-out infinite;
}

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

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

.theme-toggle-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Messages area — padding-top: 0 so sticky children flush to top; spacing added by first child */
.chat-messages {
  flex: 1;
  overflow-y: scroll;
  padding: 0 var(--space-4) var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  background: var(--chat-bg);
  transition: background 0.2s;
}

/* Top spacing for non-shop content. Shop section omits this so its sticky
   tabs sit flush at the top of the scroll viewport. */
.chat-messages > *:first-child:not(.chat-section-welcome) {
  margin-top: var(--space-8);
}

.chat-section-welcome:not(:has(.shop-tabs-wrap)) {
  padding-top: var(--space-8);
}

.chat-section-welcome:has(.shop-tabs-wrap) {
  padding-top: 0;
}

.chat-section-welcome:has(.shop-tabs-wrap) .section-header-top {
  margin-top: var(--space-8);
}

.chat-section-welcome:has(.shop-tabs-wrap) .shop-tabs-wrap {
  padding-top: var(--space-2);
}

/* Once the user has sent messages, the store welcome section is no longer the
   only child. Disable sticky so the tabs scroll away with the products instead
   of hanging at the top of the message thread. */
.chat-messages:has(.chat-msg) .shop-tabs-wrap {
  position: static;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--chat-scrollbar);
  border-radius: 2px;
}

/* Welcome screen */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: var(--space-8) var(--space-4);
  gap: var(--space-4);
}

.chat-welcome-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--chat-text);
  line-height: 1.2;
}

.chat-welcome-title span {
  color: var(--chat-accent);
}

.chat-welcome-subtitle {
  font-size: 1rem;
  color: var(--chat-text-muted);
  max-width: 420px;
  line-height: 1.6;
}

/* Starter prompts */
.chat-starters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: center;
  margin-top: var(--space-2);
  max-width: 540px;
}

.chat-starter-btn {
  background: var(--chat-starter-bg);
  border: var(--border-width-1) solid var(--chat-border);
  color: var(--chat-starter-text);
  border-radius: 100px;
  padding: var(--space-2) var(--space-4);
  font-size: 0.875rem;
  cursor: pointer;
  transition:
    background 0.2s,
    border-color 0.2s,
    color 0.2s;
  font-family: inherit;
  white-space: nowrap;
}

.chat-starter-btn:hover {
  background: var(--chat-surface-hover);
  border-color: var(--chat-accent);
  color: var(--chat-text);
}

/* Individual messages */
.chat-msg {
  display: flex;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  scroll-margin-top: 1rem;
}

.chat-msg.user {
  justify-content: flex-end;
}

.chat-msg.assistant {
  justify-content: flex-start;
  flex-direction: column;
  align-items: flex-start;
}

.chat-msg-bubble {
  padding: 0.7rem var(--space-4);
  border-radius: var(--radius-lg);
  font-size: 1rem;
  line-height: 1.6;
  max-width: 80%;
}

.chat-msg.user .chat-msg-bubble {
  background: var(--chat-surface);
  color: var(--chat-text);
  border-bottom-right-radius: 4px;
}

.chat-msg.assistant .chat-msg-bubble {
  background: var(--chat-accent);
  color: #fff;
  border-bottom-left-radius: 4px;
  border: none;
}

/* Link chips below assistant messages */
.chat-msg-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  max-width: 80%;
  padding: 0.875rem 0;
}

.chat-msg-link-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem var(--space-3);
  background: var(--chat-surface);
  border: var(--border-width-1) solid var(--chat-border);
  border-radius: var(--radius-full);
  color: var(--chat-text-muted);
  font-size: 0.8125rem;
  text-decoration: none;
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
  white-space: nowrap;
  line-height: 1.4;
  font-family: inherit;
}

.chat-msg-link-chip:hover {
  background: var(--chat-surface-hover);
  border-color: var(--chat-text-muted);
  color: var(--chat-text);
}

.chat-msg-link-chip svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.6;
}

/* Message action bar (copy / like / dislike / share) */
.chat-msg-actions {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  padding: 0;
}

.chat-msg-action-btn {
  width: 28px;
  height: 28px;
  background: transparent;
  border: none;
  border-radius: 0.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.15s;
}

.chat-msg-action-btn:hover {
  background: var(--chat-surface-hover);
}

.chat-msg-action-btn img {
  width: 14px;
  height: 14px;
  display: block;
}

/* In dark mode the SVG fills (#555) are near-invisible — invert them */
html[data-theme="dark"] .chat-msg-action-btn img {
  filter: invert(1) opacity(0.8);
}

/* Active states (liked / disliked) should be clearly visible */
html[data-theme="dark"] .chat-msg-action-btn.liked img,
html[data-theme="dark"] .chat-msg-action-btn.disliked img {
  filter: invert(1) opacity(0.9);
}

/* Reduce top padding on link chips row when action bar is present */
.chat-msg-actions + .chat-msg-links {
  padding-top: var(--space-3);
}

/* Bold text in assistant bubbles */
.chat-msg.assistant .chat-msg-bubble .chat-inline-link {
  color: inherit;
  text-decoration: none;
  word-break: break-all;
}

.chat-msg.assistant .chat-msg-bubble .chat-inline-link:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-msg.assistant .chat-msg-bubble strong {
  font-weight: 600;
}

/* Block content inside assistant bubbles */
.chat-msg.assistant .chat-msg-bubble p {
  margin: 0 0 0.6rem;
}

.chat-msg.assistant .chat-msg-bubble p:last-child {
  margin-bottom: 0;
}

.chat-msg.assistant .chat-msg-bubble ul,
.chat-msg.assistant .chat-msg-bubble ol {
  padding-left: var(--space-5);
  margin: 0 0 0.6rem;
}

.chat-msg.assistant .chat-msg-bubble ul:last-child,
.chat-msg.assistant .chat-msg-bubble ol:last-child {
  margin-bottom: 0;
}

.chat-msg.assistant .chat-msg-bubble li {
  margin-bottom: 0.4rem;
  padding-left: 0;
  line-height: 1.6;
}

.chat-msg.assistant .chat-msg-bubble li:last-child {
  margin-bottom: 0;
}

.chat-msg.assistant .chat-msg-bubble blockquote {
  margin: var(--space-2) 0 var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: var(--border-width-1) solid var(--chat-border);
  color: var(--chat-text);
  font-style: italic;
  border-radius: var(--radius-lg);
  background: var(--chat-sidebar-bg);
}

.chat-msg.assistant .chat-msg-bubble blockquote:last-child {
  margin-bottom: 0;
}

/* Code block (uses ds-code-block from design-system.css) */
.chat-msg.assistant .chat-msg-bubble .chat-code-block {
  margin: var(--space-2) 0 var(--space-3);
  border-radius: var(--radius-md);
}

.chat-msg.assistant .chat-msg-bubble .chat-code-block:last-child {
  margin-bottom: 0;
}

/* Markdown table */
.chat-msg.assistant .chat-msg-bubble .chat-table-wrap {
  margin: var(--space-2) 0 var(--space-3);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
  border: var(--border-width-1) solid var(--chat-border);
}

.chat-msg.assistant .chat-msg-bubble .chat-table-wrap:last-child {
  margin-bottom: 0;
}

.chat-msg.assistant .chat-msg-bubble .chat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  line-height: 1.5;
}

.chat-msg.assistant .chat-msg-bubble .chat-table thead {
  background: var(--chat-sidebar-bg);
}

.chat-msg.assistant .chat-msg-bubble .chat-table th {
  padding: var(--space-2) 0.875rem;
  text-align: left;
  font-weight: 600;
  color: var(--chat-text);
  white-space: nowrap;
  border-bottom: var(--border-width-1) solid var(--chat-border);
}

.chat-msg.assistant .chat-msg-bubble .chat-table td {
  padding: 0.875rem;
  color: var(--chat-assistant-text);
  border-bottom: var(--border-width-1) solid var(--chat-border-subtle);
  vertical-align: top;
}

.chat-msg.assistant .chat-msg-bubble .chat-table tbody tr:last-child td {
  border-bottom: none;
}

/* Typing indicator */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: var(--space-2) var(--space-1);
}

.chat-typing span {
  width: 6px;
  height: 6px;
  background: var(--chat-typing-dot);
  border-radius: 50%;
  will-change: transform;
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.chat-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.chat-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    background: var(--chat-typing-dot);
  }
  30% {
    transform: translateY(-6px);
    background: var(--chat-accent);
  }
}

/* Scroll to bottom button */
.chat-scroll-btn {
  position: absolute;
  bottom: calc(var(--chat-input-height, 96px) + 0.75rem);
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s,
    transform 0.2s;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-full);
  border: none;
  background: color-mix(in srgb, var(--chat-bg) 70%, transparent);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: var(--chat-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

.chat-scroll-btn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.chat-scroll-btn:hover {
  background: color-mix(in srgb, var(--chat-surface-hover) 80%, transparent);
  color: var(--chat-text);
}

/* Input area */
.chat-input-wrapper {
  flex-shrink: 0;
  padding: 0 var(--space-4) var(--space-3);
  background: var(--chat-bg);
  transition: background 0.2s;
  position: relative;
  z-index: 200;
}

.chat-input-container {
  position: relative;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--chat-input-bg);
  border: var(--border-width-1) solid var(--chat-border);
  border-radius: 1.5rem;
  padding: 0.375rem;
  transition:
    border-color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
    background 0.2s cubic-bezier(0.4, 0, 0.2, 1),
    border-radius 0.2s cubic-bezier(0.4, 0, 0.2, 1),
    padding 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-input-container.multiline {
  border-radius: 1.5rem;
  flex-wrap: wrap;
  align-items: flex-end;
  padding-top: 8px;
  padding-bottom: 8px;
}

.chat-input-container.multiline .chat-input {
  flex-basis: 100%;
  padding: var(--space-1) var(--space-2) 0;
}

.chat-input-container.multiline .chat-input-plus-wrap {
  order: 1;
}

.chat-input-container.multiline .chat-mic-wrap {
  order: 2;
  margin-left: auto;
}

.chat-input-container.multiline .chat-send-btn {
  order: 3;
}

.chat-input-container:focus-within {
  border-color: var(--chat-accent);
}

/* Context mode: wrap layout — textarea full-width on top, controls row below */
.chat-input-container.has-context {
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4) var(--space-2);
  border-radius: 1.5rem;
  padding-top: 8px;
  padding-bottom: 8px;
}

/* Pill mode: chip row hidden */
.chat-input-bottom-row {
  display: none;
}

/* Context mode: chip row shown, fills the second flex line */
.chat-input-container.has-context .chat-input-bottom-row {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex: 1;
}

/* Textarea: full-width in context mode so it sits alone on the first row */
.chat-input-container.has-context .chat-input {
  flex-basis: 100%;
  padding: var(--space-2) var(--space-2) 0;
}

/* Send button: move to end of second row in context mode (after mic btn order 3) */
.chat-input-container.has-context .chat-send-btn {
  order: 4;
}

/* + button: move to start of second row in context mode */
.chat-input-container.has-context .chat-input-plus-wrap {
  order: 1;
}

.chat-input-container.has-context .chat-input-plus-btn {
  width: 36px;
  height: 36px;
}

/* Chip row fills between + and send */
.chat-input-container.has-context .chat-input-bottom-row {
  order: 2;
  flex: 1;
}

/* Chip: hidden until context active */
.chat-context-chip {
  display: none;
}
.chat-input-container.has-context .chat-context-chip {
  display: flex;
}

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--chat-text);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.5;
  resize: none;
  max-height: 140px;
  min-height: 24px;
  overflow-y: auto;
  text-align: left;
  transition: none;
}
.chat-input::placeholder {
  color: var(--chat-text-dim);
}

.chat-stop-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--chat-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--chat-send-icon);
  position: absolute;
  right: 0.375rem;
  bottom: 0.375rem;
  transition:
    background 0.2s,
    opacity 0.2s;
  z-index: 2;
}

.chat-input-container.has-context .chat-stop-btn {
  order: 5;
  position: static;
  margin-left: auto;
}

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

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--chat-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--chat-send-icon);
  transition:
    background 0.2s,
    opacity 0.2s;
}

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

.chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chat-send-btn svg {
  width: 18px;
  height: 18px;
}

.chat-input-hint {
  text-align: center;
  font-size: 0.75rem;
  color: var(--chat-text-dim);
  margin-top: var(--space-2);
}

/* Error state */
.chat-error {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  background: var(--chat-error-bg);
  border: var(--border-width-1) solid var(--chat-error-border);
  color: var(--chat-error-text);
  border-radius: var(--radius-lg);
  padding: 0.875rem var(--space-4);
  font-size: 0.875rem;
  line-height: 1.6;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

/* Scrollbar for textarea */
.chat-input::-webkit-scrollbar {
  width: 3px;
}
.chat-input::-webkit-scrollbar-thumb {
  background: var(--chat-scrollbar);
}

/* Responsive */

@media (max-width: 768px) {
  .shortcuts-footer-btn {
    display: none;
  }

  .chat-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    z-index: 250;
    width: 260px !important;
    transform: translateX(-100%);
  }

  .chat-sidebar.open {
    transform: translateX(0);
  }

  /* Collapsed header actions pill + logogram always visible on mobile */
  .collapsed-header-actions {
    display: flex;
  }

  /* Logogram link always shown on mobile */
  .chat-header-logogram-link {
    display: flex;
  }

  /* Hide pill + logogram while sidebar is open on mobile */
  .chat-sidebar.open ~ .chat-main .collapsed-header-actions,
  .chat-sidebar.open ~ .chat-main .chat-header-logogram-link {
    display: none;
  }

  .shop-product-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Hide all tooltips in the chat header on mobile — no hover on touch */
  .chat-header .ui-tooltip {
    display: none !important;
  }
}

@media (min-width: 769px) {
  .sidebar-overlay {
    display: none !important;
  }

  /* Style containment on desktop — prevents CSS counters/quotes from crossing
     the sidebar boundary without creating a new containing block for abs children */
  .chat-sidebar {
    contain: style;
  }
}

@media (max-width: 600px) {
  .chat-messages {
    padding: 0 var(--space-4) var(--space-5);
  }

  .chat-messages > *:first-child:not(.chat-section-welcome) {
    margin-top: var(--space-5);
  }

  .chat-section-welcome:not(:has(.shop-tabs-wrap)) {
    padding-top: var(--space-5);
  }

  .chat-welcome-title {
    font-size: 1.75rem;
  }

  .chat-starter-btn {
    font-size: 0.875rem;
    padding: var(--space-2) var(--space-3);
  }

  .chat-msg-bubble {
    font-size: 1rem;
    max-width: 90%;
  }

  .chat-msg.assistant .chat-msg-bubble {
    max-width: 100%;
  }

  .section-cards {
    grid-template-columns: 1fr;
  }

  .section-title {
    font-size: 1.35rem;
  }

  .section-header-inner {
    padding: var(--space-5) var(--space-4) var(--space-5);
  }
}

.chat-msg.assistant .chat-msg-bubble {
  background: none !important;
  color: var(--chat-text) !important;
  border: none !important;
  box-shadow: none;
  padding: var(--space-3) 0;
  max-width: 100%;
}

/* Delete confirmation modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.modal-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--chat-sidebar-bg);
  border: var(--border-width-1) solid var(--chat-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  max-width: 360px;
  width: calc(100% - 2rem);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  transform: scale(0.95);
  transition: transform 0.15s ease;
}

.modal-overlay.visible .modal {
  transform: scale(1);
}

.modal-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--chat-text);
}

.modal-body {
  font-size: 0.875rem;
  color: var(--chat-text-muted);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  margin-top: var(--space-2);
}

/* Modal buttons use ui-btn from design-system.css; wire chat tokens to ds tokens */
.modal-actions .ui-btn--primary {
  background: var(--chat-accent);
  color: var(--chat-bg);
  border-color: var(--chat-accent);
}

.modal-actions .ui-btn--primary:hover {
  background: var(--chat-accent-hover);
  border-color: var(--chat-accent-hover);
  opacity: 1;
}

.modal-actions .ui-btn--secondary {
  background: var(--chat-surface-hover);
  color: var(--chat-text);
  border-color: var(--chat-border);
}

.modal-actions .ui-btn--secondary:hover {
  border-color: var(--chat-text-muted);
}

/* Header SVG icon colors: white in dark mode, muted in light mode */
.header-newchat-btn,
.header-share-btn,
.theme-toggle-btn,
.sidebar-collapse-btn,
.chat-header-toggle {
  color: var(--chat-text);
}

html[data-theme="light"] .header-newchat-btn,
html[data-theme="light"] .header-share-btn,
html[data-theme="light"] .theme-toggle-btn,
html[data-theme="light"] .sidebar-collapse-btn,
html[data-theme="light"] .chat-header-toggle {
  color: var(--chat-text-muted);
}

/* Wave emoji animation */
@keyframes wave {
  0% {
    transform: rotate(0deg);
  }
  15% {
    transform: rotate(20deg);
  }
  30% {
    transform: rotate(-8deg);
  }
  45% {
    transform: rotate(18deg);
  }
  60% {
    transform: rotate(-6deg);
  }
  75% {
    transform: rotate(14deg);
  }
  100% {
    transform: rotate(0deg);
  }
}

.wave-emoji {
  display: inline-block;
  transform-origin: 70% 70%;
  vertical-align: middle;
  position: relative;
  cursor: pointer;
  user-select: none;
  will-change: transform;
}

/* Typewriter cursor */
@keyframes cursor-blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

.chat-typing-cursor {
  display: inline-block;
  width: 2px;
  height: 0.9em;
  background: currentColor;
  margin-left: 2px;
  vertical-align: text-bottom;
  border-radius: 1px;
  will-change: opacity;
  animation: cursor-blink 0.6s step-end infinite;
}

/* Tooltip */

.ui-tooltip-wrap {
  position: relative;
  display: inline-flex;
}

.ui-tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  border: none;
  font-size: 0.75rem;
  font-weight: 500;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition:
    opacity 0.15s,
    transform 0.15s;
  z-index: 10;
}

.ui-tooltip-wrap:hover .ui-tooltip,
.ui-tooltip-wrap:focus-within .ui-tooltip {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  transition-delay: 0s;
}

.ui-tooltip--bottom {
  bottom: auto;
  top: calc(100% + 6px);
  transform: translateX(-50%) translateY(-4px);
}

.ui-tooltip-wrap:hover .ui-tooltip--bottom,
.ui-tooltip-wrap:focus-within .ui-tooltip--bottom {
  transform: translateX(-50%) translateY(0);
  transition-delay: 0s;
}

.ui-tooltip--right {
  left: auto;
  right: 0;
  transform: translateX(0) translateY(-4px);
}

.ui-tooltip--bottom.ui-tooltip--right {
  transform: translateX(0) translateY(-4px);
}

.ui-tooltip-wrap:hover .ui-tooltip--right,
.ui-tooltip-wrap:focus-within .ui-tooltip--right {
  transform: translateX(0) translateY(0);
}

.ui-tooltip-wrap:hover .ui-tooltip--bottom.ui-tooltip--right,
.ui-tooltip-wrap:focus-within .ui-tooltip--bottom.ui-tooltip--right {
  transform: translateX(0) translateY(0);
}

/* Context picker */
.chat-input-plus-wrap {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-input-plus-tooltip {
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.chat-tooltip-kbd-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 0.25rem;
  padding: 0;
}

html[data-theme="light"] .chat-tooltip-kbd-wrap {
  background: rgba(255, 255, 255, 0.2);
}

.chat-tooltip-kbd {
  font-size: 0.75rem;
  font-family: inherit;
  font-weight: 600;
  line-height: 1;
  background: none;
  border: none;
  padding: 0;
}

/* Keep tooltip hidden while picker is open or suppressed after click */
.chat-input-plus-wrap.tooltip-suppressed .ui-tooltip,
.chat-input-plus-btn[aria-expanded="true"] ~ .ui-tooltip {
  opacity: 0 !important;
  pointer-events: none !important;
  transition: none !important;
}

.chat-input-plus-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--chat-text-muted);
  transition:
    background 0.15s,
    color 0.15s;
}
.chat-input-plus-btn:hover {
  background: var(--chat-surface-hover);
  color: var(--chat-text);
}
.chat-input-plus-btn.active {
  color: var(--chat-text-muted);
}

.chat-context-chip {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--chat-surface);
  border: var(--border-width-1) solid var(--chat-border);
  border-radius: var(--radius-full);
  padding: 0 var(--space-2) 0 var(--space-3);
  height: 36px;
  flex-shrink: 0;
  max-width: 180px;
  cursor: default;
  transition: border-color 0.15s;
}
.chat-context-chip:hover {
  border-color: var(--chat-text-muted);
}
.chat-context-chip-icon {
  display: flex;
  align-items: center;
  color: var(--chat-text-muted);
  flex-shrink: 0;
}
.chat-context-chip-icon svg {
  width: 14px;
  height: 14px;
}
.chat-context-chip-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--chat-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: default;
  user-select: none;
}
.chat-context-chip-remove {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--chat-text-muted);
  padding: 0;
  transition:
    background 0.12s,
    color 0.12s;
}
.chat-context-chip-remove:hover {
  background: var(--chat-surface-hover);
  color: var(--chat-text);
}

/* Context picker floating menu — matches session-menu style */
.context-picker-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  background: var(--chat-input-bg);
  border: var(--border-width-1) solid var(--chat-border);
  border-radius: var(--radius-lg);
  padding: var(--space-1);
  min-width: 180px;
  box-shadow: var(--shadow-md);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  opacity: 0;
  pointer-events: none;
}
.context-picker-menu:not(.open) {
  opacity: 0 !important;
  pointer-events: none !important;
}
.context-picker-menu.open {
  pointer-events: auto;
}
.context-picker-title {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--chat-text-muted);
  padding: var(--space-2) 0.65rem var(--space-1);
  letter-spacing: 0.04em;
  user-select: none;
}
.context-picker-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: 0.45rem 0.65rem;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--chat-text);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition:
    background 0.12s,
    color 0.12s;
}
.context-picker-item:hover,
.context-picker-item.focused {
  background: var(--chat-surface-hover);
}
.context-picker-item.selected {
  color: var(--chat-accent);
}
.context-picker-item.selected:hover {
  background: var(--chat-surface-hover);
}
.context-picker-item svg {
  flex-shrink: 0;
  color: var(--chat-text-muted);
  width: 14px;
  height: 14px;
}
.context-picker-item.selected svg {
  color: var(--chat-accent);
}

.context-picker-item.hidden {
  display: none;
}

/* Dark mode menu fixes — surface-hover == input-bg in dark so hover is invisible; use surface instead */
html[data-theme="dark"] .session-menu-item:hover {
  background: #383838;
}
html[data-theme="dark"] .session-menu-item.danger:hover {
  background: var(--chat-error-bg);
}

html[data-theme="dark"] .context-picker-item:hover,
html[data-theme="dark"] .context-picker-item.selected:hover,
html[data-theme="dark"] .context-picker-item.focused {
  background: #383838;
}

html[data-theme="dark"] .context-picker-item svg {
  color: var(--chat-text-dim);
}

html[data-theme="dark"] .sidebar-nav-item:hover,
html[data-theme="dark"] .sidebar-nav-item.active:hover {
  background: var(--chat-surface);
}

html[data-theme="dark"] .chat-input-plus-btn:hover {
  background: var(--chat-surface);
}

html[data-theme="dark"] .chat-input-plus-btn.active {
  color: var(--chat-text);
}

/* CSS mask icon system — <span class="icon icon-{name}">; color via --chat-icon-color */
.icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  background-color: var(--chat-icon-color);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
  vertical-align: middle;
}
.icon-edit {
  -webkit-mask-image: url(/assets/images/icons/edit.svg);
  mask-image: url(/assets/images/icons/edit.svg);
}
.icon-pin {
  -webkit-mask-image: url(/assets/images/icons/pin.svg);
  mask-image: url(/assets/images/icons/pin.svg);
}
.icon-unpin {
  -webkit-mask-image: url(/assets/images/icons/unpin.svg);
  mask-image: url(/assets/images/icons/unpin.svg);
}
.icon-share {
  -webkit-mask-image: url(/assets/images/icons/share.svg);
  mask-image: url(/assets/images/icons/share.svg);
}
.icon-copy {
  -webkit-mask-image: url(/assets/images/icons/copy.svg);
  mask-image: url(/assets/images/icons/copy.svg);
}
.icon-check {
  -webkit-mask-image: url(/assets/images/icons/check.svg);
  mask-image: url(/assets/images/icons/check.svg);
}
.icon-like {
  -webkit-mask-image: url(/assets/images/icons/like.svg);
  mask-image: url(/assets/images/icons/like.svg);
}
.icon-like-fill {
  -webkit-mask-image: url(/assets/images/icons/like-fill.svg);
  mask-image: url(/assets/images/icons/like-fill.svg);
}
.icon-dislike {
  -webkit-mask-image: url(/assets/images/icons/dislike.svg);
  mask-image: url(/assets/images/icons/dislike.svg);
}
.icon-dislike-fill {
  -webkit-mask-image: url(/assets/images/icons/dislike-fill.svg);
  mask-image: url(/assets/images/icons/dislike-fill.svg);
}
.icon-new-chat {
  -webkit-mask-image: url(/assets/images/icons/new-chat.svg);
  mask-image: url(/assets/images/icons/new-chat.svg);
}
.icon-search {
  -webkit-mask-image: url(/assets/images/icons/search.svg);
  mask-image: url(/assets/images/icons/search.svg);
}
.icon-close {
  -webkit-mask-image: url(/assets/images/icons/close.svg);
  mask-image: url(/assets/images/icons/close.svg);
}

/* session-menu icons use sidebar-nav link color treatment */
.session-menu-icon,
.session-menu-pin-icon {
  background-color: var(--chat-link);
}

/* pinned indicator on session items matches sidebar-nav muted color */
.session-pinned-icon {
  background-color: var(--chat-link);
}

/* liked/disliked filled state — accent color */
.chat-msg-action-btn.liked .icon,
.chat-msg-action-btn.disliked .icon {
  background-color: var(--chat-accent);
}

html[data-theme="dark"] .chat-context-chip-icon {
  color: var(--chat-text);
}
