:root {
  color-scheme: light;
  --canvas: #f3eee5;
  --paper: #fbf8f2;
  --paper-strong: #fffdf9;
  --paper-soft: #f0e8dc;
  --ink: #29241f;
  --muted: #7b7168;
  --line: #ddd3c6;
  --line-strong: #cbbdaf;
  --accent: #d36f4a;
  --accent-dark: #b95d3e;
  --accent-soft: #f5e3da;
  --red: #a84a42;
  --green: #47725f;
  --amber: #94611e;
  --control-height: 46px;
  --radius-control: 10px;
  --radius-panel: 16px;
  --shadow: 0 18px 48px rgba(78, 60, 45, 0.08);
  --font-display: "Iowan Old Style", "Palatino Linotype", "Source Han Serif SC",
    "Noto Serif SC", "Songti SC", serif;
  --font-ui: Inter, "SF Pro Text", -apple-system, BlinkMacSystemFont,
    "PingFang SC", "Microsoft YaHei", sans-serif;
  font-family: var(--font-ui);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% -16rem, rgba(255, 253, 249, 0.95), transparent 42rem),
    var(--canvas);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

button,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control-height);
  padding: 0 1rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: rgba(255, 253, 249, 0.88);
  color: var(--ink);
  cursor: pointer;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  transition:
    border-color 150ms ease,
    background-color 150ms ease,
    color 150ms ease,
    box-shadow 150ms ease,
    transform 150ms ease;
}

button:hover:not(:disabled),
.button-link:hover {
  border-color: rgba(211, 111, 74, 0.58);
  background: var(--paper-strong);
  color: var(--accent-dark);
  box-shadow: 0 5px 16px rgba(105, 76, 54, 0.08);
  transform: translateY(-1px);
}

button:active:not(:disabled),
.button-link:active {
  transform: translateY(0);
}

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

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fffdf9;
  box-shadow: 0 7px 18px rgba(185, 93, 62, 0.18);
}

button.primary:hover:not(:disabled) {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
  color: #fff;
}

.danger-button {
  border-color: rgba(168, 74, 66, 0.32);
  color: var(--red);
}

:focus-visible {
  outline: 3px solid rgba(211, 111, 74, 0.28);
  outline-offset: 3px;
}

label {
  color: #514941;
  font-size: 0.82rem;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-height: var(--control-height);
  margin-top: 0.42rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--paper-strong);
  color: var(--ink);
  transition:
    border-color 150ms ease,
    box-shadow 150ms ease,
    background-color 150ms ease;
}

input:hover,
select:hover,
textarea:hover {
  border-color: #b9a99a;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(211, 111, 74, 0.1);
  outline: none;
}

textarea {
  min-height: 5rem;
  resize: vertical;
}

h1,
h2,
h3 {
  margin-top: 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 600;
}

p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0.55rem;
  font-size: clamp(2.25rem, 4vw, 3.65rem);
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1.12;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.3rem, 2vw, 1.55rem);
  line-height: 1.3;
}

h3 {
  margin-bottom: 0.7rem;
  font-size: 1.05rem;
}

.workbench {
  width: min(1280px, calc(100% - 3rem));
  margin: 0 auto;
  padding: 1.5rem 0 4.5rem;
}

.workbench-header,
.section-heading,
.drawer-header,
.archive-card,
.file-link,
.button-row,
.header-actions,
.export-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.workbench-hero {
  position: relative;
  justify-content: center;
  min-height: 15.5rem;
  padding: 2.7rem 15rem 2.3rem;
  text-align: center;
}

.workbench-hero > div {
  max-width: 42rem;
}

.workbench-hero .muted {
  max-width: 34rem;
  margin: 0 auto;
  font-size: 0.98rem;
}

