:root {
  color-scheme: light;
  --paper: #f4f4ef;
  --surface: #fffefa;
  --ink: #202c2a;
  --muted: #707b76;
  --line: #dfe3dc;
  --green: #246c55;
  --green-dark: #194e3d;
  --green-pale: #e5f1e9;
  --coral: #bd543f;
  --coral-pale: #f8ebe6;
  --yellow: #d7a94a;
  --heading-font: "Fraunces", Georgia, serif;
  --body-font: "DM Sans", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background-color: var(--paper);
  background-image: radial-gradient(#d6d9d0 0.65px, transparent 0.65px);
  background-size: 18px 18px;
  color: var(--ink);
  font-family: var(--body-font);
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
  position: relative;
  z-index: 5;
  min-height: 72px;
  padding: 0 clamp(20px, 5vw, 72px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 254, 250, 0.88);
}

.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 19px; }
.brand-mark { display: grid; width: 30px; height: 30px; place-items: center; background: var(--green); color: white; border-radius: 50% 50% 48% 8px; font-family: var(--heading-font); font-size: 17px; }
.brand-period { color: var(--coral); }
.desktop-nav { display: flex; align-self: stretch; align-items: center; gap: 7px; margin-left: auto; }
.nav-link { min-height: 40px; display: inline-flex; align-items: center; padding: 0 13px; border-radius: 4px; color: var(--muted); font-size: 13px; font-weight: 600; }
.nav-link:hover, .nav-link.is-active { background: var(--green-pale); color: var(--green-dark); }
.nav-logout-form { margin: 0; }
.nav-action { border: 0; background: transparent; cursor: pointer; font-family: inherit; }
.nav-action:hover { background: var(--coral-pale); color: #873d30; }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: 17px; }
.mobile-nav { display: none; }
.menu-toggle { min-height: 42px; display: inline-flex; align-items: center; gap: 8px; padding: 0 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--ink); cursor: pointer; font-size: 13px; font-weight: 700; list-style: none; }
.menu-toggle::-webkit-details-marker { display: none; }
.menu-glyph { color: var(--green); font-size: 18px; line-height: 1; }
.mobile-nav-panel { position: absolute; top: calc(100% + 8px); right: 16px; z-index: 10; width: min(260px, calc(100vw - 32px)); display: grid; gap: 4px; padding: 8px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); box-shadow: 0 12px 30px rgba(32, 44, 42, 0.14); }
.mobile-nav-panel .nav-link { width: 100%; min-height: 46px; }
.page-shell { width: min(1100px, calc(100% - 40px)); margin: 0 auto; padding: 54px 0 96px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding-bottom: 32px; }
h1, h2, h3, p { margin-top: 0; }
h1, h2 { font-family: var(--heading-font); font-weight: 600; letter-spacing: 0; }
h1 { margin-bottom: 8px; font-size: 42px; line-height: 1.1; }
h2 { margin-bottom: 0; font-size: 27px; line-height: 1.2; }
h3 { margin-bottom: 3px; font-size: 16px; font-weight: 700; line-height: 1.3; }

