:root {
  color-scheme: light;
  --ink: #111111;
  --paper: #ffffff;
  --muted: #9a9a9a;
  --hairline: #eaeaea;
  --line-strong: #111111;
  --line-hover: #888888;
  --field: #f4f4f4;
  --danger: #aa3333;
  --accent: #a67c00;
  --radius-card: 3px;
  --radius-button: 2px;
  --font-brand: "Montserrat", "Noto Sans SC", sans-serif;
  --font-serif: "Noto Serif SC", "Cormorant", serif;
  --font-body: "Montserrat", "Noto Sans SC", sans-serif;
  --font-mono: "SFMono-Regular", "JetBrains Mono", "Roboto Mono", monospace;
  --ease: 180ms ease;
  --page-gutter: clamp(18px, 5vw, 32px);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--paper);
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  letter-spacing: 0;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 48px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-button);
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--ease), color var(--ease), border-color var(--ease), opacity var(--ease);
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

button:hover {
  background: var(--ink);
  color: var(--paper);
}

.app {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) var(--page-gutter) calc(32px + env(safe-area-inset-bottom));
  background: var(--paper);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  gap: 10px;
  margin: calc(-12px - env(safe-area-inset-top)) calc(var(--page-gutter) * -1) 14px;
  padding: calc(10px + env(safe-area-inset-top)) var(--page-gutter) 10px;
  border-bottom: 1px solid var(--hairline);
  background: color-mix(in srgb, var(--paper) 96%, transparent);
  backdrop-filter: blur(14px);
}

.top-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
}

.brand {
  min-width: 0;
}

.wordmark {
  color: var(--ink);
  font-family: var(--font-brand);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 3.2px;
  line-height: 0.95;
  text-transform: uppercase;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-family: var(--font-brand);
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 4px;
  text-transform: uppercase;
}

.avatar {
  position: relative;
  display: grid;
  place-items: center;
  width: 48px;
  min-width: 48px;
  height: 48px;
  min-height: 48px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  overflow: visible;
  padding: 0;
}

.avatar img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.avatar.switchable::after {
  content: "⇄";
  position: absolute;
  left: -3px;
  bottom: -3px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--paper);
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  font-size: 11px;
  line-height: 1;
}

.title-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 10px;
  margin-top: 0;
}

.back-button {
  display: grid;
  place-items: center;
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-color: var(--hairline);
}

.back-button svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.back-button[hidden] {
  visibility: hidden;
  display: grid;
}

.title-spacer {
  grid-column: 3;
  width: 44px;
  height: 44px;
}

.page-heading {
  grid-column: 2;
  display: grid;
  justify-items: center;
  gap: 6px;
  min-width: 0;
  text-align: center;
}

#page-title {
  text-indent: 3px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-family: var(--font-serif);
  font-size: clamp(22px, 6vw, 28px);
  font-weight: 700;
  letter-spacing: 3px;
  line-height: 1.05;
  white-space: nowrap;
}

#page-kicker,
.section-kicker,
.modal-kicker {
  color: var(--muted);
  font-family: var(--font-brand);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 2.2px;
  line-height: 1;
  text-transform: uppercase;
}

.page-heading::after {
  content: "";
  width: 32px;
  height: 1px;
  margin-top: 1px;
  background: var(--ink);
}

h2 {
  display: grid;
  gap: 5px;
  margin-bottom: 18px;
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 900;
  line-height: 1.2;
}

h2::after {
  content: attr(data-kicker);
  min-height: 10px;
  color: var(--muted);
  font-family: var(--font-brand);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 2.4px;
  text-transform: uppercase;
}

.panel {
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  padding: 22px;
  margin-bottom: 18px;
  background: var(--paper);
}

.panel[hidden],
[hidden] {
  display: none !important;
}

.user-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 14px;
  margin-bottom: 20px;
}

.user-line strong {
  font-family: var(--font-serif);
  font-size: 24px;
  line-height: 1.1;
}

.user-line span {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 1px;
}

