/* ============================================================
   QuantX AI Surface — Homepage AI Chat Module
   Supports both light (default) and dark (data-theme="dark") themes
   ============================================================ */

/* ---- Light theme (default) ---- */
.ai-surface {
  --ai-page: #f2f2f2;
  --ai-bg: #ffffff;
  --ai-sidebar: #f8f8f8;
  --ai-fg: #1a1a1a;
  --ai-muted: rgba(0,0,0,.55);
  --ai-muted-soft: rgba(0,0,0,.40);
  --ai-border: rgba(0,0,0,.08);
  --ai-border-strong: rgba(0,0,0,.14);
  --ai-hover: rgba(0,0,0,.06);
  --ai-composer: rgba(245,245,245,.96);
  --ai-composer-footer: #e8e8e8;
  --ai-menu: #ffffff;
  --ai-shadow: 0 20px 25px -5px rgba(0,0,0,.08), 0 8px 10px -6px rgba(0,0,0,.06);

  --ai-send-bg: #1a1a1a;
  --ai-send-fg: #ffffff;
  --ai-send-disabled-bg: rgba(0,0,0,.12);
  --ai-send-disabled-fg: rgba(0,0,0,.30);
  --ai-code-bg: #f5f5f5;
  --ai-code-fg: #333333;
  --ai-mode-bg: #e8e8e8;
  --ai-mode-indicator-bg: #ffffff;
  --ai-user-bubble-bg: #e8e8e8;
  --ai-scroll-thumb: rgba(0,0,0,.18);
  --ai-focus-outline: rgba(0,0,0,.25);
  --ai-menu-shadow: 0 8px 16px -4px rgba(0,0,0,.12);
  --ai-mobile-shadow: 12px 0 28px rgba(0,0,0,.12);
  --ai-overlay: rgba(0,0,0,.15);
}

/* ---- Dark theme override ---- */
[data-theme="dark"] .ai-surface {
  --ai-page: #050505;
  --ai-bg: #181818;
  --ai-sidebar: #000000;
  --ai-fg: #ffffff;
  --ai-muted: rgba(255,255,255,.50);
  --ai-muted-soft: rgba(255,255,255,.34);
  --ai-border: rgba(255,255,255,.08);
  --ai-border-strong: rgba(255,255,255,.08);
  --ai-hover: rgba(255,255,255,.08);
  --ai-composer: rgba(33,33,33,.96);
  --ai-composer-footer: #181818;
  --ai-menu: #242424;
  --ai-shadow: 0 20px 25px -5px rgba(0,0,0,.28), 0 8px 10px -6px rgba(0,0,0,.22);

  --ai-send-bg: #ffffff;
  --ai-send-fg: #111111;
  --ai-send-disabled-bg: rgba(255,255,255,.15);
  --ai-send-disabled-fg: rgba(255,255,255,.35);
  --ai-code-bg: #121212;
  --ai-code-fg: #eeeeee;
  --ai-mode-bg: #090909;
  --ai-mode-indicator-bg: #252525;
  --ai-user-bubble-bg: #2a2a2a;
  --ai-scroll-thumb: rgba(255,255,255,.18);
  --ai-focus-outline: rgba(255,255,255,.35);
  --ai-menu-shadow: 0 8px 16px -4px rgba(0,0,0,.45);
  --ai-mobile-shadow: 12px 0 28px rgba(0,0,0,.38);
  --ai-overlay: rgba(0,0,0,.28);
}

.ai-surface,
.ai-surface *,
.ai-surface *::before,
.ai-surface *::after {
  box-sizing: border-box;
}

