/* ============ 设计令牌 ============ */
:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-2: #f9fafa;
  --ink: #1d2939;
  --ink-2: #344054;
  --muted: #667085;
  --line: #e4e7ec;
  --line-2: #eef0f3;
  --brand: #0f766e;
  --brand-dark: #0b5d57;
  --brand-soft: #e6f4f1;
  --brand-soft-2: #d1ebe6;
  --gold: #b45309;
  --gold-soft: #fdf3e6;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --ok: #067647;
  --ok-soft: #e7f6ec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, .10);
  --radius: 14px;
  --radius-sm: 10px;
  --sidebar-w: 228px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
button { font-family: inherit; }
mark { background: #fef0c7; color: inherit; padding: 0 2px; border-radius: 3px; }

/* ============ 布局 ============ */
.layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  position: sticky; top: 0;
  height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; }
.brand-logo {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  background: linear-gradient(135deg, #0f766e, #14b8a6);
  display: grid; place-items: center; color: #fff;
  box-shadow: 0 4px 10px rgba(15, 118, 110, .28);
}
.brand-logo svg { width: 20px; height: 20px; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: .2px; }
.brand-sub { font-size: 11px; color: var(--muted); margin-top: -2px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 10px;
  color: var(--ink-2); font-weight: 500; cursor: pointer;
  border: 1px solid transparent;
}
.nav-item svg { width: 18px; height: 18px; flex: none; opacity: .75; }
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--brand-soft); color: var(--brand-dark); border-color: var(--brand-soft-2); }
.nav-item.active svg { opacity: 1; }
.nav-item .nav-badge { margin-left: auto; font-size: 12px; color: var(--muted); }
.nav-item.primary { background: var(--brand); color: #fff; box-shadow: 0 4px 10px rgba(15,118,110,.24); }
.nav-item.primary svg { opacity: 1; }
.nav-item.primary:hover { background: var(--brand-dark); }
.sidebar-foot { margin-top: auto; padding: 12px 10px; border-top: 1px solid var(--line-2); font-size: 12px; color: var(--muted); }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 12px 28px;
  display: flex; align-items: center; gap: 16px;
}
.search-wrap { position: relative; flex: 1; max-width: 560px; }
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  transition: border-color .15s, box-shadow .15s;
}
.search-box:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); background: #fff; }
.search-box svg { width: 17px; height: 17px; color: var(--muted); flex: none; }
.search-box input {
  border: 0; outline: 0; background: transparent; flex: 1;
  font-size: 14px; color: var(--ink); min-width: 0;
}
.search-box input::placeholder { color: #98a2b3; }
.search-pop {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow-lg);
  overflow: hidden; display: none; z-index: 40;
}
.search-pop.show { display: block; }
.pop-group-title { font-size: 11px; color: var(--muted); padding: 8px 12px 4px; letter-spacing: .4px; }
.pop-item { padding: 8px 12px; cursor: pointer; display: flex; gap: 10px; align-items: baseline; }
.pop-item:hover { background: var(--surface-2); }
.pop-item .t { font-weight: 600; }
.pop-item .s { color: var(--muted); font-size: 12px; }
.pop-empty { padding: 12px; color: var(--muted); font-size: 13px; }

.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand-dark);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}

.content { padding: 24px 28px 56px; max-width: 1240px; width: 100%; margin: 0 auto; }

/* ============ 通用组件 ============ */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: .2px; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--brand); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.card-title { font-weight: 700; font-size: 15px; }
.card-sub { color: var(--muted); font-size: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  padding: 8px 14px; border-radius: 10px; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap; transition: all .15s;
}
.btn:hover { border-color: #cfd4dc; background: var(--surface-2); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 2px 6px rgba(15,118,110,.24); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn-danger { color: var(--danger); border-color: #fecdca; background: #fff; }
.btn-danger:hover { background: var(--danger-soft); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

.icon-btn {
  width: 32px; height: 32px; display: grid; place-items: center;
  border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-muted { background: #f2f4f7; color: var(--muted); }
.badge-warn { background: var(--gold-soft); color: var(--gold); }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 6px; background: #f2f4f7; color: var(--ink-2); font-size: 12px; }
.chip-brand { background: var(--brand-soft); color: var(--brand-dark); }
.chip + .chip { margin-left: 4px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
.money { font-variant-numeric: tabular-nums; font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: 44px 16px; color: var(--muted); }
.empty .big { font-size: 28px; margin-bottom: 8px; }

/* ============ 总览 ============ */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat { padding: 14px 16px; }
.stat-label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 2px; letter-spacing: .2px; }
.stat-value small { font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 3px; }

.zone-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.zone-card {
  padding: 16px; cursor: pointer; position: relative; overflow: hidden;
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.zone-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--brand-soft-2); }
.zone-code { font-size: 20px; font-weight: 800; color: var(--brand-dark); letter-spacing: .4px; text-transform: uppercase; }
.zone-name { font-size: 12px; color: var(--muted); margin-top: -2px; }
.zone-meta { display: flex; gap: 14px; margin-top: 12px; }
.zone-meta div { font-size: 12px; color: var(--muted); }
.zone-meta b { display: block; font-size: 15px; color: var(--ink); font-variant-numeric: tabular-nums; }
.zone-value { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 13px; color: var(--gold); font-weight: 700; }

.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-top: 20px; }

.timeline { display: flex; flex-direction: column; }
.timeline-row { display: flex; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line-2); align-items: baseline; }
.timeline-row:last-child { border-bottom: 0; }
.timeline-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); flex: none; margin-top: 7px; }
.timeline-text { flex: 1; font-size: 13px; }
.timeline-time { font-size: 12px; color: var(--muted); white-space: nowrap; }