.quick-actions,
.form,
.filter-form,
.inventory-current,
.home-return,
.home-recent {
  display: grid;
  gap: 16px;
}

.section-label {
  margin: 4px 0 -4px;
  color: var(--muted);
  font-family: var(--font-brand);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 3px;
  line-height: 1.2;
  text-transform: uppercase;
}

.section-label[hidden] {
  display: none !important;
}

.home-search {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 56px;
  align-items: stretch;
  min-height: 56px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-button);
  overflow: hidden;
  background: var(--paper);
}

.home-search::before {
  content: "";
  position: absolute;
  left: 16px;
  top: 50%;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
  transform: translateY(-58%);
}

.home-search::after {
  content: "";
  position: absolute;
  left: 30px;
  top: 34px;
  width: 7px;
  height: 1.5px;
  background: var(--muted);
  transform: rotate(45deg);
  transform-origin: left center;
}

.home-search input {
  width: 100%;
  min-width: 0;
  border: 0;
  padding: 0 16px 0 44px;
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
}

.home-search input::placeholder,
input::placeholder {
  color: var(--muted);
}

.home-scan-button,
.home-search-button {
  min-height: 56px;
  border: 0;
  border-left: 1px solid var(--hairline);
  border-radius: 0;
}

.home-search-button {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.home-scan-button {
  display: grid;
  place-items: center;
}

.scan-icon {
  position: relative;
  display: block;
  width: 23px;
  height: 23px;
}

.scan-icon::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(var(--ink), var(--ink)) left top / 8px 1.5px no-repeat,
    linear-gradient(var(--ink), var(--ink)) left top / 1.5px 8px no-repeat,
    linear-gradient(var(--ink), var(--ink)) right top / 8px 1.5px no-repeat,
    linear-gradient(var(--ink), var(--ink)) right top / 1.5px 8px no-repeat,
    linear-gradient(var(--ink), var(--ink)) left bottom / 8px 1.5px no-repeat,
    linear-gradient(var(--ink), var(--ink)) left bottom / 1.5px 8px no-repeat,
    linear-gradient(var(--ink), var(--ink)) right bottom / 8px 1.5px no-repeat,
    linear-gradient(var(--ink), var(--ink)) right bottom / 1.5px 8px no-repeat;
}

.scan-icon::after {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  top: 10px;
  height: 1.5px;
  background: var(--ink);
}

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

.actions.single {
  grid-template-columns: 1fr;
}

.admin-actions,
.employee-actions {
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.admin-actions button,
.employee-actions button {
  display: grid;
  justify-items: start;
  align-content: start;
  gap: 8px;
  min-height: 98px;
  padding: 14px;
  border-color: var(--hairline);
  background: var(--paper);
  color: var(--ink);
  text-align: left;
}

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

.admin-actions button:hover,
.employee-actions button:hover,
.permission-entry:hover {
  border-color: var(--line-hover);
  background: var(--paper);
  color: var(--ink);
}

.admin-actions svg,
.employee-actions svg,
.permission-entry svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.action-copy {
  display: grid;
  gap: 2px;
}

.action-copy strong {
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 1px;
  line-height: 1.25;
}

.action-copy small {
  color: var(--muted);
  font-family: var(--font-brand);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 2px;
  line-height: 1.2;
  text-transform: uppercase;
}

.permission-entry {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  justify-self: stretch;
  min-height: 64px;
  padding: 16px 18px;
  border-style: dashed;
  color: var(--ink);
  background: var(--paper);
  text-align: left;
}

.filter-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 46px;
  margin-bottom: 12px;
  padding: 0 13px;
  text-align: left;
}

.filter-toggle::after {
  content: "";
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-left: auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  transition: transform var(--ease);
}

.filter-toggle[aria-expanded="true"]::after {
  transform: rotate(225deg) translate(-2px, -1px);
}

.filter-toggle > span {
  flex: 0 0 auto;
  font-weight: 700;
}

.filter-toggle small {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--font-brand);
  font-size: 10px;
  letter-spacing: 1.5px;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

