/* 华溯 Stitch UI — White Card Utility (light/dark) */
:root, html[data-theme="light"] {
  --hs-bg: #f8f9fb;
  --hs-surface: #ffffff;
  --hs-surface-low: #f3f4f6;
  --hs-surface-high: #e7e8ea;
  --hs-border: #c3c6d7;
  --hs-border-soft: #e1e2e4;
  --hs-text: #191c1e;
  --hs-text-secondary: #434654;
  --hs-text-muted: #737686;
  --hs-primary: #0052d9;
  --hs-primary-dark: #003da6;
  --hs-primary-soft: rgba(0, 82, 217, 0.1);
  --hs-success: #2da44e;
  --hs-warning: #d97706;
  --hs-error: #ba1a1a;
  --hs-shadow: 0 1px 3px rgba(25, 28, 30, 0.06), 0 4px 12px rgba(25, 28, 30, 0.04);
  --hs-header-h: 56px;
  --hs-sidebar-w: 200px;
  --hs-bottom-nav-h: 64px;
  --hs-beian-h: 1.625rem;
  --hs-radius: 8px;
  --hs-radius-lg: 12px;
  --hs-modal-overlay: rgba(25, 28, 30, 0.45);
}

html[data-theme="dark"] {
  --hs-bg: #0d1117;
  --hs-surface: #161b22;
  --hs-surface-low: #1c2128;
  --hs-surface-high: #21262d;
  --hs-border: #30363d;
  --hs-border-soft: #21262d;
  --hs-text: #e6edf3;
  --hs-text-secondary: #8b949e;
  --hs-text-muted: #6e7681;
  --hs-primary: #4493f8;
  --hs-primary-dark: #58a6ff;
  --hs-primary-soft: rgba(68, 147, 248, 0.15);
  --hs-success: #3fb950;
  --hs-warning: #d29922;
  --hs-error: #f85149;
  --hs-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  --hs-modal-overlay: rgba(0, 0, 0, 0.65);
}

html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

.stitch-app {
  background: var(--hs-bg) !important;
  color: var(--hs-text) !important;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

.stitch-app ::-webkit-scrollbar { width: 6px; height: 6px; }
.stitch-app ::-webkit-scrollbar-thumb { background: var(--hs-border); border-radius: 99px; }

/* Layout */
.stitch-shell { display: flex; flex: 1; min-height: 0; width: 100%; }
.stitch-app-main {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  width: 100%;
}
@media (min-width: 1024px) {
  .stitch-app-main { margin-left: var(--hs-sidebar-w); }
}

.stitch-sidebar {
  display: none;
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--hs-sidebar-w);
  background: var(--hs-surface); border-right: 1px solid var(--hs-border);
  flex-direction: column; z-index: 45; padding: 12px 0;
}
@media (min-width: 1024px) {
  .stitch-sidebar { display: flex; }
}

.stitch-sidebar-brand {
  padding: 12px 16px 16px; font-weight: 700; font-size: 15px;
  border-bottom: 1px solid var(--hs-border-soft); display: flex; align-items: center; gap: 8px;
  color: var(--hs-text);
}
.stitch-sidebar-brand .logo {
  width: 28px; height: 28px; border-radius: 6px; background: var(--hs-primary);
  display: grid; place-items: center; color: #fff; font-size: 11px; font-weight: 800;
}

.stitch-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; margin: 2px 8px; border-radius: var(--hs-radius);
  border: none; background: none; color: var(--hs-text-secondary);
  font-size: 13px; cursor: pointer; text-align: left; width: calc(100% - 16px);
  transition: background 0.15s, color 0.15s;
}
.stitch-nav-item:hover { background: var(--hs-surface-low); color: var(--hs-text); }
.stitch-nav-item.active { background: var(--hs-primary-soft); color: var(--hs-primary); font-weight: 600; }
.stitch-nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.stitch-sidebar-foot {
  margin-top: auto; padding: 12px 8px; border-top: 1px solid var(--hs-border-soft);
}

