/* ==========================================================================
   砚序 API · Yanxu API
   方案：宣纸矿物（Paper & Mineral）
   --------------------------------------------------------------------------
   适配：New API 二开后台（React + Tailwind + shadcn/ui，原生浅色 UI）

   ★ 本文件只换皮，不改布局
     不动 padding / margin / width / height / font-size / line-height /
     display / position / overflow。

   色值表
     宣纸底 background #F6F3EC      卡片   card      #FCFAF6
     侧栏底 sidebar    #EFEAE0      表头   muted     #EDE6D9
     悬浮底 accent     #F1EADA      行悬浮 row-hover #F4EEDF
     墨色   foreground #211E1A      次级   muted-fg  #6A6358
     朱砂   primary    #A32B21      朱砂悬浮 #8E241B
     深朱   danger     #8C1F1A      金     ring      #B0863C
     淡茶线 border     #DED5C4      输入线 input     #D3C8B4

   对比度（实测，WCAG 2.1）
     墨 / 纸底 15.0:1   墨 / 卡片 15.9:1   墨 / 侧栏 13.9:1
     次级 / 纸底 5.4:1  次级 / 卡片 5.7:1  次级 / 侧栏 5.0:1
     白 / 朱砂 7.2:1    白 / 深朱 9.1:1    表头字 / 表头底 7.8:1
     金 / 纸底 3.0:1 —— 仅 1px 描边与焦点环，绝不用于文字

   三重保险（这是本文件与上一版最大的区别）
     1. 变量层：七个选择器并列，<html> 挂 dark / light / data-theme 或什么都不挂，
        取值恒定，从变量层就封死「顶栏深、内容白、字糊死」。
     2. 工具类层：直接给 .bg-background / .bg-card / .text-foreground 等
        Tailwind 工具类写死颜色，绕开「变量怎么被消费」这个不确定性。
     3. 兜底层：把 bg-zinc-900 / bg-neutral-900 这类写死的深色背景强行拉回宣纸，
        并反向修正其内部文字，防止个别组件把深色硬编码带回来。
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. 设计令牌
   -------------------------------------------------------------------------- */
