/* web-skin.css — Alioth Agent OS“皮肤应用桥”(P-THEME-1 §9.2).

HTMX 页面在皮肤落地时仍大量使用字面 Tailwind 蓝类；此桥把高频 legacy 颜色类
映射到语义 CSS 变量（--sw-*，由服务端按当前解析主题注入）。这样“主题 + 本桥”
能让旧页面整体随主题换色，而在无自定义主题时以内置默认值（灰蓝）退回原外观。

原则：
- 统一 !important 以稳定胜过 Tailwind Play CDN 运行时生成的同名类；
- 一律 `var(--sw-x, <原值 fallback>)`：自定义主题时取皮肤色，否则与原外观零差异；
- 只覆盖高频颜色类，灰阶/布局保持原样（中性灰一般不随皮肤变）。

无领域词（Rule-018）。由 base.html / chat_embedded.html 以 /sdk/web-skin.css 引入。
*/

/* ── 页面底色骨架 ─────────────────────────────────────────── */
body {
  background-color: var(--sw-background, #f9fafb) !important;
  background-image: var(--sw-glow-soft, none);
  background-attachment: fixed;
  color: var(--sw-ink, #111827) !important;
}
body.bg-gray-50 {
  background-color: var(--sw-background, #f9fafb) !important;
}
.text-gray-900, .text-gray-800, .text-gray-700
{ color: var(--sw-ink, #111827) !important; }
.text-gray-500 { color: var(--sw-ink-muted, #6b7280) !important; }

/* ── 主按钮 / 链接 / 强调：蓝系 → 语义主色 ───────────────── */
.bg-blue-600, .bg-blue-500, .hover\:bg-blue-600:hover
{ background-color: var(--sw-primary, #2563eb) !important; }
.bg-blue-700, .hover\:bg-blue-700:hover
{ background-color: var(--sw-primary-hover, #1d4ed8) !important; }
.hover\:bg-blue-800:hover
{ background-color: var(--sw-primary-active, #1e40af) !important; }

.bg-indigo-600, .bg-indigo-700 {
  background-color: var(--sw-primary, #2563eb) !important;
}

.text-blue-600, .text-blue-700, .text-blue-800,
.text-indigo-600, .text-indigo-700, .hover\:text-blue-700:hover {
  color: var(--sw-primary, #2563eb) !important;
}
.text-blue-400 { color: var(--sw-primary-hover, #60a5fa) !important; }

/* 浅主色底：chip / 徽章 / 柔和区 */
.bg-blue-50, .bg-blue-100, .hover\:bg-blue-50:hover {
  background-color: var(--sw-primary-soft, #eff6ff) !important;
}
.border-blue-200 { border-color: var(--sw-line, #e5e7eb) !important; }
.border-blue-600, .focus\:border-blue-600 { border-color: var(--sw-primary, #2563eb) !important; }

/* 焦点环 / 选中环：ring 色以 RGBA 主色表达 */
.ring-blue-500, .focus\:ring-blue-500,
.ring-indigo-500, .focus\:ring-indigo-500 {
  --tw-ring-color: var(--sw-primary, #2563eb) !important;
}

/* 卡片/输入等“纸面”，允许被浅灰页衬托 */
.bg-white { background-color: var(--sw-surface, #ffffff) !important; }

/* ── 语义状态（很少被旧类直接用，兜底给 ring/文本色） ─────── */
.text-green-600 { color: var(--sw-success, #16a34a) !important; }
.text-amber-600 { color: var(--sw-warning, #d97706) !important; }
.text-red-600   { color: var(--sw-danger, #dc2626) !important; }

/* ═══════ 暗色皮肤 → 全站暗化 ══════════════════════════════════

   服务端在解析主题背景为深色时给 <html> 置 data-sw-mode="dark"
   （theme.service.spec_is_dark），此处把高频灰阶类映射到语义角色，使
   深色皮肤覆盖所有 HTMX 页面（含系统主页）。亮色皮肤/内置默认无此属性
   → 灰阶保持原样（零差异）；品牌主色仍由活跃皮肤注入值承接。
   中性角色默认值取内置暗色基线，实际运行时 --sw-* 已由深色主题注入，
   fallback 仅作无主题时的兜底。 */

html[data-sw-mode="dark"] body,
html[data-sw-mode="dark"] .bg-gray-50 {
  background-color: var(--sw-background, #0f1115) !important;
}
html[data-sw-mode="dark"] .bg-gray-100 {
  background-color: var(--sw-surface-alt, #1a1d24) !important;
}
html[data-sw-mode="dark"] .bg-gray-200 {
  background-color: var(--sw-surface-alt, #232833) !important;
}
html[data-sw-mode="dark"] .hover\:bg-gray-50:hover,
html[data-sw-mode="dark"] .hover\:bg-gray-100:hover,
html[data-sw-mode="dark"] .hover\:bg-gray-200:hover {
  background-color: var(--sw-surface-alt, #232833) !important;
}

html[data-sw-mode="dark"] .text-gray-600,
html[data-sw-mode="dark"] .text-gray-500,
html[data-sw-mode="dark"] .text-gray-400,
html[data-sw-mode="dark"] .text-gray-300 {
  color: var(--sw-ink-muted, #9aa3b2) !important;
}

/* 悬停/激活深灰文本：暗色下同样抬升为语义主文本（否则 hover 深灰不可见） */
html[data-sw-mode="dark"] .hover\:text-gray-900:hover,
html[data-sw-mode="dark"] .hover\:text-gray-800:hover,
html[data-sw-mode="dark"] .hover\:text-gray-700:hover {
  color: var(--sw-ink, #e5e7eb) !important;
}

html[data-sw-mode="dark"] .border-gray-300,
html[data-sw-mode="dark"] .border-gray-200,
html[data-sw-mode="dark"] .border-gray-100,
html[data-sw-mode="dark"] .border-gray-50 {
  border-color: var(--sw-line, #2e3542) !important;
}
html[data-sw-mode="dark"] .divide-gray-200 > :not([hidden]) ~ :not([hidden]),
html[data-sw-mode="dark"] .divide-gray-100 > :not([hidden]) ~ :not([hidden]) {
  border-color: var(--sw-line, #2e3542) !important;
}

html[data-sw-mode="dark"] .placeholder-gray-400::placeholder,
html[data-sw-mode="dark"] .placeholder-gray-300::placeholder {
  color: var(--sw-ink-muted, #9aa3b2) !important;
}

/* 原生表单控件：多数 input/select/textarea 无 bg-white 类，浏览器默认白底黑字
   在暗色皮肤下保持原样；统一映射到语义 surface/ink（checkbox/radio 保留原生渲染）。 */
html[data-sw-mode="dark"] input:not([type="checkbox"]):not([type="radio"]),
html[data-sw-mode="dark"] select,
html[data-sw-mode="dark"] textarea {
  background-color: var(--sw-surface, #111827) !important;
  color: var(--sw-ink, #e5e7eb) !important;
}
html[data-sw-mode="dark"] select option {
  background-color: var(--sw-surface, #111827) !important;
  color: var(--sw-ink, #e5e7eb) !important;
}

/* ── P-THEME-3 aurora 语义组件类 ─────────────────────────────
   token 由服务端按当前解析主题注入（theme/service.py::_derived_css_pairs）：
   --sw-accent-grad / --sw-glow-soft / --sw-card-radius / --sw-shadow-md /
   --sw-glass-bg。fallback 取 aurora 值，无注入时观感不变。 */
.sw-card {
  background: var(--sw-surface, #ffffff);
  border: 1px solid var(--sw-line, #e2e7f2);
  border-radius: var(--sw-card-radius, 16px);
  box-shadow: var(--sw-shadow-md, 0 4px 16px rgba(31, 41, 55, 0.08));
}

/* 玻璃拟态卡：半透明纸面 + 背景模糊（surface 派生，暗色预设同步适配） */
.sw-glass {
  background: var(--sw-glass-bg, rgba(255, 255, 255, 0.68));
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--sw-line, #e2e7f2);
  border-radius: var(--sw-card-radius, 16px);
  box-shadow: var(--sw-shadow-md, 0 4px 16px rgba(31, 41, 55, 0.08));
}

/* 等宽模块网格（16 模块页/主页通用）：4 列 / 6 列，窄屏降级 */
.sw-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}
.sw-grid-6 {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 1rem;
}
@media (max-width: 1024px) {
  .sw-grid-4, .sw-grid-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .sw-grid-4, .sw-grid-6 { grid-template-columns: minmax(0, 1fr); }
}

/* ── 语义工具类（chat 工作台重设计引入；主题变量驱动，暗色皮肤自动适配） ── */
.sw-paper   { background-color: var(--sw-surface, #ffffff); }
.sw-paper-alt { background-color: var(--sw-surface-alt, #f4f5ff); }
.sw-ink     { color: var(--sw-ink, #111827); }
.sw-ink-m   { color: var(--sw-ink-muted, #6b7280); }
.sw-line-b  { border: 1px solid var(--sw-line, #e5e7eb); }
.sw-line-t  { border-top: 1px solid var(--sw-line, #e5e7eb); }
.sw-line-bt { border-bottom: 1px solid var(--sw-line, #e5e7eb); }
.sw-line-r  { border-right: 1px solid var(--sw-line, #e5e7eb); }
/* 主色 12% 透明（primary 为 hex，可直接拼 alpha 后缀）：选中态淡底 */
.sw-primary-tint { background-color: color-mix(in srgb, var(--sw-primary, #2563eb) 8%, transparent); }
.sw-primary-tint-line { border-color: color-mix(in srgb, var(--sw-primary, #2563eb) 35%, transparent); }

/* 浮层面板（下拉/弹窗）：纸面 + 细边 + 阴影 */
.sw-popover {
  background-color: var(--sw-surface, #ffffff);
  border: 1px solid var(--sw-line, #e5e7eb);
  border-radius: calc(var(--sw-radius, 0.5rem) + 2px) !important;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--sw-ink, #1f2937) 12%, transparent);
}

/* 小徽章/信息芯片 */
.sw-pill {
  display: inline-flex; align-items: center; gap: .375rem;
  background-color: var(--sw-surface, #ffffff);
  border: 1px solid var(--sw-line, #e5e7eb);
  color: var(--sw-ink-muted, #6b7280);
  border-radius: 9999px !important;
}

/* 钩子插槽（chat 标题栏等）：插件贡献若为裸 button/a/span（未自带外观类），
   统一呈现为一枚**虚线圆圈**——只表明此处是可扩展位，**不展示占位文字**
   （例如示例插件的「钩子按钮」）。贡献自带 class（如 sw-pill/btn）时不命中，
   尊重插件自身外观。 */
.hook-slot > button:not([class]),
.hook-slot > a:not([class]),
.hook-slot > span:not([class]) {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.125rem; height: 1.125rem;
  padding: 0; font-size: 0; line-height: 0;
  background: transparent;
  color: transparent;
  border: 1px dashed color-mix(in srgb, var(--sw-ink-muted, #6b7280) 45%, transparent);
  border-radius: 50%;
  cursor: pointer;
  text-decoration: none;
  overflow: hidden;
  vertical-align: middle;
}
.hook-slot > button:not([class]):hover,
.hook-slot > a:not([class]):hover,
.hook-slot > span:not([class]):hover {
  border-color: color-mix(in srgb, var(--sw-primary, #2563eb) 55%, transparent);
  background: color-mix(in srgb, var(--sw-primary, #2563eb) 6%, transparent);
}

/* 用户消息气泡：主色底 + 不对称圆角 + 轻投影（chat 重设计，双端共用）。 */
.chat-bubble-user {
  background-color: var(--sw-primary, #2563eb);
  color: #ffffff;
  border-radius: 0.875rem 0.875rem 0.875rem 0.25rem;
  box-shadow: 0 2px 8px -2px color-mix(in srgb, var(--sw-primary, #2563eb) 45%, transparent);
}

/* 选择卡（★P0-Q8 疑点/动作卡，双端共用渲染器）：语义纸面 + 细边 + 主题勾选色。
   ★2026-09-15 回归：渲染器原硬编码 slate 系（bg-slate-50/border-slate-300/
   text-slate-800）不在本桥映射表内 → 任何主题下保持浅灰，暗色皮肤下刺眼白卡。
   fallback 取原 slate 值，无自定义主题时观感与旧版零差异；深色皮肤下
   --sw-* 注入暗值 → 卡片随主题暗化。 */
.sel-card {
  background-color: var(--sw-surface-alt, #f8fafc);
  border: 1px solid var(--sw-line, #cbd5e1);
  color: var(--sw-ink, #1e293b);
}
.sel-item-cb { accent-color: var(--sw-primary, #2563eb); }

/* 消息画布：语义纸面 + 极淡点阵纹理，衬托气泡（主 chat / 嵌入式共用）。 */
.chat-canvas {
  background:
    radial-gradient(circle at 1px 1px,
      color-mix(in srgb, var(--sw-ink, #64748b) 6%, transparent) 1px, transparent 0)
    0 0 / 22px 22px,
    var(--sw-surface-alt, #fafbfc);
}

/* 输入区托底：顶部细分割线，输入框与消息流分层（双端共用）。 */
.chat-input-dock {
  border-top: 1px solid var(--sw-line, #e5e7eb);
  background: var(--sw-surface, #ffffff);
}

/* 顶栏：随主题纸面 + 细底边（替换固定白/灰） */
header.sw-topbar {
  background-color: color-mix(in srgb, var(--sw-surface, #ffffff) 82%, transparent);
  border-bottom: 1px solid var(--sw-line, #e5e7eb);
}

/* 版本徽标（右下角常驻浮层） */
.sw-version-badge {
  color: var(--sw-ink-muted, #9ca3af);
  background-color: color-mix(in srgb, var(--sw-surface, #ffffff) 70%, transparent);
  border: 1px solid var(--sw-line, #e5e7eb);
  border-radius: 9999px;
}
.sw-btn-primary {
  background: var(--sw-accent-grad, var(--sw-primary, #4f46e5));
  color: #ffffff;
  border-radius: calc(var(--sw-card-radius, 16px) / 2);
  box-shadow: 0 2px 8px -2px
    color-mix(in srgb, var(--sw-primary, #4f46e5) 45%, transparent);
}
.sw-btn-primary:hover { filter: brightness(0.96); }
.sw-chip {
  display: inline-flex; align-items: center; gap: .25rem;
  background: var(--sw-primary-soft, #e6e8ff);
  color: var(--sw-primary, #4f46e5);
  border-radius: 9999px;
}
.sw-background-aura {
  background: var(--sw-background, #f4f5ff);
}