.stitch-bottom-nav {
  position: fixed; left: 0; right: 0; z-index: 50;
  bottom: calc(var(--hs-beian-h) + env(safe-area-inset-bottom, 0px));
  height: calc(var(--hs-bottom-nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--hs-surface); border-top: 1px solid var(--hs-border);
  display: flex; align-items: stretch;
}
@media (min-width: 1024px) {
  .stitch-bottom-nav { display: none !important; }
}

.stitch-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; border: none; background: none; color: var(--hs-text-muted);
  font-size: 10px; padding: 6px 4px; cursor: pointer;
}
.stitch-tab svg { width: 20px; height: 20px; }
.stitch-tab.active { color: var(--hs-primary); font-weight: 600; }

/* Header */
.stitch-header {
  position: sticky; top: 0; z-index: 40;
  background: var(--hs-surface) !important;
  border-bottom: 1px solid var(--hs-border) !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  padding: 12px 16px !important;
  min-height: var(--hs-header-h);
}
.stitch-header h1 { color: var(--hs-text) !important; letter-spacing: 0.02em !important; }
.stitch-header .header-logo {
  width: 32px; height: 32px; border-radius: 6px; background: var(--hs-primary) !important;
  box-shadow: none !important;
}

.stitch-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 12px; border-radius: 999px; font-size: 12px;
  border: 1px solid var(--hs-border); background: var(--hs-surface);
  color: var(--hs-text-secondary); cursor: pointer; transition: all 0.15s;
  white-space: nowrap;
}
.stitch-chip:hover { border-color: var(--hs-primary); color: var(--hs-primary); background: var(--hs-primary-soft); }
.stitch-chip-pro {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  color: var(--hs-warning); background: rgba(217, 119, 6, 0.1);
  border-color: rgba(217, 119, 6, 0.35); padding: 4px 8px;
}
.stitch-chip-logout { color: var(--hs-error) !important; border-color: rgba(186, 26, 26, 0.3) !important; }
.stitch-chip-logout:hover { background: rgba(186, 26, 26, 0.08) !important; color: var(--hs-error) !important; }

.stitch-theme-btn {
  width: 36px; height: 36px; border-radius: 999px; border: 1px solid var(--hs-border);
  background: var(--hs-surface-low); color: var(--hs-text-secondary);
  display: grid; place-items: center; cursor: pointer;
}
.stitch-theme-btn:hover { border-color: var(--hs-primary); color: var(--hs-primary); }

.stitch-balance-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--hs-border); background: var(--hs-surface-low);
  font-size: 12px; font-weight: 600; color: var(--hs-text);
  font-variant-numeric: tabular-nums;
}

/* Cards & glass replacement */
.stitch-app .tech-glass {
  background: var(--hs-surface) !important;
  border: 1px solid var(--hs-border) !important;
  box-shadow: var(--hs-shadow) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border-radius: var(--hs-radius-lg) !important;
}

.stitch-app .text-gradient {
  background: none !important;
  -webkit-text-fill-color: var(--hs-primary) !important;
  color: var(--hs-primary) !important;
}

.stitch-app .glow-border::before { display: none !important; }
.stitch-app .glow-border {
  background: var(--hs-primary) !important;
  border: none !important;
  box-shadow: var(--hs-shadow) !important;
}
.stitch-app .glow-border:hover { opacity: 0.92; }

/* Panels */
.stitch-panel-hero { text-align: center; padding: 32px 16px 16px; }
.stitch-panel-hero h2 { font-size: 1.75rem; font-weight: 800; color: var(--hs-text); margin-bottom: 8px; }
.stitch-panel-hero p { font-size: 14px; color: var(--hs-text-secondary); }

.stitch-tool-btn {
  background: var(--hs-surface) !important;
  border: 1px solid var(--hs-border) !important;
  border-radius: var(--hs-radius-lg) !important;
  box-shadow: var(--hs-shadow) !important;
  transition: border-color 0.15s, box-shadow 0.15s !important;
}
.stitch-tool-btn:hover { border-color: var(--hs-primary) !important; }

.stitch-footer-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--hs-surface) !important;
  border-top: 1px solid var(--hs-border) !important;
  backdrop-filter: none !important;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* 工信部备案悬挂 — 屏幕最底；移动端底部导航在其上方 */
