:root {
  --primary: #2f6fed;
  --primary-d: #1f53b8;
  --primary-l: #eef2fb;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1f2329;
  --muted: #8a94a6;
  --border: #e5e8ef;
  --danger: #e54848;
  --ok: #18a058;
  --warn: #d9822b;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
button { cursor: pointer; font-size: 14px; }
input, select, textarea { font-size: 14px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; outline: none; width: 100%; font-family: inherit; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
a { color: var(--primary); text-decoration: none; }

/* ============ 登录 ============ */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #2f6fed, #1f53b8); }
.login-card { width: 360px; max-width: 92vw; background: #fff; border-radius: 12px; padding: 32px 28px; box-shadow: 0 12px 40px rgba(0, 0, 0, .2); }
.login-card h1 { font-size: 20px; text-align: center; margin-bottom: 6px; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 22px; font-size: 13px; }
.login-card .field { margin-bottom: 14px; }
.msg { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 6px; }

/* ============ 按钮 ============ */
.btn { background: var(--primary); color: #fff; border: none; border-radius: 6px; padding: 9px 16px; white-space: nowrap; }
.btn:hover { background: var(--primary-d); }
.btn-block { width: 100%; }
.btn-ghost { background: #fff; color: var(--primary); border: 1px solid #c9d8f7; }
.btn-ghost:hover { background: var(--primary-l); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c93a3a; }
.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn-xs { padding: 2px 8px; font-size: 12px; border-radius: 4px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ============ 主框架 ============ */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 224px; background: #1f2329; color: #cfd6e4; flex-shrink: 0; overflow-y: auto; }
.sidebar .logo { padding: 18px 16px; font-size: 16px; font-weight: 700; color: #fff; border-bottom: 1px solid #2c323b; }
.sidebar .nav-item { padding: 11px 18px; cursor: pointer; font-size: 14px; }
.sidebar .nav-item:hover { background: #2c323b; }
.sidebar .nav-item.active { background: var(--primary); color: #fff; }
.sidebar .nav-group-title { padding: 14px 18px 6px; font-size: 12px; color: #6b7486; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 56px; background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 18px; flex-shrink: 0; }
.topbar .title { font-weight: 600; }
.topbar .user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.content { padding: 18px; overflow: auto; flex: 1; }

/* ============ 卡片 ============ */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.card h3 { font-size: 15px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head .toolbar { margin-bottom: 0; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; }

.page-title { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.page-title h2 { font-size: 18px; }
.page-title .sub { color: var(--muted); font-size: 13px; }
.page-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.page-title-inline { font-size: 15px; font-weight: 600; }

/* ============ 表格 ============ */
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { background: #fafbfc; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover td { background: #fafbff; }
tr.row-muted td { color: var(--muted); }
.row-actions { display: flex; gap: 6px; flex-wrap: nowrap; }
.empty { padding: 28px 10px; text-align: center; color: var(--muted); font-size: 13px; }

/* 类 Excel 工资表 */
.table-wrap.excel { border: 1px solid var(--border); border-radius: 8px; }
table.excel-table { font-size: 12px; }
.excel th, .excel td { padding: 3px 4px; border-right: 1px solid #eef0f4; white-space: nowrap; }
.excel thead th { position: sticky; top: 0; z-index: 2; }
.cell-input { width: 100%; min-width: 70px; padding: 4px 6px; border: 1px solid transparent; border-radius: 4px; font-size: 12px; background: transparent; }
.cell-input:hover { border-color: #cfd8e6; background: #fff; }
.cell-input:focus { border-color: var(--primary); background: #fff; }
.cell-input.num { text-align: right; }
.cell-ro { color: #4a5464; }

/* ============ 标签 ============ */
.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: var(--primary-l); color: var(--primary); white-space: nowrap; }
.tag.ok { background: #e7f6ee; color: var(--ok); }
.tag.off { background: #f0f2f5; color: #77808f; }
.tag.warn { background: #fdf1e3; color: var(--warn); }
.tag.danger { background: #fdeaea; color: var(--danger); }

/* ============ 表单 ============ */
.field { margin-bottom: 12px; }
.field-label { font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 5px; line-height: 1.6; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; margin: 4px 12px 4px 0; cursor: pointer; }
.chk input { width: auto; }
.chk-group { display: flex; flex-wrap: wrap; margin-bottom: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-section { font-size: 13px; font-weight: 600; color: var(--primary); margin: 16px 0 10px; padding-bottom: 6px; border-bottom: 1px dashed var(--border); }
.inline-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.inline-item { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.inline-item input, .inline-item select { width: auto; }
.ro-text { padding: 8px 0; font-size: 14px; font-weight: 500; }
.hint-line { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.7; }
.error-text { color: var(--danger); font-size: 13px; margin: 8px 0; }
.text-ok { color: var(--ok); }
.text-danger { color: var(--danger); }
.todo-done { text-decoration: line-through; color: var(--muted); }

/* ============ Tab / 分段 ============ */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tab { padding: 9px 14px; font-size: 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg-btn { background: #fff; color: var(--text); border: none; padding: 6px 12px; font-size: 13px; }
.seg-btn.active { background: var(--primary); color: #fff; }

/* ============ chips ============ */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { padding: 4px 10px; border-radius: 14px; font-size: 12px; background: #f0f2f5; color: #4a5464; cursor: pointer; }
.chip.active { background: var(--primary); color: #fff; }

/* ============ 统计卡 ============ */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; cursor: pointer; }
.stat-card:hover { border-color: var(--primary); }
.stat-value { font-size: 26px; font-weight: 700; color: var(--primary); line-height: 1.2; }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* ============ 快捷入口 ============ */
.quick-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 16px; }
.quick-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 16px; cursor: pointer; }
.quick-card:hover { border-color: var(--primary); box-shadow: 0 4px 14px rgba(47, 111, 237, .1); }
.quick-title { font-weight: 600; margin-bottom: 4px; }
.quick-sub { font-size: 12px; color: var(--muted); }

/* ============ 分页 ============ */
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 12px; font-size: 13px; }
.pager .sub { color: var(--muted); margin-right: 6px; }

/* ============ 图片 / KV ============ */
.thumb { width: 120px; height: 76px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; margin-right: 8px; }
.thumb-lg { width: 260px; max-width: 100%; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; }
.photo-box { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 18px; margin: 6px 0 16px; }
.kv span { display: block; font-size: 12px; color: var(--muted); }
.kv b { font-size: 15px; }
.json-box { background: #f7f8fa; border: 1px solid var(--border); border-radius: 6px; padding: 12px; font-size: 12px; max-height: 380px; overflow: auto; white-space: pre-wrap; word-break: break-all; }

/* ============ 弹窗 ============ */
.modal-mask { position: fixed; inset: 0; background: rgba(0, 0, 0, .42); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 10px; width: 620px; max-width: 94vw; max-height: 88vh; overflow-y: auto; padding: 20px; }
.modal h3 { margin-bottom: 14px; font-size: 16px; }
.modal .field { margin-bottom: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; position: sticky; bottom: 0; background: #fff; padding-top: 10px; }

/* ============ Toast ============ */
.toast-box { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 99; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1f2329; color: #fff; padding: 9px 18px; border-radius: 20px; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); transition: opacity .25s, transform .25s; }
.toast.err { background: var(--danger); }
.toast.out { opacity: 0; transform: translateY(-8px); }

/* ============ 工资条（打印） ============ */
.payslip { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; background: #fff; }
.payslip-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; border-bottom: 1px dashed var(--border); padding-bottom: 8px; margin-bottom: 8px; }
.payslip-foot { display: flex; justify-content: space-between; align-items: baseline; border-top: 1px dashed var(--border); padding-top: 8px; margin-top: 6px; }
.payslip-foot b { font-size: 18px; color: var(--primary); }

@media print {
  .sidebar, .topbar, .tabbar, .tabs, .toolbar, .no-print, .pager, .toast-box { display: none !important; }
  .content { padding: 0 !important; }
  .card { border: none; padding: 0; }
  .payslip { page-break-inside: avoid; border: 1px solid #999; }
  body { background: #fff; }
}

/* ============ 底部导航（仅手机显示，PC 隐藏） ============ */
.tabbar { display: none; }

/* ============ 响应式：移动端 ============ */
@media (max-width: 900px) {
  html { -webkit-text-size-adjust: 100%; }
  body { font-size: 15px; }

  /* —— 侧栏改为抽屉 —— */
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 78vw; max-width: 300px; z-index: 60; transform: translateX(-100%); transition: transform .22s; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-block; }

  /* —— 顶栏吸顶、内容区给底部导航留位 —— */
  .topbar { position: sticky; top: 0; z-index: 30; height: 50px; padding: 0 12px; }
  .topbar .title { font-size: 15px; }
  .content { padding: 12px 12px calc(72px + env(safe-area-inset-bottom)); }

  /* —— 底部导航 —— */
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 55; background: #fff; border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 7px 0 6px; font-size: 11px; color: var(--muted); }
  .tabbar-item.active { color: var(--primary); }
  .tabbar-icon { display: flex; }

  /* —— 卡片与栅格 —— */
  .card { padding: 14px; border-radius: 12px; }
  .card-head { gap: 8px; }
  .grid2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: repeat(2, 1fr); }
  .stat-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 22px; }
  .quick-row { grid-template-columns: 1fr; }
  .pager { flex-wrap: wrap; justify-content: center; }
  .inline-form { gap: 8px; }

  /* —— 表单：16px 可避免 iOS 聚焦时页面被放大 —— */
  input, select, textarea { padding: 11px 12px; font-size: 16px; border-radius: 8px; }
  .toolbar { width: 100%; }
  .toolbar input, .toolbar select, .inline-item input, .inline-item select { width: 100%; flex: 1 1 130px; }
  .field { margin-bottom: 14px; }

  /* —— 按钮：放大触摸区 —— */
  .btn { padding: 11px 16px; }
  .btn-sm { padding: 9px 14px; font-size: 14px; }
  .btn-xs { padding: 7px 11px; font-size: 13px; }
  .btn-block { padding: 13px; font-size: 16px; }
  .row-actions { flex-wrap: wrap; gap: 8px; }

  /* —— 表格转卡片（类 Excel 工资表除外，保持横向滚动） —— */
  .table-wrap:not(.excel) { overflow: visible; }
  .table-wrap:not(.excel) table,
  .table-wrap:not(.excel) tbody,
  .table-wrap:not(.excel) tr,
  .table-wrap:not(.excel) td { display: block; width: 100%; }
  .table-wrap:not(.excel) thead { display: none; }
  .table-wrap:not(.excel) tr { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
  .table-wrap:not(.excel) tr:hover td { background: transparent; }
  .table-wrap:not(.excel) tr.row-muted td { color: inherit; }
  .table-wrap:not(.excel) td { border: none; padding: 5px 0; display: flex; align-items: baseline; justify-content: space-between; gap: 14px; font-size: 14px; }
  .table-wrap:not(.excel) td::before { content: attr(data-label); color: var(--muted); font-size: 12px; flex: 0 0 auto; }
  .table-wrap:not(.excel) td:empty { display: none; }
  .table-wrap:not(.excel) td:first-child { font-size: 16px; font-weight: 600; }
  .table-wrap:not(.excel) td[data-label="ID"] { display: none; }
  .table-wrap:not(.excel) td:last-child { display: block; padding-top: 8px; margin-top: 4px; border-top: 1px dashed var(--border); }
  .table-wrap:not(.excel) td:last-child::before { display: block; margin-bottom: 6px; }

  /* —— 弹窗：底部抽屉式，按钮平分 —— */
  .modal-mask { align-items: flex-end; padding: 0; background: rgba(0, 0, 0, .5); }
  .modal { width: 100%; max-width: 100%; max-height: 94vh; border-radius: 16px 16px 0 0; padding: 18px 14px calc(14px + env(safe-area-inset-bottom)); }
  .modal h3 { font-size: 17px; }
  .modal-actions { gap: 10px; padding-top: 12px; }
  .modal-actions .btn { flex: 1; padding: 13px; font-size: 16px; }

  /* —— 其它 —— */
  .tabs { gap: 0; }
  .tab { padding: 10px 12px; font-size: 14px; }
  .thumb { width: 96px; height: 62px; }
  .login-card { width: 100%; padding: 26px 20px; }
  .excel-table { font-size: 12px; }
}
@media (min-width: 901px) { .menu-btn { display: none; } }
