:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --border-strong: #cbd5e1;
  --text: #1f2937;
  --text-2: #5b6675;
  --text-3: #8b95a5;
  --primary: #1d4ed8;
  --primary-soft: #e8efff;
  --green: #0f766e;
  --green-soft: #e2f5f0;
  --amber: #a16207;
  --amber-soft: #fdf3dc;
  --red: #b91c1c;
  --red-soft: #fdeaea;
  --gray-soft: #eef1f5;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 6px 18px rgba(16, 24, 40, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6;
}
.hidden { display: none !important; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--primary); text-decoration: none; }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: #eef2f9; padding: 24px; }
.login-card { width: 400px; max-width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow); padding: 38px 36px 28px; }
.login-brand { font-size: 21px; font-weight: 600; letter-spacing: .5px; text-align: center; color: #16327a; }
.login-sub { text-align: center; color: var(--text-3); font-size: 12px; margin: 8px 0 28px; letter-spacing: 1px; }
.field-label { display: block; color: var(--text-2); font-size: 13px; margin: 14px 0 6px; }
.login-err { color: var(--red); font-size: 13px; min-height: 22px; padding-top: 6px; }
.login-foot { text-align: center; color: var(--text-3); font-size: 12px; margin-top: 22px;
  border-top: 1px solid var(--border); padding-top: 16px; }
.linklike { color: var(--primary); cursor: pointer; }
.login-mask { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center;
  justify-content: center; padding: 24px; background: rgba(16, 24, 40, .45); }

/* ---------- 免登录填报门户 ---------- */
.portal { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.portal-head { display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 32px; background: var(--surface); border-bottom: 1px solid var(--border); }
.portal-brand { font-size: 18px; font-weight: 600; color: #16327a; }
.portal-sub { font-size: 12px; color: var(--text-3); margin-top: 3px; }
.portal-tabs { display: flex; gap: 6px; padding: 0 32px; background: var(--surface);
  border-bottom: 1px solid var(--border); }
.portal-tab { padding: 13px 22px 11px; border: 0; border-bottom: 3px solid transparent;
  background: none; color: var(--text-2); cursor: pointer; font-size: 14px; }
.portal-tab:hover { color: var(--primary); }
.portal-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.portal-content { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 24px 24px 40px; }
.portal-foot { padding: 16px; text-align: center; color: var(--text-3); font-size: 12px;
  border-top: 1px solid var(--border); }
.receipt { margin-bottom: 18px; padding: 16px 18px; border: 1px solid var(--green);
  border-radius: var(--radius); background: var(--green-soft); }
.receipt-title { font-weight: 600; color: var(--green); margin-bottom: 6px; }
/* ---------- 布局 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 218px; flex: 0 0 218px; background: #16233c; color: #dbe4f3;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side-head { padding: 22px 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.side-title { font-size: 16px; font-weight: 600; color: #fff; letter-spacing: .5px; }
.side-sub { font-size: 11px; color: #8fa3c4; margin-top: 4px; }
.menu { flex: 1; overflow-y: auto; padding: 12px 10px; }
.menu-group { font-size: 11px; color: #778cad; padding: 14px 12px 6px; letter-spacing: 1px; }
.menu-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: #c8d4e8; cursor: pointer; font-size: 13.5px; margin-bottom: 2px; user-select: none; }
.menu-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.menu-item.active { background: #2456c7; color: #fff; font-weight: 600; }
.menu-dot { width: 5px; height: 5px; border-radius: 50%; background: #6f88b5; flex: 0 0 5px; }
.menu-item.active .menu-dot { background: #fff; }
.side-foot { padding: 14px 20px; font-size: 11px; color: #6f83a5; border-top: 1px solid rgba(255,255,255,.08); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 58px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px; flex: 0 0 58px; }
.crumb { font-size: 15px; font-weight: 600; }
.top-right { display: flex; align-items: center; gap: 12px; }
.user-chip { color: var(--text-2); font-size: 13px; }
.content { padding: 22px 24px 40px; flex: 1; }

/* ---------- 通用组件 ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-title { font-size: 14.5px; font-weight: 600; }
.card-sub { color: var(--text-3); font-size: 12px; font-weight: 400; margin-left: 10px; }
.card-body { padding: 16px 18px; }
.card-body.tight { padding: 0; }
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-bottom: 2px; }
.toolbar .grow { flex: 1; }
.hint { color: var(--text-3); font-size: 12px; }
.section-gap { height: 14px; }

.btn { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: 7px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #1742b8; color: #fff; }
.btn-danger { color: var(--red); border-color: #f0c9c9; }
.btn-danger:hover { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; padding: 10px; font-size: 15px; }
.btn-link { border: none; background: none; color: var(--primary); padding: 2px 4px; cursor: pointer; font-size: 12.5px; }
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--red); }

.input, .select, .textarea { width: 100%; padding: 7px 10px; border: 1px solid var(--border-strong);
  border-radius: 7px; background: var(--surface); color: var(--text); outline: none; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.textarea { min-height: 68px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.form-item.full { grid-column: 1 / -1; }
.form-item label { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 5px; }
.form-item .hint { margin-top: 4px; }
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.inline-form .fi { min-width: 140px; }
.inline-form .fi label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 5px; }

.chip { display: inline-block; background: var(--primary-soft); color: var(--primary);
  border-radius: 20px; padding: 3px 11px; font-size: 12px; }
.badge { display: inline-block; border-radius: 5px; padding: 2px 9px; font-size: 12px; white-space: nowrap; }
.badge.gray { background: var(--gray-soft); color: var(--text-2); }
.badge.blue { background: var(--primary-soft); color: var(--primary); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }

/* ---------- 表格 ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th { background: var(--surface-2); color: var(--text-2); font-weight: 600; text-align: left;
  padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.tbl td { padding: 10px 12px; border-bottom: 1px solid #f0f2f6; vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tbody tr:hover { background: #fafbfe; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl td.act { white-space: nowrap; }
.empty { padding: 34px 16px; text-align: center; color: var(--text-3); font-size: 13px; }

/* ---------- 统计卡 ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); }
.stat-label { color: var(--text-2); font-size: 12.5px; }
.stat-value { font-size: 24px; font-weight: 600; margin-top: 6px; letter-spacing: .5px; }
.stat-note { color: var(--text-3); font-size: 11.5px; margin-top: 4px; }

/* ---------- 条形图 ---------- */
.bar-row { display: grid; grid-template-columns: 110px 1fr 100px; gap: 12px; align-items: center;
  margin-bottom: 10px; font-size: 12.5px; }
.bar-label { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { background: var(--gray-soft); border-radius: 5px; height: 16px; overflow: hidden; }
.bar-fill { background: #3b6fd4; height: 100%; border-radius: 5px; min-width: 2px; }
.bar-fill.alt { background: #2a9d8f; }
.bar-value { text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 18px; }
.tab { padding: 10px 16px; cursor: pointer; color: var(--text-2); font-size: 13.5px;
  border-bottom: 2px solid transparent; }
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ---------- 模态框 ---------- */
.modal-mask { position: fixed; inset: 0; background: rgba(17, 26, 44, .45); z-index: 1000;
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 24px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 620px; max-width: 100%;
  box-shadow: 0 18px 50px rgba(16,24,40,.22); }
.modal.wide { width: 900px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close { border: none; background: none; font-size: 22px; color: var(--text-3); cursor: pointer; line-height: 1; }
.modal-body { padding: 20px; max-height: 68vh; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex;
  justify-content: flex-end; gap: 10px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; font-size: 13px; margin-bottom: 14px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; }

/* ---------- Toast ---------- */
.toast { position: fixed; top: 18px; right: 18px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast-item { background: #16327a; color: #fff; padding: 10px 16px; border-radius: 8px;
  box-shadow: var(--shadow); font-size: 13px; min-width: 190px; }
.toast-item.err { background: var(--red); }

/* ---------- 其它 ---------- */
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.flex { display: flex; align-items: center; gap: 10px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mt10 { margin-top: 10px; }
.mt16 { margin-top: 16px; }
.mb10 { margin-bottom: 10px; }
.muted { color: var(--text-3); }
.strong { font-weight: 600; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.line-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.line-table th, .line-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.line-table th { background: var(--surface-2); color: var(--text-2); font-weight: 600; }
.pill-row { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { border: 1px solid var(--border); border-radius: 20px; padding: 4px 12px; font-size: 12px;
  background: var(--surface-2); color: var(--text-2); }
.pill.on { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.tag-pick { display: flex; flex-wrap: wrap; gap: 8px 14px; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); }
.tag-opt { display: inline-flex; align-items: center; gap: 5px; font-size: 12px;
  color: var(--text-2); cursor: pointer; white-space: nowrap; }
.tag-opt input { accent-color: var(--primary); }

/* ---------- 移动适配基础件（桌面态隐藏） ---------- */
body { -webkit-text-size-adjust: 100%; }
.top-left { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.menu-toggle { display: none; flex: 0 0 38px; width: 38px; height: 38px; padding: 0;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  flex-direction: column; align-items: center; justify-content: center; gap: 4px; cursor: pointer; }
.menu-toggle span { display: block; width: 17px; height: 2px; border-radius: 2px; background: var(--text-2); }
.side-mask { display: none; }
.scroll-hint { display: none; }
.sm-only { display: none; }

/* ========== 平板 / 小桌面：仅收紧留白，菜单文字保持完整 ========== */
@media (max-width: 1100px) {
  .sidebar { width: 196px; flex-basis: 196px; }
  .topbar { padding: 0 18px; }
  .content { padding: 18px; }
  .portal-head { padding: 16px 20px; }
  .portal-tabs { padding: 0 20px; }
  .portal-content { padding: 20px; }
  .bar-row { grid-template-columns: 90px 1fr 90px; }
}

/* ========== 手机：侧栏改抽屉、明细表卡片化、列表横滑 ========== */
@media (max-width: 768px) {
  html, body { overflow-x: hidden; }

  /* 免登录填报门户 */
  .portal-head { flex-direction: column; align-items: stretch; gap: 10px;
    padding: 14px 14px 12px; padding-top: calc(14px + env(safe-area-inset-top)); }
  .portal-brand { font-size: 15px; line-height: 1.45; }
  .portal-head .btn { align-self: stretch; text-align: center; min-height: 40px; }
  .portal-tabs { padding: 0 8px; }
  .portal-tab { flex: 1; min-height: 46px; padding: 12px 8px 10px; text-align: center; }
  .portal-content { padding: 12px 12px 28px; }
  .portal-foot { padding: 12px 12px calc(14px + env(safe-area-inset-bottom)); font-size: 11px; }

  /* 登录弹窗 */
  .login-mask { padding: 14px; }
  .login-card { padding: 24px 20px 18px; border-radius: 12px; }
  .login-brand { font-size: 18px; }

  /* 后台整体：侧栏脱离文档流，主区占满屏宽 */
  .app { display: block; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 110;
    width: 268px; max-width: 84vw; height: 100dvh; flex-basis: auto;
    transform: translateX(-102%); transition: transform .22s ease;
    box-shadow: 6px 0 26px rgba(16, 24, 40, .25);
    padding-top: env(safe-area-inset-top); }
  body.nav-open .sidebar { transform: translateX(0); }
  .side-mask { position: fixed; inset: 0; z-index: 105; background: rgba(16, 24, 40, .45); }
  body.nav-open .side-mask { display: block; }
  .menu-item { min-height: 42px; font-size: 14px; padding: 10px 12px; }
  .menu-group { padding: 12px 12px 4px; }

  /* 顶栏：汉堡 + 面包屑 + 精简右侧 */
  .topbar { position: sticky; top: 0; z-index: 90; height: auto; min-height: 54px;
    flex-basis: auto; gap: 6px; padding: 8px 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right)); }
  .menu-toggle { display: flex; }
  .crumb { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .top-right { gap: 6px; flex: 0 0 auto; }
  #top-period { display: none; }
  .user-chip { display: inline-block; max-width: 96px; font-size: 12px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
  .lg-only { display: none; }
  .sm-only { display: inline; }
  .content { padding: 12px 12px 32px; }

  /* 卡片与表单 */
  .card { margin-bottom: 12px; border-radius: 8px; }
  .card-head { flex-wrap: wrap; gap: 8px; padding: 12px; }
  .card-sub { display: block; margin-left: 0; margin-top: 2px; }
  .card-body { padding: 12px; }
  .card-body.tight { padding: 0; }
  .form-grid { grid-template-columns: 1fr; gap: 10px; }
  .inline-form { gap: 10px; }
  .inline-form .fi, .toolbar .fi { flex: 1 1 100%; min-width: 0; width: 100%; }
  .flex, .flex-between, .pill-row { flex-wrap: wrap; }

  /* 触控尺寸 + 防止 iOS 聚焦时自动缩放 */
  .input, .select, .textarea { font-size: 16px; padding: 9px 10px; min-height: 42px; }
  .textarea { min-height: 84px; }
  .btn { min-height: 38px; padding: 8px 14px; }
  .btn-sm { min-height: 34px; }
  .btn-link { min-height: 34px; padding: 6px; font-size: 13px; }
  .tabs { padding: 0 8px; }
  .tab { flex: 1; min-height: 42px; padding: 10px 8px; text-align: center; }

  /* 统计卡与条形图 */
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
  .stat { padding: 12px; }
  .stat-value { font-size: 20px; }
  .bar-row { grid-template-columns: 1fr auto; gap: 4px 10px; margin-bottom: 14px; }
  .bar-label { grid-column: 1; grid-row: 1; }
  .bar-value { grid-column: 2; grid-row: 1; }
  .bar-track { grid-column: 1 / -1; grid-row: 2; }
  .kv { grid-template-columns: 84px 1fr; }

  /* 只读列表：保留表格语义，横向滑动查看全部列 */
  .scroll-hint { display: block; padding: 8px 12px; font-size: 11.5px;
    color: var(--text-3); background: var(--surface-2); border-bottom: 1px solid var(--border); }
  .table-wrap { -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
  table.tbl { min-width: 680px; }
  table.tbl th, table.tbl td { padding: 9px 10px; white-space: nowrap; }

  /* 可编辑明细：由 6 列表格改为逐行卡片，无需横向拖动即可填写 */
  .line-table, .line-table tbody, .line-table tr, .line-table td { display: block; width: 100%; }
  .line-table thead { display: none; }
  .line-table tbody tr { margin-bottom: 10px; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
  .line-table tbody tr:last-child { margin-bottom: 0; }
  .line-table td { display: flex; align-items: center; justify-content: space-between;
    gap: 10px; min-height: 40px; padding: 5px 0; border: 0; }
  .line-table td::before { content: attr(data-label); flex: 0 0 62px;
    color: var(--text-3); font-size: 12px; }
  .line-table td > * { flex: 1 1 auto; min-width: 0; }
  .line-table td > .btn-link { flex: 0 0 auto; }

  /* 弹窗：近全屏、底部按钮均分 */
  .modal-mask { padding: 8px 8px calc(14px + env(safe-area-inset-bottom)); align-items: flex-start; }
  .modal, .modal.wide { width: 100%; max-width: 100%; border-radius: 10px; }
  .modal-head { padding: 12px 14px; }
  .modal-body { padding: 14px; max-height: calc(100dvh - 175px); }
  .modal-foot { padding: 10px 14px; }
  .modal-foot .btn { flex: 1; }
  .modal-close { min-width: 36px; min-height: 36px; }

  /* 提示条 */
  .toast { top: auto; bottom: calc(16px + env(safe-area-inset-bottom));
    left: 12px; right: 12px; align-items: center; }
  .toast-item { min-width: 0; max-width: 100%; text-align: center; }
}

/* ========== 超窄屏（≤380px，如 iPhone SE / 老安卓） ========== */
@media (max-width: 380px) {
  .crumb { font-size: 13px; }
  .user-chip { max-width: 72px; }
  .line-table td::before { flex-basis: 54px; }
  .stat { padding: 10px; }
  .stat-value { font-size: 18px; }
  .btn { padding: 8px 10px; }
}
