*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --bg: #f8fafc;
  --panel-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 24px rgba(0,0,0,.08);
  --radius: 10px;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--text); }

#app { display: flex; flex-direction: column; height: 100vh; position: relative; }

.map-wrap {
  flex: 1; display: flex; min-height: 0; position: relative; width: 100%;
}

.map-main {
  flex: 1; min-height: 0; min-width: 0; position: relative;
}

#map-container { width: 100%; height: 100%; min-height: 0; contain: strict; }

.loading-overlay {
  position: absolute; inset: 0; z-index: 200;
  background: rgba(248,250,252,.85);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
}
.loading-overlay.hidden { display: none; }
.loading-spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin .8s linear infinite;
}
.loading-text { font-size: 14px; color: var(--text-muted); }
@keyframes spin { to { transform: rotate(360deg); } }


.analytics-panel {
  width: 320px; background: #fff; border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0,0,0,.06); z-index: 50;
  display: flex; flex-direction: column; min-height: 0; flex-shrink: 0;
  padding: 12px 14px; overflow: hidden;
}
.analytics-panel.hidden { display: none; }
.analytics-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; flex-shrink: 0; }
.analytics-header h3 { font-size: 15px; }
.analytics-summary { font-size: 11px; color: var(--text-muted); margin-bottom: 10px; line-height: 1.5; flex-shrink: 0; }
.analytics-panel .chart-box { width: 100%; height: 150px; flex-shrink: 0; }
.chart-label { font-size: 12px; color: var(--text-muted); margin: 6px 0 8px; text-align: center; flex-shrink: 0; }
.analytics-list-title { margin-top: 2px; margin-bottom: 6px; font-weight: 600; color: var(--text); text-align: left; }
.analytics-school-list {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); -webkit-overflow-scrolling: touch;
}
.school-list { list-style: none; margin: 0; padding: 4px 0; }
.school-list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-bottom: 1px solid var(--border); cursor: pointer;
  font-size: 13px; transition: background .15s;
}
.school-list-item:last-child { border-bottom: none; }
.school-list-item:hover { background: #fff; }
.school-list-name { flex: 1; min-width: 0; font-weight: 500; line-height: 1.4; }
.school-list-meta { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.school-list-score { font-size: 11px; color: var(--primary); font-weight: 600; white-space: nowrap; }
.school-list-empty { margin: 0; padding: 20px 12px; text-align: center; font-size: 12px; color: var(--text-muted); }
.btn-icon-light {
  background: var(--bg); border: none; width: 28px; height: 28px;
  border-radius: 6px; cursor: pointer; font-size: 18px; color: var(--text-muted);
}

.checkbox-group {
  display: flex; flex-wrap: wrap; gap: 6px 10px; padding: 6px 0;
}
.chk-item {
  font-size: 12px; display: inline-flex; align-items: center; gap: 4px;
  cursor: pointer; user-select: none;
}
.chk-item input { accent-color: var(--primary); }

.baike-table {
  width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 8px;
}
.baike-table th, .baike-table td {
  border: 1px solid var(--border); padding: 6px 8px; text-align: center;
}
.baike-table th { background: var(--bg); font-weight: 600; }
.baike-source { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.modal-links { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; }

@media (max-width: 900px) {
  .analytics-panel {
    position: absolute; right: 0; top: 0; bottom: 0; width: min(100%, 320px);
  }
  .map-wrap { flex-direction: column; }
  .scope-note {
    left: 8px; right: 8px; bottom: 8px; max-width: none; font-size: 10px;
  }
}

.panel {
  position: absolute; top: 16px; z-index: 100;
  width: 300px; max-height: calc(100vh - 100px);
  background: var(--panel-bg); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
  transition: width .3s, opacity .3s;
}

#filter-panel { left: 16px; }
#ranking-panel { left: 332px; }

.ranking-panel .panel-body { display: flex; flex-direction: column; min-height: 0; }
.major-rank-summary {
  font-size: 11px; color: var(--text-muted); margin-bottom: 8px; line-height: 1.5; flex-shrink: 0;
}
.major-rank-list {
  flex: 1; min-height: 180px; max-height: calc(100vh - 280px);
  overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
.major-rank-empty, .major-suggest-empty {
  margin: 0; padding: 18px 12px; text-align: center; font-size: 12px; color: var(--text-muted);
}
.major-suggest-list {
  list-style: none; margin: 4px 0 0; padding: 0; max-height: 220px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; box-shadow: var(--shadow);
}
.major-suggest-list.hidden { display: none; }
.major-suggest-item {
  padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px;
}
.major-suggest-item:last-child { border-bottom: none; }
.major-suggest-item:hover { background: var(--primary-light); }
.major-suggest-name { font-size: 13px; font-weight: 600; color: var(--text); }
.major-suggest-meta { font-size: 11px; color: var(--text-muted); }
.major-rank-ol { list-style: none; margin: 0; padding: 4px 0; counter-reset: rank; }
.major-rank-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.major-rank-row:last-child { border-bottom: none; }
.major-rank-row.is-clickable { cursor: pointer; }
.major-rank-row.is-clickable:hover { background: #fff; }
.major-rank-no {
  width: 28px; flex-shrink: 0; font-weight: 700; color: var(--primary); text-align: center;
}
.major-rank-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.major-rank-school { font-weight: 500; line-height: 1.35; }
.major-rank-sub { font-size: 11px; color: var(--text-muted); }
.major-rank-meta { display: flex; align-items: center; gap: 6px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.major-rank-grade { font-size: 11px; color: #4338ca; font-weight: 600; }
.field-label-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.field-label-row label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.btn-link {
  border: none; background: none; padding: 0; font-size: 12px; color: var(--primary);
  cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn-link:hover { text-decoration: underline; }

.modal-catalog {
  max-width: 820px; width: 94%; max-height: 88vh; display: flex; flex-direction: column;
  overflow: hidden;
}
.major-catalog-content {
  padding: 20px 22px 16px; display: flex; flex-direction: column; min-height: 0; flex: 1;
}
.major-catalog-title { font-size: 18px; font-weight: 700; margin-bottom: 4px; padding-right: 28px; }
.major-catalog-desc { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }
.major-catalog-search {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; margin-bottom: 12px; outline: none;
}
.major-catalog-search:focus { border-color: var(--primary); }
.major-catalog-body {
  display: flex; gap: 12px; min-height: 0; flex: 1; overflow: hidden;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
}
.major-catalog-nav {
  width: 132px; flex-shrink: 0; overflow-y: auto; border-right: 1px solid var(--border);
  background: #fff; padding: 6px 0;
}
.major-catalog-nav-item {
  display: block; width: 100%; text-align: left; border: none; background: none;
  padding: 9px 12px; font-size: 13px; cursor: pointer; color: var(--text);
  border-left: 3px solid transparent;
}
.major-catalog-nav-item:hover { background: var(--primary-light); }
.major-catalog-nav-item.active {
  background: var(--primary-light); color: var(--primary); font-weight: 600;
  border-left-color: var(--primary);
}
.major-catalog-detail {
  flex: 1; min-width: 0; overflow-y: auto; padding: 10px 12px 12px; background: #fff;
}
.major-catalog-group { margin-bottom: 14px; }
.major-catalog-group-title {
  font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px;
  padding-bottom: 4px; border-bottom: 1px dashed var(--border);
}
.major-catalog-majors { display: flex; flex-wrap: wrap; gap: 6px; }
.major-catalog-major {
  border: 1px solid var(--border); background: var(--bg); border-radius: 6px;
  padding: 6px 10px; font-size: 12px; cursor: pointer; color: var(--text);
  display: inline-flex; align-items: center; gap: 6px; transition: background .15s, border-color .15s;
}
.major-catalog-major:hover { background: var(--primary-light); border-color: #93c5fd; }
.major-catalog-major.no-rank { opacity: .85; }
.major-catalog-badge {
  font-size: 10px; padding: 1px 5px; border-radius: 4px; background: #e2e8f0; color: #64748b;
}
.major-catalog-badge.ranked { background: #dbeafe; color: #1d4ed8; }
.major-catalog-empty {
  padding: 40px 16px; text-align: center; color: var(--text-muted); font-size: 13px;
}

@media (max-width: 640px) {
  .major-catalog-body { flex-direction: column; max-height: 55vh; }
  .major-catalog-nav {
    width: 100%; max-height: 120px; border-right: none; border-bottom: 1px solid var(--border);
    display: flex; flex-wrap: wrap; gap: 4px; padding: 8px;
  }
  .major-catalog-nav-item {
    width: auto; border-left: none; border-radius: 6px; padding: 6px 10px;
  }
  .major-catalog-nav-item.active { border-left: none; }
}

.major-rank-score { font-size: 11px; color: var(--primary); font-weight: 600; }

.panel.collapsed { width: 48px; }
.panel.collapsed .panel-body { display: none; }
.panel.collapsed .panel-header h2 { display: none; }

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--primary); color: #fff;
}

.panel-header h2 { font-size: 16px; font-weight: 600; }

.panel-body { padding: 14px 16px; overflow-y: auto; max-height: calc(100vh - 160px); }

.stat-badge {
  background: var(--primary-light); color: var(--primary);
  padding: 8px 12px; border-radius: 6px; font-size: 14px; font-weight: 600;
  margin-bottom: 6px; text-align: center;
}
.data-meta {
  font-size: 11px; color: var(--text-muted); text-align: center;
  margin-bottom: 12px; line-height: 1.4;
}

.scope-note {
  position: absolute; left: 12px; bottom: 12px; z-index: 10;
  max-width: min(360px, calc(100% - 24px));
  padding: 8px 10px; border-radius: 8px;
  background: rgba(255, 255, 255, .94);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(15, 23, 42, .08);
  font-size: 11px; color: var(--text-muted); line-height: 1.5;
  pointer-events: none;
}
.scope-note-head {
  display: flex; align-items: center; gap: 6px; margin-bottom: 2px;
}
.scope-note strong { font-size: 12px; color: var(--text); }
.scope-note p { margin: 0; }
.scope-help-wrap {
  pointer-events: auto; position: relative; flex-shrink: 0;
}
.scope-help {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--primary-light); color: var(--primary);
  font-size: 11px; font-weight: 700; line-height: 1;
  cursor: help;
}
.scope-tip {
  pointer-events: none;
  display: none; position: absolute; left: 0; bottom: calc(100% + 8px);
  width: min(320px, 80vw); padding: 10px 12px;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(15, 23, 42, .12);
  font-size: 11px; color: var(--text-muted); line-height: 1.55;
  text-align: left; z-index: 10;
}
.scope-tip[hidden] { display: none !important; }
.scope-tip p { margin: 0 0 6px; }
.scope-tip p:last-child { margin-bottom: 0; }
.scope-tip b { color: var(--text); font-weight: 600; }
.scope-help-wrap:hover .scope-tip,
.scope-help-wrap:focus-within .scope-tip {
  display: block !important;
}

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field span { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.field input, .field select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; outline: none; transition: border-color .2s;
}
.field input:focus, .field select:focus { border-color: var(--primary); }

.range-inputs { display: flex; align-items: center; gap: 6px; }
.range-inputs input { flex: 1; min-width: 0; }
.range-inputs span { color: var(--text-muted); }

.divider { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.section-title { font-size: 13px; font-weight: 600; margin-bottom: 10px; color: var(--text); }

.btn-icon {
  background: rgba(255,255,255,.2); border: none; color: #fff;
  width: 28px; height: 28px; border-radius: 6px; cursor: pointer; font-size: 18px;
}
.btn-icon:hover { background: rgba(255,255,255,.35); }

.btn-secondary {
  width: 100%; padding: 9px; margin-top: 4px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; cursor: pointer; color: var(--text);
}
.btn-secondary:hover { background: var(--border); }

#footer {
  padding: 8px 16px; background: #fff; border-top: 1px solid var(--border);
  font-size: 11px; color: var(--text-muted); text-align: center;
}
#footer .note { margin-top: 2px; font-size: 10px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: #fff; border-radius: 12px; width: 90%; max-width: 560px;
  max-height: 85vh; overflow-y: auto; position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.modal-close {
  position: absolute; top: 12px; right: 14px; background: none; border: none;
  font-size: 24px; cursor: pointer; color: var(--text-muted); z-index: 1;
}
.modal-close:hover { color: var(--text); }

.modal-content { padding: 24px; }

.modal-photo {
  width: 100%; height: 180px; object-fit: cover; border-radius: 8px;
  margin-bottom: 16px; background: var(--bg);
}

.modal-header { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.modal-logo {
  width: 56px; height: 56px; border-radius: 8px; object-fit: contain;
  background: var(--bg); border: 1px solid var(--border);
}
.modal-logo-fallback {
  width: 56px; height: 56px; border-radius: 8px; background: var(--primary-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; color: var(--primary);
}
.modal-title { font-size: 20px; font-weight: 700; }
.modal-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag {
  font-size: 11px; padding: 2px 8px; border-radius: 4px;
  background: var(--primary-light); color: var(--primary);
}
.tag-985 { background: #dbeafe; color: #1d4ed8; }
.tag-211 { background: #e0e7ff; color: #4338ca; }
.tag-dfc { background: #ede9fe; color: #6d28d9; }
.tag-yiben { background: #e2e8f0; color: #475569; }
.tag-erben { background: #f1f5f9; color: #64748b; }
.tag-qita { background: #f8fafc; color: #94a3b8; border: 1px solid var(--border); }

.modal-section { margin-bottom: 14px; }
.modal-section h4 { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.modal-section p, .modal-section li { font-size: 14px; line-height: 1.6; }
.modal-section ul { padding-left: 18px; }

.modal-link {
  display: inline-block; margin-top: 8px; color: var(--primary);
  text-decoration: none; font-size: 14px;
}
.modal-link:hover { text-decoration: underline; }

.score-info {
  background: var(--bg); padding: 10px 14px; border-radius: 8px; font-size: 13px;
}
.score-info .no-data { color: var(--text-muted); font-style: italic; }

@media (max-width: 640px) {
  .panel { width: calc(100% - 32px); max-height: 42vh; left: 16px !important; right: 16px; }
  #ranking-panel { top: calc(42vh + 24px); }
  .panel.collapsed { width: 48px; }
  .major-rank-list { max-height: 28vh; }
}
