:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #94a3b8;
  --brand: #0f766e;
  --brand-2: #14b8a6;
  --danger: #dc2626;
  --warn: #d97706;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px -12px rgba(15, 23, 42, .18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 布局 ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 216px;
  flex: 0 0 216px;
  background: #0f172a;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px 14px; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
  color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center;
  font-size: 17px; flex: 0 0 34px;
}
.brand-logo.big { width: 46px; height: 46px; font-size: 22px; border-radius: 13px; margin: 0 auto 12px; }
.brand-text b { display: block; color: #f8fafc; font-size: 14px; line-height: 1.3; }
.brand-text span { font-size: 11px; color: #64748b; letter-spacing: .02em; }

.nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px; color: #cbd5e1; font-size: 13.5px;
}
.nav-item i { font-style: normal; width: 16px; text-align: center; opacity: .7; font-size: 13px; }
.nav-item:hover { background: #1e293b; color: #fff; text-decoration: none; }
.nav-item.active { background: linear-gradient(90deg, rgba(20, 184, 166, .22), rgba(20, 184, 166, .06)); color: #5eead4; font-weight: 600; }
.nav-item.active i { opacity: 1; }

.sidebar-foot { padding: 12px; border-top: 1px solid #1e293b; }
.user { display: flex; gap: 9px; align-items: center; margin-bottom: 10px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #334155; color: #e2e8f0; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.user-meta b { display: block; color: #e2e8f0; font-size: 13px; line-height: 1.2; }
.user-meta span { font-size: 11px; color: #64748b; }
.logout { display: block; text-align: center; padding: 7px; border-radius: 7px; background: #1e293b; color: #94a3b8; font-size: 12.5px; }
.logout:hover { background: #334155; color: #fff; text-decoration: none; }

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

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: baseline; gap: 10px; }
.topbar h1 { font-size: 17px; margin: 0; font-weight: 700; letter-spacing: .2px; }
.ver { font-size: 11px; color: var(--ink-3); }
.badge-key { font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); }
.badge-key.ok { color: #047857; background: #ecfdf5; border-color: #a7f3d0; }
.badge-key.warn { color: #b45309; background: #fffbeb; border-color: #fde68a; }

.content { padding: 16px 20px 20px; flex: 1; min-width: 0; }
.foot { padding: 10px 20px 18px; color: var(--ink-3); font-size: 11.5px; }

.flash { margin: 12px 20px 0; padding: 10px 14px; border-radius: 8px; font-size: 13px; transition: opacity .4s; }
.flash-ok { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.flash-err { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.flash.fade { opacity: .35; }

/* ---------- 基础控件 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid transparent;
  font-size: 13px; font-weight: 600; cursor: pointer; background: #f1f5f9; color: var(--ink);
  transition: all .15s; font-family: inherit;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: #0d6259; }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink-2); }
.btn.ghost:hover { border-color: #cbd5e1; color: var(--ink); }
.btn.ghost.danger { color: var(--danger); border-color: #fecaca; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 5px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 13px; font-family: inherit; background: #fff; color: var(--ink); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(20, 184, 166, .12); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.check { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2); cursor: pointer; }
.hint { font-size: 12px; color: var(--ink-3); line-height: 1.6; margin: 8px 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.card + .card { margin-top: 14px; }
.card h2 { font-size: 15px; margin: 0 0 4px; }
.card .sub { color: var(--ink-3); font-size: 12px; margin-bottom: 14px; }

.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { font-size: 12px; color: var(--ink-3); }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -.5px; line-height: 1.25; }
.stat .value small { font-size: 12px; font-weight: 500; color: var(--ink-3); margin-left: 4px; }

/* ---------- 表格 ---------- */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: #f8fafc; color: var(--ink-2); font-weight: 600; font-size: 12.5px; white-space: nowrap; position: sticky; top: 0; z-index: 2; }
tr:hover td { background: #f8fafc; }
td.num { font-variant-numeric: tabular-nums; }
.empty-row { text-align: center; color: var(--ink-3); padding: 34px 0; }
td.col-name { min-width: 190px; }
td.col-type, td.col-dist, td.col-tel { white-space: nowrap; }
td.col-type { max-width: 170px; overflow: hidden; text-overflow: ellipsis; }
td.col-addr { max-width: 240px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
td.col-brand { white-space: nowrap; min-width: 88px; }
.table-wrap > table { min-width: 1060px; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.st-new { background: #eff6ff; color: #1d4ed8; }
.st-intent { background: #fff7ed; color: #c2410c; }
.st-signed { background: #ecfdf5; color: #047857; }
.st-no { background: #f1f5f9; color: #64748b; }
.st-rival { background: #fef2f2; color: #b91c1c; }

.pager { display: flex; align-items: center; gap: 6px; justify-content: flex-end; padding: 12px 14px; font-size: 12.5px; color: var(--ink-2); }
.pager a, .pager span.btn-page { padding: 4px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink-2); }
.pager a:hover { border-color: var(--brand-2); color: var(--brand); text-decoration: none; }
.pager .cur { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- 登录 ---------- */
.login-body { background: radial-gradient(1200px 600px at 20% 10%, #134e4a 0%, #0f172a 55%, #0b1220 100%); min-height: 100vh; }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 380px; background: rgba(255, 255, 255, .98); border-radius: 16px; padding: 30px 28px; box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .55); }
.login-head { text-align: center; margin-bottom: 20px; }
.login-head h1 { font-size: 18px; margin: 0 0 6px; }
.login-head p { font-size: 12px; color: var(--ink-3); margin: 0; }
.login-tip { margin-top: 14px; font-size: 11.5px; color: var(--ink-3); text-align: center; }

/* ---------- 地图页 ---------- */
.map-page { display: grid; grid-template-columns: 292px minmax(0, 1fr) 348px; gap: 12px; height: calc(100vh - 148px); }
.map-panel { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; padding-right: 2px; }
.panel-block { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; box-shadow: var(--shadow); }
.panel-block h3 { font-size: 12.5px; color: var(--ink-2); margin: 0 0 10px; font-weight: 700; letter-spacing: .3px; }
.draw-tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.draw-tools .btn { padding: 7px 4px; font-size: 12px; }
/* 圈选区域大小调整手柄（白色方块，可拖动） */
.shape-handle { width: 12px !important; height: 12px !important; background: #ffffff; border: 2px solid #0f766e; border-radius: 2px; box-shadow: 0 0 0 1px rgba(15, 118, 110, .25), 0 1px 3px rgba(0, 0, 0, .35); cursor: grab; }
.shape-handle:active { cursor: grabbing; }

/* POI 分类多选组件 */
.ms { position: relative; }
.ms-toggle { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: left; padding: 8px 10px; font-size: 13px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm, 8px); cursor: pointer; }
.ms-cur { display: block; flex: 1 1 auto; min-width: 0; font-size: 13px; font-weight: 400; color: var(--ink); margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-toggle i { font-style: normal; color: var(--ink-2); transition: transform .15s; }
.ms.is-open .ms-toggle i { transform: rotate(180deg); }
.ms-panel { position: absolute; z-index: 1200; left: 0; right: 0; top: calc(100% + 4px); max-height: 340px; overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm, 8px); box-shadow: 0 12px 32px -10px rgba(15, 23, 42, .35); padding: 8px; }
.ms-filter { width: 100%; margin-bottom: 6px; padding: 6px 8px; font-size: 12.5px; border: 1px solid var(--line); border-radius: 6px; }
.ms-actions { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.ms-act { font-size: 11.5px; padding: 3px 8px; border: 1px solid var(--line); background: #f8fafc; border-radius: 999px; cursor: pointer; color: var(--ink-2); }
.ms-act:hover { background: #eef2f7; }
.ms-act-tip { display: block; flex: 1 1 auto; min-width: 0; margin: 0; font-size: 11px; font-weight: 400; color: #94a3b8; }
.ms-group { margin-bottom: 6px; }
.ms-group-head { display: flex; align-items: center; justify-content: space-between; font-size: 11.5px; color: var(--ink-2); font-weight: 700; padding: 4px 2px; border-bottom: 1px dashed var(--line); margin-bottom: 3px; }
.ms-gname { display: block; margin: 0; font-size: 11.5px; font-weight: 700; color: var(--ink-2); }
.ms-gall { font-size: 11px; padding: 1px 6px; border: 1px solid var(--line); background: #fff; border-radius: 5px; cursor: pointer; color: var(--ink-2); }
.ms-item { display: flex; align-items: center; gap: 7px; padding: 4px 3px; font-size: 12.5px; cursor: pointer; border-radius: 5px; margin: 0; }
.ms-item:hover { background: #f1f5f9; }
.ms-item input { width: auto !important; height: auto !important; padding: 0; border: 0; box-shadow: none; margin: 0; flex: 0 0 auto; }
.ms-label { flex: 1 1 auto; min-width: 0; display: block; font-size: 12.5px; font-weight: 400; color: var(--ink); margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-group.hide, .ms-item.hide { display: none; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 10px; font-size: 12px; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-item i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.legend-item em { font-style: normal; font-size: 10px; color: #b91c1c; background: #fef2f2; border-radius: 4px; padding: 0 4px; }
.key-warn { margin-top: 10px; font-size: 12px; background: #fffbeb; border: 1px solid #fde68a; color: #92400e; padding: 8px 10px; border-radius: 8px; line-height: 1.6; }
.key-warn.hide { display: none; }

.map-canvas-wrap { position: relative; background: #e2e8f0; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow); min-height: 320px; }
.map-canvas { position: absolute; inset: 0; }
.map-loading { position: absolute; left: 50%; top: 16px; transform: translateX(-50%); z-index: 900; background: #0f172a; color: #e2e8f0; font-size: 12.5px; padding: 8px 14px; border-radius: 999px; display: flex; align-items: center; gap: 8px; box-shadow: 0 8px 24px -8px rgba(0, 0, 0, .5); }
.map-loading.hide { display: none; }
.spinner { width: 13px; height: 13px; border: 2px solid rgba(255, 255, 255, .35); border-top-color: #5eead4; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.map-stats { position: absolute; left: 12px; bottom: 12px; z-index: 900; background: rgba(255, 255, 255, .96); border: 1px solid var(--line); padding: 7px 12px; border-radius: 8px; font-size: 12px; color: var(--ink-2); box-shadow: 0 6px 18px -10px rgba(0, 0, 0, .4); }
.map-stats b { color: var(--ink); font-size: 14px; }
.cache-tag { color: #047857; background: #ecfdf5; border-radius: 4px; padding: 0 5px; }
.warn-tag { color: #b45309; background: #fffbeb; border-radius: 4px; padding: 0 5px; }
.map-stats.hide { display: none; }

.result-panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow); }
.result-head { padding: 12px 14px 10px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.result-head h3 { font-size: 13.5px; margin: 0; }
#resultSummary { font-size: 11.5px; color: var(--ink-3); margin: 2px 0 0; }
.brand-filter { display: flex; flex-wrap: wrap; gap: 6px; padding: 9px 12px; border-bottom: 1px solid var(--line); max-height: 110px; overflow-y: auto; }
.fchip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 9px; font-size: 11.5px; color: var(--ink-2); cursor: pointer; font-family: inherit; }
.fchip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.result-list { flex: 1; overflow-y: auto; padding: 6px; }
.result-item { padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.result-item:hover { background: #f1f5f9; }
.ri-name { font-size: 13px; font-weight: 600; }
.ri-sub { font-size: 11.5px; color: var(--ink-3); margin: 2px 0 5px; }
.ri-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.chip { font-size: 10.5px; border: 1px solid; border-radius: 4px; padding: 0 5px; }
.chip.grey { border-color: #cbd5e1; color: #64748b; }
.tel { font-size: 11px; color: var(--ink-2); }
.empty { color: var(--ink-3); text-align: center; padding: 36px 10px; font-size: 12.5px; }

.pop { font-size: 12.5px; line-height: 1.6; }
.pop b { font-size: 13.5px; }
.pop-brand { display: inline-block; margin-left: 6px; color: #fff; font-size: 10.5px; padding: 0 6px; border-radius: 4px; vertical-align: middle; }
.pop-row { color: var(--ink-2); }
.pop-link { display: inline-block; margin-top: 6px; font-size: 12px; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  background: #0f172a; color: #f8fafc; font-size: 13px; padding: 10px 16px; border-radius: 10px;
  z-index: 9999; box-shadow: 0 16px 40px -14px rgba(0, 0, 0, .6); max-width: 80vw;
}
.toast-err { background: #b91c1c; }
.toast-warn { background: #b45309; }
.toast.out { opacity: 0; transform: translate(-50%, 8px); transition: all .3s; }

/* ---------- 工具类 ---------- */
.hide { display: none !important; }
.mt8 { margin-top: 8px; } .mt14 { margin-top: 14px; } .mb8 { margin-bottom: 8px; }
.muted { color: var(--ink-3); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.toolbar .field { margin-bottom: 0; min-width: 130px; }
.inline-form { display: inline-block; }
textarea { resize: vertical; }
.brand-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 5px; vertical-align: middle; }

/* ---------- 响应式 ---------- */
@media (max-width: 1440px) {
  .map-page { grid-template-columns: 268px minmax(0, 1fr) 316px; }
}

@media (max-width: 1280px) {
  .map-page { grid-template-columns: 1fr; height: auto; }
  .map-panel { flex-direction: row; flex-wrap: wrap; overflow: visible; align-items: flex-start; }
  .panel-block { flex: 1 1 300px; }
  .map-canvas-wrap { height: 460px; }
  .result-panel { height: 440px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr !important; }
}

@media (max-width: 900px) {
  .sidebar { width: 64px; flex: 0 0 64px; }
  .brand-text, .user-meta, .nav-item span, .logout { display: none; }
  .brand { padding: 14px 10px; justify-content: center; }
  .nav-item { justify-content: center; padding: 10px 6px; }
  .nav-item i { width: auto; font-size: 15px; }
  .user { justify-content: center; margin-bottom: 6px; }
  .content { padding: 12px; }
  .topbar { padding: 10px 12px; }
}