.header-actions {
  position: absolute;
  top: 1rem;
  right: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.header-actions button,
.header-actions .button-link {
  min-height: 42px;
  padding-inline: 0.9rem;
  background: rgba(251, 248, 242, 0.62);
  backdrop-filter: blur(10px);
}

.export-actions,
.button-row {
  flex-wrap: wrap;
}

.eyebrow {
  margin-bottom: 0.42rem;
  color: var(--accent-dark);
  font: 700 0.69rem/1.35 var(--font-ui);
  letter-spacing: 0.18em;
}

.muted,
.timeline-meta,
.empty-copy {
  color: var(--muted);
}

.notice {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.2rem;
  margin: -0.7rem 0 0.7rem;
  color: var(--green);
  font-weight: 600;
  text-align: center;
}

.notice:empty {
  visibility: hidden;
}

.notice[data-tone="error"] {
  color: var(--red);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.65rem;
  width: min(58rem, 100%);
  margin: 0 auto 1.4rem;
}

.stats-grid article,
.panel,
.snapshot-card,
.archive-card,
.file-link,
.settings-dialog {
  border: 1px solid var(--line);
  background: rgba(251, 248, 242, 0.94);
}

.stats-grid article {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 4.2rem;
  padding: 0.7rem 0.9rem;
  border-radius: 999px;
  box-shadow: 0 7px 22px rgba(78, 60, 45, 0.045);
}

.stats-grid span {
  color: var(--muted);
  font-size: 0.79rem;
  white-space: nowrap;
}

.stats-grid strong {
  margin-left: 0.5rem;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 600;
  line-height: 1;
}

.panel {
  margin-top: 1.25rem;
  padding: 1.35rem;
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow);
}

.section-heading {
  align-items: flex-start;
  margin-bottom: 1rem;
}

.section-heading > div:first-child {
  min-width: 0;
}

.section-heading h3 {
  margin-bottom: 0;
}

.registrations-panel {
  padding-bottom: 1rem;
}

.filters-panel {
  background: rgba(251, 248, 242, 0.86);
}

.export-actions {
  justify-content: flex-end;
}

.export-actions button {
  min-height: 42px;
  background: transparent;
  color: #514941;
}

.filter-grid {
  display: grid;
  grid-template-columns:
    minmax(11rem, 1fr)
    minmax(11rem, 1fr)
    minmax(11rem, 1fr)
    minmax(20rem, 1.15fr);
  gap: 0.85rem;
  align-items: end;
}

.filter-grid label {
  min-width: 0;
}

.filter-grid input[type="date"] {
  scroll-margin-top: 1rem;
}

.workbench:has(.filter-grid input[type="date"]:focus) {
  padding-bottom: 22rem;
}

.filter-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  align-self: end;
}

.filter-actions button {
  width: 100%;
  min-height: var(--control-height);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-strong);
}

table {
  width: 100%;
  min-width: 920px;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  padding: 0.88rem 0.95rem;
  border-bottom: 1px solid #e8e0d6;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f3ede4;
  color: #655b53;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.045em;
  white-space: nowrap;
}

th:first-child {
  border-top-left-radius: 11px;
}

th:last-child {
  border-top-right-radius: 11px;
}

tbody tr {
  cursor: pointer;
  transition: background-color 140ms ease;
}

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

tbody tr:hover,
tbody tr:focus {
  background: #fcf0e9;
}

.query-cell {
  max-width: 28rem;
}

.empty-row {
  padding: 2.6rem;
  color: var(--muted);
  text-align: center;
}

