:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --border: #dfe5ef;
  --blue: #2563eb;
  --blue-dark: #1e40af;
  --green: #0f8f6f;
  --amber: #b7791f;
  --red: #c2410c;
  --shadow: 0 10px 28px rgba(25, 38, 64, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--blue);
  text-decoration: none;
}

.app-shell {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: #fff;
  font-weight: 800;
  background: var(--blue);
  border-radius: 8px;
  flex: 0 0 auto;
}

.brand-block h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.brand-block p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.top-actions,
.button-row,
.policy-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.primary-action,
.outline-action,
.text-action,
.icon-action {
  border-radius: 8px;
  min-height: 38px;
  border: 1px solid transparent;
  padding: 0 14px;
  background: transparent;
}

.primary-action {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}

.primary-action:hover {
  background: var(--blue-dark);
}

.outline-action,
.icon-action {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}

.icon-action {
  width: 38px;
  padding: 0;
}

.text-action {
  color: var(--blue);
  padding: 0 4px;
}

.metrics-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 12px 0;
}

.metric {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.metric strong {
  font-size: 22px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.view-tabs {
  display: flex;
  gap: 8px;
  padding: 8px;
  background: #e8eef8;
  border: 1px solid #d8e0ec;
  border-radius: var(--radius);
  overflow-x: auto;
}

.view-tab {
  white-space: nowrap;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
}

.view-tab.active {
  color: var(--blue);
  background: var(--surface);
  border-color: var(--border);
  box-shadow: 0 2px 8px rgba(31, 49, 89, 0.08);
}

main {
  margin-top: 14px;
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

.surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head.compact {
  margin: 18px 0 10px;
}

.section-head h2,
.surface h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.35;
}

.section-head p,
.surface > p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

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

.feature-tile {
  display: flex;
  min-height: 138px;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  text-align: left;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.feature-tile:hover {
  border-color: #b4c6ee;
}

.feature-tile strong {
  font-size: 18px;
}

.feature-tile span:last-child {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.tile-kicker {
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

.content-columns,
.policy-layout,
.strategy-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.score-grid div {
  padding: 12px 8px;
  text-align: center;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.score-grid strong {
  display: block;
  font-size: 20px;
}

.score-grid span,
.notice-line {
  color: var(--muted);
  font-size: 13px;
}

.mini-list {
  display: grid;
  gap: 8px;
}

.mini-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.mini-item strong {
  font-size: 14px;
}

.mini-item span {
  color: var(--muted);
  font-size: 12px;
}

.muted-list {
  margin-top: 10px;
}

.query-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 12px;
}

.search-panel {
  align-self: start;
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow: auto;
}

.field-label,
.filter-stack label,
.form-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.search-box {
  display: grid;
  grid-template-columns: 1fr 38px;
  gap: 8px;
  margin: 8px 0;
}

input,
select {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
}

input:focus,
select:focus {
  outline: 2px solid rgba(37, 99, 235, 0.16);
  border-color: #8fb2f3;
}

#clear-school-search {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.suggestions {
  display: none;
  max-height: 260px;
  overflow: auto;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.suggestions.show {
  display: block;
}

.suggestion-item {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
}

.suggestion-item:last-child {
  border-bottom: 0;
}

.suggestion-item span {
  color: var(--muted);
  font-size: 12px;
}

.filter-stack {
  display: grid;
  gap: 10px;
}

.school-list {
  display: grid;
  gap: 8px;
}

.school-card {
  width: 100%;
  padding: 12px;
  text-align: left;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.school-card.active {
  border-color: var(--blue);
  box-shadow: inset 3px 0 0 var(--blue);
}

.school-card strong {
  display: block;
  margin-bottom: 6px;
}

.meta-row,
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-row span,
.tag,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  color: var(--muted);
  background: #edf2f7;
  border-radius: 999px;
  font-size: 12px;
}

.status-pill.green {
  color: #087443;
  background: #dff7ea;
}

.status-pill.amber {
  color: #9a5d00;
  background: #fff2cc;
}

.status-pill.red {
  color: #a03414;
  background: #ffe2d7;
}

.detail-panel {
  display: grid;
  gap: 12px;
}

.detail-card {
  min-height: 420px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  color: var(--muted);
  text-align: center;
  background: var(--surface-soft);
  border: 1px dashed var(--border);
  border-radius: 8px;
}

.detail-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.detail-title h2 {
  margin: 0;
  font-size: 24px;
}

.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

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

.info-cell {
  padding: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.info-cell label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.info-cell p {
  margin: 0;
  line-height: 1.5;
}

.detail-section {
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px solid var(--border);
}

.detail-section h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.detail-section p {
  margin: 0;
  line-height: 1.75;
  color: #344054;
}

.community-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.community-tags span {
  padding: 5px 8px;
  background: #ecfdf5;
  border-radius: 999px;
  font-size: 12px;
}

.photo-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.photo-row img,
.zone-map {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.map-frame {
  position: relative;
  height: 320px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.map-frame.collapsed {
  display: none;
}

#school-map {
  width: 100%;
  height: 100%;
}

.map-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: #eaf0f8;
}

.map-fallback.hidden {
  display: none;
}

.smart-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.wide-field {
  grid-column: 1 / -1;
}

.button-row {
  margin-top: 12px;
}

.recommendation-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.recommend-column {
  display: grid;
  gap: 8px;
  align-content: start;
}

.recommend-column h3 {
  margin: 0;
  font-size: 16px;
}

.result-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.result-card strong {
  display: block;
  margin-bottom: 4px;
}

.result-card p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.wide-surface {
  overflow: hidden;
}

.inline-search {
  width: min(360px, 100%);
}

.candidate-table-wrap {
  overflow: auto;
  max-height: 430px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.candidate-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 14px;
}

.candidate-table th,
.candidate-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.candidate-table th {
  position: sticky;
  top: 0;
  background: #eef3fb;
  z-index: 1;
}

.policy-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.policy-cards article,
.strategy-list article {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.policy-cards p,
.strategy-list p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.policy-list {
  display: grid;
  gap: 8px;
}

.policy-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.policy-item strong {
  display: block;
  margin-bottom: 4px;
}

.policy-item p {
  margin: 0 0 8px;
  color: var(--muted);
  line-height: 1.6;
}

.strategy-list {
  display: grid;
  gap: 10px;
}

.check-list {
  margin: 0;
  padding-left: 20px;
  line-height: 1.9;
  color: #344054;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
  padding: 14px 4px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.site-footer div:last-child {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(16px);
  opacity: 0;
  pointer-events: none;
  padding: 10px 14px;
  color: #fff;
  background: rgba(23, 32, 51, 0.92);
  border-radius: 8px;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 1000;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 980px) {
  .topbar,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions .primary-action,
  .top-actions .outline-action {
    flex: 1;
  }

  .metrics-strip,
  .home-grid,
  .content-columns,
  .policy-layout,
  .strategy-grid,
  .query-layout,
  .recommendation-grid {
    grid-template-columns: 1fr;
  }

  .search-panel {
    position: static;
    max-height: none;
  }

  .score-grid,
  .form-grid,
  .info-grid,
  .photo-row,
  .policy-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 10px;
  }

  .brand-block h1 {
    font-size: 19px;
  }

  .metrics-strip,
  .score-grid,
  .form-grid,
  .info-grid,
  .photo-row,
  .policy-cards {
    grid-template-columns: 1fr;
  }

  .metric {
    justify-content: space-between;
  }

  .view-tabs {
    gap: 4px;
    padding: 6px;
    overflow-x: visible;
  }

  .view-tab {
    flex: 1 1 0;
    min-height: 38px;
    padding: 0 4px;
    font-size: 14px;
  }

  .detail-title,
  .site-footer {
    flex-direction: column;
  }

  .map-frame {
    height: 260px;
  }
}
