/* NHC Library Request System: application styles. Tokens in tokens.css, font faces in fonts.css.
   Step 1 of the UX upgrade: foundation and app shell. Form and table components are refined in later steps. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  font-family: var(--font-sans); font-size: var(--text-base); line-height: var(--leading);
  color: var(--text); background: var(--paper);
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
img, svg { max-width: 100%; height: auto; }
a { color: var(--link); text-underline-offset: .15em; }
a:hover { color: var(--link-hover); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-sm); box-shadow: 0 0 0 6px rgb(159 195 217 / .55); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

h1, h2, h3 { font-family: var(--font-serif); font-weight: 600; line-height: 1.2; letter-spacing: -.005em; color: var(--text); }
h1 { font-size: var(--text-2xl); margin: 0 0 var(--space-4); }
h2 { font-size: var(--text-xl); margin: var(--space-6) 0 var(--space-2); }
h3 { font-size: var(--text-lg); margin: var(--space-5) 0 var(--space-2); }
p { margin: 0 0 var(--space-3); }
.muted { color: var(--text-muted); }

/* ---------- App shell ---------- */
.skip { position: absolute; left: -999px; top: var(--space-2); z-index: 100; background: var(--surface); padding: var(--space-2) var(--space-3); border-radius: var(--radius); box-shadow: var(--shadow); }
.skip:focus { left: var(--space-3); }

.site-header { background: var(--surface); border-top: 4px solid var(--brand-navy); border-bottom: 1px solid var(--border); }
.site-header__inner { max-width: var(--container); margin: 0 auto; padding: var(--space-3) var(--space-4); display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-5); }
.brand { display: flex; align-items: center; gap: var(--space-3); text-decoration: none; color: var(--text); }
.brand:hover { color: var(--text); }
.brand__logo { display: block; height: 44px; width: auto; }
.brand__app { font-family: var(--font-serif); font-size: var(--text-lg); font-weight: 600; padding-left: var(--space-3); border-left: 2px solid var(--brand-sky); line-height: 1.1; }

.site-nav { display: flex; flex-wrap: wrap; gap: var(--space-1); flex: 1 1 auto; }
.site-nav a { display: inline-block; padding: var(--space-2) var(--space-3); border-radius: var(--radius); color: var(--text); text-decoration: none; font-weight: 600; border-bottom: 3px solid transparent; }
.site-nav a:hover { background: var(--navy-tint); color: var(--link-hover); }
.site-nav a[aria-current="page"] { color: var(--brand-navy); border-bottom-color: var(--brand-navy); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }

.nav-toggle { display: none; align-items: center; gap: var(--space-2); margin-left: auto; padding: var(--space-2) var(--space-3); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); cursor: pointer; font-weight: 600; }
.nav-toggle__bars { width: 1.1rem; height: 2px; background: currentColor; box-shadow: 0 -5px 0 currentColor, 0 5px 0 currentColor; }

.user-menu { position: relative; margin-left: auto; }
.user-menu > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-weight: 600; }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary::after { content: ""; width: .45rem; height: .45rem; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg) translateY(-2px); }
.user-menu[open] > summary { background: var(--navy-tint); }
.user-menu__avatar { display: inline-grid; place-items: center; width: 1.9rem; height: 1.9rem; border-radius: 50%; background: var(--brand-navy); color: var(--text-on-brand); font-size: var(--text-sm); }
.user-menu__panel { position: absolute; right: 0; top: calc(100% + var(--space-2)); z-index: 50; min-width: 15rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--space-2); }
.user-menu__who { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); margin-bottom: var(--space-2); }
.user-menu__who small { display: block; color: var(--text-muted); }
.user-menu__panel a, .user-menu__panel button { display: block; width: 100%; text-align: left; padding: var(--space-2) var(--space-3); border: 0; background: none; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; cursor: pointer; }
.user-menu__panel a:hover, .user-menu__panel button:hover { background: var(--navy-tint); color: var(--link-hover); }
.user-menu__panel form { margin: 0; }

.site-main { flex: 1 0 auto; width: 100%; max-width: var(--container); margin: 0 auto; padding: var(--space-5) var(--space-4) var(--space-7); }
.site-main--narrow { max-width: var(--container-narrow); }
.site-footer { background: var(--surface); border-top: 1px solid var(--border); color: var(--text-muted); font-size: var(--text-sm); }
.site-footer__inner { max-width: var(--container); margin: 0 auto; padding: var(--space-4); display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-5); justify-content: space-between; }
.site-footer a { color: var(--text-muted); }