.hs-site-beian-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 35;
  text-align: center;
  padding: 0.3rem 0.75rem;
  padding-bottom: max(0.3rem, env(safe-area-inset-bottom, 0px));
  background: var(--hs-surface-low, var(--hs-surface));
  border-top: 1px solid var(--hs-border);
  font-size: 10px;
  line-height: 1.35;
  color: var(--hs-text-secondary);
  transition: opacity 0.15s ease, visibility 0.15s ease;
}
html.hs-hide-beian-footer .hs-site-beian-footer {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.hs-site-beian-line {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.25rem 0.35rem;
}
.hs-site-beian-footer a {
  color: var(--hs-text-secondary);
  text-decoration: none;
}
.hs-site-beian-footer a:hover {
  color: var(--hs-primary);
  text-decoration: underline;
}
.hs-beian-sep { opacity: 0.45; user-select: none; }
.hs-site-beian-copy { opacity: 0.85; }

@media (max-width: 1023px) {
  .stitch-footer-bar { bottom: calc(var(--hs-bottom-nav-h) + var(--hs-beian-h) + env(safe-area-inset-bottom, 0px)); }
  #mainSystemPanel .stitch-home-main {
    padding-bottom: calc(8.5rem + var(--hs-bottom-nav-h) + var(--hs-beian-h) + env(safe-area-inset-bottom, 0px)) !important;
  }
  #genHistoryPanel main,
  #modelPlazaPanel main {
    padding-bottom: calc(4rem + var(--hs-bottom-nav-h) + var(--hs-beian-h)) !important;
  }
  #authPanel { padding-bottom: calc(2rem + var(--hs-bottom-nav-h) + var(--hs-beian-h)); }
}

@media (min-width: 1024px) {
  .hs-site-beian-footer { left: var(--hs-sidebar-w, 240px); }
  .stitch-footer-bar { bottom: var(--hs-beian-h); }
  #mainSystemPanel .stitch-home-main,
  #genHistoryPanel main,
  #modelPlazaPanel main { padding-bottom: calc(6rem + var(--hs-beian-h)) !important; }
}

@media (max-width: 1023px) {
  #appGrid .stitch-app-card-cover { height: 9.5rem; }
}

.stitch-btn-primary {
  background: var(--hs-primary) !important;
  color: #fff !important;
  border: none !important;
  border-radius: var(--hs-radius) !important;
  box-shadow: var(--hs-shadow) !important;
}
.stitch-btn-primary:hover { opacity: 0.92; }

.stitch-btn-success {
  background: var(--hs-success) !important;
  color: #fff !important;
  border: none !important;
}

.stitch-btn-outline {
  background: var(--hs-surface) !important;
  border: 1px solid var(--hs-border) !important;
  color: var(--hs-text) !important;
}

/* Auth */
.stitch-auth-card { max-width: 420px; width: 100%; padding: 32px !important; }
.stitch-auth-card h2 { color: var(--hs-text) !important; }
.stitch-auth-card input {
  background: var(--hs-surface-low) !important;
  border: 1px solid var(--hs-border) !important;
  color: var(--hs-text) !important;
  border-radius: var(--hs-radius) !important;
}
.stitch-auth-card input:focus { border-color: var(--hs-primary) !important; outline: none; box-shadow: 0 0 0 2px var(--hs-primary-soft); }

/* Modals */
.stitch-app #termsModal,
.stitch-app #rechargeModal,
.stitch-app #proSubModal,
.stitch-app #profileModal,
.stitch-app #creatorStudioModal,
.stitch-app #promptModal,
.stitch-app #imageToPromptModal,
.stitch-app #videoClipModal,
.stitch-app #gptImageModal,
.stitch-app #adminWithdrawModal,
.stitch-app #genHistoryPreviewModal {
  background: var(--hs-modal-overlay) !important;
  backdrop-filter: none !important;
}

.stitch-app #rechargeModal .recharge-modal-panel,
.stitch-app #proSubModal > div,
.stitch-app #profileModal > div,
.stitch-app #termsModal > div,
.stitch-app #imageToPromptModal > div,
.stitch-app #videoClipModal > div {
  background: var(--hs-surface) !important;
  border: 1px solid var(--hs-border) !important;
  color: var(--hs-text) !important;
  border-radius: var(--hs-radius-lg) !important;
  box-shadow: var(--hs-shadow) !important;
}

