/* myFlow · 纺织智造白标主题
 * 染缸青 + 织线金 + 冷灰科技面；浅色优先；对比 ≥ AA
 * 注意：勿对 :focus-visible 强制 outline（会破坏 Dify 输入框 inset-ring）
 */

/* ---------- tokens ---------- */
html,
html[data-theme="light"],
html[data-theme="dark"],
:root {
  --myflow-primary: #0f5c63;
  --myflow-primary-hover: #0a454a;
  --myflow-primary-soft: #e6f3f4;
  --myflow-tech: #0e7490;
  --myflow-accent: #b8956c;
  --myflow-accent-soft: #f5efe6;
  --myflow-bg: #eef2f4;
  --myflow-surface: #ffffff;
  --myflow-fg: #0f172a;
  --myflow-fg-secondary: #334155;
  --myflow-fg-muted: #475569;
  --myflow-border: #d0d9e0;
  --myflow-ring: #0f5c63;

  /* Tighter radii — less “default SaaS / Dify” roundness */
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 10px;
  --radius-2xl: 12px;

  --font-sans: "DM Sans", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC",
    "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: "Space Grotesk", "DM Sans", "PingFang SC", "Hiragino Sans GB",
    "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;

  --color-primary-25: #f2fafa;
  --color-primary-50: #e6f3f4;
  --color-primary-100: #c5e4e6;
  --color-primary-200: #9dced2;
  --color-primary-300: #6bb0b6;
  --color-primary-400: #3d8f97;
  --color-primary-500: #1a727a;
  --color-primary-600: #0f5c63;
  --color-primary-700: #0a454a;
  --color-primary-800: #08353a;
  --color-primary-900: #06272b;

  --color-components-button-primary-bg: #0f5c63;
  --color-components-button-primary-bg-hover: #0a454a;
  --color-components-button-primary-bg-disabled: #9dced2;
  --color-components-button-primary-border: #0f5c63;
  --color-components-button-primary-border-hover: #0a454a;
  --color-components-button-primary-border-disabled: #9dced2;
  --color-components-button-primary-text: #ffffff;
  --color-components-button-primary-text-disabled: #f2fafa;

  --color-components-button-secondary-accent-bg: #e6f3f4;
  --color-components-button-secondary-accent-bg-hover: #c5e4e6;
  --color-components-button-secondary-accent-text: #0a454a;
  --color-components-button-secondary-accent-border: #9dced2;

  --color-text-accent: #0f5c63;
  --color-text-accent-secondary: #0a454a;
  --color-state-accent-solid: #0f5c63;
  --color-state-accent-hover: #0a454a;
  --color-state-accent-active: #08353a;
  --color-divider-accent: #0f5c63;

  --color-util-colors-blue-brand-50: #e6f3f4;
  --color-util-colors-blue-brand-100: #c5e4e6;
  --color-util-colors-blue-brand-200: #9dced2;
  --color-util-colors-blue-brand-500: #1a727a;
  --color-util-colors-blue-brand-600: #0f5c63;
  --color-util-colors-blue-brand-700: #0a454a;

  --color-accent-primary: #0f5c63;
  --color-accent-primary-hover: #0a454a;
  --color-accent-primary-active: #08353a;

  /* Kill leftover indigo “Dify blue” accents */
  --color-indigo-500: #1a727a;
  --color-indigo-600: #0f5c63;
  --color-indigo-700: #0a454a;
  --color-blue-500: #0e7490;
  --color-blue-600: #0f5c63;
}