.status-chip,
.mini-chip {
  display: inline-flex;
  align-items: center;
  min-height: 1.65rem;
  padding: 0.16rem 0.58rem;
  border-radius: 999px;
  background: #ebe5df;
  color: #5f554c;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-pending,
.status-borrowed {
  background: #f7ead0;
  color: #805315;
}

.status-processing {
  background: #e7e5d7;
  color: #666134;
}

.status-completed,
.status-returned {
  background: #e2ece5;
  color: var(--green);
}

.status-cancelled {
  background: #f2e2df;
  color: var(--red);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.7rem;
  margin-top: 0.9rem;
}

.pagination button {
  min-height: 40px;
  padding-inline: 0.85rem;
}

#paginationSummary {
  min-width: 4.5rem;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.drawer-backdrop {
  position: fixed;
  z-index: 40;
  inset: 0;
  background: rgba(46, 37, 30, 0.32);
  backdrop-filter: blur(4px);
}

.drawer {
  position: fixed;
  z-index: 50;
  inset: 0 0 0 auto;
  width: min(48rem, 94vw);
  overflow: hidden;
  border-left: 1px solid var(--line);
  background: var(--paper);
  box-shadow: -24px 0 64px rgba(55, 42, 32, 0.18);
  transform: translateX(102%);
  transition: transform 180ms ease;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  min-height: 5.4rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: #f4ede4;
}

.drawer-header > button {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 1.45rem;
  font-weight: 400;
}

.drawer-body {
  height: calc(100vh - 5.4rem);
  overflow-y: auto;
  padding: 1rem 1.25rem 4rem;
}

.drawer-body > section {
  padding: 1.15rem 0;
  border-bottom: 1px solid var(--line);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
}

.detail-pair {
  min-width: 0;
  padding: 0.75rem;
  border-radius: 10px;
  background: #f2ebe2;
}

.detail-pair dt {
  color: var(--muted);
  font-size: 0.76rem;
}

.detail-pair dd {
  margin: 0.18rem 0 0;
  overflow-wrap: anywhere;
  font-weight: 600;
}

.snapshot-card,
.archive-card,
.file-link {
  margin: 0.6rem 0;
  padding: 0.8rem;
  border-radius: 11px;
  box-shadow: none;
}

.snapshot-card p,
.archive-card p {
  margin: 0.15rem 0 0;
  overflow-wrap: anywhere;
}

.rule-badges {
  display: inline-flex;
  gap: 0.35rem;
  margin-left: 0.5rem;
}

.signature-preview {
  display: block;
  width: min(100%, 30rem);
  max-height: 16rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  object-fit: contain;
}

.file-link {
  color: var(--ink);
  text-decoration: none;
}

.file-link:hover {
  border-color: var(--accent);
}

.file-link span {
  margin-left: auto;
}

.grow {
  flex: 1 1 auto;
  min-width: 0;
}

.inline-form {
  display: flex;
  align-items: end;
  gap: 0.7rem;
  margin-top: 0.85rem;
}

.timeline {
  margin: 0;
  padding-left: 1.4rem;
}

.timeline li {
  margin: 0 0 0.85rem;
  padding: 0 0 0.85rem 0.4rem;
  border-bottom: 1px dashed var(--line);
}

.timeline li::marker {
  color: var(--accent);
}

.timeline-meta {
  display: block;
  font-size: 0.76rem;
}

.timeline p {
  margin: 0.25rem 0 0;
}

.modal {
  position: fixed;
  z-index: 70;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(46, 37, 30, 0.38);
  backdrop-filter: blur(5px);
}

.settings-dialog {
  width: min(72rem, 100%);
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  border-radius: var(--radius-panel);
  box-shadow: 0 28px 80px rgba(50, 38, 29, 0.24);
}

.settings-dialog > form {
  padding: 1.25rem;
}

.settings-dialog section + section {
  margin-top: 1.5rem;
}

.settings-row {
  display: grid;
  grid-template-columns: minmax(12rem, 2fr) minmax(6rem, 0.7fr) minmax(5rem, 0.6fr);
  gap: 0.7rem;
  margin-bottom: 0.7rem;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f3ece3;
}

.settings-row.material-row {
  grid-template-columns: repeat(4, minmax(8rem, 1fr));
}

.settings-field input[type="checkbox"] {
  width: 1.3rem;
  min-height: 1.3rem;
  accent-color: var(--accent);
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 1.1rem;
}

@media (max-width: 72rem) {
  .workbench-hero {
    min-height: 14rem;
    padding-inline: 10rem;
  }

  .stats-grid {
    width: 100%;
  }

  .filter-grid {
    grid-template-columns: repeat(2, minmax(12rem, 1fr));
  }

  .settings-row.material-row {
    grid-template-columns: repeat(2, minmax(9rem, 1fr));
  }
}

@media (max-width: 52rem) {
  .workbench {
    width: min(100% - 1rem, 1280px);
    padding-top: 0.5rem;
  }

  .workbench-hero {
    align-items: stretch;
    flex-direction: column;
    min-height: auto;
    padding: 5.2rem 0 2rem;
  }

  .header-actions {
    top: 0.35rem;
    right: 0;
    left: 0;
    justify-content: center;
  }

  .header-actions button,
  .header-actions .button-link {
    flex: 1 1 9rem;
  }

  h1 {
    font-size: clamp(2rem, 11vw, 3rem);
  }

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

  .stats-grid article {
    min-width: 0;
    border-radius: 13px;
  }

  .panel {
    padding: 1rem;
    border-radius: 13px;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

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

  .filter-grid,
  .settings-row,
  .settings-row.material-row {
    grid-template-columns: 1fr;
  }

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

  .drawer {
    width: 100%;
  }

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

  .inline-form,
  .file-link,
  .archive-card {
    align-items: stretch;
    flex-direction: column;
  }

  .file-link span {
    margin-left: 0;
  }
}

@media (max-width: 24rem) {
  .stats-grid,
  .filter-actions {
    grid-template-columns: 1fr;
  }

  .pagination {
    justify-content: center;
    gap: 0.4rem;
  }
}

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