.button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 10px; padding: 0 17px; border: 1px solid transparent; border-radius: 5px; cursor: pointer; font-size: 13px; font-weight: 700; transition: background-color 140ms ease, border-color 140ms ease, transform 140ms ease; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:focus-visible, .icon-button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid rgba(36, 108, 85, 0.28); outline-offset: 2px; }
.button-primary { background: var(--green); color: #fff; }
.button-primary:hover:not(:disabled) { background: var(--green-dark); }
.button-outline { border-color: var(--line); background: transparent; color: var(--ink); }
.button-outline:hover { border-color: var(--green); color: var(--green); }
.button-quiet { background: transparent; color: var(--muted); }
.button-small { min-height: 36px; padding: 0 12px; font-size: 12px; }
.button-wide { width: 100%; margin-top: 12px; }
.button:disabled { opacity: 0.5; cursor: not-allowed; }
.button-icon { font-size: 19px; font-weight: 400; line-height: 1; }

.summary-strip { display: flex; width: fit-content; margin: 0 0 58px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.summary-item { min-width: 136px; padding: 13px 22px 13px 0; display: flex; align-items: baseline; gap: 8px; }
.summary-item + .summary-item { padding-left: 22px; border-left: 1px solid var(--line); }
.summary-number { color: var(--green); font-family: var(--heading-font); font-size: 24px; font-weight: 600; }
.summary-label { color: var(--muted); font-size: 12px; }
.content-section { margin-top: 0; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; padding-bottom: 15px; border-bottom: 1px solid var(--ink); }
.section-count { padding-bottom: 3px; color: var(--muted); font-size: 12px; }
.search-form { display: flex; align-items: center; gap: 9px; margin: 0 0 28px; }
.search-form input { flex: 1; min-width: 0; min-height: 46px; padding: 10px 13px; border: 1px solid #cdd3cb; border-radius: 4px; background: var(--surface); color: var(--ink); font: inherit; }
.search-form input:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px rgba(36, 108, 85, 0.12); }
.search-isbn-wrap { position: relative; flex: 1 1 200px; min-width: 0; }
.search-isbn-wrap input { width: 100%; padding-right: 50px; }
.search-clear { padding: 8px 4px; color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
.search-clear:hover { color: var(--green); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.book-list, .loan-list { border-bottom: 1px solid var(--line); }
.book-row { min-height: 110px; display: grid; grid-template-columns: minmax(230px, 1fr) 142px minmax(200px, auto); align-items: center; gap: 24px; padding: 19px 0; border-bottom: 1px solid var(--line); }
.book-row:last-child, .loan-row:last-child { border-bottom: 0; }
.book-main { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) 56px; align-items: start; gap: 12px; }
.book-copy { min-width: 0; grid-column: 1; }
.book-copy > p, .loan-book > p { margin: 0; color: var(--muted); font-size: 13px; }
.book-cover-slot { width: 56px; height: 82px; grid-column: 2; grid-row: 1; display: grid; place-items: start center; }
.book-cover { display: block; width: 56px; height: 82px; object-fit: contain; background: var(--surface); }
.book-identifiers { display: flex; flex-wrap: wrap; gap: 5px 14px; margin-top: 8px; color: var(--muted); font-size: 11px; }
.stock-block { display: flex; align-items: baseline; gap: 7px; }
.stock-value { color: var(--green); font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stock-divider { padding: 0 3px; color: #a0aaa2; font-size: 15px; font-weight: 400; }
.stock-label { color: var(--muted); font-size: 11px; }
.book-actions { display: flex; align-items: center; justify-content: end; gap: 5px; }
.book-actions form { display: contents; }
.icon-button { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; font-size: 20px; }
.icon-button:hover { background: #e9ece5; color: var(--ink); }
.icon-primary { background: var(--green); color: #fff; }
.icon-primary:hover { background: var(--green-dark); color: #fff; }
.icon-danger { color: var(--coral); }
.icon-danger:hover { background: var(--coral-pale); color: #873d30; }
.availability-none { margin-right: 5px; color: var(--muted); font-size: 11px; }
.empty-state { padding: 48px 20px; text-align: center; }
.empty-mark { width: 42px; height: 42px; display: grid; place-items: center; margin: 0 auto 14px; border: 1px solid #c6d4c9; border-radius: 50%; color: var(--green); font-size: 23px; }
.empty-state h3 { font-family: var(--heading-font); font-size: 20px; }
.empty-state p, .quiet-empty { color: var(--muted); font-size: 13px; }
.text-link { display: inline-flex; gap: 8px; margin-top: 7px; color: var(--green); font-size: 13px; font-weight: 700; }
.loans-section { margin-top: 60px; }
.loan-row { min-height: 86px; display: grid; grid-template-columns: minmax(180px, 1fr) minmax(160px, 0.8fr) minmax(140px, 0.7fr) auto; align-items: center; gap: 20px; padding: 15px 0; border-bottom: 1px solid var(--line); }
.loan-student { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.loan-student span, .date-label { color: var(--muted); font-size: 11px; }
.loan-date { display: flex; flex-direction: column; gap: 2px; font-size: 13px; font-variant-numeric: tabular-nums; }
.loan-date-value { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 5px; }
.loan-age { color: var(--muted); font-size: 12px; }
.loan-age-warning { padding: 2px 7px; border-radius: 3px; background: var(--coral-pale); color: #873d30; font-weight: 700; }
.quiet-empty { padding: 22px 0; }

.back-link { display: inline-flex; align-items: center; gap: 8px; margin: 0 0 26px; color: var(--muted); font-size: 13px; }
.back-link:hover { color: var(--green); }
.form-page { width: min(100%, 600px); }
.duplicate-confirmation { margin-top: 24px; padding: 18px; border: 1px solid var(--line); border-left: 4px solid var(--yellow); border-radius: 4px; background: var(--surface); }
.duplicate-confirmation h2 { margin-bottom: 12px; font-size: 22px; }
.duplicate-confirmation > p { margin-bottom: 8px; color: var(--muted); font-size: 13px; }
.duplicate-confirmation > p strong { color: var(--ink); }
.duplicate-confirmation .form-actions { flex-wrap: wrap; }
.form-stack { display: flex; flex-direction: column; align-items: stretch; gap: 9px; }
.form-stack label { margin-top: 8px; font-size: 13px; font-weight: 700; }
.form-stack input { width: 100%; min-height: 47px; padding: 10px 12px; border: 1px solid #cdd3cb; border-radius: 4px; background: var(--surface); color: var(--ink); }
.form-stack input:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px rgba(36, 108, 85, 0.12); }
.required-mark { color: var(--coral); }
.form-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field-group { display: flex; flex-direction: column; gap: 9px; }
.field-hint { margin: 0; color: var(--muted); font-size: 12px; }
.isbn-lookup-row { display: flex; align-items: center; gap: 8px; }
.isbn-lookup-row { flex-wrap: wrap; }
.isbn-input-wrap { position: relative; flex: 1 1 150px; min-width: 0; }
.isbn-input-wrap input { width: 100%; min-width: 0; padding-right: 50px; }
.isbn-scan-button { position: absolute; top: 4px; right: 4px; width: 39px; height: 39px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 4px; background: transparent; color: var(--green); cursor: pointer; }
.isbn-scan-button:hover { background: var(--green-pale); color: var(--green-dark); }
.isbn-scan-button:focus-visible { outline: 3px solid rgba(36, 108, 85, 0.28); outline-offset: 1px; }
.isbn-lookup-row .button { flex: 0 0 auto; }
.scanner-dialog { width: min(520px, calc(100vw - 28px)); max-height: min(90dvh, 760px); margin: auto; padding: 20px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); box-shadow: 0 18px 56px rgba(20, 35, 30, 0.24); }
.scanner-dialog::backdrop { background: rgba(20, 35, 30, 0.62); }
.scanner-dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.scanner-dialog-header h2 { font-size: 24px; }
.scanner-dialog-header .icon-button { flex: 0 0 auto; }
.scanner-instructions { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.scanner-video { display: block; width: 100%; max-height: 56dvh; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 4px; background: #17231f; }
.scanner-photo-fallback { display: grid; justify-items: start; gap: 8px; }
.scanner-photo-fallback .scanner-instructions { margin-bottom: 0; }
.scanner-dialog .lookup-status { margin-top: 10px; }
.lookup-status { min-height: 0; margin: 0; color: var(--muted); font-size: 12px; }
.lookup-status:not(:empty) { min-height: 18px; }
.lookup-status.lookup-error { color: #873d30; }
.metadata-preview { padding: 15px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); }
.metadata-preview-main { display: flex; align-items: flex-start; gap: 16px; }
.metadata-cover { width: 90px; height: 132px; flex: 0 0 auto; object-fit: contain; background: var(--paper); }
.metadata-list { flex: 1; min-width: 0; display: grid; gap: 8px; margin: 0; }
.metadata-list > div { display: grid; grid-template-columns: minmax(145px, 0.45fr) minmax(0, 1fr); gap: 12px; font-size: 12px; }
.metadata-list dt { color: var(--muted); }
.metadata-list dd { min-width: 0; margin: 0; overflow-wrap: anywhere; }
.metadata-list [data-metadata-field="description"] dd { max-height: 8em; overflow: auto; }
.metadata-hint { margin: 12px 0 0; color: var(--muted); font-size: 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.selected-book { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin: 25px 0 24px; padding: 18px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.selected-book h2 { font-size: 20px; }
.selected-book p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.available-pill { flex: 0 0 auto; padding: 6px 10px; border-radius: 3px; background: var(--green-pale); color: var(--green-dark); font-size: 11px; font-weight: 700; }
.flash-stack { display: grid; gap: 8px; margin-bottom: 20px; }
.flash { margin: 0; padding: 11px 14px; border-left: 3px solid; font-size: 13px; }
.flash-success { border-color: var(--green); background: var(--green-pale); color: var(--green-dark); }
.flash-error { border-color: var(--coral); background: var(--coral-pale); color: #783e33; }
.login-shell { min-height: calc(100vh - 72px); display: grid; place-items: center; padding-top: 30px; }
.login-panel { width: min(100%, 410px); padding: 36px; border: 1px solid var(--line); border-top: 4px solid var(--green); background: var(--surface); box-shadow: 0 16px 40px rgba(32, 44, 42, 0.06); }
.login-panel h1 { font-size: 36px; }

@media (max-width: 760px) {
  .page-shell { width: min(100% - 32px, 600px); padding-top: 34px; }
  .topbar { min-height: 62px; padding: 0 16px; }
  .desktop-nav { display: none; }
  .topbar-actions { margin-left: auto; }
  .mobile-nav { display: block; }
  .mobile-nav-panel .nav-logout-form .nav-action { width: 100%; justify-content: flex-start; }
  .page-heading { align-items: start; flex-direction: column; padding-bottom: 25px; }
  .page-heading .button { align-self: stretch; }
  .search-form { gap: 6px; margin-bottom: 23px; }
  .search-form .button { min-height: 44px; padding: 0 12px; }
  .search-clear { padding: 6px 2px; }
  h1 { font-size: 36px; }
  .summary-strip { width: 100%; margin-bottom: 43px; }
  .summary-item { min-width: 0; flex: 1; padding-right: 10px; gap: 6px; }
  .summary-item + .summary-item { padding-left: 12px; }
  .summary-number { font-size: 22px; }
  .summary-label { font-size: 11px; }
  .book-row { grid-template-columns: 1fr auto; gap: 10px 12px; padding: 17px 0; }
  .book-main { grid-column: 1 / -1; }
  .stock-block { grid-column: 1; align-self: center; }
  .book-actions { grid-column: 2; grid-row: 2; }
  .book-actions .button-small { min-height: 34px; }
  .availability-none { display: none; }
  .loans-section { margin-top: 44px; }
  .loan-row { grid-template-columns: 1fr auto; gap: 12px; padding: 16px 0; }
  .loan-book { grid-column: 1; }
  .loan-student { grid-column: 1; }
  .loan-date { grid-column: 1; }
  .loan-row form { grid-column: 2; grid-row: 1 / span 3; }
  .loan-row form .button { white-space: nowrap; }
}

@media (max-width: 430px) {
  .form-columns { grid-template-columns: 1fr; gap: 9px; }
  .metadata-preview-main { display: grid; grid-template-columns: minmax(0, 1fr); }
  .metadata-list > div { grid-template-columns: minmax(135px, 0.45fr) minmax(0, 1fr); gap: 8px; }
  .login-panel { padding: 28px 22px; }
  .section-heading { align-items: end; }
  .section-heading h2 { font-size: 23px; }
  .section-count { white-space: nowrap; }
}

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