:root {
  color-scheme: light;
  --bg: #f6f9fc;
  --surface: #ffffff;
  --surface-soft: #eef6f7;
  --text: #142235;
  --muted: #66758a;
  --border: #d9e3ee;
  --accent: #1769c2;
  --accent-strong: #1053a1;
  --green: #1b9a67;
  --green-soft: #e5f6ef;
  --danger: #b92d44;
  --shadow: 0 18px 50px rgba(35, 61, 88, 0.1);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgba(23, 105, 194, 0.08), transparent 260px),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 76px;
  padding: 14px clamp(18px, 4vw, 56px);
  background: linear-gradient(90deg, #115fb5, #14817a);
  color: #fff;
  box-shadow: 0 10px 30px rgba(10, 48, 86, 0.16);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark,
.shield {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.13);
}

.brand-mark svg,
.shield svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  font-size: clamp(20px, 3vw, 28px);
  line-height: 1.1;
}

.brand p {
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.admin-jump,
.copy-link-button {
  flex: 0 0 auto;
  color: #fff;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.08);
  padding: 9px 12px;
  font-size: 14px;
  font-weight: 700;
}

.copy-link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.share-notice {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(1480px, calc(100% - 32px));
  margin: 16px auto 0;
  padding: 12px 14px;
  border: 1px solid #cfdced;
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  background: #fff;
  color: #30445d;
  box-shadow: 0 10px 24px rgba(35, 61, 88, 0.08);
}

.share-notice strong {
  flex: 0 0 auto;
  color: var(--accent-strong);
  font-size: 14px;
}

.share-notice span {
  min-width: 0;
  color: var(--muted);
  font-size: 14px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 24px;
  width: min(1480px, calc(100% - 32px));
  margin: 24px auto 52px;
  align-items: start;
}

.layout > *,
.form-shell,
.admin-shell,
.admin-card,
.panel {
  min-width: 0;
  max-width: 100%;
}

.form-shell,
.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.form-shell {
  padding: clamp(16px, 2vw, 24px);
}

.section-heading,
.admin-title-row,
.form-actions,
.record-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.section-heading {
  margin-bottom: 18px;
}

.section-heading h2,
.section-heading p,
.admin-title-row h2,
.admin-title-row p {
  margin: 0;
}

.section-heading h2,
.admin-title-row h2 {
  font-size: 22px;
  line-height: 1.2;
}

.section-heading p,
.admin-title-row p,
.field-note {
  color: var(--muted);
  font-size: 14px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
}

.status-pill.success {
  background: var(--green-soft);
  color: var(--green);
}

.status-pill.error {
  background: #fff0f3;
  color: var(--danger);
}

.pending-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid #f2d6a3;
  border-radius: var(--radius);
  background: #fff9ed;
}

.pending-card strong {
  color: #7c4c03;
  font-size: 14px;
}

.pending-card p {
  margin: 4px 0 0;
  color: #7a6650;
  font-size: 13px;
}

.pending-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.panel {
  margin: 0 0 12px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

.panel h3,
.admin-card h3 {
  margin: 0 0 14px;
  color: var(--accent-strong);
  font-size: 17px;
  line-height: 1.25;
}

.field-grid,
.factor-grid,
.exercise-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
}

label,
.segmented-field {
  display: grid;
  gap: 7px;
}

label span,
legend {
  color: #30445d;
  font-size: 13px;
  font-weight: 800;
}

b {
  color: var(--danger);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  min-height: 42px;
  padding: 10px 12px;
  outline: none;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 105, 194, 0.14);
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  overflow: hidden;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

.compact .segmented {
  max-width: 260px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.exercise-grid {
  grid-template-columns: repeat(2, minmax(240px, 1fr));
}

.exercise-grid .segmented-field,
.exercise-grid label {
  min-width: 0;
}

.exercise-grid .compact .segmented {
  max-width: none;
}

.exercise-note {
  margin: 14px 0 0;
  font-weight: 800;
}

.segmented label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  padding: 8px 10px;
  border-right: 1px solid var(--border);
  color: #30445d;
  font-weight: 800;
}

.segmented label:last-child {
  border-right: 0;
}

.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  opacity: 0;
  pointer-events: none;
}

.segmented label:has(input:checked) {
  background: var(--accent);
  color: #fff;
}

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

.check-grid label {
  display: flex;
  align-items: center;
  min-height: 36px;
  gap: 8px;
  color: #30445d;
  font-size: 14px;
  font-weight: 700;
}

.check-grid input {
  width: 16px;
  height: 16px;
  min-height: auto;
  accent-color: var(--accent);
}

.family-matrix {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  contain: layout paint;
  padding-bottom: 4px;
}

.family-header,
.family-row {
  display: grid;
  grid-template-columns: 92px repeat(5, minmax(92px, 1fr));
  min-width: 640px;
}