.ai-surface {
  color: var(--ai-fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 13px;
  line-height: 20px;
  -webkit-font-smoothing: antialiased;
}

.ai-surface button,
.ai-surface textarea {
  font: inherit;
  color: inherit;
}

.ai-surface button {
  cursor: pointer;
}

.ai-surface button:focus-visible {
  outline: 2px solid var(--ai-focus-outline);
  outline-offset: 2px;
}

.ai-surface textarea:focus,
.ai-surface textarea:focus-visible {
  outline: none;
  box-shadow: none;
}

/* ---- Surface container ---- */
.ai-surface-wrap {
  position: relative;
  width: min(1240px, 100%);
  height: min(660px, calc(100vh - 32px));
  min-height: 500px;
  overflow: hidden;
  border: 1px solid var(--ai-border-strong);
  border-radius: 12px;
  background: var(--ai-bg);
  box-shadow: var(--ai-shadow);
}

.ai-surface-app {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ---- Sidebar ---- */
.ai-sidebar {
  width: 224px;
  flex: 0 0 224px;
  overflow: hidden;
  padding: 8px;
  border-right: 1px solid var(--ai-border);
  background: var(--ai-sidebar);
  opacity: 1;
  transform: translateX(0);
  transition: width .2s cubic-bezier(.16,1,.3,1), flex-basis .2s cubic-bezier(.16,1,.3,1), padding .2s cubic-bezier(.16,1,.3,1), opacity .16s ease, transform .2s cubic-bezier(.16,1,.3,1);
}

.ai-surface-app.sidebar-closed .ai-sidebar {
  width: 0;
  flex-basis: 0;
  padding-left: 0;
  padding-right: 0;
  border-right-color: transparent;
  opacity: 0;
  transform: translateX(-8px);
  pointer-events: none;
}

.ai-sidebar-top {
  display: flex;
  height: 28px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.ai-traffic {
  display: flex;
  gap: 6px;
  padding-left: 4px;
}

.ai-traffic i {
  width: 10px;
  height: 10px;
  border: 1px solid var(--ai-border);
  border-radius: 50%;
}

.ai-traffic i:nth-child(1) { background: #ff5f57; }
.ai-traffic i:nth-child(2) { background: #febc2e; }
.ai-traffic i:nth-child(3) { background: #28c840; }

.ai-icon-btn {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ai-muted);
}

.ai-icon-btn:hover {
  background: var(--ai-hover);
  color: var(--ai-fg);
}

.ai-icon-btn svg {
  width: 14px;
  height: 14px;
}

.ai-product {
  display: flex;
  height: 32px;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 0 8px;
  border-radius: 10px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.02em;
}

.ai-product svg {
  width: 18px;
  height: 18px;
  color: var(--ai-fg);
}

.ai-nav-item,
.ai-chat-item {
  position: relative;
  display: flex;
  width: 100%;
  align-items: center;
  border: 0;
  background: transparent;
  color: var(--ai-muted);
  text-align: left;
}

.ai-nav-item {
  height: 28px;
  gap: 10px;
  padding: 0 8px;
  border-radius: 8px;
  font-size: 13px;
}

.ai-nav-item:hover,
.ai-chat-item:hover,
.ai-chat-item.active {
  background: var(--ai-hover);
  color: var(--ai-fg);
}

.ai-nav-item svg {
  width: 14px;
  height: 14px;
  color: var(--ai-muted-soft);
}

.ai-section-title {
  padding: 16px 8px 4px;
  color: var(--ai-muted-soft);
  font-weight: 500;
}

.ai-chat-list {
  min-height: 0;
  max-height: calc(100% - 116px);
  overflow-y: auto;
  scrollbar-width: none;
}

.ai-chat-list::-webkit-scrollbar {
  display: none;
}

.ai-day {
  padding: 6px 8px 3px;
  color: var(--ai-muted-soft);
  font-size: 11px;
}

.ai-chat-item {
  height: 30px;
  padding: 0 32px 0 8px;
  border-radius: 8px;
  font-size: 13px;
}

.ai-chat-item .ai-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-more {
  position: absolute;
  top: 50%;
  right: 4px;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  padding: 0;
  transform: translateY(-50%);
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ai-muted-soft);
  opacity: 0;
}

.ai-chat-item:hover .ai-more,
.ai-chat-item:focus-within .ai-more {
  opacity: 1;
}

.ai-more:hover {
  background: var(--ai-hover);
  color: var(--ai-fg);
}

.ai-more svg {
  width: 13px;
  height: 13px;
}

/* ---- Main area ---- */
.ai-main {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  background: var(--ai-bg);
}

.ai-header {
  display: grid;
  height: 40px;
  flex: 0 0 40px;
  grid-template-columns: minmax(0,1fr) auto minmax(0,1fr);
  align-items: center;
  padding: 6px 10px;
}

.ai-header-left {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 4px;
}

.ai-reopen-sidebar {
  display: none;
  flex: 0 0 28px;
}

.ai-surface-app.sidebar-closed .ai-reopen-sidebar {
  display: inline-grid;
}

.ai-title {
  min-width: 0;
  overflow: hidden;
  padding-left: 4px;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

/* ---- Mode toggle ---- */
.ai-mode {
  position: relative;
  display: inline-grid;
  height: 28px;
  grid-template-columns: 1fr 1fr;
  padding: 2px;
  border-radius: 999px;
  background: var(--ai-mode-bg);
  user-select: none;
}

.ai-mode-indicator {
  position: absolute;
  inset-block: 2px;
  left: 2px;
  width: calc(50% - 2px);
  border-radius: 999px;
  background: var(--ai-mode-indicator-bg);
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
  transition: transform .2s ease;
}

.ai-mode[data-mode="code"] .ai-mode-indicator {
  transform: translateX(100%);
}

.ai-mode button {
  position: relative;
  z-index: 1;
  height: 24px;
  min-width: 74px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ai-muted);
  font-weight: 500;
}

.ai-mode button.active {
  color: var(--ai-fg);
}

/* ---- Content ---- */
.ai-content {
  position: relative;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.ai-home {
  display: flex;
  width: 100%;
  height: 100%;
  min-height: 0;
  flex-direction: column;
}

.ai-hero-region {
  display: flex;
  min-height: 112px;
  flex: 1 1 0;
  align-items: flex-end;
  justify-content: center;
  padding: 24px 24px 92px;
}

.ai-hero-inner {
  display: flex;
  width: 100%;
  min-height: 112px;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 22px;
  text-align: center;
}

.ai-hero-logo {
  width: 56px;
  height: 56px;
  color: var(--ai-fg);
  opacity: .30;
}

.ai-hero-title {
  margin: 0;
  color: var(--ai-fg);
  font-size: 27px;
  line-height: 1.25;
  font-weight: 400;
  letter-spacing: -.025em;
}

.ai-composer-home-region {
  display: flex;
  min-height: 0;
  flex: 1 1 0;
  flex-direction: column;
  justify-content: flex-end;
}

/* ---- Thread ---- */
.ai-thread {
  display: none;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 26px 24px 160px;
  scrollbar-width: thin;
  scrollbar-color: var(--ai-scroll-thumb) transparent;
}

.ai-thread.show {
  display: block;
}

.ai-thread::-webkit-scrollbar {
  width: 6px;
}

.ai-thread::-webkit-scrollbar-track {
  background: transparent;
}

.ai-thread::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: var(--ai-scroll-thumb);
}

.ai-thread-inner {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

.ai-user-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 24px;
}

.ai-user-bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 18px 18px 5px 18px;
  background: var(--ai-user-bubble-bg);
  white-space: pre-wrap;
}

.ai-assistant {
  display: grid;
  grid-template-columns: 28px minmax(0,1fr);
  gap: 12px;
}

.ai-assistant-logo {
  width: 25px;
  height: 25px;
  color: var(--ai-fg);
  opacity: .48;
}

.ai-answer {
  color: var(--ai-muted);
  line-height: 1.65;
}

.ai-answer strong {
  color: var(--ai-fg);
}

.ai-code {
  margin-top: 12px;
  overflow: auto;
  padding: 14px 16px;
  border: 1px solid var(--ai-border);
  border-radius: 10px;
  background: var(--ai-code-bg);
  color: var(--ai-code-fg);
  font: 12.5px/1.65 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* ---- Composer ---- */
.ai-composer-region {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  padding: 12px 24px 16px;
}

.ai-thread-composer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  display: none;
  background: linear-gradient(to top, var(--ai-bg) 70%, transparent);
}

.ai-thread.show + .ai-thread-composer {
  display: block;
}

.ai-composer-wrap {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
}

.ai-utility {
  position: relative;
  top: 4px;
  z-index: 0;
  margin: 0 6px -18px;
  padding: 6px 6px 27px;
  border-radius: 16px 16px 0 0;
  background: var(--ai-composer-footer);
}

.ai-utility.hidden {
  display: none;
}

.ai-platform-btn {
  display: inline-flex;
  height: 28px;
  max-width: 240px;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ai-muted);
  font-size: 12px;
  line-height: 18px;
  font-weight: 400;
}

.ai-platform-btn:hover,
.ai-platform-btn.open {
  background: var(--ai-hover);
  color: var(--ai-fg);
}

.ai-platform-btn svg {
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
}

.ai-platform-prefix {
  color: var(--ai-muted);
  font-weight: 400;
}

.ai-platform-btn strong {
  overflow: hidden;
  color: var(--ai-fg);
  font-size: 12px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-chevron {
  width: 12px !important;
  height: 12px !important;
  color: var(--ai-muted-soft);
}

.ai-platform-menu {
  position: absolute;
  bottom: 35px;
  left: 6px;
  z-index: 10;
  display: none;
  width: 148px;
  padding: 5px;
  border: 1px solid var(--ai-border);
  border-radius: 10px;
  background: var(--ai-menu);
  box-shadow: var(--ai-menu-shadow);
}

.ai-platform-menu.show {
  display: block;
}

.ai-platform-option {
  display: flex;
  width: 100%;
  height: 31px;
  align-items: center;
  justify-content: space-between;
  padding: 0 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ai-muted);
  text-align: left;
  font-size: 12px;
}

.ai-platform-option:hover {
  background: var(--ai-hover);
  color: var(--ai-fg);
}

.ai-platform-option.selected::after {
  content: "✓";
  color: var(--ai-muted);
}

/* ---- Composer input ---- */
.ai-composer {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 63px;
  overflow: hidden;
  cursor: text;
  border-radius: 24px;
  background: var(--ai-composer);
  box-shadow: 0 0 0 .5px var(--ai-border), 0 4px 16px rgba(0,0,0,.10);
  backdrop-filter: blur(16px);
}

.ai-input-shell {
  position: relative;
  min-height: 36px;
  padding: 12px 12px 4px;
  cursor: text;
}

.ai-surface textarea {
  display: block;
  width: 100%;
  height: 20px;
  max-height: 100px;
  resize: none;
  overflow-y: hidden;
  padding: 0 16px 0 4px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ai-fg);
  font-size: 13px;
  line-height: 20px;
  scrollbar-width: none;
}

.ai-surface textarea::-webkit-scrollbar {
  display: none;
}

.ai-surface textarea::placeholder {
  color: var(--ai-muted-soft);
  opacity: 1;
}

.ai-custom-scroll {
  position: absolute;
  top: 12px;
  right: 8px;
  bottom: 4px;
  width: 3px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s ease;
}

.ai-custom-scroll.visible {
  opacity: 1;
}

.ai-custom-thumb {
  position: absolute;
  top: 0;
  right: 0;
  width: 3px;
  min-height: 18px;
  border-radius: 999px;
  background: var(--ai-scroll-thumb);
}

.ai-composer-footer {
  display: grid;
  grid-template-columns: auto minmax(0,1fr) auto;
  align-items: center;
  gap: 5px;
  padding: 0 8px 8px;
}

.ai-footer-left {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 3px;
}

.ai-input-click-zone {
  min-width: 0;
  height: 28px;
  cursor: text;
}

.ai-send {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--ai-send-bg) !important;
  color: var(--ai-send-fg) !important;
  transition: background .15s ease, color .15s ease;
}

.ai-send:disabled {
  background: var(--ai-send-disabled-bg) !important;
  color: var(--ai-send-disabled-fg) !important;
  cursor: not-allowed;
}

.ai-send svg {
  width: 14px;
  height: 14px;
}

/* ---- Responsive ---- */
@media (max-width: 760px) {
  .ai-surface-wrap {
    height: calc(100vh - 20px);
    min-height: 0;
  }

  .ai-sidebar {
    position: absolute;
    z-index: 80;
    inset: 0 auto 0 0;
    box-shadow: var(--ai-mobile-shadow);
  }

  .ai-surface-app.sidebar-closed .ai-sidebar {
    transform: translateX(-100%);
  }

  .ai-surface-app:not(.sidebar-closed)::after {
    content: "";
    position: absolute;
    z-index: 70;
    inset: 0;
    background: var(--ai-overlay);
  }

  .ai-sidebar { z-index: 80; }
  .ai-header, .ai-main { position: relative; z-index: 1; }
  .ai-hero-region { padding-bottom: 64px; }
  .ai-composer-region { padding-inline: 14px; }
}