/* Small screens: with JavaScript the nav folds behind a button; without it the links simply stay visible and wrap. */
@media (max-width: 48rem) {
  .brand__logo { height: 38px; }
  .brand__app { font-size: var(--text-base); }
  .site-nav { order: 3; flex-basis: 100%; flex-direction: column; }
  .site-nav a { padding: var(--space-3); }
  .js .nav-toggle { display: inline-flex; }
  .js .site-nav[data-collapsed="true"] { display: none; }
  .user-menu { order: 2; }
}

/* ---------- Surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: var(--space-5); }
.card h1 { margin-top: 0; }
.page-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.page-header h1 { margin: 0; }
.error-page { text-align: center; padding: var(--space-7) var(--space-4); }
.error-page__code { font-family: var(--font-serif); font-size: 4rem; line-height: 1; margin: 0; color: var(--brand-navy); }

/* ---------- Buttons ---------- */
button, .button { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); padding: var(--space-2) var(--space-4); min-height: 2.5rem; border: 1px solid var(--brand-navy); border-radius: var(--radius); background: var(--surface); color: var(--brand-navy); font-weight: 600; text-decoration: none; cursor: pointer; line-height: 1.2; }
button:hover, .button:hover { background: var(--navy-tint); color: var(--link-hover); }
button.primary, .button.primary { background: var(--brand-navy); color: var(--text-on-brand); }
button.primary:hover, .button.primary:hover { background: var(--navy-hover); color: var(--text-on-brand); }
button.danger { border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: var(--danger-bg); color: var(--danger); }
button.link { border: 0; background: none; padding: 0; min-height: 0; font-weight: 400; color: var(--link); text-decoration: underline; }
button[disabled] { opacity: .55; cursor: not-allowed; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- Forms ---------- */
/* Markup comes from templates/django/forms/field.html: .field > label, .helptext, the control, .errorlist. */
label, legend { font-weight: 600; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=url], input[type=date], select, textarea {
  display: block; width: 100%; min-height: 2.6rem; padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface);
}
textarea { min-height: 6rem; resize: vertical; line-height: 1.4; }
input[size], input[type=date] { width: auto; max-width: 100%; }
input[type=checkbox], input[type=radio] { width: 1.15rem; height: 1.15rem; margin: 0; accent-color: var(--brand-navy); flex: none; }
select { appearance: auto; }

.field { margin: 0 0 var(--space-4); min-width: 0; }
.field > label, .field > fieldset > legend { display: block; margin: 0 0 var(--space-1); padding: 0; }
.field fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.field__req { margin-left: var(--space-1); color: var(--text-muted); font-size: var(--text-sm); font-weight: 400; }
.helptext { margin: 0 0 var(--space-1); color: var(--text-muted); font-size: var(--text-sm); }
.field .errorlist { margin: var(--space-1) 0 0; }
.field--error input:not([type=checkbox]):not([type=radio]), .field--error select, .field--error textarea {
  border-color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger);
}
.errorlist { list-style: none; padding: 0; margin: var(--space-1) 0; color: var(--danger); font-size: var(--text-sm); font-weight: 600; }
.errorlist li::before { content: "Error: "; } /* text, so the error is never signalled by colour alone */
.form-errors { margin-bottom: var(--space-3); }

.choices { display: grid; gap: var(--space-2); }
.choice label, .field__check label { display: flex; align-items: center; gap: var(--space-2); font-weight: 400; }
.field__check { display: flex; align-items: center; gap: var(--space-2); }
.field--checkbox .field__check label { order: 2; }

/* Layouts */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 0 var(--space-4); align-items: start; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-top: var(--space-4); }
.form-narrow { max-width: 40rem; }
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3); margin-bottom: var(--space-4); }
.inline-form .field { flex: 1 1 14rem; margin: 0; }
.inline-form .form-actions { margin: 0; }
.inline-form--spaced { margin-top: var(--space-3); }

.error-summary { border: 2px solid var(--danger); background: var(--danger-bg); border-radius: var(--radius); padding: var(--space-3) var(--space-4); margin-bottom: var(--space-4); }
.error-summary h2 { margin: 0 0 var(--space-2); font-size: var(--text-lg); color: var(--danger); }
.error-summary ul { margin: 0; padding-left: var(--space-5); }
.error-summary:focus { outline-offset: 3px; }

/* The staff filter: the few filters used daily stay visible, the rest fold away (open when one is active). */
.filter-bar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-4); margin-bottom: var(--space-4); }
.filter-bar .form-grid { margin-bottom: var(--space-1); }
.more-filters { margin-bottom: var(--space-3); border-top: 1px solid var(--border); padding-top: var(--space-2); }
.more-filters > summary { cursor: pointer; font-weight: 600; color: var(--brand-navy); padding: var(--space-1) 0; }
.more-filters__count { display: inline-grid; place-items: center; min-width: 1.4rem; height: 1.4rem; padding: 0 .35rem; margin-left: var(--space-1); border-radius: 999px; background: var(--brand-navy); color: var(--text-on-brand); font-size: var(--text-sm); }
.more-filters .form-grid { margin-top: var(--space-3); }