:root,
:root.light,
:root.dark,
:root[data-theme="light"],
:root[data-theme="dark"],
.light,
.dark {
  color-scheme: light;

  --background: #F6F3EC;
  --foreground: #211E1A;
  --card: #FCFAF6;
  --card-foreground: #211E1A;
  --popover: #FCFAF6;
  --popover-foreground: #211E1A;

  --primary: #A32B21;
  --primary-foreground: #FFFFFF;

  --secondary: #EFEAE0;
  --secondary-foreground: #211E1A;

  --muted: #EDE6D9;
  --muted-foreground: #6A6358;

  --accent: #F1EADA;
  --accent-foreground: #211E1A;

  --destructive: #8C1F1A;
  --destructive-foreground: #FFFFFF;

  --border: #DED5C4;
  --input: #D3C8B4;
  --ring: #B0863C;

  --chart-1: #A8352A;
  --chart-2: #4F6B6B;
  --chart-3: #A9782F;
  --chart-4: #3C5169;
  --chart-5: #4C6B4F;

  --sidebar: #EFEAE0;
  --sidebar-foreground: #211E1A;
  --sidebar-primary: #A32B21;
  --sidebar-primary-foreground: #FFFFFF;
  --sidebar-accent: #F1EADA;
  --sidebar-accent-foreground: #211E1A;
  --sidebar-border: #DED5C4;
  --sidebar-ring: #B0863C;

  --radius: 0px;
  --radius-sm: 0px;
  --radius-md: 0px;
  --radius-lg: 0px;
  --radius-xl: 0px;
  --radius-2xl: 0px;

  /* 品牌辅助 */
  --yx-hairline: #E4DBC9;
  --yx-gold-line: #D8C08C;
  --yx-gold-wash: rgba(176, 134, 60, 0.18);
  --yx-primary-hover: #8E241B;
  --yx-row-hover: #F4EEDF;
  --yx-th-fg: #4A443B;
  --yx-success: #3F7A4A;
  --yx-warning: #88631F;
  --yx-placeholder: #7C7466;

  --yx-font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", system-ui,
    "Noto Sans SC", sans-serif;
  --yx-font-serif: "Songti SC", "STSong", "STZhongsong", "SimSun",
    "Source Han Serif SC", "Noto Serif SC", Georgia, serif;
  --yx-font-mono: "SF Mono", "JetBrains Mono", "Cascadia Mono",
    "Roboto Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

/* --------------------------------------------------------------------------
   2. 基底
   -------------------------------------------------------------------------- */
html,
body {
  background-color: var(--background) !important;
  color: var(--foreground) !important;
  font-family: var(--yx-font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.font-inter,
[class*="font-inter"] {
  font-family: var(--yx-font-sans) !important;
}

/* 宋体只给真正的大标题 */
:is(h1, h2, .font-serif, [data-slot="page-title"], .page-title) {
  font-family: var(--yx-font-serif);
  font-weight: 600;
}

:is(code, pre, kbd, samp, .font-mono, [class*="font-mono"]) {
  font-family: var(--yx-font-mono) !important;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

:is(table, .tabular-nums, [class*="tabular-nums"]) {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

::selection {
  background: rgba(163, 43, 33, 0.14);
  color: var(--foreground);
}

/* --------------------------------------------------------------------------
   3. 工具类直改 —— 绕开变量消费方式的不确定性
   -------------------------------------------------------------------------- */
.bg-background { background-color: var(--background) !important; }
.bg-card       { background-color: var(--card) !important; }
.bg-popover    { background-color: var(--card) !important; }
.bg-muted      { background-color: var(--muted) !important; }
.bg-secondary  { background-color: var(--secondary) !important; }
.bg-accent     { background-color: var(--accent) !important; }
.bg-sidebar    { background-color: var(--sidebar) !important; }
.bg-primary    { background-color: var(--primary) !important; }

.text-foreground       { color: var(--foreground) !important; }
.text-card-foreground  { color: var(--card-foreground) !important; }
.text-muted-foreground { color: var(--muted-foreground) !important; }
.text-secondary-foreground { color: var(--secondary-foreground) !important; }
.text-primary          { color: var(--primary) !important; }
.text-primary-foreground { color: var(--primary-foreground) !important; }

.border-border  { border-color: var(--border) !important; }
.border-input   { border-color: var(--input) !important; }
.border-ring    { border-color: var(--ring) !important; }

/* --------------------------------------------------------------------------
   4. 顶栏
   -------------------------------------------------------------------------- */
:is(header, [data-slot="header"], .navbar, .app-header, nav[class*="border-b"]) {
  background-color: var(--card) !important;
  border-bottom: 1px solid var(--border) !important;
  box-shadow: none !important;
  color: var(--foreground) !important;
}

/* 顶栏圆形图标按钮 */
:is(header, [data-slot="header"], .navbar) :is(button, a)[class*="rounded-full"] {
  background-color: transparent !important;
  border: 1px solid var(--border) !important;
  color: var(--muted-foreground) !important;
  box-shadow: none !important;
}
:is(header, [data-slot="header"], .navbar) :is(button, a)[class*="rounded-full"]:hover {
  background-color: var(--accent) !important;
  color: var(--foreground) !important;
  border-color: var(--yx-gold-line) !important;
}

/* --------------------------------------------------------------------------
   5. 侧栏
   -------------------------------------------------------------------------- */
:is(aside, [data-slot="sidebar"], [data-sidebar="sidebar"], .sidebar, .app-sidebar) {
  background-color: var(--sidebar) !important;
  border-right: 1px solid var(--border) !important;
  color: var(--sidebar-foreground) !important;
}
:is([data-sidebar="group-label"], [data-sidebar="group"] > [class*="text-xs"],
    .sidebar-group-title) {
  color: var(--muted-foreground) !important;
  letter-spacing: 0.04em;
}
:is([data-sidebar="menu-button"], [data-sidebar="menu-sub-button"],
    [data-slot="sidebar"] a, .sidebar-menu-item) {
  border-radius: 2px !important;
  color: var(--sidebar-foreground) !important;
  box-shadow: none !important;
}
:is([data-sidebar="menu-button"], [data-sidebar="menu-sub-button"],
    [data-slot="sidebar"] a, .sidebar-menu-item):hover {
  background-color: var(--sidebar-accent) !important;
  color: var(--sidebar-accent-foreground) !important;
}
:is([data-sidebar="menu-button"][data-active="true"],
    [data-sidebar="menu-sub-button"][data-active="true"],
    [data-sidebar="menu-button"][data-state="active"],
    [data-slot="sidebar"] a[aria-current="page"],
    aside a[aria-current="page"],
    .sidebar-menu-item.active) {
  background-color: var(--sidebar-accent) !important;
  color: var(--sidebar-accent-foreground) !important;
  box-shadow: inset 2px 0 0 0 var(--primary) !important;
  border-radius: 2px !important;
}

/* --------------------------------------------------------------------------
   6. 按钮
   -------------------------------------------------------------------------- */
:is(button, [role="button"], a[data-slot="button"], .btn) {
  border-radius: 2px !important;
  box-shadow: none !important;
  font-family: var(--yx-font-sans);
  transition: background-color 120ms linear, border-color 120ms linear,
    color 120ms linear;
}
:is(button, [role="button"], a[data-slot="button"])[class*="rounded-full"] {
  border-radius: 9999px !important;
}
:is(button, a, [role="button"])[class*="bg-primary"] {
  background-color: var(--primary) !important;
  color: var(--primary-foreground) !important;
  border: 1px solid var(--primary) !important;
}
:is(button, a, [role="button"])[class*="bg-primary"]:hover {
  background-color: var(--yx-primary-hover) !important;
  border-color: var(--yx-primary-hover) !important;
}
:is(button, a, [role="button"]):is([class*="variant-outline"],
    [class*="bg-transparent"][class*="border"]) {
  background-color: transparent !important;
  border: 1px solid var(--border) !important;
  color: var(--foreground) !important;
}
:is(button, a, [role="button"]):is([class*="variant-outline"],
    [class*="bg-transparent"][class*="border"]):hover {
  background-color: var(--accent) !important;
  border-color: var(--yx-gold-line) !important;
}
:is(button, [role="button"]):disabled,
:is(button, [role="button"])[data-disabled] {
  opacity: 0.45;
  background-color: var(--muted) !important;
  color: var(--muted-foreground) !important;
  border-color: var(--border) !important;
}

/* --------------------------------------------------------------------------
   7. 输入框 / 下拉
   -------------------------------------------------------------------------- */
:is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
    textarea, select, [data-slot="input"], [data-slot="textarea"],
    [data-slot="select-trigger"], [role="combobox"]) {
  background-color: #FFFFFF !important;
  border: 1px solid var(--input) !important;
  border-radius: 2px !important;
  box-shadow: none !important;
  color: var(--foreground) !important;
  font-family: var(--yx-font-sans);
}
:is(input, textarea, select, [data-slot="input"], [data-slot="textarea"],
    [data-slot="select-trigger"], [role="combobox"]):focus,
:is(input, textarea, select, [data-slot="input"], [data-slot="textarea"],
    [data-slot="select-trigger"], [role="combobox"]):focus-visible {
  outline: none !important;
  border-color: var(--ring) !important;
  box-shadow: 0 0 0 3px var(--yx-gold-wash) !important;
}
:is(input, textarea, [data-slot="input"])::placeholder {
  color: var(--yx-placeholder);
}
:is([data-slot="select-content"], [data-slot="dropdown-menu-content"],
    [data-slot="popover-content"], [role="listbox"], [role="menu"]) {
  background-color: #FFFFFF !important;
  border: 1px solid var(--border) !important;
  border-radius: 0 !important;
  color: var(--foreground) !important;
}
:is([role="option"], [data-slot="select-item"], [data-slot="dropdown-menu-item"]):focus,
:is([role="option"], [data-slot="select-item"], [data-slot="dropdown-menu-item"]):hover {
  background-color: var(--accent) !important;
  color: var(--foreground) !important;
}

/* --------------------------------------------------------------------------
   8. 表格
   -------------------------------------------------------------------------- */
:is(table, [data-slot="table"]) {
  border-collapse: collapse !important;
  border-spacing: 0 !important;
  font-variant-numeric: tabular-nums;
}
:is(table, [data-slot="table"]) :is(thead, tbody, tfoot, tr, th, td) {
  border-left: 0 !important;
  border-right: 0 !important;
  border-color: var(--yx-hairline) !important;
}
:is(table, [data-slot="table"]) thead,
:is(table, [data-slot="table"]) thead tr {
  background-color: var(--muted) !important;
}
:is(table, [data-slot="table"]) th {
  background-color: var(--muted) !important;
  color: var(--yx-th-fg) !important;
  border-top: 0 !important;
  border-bottom: 1px solid var(--border) !important;
  font-weight: 500;
}
:is(table, [data-slot="table"]) td {
  border-bottom: 1px solid var(--yx-hairline) !important;
  color: var(--foreground) !important;
  background-color: transparent;
}
:is(table, [data-slot="table"]) tbody tr:hover > td,
:is(table, [data-slot="table"]) tbody tr:hover {
  background-color: var(--yx-row-hover) !important;
}
:is(table, [data-slot="table"]) body tr:last-child > td,
:is(table, [data-slot="table"]) tbody tr:last-child > td {
  border-bottom-color: var(--border) !important;
}

/* --------------------------------------------------------------------------
   9. 卡片 / 弹层 / 徽标 / 进度条
   -------------------------------------------------------------------------- */
:is([data-slot="card"], .card, [data-card], [class*="bg-card"]) {
  background-color: var(--card) !important;
  border: 1px solid var(--border) !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  color: var(--card-foreground) !important;
}
:is([data-slot="dialog-content"], [role="dialog"], [data-slot="sheet-content"],
    [data-slot="alert-dialog-content"]) {
  background-color: var(--card) !important;
  border: 1px solid var(--border) !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}
:is([data-slot="badge"], .badge) {
  border-radius: 0 !important;
  border: 1px solid var(--border) !important;
  font-weight: 500;
}
:is([data-slot="progress"], .progress) {
  background-color: var(--muted) !important;
  border-radius: 0 !important;
  overflow: hidden;
}
:is([data-slot="progress-indicator"], .progress-bar, .progress > div) {
  background-color: var(--primary) !important;
  border-radius: 0 !important;
}
/* 余额卡：金细线，唯一允许金色出现的位置之一 */
:is(.yx-balance-card, [data-card="balance"]) {
  border-color: var(--yx-gold-line) !important;
  background-image: none !important;
}
/* 压平所有渐变 */
:is([class*="bg-gradient"]) {
  background-image: none !important;
}

/* --------------------------------------------------------------------------
   10. 去阴影 / 去图案
   -------------------------------------------------------------------------- */
:is([class*="shadow"], [data-slot="card"], [data-slot="dialog-content"],
    [data-slot="popover-content"], [data-slot="dropdown-menu-content"],
    [data-slot="select-content"], [role="dialog"], [role="menu"]) {
  box-shadow: none !important;
}

/* --------------------------------------------------------------------------
   11. 语义色
   -------------------------------------------------------------------------- */
:is(.text-green-500, .text-green-600, .text-emerald-500, .text-emerald-600) {
  color: var(--yx-success) !important;
}
:is(.text-amber-500, .text-amber-600, .text-yellow-500, .text-yellow-600) {
  color: var(--yx-warning) !important;
}
:is(.text-red-500, .text-red-600, .text-rose-500, .text-rose-600) {
  color: var(--primary) !important;
}

/* --------------------------------------------------------------------------
   12. 兜底：把硬编码的深色背景拉回宣纸（防止组件级深色回来）
   -------------------------------------------------------------------------- */
:is([class*="bg-zinc-9"], [class*="bg-neutral-9"], [class*="bg-stone-9"],
    [class*="bg-slate-9"], [class*="bg-gray-9"], [class*="bg-neutral-8"],
    [class*="bg-stone-8"], [class*="bg-zinc-8"]) {
  background-color: var(--background) !important;
}
:is([class*="bg-zinc-9"], [class*="bg-neutral-9"], [class*="bg-stone-9"],
    [class*="bg-slate-9"], [class*="bg-gray-9"]) :is([class*="text-white"],
    [class*="text-zinc-1"], [class*="text-neutral-1"], [class*="text-stone-1"],
    [class*="text-slate-1"], [class*="text-gray-1"]) {
  color: var(--foreground) !important;
}
:is([class*="bg-zinc-9"], [class*="bg-neutral-9"], [class*="bg-stone-9"])
  :is([class*="border-white"], [class*="border-zinc-7"], [class*="border-neutral-7"]) {
  border-color: var(--border) !important;
}

/* --------------------------------------------------------------------------
   13. 滚动条
   -------------------------------------------------------------------------- */
* {
  scrollbar-width: thin;
  scrollbar-color: #D8CDB9 transparent;
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background-color: #D8CDB9;
  border: 2px solid transparent;
  background-clip: content-box;
  border-radius: 0;
}
::-webkit-scrollbar-thumb:hover { background-color: #C6B99F; }

/* --------------------------------------------------------------------------
   14. 打印
   -------------------------------------------------------------------------- */
@media print {
  html, body { background: #FFFFFF !important; }
  header, aside, [data-sidebar="sidebar"] { display: none !important; }
}