#sample-filter-form {
  display: none;
  margin-bottom: 12px;
}

#sample-filter-form.expanded {
  display: grid;
}

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

.compact-list {
  max-height: 280px;
  overflow: auto;
  padding-right: 2px;
}

.card {
  position: relative;
  display: grid;
  gap: 8px;
  width: 100%;
  min-height: 0;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  padding: 15px;
  background: var(--paper);
  color: var(--ink);
  text-align: left;
}

button.card {
  cursor: pointer;
}

.card:hover {
  border-color: var(--line-hover);
  background: var(--paper);
  color: var(--ink);
}

.sample-card {
  grid-template-columns: 60px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
}

.sample-thumb {
  display: grid;
  place-items: center;
  width: 60px;
  aspect-ratio: 3 / 4;
  border: 1px solid var(--hairline);
  background: var(--field);
  overflow: hidden;
}

.sample-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sample-thumb svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.5;
}

.sample-copy {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.card strong,
.sample-title {
  display: block;
  min-width: 0;
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 900;
  line-height: 1.25;
  word-break: break-word;
}

.card span,
.result,
.sample-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.sample-meta,
.field strong,
.qr-preview span {
  font-family: var(--font-mono);
  letter-spacing: 0.2px;
}

.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 3px 9px;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: var(--paper);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  white-space: nowrap;
}

.status.warn,
.status-borrowed,
.status-progress {
  background: var(--ink);
  color: var(--paper);
}

.status-overdue,
.status-danger {
  gap: 6px;
  background: var(--ink);
  color: var(--paper);
}

.status-overdue::before,
.overdue-line::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--danger);
}

.card .status {
  color: var(--ink);
}

.card .status.warn,
.card .status.status-borrowed,
.card .status.status-progress,
.card .status.status-danger,
.card .status.status-overdue {
  color: var(--paper);
}

.recent-list {
  display: grid;
  border-top: 1px solid var(--hairline);
}

.recent-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 13px 0;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  text-align: left;
}

.recent-row:hover {
  background: var(--paper);
  color: var(--ink);
}

.recent-row .sample-thumb {
  width: 42px;
  aspect-ratio: 3 / 4;
}

.recent-row .sample-thumb svg {
  width: 20px;
  height: 20px;
}

.recent-row .sample-copy {
  gap: 1px;
}

.recent-row .sample-title {
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0;
}

.recent-row .sample-meta {
  font-size: 10px;
  letter-spacing: 1px;
}

.overdue-line {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--danger);
  font-weight: 700;
}

