:root {
  --bg: #f7f8fa;
  --card: #ffffff;
  --fg: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-fg: #ffffff;
  --primary-weak: #eff6ff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.6;
}
a { color: inherit; text-decoration: none; }
.container { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--muted); }
h1, h2, h3 { line-height: 1.25; }

/* Header / nav */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.nav { display: flex; align-items: center; gap: 20px; height: 60px; }
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.nav-links { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav-links a { padding: 6px 10px; border-radius: 8px; color: var(--muted); font-size: 14px; }
.nav-links a:hover { background: var(--primary-weak); color: var(--primary); }
.nav-user { display: flex; align-items: center; gap: 8px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid transparent;
  font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 22px; font-size: 15px; }
.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-primary:hover { background: #1d4ed8; }
.btn-outline { background: #fff; border-color: var(--border); color: var(--fg); }
.btn-outline:hover { background: #f1f5f9; }
.btn-ghost { background: transparent; color: var(--fg); }
.btn-ghost:hover { background: #f1f5f9; }
.btn-danger { background: #fef2f2; color: #dc2626; border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card-head { padding: 18px 20px; border-bottom: 1px solid var(--border); font-weight: 600; }

/* Grid */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 620px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* Hero */
.hero { background: linear-gradient(180deg, #eef2ff, var(--bg)); border-bottom: 1px solid var(--border); }
.hero-inner { padding: 72px 0; }
.hero h1 { font-size: 40px; margin: 12px 0; }
.hero p { font-size: 18px; color: var(--muted); max-width: 640px; }
.hero-actions { display: flex; gap: 12px; margin-top: 22px; flex-wrap: wrap; }

/* Sections */
.section { padding: 56px 0; }
.section h2 { font-size: 24px; margin: 0 0 24px; }

/* Product card */
.pcard { display: flex; flex-direction: column; padding: 20px; }
.pcard h3 { margin: 6px 0; font-size: 17px; }
.spec { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 3px 0; }
.spec .k { color: var(--muted); }
.pcard-foot { margin-top: auto; padding-top: 14px; display: flex; align-items: flex-end; justify-content: space-between; }
.price { font-size: 26px; font-weight: 700; }
.price small { font-size: 13px; font-weight: 400; color: var(--muted); }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-blue { background: var(--primary-weak); color: var(--primary); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; }
tbody tr:hover { background: #fafbfc; }
.right { text-align: right; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

/* Forms */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px;
  font: inherit; background: #fff; color: var(--fg);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; padding: 10px 12px; border-radius: 9px; margin-bottom: 14px; font-size: 14px; }
.flash { background: var(--primary-weak); color: var(--primary); border: 1px solid #bfdbfe; padding: 10px 14px; border-radius: 9px; margin: 16px 0; font-size: 14px; }

.auth-wrap { max-width: 420px; margin: 48px auto; }

/* Features */
.feature .emoji { font-size: 26px; }
.feature h4 { margin: 8px 0 4px; }

/* Footer */
.site-footer { margin-top: 64px; border-top: 1px solid var(--border); background: #fff; }
.foot-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 28px; padding: 40px 0; }
.foot-grid a { display: block; color: var(--muted); font-size: 14px; padding: 2px 0; }
.foot-grid a:hover { color: var(--primary); }
.foot-title { font-weight: 600; margin-bottom: 8px; }
.foot-copy { text-align: center; padding: 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; }
@media (max-width: 720px) { .foot-grid { grid-template-columns: 1fr 1fr; } }

/* Configurator */
.cfg { display: grid; grid-template-columns: 1fr 380px; gap: 28px; align-items: start; }
@media (max-width: 900px) { .cfg { grid-template-columns: 1fr; } .cfg-panel { position: static; } }
.cfg-panel { position: sticky; top: 76px; }
.summary { font-size: 14px; }
.summary .row { display: flex; justify-content: space-between; padding: 3px 0; }
.summary .total { font-size: 24px; font-weight: 700; }
.summary hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }

/* Admin */
.admin-body { display: flex; min-height: 100vh; }
.admin-side { width: 232px; flex-shrink: 0; background: #fff; border-right: 1px solid var(--border); padding: 18px 14px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.admin-side .brand { padding: 0 8px 16px; }
.admin-nav { display: flex; flex-direction: column; gap: 2px; }
.admin-nav a { display: flex; align-items: center; gap: 9px; padding: 9px 12px; border-radius: 9px; color: var(--muted); font-size: 14px; font-weight: 500; }
.admin-nav a:hover { background: #f1f5f9; color: var(--fg); }
.admin-nav a.active { background: var(--primary); color: #fff; }
.admin-nav .emoji { width: 18px; text-align: center; }
.admin-side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding-top: 16px; }
.admin-main { flex: 1; padding: 28px 32px; max-width: 1000px; }
.admin-main h1 { margin-top: 0; }
.stat { padding: 18px 20px; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .num { font-size: 30px; font-weight: 700; margin-top: 4px; }
@media (max-width: 760px) {
  .admin-body { flex-direction: column; }
  .admin-side { width: 100%; height: auto; position: sticky; top: 0; z-index: 30; flex-direction: column; padding: 10px 12px; }
  .admin-side .brand { padding: 2px 4px 8px; font-size: 16px; }
  .admin-nav { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; gap: 4px; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
  .admin-nav::-webkit-scrollbar { height: 0; }
  .admin-nav a { flex-shrink: 0; white-space: nowrap; padding: 8px 12px; }
  .admin-side-foot { margin-top: 8px; padding-top: 8px; flex-direction: row; flex-wrap: wrap; gap: 8px; }
  .admin-side-foot .muted { width: 100%; }
}

/* Dialog (details/summary based) */
details.dlg > summary { list-style: none; cursor: pointer; display: inline-block; }
details.dlg > summary::-webkit-details-marker { display: none; }
details.dlg[open] > .dlg-body { display: block; }
.dlg-body { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.dlg-card { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.dlg-card h3 { margin: 0 0 4px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.stack { display: flex; flex-direction: column; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tag { display:inline-flex; align-items:center; gap:6px; font-size:13px; color:var(--muted); }
.mb-0 { margin-bottom: 0; }
.mt-2 { margin-top: 8px; }
.section-title { display:flex; align-items:center; gap:10px; margin: 24px 0 12px; }

/* ============ 后台规范化组件 ============ */
/* 页头：标题 + 副标题 + 右侧操作 */
.page-head { display:flex; align-items:flex-start; justify-content:space-between; gap:16px; flex-wrap:wrap; margin: 0 0 22px; }
.page-head h1 { margin:0; font-size:24px; }
.page-head .sub { color:var(--muted); font-size:14px; margin:4px 0 0; }
.page-head-actions { display:flex; gap:8px; flex-wrap:wrap; }

/* KPI 统计卡 */
.kpi-grid { display:grid; gap:16px; grid-template-columns:repeat(4,1fr); margin-bottom:24px; }
@media (max-width:900px){ .kpi-grid { grid-template-columns:repeat(2,1fr); } }
@media (max-width:520px){ .kpi-grid { grid-template-columns:1fr; } }
.kpi { background:var(--card); border:1px solid var(--border); border-radius:var(--radius); box-shadow:var(--shadow); padding:16px 18px; display:block; }
.kpi .label { font-size:12px; color:var(--muted); text-transform:uppercase; letter-spacing:.03em; display:flex; align-items:center; gap:6px; }
.kpi .num { font-size:28px; font-weight:700; margin-top:6px; line-height:1.1; }
.kpi .foot { font-size:12px; color:var(--muted); margin-top:4px; }
.kpi.accent { border-color:#bfdbfe; }
.kpi.accent .num { color:var(--primary); }
.kpi.rev .num { color:#166534; }
.kpi.warn .num { color:#b45309; }

/* 卡片带表头（区块） */
.panel { background:var(--card); border:1px solid var(--border); border-radius:var(--radius); box-shadow:var(--shadow); margin-bottom:22px; overflow:hidden; }
.panel > .panel-head { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:14px 18px; border-bottom:1px solid var(--border); font-weight:600; }
.panel > .panel-head .muted { font-weight:400; }
.panel > .table-wrap { border:none; box-shadow:none; }
.panel > table { margin:0; }

/* 工具条 / 过滤标签 */
.toolbar { display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap; margin-bottom:16px; }
.seg { display:inline-flex; gap:2px; background:#f1f5f9; border:1px solid var(--border); border-radius:10px; padding:3px; }
.seg a { padding:6px 14px; border-radius:8px; font-size:13px; font-weight:500; color:var(--muted); }
.seg a:hover { color:var(--fg); }
.seg a.active { background:#fff; color:var(--primary); box-shadow:var(--shadow); }
.seg a .cnt { font-size:11px; opacity:.7; margin-left:4px; }

/* 定义列表（键值明细） */
.dl { display:grid; grid-template-columns:auto 1fr; gap:8px 18px; font-size:14px; }
.dl dt { color:var(--muted); }
.dl dd { margin:0; text-align:right; }
@media (max-width:520px){ .dl { grid-template-columns:1fr; gap:2px 0; } .dl dd { text-align:left; margin-bottom:8px; } }

/* 金额强调 */
.money { font-variant-numeric:tabular-nums; font-weight:600; }
.money-pos { color:#166534; }
.money-muted { color:var(--muted); }

/* 空状态 */
.empty { text-align:center; color:var(--muted); padding:40px 20px; }
.empty .ico { font-size:34px; display:block; margin-bottom:8px; opacity:.6; }

/* 到期提示 */
.due-soon { color:#b45309; font-weight:600; }
.due-over { color:#dc2626; font-weight:600; }

/* 后台正文加宽以容纳财务表格 */
.admin-main.wide { max-width:1180px; }

/* 可折叠分类卡（产品页） */
details.cat-fold { background:var(--card); border:1px solid var(--border); border-radius:var(--radius); box-shadow:var(--shadow); margin-bottom:14px; }
details.cat-fold > summary { list-style:none; cursor:pointer; display:flex; align-items:center; gap:10px; padding:14px 18px; font-weight:600; user-select:none; border-radius:var(--radius); }
details.cat-fold > summary::-webkit-details-marker { display:none; }
details.cat-fold > summary:hover { background:#fafbfc; }
.cat-fold .cat-name { font-size:16px; }
.cat-fold .fold-caret { margin-left:auto; transition:transform .2s; color:var(--muted); font-size:13px; }
details.cat-fold[open] > summary { border-bottom:1px solid var(--border); border-radius:var(--radius) var(--radius) 0 0; }
details.cat-fold[open] > summary .fold-caret { transform:rotate(90deg); }
.cat-body .cat-toolbar { display:flex; align-items:center; justify-content:space-between; gap:10px; padding:12px 16px; border-bottom:1px solid var(--border); }
.cat-body > .table-wrap { border:0; box-shadow:none; }
.cat-body .empty { padding:26px 16px; }

/* ============ 移动端适配（安卓 Chrome / iOS Safari）============ */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: rgba(0,0,0,.06); }
img, svg, video { max-width: 100%; height: auto; }

/* 顶部导航：桌面默认（汉堡隐藏，菜单平铺） */
.nav-toggle-cb { display: none; }
.nav-toggle { display: none; }
.nav-menu { display: flex; flex: 1; align-items: center; gap: 20px; min-width: 0; }

@media (max-width: 760px) {
  /* --- 汉堡菜单 --- */
  .nav { position: relative; height: 56px; gap: 10px; }
  .nav-toggle { display: flex; flex-direction: column; justify-content: center; gap: 5px;
    width: 44px; height: 44px; margin-left: auto; cursor: pointer; border-radius: 9px; }
  .nav-toggle:active { background: #f1f5f9; }
  .nav-toggle span { display: block; width: 22px; height: 2px; background: var(--fg); border-radius: 2px; transition: transform .2s, opacity .2s; }
  .nav-menu { display: none; position: absolute; left: 0; right: 0; top: 100%;
    flex-direction: column; align-items: stretch; gap: 0; background: #fff;
    border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow); padding: 8px; max-height: calc(100dvh - 56px); overflow-y: auto; }
  .nav-toggle-cb:checked ~ .nav-menu { display: flex; }
  .nav-links { flex-direction: column; align-items: stretch; gap: 2px; flex: none; }
  .nav-links a { padding: 12px; font-size: 15px; border-radius: 9px; }
  .nav-user { flex-direction: column; align-items: stretch; gap: 8px; margin-top: 6px; padding-top: 10px; border-top: 1px solid var(--border); }
  .nav-user .btn { width: 100%; justify-content: center; padding: 11px 16px; font-size: 14px; }
  .nav-toggle-cb:checked ~ .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .nav-toggle-cb:checked ~ .nav-toggle span:nth-child(2) { opacity: 0; }
  .nav-toggle-cb:checked ~ .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  /* --- Hero / 区块 --- */
  .hero-inner { padding: 44px 0; }
  .hero h1 { font-size: 28px; }
  .hero p { font-size: 16px; }
  .section { padding: 36px 0; }
  .section h2 { font-size: 20px; margin-bottom: 18px; }

  /* --- 后台正文 --- */
  .admin-main, .admin-main.wide { padding: 18px 16px; max-width: 100%; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head h1 { font-size: 21px; }
  .page-head-actions { flex-wrap: nowrap; }
  .page-head-actions .btn { flex: 1; justify-content: center; }

  /* --- iOS 聚焦不放大：表单控件字号 ≥16px；触摸目标略增大 --- */
  input[type=text], input[type=email], input[type=password], input[type=number], select, textarea { font-size: 16px; }
  .btn-sm { padding: 8px 13px; }

  /* --- 对话框贴合小屏 --- */
  .dlg-body { padding: 16px 10px; }
  .dlg-card { padding: 18px; }

  /* --- 安全区（刘海/底部横条）--- */
  .foot-copy { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
}

@media (max-width: 560px) {
  .hero-actions { flex-direction: column; }
  .hero-actions .btn { width: 100%; }
  .container { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .kpi .num { font-size: 24px; }
}

@media (max-width: 400px) {
  .hero h1 { font-size: 24px; }
  .brand { font-size: 15px; }
}
