:root {
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #f0fdfa;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --ink: #111827;
  --ink-2: #374151;
  --ink-3: #6b7280;
  --line: #e5e7eb;
  --bg: #f5f7fb;
  --card: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --sidebar-w: 220px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px; line-height: 1.5;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }

/* ================= 外壳 ================= */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.sidebar { display: none; }
.sidebar .logo { padding: 22px 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .logo-main { display: block; font-size: 18px; font-weight: 700; letter-spacing: 1px; }
.sidebar .logo-sub { display: block; font-size: 11px; color: #94a3b8; margin-top: 2px; letter-spacing: 3px; }
.side-nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.side-nav a { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 10px; color: #cbd5e1; font-size: 14px; transition: background .15s, color .15s; }
.side-nav a .ico { width: 20px; text-align: center; font-size: 16px; }
.side-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side-nav a.active { background: var(--primary); color: #fff; font-weight: 600; }
.side-user { padding: 14px 18px 20px; border-top: 1px solid rgba(255,255,255,.08); }
.side-user .u-name { font-size: 13px; color: #e2e8f0; margin-bottom: 8px; }
.side-logout { width: 100%; background: rgba(255,255,255,.1); color: #fff; border: 0; padding: 8px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.side-logout:hover { background: rgba(255,255,255,.18); }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(15,118,110,.25); }
.topbar .brand { font-size: 17px; font-weight: 700; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; opacity: .92; }
.topbar button { background: rgba(255,255,255,.16); color: #fff; border: 0; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: #fff; border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); box-shadow: 0 -2px 10px rgba(16,24,40,.05); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 8px 0 6px; color: var(--ink-3); font-size: 11px; }
.tabbar a .ico { font-size: 19px; line-height: 1; }
.tabbar a.active { color: var(--primary); font-weight: 600; }

.content { flex: 1; width: 100%; max-width: 1400px; margin: 0 auto; padding: 16px 14px 96px; }

@media (min-width: 900px) {
  .app-shell { flex-direction: row; }
  .sidebar { display: flex; flex-direction: column; position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w); background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%); color: #fff; z-index: 20; }
  .topbar { display: none; }
  .tabbar { display: none; }
  .content { margin-left: var(--sidebar-w); max-width: none; padding: 22px 26px 40px; min-height: 100vh; }
}

/* ================= 卡片 / 表单 ================= */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.card h3 { margin: 0 0 10px; font-size: 15px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.field input, .field select, .field textarea { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; outline: none; min-height: 40px; transition: border-color .15s, box-shadow .15s; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.field input[readonly] { background: #f8fafc; color: var(--ink-2); }

.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 620px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 10px; border: 1px solid transparent; background: var(--primary); color: #fff; font-weight: 600; cursor: pointer; min-height: 40px; }
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink-2); }
.btn.danger { background: var(--red); }
.btn.sm { padding: 5px 11px; min-height: 32px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

/* ================= 表格 ================= */
.table-wrap { overflow: auto; -webkit-overflow-scrolling: touch; max-height: calc(100vh - 300px); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #f8fafc; color: var(--ink-2); font-weight: 600; position: sticky; top: 0; z-index: 1; }
tr:hover td { background: #f9fafb; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 180px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; line-height: 18px; }
.badge.blue { background: #dbeafe; color: #1e40af; }
.badge.green { background: #dcfce7; color: #166534; }
.badge.red { background: #fee2e2; color: #991b1b; }
.badge.amber { background: #fef3c7; color: #92400e; }
.badge.gray { background: #f1f5f9; color: #475569; }
.badge.teal { background: #ccfbf1; color: #115e59; }

/* ================= 地图 ================= */
.map-layout { display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 900px) { .map-layout { flex-direction: row; align-items: stretch; } }
.map-side { width: 100%; }
@media (min-width: 900px) { .map-side { width: 300px; flex: 0 0 300px; } }
#map { width: 100%; height: 60vh; min-height: 380px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: #e5e7eb; }
@media (min-width: 900px) { #map { height: calc(100vh - 160px); min-height: 500px; } }

.legend { display: flex; flex-direction: column; gap: 6px; max-height: 46vh; overflow: auto; }
.legend-item { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.legend-item:hover { background: #f8fafc; }
.legend-item.active { background: var(--primary-soft); outline: 1px solid #99f6e4; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 12px; }
.legend-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-count { color: var(--ink-3); font-size: 12px; }

.locate-list { display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow: auto; }
.locate-item { display: flex; justify-content: space-between; gap: 8px; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: 13px; border: 1px solid transparent; }
.locate-item:hover { background: #f8fafc; }
.locate-item.active { background: #fff7ed; border-color: #fdba74; }

/* ================= 其他 ================= */
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; }
.empty { text-align: center; color: var(--ink-3); padding: 36px 10px; font-size: 14px; }
.filter-grid { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
@media (min-width: 900px) { .filter-grid { grid-template-columns: repeat(4, 1fr); } }
.footer-note { text-align: center; color: var(--ink-3); font-size: 12px; padding: 14px 0 4px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding-top: 10px; flex-wrap: wrap; }
.pager button { min-width: 34px; }

/* 登录 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(160deg, #0f766e 0%, #115e59 55%, #0f172a 100%); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 16px; padding: 26px 22px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p.sub { margin: 0 0 20px; color: var(--ink-3); font-size: 13px; }
.login-card .field { margin-bottom: 14px; }
.login-card .err { color: var(--red); font-size: 13px; min-height: 20px; }

/* 模态 */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(15,23,42,.5); display: flex; align-items: flex-end; justify-content: center; padding: 0; }
@media (min-width: 620px) { .modal { align-items: center; padding: 24px; } }
.modal-box { background: #fff; width: 100%; max-width: 860px; max-height: 92vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 18px; position: relative; }
@media (min-width: 620px) { .modal-box { border-radius: 16px; } }
.modal-box h3 { margin: 0 0 14px; font-size: 16px; padding-right: 44px; }
.modal-close { position: absolute; right: 12px; top: 10px; width: 34px; height: 34px; border: 0; background: #f1f5f9; border-radius: 8px; font-size: 20px; line-height: 1; color: #6b7280; cursor: pointer; z-index: 2; }
.modal-close:hover { background: #e2e8f0; color: #111827; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* 回访记录 */
.visit-list { display: flex; flex-direction: column; gap: 8px; }
.visit-item { display: grid; grid-template-columns: 150px 1fr 34px; gap: 8px; align-items: start; }
@media (max-width: 620px) { .visit-item { grid-template-columns: 120px 1fr 34px; } }
.visit-item input { min-height: 36px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: rgba(17,24,39,.92); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; z-index: 100; max-width: 86vw; text-align: center; }
.toast.err { background: rgba(185,28,28,.95); }

.info-window { padding: 10px 12px; font-size: 13px; line-height: 1.7; min-width: 220px; }
.info-window b { font-size: 14px; }