/* Light surfaces */
html[data-theme="light"],
html:not([data-theme="dark"]) {
  --color-background-body: #eef2f4;
  --color-background-default: #ffffff;
  --color-background-default-subtle: #f7f9fa;
  --color-background-soft: #e8eef1;
  --color-background-section: #e2e9ed;
  --color-background-sidenav-bg: #f3f6f7;
  --color-background-surface-white: #ffffff;
  --color-background-neutral-subtle: #e8eef1;
  --color-border-default: #d0d9e0;
  --color-border-muted: #e0e6eb;
  --color-text-primary: #0f172a;
  --color-text-secondary: #334155;
  --color-text-tertiary: #475569;
  --color-text-quaternary: #64748b;

  --color-components-input-bg-normal: #ffffff;
  --color-components-input-bg-hover: #f7f9fa;
  --color-components-input-bg-active: #ffffff;
  --color-components-input-border-hover: #9dced2;
  --color-components-input-border-active: #0f5c63;
  --color-components-input-border-active-prompt-1: #0f5c63;
  --color-components-input-text-filled: #0f172a;
  --color-components-input-text-placeholder: #64748b;
  --color-components-input-bg-disabled: #eef2f4;
}

/* Dark */
html[data-theme="dark"] {
  --color-primary-25: #06272b;
  --color-primary-50: #08353a;
  --color-primary-100: #0a454a;
  --color-primary-200: #0f5c63;
  --color-primary-300: #1a727a;
  --color-primary-400: #3d8f97;
  --color-primary-500: #6bb0b6;
  --color-primary-600: #2dd4bf;
  --color-primary-700: #5eead4;
  --color-primary-800: #99f6e4;
  --color-primary-900: #ccfbf1;

  --color-components-button-primary-bg: #14b8a6;
  --color-components-button-primary-bg-hover: #2dd4bf;
  --color-components-button-primary-border: #14b8a6;
  --color-components-button-primary-border-hover: #2dd4bf;
  --color-components-button-primary-text: #042f2e;

  --color-text-accent: #5eead4;
  --color-text-accent-secondary: #99f6e4;
  --color-state-accent-solid: #14b8a6;

  --color-background-body: #0b1220;
  --color-background-default: #111827;
  --color-background-default-subtle: #0f172a;
  --color-background-soft: #1e293b;
  --color-background-section: #1e293b;
  --color-background-sidenav-bg: #0c1424;
  --color-border-default: rgba(148, 163, 184, 0.22);
  --color-border-muted: rgba(148, 163, 184, 0.14);
  --color-text-primary: #f8fafc;
  --color-text-secondary: #e2e8f0;
  --color-text-tertiary: #cbd5e1;
  --color-text-quaternary: #94a3b8;

  --color-components-input-bg-normal: #111827;
  --color-components-input-bg-hover: #1e293b;
  --color-components-input-bg-active: #111827;
  --color-components-input-border-active: #2dd4bf;
  --color-components-input-border-active-prompt-1: #2dd4bf;
  --color-components-input-border-hover: #3d8f97;
  --color-components-input-text-filled: #f8fafc;
  --color-components-input-text-placeholder: #94a3b8;
}

