@font-face {
  font-family: "Source Serif 4";
  src: url("fonts/source-serif-4-variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
}

@font-face {
  font-family: "Inter";
  src: url("fonts/inter-variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/ibm-plex-mono-regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  --paper: #e8dcc4;
  --paper-light: #d7e7da;
  --paper-deep: #bfd6c5;
  --ink: #202a38;
  --ink-soft: #55606c;
  --pen-red: #b0342b;
  --moss: #3e6b4f;
  --ochre: #a97a20;
  --rule: rgba(62, 107, 79, 0.12);
  --line: rgba(32, 42, 56, 0.28);
  --shadow: rgba(32, 42, 56, 0.14);
  --serif: "Source Serif 4", "Noto Serif CJK SC", "Songti SC", serif;
  --ui: "Inter", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --mono: "IBM Plex Mono", "Noto Sans Mono CJK SC", monospace;
}

* {
  border-radius: 0 !important;
  letter-spacing: 0;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--serif);
  background: var(--paper);
}

h1,
h2,
h3,
h4,
p,
dl,
dd {
  font-family: var(--serif);
}

h1,
h2,
h3 {
  color: var(--ink);
  font-weight: 680;
}

a {
  color: var(--ink);
  text-decoration-color: var(--pen-red);
  text-underline-offset: 3px;
}

a:hover {
  color: var(--pen-red);
}

button,
.button,
input,
select,
textarea,
label,
.topbar,
.workspace-top,
.review-workspace-bar,
.state-pill,
.badge,
.project-meta,
.meta,
.status-key,
.status-value,
.filter-count,
.slot-content,
.doctor-admin-table,
.admin-row,
.case-item {
  font-family: var(--ui);
}

button,
.button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(32, 42, 56, 0.46);
  background: var(--paper-light);
  color: var(--ink);
  padding: 7px 12px;
  box-shadow: none;
  font-weight: 650;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

button:hover,
.button:hover {
  color: var(--ink);
  border-color: var(--moss);
  background: var(--paper-deep);
}

button:active,
.button:active {
  background: #d2e5d6;
}

button:focus-visible,
.button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 2px solid var(--ochre);
  outline-offset: 3px;
}

.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper-light);
}

.primary:hover {
  background: var(--ink);
  border-color: var(--ink);
  color: #fffdf4;
}

.danger-button,
.danger-text,
.link-danger {
  color: var(--pen-red);
  border-color: var(--pen-red);
  background: #f8eeee;
}

