:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-strong: #ffffff;
  --ink: #18212f;
  --muted: #657084;
  --line: #dbe1e8;
  --line-soft: #edf1f5;
  --brand: #176b87;
  --brand-dark: #104f66;
  --accent: #b96b35;
  --safe: #247558;
  --warn: #936000;
  --danger: #ad3f3f;
  --focus: rgba(23, 107, 135, 0.18);
  --shadow: 0 10px 30px rgba(24, 33, 47, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(180deg, #fbfcfd 0, var(--bg) 260px),
    var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow-x: hidden;
}

body.access-locked {
  min-height: 100vh;
  overflow: hidden;
}

body.access-locked .topbar,
body.access-locked .shell,
body.access-locked dialog {
  display: none;
}

body:not(.access-locked) .access-gate {
  display: none;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(14px);
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.top-subtitle {
  max-width: 680px;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 26px;
  line-height: 1.2;
}

h2 {
  margin-bottom: 0;
  font-size: 17px;
}

h3 {
  margin-bottom: 8px;
  font-size: 15px;
}

.status-pill,
.tag,
.score-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  white-space: nowrap;
}

.status-pill {
  padding: 8px 11px;
  background: #edf7fa;
  border: 1px solid #cfe6ed;
  color: var(--brand-dark);
  font-size: 13px;
  font-weight: 700;
}

.access-gate {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(244, 246, 248, 0.98)),
    var(--bg);
}

.access-card {
  width: min(440px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.access-card h1 {
  font-size: 24px;
}

.access-copy {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.access-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(360px, 0.82fr);
  gap: 16px;
  padding: 16px;
  align-items: start;
}

.main-column {
  display: grid;
  align-content: start;
  gap: 16px;
  min-width: 0;
}

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls-panel,
.results-panel,
.profile-panel,
.detail-panel,
.candidates-panel,
.data-panel {
  padding: 16px;
}

.controls-panel {
  grid-column: 1 / 2;
}

.results-panel {
  grid-column: 1 / 2;
}

.side-column {
  display: grid;
  align-content: start;
  gap: 16px;
  position: sticky;
  top: 96px;
}

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

.muted {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(112px, 1fr));
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: #354154;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid var(--focus);
  border-color: var(--brand);
}

textarea {
  min-height: 60px;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.5;
}

.wide-field {
  grid-column: span 2;
}

.quick-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #f8fafc;
}

.quick-panel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.quick-panel-heading strong {
  font-size: 14px;
}

.quick-panel-heading span {
  color: var(--muted);
  font-size: 12px;
}

.family-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.family-chip {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #344155;
  font-size: 13px;
  font-weight: 700;
}

.family-chip:hover,
.family-chip.active {
  border-color: #9bc8d6;
  background: #eaf6fa;
  color: var(--brand-dark);
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 12px;
}

.toggle-row label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-row input {
  width: auto;
  min-height: auto;
}