/* 手机端弹窗：避免超出视口、底部被挡 */
.stitch-app #imageToPromptModal,
.stitch-app #videoClipModal {
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
}
.stitch-app #imageToPromptModal > div,
.stitch-app #videoClipModal > div {
  -webkit-overflow-scrolling: touch;
}
.stitch-app #gptImageModal .max-h-\[420px\] {
  max-height: min(420px, 38vh);
}
@media (min-width: 640px) {
  .stitch-app #gptImageModal .max-h-\[420px\] {
    max-height: 420px;
  }
}
.stitch-app .pkg-inactive {
  border-color: var(--hs-border) !important;
  background: var(--hs-surface) !important;
}
.stitch-app .pkg-active {
  border-color: var(--hs-primary) !important;
  background: var(--hs-primary-soft) !important;
  box-shadow: 0 0 0 1px var(--hs-primary);
}
.stitch-app .recharge-pkg.pkg-active::after {
  background: var(--hs-primary) !important;
  color: #fff !important;
  box-shadow: none !important;
}
.stitch-app .recharge-tier-hero {
  background: var(--hs-surface) !important;
  border-color: var(--hs-border) !important;
}
.stitch-app .recharge-tier-hero.pkg-active {
  border-color: var(--hs-warning) !important;
  background: rgba(217, 119, 6, 0.08) !important;
  box-shadow: 0 0 0 2px rgba(217, 119, 6, 0.35) !important;
}
.stitch-app .recharge-tier-studio.pkg-active {
  border-color: var(--hs-primary) !important;
  background: var(--hs-primary-soft) !important;
}

.stitch-app .recharge-pay-btn {
  background: var(--hs-primary) !important;
  box-shadow: var(--hs-shadow) !important;
}

/* Studio */
.stitch-app #creatorStudioModal {
  background: var(--hs-bg) !important;
}
.stitch-app #creatorStudioModal > div:first-child {
  background: var(--hs-surface) !important;
  border-color: var(--hs-border) !important;
}
.stitch-app #creatorStudioModal h2 { color: var(--hs-text) !important; }
.stitch-app #creatorStudioModal .bg-slate-900,
.stitch-app #creatorStudioModal .bg-slate-950 {
  background: var(--hs-surface) !important;
  border-color: var(--hs-border) !important;
}
.stitch-app #creatorStudioModal input,
.stitch-app #creatorStudioModal select,
.stitch-app #creatorStudioModal textarea {
  background: var(--hs-surface-low) !important;
  border-color: var(--hs-border) !important;
  color: var(--hs-text) !important;
}
.stitch-app #renderScreen {
  background: var(--hs-surface-low) !important;
  border: 1px solid var(--hs-border) !important;
  border-radius: var(--hs-radius-lg) !important;
}
.stitch-app #modeSwitcher { background: var(--hs-surface-low) !important; border-color: var(--hs-border) !important; }

.stitch-mode-active {
  background: var(--hs-primary) !important;
  color: #fff !important;
  box-shadow: none !important;
}
.stitch-mode-inactive {
  background: transparent !important;
  color: var(--hs-text-secondary) !important;
}
.stitch-mode-inactive:hover { color: var(--hs-text) !important; background: var(--hs-surface-high) !important; }

/* Model plaza */
.stitch-app .model-plaza-card {
  border-color: var(--hs-border) !important;
  border-radius: var(--hs-radius) !important;
}
.stitch-app .model-plaza-card:hover {
  border-color: var(--hs-primary) !important;
  box-shadow: var(--hs-shadow) !important;
  transform: translateY(-2px);
}

/* App grid card */
.stitch-app-card-cover { position: relative; height: 14rem; overflow: hidden; }
.stitch-app-card-cover img { width: 100%; height: 100%; object-fit: cover; }
.stitch-app-card-cover .overlay {
  position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(25,28,30,0.75), transparent 55%);
}
.stitch-app-card-cover h3 {
  position: absolute; bottom: 16px; left: 20px; right: 20px;
  font-size: 1.25rem; font-weight: 700; color: #fff;
}

