:root {
  color-scheme: light;
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface-2: #ebe6de;
  --text: #1f2629;
  --muted: #6b7478;
  --line: #d7d2ca;
  --primary: #263238;
  --primary-soft: #dfe8e8;
  --accent: #8a5b38;
  --danger: #b42318;
  --danger-bg: #fff0ed;
  --ok: #197a4d;
  --warn: #9a6200;
  --shadow: 0 8px 24px rgba(31, 38, 41, 0.08);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 160ms ease, background-color 180ms ease, color 180ms ease, border-color 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}

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

img {
  display: block;
  max-width: 100%;
}

.app-shell {
  min-height: 100vh;
  padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.screen {
  width: min(1120px, 100%);
  margin: 0 auto;
  animation: screen-enter 210ms cubic-bezier(0.22, 1, 0.36, 1);
}

.home-screen {
  min-height: calc(100vh - 44px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 24px;
}

.brand-bar,
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-title,
.page-title {
  margin: 0;
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1.1;
  font-weight: 800;
}

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

.home-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-content: center;
}

.entry-button {
  min-height: clamp(220px, 35vh, 380px);
  padding: 28px;
  border-radius: 8px;
  color: #fff;
  background: var(--primary);
  box-shadow: var(--shadow);
  text-align: left;
}

.entry-button.secondary {
  background: var(--accent);
}

.entry-button strong {
  display: block;
  font-size: clamp(34px, 7vw, 76px);
  line-height: 1;
}

.entry-button span {
  display: block;
  margin-top: 16px;
  font-size: clamp(17px, 2vw, 24px);
  opacity: 0.86;
}

.quiet-link {
  justify-self: end;
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
}

.quiet-link:hover,
.quiet-link:focus-visible {
  background: var(--surface-2);
  color: var(--text);
}

.back-button,
.ghost-button,
.small-button,
.icon-button {
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 6px;
  color: var(--text);
  background: var(--surface-2);
}

.icon-button {
  width: 44px;
  padding: 0;
  font-size: 26px;
  line-height: 1;
}

.primary-button,
.danger-button {
  min-height: 48px;
  padding: 12px 18px;
  border-radius: 6px;
  color: #fff;
  background: var(--primary);
  font-weight: 700;
}

.danger-button {
  background: var(--danger);
}

.export-button {
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 6px;
  color: #fff;
  background: #2e7d32;
  font-weight: 600;
  margin-left: auto;
}

.toolbar,
.form-grid,
.admin-login,
.return-search {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.return-search,
.admin-login {
  grid-template-columns: 1fr auto;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
}

.field textarea {
  min-height: 88px;
  resize: vertical;
}

.action-row {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.status-line {
  min-height: 24px;
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 650;
}

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

.catalog-grid,
.return-list,
.admin-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  margin: 16px 0 96px;
}

.item-card,
.return-card,
.admin-card,
.order-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  contain: layout paint style;
}

.item-card {
  position: relative;
  text-align: left;
  transform: translateZ(0);
  will-change: transform;
}

.catalog-grid .item-card,
.admin-list .admin-card,
.return-list .return-card {
  content-visibility: auto;
  contain-intrinsic-size: 360px 430px;
}

.item-card:active,
.entry-button:active,
.primary-button:active,
.danger-button:active,
.ghost-button:active,
.small-button:active,
.back-button:active {
  transform: scale(0.985);
}

.photo {
  width: 100%;
  aspect-ratio: 4 / 5;
  background: #d9d4ca;
  object-fit: cover;
  transform: translateZ(0);
}

.photo-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 4 / 5;
  background: #d9d4ca;
  color: var(--muted);
  font-weight: 800;
  font-size: 34px;
}

.card-body {
  display: grid;
  gap: 7px;
  padding: 12px;
}

.code-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 20px;
  font-weight: 800;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.meta {
  color: var(--muted);
  line-height: 1.35;
}

.note {
  color: var(--text);
  line-height: 1.4;
}

.match-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}

.label-text {
  font-size: 0.8rem;
  color: var(--muted);
  margin-right: 2px;
}

.match-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  background: #e8f5e9;
  color: #2e7d32;
  font-size: 0.82rem;
  font-weight: 500;
}

.borrow-bar {
  position: fixed;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  width: min(1088px, calc(100% - 28px));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 1fr minmax(180px, 260px) auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 14px 32px rgba(31, 38, 41, 0.16);
  backdrop-filter: blur(10px);
  animation: borrow-bar-enter 240ms cubic-bezier(0.22, 1, 0.36, 1);
}

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  animation: overlay-enter 160ms ease-out;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  min-height: 100%;
  padding: 0;
  border-radius: 0;
  background: rgba(31, 38, 41, 0.54);
  animation: backdrop-enter 180ms ease-out;
}

