/* MDS Apple HIG + apple-design — 病历质控 B2B 分组风格 */
:root {
  --mds-primary: #007aff;
  --mds-primary-dark: #0051d5;
  --mds-accent: #5856d6;
  --mds-success: #34c759;
  --mds-warning: #ff9500;
  --mds-danger: #ff3b30;
  --mds-bg: #f2f2f7;
  --mds-surface: #ffffff;
  --mds-text: #1d1d1f;
  --mds-text-secondary: rgba(60, 60, 67, 0.68);
  --mds-text-muted: rgba(60, 60, 67, 0.45);
  --mds-separator: rgba(60, 60, 67, 0.18);
  --mds-input-fill: rgba(120, 120, 128, 0.12);
  --mds-radius-xl: 14px;
  --mds-radius-lg: 12px;
  --mds-radius-pill: 999px;
  --mds-shadow-subtle: 0 1px 3px rgba(0, 0, 0, 0.04);
  --spring-fast: 200ms cubic-bezier(0.25, 0.1, 0.25, 1);
  --spring-press: 100ms ease-out;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 17px;
  line-height: 1.47;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--mds-bg);
  color: var(--mds-text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ── Brand header ── */
.page-brand {
  padding: 8px 4px 18px;
}

.page-brand--center {
  text-align: center;
}

.brand-mark {
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
}

.brand-mark--hero {
  margin-bottom: 14px;
}

.brand-icon {
  opacity: 0.88;
  color: var(--mds-primary);
}

.brand-hospital {
  font-size: 13px;
  font-weight: 500;
  color: var(--mds-text-secondary);
  letter-spacing: 0.06em;
  line-height: 1.55;
}

.brand-system {
  font-size: 14px;
  font-weight: 500;
  color: var(--mds-text-muted);
  margin-top: 3px;
  letter-spacing: 0.03em;
  line-height: 1.5;
}

.brand-rule {
  height: 0.5px;
  margin: 14px 0 16px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--mds-separator) 15%,
    var(--mds-separator) 85%,
    transparent
  );
}

.brand-page-title {
  font-size: clamp(26px, 6.5vw, 32px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.12;
  color: var(--mds-text);
}

.page-brand--compact {
  padding: 0;
  text-align: center;
}

.page-brand--compact .brand-hospital {
  font-size: 10px;
  letter-spacing: 0.04em;
  line-height: 1.45;
  max-width: 100%;
}

.page-brand--compact .brand-system {
  display: none;
}

.page-brand--compact .brand-rule {
  display: none;
}

.page-brand--compact .brand-page-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-top: 2px;
}

.record-subtitle {
  font-size: 15px;
  color: var(--mds-text-secondary);
  padding: 0 4px 16px;
  line-height: 1.5;
}

/* ── Large Title (iOS Settings 首页感) ── */
.page {
  max-width: 680px;
  margin: 0 auto;
  padding: 12px 16px calc(40px + env(safe-area-inset-bottom));
}

.page-wide {
  max-width: 1080px;
}

.large-title {
  font-size: clamp(28px, 7vw, 34px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  padding: 8px 4px 4px;
}

.large-subtitle {
  font-size: 15px;
  color: var(--mds-text-secondary);
  padding: 0 4px 16px;
  line-height: 1.5;
}

/* ── Meta chips ── */
.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 4px 20px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: var(--mds-radius-pill);
  background: var(--mds-surface);
  font-size: 13px;
  color: var(--mds-text-secondary);
  box-shadow: var(--mds-shadow-subtle);
}

.chip img,
.chip .chip-icon { width: 14px; height: 14px; opacity: 0.55; flex-shrink: 0; }

.chip--patient {
  font-weight: 500;
  color: var(--mds-text);
}

.meta-row--pc {
  padding: 0 4px 18px;
}

.subtitle-icon {
  vertical-align: -2px;
  margin-right: 4px;
  opacity: 0.55;
}

/* ── Icons (Tabler) ── */
.icon {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  opacity: 0.72;
}

/* ── Grouped List (HIG 核心) ── */
.group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--mds-text-secondary);
  padding: 0 16px 6px;
  margin-top: 22px;
}

.group-header-icon {
  opacity: 0.5;
}

.group-header:first-of-type { margin-top: 0; }

.label-icon,
.footnote-icon,
.summary-icon,
.bullet-icon,
.revision-label-icon {
  margin-right: 4px;
  vertical-align: -2px;
}

.icon-spin {
  opacity: 0.55;
  animation: iconSpin 0.9s linear infinite;
}

