/* =========================================================================
   CMS — Apple OS 风格主题
   · 颜色/圆角/字号/间距均由「主题令牌」驱动（设置 → 外观 可改，即时生效）
   · 支持浅色/深色、毛玻璃、克制动效、无障碍焦点、响应式、打印
   ========================================================================= */

:root {
  --primary: #0A84FF;
  --accent: #5E5CE6;
  --bg: #F5F5F7;
  --surface: #FFFFFF;
  --text: #1D1D1F;
  --text-muted: #6E6E73;
  --border: #E5E5EA;
  --radius: 12px;
  --font-scale: 1;
  --spacing: 1;
  --mode: light;

  /* 派生令牌（引用主题令牌，随其变化） */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .05), 0 1px 3px rgba(0, 0, 0, .04);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, .04), 0 10px 28px rgba(0, 0, 0, .07);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, .18);
  --ring: color-mix(in srgb, var(--primary) 38%, transparent);
  --tint: color-mix(in srgb, var(--primary) 9%, transparent);
  --tint-strong: color-mix(in srgb, var(--primary) 16%, transparent);
  --hairline: color-mix(in srgb, var(--text) 9%, transparent);
  --glass: color-mix(in srgb, var(--surface) 72%, transparent);
  --glass-strong: color-mix(in srgb, var(--surface) 88%, transparent);
}

html { color-scheme: light; }
html.dark { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: calc(14px * var(--font-scale));
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: none; }
::selection { background: color-mix(in srgb, var(--primary) 26%, transparent); }

/* 细滚动条 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--text) 18%, transparent);
  border-radius: 999px; border: 2px solid transparent; background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--text) 30%, transparent); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* 无障碍焦点 */
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: 6px; }

/* ========================= 布局 ========================= */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 218px; flex-shrink: 0;
  padding: 16px 12px 12px;
  position: sticky; top: 0; height: 100vh;
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 16px; }
.logo {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 30px; padding: 0 7px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--primary) 88%, #fff), var(--primary) 60%, var(--accent));
  color: #fff; font-weight: 700; font-size: 12.5px; letter-spacing: .02em;
  border-radius: 9px;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 35%, transparent), inset 0 1px 0 rgba(255,255,255,.35);
}
.brand-name { font-weight: 650; letter-spacing: -.01em; }

/* 品牌 LOGO：侧栏 / 登录页 / 设置预览 */
.brand-logo {
  display: block; max-height: 28px; max-width: 132px;
  object-fit: contain; flex: none;
}
.brand-logo.lg { max-height: 40px; max-width: 200px; }
.brand .brand-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.login-brand { justify-content: center; flex-wrap: wrap; row-gap: 8px; text-align: center; }

/* 设置-品牌 预览框 */
.logo-box {
  display: flex; align-items: center; justify-content: center;
  min-height: 92px; padding: 14px;
  border: 1px dashed var(--border); border-radius: var(--radius-2, 12px);
  background: color-mix(in srgb, var(--surface) 82%, var(--bg));
}
.logo-box img { max-height: 64px; max-width: 100%; object-fit: contain; }


.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item {
  position: relative;
  padding: 8px 11px; border-radius: 10px;
  color: var(--text); font-size: 13.5px; font-weight: 500;
  transition: background .16s ease, color .16s ease;
}
.nav-item:hover { background: var(--tint); }
.nav-item.active {
  background: var(--tint-strong);
  color: var(--primary);
  font-weight: 650;
}
.nav-item.active::before {
  content: ""; position: absolute; left: 3px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 16px; border-radius: 3px; background: var(--primary);
}

