/* ============ 模型台账 · 双色主题 ============
   白昼：宣纸底 × 朱砂批 × 松烟墨字 —— 日光下可读
   夜览：深墨底 × 琥珀印 × 衬线大标 —— 夜间不刺眼
   两套配色共用同一组语义 token，全本地、零外部依赖。
   分层：app.css（token/布局/导航/控制台）→ tables.css（表格/弹窗）→ views.css（视图/打印） */

/* ---------- 共享骨架 token ---------- */
:root {
  --font-display: "Songti SC", "STSongti-SC", "Noto Serif SC", "Source Han Serif SC", Georgia, "Times New Roman", serif;
  --font-body: "PingFang SC", "Hiragino Sans GB", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, "Courier New", monospace;
  --r: 2px;
  --grid: 32px;
}

/* ---------- 白昼（默认）：宣纸 ---------- */
:root {
  color-scheme: light;
  --bg: #f1ebdd;
  --panel: #faf6ec;
  --panel-2: #ebe2cf;
  --panel-3: #e0d4bb;
  --edge: #b3a487;
  --edge-soft: #cbbfa5;
  --rule: #a8997c;          /* 表格行线：白昼下需能“分出”每一行 */
  --text: #1f1a12;
  --text-2: #3d3527;
  --muted: #5f5643;
  --faint: #6b6152;
  --accent: #ab3520;        /* 朱砂 */
  --accent-hi: #8a2414;     /* 纸面强调文字，对比度优先 */
  --on-accent: #fdf4e3;
  --seal: #a8321e;
  --seal-ink: #f9ecd9;
  --jade: #2f5b40;
  --cinnabar: #a8402a;
  --stripe: rgba(31, 26, 18, .04);
  --stripe-cell: #f1eadb;   /* panel 叠加 stripe 的不透明等价色 */
  --hover-cell: #f7ebe4;    /* 粘性首列 hover 用的不透明等价色，防透出 */
  --hover-veil: rgba(171, 53, 32, .06);
  --rail-hover: rgba(31, 26, 18, .045);
  --tag-border: rgba(171, 53, 32, .55);
  --focus-ring: rgba(171, 53, 32, .16);
  --glow: rgba(171, 53, 32, .11);
  --grid-line: rgba(31, 26, 18, .05);
  --shadow-sm: 0 12px 30px rgba(92, 71, 36, .13);
  --shadow-lg: 0 26px 64px rgba(92, 71, 36, .2);
  --scrim: rgba(58, 46, 26, .38);
  --noise-op: 1;
  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3CfeColorMatrix values='0 0 0 0 0.29 0 0 0 0 0.23 0 0 0 0 0.13 0 0 0 0.07 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- 夜览：墨账 ---------- */
:root[data-theme="night"] {
  color-scheme: dark;
  --bg: #0b0e12;
  --panel: #10141a;
  --panel-2: #161c24;
  --panel-3: #1c232d;
  --edge: #29313d;
  --edge-soft: #1e2530;
  --rule: #2c3543;   /* 夜览行线：需能从深底上分出每一行 */
  --text: #eae4d4;
  --text-2: #c9c3b4;
  --muted: #8d97a6;
  --faint: #6b7686;
  --accent: #e3a13c;
  --accent-hi: #f6c063;
  --on-accent: #221402;
  --seal: #b23a2a;
  --seal-ink: #f6ecdc;
  --jade: #7fae90;
  --cinnabar: #cf6a4e;
  --stripe: rgba(234, 228, 212, .022);
  --stripe-cell: #12161d;
  --hover-cell: #171d26;
  --hover-veil: rgba(227, 161, 60, .05);
  --rail-hover: rgba(234, 228, 212, .03);
  --tag-border: rgba(227, 161, 60, .4);
  --focus-ring: rgba(227, 161, 60, .14);
  --glow: rgba(227, 161, 60, .07);
  --grid-line: rgba(234, 228, 212, .028);
  --shadow-sm: 0 14px 34px rgba(0, 0, 0, .35);
  --shadow-lg: 0 30px 80px rgba(0, 0, 0, .6);
  --scrim: rgba(6, 8, 11, .72);
  --noise-op: .5;
  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.03 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

* { margin: 0; padding: 0; box-sizing: border-box; }
/* 兼容性兜底：flex/grid 容器上的 hidden 属性需强制隐藏 */
[hidden] { display: none !important; }

html { font-size: 15px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
/* 换肤时整体柔和过渡 */
body, .console, .stats, .table-wrap, .ledger th, .ledger td, .rail-item, .tab,
.modal-card, .json, .kv th, .kv td, select, input, .toast, .endpoint code, .theme-switch {
  transition-property: background-color, color, border-color, box-shadow;
  transition-duration: .3s;
  transition-timing-function: ease;
}
/* 层叠氛围：细网格 + 顶部朱砂/琥珀微光 + 纸纤维噪点 */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(1100px 420px at 78% -8%, var(--glow), transparent 62%),
    repeating-linear-gradient(0deg, transparent 0 calc(var(--grid) - 1px), var(--grid-line) calc(var(--grid) - 1px) var(--grid)),
    repeating-linear-gradient(90deg, transparent 0 calc(var(--grid) - 1px), var(--grid-line) calc(var(--grid) - 1px) var(--grid));
}
body::after {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  opacity: var(--noise-op); background-image: var(--noise);
}
.frame { position: relative; z-index: 1; max-width: 1440px; margin: 0 auto; padding: 28px 34px 60px; }

/* ---------- 报头 ---------- */
.masthead {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding-bottom: 20px; border-bottom: 2px solid var(--text);
  position: relative; animation: dropIn .55s cubic-bezier(.2, .8, .2, 1) both;
}
.masthead::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -6px;
  height: 1px; background: var(--edge);
}
.brand { display: flex; align-items: center; gap: 16px; }
.seal {
  writing-mode: vertical-rl; font-family: var(--font-display);
  background: var(--seal); color: var(--seal-ink); font-size: 15px; letter-spacing: 4px;
  padding: 8px 5px; border-radius: 3px; transform: rotate(-2deg);
  box-shadow: 0 2px 10px var(--glow), inset 0 0 0 1px rgba(246, 236, 220, .35);
  user-select: none;
}
.brand-text h1 {
  font-family: var(--font-display); font-size: 34px; font-weight: 700;
  letter-spacing: 10px; line-height: 1;
}
.brand-en {
  display: block; margin-top: 7px; font-family: var(--font-mono);
  font-size: 10px; letter-spacing: 3.5px; color: var(--muted);
}
.masthead-meta { display: flex; align-items: center; gap: 14px; font-family: var(--font-mono); font-size: 12px; color: var(--muted); padding-bottom: 4px; flex-wrap: wrap; }
.meta-item b { color: var(--accent); font-weight: 600; }
.meta-item { white-space: nowrap; }
.meta-sep { width: 1px; height: 14px; background: var(--edge); }

/* 昼夜切换 */
.theme-switch {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--edge); border-radius: 999px;
  padding: 5px 11px 5px 7px; color: var(--muted);
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 1.5px;
}
.theme-switch:hover { color: var(--accent); border-color: var(--accent); }
.ts-track {
  width: 30px; height: 14px; border-radius: 999px; position: relative;
  background: var(--panel-3); box-shadow: inset 0 0 0 1px var(--edge-soft);
}
.ts-knob {
  position: absolute; top: 2px; left: 2px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--glow);
  transition: transform .3s cubic-bezier(.2, .8, .2, 1), box-shadow .3s;
}
/* 纯 CSS 日/月：白昼为满盈的日，夜览缺一侧成月牙（不依赖字形） */
:root[data-theme="night"] .ts-knob {
  transform: translateX(16px); background: transparent;
  box-shadow: inset -3.5px 1.5px 0 0 var(--accent);
}
.ts-label { min-width: 34px; text-align: left; white-space: nowrap; }
.theme-switch .ts-track { flex: none; }