.item-modal,
.success-modal,
.edit-modal,
.delete-modal {
  position: relative;
  z-index: 1;
  width: min(960px, 100%);
  max-height: min(86vh, 760px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(31, 38, 41, 0.28);
  overflow: hidden;
  animation: modal-enter 240ms cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform, opacity;
}

.item-modal {
  display: grid;
  grid-template-columns: minmax(320px, 1.05fr) minmax(300px, 0.95fr);
}

.modal-photo {
  display: grid;
  align-items: stretch;
  min-height: 460px;
  background: #e8e2d8;
}

.modal-photo .photo,
.modal-photo .photo-placeholder {
  height: 100%;
  aspect-ratio: auto;
  object-fit: contain;
}

.modal-detail {
  display: grid;
  align-content: start;
  gap: 16px;
  padding: 22px;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.modal-header h2,
.success-modal h2 {
  margin: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.modal-actions,
.modal-borrow-form {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
}

.modal-borrow-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  padding-top: 6px;
}

.success-modal {
  display: grid;
  gap: 14px;
  width: min(520px, 100%);
  padding: 28px;
}

.success-modal p,
.delete-modal p {
  margin: 0;
  line-height: 1.5;
}

.delete-modal {
  display: grid;
  gap: 14px;
  width: min(540px, 100%);
  padding: 28px;
}

.delete-modal h2 {
  margin: 0;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.15;
}

.edit-modal {
  display: grid;
  gap: 18px;
  padding: 22px;
  overflow-y: auto;
}

.edit-form {
  margin: 0;
}

.edit-actions {
  grid-column: 1 / -1;
}

.helper-text {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.return-card,
.admin-card,
.order-card {
  padding: 14px;
}

.admin-card {
  position: relative;
}

.admin-card-tools {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: flex;
  gap: 6px;
}

.tool-button {
  min-width: 44px;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid rgba(31, 38, 41, 0.16);
  border-radius: 999px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 6px 14px rgba(31, 38, 41, 0.12);
  font-size: 13px;
  font-weight: 800;
}

.delete-tool {
  color: #fff;
  background: var(--danger);
}

.status-button.is-current {
  color: var(--ok);
  background: #e8f5e9;
}

.return-card {
  display: grid;
  gap: 12px;
}

.hang-tip {
  padding: 12px;
  border-radius: 6px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 19px;
  font-weight: 800;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  margin: 18px 0;
  overflow-x: auto;
  padding-bottom: 4px;
}

.tab-button {
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 6px;
  color: var(--text);
  background: var(--surface-2);
  white-space: nowrap;
}

.tab-button.active {
  color: #fff;
  background: var(--primary);
}

.admin-panel {
  display: grid;
  gap: 14px;
}

.admin-card.danger {
  border-color: #f1b0a9;
  background: var(--danger-bg);
}

.admin-card .button-row,
.return-card .button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.status-available {
  color: var(--ok);
}

.status-borrowed,
.status-overdue {
  color: var(--warn);
}

.status-exception {
  color: var(--danger);
}

.empty-state {
  margin: 40px auto;
  padding: 30px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
  text-align: center;
}

.order-card {
  display: grid;
  gap: 8px;
}

.orders-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.orders-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
}

.orders-table th,
.orders-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.orders-table th {
  color: var(--muted);
  background: #f8fafc;
  font-size: 13px;
  font-weight: 800;
}

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

.orders-table td:nth-child(5) {
  min-width: 220px;
  white-space: normal;
}

.orders-table td:last-child {
  display: flex;
  gap: 10px;
  align-items: center;
}

.orders-table a {
  color: #0f766e;
  font-weight: 800;
  text-decoration: none;
}

.table-sub {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.order-items {
  display: grid;
  gap: 8px;
}

.order-item {
  display: grid;
  grid-template-columns: 92px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.order-item a {
  color: #0f766e;
  font-weight: 800;
  text-decoration: none;
}

@keyframes screen-enter {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes borrow-bar-enter {
  from {
    opacity: 0;
    transform: translate(-50%, 12px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@keyframes overlay-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes backdrop-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-enter {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.975);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

@media (max-width: 760px) {
  .app-shell {
    padding: 14px;
  }

  .brand-bar,
  .top-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .home-actions {
    grid-template-columns: 1fr;
    align-content: stretch;
  }

  .entry-button {
    min-height: 210px;
  }

  .toolbar,
  .form-grid,
  .return-search,
  .admin-login {
    grid-template-columns: 1fr;
  }

  .catalog-grid,
  .return-list,
  .admin-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .borrow-bar {
    grid-template-columns: 1fr;
  }

  .modal-layer {
    align-items: end;
    padding: 12px;
  }

  .item-modal {
    grid-template-columns: 1fr;
    max-height: calc(100vh - 24px);
  }

  .modal-photo {
    min-height: 300px;
    max-height: 48vh;
  }

  .modal-detail {
    padding: 16px;
  }

  .modal-borrow-form {
    grid-template-columns: 1fr;
  }

  .order-item {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 440px) {
  .catalog-grid,
  .return-list,
  .admin-list {
    grid-template-columns: 1fr;
  }
}
