:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
  background: #f6f7f9;
  color: #17202a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 24px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid #d9dee7;
  background: #ffffff;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.2;
}

h2 {
  margin-bottom: 16px;
  font-size: 18px;
}

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

.section-head h2 {
  margin-bottom: 0;
}

.topbar p {
  margin-top: 8px;
  color: #5c6675;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
  grid-template-areas:
    "controls results";
  gap: 16px;
  padding: 20px clamp(16px, 4vw, 40px) 40px;
}

.settings-layout {
  max-width: 920px;
  padding: 20px clamp(16px, 4vw, 40px) 40px;
}

.table-layout {
  padding: 20px clamp(16px, 4vw, 40px) 40px;
}

.panel {
  border: 1px solid #d9dee7;
  border-radius: 8px;
  background: #ffffff;
  padding: 20px;
}

.controls-panel {
  grid-area: controls;
}

.results-panel {
  grid-area: results;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.choice-panel {
  margin: 16px 0 0;
  border: 1px solid #e1e6ee;
  border-radius: 8px;
  padding: 12px;
}

.choice-panel legend {
  padding: 0 6px;
  color: #313b49;
  font-size: 14px;
  font-weight: 700;
}

.field-help {
  margin-bottom: 10px;
  color: #697386;
  font-size: 13px;
  line-height: 1.5;
}

.condition-group {
  margin-top: 10px;
  border-top: 1px solid #e1e6ee;
  padding-top: 8px;
}

.condition-group:first-of-type {
  margin-top: 0;
  border-top: 0;
  padding-top: 0;
}

.condition-group summary {
  min-height: 34px;
  color: #313b49;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.condition-group-body {
  display: grid;
  gap: 12px;
  padding-top: 8px;
}

.score-grid {
  display: grid;
  gap: 12px;
}

.two-column-score-grid,
.language-score-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.score-field {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.score-field span {
  white-space: nowrap;
}

.score-field input,
.score-field select {
  min-width: 0;
}

.subject-score-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
}

.subject-score-row {
  display: grid;
  grid-template-columns: minmax(64px, auto) minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.subject-score-row input[type="number"] {
  min-width: 0;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
}

label {
  display: grid;
  gap: 6px;
  color: #313b49;
  font-size: 14px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c7ced8;
  border-radius: 6px;
  padding: 10px 11px;
  color: #17202a;
  background: #ffffff;
  font: inherit;
  font-weight: 400;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #1f6feb;
  outline-offset: 1px;
  border-color: #1f6feb;
}

.wide-field {
  margin-top: 14px;
}

.filter-toggles,
.feature-toggles {
  display: flex;
  gap: 16px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.model-picker {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
}

button,
.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid #1f6feb;
  border-radius: 6px;
  padding: 0 14px;
  background: #1f6feb;
  color: #ffffff;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}

button.secondary {
  border-color: #c7ced8;
  background: #ffffff;
  color: #17202a;
}

.secondary-link {
  border-color: #c7ced8;
  background: #ffffff;
  color: #17202a;
}

button:disabled {
  opacity: 0.65;
  cursor: wait;
}

.status {
  min-height: 20px;
  color: #5c6675;
  font-size: 14px;
}

.result-list,
.favorite-list {
  display: grid;
  gap: 12px;
}

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

.result-table {
  width: max-content;
  min-width: 100%;
  table-layout: auto;
  border-collapse: collapse;
  font-size: 13px;
}

.result-table th,
.result-table td {
  border: 1px solid #d9dee7;
  padding: 8px 9px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.result-table th {
  background: #f0f3f7;
  color: #313b49;
  font-weight: 700;
}

.result-row {
  cursor: pointer;
}

.result-row:hover td {
  background: #f8fafc;
}

.result-row.nature-public td:first-child {
  border-left: 5px solid #2e7d32;
}

.result-row.nature-private td:first-child {
  border-left: 5px solid #1565c0;
}

.result-row.nature-junior td:first-child {
  border-left: 5px solid #c62828;
}

.result-row.nature-unknown td:first-child {
  border-left: 5px solid #8b95a5;
}

.result-detail-row td {
  background: #fbfcfe;
  white-space: normal;
}

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

.result-index-cell {
  color: #697386;
  text-align: right;
}

.result-school,
.result-major {
  font-weight: 700;
}

.result-school-button,
.result-major-button {
  min-height: 0;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  font: inherit;
  font-weight: 800;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.result-school-button {
  color: #0b6b3a;
}

.result-major-button {
  color: #8a4b00;
}

.result-tags-cell {
  max-width: 260px;
  white-space: normal;
}

.empty-state {
  color: #697386;
}

.result-card,
.favorite-card {
  border: 1px solid #e1e6ee;
  border-left-width: 5px;
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfe;
}

.nature-public {
  border-left-color: #2e7d32;
}

.nature-private {
  border-left-color: #1565c0;
}

.nature-junior {
  border-left-color: #c62828;
}

.nature-unknown {
  border-left-color: #8b95a5;
}

.card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.result-select {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin-top: 2px;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
}

.text-link-button {
  min-height: 0;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  color: #174ea6;
  font: inherit;
  font-weight: 700;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.title-separator {
  color: #5c6675;
}

.badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 9px;
  background: #edf4ff;
  color: #174ea6;
  font-size: 12px;
  font-weight: 700;
}

.tag-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.school-tag {
  border: 1px solid #c7ced8;
  border-radius: 999px;
  padding: 3px 8px;
  background: #ffffff;
  color: #313b49;
  font-size: 12px;
  font-weight: 700;
}

.school-tag-public {
  border-color: #7fb685;
  background: #eaf6ed;
  color: #1b5e20;
}

.school-tag-private {
  border-color: #8bb7e8;
  background: #edf5ff;
  color: #0d47a1;
}

.school-tag-junior {
  border-color: #ef9a9a;
  background: #fff0f0;
  color: #b71c1c;
}

.compact-tags {
  margin-top: 0;
}

.meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
  color: #5c6675;
  font-size: 13px;
}

.detail {
  margin-top: 10px;
  color: #313b49;
  font-size: 14px;
  line-height: 1.6;
}

.history-block {
  margin-top: 12px;
  overflow-x: auto;
}

.history-title {
  margin-bottom: 6px;
  color: #313b49;
  font-size: 13px;
  font-weight: 700;
}

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

.history-table th,
.history-table td {
  border: 1px solid #d9dee7;
  padding: 6px 8px;
  text-align: left;
  white-space: nowrap;
}

.history-table th {
  background: #f0f3f7;
  color: #313b49;
  font-weight: 700;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

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

.waitlist-table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
  font-size: 13px;
}

.waitlist-table th,
.waitlist-table td {
  border: 1px solid #d9dee7;
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}

.waitlist-table th {
  background: #f0f3f7;
  color: #313b49;
  font-weight: 700;
  white-space: nowrap;
}

.waitlist-table tr.nature-public td:first-child {
  border-left: 5px solid #2e7d32;
}

.waitlist-table tr.nature-private td:first-child {
  border-left: 5px solid #1565c0;
}

.waitlist-table tr.nature-junior td:first-child {
  border-left: 5px solid #c62828;
}

.waitlist-table tr.nature-unknown td:first-child {
  border-left: 5px solid #8b95a5;
}

.analysis-cell {
  display: grid;
  gap: 6px;
}

.analysis-summary {
  color: #313b49;
  line-height: 1.5;
}

.analysis-column {
  min-width: 220px;
}

.history-column {
  min-width: 240px;
  line-height: 1.6;
}

.compact-button {
  min-height: 32px;
  padding: 0 10px;
}

.detail-modal[hidden] {
  display: none;
}

.detail-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
}

.detail-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 32, 42, 0.48);
}

.detail-modal-panel {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1120px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  border: 1px solid #c7ced8;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 16px 44px rgba(23, 32, 42, 0.22);
}

.detail-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid #d9dee7;
}