.side-foot {
  margin-top: 8px; padding: 10px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 9px;
}
.side-foot .avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
  background: linear-gradient(150deg, var(--primary), var(--accent));
}
.side-foot .who { min-width: 0; }
.user-mini { font-weight: 650; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-mini { color: var(--text-muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 54px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; gap: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  position: sticky; top: 0; z-index: 8;
}
.crumb { font-weight: 650; font-size: 15px; letter-spacing: -.01em; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.top-user { display: none; font-size: 13px; color: var(--text-muted); }

.content { padding: 20px 22px 48px; max-width: 1680px; width: 100%; }

/* ========================= 深色模式 ========================= */
html.dark {
  --bg: #1c1c1e;
  --surface: #2c2c2e;
  --text: #f5f5f7;
  --text-muted: #98989d;
  --border: #3a3a3c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, .45), 0 16px 40px rgba(0, 0, 0, .5);
  --shadow-lg: 0 28px 72px rgba(0, 0, 0, .7);
  --glass: color-mix(in srgb, var(--surface) 66%, transparent);
}

/* ========================= 卡片 ========================= */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: calc(14px * var(--spacing));
  box-shadow: var(--shadow-sm);
}
.card-h {
  font-weight: 650; margin: 0 0 10px; letter-spacing: -.01em;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}

.grid { display: grid; gap: calc(14px * var(--spacing)); }
.stats { grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); }
.stat {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 16px;
  box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: color-mix(in srgb, var(--primary) 28%, var(--border)); }
.stat::after {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  opacity: .8;
}
.stat .n { font-size: 27px; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }

/* ========================= 按钮 ========================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; min-height: 34px;
  border-radius: calc(var(--radius) * .78);
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font-size: 13.5px; font-weight: 550; font-family: inherit;
  cursor: pointer; user-select: none;
  transition: transform .12s ease, background .18s ease, box-shadow .18s ease, border-color .18s ease;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .03);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); border-color: color-mix(in srgb, var(--text) 16%, var(--border)); }
.btn:active { transform: translateY(0) scale(.985); box-shadow: none; }
.btn[disabled], .btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

.btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--primary) 88%, #fff), var(--primary));
  color: #fff; border-color: transparent;
  box-shadow: 0 1px 2px color-mix(in srgb, var(--primary) 40%, transparent), 0 6px 16px color-mix(in srgb, var(--primary) 26%, transparent);
}
.btn.primary:hover { filter: brightness(1.04); box-shadow: 0 2px 4px color-mix(in srgb, var(--primary) 40%, transparent), 0 10px 24px color-mix(in srgb, var(--primary) 30%, transparent); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--tint); border-color: transparent; box-shadow: none; }
.btn.danger {
  background: linear-gradient(180deg, #ff5b52, #ff3b30);
  color: #fff; border-color: transparent;
  box-shadow: 0 1px 2px #ff3b3040, 0 6px 16px #ff3b3026;
}
.btn.danger:hover { filter: brightness(1.04); }
.btn.sm { padding: 4px 10px; min-height: 28px; font-size: 12.5px; border-radius: calc(var(--radius) * .62); }

.icon-btn {
  width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: calc(var(--radius) * .78);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; font-size: 16px; line-height: 1;
  transition: background .16s ease, transform .12s ease, border-color .16s ease;
}
.icon-btn:hover { background: var(--tint); border-color: color-mix(in srgb, var(--primary) 30%, var(--border)); transform: translateY(-1px); }
.icon-btn:active { transform: translateY(0) scale(.96); }

/* ========================= 表格 ========================= */
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
.table thead th {
  position: sticky; top: 0; z-index: 2;
  color: var(--text-muted); font-weight: 650; font-size: 11.5px;
  letter-spacing: .02em; text-transform: none; white-space: nowrap;
  background: var(--glass-strong);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.table tbody tr { transition: background .14s ease; }
.table tbody tr:nth-child(even) { background: color-mix(in srgb, var(--text) 2%, transparent); }
.table tbody tr:hover { background: var(--tint); }
.table tbody tr:last-child td { border-bottom: none; }
.table td .btn + .btn { margin-left: 4px; }

.muted { color: var(--text-muted); }

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1.5px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--tint-strong); color: var(--primary);
}
.tag.gray { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text-muted); }
.tag.green { background: #34c75922; color: #1f9e3e; }
.tag.red { background: #ff3b3022; color: #d23b30; }
.tag.orange { background: #ff9f0a22; color: #b97700; }
.tag.blue { background: var(--tint-strong); color: var(--primary); }
html.dark .tag.green { color: #4ade80; }
html.dark .tag.red { color: #ff6961; }
html.dark .tag.orange { color: #ffb340; }

img.thumb {
  max-height: 40px; border-radius: 8px; border: 1px solid var(--border);
  vertical-align: middle; object-fit: cover; background: var(--bg);
}

/* ========================= 表单 ========================= */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; letter-spacing: .01em; }

.input, select, textarea {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * .78);
  background: var(--surface); color: var(--text);
  font-size: 13.5px; font-family: inherit;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
  appearance: none;
}
.input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--text-muted) 80%, transparent); }
.input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--text) 18%, var(--border)); }
.input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3.5px var(--ring);
  background: var(--surface);
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
                    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
textarea { min-height: 120px; resize: vertical; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; line-height: 1.6; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); width: 15px; height: 15px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }

/* 明细行内联操作 */
.link { background: none; border: none; padding: 2px 4px; cursor: pointer; font-size: 12.5px; font-weight: 600;
  color: var(--primary); border-radius: 6px; }