/* Toast */
.stitch-app #toast {
  background: var(--hs-surface) !important;
  border: 1px solid var(--hs-border) !important;
  color: var(--hs-text) !important;
  box-shadow: var(--hs-shadow) !important;
}
.stitch-app #toast.bg-rose-600 {
  background: var(--hs-error) !important;
  color: #fff !important;
  border-color: transparent !important;
}

/* Dark mode text overrides for legacy tailwind classes */
html[data-theme="light"] .stitch-app .text-slate-100,
html[data-theme="light"] .stitch-app .text-slate-200,
html[data-theme="light"] .stitch-app .text-white { color: var(--hs-text) !important; }
html[data-theme="light"] .stitch-app .text-slate-300,
html[data-theme="light"] .stitch-app .text-slate-400,
html[data-theme="light"] .stitch-app .text-slate-500 { color: var(--hs-text-secondary) !important; }
html[data-theme="light"] .stitch-app .text-cyan-300,
html[data-theme="light"] .stitch-app .text-cyan-400 { color: var(--hs-primary) !important; }

html[data-theme="dark"] .stitch-app .bg-slate-800,
html[data-theme="dark"] .stitch-app .bg-slate-900,
html[data-theme="dark"] .stitch-app .bg-slate-950 {
  background-color: var(--hs-surface) !important;
}
html[data-theme="dark"] .stitch-app .border-slate-700,
html[data-theme="dark"] .stitch-app .border-slate-800 {
  border-color: var(--hs-border) !important;
}

/* Hide header nav duplicates on mobile when bottom nav shows */
@media (max-width: 1023px) {
  .stitch-header .header-nav-chips { display: none !important; }
  #userInfoHeader .stitch-chip:not(.stitch-chip-logout):not(.stitch-balance-pill) { display: none !important; }
}

.stitch-nav-hidden { display: none !important; }

/* 首页：历史生成入口 — 浅色模式提高对比度 */
html[data-theme="light"] .hs-history-label { color: #191c1e; }
html[data-theme="light"] .hs-history-icon { color: #0052d9; }
html[data-theme="light"] .hs-history-hint { color: #434654; }
html[data-theme="light"] .hs-history-entry:hover .hs-history-label { color: #0052d9; }
html[data-theme="dark"] .hs-history-label { color: #e6edf3; }
html[data-theme="dark"] .hs-history-icon { color: #4493f8; }
html[data-theme="dark"] .hs-history-hint { color: #8b949e; }

/* 运行溯币徽章 — 浅色模式深色字，避免黄字看不清 */
html[data-theme="light"] .hs-run-badge-pro {
  color: #78350f; background: #fef3c7; border: 1px solid #d97706;
}
html[data-theme="light"] .hs-run-badge-pro .hs-run-badge-tag {
  color: #92400e; border: 1px solid #f59e0b; background: #fffbeb;
}
html[data-theme="light"] .hs-run-badge-normal {
  color: #1e3a8a; background: #eff6ff; border: 1px solid #3b82f6;
}
html[data-theme="light"] .hs-run-badge-normal .hs-run-badge-sub { color: #1d4ed8; }

html[data-theme="dark"] .hs-run-badge-pro {
  color: #fde68a; background: rgba(245, 158, 11, 0.15); border: 1px solid rgba(245, 158, 11, 0.45);
}
html[data-theme="dark"] .hs-run-badge-pro .hs-run-badge-tag {
  color: #fcd34d; border: 1px solid rgba(251, 191, 36, 0.35); background: rgba(0,0,0,0.15);
}
html[data-theme="dark"] .hs-run-badge-normal {
  color: #c4b5fd; background: rgba(99, 102, 241, 0.15); border: 1px solid rgba(129, 140, 248, 0.45);
}
html[data-theme="dark"] .hs-run-badge-normal .hs-run-badge-sub { color: #a5b4fc; }

input[type=file]::file-selector-button {
  margin-right: 1rem; padding: 0.5rem 1rem; border-radius: var(--hs-radius);
  border: none; background: var(--hs-primary); color: #fff; cursor: pointer;
}
input[type="checkbox"] { accent-color: var(--hs-primary); }