/* ---------- Tables, badges, messages ---------- */
table { border-collapse: collapse; width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); font-size: .98rem; }
th, td { text-align: left; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-muted); font-weight: 600; font-size: var(--text-sm); text-transform: none; color: var(--neutral-90); }
caption { text-align: left; font-weight: 600; padding: var(--space-1) 0; color: var(--text-muted); }
tbody tr:hover { background: var(--mist-tint); }

.badge { display: inline-flex; align-items: center; gap: .4rem; padding: .1rem .65rem; border-radius: 999px; font-size: var(--text-sm); font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; }
.badge--pending { background: var(--navy-tint); color: var(--brand-navy); }
.badge--fulfilled { background: var(--mist-tint); color: var(--brand-navy); box-shadow: inset 0 0 0 1px var(--brand-sky); }
.badge--unavailable { background: var(--warning-bg); color: var(--warning); }
.badge--returned { background: var(--success-bg); color: var(--success); }

.alert, ul.messages li { padding: var(--space-3) var(--space-4); margin: var(--space-2) 0; border-radius: var(--radius); border-left: 4px solid var(--info); background: var(--info-bg); }
.alert--success, ul.messages li.success { border-color: var(--success); background: var(--success-bg); color: var(--success); }
.alert--warning, ul.messages li.warning { border-color: var(--warning-fill); background: var(--warning-bg); color: var(--warning); }
.alert--error, ul.messages li.error { border-color: var(--danger); background: var(--danger-bg); color: var(--danger); }
ul.messages { list-style: none; padding: 0; margin: 0 0 var(--space-4); }

dl.fields { display: grid; grid-template-columns: 12rem 1fr; gap: var(--space-1) var(--space-4); }
dl.fields dt { color: var(--text-muted); }
dl.fields dd { margin: 0; }
.actions form { display: inline; }
.pager { display: flex; gap: var(--space-4); margin: var(--space-4) 0; }
article { border-top: 1px solid var(--border); padding-top: var(--space-1); margin-top: var(--space-4); }
article h2 { font-size: 1.15rem; margin: var(--space-2) 0 var(--space-1); }

/* Citations and bibliographies are reading text, so they use the serif face. */
ul.bibliography, .citation { font-family: var(--font-serif); font-size: 1.05rem; line-height: 1.55; }
ul.bibliography { list-style: none; padding: 0; }
ul.bibliography li { padding-left: var(--space-6); text-indent: calc(-1 * var(--space-6)); margin: var(--space-2) 0; } /* hanging indent */

@media (max-width: 40rem) { dl.fields { grid-template-columns: 1fr; } h1 { font-size: var(--text-xl); } }
.card-links { margin: var(--space-4) 0 0; font-size: var(--text-sm); }
.form-grid .field--checkbox { align-self: end; padding-bottom: .6rem; } /* line a lone checkbox up with the inputs beside it */
.page-header--inline { justify-content: flex-start; gap: var(--space-4); }

/* ---------- htmx: progress bar and toasts ---------- */
.page-progress { position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 60; background: var(--brand-navy); transform: scaleX(0); transform-origin: left; opacity: 0; pointer-events: none; }
.page-progress.htmx-request { opacity: 1; transform: scaleX(0.85); transition: transform 8s cubic-bezier(.1,.7,.2,1), opacity 0.1s; }
.js ul.messages { position: fixed; right: var(--space-4); bottom: var(--space-4); z-index: 50; width: min(24rem, calc(100vw - 2 * var(--space-4))); margin: 0; }
.js ul.messages:empty { display: none; }
.js ul.messages li { display: flex; gap: var(--space-3); justify-content: space-between; align-items: flex-start; box-shadow: var(--shadow); background-clip: padding-box; }
ul.messages .toast__close { background: none; border: 0; padding: 0 var(--space-1); font: inherit; line-height: 1; color: inherit; cursor: pointer; }
@media (prefers-reduced-motion: reduce) { .page-progress.htmx-request { transition: none; } }

