:root {
  --bg: #F4F6F9;
  --surface: #FFFFFF;
  --ink: #1A1D21;
  --text-secondary: #5B6770;
  --text-muted: #8B959E;
  --line: #E4E8ED;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 6px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 4px 16px rgba(15, 23, 42, 0.06);
  --radius: 8px;
  --radius-sm: 6px;
  --accent: #0B5E7C;
  --accent-hover: #094D66;
  --accent-light: #EAF4F8;
  --grade-s: #B42318;
  --grade-a: #0B5E7C;
  --grade-b: #2E7D44;
  --grade-c: #B26B00;
  --predict: #A8485E;
  --predict-light: #F8ECEF;
  --transition: 180ms ease;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Inter", "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
}

/* ── Loading Overlay ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--surface);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 280ms ease;
}
.loading-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}
.loading-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}
.loading-text {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}
@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.92); }
  50% { opacity: 1; transform: scale(1); }
}

/* ── Workspace & App ── */
.workspace { min-height: 100vh; }

.app {
  width: min(1400px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 20px 0 32px;
}

/* ── Top Bar ── */
.topbar {
  display: grid;
  grid-template-columns: minmax(240px, 0.7fr) minmax(380px, 0.9fr);
  gap: 20px;
  align-items: center;
  margin-bottom: 16px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.title-block h1 {
  margin: 0 0 3px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.tagline {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 84px;
  gap: 8px;
  align-items: center;
}

.search-wrap {
  position: relative;
}

.search-wrap input {
  width: 100%;
  height: 36px;
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 94, 124, 0.1);
}

.search-wrap input::placeholder {
  color: var(--text-muted);
}

.search-button {
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform 60ms ease;
}
.search-button:hover { background: var(--accent-hover); }
.search-button:active { transform: scale(0.97); }

/* ── Dashboard Layout ── */
.dashboard {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.dashboard-top {
  display: grid;
  grid-template-columns: 0.78fr 1.22fr;
  gap: 14px;
}

.dashboard-bottom {
  display: grid;
  grid-template-columns: 60% 40%;
  gap: 14px;
}

/* ── Panels (Cards) ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px 22px;
  transition: box-shadow var(--transition);
}
.panel:hover {
  box-shadow: var(--shadow-md);
}

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

.section-head.compact {
  align-items: center;
  margin-bottom: 14px;
}

.section-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}

/* ── Profile Panel ── */
.identity {
  display: flex;
  gap: 16px;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.avatar {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--accent-light);
  color: var(--accent);
  font-size: 20px;
  font-weight: 700;
}

.identity h3 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 650;
}

.identity p {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 20px;
  margin: 16px 0 0;
}

.profile-grid div { min-width: 0; }

.profile-grid dt {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.profile-grid dd {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.note-row { margin-top: 16px; }
.note-label { font-size: 11.5px; font-weight: 600; color: var(--text-muted); letter-spacing: 0.02em; text-transform: uppercase; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--text-secondary);
  background: var(--bg);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

/* ── Rating Panel ── */
.rating-core {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 16px;
  align-items: center;
}

.grade {
  display: grid;
  width: 88px;
  height: 88px;
  place-items: center;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 44px;
  font-weight: 800;
  line-height: 1;
  transition: background var(--transition);
}

.grade.s  { background: var(--grade-s); }
.grade.a  { background: var(--grade-a); }
.grade.b  { background: var(--grade-b); }
.grade.c  { background: var(--grade-c); }

.grade-title {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 700;
}

.grade-desc {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.rating-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 18px;
}

.metric-card {
  min-height: 60px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.metric-card:hover {
  border-color: var(--accent);
  background: #FAFCFD;
}

.metric-card.active {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: inset 0 2px 0 var(--accent);
}

.metric-card span {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  margin-top: 6px;
  font-size: 18px;
  font-weight: 700;
}

.support-box {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #FBFCFE;
  padding: 14px 16px;
}

.support-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.support-head span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.support-head strong {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}

.support-body ul {
  margin: 0;
  padding-left: 18px;
}

.support-body li {
  margin-bottom: 5px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink);
}

.support-body p {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink);
}

/* ── Radar Panel ── */
.radar-charts {
  display: flex;
  gap: 14px;
  flex: 1;
  min-height: 0;
}

.radar-chart-box {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.radar-subtitle {
  margin: 0 0 8px;
  font-size: 12.5px;
  font-weight: 700;
  text-align: center;
}

.radar-chart-box:first-child .radar-subtitle { color: var(--accent); }
.radar-chart-box:last-child .radar-subtitle { color: var(--predict); }

#radarCanvasHistorical,
#radarCanvasPrediction {
  width: 100%;
  flex: 1;
  min-height: 220px;
}

.scale,
.selected-dim {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
}

.selected-dim { color: var(--accent); }

/* ── Detail Panel ── */
.detail-panel { display: flex; flex-direction: column; }

.evidence {
  flex: 1;
  overflow: auto;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.detail-subsection {
  margin-bottom: 14px;
}
.detail-subsection:last-child { margin-bottom: 0; }

.subsection-title {
  margin: 0 0 8px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent);
}

.detail-subsection ul {
  margin: 0;
  padding-left: 18px;
}

.detail-subsection li {
  margin-bottom: 6px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--ink);
}

.detail-subsection p {
  margin: 0;
  font-size: 13px;
  line-height: 1.75;
  color: var(--ink);
}

/* ── Responsive ── */
@media (max-width: 1080px) {
  .dashboard-top,
  .dashboard-bottom {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app {
    width: min(100vw - 28px, 600px);
    padding-top: 16px;
  }

  .topbar {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .profile-grid,
  .rating-stats {
    grid-template-columns: 1fr;
  }

  .rating-core {
    grid-template-columns: 76px 1fr;
  }

  .grade {
    width: 76px;
    height: 76px;
    font-size: 36px;
  }

  .panel {
    padding: 16px;
  }

  .radar-charts {
    flex-direction: column;
  }
}