@keyframes iconSpin {
  to { transform: rotate(360deg); }
}

.btn-with-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-icon { opacity: 0.9; }

.input-icon-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.input-icon-wrap--hero {
  width: 100%;
}

.input-prefix-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.45;
  pointer-events: none;
}

.input-with-icon {
  padding-left: 42px !important;
  text-align: left;
}

.nav-key-label {
  display: flex;
  align-items: center;
  gap: 5px;
}

.group-cell-label {
  display: flex;
  align-items: center;
  gap: 5px;
}

.pc-hint-url {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

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

.pc-hint-footnote {
  display: flex;
  align-items: center;
  gap: 5px;
}

.dim-card .name {
  display: flex;
  align-items: center;
  gap: 5px;
}

.dim-icon { opacity: 0.5; }

.dim-total-val {
  font-size: 28px !important;
}

.dim-card--total {
  grid-column: 1 / -1;
}

.bullet-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.bullet-list li::after { display: none; }

.bullet-list li { padding-left: 16px; }

.revision-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.badge-icon { opacity: 0.85; }

.revision-empty-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 20px 16px !important;
}

.revision-empty-icon { opacity: 0.45; }

.squircle .squircle-icon,
.squircle img {
  filter: brightness(0) invert(1);
  opacity: 1;
}

/* ── Grouped List (HIG 核心) ── */
.group {
  background: var(--mds-surface);
  border-radius: var(--mds-radius-xl);
  overflow: hidden;
  box-shadow: var(--mds-shadow-subtle);
}

.group-cell {
  padding: 14px 16px;
  position: relative;
}

.group-cell + .group-cell::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 0.5px;
  background: var(--mds-separator);
}

.group-cell-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--mds-text-secondary);
  margin-bottom: 4px;
}

.group-cell-value {
  font-size: 17px;
  font-weight: 400;
  line-height: 1.4;
}

/* ── Score panel ── */
.score-panel {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0;
  align-items: center;
  padding: 20px 16px;
}

@media (max-width: 520px) {
  .score-panel { grid-template-columns: 1fr; gap: 16px; }
}

.score-ring-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#score-canvas {
  width: 140px;
  height: 140px;
  display: block;
}

.score-fallback .score-number {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--mds-primary);
  font-variant-numeric: tabular-nums;
}

.score-fallback .score-label {
  font-size: 13px;
  color: var(--mds-text-secondary);
  margin-top: 2px;
  text-align: center;
}

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

.dim-card {
  padding: 12px 14px;
  border-radius: var(--mds-radius-lg);
  background: var(--mds-bg);
}

.dim-card .name {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--mds-text-secondary);
  letter-spacing: 0.01em;
}

.dim-card .val {
  font-size: 22px;
  font-weight: 600;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.dim-card .val.tone-blue { color: var(--mds-primary); }
.dim-card .val.tone-green { color: var(--mds-success); }
.dim-card .val.tone-orange { color: var(--mds-warning); }
.dim-card .val.tone-indigo { color: var(--mds-accent); }

/* ── Revision cards（分段修改建议）── */
.revision-cell {
  padding: 16px;
}

.revision-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  margin-bottom: 12px;
  padding: 0;
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.revision-head-left,
.revision-head-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.revision-head-right { flex-shrink: 0; }

.revision-section-icon { opacity: 0.55; }

.revision-chevron {
  opacity: 0.45;
  transition: transform var(--spring-fast);
}

.revision-cell.is-collapsed .revision-chevron {
  transform: rotate(-90deg);
}

.revision-body {
  overflow: hidden;
  max-height: 2400px;
  opacity: 1;
  transition: max-height 0.32s cubic-bezier(0.25, 0.1, 0.25, 1), opacity 0.24s ease;
}

.revision-cell.is-collapsed .revision-body {
  max-height: 0;
  opacity: 0;
  margin-top: -12px;
}

.revision-cell.is-collapsed .revision-head {
  margin-bottom: 0;
}

.revision-head--static {
  cursor: default;
  margin-bottom: 12px;
}

.revision-section {
  font-size: 13px;
  font-weight: 600;
  color: var(--mds-primary);
  letter-spacing: 0.02em;
}

.revision-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--mds-radius-pill);
  flex-shrink: 0;
}

.revision-badge.sev-high {
  background: rgba(255, 59, 48, 0.12);
  color: var(--mds-danger);
}

.revision-badge.sev-medium {
  background: rgba(255, 149, 0, 0.14);
  color: var(--mds-warning);
}