/* ---------- Staff queue: busy state and phone cards ---------- */
.results.htmx-request { opacity: .55; transition: opacity .15s; }
.stack__empty td { padding: var(--space-5, 1.5rem) var(--space-4); text-align: center; color: var(--text-muted); }
@media (max-width: 40rem) {
  table.stack, table.stack thead, table.stack tbody, table.stack tr, table.stack td { display: block; }
  table.stack { border: 0; background: none; }
  table.stack thead { position: absolute; left: -9999px; }
  table.stack caption { display: block; width: auto; margin-bottom: var(--space-2); }
  table.stack td:empty { display: none; }
  table.stack tbody tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: var(--space-3); padding: var(--space-2) var(--space-3); }
  table.stack td { display: flex; gap: var(--space-3); justify-content: space-between; border: 0; padding: var(--space-1) 0; text-align: right; }
  table.stack td::before { content: attr(data-label); font-weight: 600; color: var(--text-muted); text-align: left; flex: none; }
  table.stack td.stack__main { display: block; text-align: left; font-weight: 600; }
  table.stack td.stack__main::before { content: none; }
  table.stack tr.stack__empty td { display: block; text-align: center; }
  table.stack tr.stack__empty td::before { content: none; }
}
@media (prefers-reduced-motion: reduce) { .results.htmx-request { transition: none; } }

/* ---------- Request page sections and scan log ---------- */
[data-live]:focus { outline: none; }
.confirm { margin: var(--space-2) 0; }
.confirm > summary { cursor: pointer; color: var(--danger); font-weight: 600; }
.confirm p { margin: var(--space-2) 0; }
.scan-log { list-style: none; padding: 0; margin: 0; }
.scan-log__title { margin-top: var(--space-5, 1.5rem); }
.scan-entry { padding: var(--space-3) var(--space-4); margin: var(--space-2) 0; border-radius: var(--radius); border-left: 4px solid var(--info); background: var(--info-bg); }
.scan-entry--success { border-color: var(--success); background: var(--success-bg); color: var(--success); }
.scan-entry--warning { border-color: var(--warning-fill); background: var(--warning-bg); color: var(--warning); }
.scan-entry--error { border-color: var(--danger); background: var(--danger-bg); color: var(--danger); }
.scan-entry .scan-candidates { margin-top: var(--space-2); color: var(--text); }

/* ---------- Patron: chooser cards, steps, results, timeline ---------- */
.choice-cards { list-style: none; padding: 0; margin: 0 0 var(--space-5, 1.5rem); display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); }
.choice-card { display: flex; flex-direction: column; gap: var(--space-1); height: 100%; padding: var(--space-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); color: var(--text); text-decoration: none; box-shadow: var(--shadow-sm); }
.choice-card:hover, .choice-card:focus-visible { border-color: var(--brand-navy); box-shadow: var(--shadow); }
.choice-card__title { font-family: var(--font-serif); font-size: 1.2rem; color: var(--brand-navy); font-weight: 600; }
.choice-card__blurb { color: var(--text-muted); }
.steps { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); list-style: none; padding: 0; margin: 0 0 var(--space-4); counter-reset: step; color: var(--text-muted); }
.steps li { counter-increment: step; }
.steps li::before { content: counter(step); display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; margin-right: var(--space-2); border-radius: 50%; border: 1px solid var(--border-strong, var(--border)); font-size: var(--text-sm); }
.steps li[aria-current="step"] { color: var(--brand-navy); font-weight: 600; }
.steps li[aria-current="step"]::before { background: var(--brand-navy); border-color: var(--brand-navy); color: var(--text-on-brand); }
.result-cards { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--space-3); }
.result-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-4); }
.result-card h2 { margin-top: 0; font-size: 1.15rem; }
.holdings { padding-left: var(--space-4); margin: var(--space-2) 0; }
#catalog-results.htmx-request { opacity: .55; }
.timeline { list-style: none; margin: 0 0 var(--space-4); padding: 0 0 0 var(--space-4); border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 var(--space-3) var(--space-3); }
.timeline li::before { content: ""; position: absolute; left: calc(-1 * var(--space-4) - 7px); top: .35em; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--brand-navy); }
.timeline li[aria-current="step"]::before { background: var(--brand-navy); }
.timeline__label { font-weight: 600; }
.timeline li:not([aria-current]) .timeline__label { font-weight: 400; }
.timeline__date { color: var(--text-muted); margin-left: var(--space-2); }
@media (prefers-reduced-motion: reduce) { #catalog-results.htmx-request { transition: none; } }

/* ---------- Print (bibliography and request pages) ---------- */
[data-print] { display: none; }
.js [data-print] { display: inline-flex; }
@media print {
  .skip, .site-header, .site-footer, .filter-bar, .no-print, ul.messages, .page-progress, .pager, button, .button { display: none !important; }
  body { background: Canvas; color: CanvasText; font-size: 11pt; }
  .site-main { max-width: none; padding: 0; }
  a { color: inherit; text-decoration: none; }
  ul.bibliography { list-style: none; padding: 0; }
  ul.bibliography li { margin: 0 0 .6em; padding-left: 2em; text-indent: -2em; break-inside: avoid; }  /* hanging indent */
  table { font-size: 10pt; }
  tr { break-inside: avoid; }
}