/* ---------- 布局 ---------- */
.shell { display: grid; grid-template-columns: 190px 1fr; gap: 34px; margin-top: 30px; }
/* min-width:0 使宽表在 .table-wrap 内部横向滚动，否则整页被撑开、粘性首列失效 */
.shell > .stage { min-width: 0; }

.rail { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 24px; align-self: start; }
.rail-item {
  display: flex; align-items: baseline; gap: 10px; text-align: left;
  background: none; border: none; cursor: pointer; color: var(--muted);
  font-family: var(--font-body); font-size: 15px; padding: 11px 12px 11px 14px;
  border-left: 2px solid var(--edge-soft); position: relative;
  transition: color .2s, border-color .2s, background .2s;
}
.rail-item i { font-style: normal; font-family: var(--font-mono); font-size: 10px; letter-spacing: 1px; color: var(--faint); transition: color .2s; }
.rail-item:hover { color: var(--text); background: var(--rail-hover); }
.rail-item.active { color: var(--text); border-left-color: var(--accent); background: linear-gradient(90deg, var(--hover-veil), transparent 70%); }
.rail-item.active i { color: var(--accent); }
.rail-foot { margin-top: 34px; padding-left: 16px; font-family: var(--font-mono); font-size: 10px; letter-spacing: 1px; color: var(--faint); line-height: 1.7; }
.rail-foot span { color: var(--muted); }
/* 导航栏底部：MySQL 同步区块与状态灯 */
.mysql-box { margin-top: 12px; }
.mysql-state::before {
  content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--faint); margin-right: 5px; vertical-align: 1px;
  transition: background-color .3s;
}
.mysql-state.ok::before { background: var(--jade); }
.mysql-box .btn-mini { margin-top: 4px; letter-spacing: 2px; }