.revision-badge.sev-low {
  background: rgba(0, 122, 255, 0.1);
  color: var(--mds-primary);
}

.revision-block {
  margin-bottom: 12px;
}

.revision-block:last-child {
  margin-bottom: 0;
}

.revision-label {
  display: flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--mds-text-muted);
  margin-bottom: 5px;
}

.revision-original {
  font-size: 14px;
  line-height: 1.65;
  color: var(--mds-text-secondary);
  padding: 10px 12px;
  border-radius: var(--mds-radius-lg);
  background: var(--mds-bg);
  border-left: 3px solid rgba(60, 60, 67, 0.2);
  word-break: break-word;
}

.highlight-target {
  color: var(--mds-danger);
  font-weight: 600;
  background: rgba(255, 59, 48, 0.12);
  padding: 1px 3px;
  border-radius: 3px;
}

.revision-original .ctx-ellipsis {
  color: var(--mds-text-muted);
}

/* PC 原文中的方括号占位符弱化显示 */
.content-box .emr-placeholder {
  color: var(--mds-text-muted);
  font-size: 0.92em;
  background: rgba(120, 120, 128, 0.08);
  padding: 0 2px;
  border-radius: 2px;
}


.revision-reason {
  font-size: 14px;
  line-height: 1.55;
  color: var(--mds-text);
}

.revision-revised {
  font-size: 14px;
  line-height: 1.6;
  color: var(--mds-text);
  padding: 12px 14px;
  border-radius: var(--mds-radius-lg);
  background: rgba(52, 199, 89, 0.08);
  border-left: 3px solid var(--mds-success);
}

.revision-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  color: var(--mds-text-secondary);
  font-weight: 500;
}

.revision-empty {
  font-size: 15px;
  color: var(--mds-text-secondary);
  text-align: center;
  padding: 8px 0;
}

/* ── Issue cards (legacy) ── */
.issue-cell .loc {
  font-size: 12px;
  font-weight: 600;
  color: var(--mds-primary);
  margin-bottom: 4px;
}

.issue-cell .problem {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.45;
  margin-bottom: 4px;
}

.issue-cell .suggestion {
  font-size: 14px;
  color: var(--mds-text-secondary);
  line-height: 1.55;
}

.bullet-list {
  list-style: none;
  padding: 0;
}

.bullet-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 16px;
  font-size: 15px;
  line-height: 1.55;
  position: relative;
}

.bullet-list li + li::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 0.5px;
  background: var(--mds-separator);
}

.bullet-list li::after { display: none; }