.family-header {
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  background: #f0f5fb;
}

.family-row {
  border: 1px solid var(--border);
  border-bottom: 0;
  background: #fff;
}

.family-row:last-child {
  border-bottom: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
}

.family-header span,
.family-row > span,
.family-row label {
  min-height: 42px;
  padding: 10px;
  border-right: 1px solid var(--border);
  font-size: 13px;
}

.family-header span:last-child,
.family-row label:last-child {
  border-right: 0;
}

.family-header span,
.family-row > span {
  color: #30445d;
  font-weight: 900;
}

.family-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #30445d;
  font-weight: 700;
}

.family-row input {
  width: 16px;
  height: 16px;
  min-height: auto;
  accent-color: var(--accent);
}

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

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

.rating-row {
  grid-template-columns: minmax(140px, 1fr) minmax(190px, 1.3fr);
  align-items: center;
  gap: 16px;
  min-height: 42px;
}

.select-wrap {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.select-wrap select {
  min-height: 40px;
}

.field-note {
  margin: -6px 0 12px;
}

.missing-note {
  color: var(--danger);
  font-size: 12px;
  font-weight: 900;
}

.missing {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(185, 45, 68, 0.12);
}

.section-missing {
  margin: -6px 0 12px;
}

.form-actions {
  margin-top: 18px;
  justify-content: flex-end;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border-radius: var(--radius);
  padding: 10px 16px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 900;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

.primary-button {
  background: var(--green);
  color: #fff;
  box-shadow: 0 10px 22px rgba(27, 154, 103, 0.18);
}

.primary-button:hover {
  background: #15875a;
  transform: translateY(-1px);
}

.secondary-button {
  background: #fff;
  color: var(--accent-strong);
  border-color: var(--border);
}

.secondary-button:hover {
  background: var(--surface-soft);
}

.full-width {
  width: 100%;
}

.admin-shell {
  position: sticky;
  top: 100px;
  display: grid;
  gap: 16px;
}

.admin-card {
  padding: 18px;
}

.shield {
  flex: 0 0 auto;
  color: var(--accent);
  border-color: rgba(23, 105, 194, 0.2);
  background: rgba(23, 105, 194, 0.08);
}

.login-form {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

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

.records-area {
  margin-top: 18px;
}

.record-tools {
  flex-wrap: wrap;
  justify-content: flex-start;
}

.record-count {
  margin: 14px 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

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

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

th {
  background: #f0f5fb;
  color: #30445d;
  font-weight: 900;
}

td {
  color: #314359;
}

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

.compact-card {
  box-shadow: none;
}

.compact-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 14px;
}

.compact-card li + li {
  margin-top: 8px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 30;
  min-width: 150px;
  max-width: calc(100vw - 48px);
  padding: 12px 16px;
  border: 1px solid rgba(27, 154, 103, 0.25);
  border-radius: var(--radius);
  background: #fff;
  color: var(--green);
  box-shadow: 0 18px 48px rgba(35, 61, 88, 0.18);
  font-weight: 900;
}

.noscript-warning {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  max-width: calc(100vw - 40px);
  padding: 12px 14px;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: #fff;
  color: var(--danger);
  font-weight: 900;
}

.detail-button {
  min-height: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 900;
}

.detail-button:hover {
  background: var(--surface-soft);
}

.record-detail {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fbfdff;
}

.record-detail h3 {
  margin: 0 0 12px;
}

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

.detail-item {
  padding: 10px;
  border: 1px solid #e6edf5;
  border-radius: 6px;
  background: #fff;
}

.detail-item span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.detail-item p {
  margin: 0;
  color: #243850;
  font-size: 13px;
}

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

  .admin-shell {
    position: static;
  }

  .field-grid,
  .factor-grid,
  .exercise-grid {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }
}

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

  .topbar-actions,
  .share-notice,
  .pending-card,
  .pending-actions {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .share-notice {
    width: min(100% - 20px, 1480px);
    margin-top: 10px;
  }

  .layout {
    width: min(100% - 20px, 1480px);
    margin-top: 12px;
  }

  .section-heading,
  .admin-title-row,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .field-grid,
  .factor-grid,
  .exercise-grid,
  .ratings,
  .check-grid {
    grid-template-columns: 1fr;
  }

  .rating-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .select-wrap {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

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

  .family-header,
  .family-row {
    grid-template-columns: 56px repeat(5, minmax(0, 1fr));
    min-width: 0;
  }

  .family-header span,
  .family-row > span,
  .family-row label {
    min-height: 46px;
    padding: 8px 4px;
    font-size: 12px;
    text-align: center;
  }

  .family-row label {
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 3px;
  }

  .form-actions button,
  .copy-link-button,
  .admin-jump {
    width: 100%;
  }
}