.proof-line,
.proof-preview {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.proof-image,
.proof-preview img,
.image-preview img {
  display: block;
  width: 96px;
  aspect-ratio: 3 / 4;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  object-fit: cover;
}

.detail-hero {
  display: grid;
  place-items: center;
  justify-self: center;
  place-self: center;
  width: min(100%, 240px);
  min-height: 200px;
  max-height: 320px;
  aspect-ratio: 3 / 4;
  margin-inline: auto;
  margin-bottom: 14px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  background: var(--field);
  background-position: center;
  background-size: cover;
  color: var(--ink);
  font-family: var(--font-brand);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 3px;
  text-transform: uppercase;
}

.detail-hero:not(.empty)::after {
  content: "";
  position: absolute;
}

.fields {
  display: grid;
  margin-bottom: 18px;
}

.field {
  display: grid;
  grid-template-columns: minmax(112px, 34%) 1fr;
  gap: 16px;
  align-items: center;
  min-height: 48px;
  border-bottom: 1px solid var(--hairline);
}

.field > span:first-child {
  color: var(--muted);
  font-size: 13px;
}

.field strong,
.field > span:last-child {
  min-width: 0;
  justify-self: end;
  color: var(--ink);
  text-align: right;
  word-break: break-word;
}

.field > .status.warn,
.field > .status.status-borrowed,
.field > .status.status-progress,
.field > .status.status-danger,
.field > .status.status-overdue {
  color: var(--paper);
}

.field > .status:not(.warn):not(.status-borrowed):not(.status-progress):not(.status-danger):not(.status-overdue) {
  color: var(--ink);
}

label:has(input[required])::after,
label:has(select[required])::after {
  content: "必填";
  justify-self: start;
  margin-top: -4px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 1.8px;
}

.qr-detail-block,
.qr-preview {
  display: grid;
  justify-items: center;
  gap: 10px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  padding: 18px;
  background: var(--paper);
}

.qr-detail-block img,
.qr-preview img {
  width: 176px;
  height: 176px;
  image-rendering: crisp-edges;
}

.qr-preview label {
  width: 100%;
}

.image-preview {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.summary div,
.summary-card {
  min-height: 92px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  padding: 13px;
  background: var(--paper);
  color: var(--ink);
  text-align: left;
}

.summary-card {
  cursor: pointer;
}

.summary-card:hover {
  border-color: var(--line-hover);
  background: var(--paper);
  color: var(--ink);
}

.summary strong {
  display: block;
  font-family: var(--font-serif);
  font-size: 32px;
  font-weight: 900;
  line-height: 1;
}

.summary span {
  display: block;
  margin-top: 11px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 1px;
}

.summary .status-summary {
  grid-column: 1 / -1;
  min-height: 68px;
}

.summary .status-summary strong {
  font-family: var(--font-body);
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
}

.inventory-board,
.inventory-create-section {
  display: grid;
  gap: 14px;
}

.inventory-record-card {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  cursor: pointer;
}

.inventory-record-card:active,
.summary-card:active,
.log-card:active {
  transform: translateY(1px);
}

.log-card {
  cursor: pointer;
}

.log-detail {
  display: grid;
  gap: 5px;
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--hairline);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.log-card.expanded {
  border-color: var(--line-strong);
}

.report-chart {
  display: grid;
  gap: 9px;
  margin-top: 10px;
}

.chart-row {
  display: grid;
  grid-template-columns: minmax(76px, 34%) 1fr auto;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.chart-bar {
  height: 5px;
  background: var(--field);
}

.chart-bar span {
  display: block;
  height: 100%;
  background: var(--ink);
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-button);
  padding: 0 13px;
  background: var(--field);
  color: var(--ink);
}

input[readonly] {
  background: var(--paper);
  color: var(--muted);
}

input[type="file"] {
  min-height: auto;
  padding: 12px;
}

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

.return-check-form,
.return-request-form {
  display: grid;
  gap: 12px;
  margin-top: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
}

.inline-action,
.action-main {
  width: 100%;
}

.inventory-scan-actions {
  margin-top: 2px;
}

.inventory-complete-actions {
  margin-bottom: 8px;
}

.result {
  min-height: 24px;
}

.result.error {
  color: var(--danger);
}

.result.ok {
  color: var(--ink);
  font-weight: 700;
}

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--ink) 58%, transparent);
}

.modal-card {
  width: min(100%, 420px);
  border: 1px solid var(--ink);
  border-radius: var(--radius-card);
  padding: 24px;
  background: var(--paper);
  color: var(--ink);
}

.modal-card h2 {
  margin-bottom: 10px;
}

.modal-card p:not(.modal-kicker) {
  margin-bottom: 18px;
  color: var(--muted);
}

.modal-card .actions {
  gap: 10px;
}

@media (max-width: 420px) {
  .app {
    padding-left: 16px;
    padding-right: 16px;
  }

  .topbar {
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
    padding-right: 16px;
  }

  .panel {
    padding: 18px;
  }

  .sample-card {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .sample-card .status {
    grid-column: 2;
    justify-self: start;
  }

  .summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid,
  .field {
    grid-template-columns: 1fr;
  }

  .field strong,
  .field > span:last-child {
    justify-self: start;
    text-align: left;
  }

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

  .admin-actions,
  .employee-actions,
  #sample-filter-form .actions,
  #sample-filter-form .form-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .home-search {
    grid-template-columns: minmax(0, 1fr) 56px;
  }
}

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