:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #e2e6ec;
  --line-soft: #eef1f5;
  --text: #1a1f28;
  --muted: #6b7280;
  --faint: #9aa3af;
  --brand: #1e3a5f;
  --accent: #2563eb;
  --danger: #b42318;
  --ok: #0f7b5f;
  --side-bg: #16202e;
  --side-text: #93a1b5;
  --side-active: #22304a;
  --side-width: 216px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.flex-1 { flex: 1; }

.boot {
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  letter-spacing: 0.04em;
}

/* ---------------- 登录 ---------------- */
.auth-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 372px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 34px 30px 28px;
}
.brand { font-size: 21px; font-weight: 600; letter-spacing: -0.01em; color: var(--brand); }
.brand-sub { margin: 2px 0 26px; font-size: 12.5px; color: var(--muted); }

label.field { display: block; margin-bottom: 15px; }
label.field > span { display: block; margin-bottom: 6px; font-size: 12.5px; color: var(--muted); }
.field-hint { display: block; margin-top: 6px; font-style: normal; font-size: 11.5px; color: var(--faint); }

input[type="text"], input[type="password"], input[type="search"], select, textarea {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

button {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
button:disabled { opacity: 0.55; cursor: default; }

.btn-primary { width: 100%; height: 40px; margin-top: 8px; background: var(--brand); color: #fff; font-weight: 500; }
.btn-primary:hover:not(:disabled) { background: #162c48; }
.btn-primary.btn-inline { width: auto; margin: 0; padding: 0 18px; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); padding: 6px 13px; }
.btn-ghost:hover:not(:disabled) { border-color: #c8ced8; color: var(--text); }
.btn-mini { background: #fff; border-color: var(--line); color: var(--muted); padding: 0 10px; height: 32px; font-size: 12px; white-space: nowrap; }
.btn-mini:hover:not(:disabled) { border-color: #c8ced8; color: var(--text); }

.err { margin-top: 14px; padding: 9px 12px; border-radius: 8px; background: #fdf2f1; border: 1px solid #f6d5d2; color: var(--danger); font-size: 12.5px; }
.hint { margin-top: 18px; font-size: 12px; color: var(--muted); text-align: center; }
.notice { padding: 10px 14px; border-radius: 9px; background: #fff8e6; border: 1px solid #f3e0b0; color: #7a5a10; font-size: 12.5px; margin-bottom: 16px; }

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

.sidebar {
  width: var(--side-width);
  flex: none;
  background: var(--side-bg);
  display: flex;
  flex-direction: column;
  padding: 16px 10px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
}
.side-brand { display: flex; align-items: center; gap: 9px; padding: 2px 8px 20px; }
.logo {
  width: 28px; height: 28px; flex: none;
  border-radius: 8px;
  background: #2b4a74;
  color: #dbe7f6;
  font-size: 11.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.02em;
}
.side-brand-text { display: flex; flex-direction: column; color: #e6edf7; font-size: 13.5px; font-weight: 600; line-height: 1.25; }
.side-brand-text em { font-style: normal; font-size: 10.5px; font-weight: 400; color: #64748b; margin-top: 2px; }

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--side-text);
  font-size: 13px;
  text-align: left;
}
.nav-item svg { width: 17px; height: 17px; flex: none; opacity: 0.85; }
.nav-item:hover { background: rgba(255, 255, 255, 0.05); color: #dbe4f0; }
.nav-item.is-on { background: var(--side-active); color: #eaf1fb; }
.nav-item.is-on svg { opacity: 1; }

.side-sep { height: 1px; background: rgba(255, 255, 255, 0.07); margin: 12px 8px; }

.side-foot { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid rgba(255, 255, 255, 0.07); }
.side-user { font-size: 11.5px; color: #7c8ba1; margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user b { display: block; color: #cbd6e5; font-weight: 500; font-size: 12.5px; }
.side-logout { width: 100%; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.09); color: #9fb0c6; padding: 6px 0; font-size: 12px; }
.side-logout:hover { background: rgba(255,255,255,0.09); color: #e6edf7; }

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

/* ---------------- 监控台 ---------------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 26px 64px; }
.page-head { margin-bottom: 16px; }
h1 { font-size: 19px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.page-desc { margin: 4px 0 0; font-size: 12px; color: var(--muted); }

.statusbar {
  display: flex; align-items: center; gap: 10px;
  background: #fffbe8; border: 1px solid #f2e2a8; border-radius: 9px;
  padding: 9px 14px; font-size: 11.5px; color: #7a5a10; margin-bottom: 16px;
}
.statusbar.is-ok { background: #f2f9f4; border-color: #cfe8d8; color: #14603f; }
.statusbar.is-empty { background: #f7f8fa; border-color: var(--line); color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #d1a11a; flex: none; }
.statusbar.is-ok .dot { background: #16a34a; }
.statusbar.is-empty .dot { background: #c3c9d2; }
.statusbar button { background: transparent; border-color: currentColor; color: inherit; padding: 3px 10px; font-size: 11px; opacity: 0.85; }
.statusbar button:hover:not(:disabled) { opacity: 1; }

.tabs { display: flex; align-items: flex-end; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tab {
  background: transparent; border: none; border-bottom: 2px solid transparent; border-radius: 0;
  padding: 9px 13px 10px; font-size: 13px; color: var(--muted); white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-on { color: var(--brand); font-weight: 500; border-bottom-color: var(--brand); }
.sub-hint { font-size: 10.5px; color: var(--faint); padding-bottom: 12px; white-space: nowrap; }

.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-bottom: 20px; }
@media (min-width: 1024px) { .kpi-grid { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 17px 18px; }
.kpi .k { font-size: 11.5px; color: var(--faint); font-weight: 500; }
.kpi .v { margin-top: 9px; font-size: 28px; font-weight: 600; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi .v .unit { font-size: 13px; font-weight: 500; color: var(--faint); margin-left: 4px; letter-spacing: 0; }
.kpi .v.is-ok { color: var(--ok); }
.kpi .s { margin-top: 9px; font-size: 11px; color: var(--faint); }

.grid2 { display: grid; grid-template-columns: 1fr; gap: 16px; margin-bottom: 16px; }
@media (min-width: 1024px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 17px 18px 18px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.panel-head h3 { margin: 0; font-size: 13.5px; font-weight: 600; }
.panel-head .note { font-size: 10.5px; color: var(--faint); }
.seg { display: flex; gap: 4px; }
.seg button { padding: 3px 9px; font-size: 10.5px; border-radius: 6px; background: transparent; color: var(--muted); border-color: transparent; }
.seg button:hover { background: #f1f3f7; }
.seg button.is-on { background: #1f2937; color: #fff; }

.stack { display: flex; height: 10px; border-radius: 6px; overflow: hidden; background: #f0f2f6; margin-bottom: 15px; }
.stack span { display: block; height: 100%; }
.legend-row { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.legend-row:last-child { margin-bottom: 0; }
.legend-dot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.legend-label { flex: 1; font-size: 11.5px; color: #4b5563; }
.legend-val { font-size: 11.5px; font-weight: 500; font-variant-numeric: tabular-nums; }
.legend-pct { width: 44px; text-align: right; font-size: 10.5px; color: var(--faint); font-variant-numeric: tabular-nums; }

.bar-row { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.bar-row:last-child { margin-bottom: 0; }
.bar-label { flex: none; width: 62px; font-size: 11.5px; color: #4b5563; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 7px; border-radius: 5px; background: #f0f2f6; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 5px; }
.bar-num { flex: none; width: 38px; text-align: right; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.empty-note { font-size: 11.5px; color: var(--faint); padding: 6px 0 2px; margin: 0; }
.panel-foot { font-size: 10px; color: var(--faint); padding-top: 8px; }

.monthly { display: flex; align-items: flex-end; gap: 5px; height: 96px; padding-top: 6px; }
.monthly .m { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; justify-content: flex-end; }
.monthly .m i { display: block; width: 100%; max-width: 26px; background: #c7d2e4; border-radius: 3px 3px 0 0; }
.monthly .m em { font-style: normal; font-size: 9.5px; color: var(--faint); white-space: nowrap; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th { text-align: left; font-weight: 500; font-size: 11.5px; color: var(--faint); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fafbfc; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); font-size: 12.5px; vertical-align: top; }
tr:last-child td { border-bottom: none; }
td.name { font-weight: 500; color: var(--brand); }
td.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 11px 14px; border-top: 1px solid var(--line); }
.pager span { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pager button { background: #fff; border-color: var(--line); color: var(--text); padding: 4px 12px; font-size: 12.5px; }
.pager button:hover:not(:disabled) { border-color: #c8ced8; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); gap: 14px; }
.pcard { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 15px 16px; }
.pcard .top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.pcard .name { font-size: 13.5px; font-weight: 600; color: var(--brand); }
.pcard .rating { flex: none; font-size: 11px; padding: 1px 7px; border-radius: 20px; background: #eef2f8; color: var(--brand); }
.pcard .meta { margin-top: 5px; font-size: 11.5px; color: var(--muted); }
.pcard .sum { margin-top: 9px; font-size: 11.5px; color: #4b5563; line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pcard .foot { margin-top: 11px; padding-top: 9px; border-top: 1px solid var(--line-soft); display: flex; justify-content: space-between; font-size: 11px; color: var(--faint); }

.placeholder { background: var(--panel); border: 1px dashed #d6dbe3; border-radius: 12px; padding: 56px 28px; text-align: center; }
.placeholder h3 { margin: 0 0 8px; font-size: 14px; font-weight: 600; }
.placeholder p { margin: 0 auto; max-width: 460px; font-size: 12px; color: var(--muted); line-height: 1.7; }

/* ---------------- AI 助手 ---------------- */
#view-chat { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 1180px; margin: 0 auto; padding: 22px 26px 18px; }
.chat-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.chat-tools { display: flex; align-items: center; gap: 10px; flex: none; }
.model-pick { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.model-pick select { width: 210px; height: 34px; font-size: 12.5px; }

.chat-body { flex: 1; overflow-y: auto; padding: 20px 2px; display: flex; flex-direction: column; gap: 14px; }
.chat-empty { margin: auto; text-align: center; color: var(--faint); font-size: 13px; }
.chat-empty .sub { font-size: 11.5px; margin-top: 6px; }

.msg { display: flex; gap: 10px; max-width: 860px; }
.msg .avatar { width: 26px; height: 26px; flex: none; border-radius: 7px; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.user .avatar { background: #dbe7f6; color: #1e3a5f; }
.msg.assistant .avatar { background: #e6e9ee; color: #475569; }
.msg .bubble { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 13px; font-size: 13px; line-height: 1.75; white-space: pre-wrap; word-break: break-word; }
.msg.user .bubble { background: #1e3a5f; border-color: #1e3a5f; color: #eef4fb; }
.msg .meta-line { font-size: 10.5px; color: var(--faint); margin-top: 6px; }
.cursor-blink::after { content: "▌"; color: var(--faint); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.chat-input { display: flex; gap: 10px; align-items: flex-end; padding-top: 12px; border-top: 1px solid var(--line); }
.chat-input textarea { flex: 1; min-height: 62px; max-height: 180px; }
.chat-send { width: 92px; height: 62px; margin: 0; flex: none; }

/* ---------------- 弹窗 ---------------- */
.modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal-card {
  width: 100%; max-width: 620px; max-height: 88vh;
  background: #fff; border-radius: 14px;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 22px 14px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-head p { margin: 4px 0 0; font-size: 11.5px; color: var(--muted); }
.modal-x { background: transparent; border: none; color: var(--faint); font-size: 22px; line-height: 1; padding: 0 4px; }
.modal-x:hover { color: var(--text); }
.modal-body { padding: 16px 22px; overflow-y: auto; }
.modal-foot { display: flex; align-items: center; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); background: #fafbfc; }

.chan-list-head { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 8px; }

.modal-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.mtab {
  background: transparent; border: none; border-bottom: 2px solid transparent; border-radius: 0;
  padding: 7px 10px 9px; font-size: 12.5px; color: var(--muted); white-space: nowrap;
}
.mtab:hover { color: var(--text); }
.mtab.is-on { color: var(--brand); font-weight: 500; border-bottom-color: var(--brand); }
.tab-hint { margin: 0 0 14px; font-size: 11px; color: var(--faint); line-height: 1.6; }
.chan-list { display: flex; flex-direction: column; gap: 6px; }
.chan-item {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px;
  cursor: pointer; background: #fff;
}
.chan-item:hover { border-color: #cbd3de; }
.chan-item.is-on { border-color: var(--brand); background: #f4f7fb; }
.chan-item .ci-name { font-size: 12.5px; font-weight: 500; color: var(--text); }
.chan-item .ci-sub { font-size: 11px; color: var(--faint); }
.chan-item .ci-body { flex: 1; min-width: 0; }
.chan-item .ci-del { background: transparent; border: none; color: var(--faint); font-size: 12px; padding: 2px 6px; }
.chan-item .ci-del:hover { color: var(--danger); }
.chan-empty { font-size: 11.5px; color: var(--faint); padding: 8px 2px; }

.form-sep { height: 1px; background: var(--line); margin: 16px 0; }
.key-row { display: flex; gap: 8px; align-items: center; }
.key-row input { flex: 1; }
.test-result { margin-top: 12px; padding: 9px 12px; border-radius: 8px; font-size: 12px; }
.test-result.ok { background: #f2f9f4; border: 1px solid #cfe8d8; color: #14603f; }
.test-result.bad { background: #fdf2f1; border: 1px solid #f6d5d2; color: var(--danger); }

.toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); background: #1f2937; color: #fff; padding: 9px 18px; border-radius: 8px; font-size: 13px; z-index: 80; }

/* ---------------- 响应式 ---------------- */
@media (max-width: 900px) {
  :root { --side-width: 60px; }
  .side-brand-text, .nav-item span, .side-user, .side-logout { display: none; }
  .side-brand { justify-content: center; padding: 2px 0 18px; }
  .nav-item { justify-content: center; padding: 10px 0; }
  .side-foot { display: none; }
  .wrap { padding: 18px 14px 50px; }
  #view-chat { padding: 16px 14px 14px; }
  .chat-head { flex-direction: column; }
  .model-pick select { width: 100%; }
  .bar-label { width: 52px; }
  .msg { max-width: 100%; }
}

/* ---------------- 产业地图 ---------------- */
.map-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.map-filters { display: flex; gap: 8px; flex-wrap: wrap; }
.map-filters select { height: 32px; padding: 0 8px; font-size: 12.5px; width: auto; }
.map-meta { font-size: 11.5px; color: var(--muted); margin-left: auto; }

.map-wrap { padding: 0; overflow: hidden; position: relative; }
#map-canvas { width: 100%; height: 560px; }
.map-fallback {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px;
  background: rgba(255, 255, 255, 0.95); padding: 32px; text-align: center;
}
.map-fallback h4 { margin: 0; font-size: 13.5px; font-weight: 600; color: var(--danger); }
.map-fallback p { margin: 0; max-width: 460px; font-size: 12px; color: var(--muted); line-height: 1.7; }

.unloc-row { display: flex; align-items: baseline; gap: 8px; padding: 5px 0; font-size: 12px; border-bottom: 1px dashed var(--line-soft); }
.unloc-row:last-child { border-bottom: 0; }
.unloc-tag {
  flex: none; font-size: 10px; padding: 1px 6px; border-radius: 4px;
  background: #f1f3f6; color: var(--muted); border: 1px solid var(--line);
}
.unloc-name { color: var(--text); }
.unloc-raw { color: var(--faint); font-size: 11px; }

/* ---------------- 项目导出 ---------------- */
.export-filters { display: flex; gap: 8px; flex-wrap: wrap; }
.export-filters input[type="search"], .export-filters select { height: 34px; font-size: 13px; width: auto; }
.export-filters input[type="search"] { width: 240px; }
.export-foot {
  display: flex; align-items: center; gap: 10px;
  margin-top: 15px; padding-top: 14px; border-top: 1px solid var(--line-soft);
}
.export-foot .map-meta { margin-left: 0; }

@media (max-width: 720px) {
  #map-canvas { height: 380px; }
  .export-filters input[type="search"] { width: 100%; }
  .map-meta { margin-left: 0; }
}