/* ---------- typography ---------- */
html,
body,
#__next,
[class*="system-"],
button,
input,
textarea,
select {
  font-family: var(--font-sans) !important;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3,
.system-xl-semibold,
.system-2xl-semibold,
.system-3xl-semibold {
  font-family: var(--font-display) !important;
  letter-spacing: -0.02em;
  color: var(--color-text-primary);
}

body {
  color: var(--color-text-primary);
  background-color: var(--color-background-body);
  line-height: 1.55;
}

/* ---------- atmosphere ---------- */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  opacity: 0.035;
  background-image:
    linear-gradient(90deg, var(--myflow-primary) 1px, transparent 1px),
    linear-gradient(0deg, var(--myflow-primary) 1px, transparent 1px);
  background-size: 24px 24px;
  mask-image: radial-gradient(ellipse at 20% 0%, #000 0%, transparent 65%);
}

html[data-theme="light"] body {
  background-color: #eef2f4 !important;
  background-image:
    radial-gradient(ellipse 70% 45% at 8% -8%, rgba(15, 92, 99, 0.08), transparent 55%),
    radial-gradient(ellipse 50% 35% at 100% 0%, rgba(184, 149, 108, 0.06), transparent 50%),
    linear-gradient(180deg, #f5f8f9 0%, #e8eef1 100%);
  background-attachment: fixed;
}

html[data-theme="dark"] body {
  background-image:
    radial-gradient(ellipse 70% 45% at 15% -5%, rgba(45, 212, 191, 0.07), transparent 55%),
    radial-gradient(ellipse 50% 35% at 100% 0%, rgba(184, 149, 108, 0.04), transparent 50%);
  background-attachment: fixed;
}

html[data-theme="dark"] body::before {
  opacity: 0.05;
  background-image:
    linear-gradient(90deg, #5eead4 1px, transparent 1px),
    linear-gradient(0deg, #5eead4 1px, transparent 1px);
}

/* Auth pages: stronger textile shell (does not change React tree) */
html[data-myflow-page="auth"] body {
  background-color: #e8eef1 !important;
  background-image:
    radial-gradient(ellipse 90% 60% at 0% 0%, rgba(15, 92, 99, 0.14), transparent 55%),
    radial-gradient(ellipse 70% 50% at 100% 100%, rgba(184, 149, 108, 0.1), transparent 50%),
    linear-gradient(165deg, #f4f7f8 0%, #dde6ea 100%) !important;
}

html[data-myflow-page="auth"] body::before {
  opacity: 0.06;
  background-size: 20px 20px;
  mask-image: none;
}

html[data-myflow-page="auth"] img[src*="/logo/"],
html[data-myflow-page="auth"] img[src*="logo-site"] {
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(15, 92, 99, 0.18);
}

/* ---------- focus / inputs（修复重点）---------- */
/* 取消全局 outline：Dify 输入依赖 inset-ring，!important outline 会叠坏边框 */
:focus {
  outline: none;
}
:focus-visible {
  outline: none;
}

/* 原生控件：用 inset box-shadow 表达 focus，不抢 layout */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):focus,
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):focus-visible,
textarea:focus,
textarea:focus-visible,
select:focus,
select:focus-visible {
  outline: none !important;
  border-color: var(--color-components-input-border-active) !important;
  box-shadow: inset 0 0 0 1px var(--color-components-input-border-active) !important;
  caret-color: var(--myflow-primary) !important;
}

html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):focus,
html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):focus-visible,
html[data-theme="dark"] textarea:focus,
html[data-theme="dark"] textarea:focus-visible,
html[data-theme="dark"] select:focus,
html[data-theme="dark"] select:focus-visible {
  caret-color: #2dd4bf !important;
  box-shadow: inset 0 0 0 1px var(--color-components-input-border-active) !important;
}

/* 搜索等 focus-within 容器：统一染缸青环，避免残留蓝/双环 */
.focus-within\:inset-ring-components-input-border-active:focus-within,
[class*="focus-within:inset-ring-components-input-border-active"]:focus-within,
[class*="focus-within:border-components-input-border-active"]:focus-within {
  --tw-inset-ring-color: var(--color-components-input-border-active) !important;
  border-color: var(--color-components-input-border-active) !important;
}

/* 键盘可达的按钮：细环，不挡住圆角 */
button:focus-visible,
[role="button"]:focus-visible,
a:focus-visible {
  outline: 2px solid var(--myflow-ring) !important;
  outline-offset: 2px !important;
}

/* 输入类元素不要上面的按钮 outline */
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[contenteditable="true"]:focus-visible {
  outline: none !important;
}

/* ---------- layout chrome（整体更不像上游）---------- */
/* 侧栏：略偏冷灰织面 */
.bg-background-sidenav-bg,
[class*="bg-background-sidenav"] {
  border-right: 1px solid var(--color-border-muted);
}

/* 卡片 / 面板：更克制的阴影与描边 */
.bg-components-panel-bg,
[class*="bg-components-panel-bg"],
.shadow-md,
.shadow-lg {
  --tw-shadow-color: rgba(15, 92, 99, 0.06);
}

/* 主按钮 */
.bg-components-button-primary-bg,
button.btn-primary {
  transition: background-color 160ms ease, border-color 160ms ease,
    box-shadow 160ms ease !important;
  letter-spacing: 0.02em;
}

.bg-components-button-primary-bg:hover {
  box-shadow: 0 2px 8px rgba(15, 92, 99, 0.2);
}

/* 顶栏分隔 */
header,
[class*="border-b"][class*="border-divider"] {
  border-color: var(--color-border-muted) !important;
}

/* 链接：仅强调文案链，勿染全局 nav */
a.system-xs-medium.text-text-secondary:hover,
a.text-text-accent,
.text-text-accent {
  color: var(--color-text-accent) !important;
}

::selection {
  background: var(--myflow-primary-soft);
  color: var(--myflow-fg);
}

html[data-theme="dark"] ::selection {
  background: #134e4a;
  color: #f8fafc;
}

/* ---------- de-Dify chrome ---------- */
a[href*="dify.ai"],
a[href*="langgenius"],
a[data-myflow-blocked],
[class*="powered-by"],
[class*="PoweredBy"],
[data-myflow-hide="1"] {
  display: none !important;
}

/* Creators / Learn / Cloud 上架入口整块隐藏（功能开关关闭后的兜底） */
[data-myflow-section="creators"],
a[href*="publish-to-creators"],
a[href*="creators.dify"] {
  display: none !important;
}

/* ---------- Marketplace 右侧顶部 Hero（仅 UI，不改功能/文案）---------- */
html[data-theme="light"],
html:not([data-theme="dark"]) {
  --color-components-marketplace-header-bg: rgba(255, 255, 255, 0.88);
  --color-marketplace-divider-bg: linear-gradient(
    90deg,
    rgba(15, 92, 99, 0.14) 0%,
    rgba(255, 255, 255, 0) 100%
  );
  --color-marketplace-plugin-empty: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0) 0%,
    #f3f6f7 100%
  );
}