input,
select,
textarea {
  border: 1px solid rgba(32, 42, 56, 0.46);
  border-bottom: 2px solid var(--ink);
  background: #ffffff;
  color: var(--ink);
  padding: 9px 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

input::placeholder,
textarea::placeholder {
  color: #7b786d;
}

.paper-select {
  min-height: 48px;
  border: 1px solid rgba(32, 42, 56, 0.62);
  border-left: 5px solid var(--moss);
  border-bottom: 2px solid var(--ink);
  background-color: rgba(223, 236, 226, 0.92);
  color: var(--ink);
  font-weight: 650;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.paper-select:hover {
  border-color: var(--moss);
  background-color: #d2e5d6;
}

.paper-select:invalid {
  color: var(--ink-soft);
  font-weight: 500;
}

.paper-select option {
  background: var(--paper-light);
  color: var(--ink);
  font-weight: 500;
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--pen-red);
  box-shadow: none;
}

.topbar,
.workspace-top {
  min-height: 58px;
  height: auto;
  position: relative;
  z-index: 20;
  background: rgba(232, 220, 196, 0.98);
  border: 0;
  border-bottom: 1px solid rgba(32, 42, 56, 0.24);
  box-shadow: none;
  padding: 10px clamp(16px, 3vw, 42px);
}

.topbar strong,
.workspace-top strong {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 720;
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  color: var(--ink);
  font-family: var(--ui);
  line-height: 1;
  white-space: nowrap;
}

.site-brand-logo {
  width: 46px;
  height: 36px;
  flex: 0 0 46px;
  overflow: hidden;
}

.site-brand-logo img {
  display: block;
  width: 54px;
  height: 54px;
  margin: -9px 0 0 -4px;
  object-fit: contain;
  mix-blend-mode: multiply;
}

.site-brand-name {
  font-size: 18px;
  font-weight: 720;
}

.topbar-identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-identity > span:last-child {
  padding-left: 12px;
  border-left: 1px solid rgba(32, 42, 56, 0.22);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar span,
.workspace-top span {
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 11px;
}

.page {
  width: min(1440px, calc(100% - 36px));
  margin: 0 auto;
  padding: 42px 0 70px;
}

.page h1 {
  font-size: 27px;
  line-height: 1.15;
}

.page-intro,
.section-heading,
.section-title-row {
  border-bottom: 1px solid var(--ink);
  padding-bottom: 13px;
}

.page-intro p,
.section-heading p,
.section-title-row .meta,
.project-main > p,
.instruction-summary > p {
  text-decoration: none;
}

.meta,
.subtle {
  color: var(--ink-soft);
}

.notification-section {
  margin: 0 0 28px;
}

.notification-heading,
.tab-panel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.notification-heading h1,
.tab-panel-heading h1 {
  margin: 0;
  font-size: 22px;
}

.notification-heading span,
.tab-panel-heading p {
  margin: 0;
  color: var(--ink-soft);
  font-family: var(--ui);
  font-size: 12px;
}

.notification-list {
  display: grid;
  gap: 10px;
}

.notification-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 16px;
  border: 1px solid rgba(32, 42, 56, 0.32);
  border-left: 4px solid var(--ochre);
  background: var(--paper-light);
}

.notification-card.review-submitted {
  border-left-color: var(--moss);
}

.notification-content {
  min-width: 0;
}

.notification-content strong {
  display: block;
  font-family: var(--serif);
  font-size: 16px;
}

.notification-content p {
  margin: 4px 0;
  color: var(--ink-soft);
}

.notification-content time {
  color: var(--ink-soft);
  font: 11px/1.4 var(--mono);
}

.task-tabs {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 20px;
}

.task-tab {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  border: 1px solid rgba(32, 42, 56, 0.34);
  background: rgba(232, 220, 196, 0.72);
  color: var(--ink);
  font-family: var(--ui);
  font-weight: 700;
  text-decoration: none;
}

.task-tab:hover,
.task-tab.active {
  border-color: var(--moss);
  background: var(--paper-light);
  color: var(--ink);
}

.task-tab span {
  min-width: 22px;
  padding: 2px 5px;
  border: 1px solid rgba(32, 42, 56, 0.25);
  text-align: center;
  font: 11px/1.2 var(--mono);
}

.task-tab-panel {
  min-width: 0;
}

button:disabled,
.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.alert,
.status-banner,
.workspace-alert {
  border: 1px solid currentColor;
  border-left-width: 3px;
  box-shadow: none;
}

.alert,
.status-banner.fail,
.workspace-alert {
  color: var(--pen-red);
  background: #f3d8c9;
}

.status-banner.pass,
.workspace-alert.success {
  color: var(--moss);
  background: #dbe5cf;
  border-color: var(--moss);
}

.status-banner.warn {
  color: #775313;
  background: #ebd59d;
  border-color: var(--ochre);
}

.admin-section {
  position: relative;
  background: transparent;
  border: 0;
  padding: 0 0 30px;
  margin: 0 0 28px;
}

.review-admin-table,
.review-project-list {
  display: grid;
  gap: 16px;
  border: 0;
}

.review-admin-project,
.review-project-row {
  position: relative;
  border: 1px solid rgba(32, 42, 56, 0.32);
  background: var(--paper-light);
  padding: 20px;
}

.review-admin-project:nth-child(even),
.review-project-row:nth-child(even),
.review-project-row.available {
  background: var(--paper-light);
}

.review-admin-project > header {
  align-items: center;
}

.project-title-line h2 {
  font-family: var(--serif);
  font-size: 20px;
}

.project-number,
.slot-letter,
.workspace-progress strong,
.status-count-grid strong,
.project-facts dd,
.progress-row,
.case-id {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.project-number {
  background: var(--ink);
  color: var(--paper-light);
  border: 0;
  padding: 4px 8px;
}

.state-pill,
.badge {
  min-height: 24px;
  border: 1px solid rgba(32, 42, 56, 0.5);
  box-shadow: none;
  transform: none;
  font-size: 11px;
}

.state-pill.open,
.state-pill.active,
.badge.done {
  color: #173f2a;
  background: #cbd9be;
}

.state-pill.locked,
.badge.partial {
  color: #69490f;
  background: #e7cf8d;
}

.state-pill.expired,
.state-pill.withdrawn,
.state-pill.submitted,
.state-pill.completed {
  color: #76251f;
  background: #e9beb2;
}

.state-pill.submitted,
.state-pill.completed {
  color: #244f36;
  background: #c6dac5;
}

.project-meta {
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 11px;
}

.progress,
.progress.compact,
.progress.small {
  height: 7px;
  border: 1px solid rgba(32, 42, 56, 0.45);
  background: var(--paper-deep);
}

.progress > div,
.progress.compact > div,
.progress.small > div {
  height: 100%;
  background: var(--moss);
}

.review-project-filters {
  margin: 18px 0 16px;
  padding: 14px;
  border: 1px solid rgba(32, 42, 56, 0.28);
  background: var(--paper-light);
  box-shadow: none;
}

.review-slot-grid {
  gap: 0;
  border: 1px solid rgba(32, 42, 56, 0.28);
  background: rgba(232, 220, 196, 0.48);
}

.review-slot {
  position: relative;
  min-height: 112px;
  border: 0;
  border-right: 1px solid rgba(32, 42, 56, 0.28);
  background: transparent;
  box-shadow: none;
  transform: none;
}

.review-slot:last-child {
  border-right: 0;
}

.review-slot:nth-child(2) {
  transform: none;
}

.review-slot:nth-child(3) {
  transform: none;
}

.slot-letter {
  background: var(--ink);
  color: var(--paper-light);
  font-size: 18px;
}

.slot-export-actions {
  border-color: rgba(32, 42, 56, 0.25);
}

.export-control {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
}

.export-details > summary {
  list-style: none;
  cursor: pointer;
}

.export-details > summary::-webkit-details-marker {
  display: none;
}

.export-details[open] > summary,
.export-control > button[aria-expanded="true"] {
  border-color: var(--moss);
  background: #d2e5d6;
}

.export-menu-options {
  position: absolute;
  z-index: 40;
  top: calc(100% + 5px);
  right: 0;
  display: grid;
  min-width: 174px;
  padding: 4px;
  border: 1px solid rgba(32, 42, 56, 0.58);
  background: var(--paper-light);
  box-shadow: 3px 4px 0 rgba(32, 42, 56, 0.12);
}

.export-menu-options[hidden] {
  display: none;
}

.export-menu-options a {
  min-height: 34px;
  display: flex;
  align-items: center;
  padding: 7px 9px;
  color: var(--ink);
  font-family: var(--ui);
  font-size: 12px;
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
}

.export-menu-options a:hover {
  color: var(--ink);
  background: #d2e5d6;
}

.slot-export-actions .export-menu-options {
  right: auto;
  left: 0;
}

.auto-project-number {
  border: 1px solid rgba(32, 42, 56, 0.28);
  background: var(--paper-light);
  box-shadow: none;
}

.auto-project-number strong {
  font-family: var(--mono);
  color: var(--ink);
}

.review-upload-form {
  padding: 20px;
  border: 1px solid rgba(32, 42, 56, 0.28);
  background: var(--paper-light);
}

.draft-file-status {
  display: block;
  margin-top: 6px;
  color: var(--moss);
  font: 11px/1.4 var(--mono);
}

#projectDraftStatus {
  min-height: 20px;
  display: inline-flex;
  align-items: center;
}

.registration-code-form {
  padding: 16px;
  border: 1px solid rgba(32, 42, 56, 0.28);
  background: var(--paper-light);
}

.doctor-admin-table,
.admin-table,
.progress-table {
  border: 1px solid rgba(32, 42, 56, 0.28);
  background: rgba(223, 236, 226, 0.76);
}

.doctor-admin-row,
.admin-row,
.progress-row {
  border-color: rgba(32, 42, 56, 0.24);
}

.doctor-admin-row.head,
.admin-row.head,
.progress-row.head {
  background: var(--ink);
  color: var(--paper-light);
}

.status-grid {
  grid-template-columns: repeat(5, minmax(140px, 1fr));
}

.status-item {
  border: 1px solid rgba(32, 42, 56, 0.28);
  background: var(--paper-light);
  box-shadow: none;
  transform: none;
}

.status-item:nth-child(even) {
  transform: none;
}

.status-item.pass {
  border-left: 6px solid var(--moss);
}

.status-item.warn {
  border-left: 6px solid var(--ochre);
  background: #f3e4bd;
}

.status-item.fail {
  border-left: 6px solid var(--pen-red);
}

.status-count-grid {
  border-color: var(--ink);
  background: var(--paper-light);
}

.status-count-grid > div {
  border-color: rgba(32, 42, 56, 0.38);
}

.status-count-grid strong {
  color: var(--pen-red);
}

.empty-state {
  border: 1px dashed var(--ink);
  background: var(--paper-light);
  color: var(--ink-soft);
  font-family: var(--ui);
}

.auth {
  position: relative;
  align-items: flex-start;
  padding-top: clamp(64px, 12vh, 130px);
}

.auth-panel {
  position: relative;
  background: var(--paper-light);
  border: 1px solid rgba(32, 42, 56, 0.28);
  padding: 34px;
  box-shadow: none;
  transform: none;
}

.auth-panel h1 {
  font-size: 30px;
  margin-top: 0;
}

.instruction-layout {
  grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
  gap: 26px;
  padding: 34px;
  background: transparent;
}

.instruction-viewer {
  grid-column: 1;
  grid-row: 1;
  padding: 0;
  filter: none;
}

.instruction-viewer iframe {
  border: 1px solid var(--ink);
  background: #ffffff;
}

.instruction-summary {
  grid-column: 2;
  grid-row: 1;
  align-self: start;
  position: relative;
  overflow: auto;
  border: 1px solid rgba(32, 42, 56, 0.28);
  background: var(--paper-light);
  padding: 28px;
  box-shadow: none;
  transform: none;
}

.project-facts {
  border-color: var(--ink);
}

.project-facts > div {
  border-color: rgba(32, 42, 56, 0.3);
}

.claim-form {
  border-top: 2px solid var(--pen-red);
  padding-top: 14px;
}

.review-workspace-shell {
  background: var(--paper);
}

.review-workspace-bar {
  background: rgba(232, 220, 196, 0.98);
  border-bottom: 1px solid rgba(32, 42, 56, 0.24);
  box-shadow: none;
}

.save-status-banner {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 14px;
  border-bottom: 1px solid rgba(62, 107, 79, 0.36);
  background: var(--paper-light);
  color: var(--moss);
  font-family: var(--ui);
  font-size: 12px;
}

.save-status-banner strong {
  font-family: var(--ui);
  font-size: 13px;
}

.workspace-project-name strong {
  font-family: var(--serif);
  font-size: 17px;
}

.workspace-project-name .site-brand {
  margin-bottom: 2px;
}

.review-workspace-bar .site-brand-logo,
.workspace-top .site-brand-logo {
  width: 35px;
  height: 28px;
  flex-basis: 35px;
}

.review-workspace-bar .site-brand-logo img,
.workspace-top .site-brand-logo img {
  width: 42px;
  height: 42px;
  margin: -7px 0 0 -3px;
}

.review-workspace-bar .site-brand-name,
.workspace-top .site-brand-name {
  font-size: 15px;
}

.review-task-frame {
  margin: 12px;
  width: calc(100% - 24px);
  border: 1px solid var(--ink);
  background: #ffffff;
  box-shadow: none;
}

.workspace {
  background: transparent;
}

.case-pane,
.annotation-pane {
  background: var(--paper-light);
  border-color: var(--ink);
}

.evidence-pane {
  background: #ffffff;
}

.case-item,
.card,
.doctor-answer,
.thumb,
.pdf-link {
  border: 1px solid rgba(32, 42, 56, 0.48);
  background: var(--paper-light);
  box-shadow: none;
}

.case-item.active,
.visit.current {
  border-left: 3px solid var(--pen-red);
  box-shadow: none;
}

.datebar {
  background: var(--paper-light);
  border-color: var(--ink);
}

.datebtn {
  border-color: var(--ink);
  background: transparent;
}

.datebtn.current {
  background: var(--ink);
  color: var(--paper-light);
}

code,
.fname,
.case-meta,
.system-status-meta {
  font-family: var(--mono);
}

@media (max-width: 1100px) {
  .status-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .instruction-layout {
    grid-template-columns: minmax(0, 1fr) 320px;
  }
}

@media (max-width: 900px) {
  .page {
    width: min(100% - 24px, 760px);
    padding-top: 34px;
  }

  .instruction-layout {
    display: flex;
    flex-direction: column;
    padding: 22px 14px;
  }

  .instruction-summary {
    order: 1;
    transform: none;
  }

  .instruction-viewer {
    order: 2;
    height: 68vh;
  }

  .review-slot {
    border-right: 0;
    border-bottom: 1px solid rgba(32, 42, 56, 0.28);
    transform: none !important;
  }

  .review-slot:last-child {
    border-bottom: 0;
  }

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

@media (max-width: 600px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
    padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  }

  .topbar-identity {
    width: 100%;
    flex: 0 0 auto;
    gap: 6px;
  }

  .topbar-identity > span:last-child {
    display: none;
  }

  .topbar .site-brand-logo {
    width: 38px;
    height: 30px;
    flex-basis: 38px;
  }

  .topbar .site-brand-logo img {
    width: 45px;
    height: 45px;
    margin: -7px 0 0 -3px;
  }

  .topbar .site-brand-name {
    font-size: 14px;
    white-space: normal;
    line-height: 1.2;
  }

  .topbar > div:last-child {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
    width: 100%;
    gap: 6px;
  }

  .topbar > div:last-child .button {
    width: 100%;
    min-width: 0;
  }

  .review-workspace-bar .workspace-actions {
    overflow-x: visible;
    flex-wrap: wrap;
  }

  .review-workspace-bar .export-menu-options {
    right: auto;
    left: 0;
  }

  .notification-card {
    align-items: flex-start;
    gap: 10px;
  }

  .notification-card .button {
    flex: 0 0 auto;
  }

  .task-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .task-tab {
    justify-content: center;
    padding-inline: 10px;
  }

  .tab-panel-heading {
    display: block;
  }

  .tab-panel-heading p {
    margin-top: 5px;
  }

  .auth {
    min-height: 100dvh;
    padding: 40px max(14px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }

  .auth-panel,
  .auth-panel.wide {
    width: 100%;
    padding: 26px 20px;
    transform: none;
  }

  .auth-panel .site-brand {
    max-width: 100%;
    white-space: normal;
    line-height: 1.2;
  }

  .auth-panel .site-brand-name {
    font-size: 16px;
  }

  button,
  .button,
  input,
  select,
  textarea {
    min-height: 44px;
    font-size: 16px;
  }

  input[type="checkbox"],
  input[type="radio"] {
    min-height: 20px;
    min-width: 20px;
  }

  .page {
    width: calc(100% - 24px);
    padding: 28px 0 max(48px, env(safe-area-inset-bottom));
  }

  .admin-section {
    padding: 14px;
  }

  .doctor-admin-table {
    border: 0;
    background: transparent;
  }

  .doctor-admin-row {
    background: rgba(223, 236, 226, 0.9);
  }

  .save-status-banner {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }

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

  .review-task-frame {
    margin: 6px;
    width: calc(100% - 12px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