.alert-row { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.alert-row:last-child { border-bottom: 0; }
.alert-row svg { width: 16px; height: 16px; flex: none; color: var(--muted); }
.alert-row .chip { margin-left: auto; }

/* ============ 列表/表格 ============ */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .grow { flex: 1; min-width: 160px; }
.input, .select {
  width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; font-size: 13px; color: var(--ink); outline: none;
}
.input:focus, .select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2.5'><path d='m6 9 6 6 6-6'/></svg>"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }

.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2);
}
.tbl td { padding: 11px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.clickable:hover { background: var(--surface-2); }
.tbl .name { font-weight: 600; }
.tbl .right { text-align: right; }
.tbl tr.total-row td { background: var(--surface-2); font-weight: 700; }

.box-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.box-card { padding: 14px; cursor: pointer; transition: transform .12s, box-shadow .12s; }
.box-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.box-code { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.box-pos { color: var(--muted); font-size: 12px; margin-top: 2px; }
.box-stats { display: flex; gap: 12px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.box-stats b { color: var(--ink); }

.kv { display: grid; grid-template-columns: 92px 1fr; gap: 8px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ============ 搜索页 ============ */
.search-head { margin-bottom: 18px; }
.search-big {
  display: flex; align-items: center; gap: 10px;
  background: #fff; border: 1.5px solid var(--brand); border-radius: 12px;
  padding: 10px 14px; box-shadow: 0 0 0 4px var(--brand-soft);
}
.search-big svg { width: 20px; height: 20px; color: var(--brand); flex: none; }
.search-big input { border: 0; outline: 0; flex: 1; font-size: 16px; background: transparent; min-width: 0; }
.search-group-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 22px 0 8px; letter-spacing: .3px; }
.result-item { padding: 14px 18px; border-bottom: 1px solid var(--line-2); cursor: pointer; }
.result-item:hover { background: var(--surface-2); }
.result-item:last-child { border-bottom: 0; }
.result-title { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.result-meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.result-nums { display: flex; gap: 18px; margin-top: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.result-nums b { color: var(--ink); font-size: 14px; }
.dist { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.dist .chip { background: var(--brand-soft); color: var(--brand-dark); }

/* ============ 表单 ============ */
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.field .hint { font-size: 11px; color: var(--muted); }
.field.wide { grid-column: span 2; }
.req { color: var(--danger); }

.line-table { width: 100%; border-collapse: collapse; }
.line-table th { font-size: 12px; color: var(--muted); text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); font-weight: 600; white-space: nowrap; }
.line-table td { padding: 6px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.line-table .num-cell { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; padding-top: 14px; }
.line-table .input, .line-table .select { padding: 7px 9px; }
.mini-del { width: 30px; height: 30px; margin-top: 4px; }
.add-line { margin-top: 10px; }
.intake-total {
  display: flex; justify-content: flex-end; gap: 10px; align-items: baseline;
  padding: 12px 6px; font-size: 13px; color: var(--muted);
}
.intake-total b { font-size: 20px; color: var(--ink); }

/* ============ 登录 ============ */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 500px at 50% -10%, #e6f4f1 0%, var(--bg) 60%); }
.login-card { width: 100%; max-width: 400px; padding: 30px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand .brand-logo { width: 44px; height: 44px; }
.login-brand h1 { font-size: 19px; margin: 0; }
.login-brand p { margin: 0; font-size: 12px; color: var(--muted); }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; padding: 10px; }
.login-tip { margin-top: 16px; font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; }

/* ============ 手机 ============ */
.bottom-nav { display: none; }
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding: 10px 14px; }
  .content { padding: 16px 14px 88px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .zone-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .field.wide { grid-column: span 2; }
  .page-title { font-size: 19px; }
  .topbar-user .who { display: none; }
  .hide-sm { display: none !important; }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: rgba(255,255,255,.96); backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav .nav-item {
    flex: 1; flex-direction: column; gap: 3px; font-size: 10.5px;
    padding: 6px 2px; border-radius: 10px; justify-content: center;
  }
  .bottom-nav .nav-item svg { width: 20px; height: 20px; }
  .bottom-nav .nav-item.primary { background: transparent; color: var(--brand); box-shadow: none; }
  .bottom-nav .nav-item.primary svg { color: #fff; background: var(--brand); border-radius: 50%; padding: 6px; width: 34px; height: 34px; }
  .bottom-nav .nav-item.primary span { display: none; }
  .line-table thead { display: none; }
  .line-table td { display: block; border: 0; padding: 3px 6px; }
  .line-table tr.line-row { display: block; border: 1px solid var(--line); border-radius: 12px; padding: 8px; margin-bottom: 10px; background: var(--surface-2); }
  .line-table .num-cell { text-align: left; padding-left: 6px; }
}
@media (max-width: 560px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .zone-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .field.wide { grid-column: span 1; }
}

/* ============ Toast ============ */
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translate(-50%, 12px);
  background: #101828; color: #fff; padding: 11px 18px; border-radius: 12px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: all .22s; z-index: 90;
  max-width: 86vw; text-align: center; box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 981px) { .toast { bottom: 28px; } }

/* ============ 照片 ============ */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding: 14px 18px; }
.photo-grid.inline { padding: 0; margin-top: 8px; }
.photo-thumb { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: #f8fafc; }
.photo-thumb img { width: 100%; height: 118px; object-fit: cover; display: block; cursor: zoom-in; }
.photo-label { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.55); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 4px; }
.photo-del { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.55); color: #fff; cursor: pointer; font-size: 14px; line-height: 1; padding: 0; }
.photo-del:hover { background: rgba(180,35,24,.85); }
.photo-empty { grid-column: 1 / -1; padding: 18px; text-align: center; color: var(--muted); font-size: 13px; border: 1px dashed var(--line); border-radius: 10px; background: var(--surface-2); }
.box-thumb { width: 100%; height: 88px; object-fit: cover; border-radius: 10px; margin-bottom: 10px; background: #f1f5f9; display: block; }
.row-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 8px; flex: none; background: #eef2f4; }
.lightbox { display: none; position: fixed; inset: 0; z-index: 100; background: rgba(15,23,42,.84); place-items: center; padding: 24px; }
.lightbox.show { display: grid; }
.lightbox img { max-width: min(92vw, 1040px); max-height: 86vh; border-radius: 12px; box-shadow: var(--shadow-lg); cursor: zoom-out; }
@media (max-width: 980px) { .photo-thumb img { height: 100px; } }

/* ============ 真实版追加 ============ */
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 64px 0; color: var(--muted); font-size: 13px; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login-error { color: var(--danger); font-size: 13px; margin: 6px 0 10px; min-height: 18px; }
.login-card .field label { display: flex; justify-content: space-between; }

.inline-form { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); background: var(--surface-2); }
.inline-form .field { gap: 4px; }
.inline-form .actions { grid-column: 1 / -1; display: flex; gap: 8px; }
@media (max-width: 980px) { .inline-form { grid-template-columns: 1fr 1fr; } }

.row-actions { display: flex; gap: 4px; justify-content: flex-end; flex-wrap: wrap; }
.btn-xs { padding: 3px 8px; font-size: 12px; border-radius: 7px; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line-2); font-size: 13px; color: var(--muted); }
.pagination .pages { display: flex; gap: 6px; align-items: center; }

.hint-line { color: var(--muted); font-size: 12px; margin-top: 4px; }
.error-banner { background: var(--danger-soft); color: var(--danger); padding: 10px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 14px; }

.search-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; flex: none; background: #eef2f4; }
.result-item.with-thumb { display: flex; gap: 12px; }
.result-item.with-thumb .grow { flex: 1; min-width: 0; }

.role-badge { font-weight: 600; }
.readonly-note { font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px dashed var(--line); padding: 8px 12px; border-radius: 10px; margin-bottom: 12px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--brand); font-size: inherit; cursor: pointer; }