.detail-modal-head h2 {
  margin-bottom: 0;
}

.detail-modal-body {
  overflow: auto;
  padding: 16px 18px 18px;
}

.detail-section + .detail-section {
  margin-top: 18px;
}

.detail-section h3 {
  margin: 0 0 10px;
  color: #313b49;
  font-size: 15px;
}

.detail-link-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.detail-link-list a {
  border: 1px solid #c7ced8;
  border-radius: 6px;
  padding: 7px 10px;
  color: #174ea6;
  background: #f8fafc;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.major-catalog-tree {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  border-left: 2px solid #c7d8ef;
  padding-left: 12px;
}

.major-catalog-node {
  position: relative;
  color: #313b49;
  font-size: 13px;
  line-height: 1.5;
}

.major-catalog-node::before {
  content: "";
  position: absolute;
  top: 0.75em;
  left: -12px;
  width: 8px;
  border-top: 1px solid #c7d8ef;
}

.level-discipline {
  font-weight: 800;
}

.level-category {
  margin-left: 16px;
  color: #174ea6;
  font-weight: 700;
}

.level-major {
  margin-left: 32px;
  color: #8a4b00;
  font-weight: 700;
}

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

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

.detail-table th,
.detail-table td {
  border: 1px solid #d9dee7;
  padding: 7px 8px;
  text-align: left;
  white-space: nowrap;
}

