:root {
  --bg: #f5f8fa;
  --surface: #ffffff;
  --line: #dce7ec;
  --line-strong: #bfd3dc;
  --text: #13252d;
  --muted: #657882;
  --primary: #087e8b;
  --primary-dark: #066974;
  --primary-soft: #e8f6f7;
  --blue: #1769aa;
  --warn: #9a5b00;
  --danger: #b42318;
  --success: #087443;
  --shadow: 0 18px 48px rgba(13, 48, 63, 0.12);
  color-scheme: light;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.app-shell {
  width: min(100%, 430px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 12px 12px 28px;
  background: #fff;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0 10px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.25;
  font-weight: 750;
  letter-spacing: 0;
}

h2 {
  font-size: 15px;
  line-height: 1.4;
  font-weight: 720;
}

.risk-note {
  max-width: 280px;
  margin-top: 5px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--warn);
}

.status-badge {
  flex: 0 0 auto;
  min-width: 58px;
  padding: 5px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--muted);
  background: #f8fbfc;
  font-size: 12px;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}

.status-badge[data-state="active"] {
  color: var(--success);
  border-color: #a9ddc4;
  background: #eefaf4;
}

.status-badge[data-state="inactive"],
.status-badge[data-state="error"] {
  color: var(--danger);
  border-color: #f0b8b4;
  background: #fff4f3;
}

.panel,
.results-panel {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.muted {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 106px;
  gap: 8px;
  align-items: end;
}

.query-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: grid;
  gap: 5px;
  min-width: 0;
}

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

.field span,
.choice-block legend {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--text);
  background: #fff;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(8, 126, 139, 0.14);
}

.compact-field {
  gap: 4px;
}

.inline-form button,
.primary-button {
  min-height: 42px;
  border-radius: 7px;
  color: #fff;
  background: var(--primary);
  font-size: 14px;
  font-weight: 700;
}

.inline-form button:active,
.primary-button:active {
  background: var(--primary-dark);
}

.choice-block {
  grid-column: 1 / -1;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.choice-block legend {
  margin-bottom: 7px;
}

.choice-hint {
  margin-bottom: 7px;
}

.chips,
.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chips label,
.segmented label {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  max-width: 100%;
}

.chips input,
.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.chips span,
.segmented span {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  max-width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--text);
  background: #fff;
  font-size: 13px;
  line-height: 1.2;
  white-space: normal;
}

.chips input:checked + span,
.segmented input:checked + span {
  color: var(--primary-dark);
  border-color: #72c8cf;
  background: var(--primary-soft);
  font-weight: 700;
}

.primary-button {
  grid-column: 1 / -1;
  width: 100%;
}

.message {
  min-height: 22px;
  padding: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.message[data-tone="error"] {
  color: var(--danger);
}

.message[data-tone="success"] {
  color: var(--success);
}

.result-groups {
  display: grid;
  gap: 12px;
}

.result-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

.group-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  background: #f7fbfc;
  border-bottom: 1px solid var(--line);
}

.group-head strong {
  font-size: 14px;
}

.table-scroll {
  overflow-x: auto;
}

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

th,
td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: #fbfdfe;
  font-weight: 650;
  white-space: nowrap;
}

td {
  color: var(--text);
}

tbody tr:last-child td {
  border-bottom: 0;
}

.school-cell {
  max-width: 140px;
  font-weight: 700;
}

.text-clip {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.major-list {
  min-width: 150px;
  max-width: 230px;
  color: var(--text);
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
}

.major-example-line {
  margin: 0 0 6px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.detail-link {
  min-height: 32px;
  padding: 0 9px;
  border: 1px solid #8fcfd5;
  border-radius: 6px;
  color: var(--primary-dark);
  background: #f0fbfc;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.empty-state {
  padding: 16px 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(10, 27, 34, 0.34);
}

.detail-drawer {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 21;
  width: min(100%, 430px);
  max-height: min(78vh, 680px);
  padding: 9px 12px calc(14px + env(safe-area-inset-bottom));
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: #fff;
  border-radius: 14px 14px 0 0;
  box-shadow: var(--shadow);
  transform: translate(-50%, 110%);
  transition: transform 180ms ease;
}

.detail-drawer[aria-hidden="false"] {
  transform: translate(-50%, 0);
}

.drawer-handle {
  width: 42px;
  height: 4px;
  margin: 0 auto 10px;
  border-radius: 999px;
  background: #c7d5dc;
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  color: var(--muted);
  background: #f1f6f8;
  font-size: 24px;
  line-height: 1;
}

.detail-body {
  position: relative;
  padding-top: 12px;
}

.watermark {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 8px;
  margin-bottom: 10px;
  padding: 8px 9px;
  border: 1px dashed #b8d9de;
  border-radius: 8px;
  color: rgba(6, 105, 116, 0.72);
  background: rgba(240, 251, 252, 0.9);
  font-size: 11px;
  line-height: 1.35;
}

.detail-card {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.detail-card:last-child {
  border-bottom: 0;
}

.detail-card h3 {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.35;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.history-col {
  min-width: 0;
  padding: 8px 6px;
  border-right: 1px solid var(--line);
  background: #fff;
}

.history-col:last-child {
  border-right: 0;
}

.history-year {
  margin-bottom: 5px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 750;
}

.metric {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.metric b {
  color: var(--text);
  font-weight: 650;
  overflow-wrap: anywhere;
}

@media (min-width: 431px) {
  body {
    padding: 18px 0;
  }

  .app-shell {
    min-height: calc(100vh - 36px);
    border: 1px solid var(--line);
    border-radius: 12px;
  }
}

@media (max-width: 720px) {
  .table-scroll {
    overflow-x: visible;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
    padding: 10px 10px 12px;
    border-bottom: 1px solid var(--line);
  }

  tbody td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
    padding: 0;
    border-bottom: 0;
    white-space: normal;
  }

  tbody td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.35;
  }

  .school-cell,
  .major-list-cell,
  .detail-cell {
    grid-column: 1 / -1;
  }

  .detail-cell {
    justify-content: flex-end;
  }

  .detail-cell::before {
    content: none;
  }

  .detail-link {
    width: 100%;
  }

  .text-clip,
  .major-list {
    white-space: normal;
  }
}

@media (prefers-reduced-motion: reduce) {
  .detail-drawer {
    transition: none;
  }
}