html[data-theme="dark"] {
  --color-components-marketplace-header-bg: rgba(15, 23, 42, 0.86);
  --color-marketplace-divider-bg: linear-gradient(
    90deg,
    rgba(94, 234, 212, 0.16) 0%,
    rgba(0, 0, 0, 0) 100%
  );
  --color-marketplace-plugin-empty: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0) 0%,
    #0b1220 100%
  );
}

/* 底色：去掉 Dify #0033ff，改为染缸青渐变（浅/深色各一版） */
html[data-theme="light"] .bg-\[\#0033ff\],
html:not([data-theme="dark"]) .bg-\[\#0033ff\],
html[data-theme="light"] [class*="bg-[#0033ff]"],
html:not([data-theme="dark"]) [class*="bg-[#0033ff]"] {
  background: linear-gradient(
    125deg,
    #0c4a52 0%,
    #0f5c63 42%,
    #0e7490 78%,
    #134e4a 100%
  ) !important;
}

html[data-theme="dark"] .bg-\[\#0033ff\],
html[data-theme="dark"] [class*="bg-[#0033ff]"] {
  background: linear-gradient(
    125deg,
    #041618 0%,
    #06272b 35%,
    #0a454a 70%,
    #0b1220 100%
  ) !important;
}

/* 背景图层：cover + 柔和混合，避免 110% + lighten 发脏 */
[style*="hero-bg.jpg"] {
  background-size: cover !important;
  background-position: center 28% !important;
  background-repeat: no-repeat !important;
  mix-blend-mode: soft-light !important;
  opacity: 0.42 !important;
}

html[data-theme="dark"] [style*="hero-bg.jpg"] {
  mix-blend-mode: overlay !important;
  opacity: 0.38 !important;
  background-position: center 35% !important;
}

/* 噪点渐变层：降低存在感，避免抢标题 */
[style*="hero-gradient-noise.svg"] {
  opacity: 0.55 !important;
  mix-blend-mode: normal !important;
}

html[data-theme="dark"] [style*="hero-gradient-noise.svg"] {
  opacity: 0.4 !important;
}

/* Hero 容器：更干净的卡片感（sticky 顶栏仍保留） */
.sticky.top-0.z-20.w-full.shrink-0.overflow-hidden.rounded-lg:has(.bg-\[\#0033ff\]),
.sticky.top-0.z-20.w-full.shrink-0.overflow-hidden.rounded-lg:has([class*="bg-[#0033ff]"]) {
  border-radius: 12px !important;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.12) inset,
    0 8px 28px rgba(15, 92, 99, 0.18);
  isolation: isolate;
}

html[data-theme="dark"]
  .sticky.top-0.z-20.w-full.shrink-0.overflow-hidden.rounded-lg:has(.bg-\[\#0033ff\]),
html[data-theme="dark"]
  .sticky.top-0.z-20.w-full.shrink-0.overflow-hidden.rounded-lg:has([class*="bg-[#0033ff]"]) {
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.06) inset,
    0 10px 32px rgba(0, 0, 0, 0.35);
}

/* 标题区：保证浅/深色都清晰（on-surface 本就为浅色字） */
.sticky.top-0.z-20:has(.bg-\[\#0033ff\]) .text-text-primary-on-surface,
.sticky.top-0.z-20:has([class*="bg-[#0033ff]"]) .text-text-primary-on-surface {
  color: #ffffff !important;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.22);
  letter-spacing: -0.02em;
}

.sticky.top-0.z-20:has(.bg-\[\#0033ff\]) .text-text-secondary-on-surface,
.sticky.top-0.z-20:has([class*="bg-[#0033ff]"]) .text-text-secondary-on-surface {
  color: rgba(255, 255, 255, 0.86) !important;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.18);
}

/* Hero 内搜索条：毛玻璃更干净，浅/深都可读 */
.sticky.top-0.z-20:has(.bg-\[\#0033ff\]) .bg-components-panel-bg-blur,
.sticky.top-0.z-20:has(.bg-\[\#0033ff\]) [class*="bg-components-panel-bg-blur"],
.sticky.top-0.z-20:has([class*="bg-[#0033ff]"]) .bg-components-panel-bg-blur,
.sticky.top-0.z-20:has([class*="bg-[#0033ff]"]) [class*="bg-components-panel-bg-blur"] {
  background-color: rgba(255, 255, 255, 0.14) !important;
  border-color: rgba(255, 255, 255, 0.35) !important;
  backdrop-filter: blur(10px) saturate(1.1);
  -webkit-backdrop-filter: blur(10px) saturate(1.1);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
}

html[data-theme="dark"]
  .sticky.top-0.z-20:has(.bg-\[\#0033ff\])
  .bg-components-panel-bg-blur,
html[data-theme="dark"]
  .sticky.top-0.z-20:has(.bg-\[\#0033ff\])
  [class*="bg-components-panel-bg-blur"],
html[data-theme="dark"]
  .sticky.top-0.z-20:has([class*="bg-[#0033ff]"])
  .bg-components-panel-bg-blur,
html[data-theme="dark"]
  .sticky.top-0.z-20:has([class*="bg-[#0033ff]"])
  [class*="bg-components-panel-bg-blur"] {
  background-color: rgba(15, 23, 42, 0.45) !important;
  border-color: rgba(148, 163, 184, 0.28) !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

/* Hero 搜索输入字色 */
.sticky.top-0.z-20:has(.bg-\[\#0033ff\]) input,
.sticky.top-0.z-20:has([class*="bg-[#0033ff]"]) input {
  color: #ffffff !important;
  caret-color: #ffffff !important;
}

.sticky.top-0.z-20:has(.bg-\[\#0033ff\]) input::placeholder,
.sticky.top-0.z-20:has([class*="bg-[#0033ff]"]) input::placeholder {
  color: rgba(255, 255, 255, 0.55) !important;
}

html[data-theme="dark"] .sticky.top-0.z-20:has(.bg-\[\#0033ff\]) input,
html[data-theme="dark"] .sticky.top-0.z-20:has([class*="bg-[#0033ff]"]) input {
  color: #f8fafc !important;
}

/* 分隔线弱化 */
.bg-marketplace-divider-bg {
  background-image: var(--color-marketplace-divider-bg) !important;
}

.bg-marketplace-plugin-empty {
  background-image: var(--color-marketplace-plugin-empty) !important;
}

.text-text-quaternary,
.text-gray-400,
.text-gray-300 {
  color: var(--color-text-tertiary) !important;
}

html[data-theme="light"] .text-text-quaternary {
  color: #475569 !important;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