.detail-table th {
  background: #f0f3f7;
  color: #313b49;
  font-weight: 700;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "controls"
      "results";
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

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

  .two-column-score-grid,
  .language-score-grid,
  .subject-score-list {
    grid-template-columns: 1fr;
  }

  .model-picker {
    grid-template-columns: 1fr;
  }

  .top-actions {
    width: 100%;
  }
}

@media (max-width: 480px) {
  body {
    min-width: 0;
  }

  .topbar {
    gap: 12px;
    padding: 16px 12px;
  }

  .top-actions,
  .actions {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .top-actions .link-button,
  .actions button,
  .actions .link-button {
    width: 100%;
  }

  .layout,
  .settings-layout,
  .table-layout {
    padding: 12px 8px 24px;
  }

  .panel {
    border-radius: 6px;
    padding: 14px 12px;
  }

  .choice-panel {
    padding: 10px;
  }

  .card-head {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .card-title {
    flex: 1 1 220px;
    line-height: 1.45;
  }

  .badge {
    margin-left: auto;
  }

  .meta {
    gap: 6px 10px;
  }

  .history-block,
  .table-scroll,
  .result-table-scroll,
  .detail-table-scroll {
    margin-right: -8px;
    padding-bottom: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .history-table {
    min-width: 760px;
  }

  .result-table {
    min-width: 980px;
  }

  .waitlist-table {
    min-width: 1060px;
  }

  .detail-modal {
    padding: 8px;
  }

  .detail-modal-panel {
    width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
  }

  .detail-modal-head {
    padding: 12px;
  }

  .detail-modal-body {
    padding: 12px;
  }

  .detail-table {
    min-width: 820px;
  }
}

@media print {
  :root {
    background: #ffffff;
    color: #000000;
  }

  body {
    min-width: 0;
    background: #ffffff;
  }

  .topbar,
  .no-print,
  .controls-panel,
  .results-panel,
  .favorite-card .actions,
  #printWaitlist,
  .status {
    display: none !important;
  }

  .layout {
    display: block;
    padding: 0;
  }

  .favorites-panel {
    border: 0;
    padding: 0;
  }

  .favorite-list {
    gap: 10px;
  }

  .favorite-card {
    break-inside: avoid;
    border-color: #999999;
    background: #ffffff;
  }

  .history-block {
    overflow: visible;
  }

  .history-table {
    min-width: 0;
    font-size: 10px;
  }

  .history-table th,
  .history-table td {
    padding: 4px 5px;
  }

  .table-layout {
    padding: 0;
  }

  .waitlist-table-panel {
    border: 0;
    padding: 0;
  }

  .table-scroll {
    overflow: visible;
  }

  .waitlist-table {
    min-width: 0;
    font-size: 10px;
  }

  .waitlist-table th,
  .waitlist-table td {
    padding: 4px 5px;
  }

  .waitlist-table .no-print {
    display: none !important;
  }
}