.field-help {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.hint-box {
  display: grid;
  gap: 4px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #e8dcc7;
  border-radius: 6px;
  background: #fffaf2;
  color: #604423;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.primary-button,
.secondary-button,
.ghost-button,
.tiny-button {
  border-radius: 6px;
  border: 1px solid transparent;
  min-height: 36px;
  padding: 0 12px;
  font-weight: 700;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.primary-button {
  background: var(--brand);
  color: #fff;
}

.secondary-button {
  background: #edf7fa;
  color: var(--brand-dark);
  border-color: #cfe6ed;
}

.ghost-button {
  background: #fff;
  color: var(--brand-dark);
  border-color: var(--line);
}

.tiny-button {
  min-height: 32px;
  padding: 0 9px;
  background: #fff;
  color: var(--brand-dark);
  border-color: var(--line);
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.tiny-button:hover {
  transform: translateY(-1px);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  max-height: calc(100vh - 310px);
  min-height: 420px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

th,
td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
  overflow-wrap: break-word;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: #4a5568;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  overflow-wrap: normal;
}

th:nth-child(1),
td:nth-child(1) {
  width: 42px;
  min-width: 42px;
}

th:nth-child(2),
td:nth-child(2),
th:nth-child(4),
td:nth-child(4) {
  width: 76px;
  min-width: 76px;
  white-space: nowrap;
}

th:nth-child(3),
td:nth-child(3) {
  width: 132px;
  min-width: 132px;
}

th:nth-child(5),
td:nth-child(5) {
  min-width: 360px;
}

th:nth-child(6),
td:nth-child(6) {
  width: 76px;
  min-width: 76px;
  white-space: nowrap;
}

th:nth-child(7),
td:nth-child(7) {
  width: 128px;
  min-width: 128px;
}

th:nth-child(8),
td:nth-child(8) {
  width: 76px;
  min-width: 76px;
}

tr:hover td {
  background: #f7fbfd;
}

.result-row {
  cursor: pointer;
}

.score-badge {
  padding: 5px 8px;
  background: #eaf6fa;
  color: var(--brand-dark);
  font-weight: 800;
}

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

.tag {
  padding: 3px 7px;
  background: #f1f4f7;
  color: #526071;
  font-size: 12px;
  border: 1px solid transparent;
}

.tag.warn {
  background: #fff6df;
  color: var(--warn);
  border-color: #f1ddad;
}

.tag.danger {
  background: #ffe8e8;
  color: var(--danger);
  border-color: #f3c7c7;
}

.tag.safe {
  background: #e8f5ef;
  color: var(--safe);
  border-color: #cbe8da;
}

.detail-content,
.empty-state {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfcfd;
}

.detail-block {
  padding: 12px 0;
  border-top: 1px solid var(--line-soft);
}

.detail-block:first-child {
  padding-top: 0;
  border-top: 0;
}

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

.decision-block {
  border-radius: 8px;
  border: 1px solid #cfe6ed;
  background: #f3fafc;
  padding: 12px;
}

.decision-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.metric {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.metric strong {
  display: block;
  margin-bottom: 2px;
  font-size: 16px;
}

.quality-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.quality-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: #fff;
}

.quality-item-relevant {
  border-color: #b8d8c9;
  background: #f4fbf7;
}

.quality-item strong,
.quality-item span {
  display: block;
}

.quality-item p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.candidate-list {
  display: grid;
  gap: 10px;
  max-height: 360px;
  overflow: auto;
}

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

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

.profile-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.profile-status {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid #cfe6ed;
  border-radius: 8px;
  background: #f3fafc;
  color: #24485a;
  font-size: 13px;
  line-height: 1.5;
}

.profile-status p {
  margin: 0;
}

.profile-status-line {
  display: grid;
  gap: 3px;
}

.profile-status-line strong {
  color: var(--brand-dark);
}

.candidate-card {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fff;
  min-width: 0;
}

.candidate-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.candidate-card strong {
  font-size: 14px;
  line-height: 1.45;
}

.candidate-controls {
  display: grid;
  grid-template-columns: minmax(110px, 0.45fr);
  gap: 8px;
}

.risk-line {
  color: #604423;
  background: #fffaf2;
  border: 1px solid #e8dcc7;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.45;
}

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

.data-readiness {
  display: grid;
  gap: 12px;
}

.readiness-summary,
.source-level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 8px;
}

.source-level-grid {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

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

.readiness-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fff;
}

.readiness-item strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}

.readiness-item p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.validation-card {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fff;
}

.validation-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.validation-header strong,
.validation-header span {
  display: block;
}

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

.validation-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

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

.validation-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: #fbfcfd;
}

.validation-item strong {
  display: block;
  margin-bottom: 2px;
  font-size: 13px;
}

.validation-item p {
  margin: 0;
  color: #4d5b6d;
  font-size: 12px;
  line-height: 1.45;
}

.sources-table-wrap {
  max-height: 460px;
}

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

.compare-dialog {
  width: min(1100px, calc(100vw - 28px));
  max-height: min(760px, calc(100vh - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.24);
}

.compare-dialog::backdrop {
  background: rgba(28, 25, 20, 0.42);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.compare-content {
  padding: 18px;
  overflow: auto;
}

.compare-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.compare-card {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.compare-card dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.compare-card dt {
  color: var(--muted);
  font-size: 12px;
}

.compare-card dd {
  margin: 0;
  font-weight: 700;
}

@media (max-width: 1050px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .main-column,
  .controls-panel,
  .results-panel,
  .side-column {
    grid-column: 1;
    grid-row: auto;
    position: static;
  }
}

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

  .top-actions {
    justify-content: flex-start;
  }

  h1 {
    font-size: 23px;
  }

  .shell {
    padding: 10px;
    gap: 12px;
  }

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

  .wide-field {
    grid-column: auto;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .button-row {
    justify-content: flex-start;
  }

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

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

  .readiness-summary {
    grid-template-columns: 1fr;
  }

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

  .quick-panel-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .table-wrap {
    max-height: 560px;
    min-height: 360px;
  }

  .readiness-item {
    grid-template-columns: 1fr;
  }
}