/* ---------- 视图 ---------- */
.view { display: none; }
.view.active { display: block; animation: riseIn .4s cubic-bezier(.2, .8, .2, 1) both; }
.view-head { display: flex; align-items: baseline; gap: 18px; flex-wrap: wrap; margin-bottom: 22px; }
.view-head h2 { font-family: var(--font-display); font-size: 25px; letter-spacing: 5px; font-weight: 700; }
.view-head h2 i { font-style: normal; font-family: var(--font-mono); font-size: 11px; color: var(--accent); letter-spacing: 2px; margin-right: 10px; vertical-align: 3px; }
.view-head p { color: var(--muted); font-size: 13px; flex: 1; min-width: 220px; }

/* ---------- 控制台 ---------- */
.console {
  background: var(--panel); border: 1px solid var(--edge-soft);
  border-top: 1px solid var(--edge); padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.console-row { display: flex; align-items: flex-end; gap: 18px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span, .endpoint-label {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 2px; color: var(--faint);
}
select, input[type="search"], input[type="text"], input[type="password"] {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--edge);
  font-family: var(--font-mono); font-size: 13px; padding: 9px 12px; border-radius: var(--r);
  outline: none; transition: border-color .2s, box-shadow .2s;
}
select:focus, input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
select { cursor: pointer; }
::placeholder { color: var(--faint); opacity: 1; }
.endpoint { flex: 1; min-width: 260px; display: flex; flex-direction: column; gap: 6px; }
.endpoint code {
  font-family: var(--font-mono); font-size: 12px; color: var(--accent-hi);
  background: var(--panel-3); border: 1px dashed var(--edge); padding: 9px 12px;
  display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: var(--r);
}
.console-actions { display: flex; gap: 10px; margin-left: auto; }

/* 按钮 */
.btn {
  font-family: var(--font-mono); font-size: 12px; letter-spacing: 1.5px;
  color: var(--text); background: transparent; border: 1px solid var(--edge);
  padding: 10px 18px; cursor: pointer; border-radius: var(--r); position: relative;
  transition: border-color .2s, color .2s, background .2s, transform .12s;
}
.btn:hover { border-color: var(--accent); color: var(--accent-hi); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.btn-primary:hover { background: var(--accent-hi); border-color: var(--accent-hi); color: var(--on-accent); }
.btn-danger:hover { border-color: var(--cinnabar); color: var(--cinnabar); }
.btn-mini { padding: 5px 12px; font-size: 11px; }

/* 进度 */
.progress { display: flex; align-items: center; gap: 14px; margin-top: 16px; }
.progress[hidden] { display: none; }
.progress-track { flex: 1; height: 3px; background: var(--panel-3); overflow: hidden; }
.progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-hi)); transition: width .35s ease; }
.progress-text { font-family: var(--font-mono); font-size: 11px; color: var(--accent-hi); letter-spacing: 1px; min-width: 130px; text-align: right; }

/* ---------- 响应式（布局侧：框架 / 导航） ---------- */
@media (max-width: 900px) {
  .frame { padding: 18px 16px 40px; }
  .shell { grid-template-columns: 1fr; gap: 18px; }
  .rail { flex-direction: row; position: static; }
  .rail-item { border-left: none; border-bottom: 2px solid var(--edge-soft); }
  .rail-item.active { border-bottom-color: var(--accent); }
  .rail-foot { display: none; }
  .brand-text h1 { font-size: 26px; letter-spacing: 6px; }
}
