:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-strong: #f9fafc;
  --text: #1f2937;
  --muted: #667085;
  --line: #d8dee9;
  --line-soft: #e8edf4;
  --brand: #1f6feb;
  --brand-strong: #1557b7;
  --danger: #c24141;
  --danger-soft: #fff0f0;
  --ok: #1f7a4d;
  --shadow: 0 18px 48px rgba(30, 41, 59, 0.14);
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

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

button {
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  min-height: 36px;
  padding: 0 13px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

button:hover {
  border-color: #b9c6da;
  background: #f7faff;
}

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

button.primary:hover {
  background: var(--brand-strong);
  border-color: var(--brand-strong);
}

button.danger {
  color: var(--danger);
  border-color: #f0c3c3;
  background: var(--danger-soft);
}

button.ghost {
  background: transparent;
  border-color: transparent;
}

button.small {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

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

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

input[type="checkbox"] {
  width: auto;
  min-height: 0;
}

textarea {
  min-height: 86px;
  resize: vertical;
  line-height: 1.55;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.12);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, #eef4ff 0%, #f7f8fb 58%, #f5f7fb 100%);
}

.login-panel {
  width: min(430px, 100%);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px;
}

.login-title {
  margin: 0 0 6px;
  font-size: 28px;
  line-height: 1.2;
}

.login-subtitle {
  margin: 0 0 24px;
  color: var(--muted);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

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

.brand-block {
  min-width: 0;
}

.brand-block h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.2;
}

.brand-block p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

.content {
  padding: 22px 24px 32px;
  min-width: 0;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(280px, 620px) minmax(420px, 1fr);
  align-items: start;
  gap: 14px;
  margin-bottom: 14px;
  min-width: 0;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(620px, 100%);
  min-width: 0;
}

.layered-filter {
  display: grid;
  grid-template-columns: auto auto 145px 145px minmax(210px, 1fr);
  gap: 8px;
  align-items: end;
  width: 100%;
  min-width: 0;
}

.filter-heading {
  color: #344054;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

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

.filter-field span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.filter-row input {
  min-width: 190px;
}

.layer-filter-rows {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  min-width: 0;
}

.layer-filter-row {
  display: grid;
  grid-template-columns: 86px 58px minmax(150px, 1.1fr) 130px minmax(150px, 1fr) minmax(130px, 0.8fr) auto;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.layer-negate {
  justify-content: center;
}

.layer-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.layer-empty {
  min-height: 34px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.hidden {
  display: none !important;
}

.table-panel {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(31, 43, 61, 0.07);
}

.table-scroll {
  width: 100%;
  max-width: 100%;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

.patients-table {
  min-width: 1240px;
}

th,
td {
  border-bottom: 1px solid var(--line-soft);
  padding: 11px 12px;
  vertical-align: top;
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7f9fc;
  color: #344054;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

td {
  font-size: 14px;
  line-height: 1.45;
}

tr:hover td {
  background: #fbfdff;
}

.muted {
  color: var(--muted);
}

.nowrap {
  white-space: nowrap;
}

.cell-main {
  max-width: 300px;
}

.diagnosis {
  max-width: 360px;
}

.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid #cfe0fb;
  border-radius: 999px;
  background: #eef5ff;
  color: #1b5fbf;
  font-size: 12px;
  white-space: nowrap;
}

.followup-cell {
  min-width: 120px;
}

.followup-button {
  margin-bottom: 5px;
  border-color: #cfe0fb;
  background: #eef5ff;
  color: #1b5fbf;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 13px;
  background: var(--surface-strong);
}

.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.42);
}

.modal {
  width: min(1180px, 100%);
  max-height: min(88vh, 980px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal.narrow {
  width: min(620px, 100%);
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line-soft);
}

.modal-footer {
  border-top: 1px solid var(--line-soft);
  border-bottom: 0;
  justify-content: flex-end;
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

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

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

.detail-item {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: #fff;
  padding: 10px 11px;
  min-width: 0;
}

.detail-item.wide {
  grid-column: span 3;
}

.detail-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.detail-value {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.55;
}

.section-title {
  margin: 22px 0 10px;
  font-size: 16px;
}

.timeline {
  display: grid;
  gap: 9px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 118px 130px 1fr;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: #fff;
}

.timeline-date {
  font-weight: 650;
  color: #111827;
}

.timeline-source {
  color: var(--muted);
  font-size: 13px;
}

.survival-modal {
  width: min(1280px, 100%);
}

.survival-toolbar {
  display: flex;
  align-items: end;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.survival-toolbar .filter-field {
  width: min(240px, 100%);
}

.survival-note {
  padding: 11px 12px;
  border: 1px solid #cfe0fb;
  border-radius: var(--radius);
  background: #f3f8ff;
  color: #344054;
  line-height: 1.55;
  margin-bottom: 14px;
}

.survival-stats,
.km-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.survival-stat,
.km-card {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: #fff;
  padding: 13px;
  min-width: 0;
}

.paper-card {
  border-color: #d0d5dd;
}

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

.km-card-header h3 {
  margin: 0;
}

.km-actions {
  display: flex;
  gap: 6px;
}

.survival-stat h3,
.km-card h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.km-card-header h3 {
  margin: 0;
}

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

.survival-stat-grid div {
  padding: 8px;
  border-radius: 7px;
  background: #f8fafc;
  min-width: 0;
}

.survival-stat-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.survival-stat-grid strong {
  font-size: 16px;
  overflow-wrap: anywhere;
}

.km-svg {
  width: 100%;
  height: auto;
  display: block;
}

.paper-km-svg {
  font-family: Arial, "Helvetica Neue", sans-serif;
}

.km-title {
  fill: #101828;
  font-size: 20px;
  font-weight: 700;
}

.km-axis {
  fill: #101828;
  font-size: 13px;
}

.km-label {
  fill: #101828;
  font-size: 15px;
  font-weight: 600;
}

.km-axis-line {
  stroke: #101828;
  stroke-width: 1.4;
}

.km-grid-line {
  stroke: #e4e7ec;
  stroke-width: 1;
}

.km-grid-line.light {
  stroke: #f2f4f7;
}

.km-curve {
  stroke-width: 3.2;
  fill: none;
}

.km-censor {
  stroke: #101828;
  stroke-width: 1.6;
}

.km-risk-label {
  fill: #101828;
  font-size: 14px;
  font-weight: 700;
}

.km-risk-group,
.km-risk-number {
  fill: #101828;
  font-size: 13px;
}

.km-risk-rule {
  stroke: #d0d5dd;
  stroke-width: 1;
}

.km-footnote {
  fill: #667085;
  font-size: 11px;
}

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

.form-field {
  min-width: 0;
}

.form-field.long {
  grid-column: span 2;
}

.form-field label {
  display: block;
  margin-bottom: 6px;
  color: #344054;
  font-size: 13px;
  font-weight: 600;
}

.date-input-pair {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 8px;
  min-width: 0;
}

.date-picker {
  min-width: 0;
}

.choice-input-group {
  display: grid;
  grid-template-columns: minmax(150px, 0.7fr) minmax(0, 1fr);
  gap: 8px;
  min-width: 0;
}

.choice-other-input.hidden {
  display: none;
}

.followup-editor {
  display: grid;
  gap: 9px;
}

.followup-add {
  margin-top: 10px;
}

.followup-row {
  display: grid;
  grid-template-columns: 150px 150px 1fr auto;
  gap: 8px;
  align-items: start;
}

.empty {
  padding: 34px 18px;
  text-align: center;
  color: var(--muted);
}

.user-row {
  display: grid;
  grid-template-columns: 1fr auto 170px auto;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line-soft);
}

.user-row:last-child {
  border-bottom: 0;
}

.stack {
  display: grid;
  gap: 12px;
}

.error-text {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
}

#toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  display: grid;
  gap: 8px;
}

.toast-item {
  min-width: 220px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 11px 13px;
  border-radius: var(--radius);
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow);
}

@media (max-width: 860px) {
  .topbar,
  .toolbar {
    align-items: stretch;
  }

  .topbar {
    flex-direction: column;
  }

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

  .top-actions,
  .filter-row,
  .layered-filter {
    width: 100%;
    justify-content: flex-start;
  }

  .filter-row {
    flex-wrap: wrap;
  }

  .filter-row input {
    flex: 1 1 100%;
  }

  .layered-filter {
    grid-template-columns: 1fr;
  }

  .layer-filter-row {
    grid-template-columns: 1fr;
  }

  .content {
    padding: 16px;
  }

  .detail-grid,
  .form-grid,
  .survival-stats,
  .km-grid {
    grid-template-columns: 1fr;
  }

  .detail-item.wide,
  .form-field.long {
    grid-column: span 1;
  }

  .timeline-item,
  .followup-row {
    grid-template-columns: 1fr;
  }

  .date-input-pair {
    grid-template-columns: 1fr;
  }

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

  .user-row {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .modal-backdrop {
    padding: 10px;
  }
}
