:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #e6eaf2;
  --text: #1b2333;
  --muted: #6b7690;
  --brand: #2563eb;
  --brand-soft: #eaf0ff;
  --up: #d92b2b;
  --down: #16a34a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 32, 60, .05), 0 8px 24px rgba(20, 32, 60, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font-family: inherit; font-size: 14px; color: var(--text); }
.wrap { max-width: 1360px; margin: 0 auto; padding: 20px 22px 60px; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 6px 2px 18px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 19px; box-shadow: 0 6px 14px rgba(37, 99, 235, .28);
  overflow: hidden;
}
.logo img { width: 26px; height: 26px; object-fit: contain; display: block; }
.brand h1 { font-size: 17px; margin: 0; letter-spacing: .2px; }
.brand p { margin: 1px 0 0; font-size: 12px; color: var(--muted); }
.topbar .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- 通用控件 ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 10px;
  padding: 7px 14px; cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: #c9d4e8; background: #fbfcff; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #1d4fd7; }
.btn.ghost { background: transparent; }
.btn.danger { color: #c0392b; border-color: #f0d5d0; }
.btn.danger:hover { background: #fff4f2; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.sm { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
input[type=text], input[type=password], input[type=date], input[type=month], select {
  border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 7px 11px; outline: none;
}
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

/* ---------- 卡片 ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 16px;
}
.panel .hd {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.panel .hd h3 { margin: 0; font-size: 14.5px; font-weight: 650; }
.panel .hd .sub { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 8px; }
.panel .bd { padding: 16px 18px; }

/* ---------- 控制区 ---------- */
.toolbar { display: flex; flex-direction: column; gap: 14px; }
.trow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.trow > .label { font-size: 12.5px; color: var(--muted); min-width: 56px; }
.seg { display: inline-flex; background: #eef2f9; border-radius: 10px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 6px 16px; border-radius: 8px; cursor: pointer;
  color: var(--muted); font-weight: 500;
}
.seg button.on { background: #fff; color: var(--brand); box-shadow: 0 1px 3px rgba(20,32,60,.12); font-weight: 650; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 13px;
  cursor: pointer; font-size: 13px; color: #46536e;
}
.chip.on { background: var(--brand-soft); border-color: #b9cdfd; color: var(--brand); font-weight: 600; }

.canteen-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.citem {
  display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: #fff;
  border-radius: 10px; padding: 7px 12px; cursor: pointer; transition: .15s; user-select: none;
}
.citem:hover { border-color: #c9d4e8; }
.citem.on { border-color: #b9cdfd; background: #f7faff; box-shadow: 0 0 0 3px #f0f5ff; }
.citem .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.citem .nm { font-weight: 550; }
.citem .st { font-size: 11px; color: var(--muted); }
.citem .st.err { color: #c0392b; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 14px; }
.kpi {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 17px; box-shadow: var(--shadow);
}
.kpi .k { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi .v { font-size: 25px; font-weight: 700; margin-top: 6px; letter-spacing: -.4px; font-variant-numeric: tabular-nums; }
.kpi .v small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.kpi .x { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ---------- 图表 ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 980px) { .grid2 { grid-template-columns: 1fr; } }
.chart { width: 100%; height: 340px; }
.chart.tall { height: 400px; }

/* ---------- 表格 ---------- */
.tabs { display: flex; gap: 4px; }
.tabs button {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; cursor: pointer; color: var(--muted);
}
.tabs button.on { background: var(--brand-soft); color: var(--brand); font-weight: 650; }
.tablewrap { overflow: auto; max-height: 560px; border-radius: 10px; border: 1px solid var(--line); }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
th, td { padding: 9px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid #f0f3f9; }
th { background: #f8fafd; font-weight: 600; color: #46536e; position: sticky; top: 0; z-index: 2; }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: #fff; z-index: 1; }
th:first-child { background: #f8fafd; z-index: 3; }
tbody tr:hover td { background: #fafcff; }
tbody tr:hover td:first-child { background: #fafcff; }
tr.total td { font-weight: 700; background: #f7f9fe; border-top: 2px solid #dfe6f5; }
tr.total td:first-child { background: #f7f9fe; }
.grp { color: var(--muted); font-size: 12px; }

/* ---------- 弹窗 ---------- */
.mask {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .42); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 560px; max-height: 88vh; overflow: auto;
  box-shadow: 0 24px 60px rgba(16,24,40,.28);
}
.modal .mhd { padding: 18px 20px 12px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal .mhd h3 { margin: 0; font-size: 15.5px; }
.modal .mbd { padding: 18px 20px; }
.modal .mft { padding: 12px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; }
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.field input { width: 100%; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.clist { display: flex; flex-direction: column; gap: 8px; }
.crow {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.crow .info { min-width: 0; }
.crow .info b { display: block; font-weight: 600; }
.crow .info span { font-size: 12px; color: var(--muted); }
.err-banner {
  background: #fff4f2; border: 1px solid #f3d6d0; color: #b83a2a;
  border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 13px;
}
.empty { text-align: center; color: var(--muted); padding: 40px 10px; font-size: 13.5px; }
/* ---------- 管理员 ---------- */
.admin-chip {
  display: inline-flex; align-items: center; height: 30px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; color: #8a6d1f; background: #fdf6e3; border: 1px solid #f0e2b8; white-space: nowrap;
}
.admin-chip.on {
  color: #1a7f5a; background: #eaf8f1; border-color: #bfe6d5; cursor: pointer;
}
.admin-chip.warn {
  color: #a4610f; background: #fff4e2; border-color: #f3d9ac; cursor: pointer;
}
.modal .sec-title {
  font-size: 13px; font-weight: 700; color: #34405c; margin: 0 0 10px;
  padding-left: 9px; border-left: 3px solid var(--brand);
}
.msep { border: 0; border-top: 1px dashed var(--line); margin: 18px 0; }
.hint.warn-tip {
  background: #fff9e8; border: 1px solid #f2e3b6; color: #8a6d1f;
  border-radius: 9px; padding: 9px 12px; margin: 0 0 12px; line-height: 1.6;
}
.hint.warn-tip code {
  background: #fff; border: 1px solid #ecdcae; border-radius: 5px;
  padding: 0 4px; font-size: 12px; color: #6b5312;
}
.loadingbar {
  position: fixed; top: 0; left: 0; height: 3px; width: 100%; z-index: 99;
  background: linear-gradient(90deg, transparent, var(--brand), transparent);
  background-size: 40% 100%; background-repeat: no-repeat;
  animation: sweep 1s linear infinite;
}
@keyframes sweep { from { background-position: -40% 0; } to { background-position: 140% 0; } }
.hide { display: none !important; }