.link:hover { background: var(--tint); }
.link.danger { color: #d23b30; }
.link.danger:hover { background: #ff3b3014; }
.row-actions { white-space: nowrap; display: flex; gap: 2px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.grid2 .field { margin-bottom: 0; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

/* ========================= 选项卡 ========================= */
.tabs {
  display: flex; gap: 2px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border); margin-bottom: 14px;
}
.tab {
  position: relative; padding: 8px 14px; cursor: pointer;
  color: var(--text-muted); font-size: 13.5px; font-weight: 550;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  border-radius: 8px 8px 0 0;
  transition: color .16s ease, background .16s ease;
}
.tab:hover { color: var(--text); background: var(--tint); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 650; }
.tabpane { display: none; } .tabpane.active { display: block; animation: fade-in .18s ease; }

/* ========================= 模态 ========================= */
.modal-mask {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: color-mix(in srgb, #000 32%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade-in .16s ease;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 1.35);
  width: min(720px, 94vw); max-height: 88vh; overflow: auto;
  padding: 20px; box-shadow: var(--shadow-lg);
  animation: pop-in .24s cubic-bezier(.22, 1, .36, 1);
}
.modal h3 { margin: 0 0 14px; font-size: 17px; letter-spacing: -.01em; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ========================= 模板可视化设计器 ========================= */
.modal.xl { width: min(1180px, 96vw); max-height: 92vh; padding: 0; display: flex; }
.designer { display: flex; width: 100%; min-height: 0; }
.designer .dl { flex: 0 0 44%; max-width: 460px; padding: 20px; overflow: auto; border-right: 1px solid var(--border); }
.designer .dl h3 { margin-bottom: 14px; }
.designer .dr { flex: 1; min-width: 0; display: flex; flex-direction: column; background: color-mix(in srgb, var(--text) 4%, var(--bg)); }
.designer .dr-bar { padding: 10px 14px; font-size: 12.5px; font-weight: 600; color: var(--text-muted);
  border-bottom: 1px solid var(--border); background: var(--surface); }
.designer .prev { flex: 1; width: 100%; border: 0; background: transparent; }

/* 明细列清单 */
.collist { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.colrow { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--line, var(--border)); }
.colrow:last-child { border-bottom: 0; }
.colrow .colname { flex: 1; font-size: 13px; }
.colrow .colbtns { display: flex; gap: 4px; }
.mini { border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
  width: 24px; height: 24px; border-radius: 7px; cursor: pointer; font-size: 13px; line-height: 1; }
.mini:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.mini:disabled { opacity: .35; cursor: default; }

/* 开关/复选行 */
.sw { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.swrap { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 4px 0; }

/* ========================= Toast ========================= */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translate(-50%, 8px);
  background: color-mix(in srgb, #1d1d1f 92%, transparent);
  color: #fff; padding: 10px 18px; border-radius: 12px;
  font-size: 13.5px; font-weight: 500;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .28);
  opacity: 0; pointer-events: none; z-index: 99;
  transition: opacity .24s ease, transform .24s cubic-bezier(.22, 1, .36, 1);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  max-width: min(560px, 90vw); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ========================= 键值信息 ========================= */
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; }

/* ========================= 工具类 ========================= */
.flex { display: flex; } .between { justify-content: space-between; } .center { align-items: center; }
.gap8 { gap: 8px; } .mt12 { margin-top: 12px; } .mb8 { margin-bottom: 8px; }
.right { text-align: right; } .hide { display: none; }

/* ========================= 登录页 ========================= */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px; position: relative; overflow: hidden;
  background:
    radial-gradient(1100px 520px at 12% -10%, color-mix(in srgb, var(--primary) 22%, transparent), transparent 62%),
    radial-gradient(900px 480px at 108% 12%, color-mix(in srgb, var(--accent) 20%, transparent), transparent 58%),
    var(--bg);
}
.login-card {
  width: min(360px, 94vw); padding: 26px 24px; margin: 0;
  border-radius: calc(var(--radius) * 1.3);
  box-shadow: var(--shadow-md);
  backdrop-filter: saturate(160%) blur(8px); -webkit-backdrop-filter: saturate(160%) blur(8px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}
.login-card .brand { justify-content: center; padding-bottom: 18px; }
.login-card .brand-name { font-size: 16px; }
.login-card .btn.primary { width: 100%; min-height: 38px; margin-top: 4px; }
.login-foot { text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 14px; }

/* ========================= 动效 ========================= */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }

/* ========================= 响应式 ========================= */
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar {
    position: sticky; top: 0; width: auto; height: auto; flex-direction: row; align-items: center;
    padding: 9px 12px; gap: 10px; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border);
  }
  .brand { padding: 0 6px 0 0; flex-shrink: 0; }
  .brand-name { display: none; }
  .nav { flex-direction: row; flex: 1; gap: 2px; overflow-x: auto; overflow-y: hidden; }
  .nav-item { white-space: nowrap; }
  .nav-item.active::before { display: none; }
  .side-foot { display: none; }
  .topbar { position: static; }
  .top-user { display: inline; }
  .content { padding: 16px 14px 40px; }
  .card { padding: 14px; }
  .kv { grid-template-columns: 96px 1fr; }
}

@media (max-width: 560px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .modal { padding: 16px; }
  .toolbar .input { max-width: none !important; }
}

/* ========================= 打印 ========================= */
@media print {
  .sidebar, .topbar, .toolbar, .tabs, .modal-mask, .toast, .btn, .icon-btn { display: none !important; }
  body { background: #fff; color: #000; font-size: 12px; }
  .app { display: block; }
  .content { padding: 0; max-width: none; }
  .card { border: 1px solid #ddd; box-shadow: none; break-inside: avoid; margin-bottom: 10px; }
  .table th { position: static; background: #f3f3f3; color: #000; }
  .table tbody tr:nth-child(even) { background: #fafafa; }
  a { color: #000; text-decoration: none; }
}

/* ========================= 无障碍：减少动效 ========================= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
