* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: "Microsoft YaHei", "PingFang SC", sans-serif; background: #f5f7fa; color: #333; font-size: 14px; }
a { text-decoration: none; color: #2563eb; }

.layout { display: flex; min-height: 100vh; }
.sidebar { width: 210px; background: #1e293b; color: #cbd5e1; flex-shrink: 0; display: flex; flex-direction: column; }
.sidebar .brand { padding: 18px 16px; font-size: 17px; font-weight: 700; color: #fff; border-bottom: 1px solid #334155; letter-spacing: 1px; }
.sidebar .brand small { display: block; font-size: 11px; font-weight: 400; color: #94a3b8; margin-top: 3px; }
.sidebar nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.sidebar nav a { display: block; padding: 11px 18px; color: #cbd5e1; font-size: 14px; }
.sidebar nav a:hover { background: #334155; color: #fff; }
.sidebar nav a.active { background: #2563eb; color: #fff; }
/* 二级菜单：一级分组标题 + 可折叠子项 */
.sidebar nav .nav-group { margin: 1px 0; border-top: 1px solid rgba(148,163,184,.2); padding-top: 5px; }
.sidebar nav .nav-group:first-of-type { border-top: 0; padding-top: 0; }
.sidebar nav .nav-head { display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; color: #e2e8f0; font-size: 14px; font-weight: 600; cursor: pointer;
  user-select: none; }
.sidebar nav .nav-head:hover { background: #334155; color: #fff; }
.sidebar nav .nav-head.group-active { color: #fff; background: #1e3a5f; }
.sidebar nav .nav-head .caret { font-size: 11px; color: #94a3b8; transition: transform .15s ease; }
.sidebar nav .nav-head.collapsed .caret { transform: rotate(-90deg); }
.sidebar nav .nav-sub a { padding-left: 34px; font-size: 13.5px; }
.sidebar nav .nav-sub a.active { background: #2563eb; color: #fff; }
.sidebar .user { padding: 14px 16px; border-top: 1px solid #334155; font-size: 13px; }
.sidebar .user .nm { color: #fff; font-weight: 600; }
.sidebar .user a { color: #f87171; font-size: 12px; }

.main { flex: 1; padding: 22px 28px; overflow-x: auto; }
.main h2 { font-size: 20px; margin-bottom: 16px; color: #1e293b; }
.card { background: #fff; border-radius: 10px; padding: 18px 20px; margin-bottom: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.card h3 { font-size: 15px; margin-bottom: 12px; color: #334155; }

table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 9px 10px; border-bottom: 1px solid #eef1f5; text-align: left; font-size: 13px; }
th { background: #f8fafc; color: #475569; font-weight: 600; white-space: nowrap; }
tr:hover td { background: #f8fafc; }

.btn { display: inline-block; padding: 7px 15px; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; color: #334155; font-size: 13px; cursor: pointer; }
.btn:hover { background: #f1f5f9; }
.btn-primary { background: #2563eb; border-color: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-danger { color: #dc2626; border-color: #fca5a5; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-xs { padding: 2px 8px; font-size: 12px; }

input, select, textarea { padding: 7px 10px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 13px; font-family: inherit; }
input:focus, select:focus { outline: none; border-color: #2563eb; }
label { display: inline-block; margin-right: 4px; color: #475569; font-size: 13px; }
.form-row { margin-bottom: 12px; }
.form-row label { width: 90px; display: inline-block; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 12px; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #e5e7eb; color: #374151; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: #fff; border-radius: 10px; padding: 16px 18px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.stat .num { font-size: 26px; font-weight: 700; color: #1e293b; }
.stat .num.red { color: #dc2626; }
.stat .lbl { color: #64748b; font-size: 13px; margin-top: 4px; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.pager { margin-top: 12px; color: #64748b; font-size: 13px; }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-ok { background: #dcfce7; color: #166534; }
.muted { color: #94a3b8; font-size: 12px; }
.right { text-align: right; }
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #1e293b; }
.login-box { background: #fff; border-radius: 12px; padding: 34px 38px; width: 360px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); }
.login-box h1 { font-size: 20px; text-align: center; margin-bottom: 4px; color: #1e293b; }
.login-box .sub { text-align: center; color: #94a3b8; font-size: 13px; margin-bottom: 22px; }
.login-box input { width: 100%; margin-bottom: 14px; padding: 10px 12px; }
.login-box .btn { width: 100%; padding: 10px; }

/* ===================== 侧边栏收缩（桌面）+ 手机适配 ===================== */

/* 侧边栏「收起 / 展开」按钮 */
.side-toggle, .side-open {
  width: 34px; height: 34px; flex-shrink: 0; padding: 0; border-radius: 8px; cursor: pointer;
  border: 1px solid #475569; background: #334155; color: #e2e8f0; font-size: 15px; line-height: 1;
}
.side-toggle:hover, .side-open:hover { background: #2563eb; border-color: #2563eb; color: #fff; }
.side-open {
  display: none; position: fixed; top: 10px; left: 10px; z-index: 90;
  width: 38px; height: 38px; font-size: 18px;
  background: #1e293b; border-color: #1e293b; color: #fff;
  box-shadow: 0 2px 8px rgba(15,23,42,.28);
}
body.side-collapsed .sidebar { display: none; }
body.side-collapsed .side-open { display: block; }
body.side-collapsed .main { padding-top: 58px; }
.nav-mask { display: none; }
.brand { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }

/* 手机 / 窄屏 */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 100; width: 245px;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 2px 0 14px rgba(15,23,42,.35);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.side-collapsed .sidebar { display: flex; }      /* 手机端改由 nav-open 控制 */
  .side-toggle { display: none; }
  .side-open { display: block; }
  body.nav-open .side-open { display: none; }
  .nav-mask { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 95; }
  body.nav-open .nav-mask { display: block; }
  .main { padding: 56px 12px 26px; }
  .main h2 { font-size: 17px; margin-bottom: 12px; }
  .card { padding: 13px; border-radius: 8px; margin-bottom: 12px; }
  .card h3 { font-size: 14px; margin-bottom: 9px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-bottom: 12px; }
  .stat { padding: 11px 12px; }
  .stat .num { font-size: 20px; }
  .stat .lbl { font-size: 12px; }
  .form-row { display: block; margin-bottom: 11px; }
  .form-row > label { display: block; width: auto; margin-bottom: 4px; }
  /* 手机端表单字段一律占满整行（用 !important 覆盖模板里的内联宽度） */
  .form-row input, .form-row select, .form-row textarea {
    width: 100% !important; box-sizing: border-box; margin-bottom: 6px; }
  .form-row .muted { display: block; margin: 2px 0 4px; }
  .inline-form { display: flex; flex-wrap: wrap; gap: 7px; }
  .inline-form input, .inline-form select { flex: 1 1 45%; min-width: 0; }
  .toolbar { gap: 7px; }
  .toolbar .btn { flex: 1 1 auto; text-align: center; }
  .btn { padding: 9px 13px; }
  .btn-sm { padding: 6px 10px; font-size: 12px; }
  /* 表格横向滚动，避免撑破屏幕 */
  .card table { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .card table th, .card table td { white-space: nowrap; }
  .card table td .muted, .card table td div { white-space: normal; }
  input, select, textarea { font-size: 16px; }          /* ≥16px 防止 iOS 聚焦自动放大 */
  .sidebar nav a { padding: 13px 18px; }
  .sidebar nav .nav-sub a { padding-left: 36px; }
  .login-box { width: 100%; padding: 26px 20px; }
}