/* ── Section title with squircle icon ── */
.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 10px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.squircle {
  width: 32px;
  height: 32px;
  border-radius: 22%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.squircle img { width: 18px; height: 18px; filter: brightness(0) invert(1); }

.squircle-blue { background: linear-gradient(135deg, #64d2ff, #007aff); }
.squircle-green { background: linear-gradient(135deg, #63e6e2, #32ade6); }
.squircle-orange { background: linear-gradient(135deg, #ffb340, #ff9500); }
.squircle-indigo { background: linear-gradient(135deg, #7d7aff, #5856d6); }

/* ── Key box ── */
.key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.key-row code {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--mds-primary);
  font-variant-numeric: tabular-nums;
}

/* ── Mobile PC browser hint ── */
.pc-hint-cell {
  background: linear-gradient(180deg, rgba(0, 122, 255, 0.06) 0%, rgba(0, 122, 255, 0.02) 100%);
}

.pc-hint {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.pc-hint-icon-img {
  opacity: 0.85;
}

.pc-hint-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(0, 122, 255, 0.12);
  color: var(--mds-primary);
}

.pc-hint-lead {
  font-size: 15px;
  font-weight: 600;
  color: var(--mds-text);
  line-height: 1.35;
}

.pc-hint-note {
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--mds-text-secondary);
}

.pc-hint-url {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--mds-primary);
  text-decoration: none;
  letter-spacing: 0.01em;
  word-break: break-all;
}

.pc-hint-url:active {
  opacity: 0.65;
}

.pc-hint-footnote {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--mds-text-muted);
}

/* ── Buttons (press on pointerdown) ── */
.btn {
  border: none;
  border-radius: var(--mds-radius-pill);
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 600;
  background: var(--mds-primary);
  color: #fff;
  cursor: pointer;
  transition: transform var(--spring-press), opacity var(--spring-press);
  touch-action: manipulation;
  user-select: none;
}

.btn.is-pressed,
.btn:active {
  transform: scale(0.97);
  opacity: 0.82;
}

.btn-secondary {
  background: var(--mds-input-fill);
  color: var(--mds-primary);
}

.btn-secondary.is-pressed,
.btn-secondary:active {
  opacity: 0.65;
}

.btn-copied {
  background: var(--mds-success) !important;
  color: #fff !important;
}

/* ── Filled input (iOS) ── */
.input-filled {
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-radius: var(--mds-radius-lg);
  background: var(--mds-input-fill);
  font-size: 17px;
  letter-spacing: 0.1em;
  text-align: center;
  text-transform: uppercase;
  color: var(--mds-text);
  outline: none;
  transition: box-shadow var(--spring-fast);
}

.input-filled:focus {
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.14);
}

.input-filled::placeholder {
  color: var(--mds-text-muted);
  letter-spacing: 0;
  text-transform: none;
}

/* ── PC layout ── */
.pc-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

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

.content-box {
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.7;
  max-height: 72vh;
  overflow: auto;
  padding: 16px;
  color: var(--mds-text);
  -webkit-overflow-scrolling: touch;
}

.content-box::-webkit-scrollbar { width: 6px; }
.content-box::-webkit-scrollbar-thumb {
  background: var(--mds-separator);
  border-radius: 3px;
}

/* ── PC nav bar ── */
.nav-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--mds-separator);
  padding: 10px 20px 12px;
  margin: -12px -16px 20px;
}

.nav-bar .page-brand--compact .brand-page-title {
  margin-top: 0;
}

.nav-key-switch {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 0.5px solid var(--mds-separator);
}

.nav-key-label {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--mds-text-secondary);
  letter-spacing: 0.02em;
}

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

.input-compact {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  font-size: 15px;
  text-align: left;
  border-radius: 10px;
}

.btn-compact {
  flex-shrink: 0;
  padding: 10px 18px;
  font-size: 14px;
}

/* ── Input hero (PC index) ── */
.input-hero {
  max-width: 480px;
  margin: 10vh auto 0;
  padding: 0 20px 40px;
  text-align: center;
}

.input-hero .page-brand {
  padding-bottom: 28px;
}

.input-hero .brand-page-title {
  font-size: clamp(28px, 5vw, 34px);
}

.input-hero .large-subtitle { padding-bottom: 24px; }

.input-hero .btn { width: 100%; margin-top: 14px; padding: 14px; }

/* ── Error page ── */
.error-page {
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  gap: 12px;
}

.error-page .squircle { width: 56px; height: 56px; border-radius: 22%; margin-bottom: 8px; }
.error-page .squircle img { width: 28px; height: 28px; }

.error-page h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.error-page p {
  color: var(--mds-text-secondary);
  max-width: 300px;
  line-height: 1.6;
  font-size: 15px;
}

/* ── Stagger entrance (≤50ms per item) ── */
.stagger > * {
  opacity: 0;
  transform: translateY(6px);
  animation: staggerIn 0.38s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 40ms; }
.stagger > *:nth-child(3) { animation-delay: 80ms; }
.stagger > *:nth-child(4) { animation-delay: 120ms; }
.stagger > *:nth-child(5) { animation-delay: 160ms; }
.stagger > *:nth-child(6) { animation-delay: 200ms; }
.stagger > *:nth-child(7) { animation-delay: 240ms; }
.stagger > *:nth-child(8) { animation-delay: 280ms; }

@keyframes staggerIn {
  to { opacity: 1; transform: translateY(0); }
}

/* ── Loading skeleton ── */
.loading-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--mds-text-muted);
  font-size: 15px;
}

.loading-state--rich {
  min-height: 50vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.loading-text {
  font-size: 16px;
  font-weight: 500;
  color: var(--mds-text-secondary);
}

.loading-sub {
  font-size: 13px;
  color: var(--mds-text-muted);
}

/* ── Reduced motion & transparency (apple-design §14) ── */
@media (prefers-reduced-motion: reduce) {
  .stagger > * {
    opacity: 1;
    transform: none;
    animation: none;
  }
  .btn { transition: opacity 150ms ease; }
  .btn.is-pressed, .btn:active { transform: none; opacity: 0.7; }
  .icon-spin { animation: none; }
  .revision-body { transition: none; }
  .revision-chevron { transition: none; }
}

@media (prefers-reduced-transparency: reduce) {
  .nav-bar {
    background: var(--mds-surface);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  .group { border: 1px solid var(--mds-separator); }
  .chip { border: 1px solid var(--mds-separator); }
}
