:root {
  color-scheme: light;
  --radius: 20px;
  font-family: "Avenir Next", Avenir, Inter, system-ui, sans-serif;
  color: var(--text);
  background: var(--page-bg);
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--page-bg);
}

button, input, select, textarea { font: inherit; }
button { color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { line-height: 1.08; }
h1, h2 { font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-weight: 400; }
h2 { font-size: clamp(2rem, 4vw, 3rem); margin-bottom: .55rem; }
h3 { margin-bottom: .45rem; }

.muted { color: var(--text-muted); }
.eyebrow {
  margin-bottom: .75rem;
  color: var(--primary);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .75rem;
  color: var(--text);
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-size: 1.55rem;
  text-decoration: none;
}

.brand--large { font-size: 1.8rem; }
.brand-mark {
  display: grid;
  width: 2.35rem;
  height: 2.35rem;
  place-items: center;
  border-radius: 50% 50% 45% 55%;
  color: var(--on-primary);
  background: var(--primary);
  font-size: 1.15rem;
}

.login-layout {
  display: grid;
  min-height: 100vh;
  grid-template-columns: minmax(0, 1.15fr) minmax(420px, .85fr);
}

.login-story {
  display: flex;
  min-height: 100vh;
  padding: clamp(2rem, 5vw, 5rem);
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  position: relative;
  background:
    radial-gradient(circle at 82% 16%, rgb(var(--highlight-rgb) / 70%) 0 7%, transparent 7.3%),
    radial-gradient(circle at 80% 24%, transparent 0 16%, rgb(var(--primary-rgb) / 12%) 16.2% 16.8%, transparent 17%),
    linear-gradient(145deg, var(--story-start), var(--story-middle) 64%, var(--story-end));
}

.login-story::after {
  content: "";
  position: absolute;
  right: -8%;
  bottom: -20%;
  width: 56%;
  aspect-ratio: 1;
  border: 2px solid rgb(var(--primary-rgb) / 16%);
  border-radius: 50%;
  box-shadow: 0 0 0 45px rgb(var(--primary-rgb) / 6%), 0 0 0 90px rgb(var(--primary-rgb) / 4%);
  pointer-events: none;
}

.story-copy { max-width: 730px; position: relative; z-index: 1; }
.story-copy h1 { margin-bottom: 1.5rem; font-size: clamp(3.5rem, 7vw, 7.2rem); letter-spacing: -.045em; }
.story-copy > p:last-child { max-width: 570px; font-size: clamp(1rem, 1.6vw, 1.3rem); line-height: 1.7; }
.story-note { margin-bottom: 0; color: var(--text-muted); font-size: .85rem; position: relative; z-index: 1; }
.story-note a { color: var(--primary-hover); font-weight: 600; text-underline-offset: .18em; }

.public-header {
  display: flex;
  padding: 1.1rem clamp(1.4rem, 4vw, 4rem);
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.about-copy h2.about-heading { font-size: clamp(1.35rem, 2.2vw, 1.75rem); margin-bottom: .55rem; }
.about-copy p { line-height: 1.7; margin-bottom: .9rem; }
.about-copy p:last-child { margin-bottom: 0; }
.about-copy a { color: var(--primary-hover); font-weight: 600; text-underline-offset: .18em; }
.about-links { display: flex; margin-top: 1.1rem; gap: .6rem; flex-wrap: wrap; }
.public-footer {
  width: min(100%, 1440px);
  margin: 0 auto;
  padding: 0 clamp(1.6rem, 4vw, 4rem) 2.5rem;
  color: var(--text-muted);
  font-size: .85rem;
}
.public-footer a { color: var(--primary-hover); font-weight: 600; text-underline-offset: .18em; }

.login-panel {
  display: grid;
  padding: clamp(1.5rem, 5vw, 6rem);
  place-items: center;
  background: var(--surface);
}

.login-card { display: grid; width: min(100%, 440px); gap: 1.25rem; }
label { display: grid; gap: .5rem; font-size: .85rem; font-weight: 600; }

input, select, textarea {
  width: 100%;
  padding: .8rem .9rem;
  border: 1px solid var(--border);
  border-radius: 11px;
  outline: 0;
  color: var(--text);
  background: var(--control-bg);
  transition: border-color .2s, box-shadow .2s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(var(--primary-rgb) / 12%);
}

textarea { min-height: 95px; resize: vertical; }

.button {
  display: inline-flex;
  min-height: 42px;
  padding: .7rem 1rem;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
  transition: transform .15s, opacity .15s, background .15s;
}

.button:hover { transform: translateY(-1px); }
.button:disabled, .is-loading { opacity: .58; pointer-events: none; }
.button--primary { color: var(--on-primary); background: var(--primary); }
.button--primary:hover { background: var(--primary-hover); }
.button--secondary { border: 1px solid var(--border); color: var(--text); background: var(--control-bg); }
.button--danger { color: var(--danger); background: var(--danger-soft); }
.button--small { min-height: 34px; padding: .45rem .7rem; font-size: .8rem; }
.button--wide { width: 100%; min-height: 50px; }

.form-error { min-height: 1.2em; margin: -.5rem 0 0; color: var(--danger); font-size: .85rem; }
.demo-accounts { border-top: 1px solid var(--border); padding-top: 1rem; color: var(--text-muted); font-size: .85rem; }
.demo-accounts summary { cursor: pointer; font-weight: 600; }
.demo-buttons { display: flex; gap: .5rem; margin-top: .8rem; flex-wrap: wrap; }
.demo-buttons button { padding: .45rem .65rem; border: 1px solid var(--border); border-radius: 8px; background: transparent; cursor: pointer; }

.app-shell { display: grid; min-height: 100vh; grid-template-columns: 260px minmax(0, 1fr); }
.sidebar {
  display: flex;
  min-height: 100vh;
  padding: 1.6rem 1.2rem;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
}

.sidebar > .brand { margin: 0 .6rem 2.2rem; }
.nav { display: grid; gap: .3rem; }
.nav-heading { margin: 1.35rem .7rem .5rem; color: var(--nav-label); font-size: .68rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.nav-heading:first-child { margin-top: 0; }
.nav-link {
  display: flex;
  width: 100%;
  padding: .72rem .8rem;
  align-items: center;
  gap: .7rem;
  border: 0;
  border-radius: 10px;
  text-align: left;
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
  font-size: .88rem;
  font-weight: 600;
  text-decoration: none;
}
.nav-link:hover, .nav-link.is-active { color: var(--primary-hover); background: rgb(var(--highlight-rgb) / 70%); }
.nav-link span { width: 1rem; font-size: 1.1rem; }

.user-card {
  display: grid;
  margin-top: auto;
  padding: .8rem;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: .65rem;
  border: 1px solid rgb(var(--primary-rgb) / 10%);
  border-radius: 14px;
  background: rgb(var(--highlight-rgb) / 56%);
}
.avatar { display: grid; width: 2.2rem; height: 2.2rem; place-items: center; border-radius: 50%; color: var(--on-primary); background: var(--primary); font-weight: 700; }
.user-card strong, .user-card span { display: block; }
.user-card strong { font-size: .82rem; }
.user-card div span { color: var(--text-muted); font-size: .7rem; }
.icon-button { display: grid; width: 2.2rem; height: 2.2rem; padding: 0; place-items: center; border: 0; border-radius: 8px; background: transparent; cursor: pointer; font-size: 1.1rem; }
.icon-button:hover { background: rgb(var(--primary-rgb) / 9%); }

.workspace { min-width: 0; }
.mobile-header { display: none; }
.content { width: min(100%, 1440px); margin: 0 auto; padding: clamp(1.6rem, 4vw, 4rem); }
.page-header { display: flex; margin-bottom: 2rem; align-items: end; justify-content: space-between; gap: 1rem; }
.page-header h1 { margin: 0 0 .3rem; font-size: clamp(2.4rem, 5vw, 4.5rem); letter-spacing: -.035em; }
.page-header p { margin: 0; color: var(--text-muted); }

.toolbar { display: flex; margin-bottom: 1.4rem; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.search-form { display: flex; width: min(100%, 560px); gap: .5rem; }
.search-form input { flex: 1; }
.result-count { color: var(--text-muted); font-size: .85rem; }

.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(245px, 1fr)); gap: 1rem; }
.book-card {
  min-width: 0;
  overflow-wrap: anywhere;
  display: flex;
  min-height: 275px;
  padding: 1.25rem;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 6px 22px rgb(var(--shadow-rgb) / 4%);
}
.book-cover { display: grid; width: 58px; height: 78px; margin-bottom: 1.25rem; place-items: center; border-radius: 4px 9px 9px 4px; color: var(--on-primary); background: linear-gradient(145deg, var(--primary), var(--cover-end)); box-shadow: inset 5px 0 rgb(var(--highlight-rgb) / 12%); font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-size: 1.6rem; }
.book-card h3 { font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-size: 1.35rem; font-weight: 400; }
.book-meta { margin-bottom: .9rem; color: var(--text-muted); font-size: .8rem; line-height: 1.55; }
.book-card .button { margin-top: auto; }

.panel { padding: 1.4rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: 0 6px 22px rgb(var(--shadow-rgb) / 4%); }
.panel + .panel { margin-top: 1rem; }
.panel-heading { display: flex; margin-bottom: 1.2rem; align-items: center; justify-content: space-between; gap: .8rem; }
.panel-heading h3 { margin: 0; }
.detail-grid { display: grid; grid-template-columns: minmax(220px, .7fr) minmax(0, 1.3fr); gap: 1.5rem; }
.detail-grid > * { min-width: 0; }
.detail-card { container-type: inline-size; min-height: 360px; padding: clamp(1.5rem, 4vw, 3rem); border-radius: var(--radius); color: var(--on-primary); background: linear-gradient(145deg, var(--primary-hover), var(--primary)); overflow-wrap: anywhere; }
.detail-card h2 { font-size: 1.6rem; font-size: clamp(1.6rem, 12cqi, 3.6rem); }
.detail-card .eyebrow { color: var(--detail-eyebrow); }
.detail-card p { color: rgb(var(--highlight-rgb) / 72%); line-height: 1.7; }
.reservation-state { display: grid; padding: 1rem; gap: .45rem; border-radius: 12px; color: var(--text); background: var(--control-bg); }
.reservation-state strong, .reservation-state span { display: block; }
.reservation-state span { color: var(--text-muted); font-size: .82rem; }
.reservation-state .badge { width: fit-content; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: .9rem .75rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--text-muted); font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }

.badge { display: inline-flex; padding: .3rem .55rem; border-radius: 999px; color: var(--primary-hover); background: var(--primary-soft); font-size: .7rem; font-weight: 700; white-space: nowrap; }
.badge--warning { color: var(--warning-text); background: var(--warning-bg); }
.badge--danger { color: var(--danger-text); background: var(--danger-bg); }
.badge--neutral { color: var(--neutral-text); background: var(--neutral-bg); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .button { align-self: end; }
.management-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: start; }
.stack { display: grid; gap: .75rem; }
.inline-form { display: flex; gap: .5rem; align-items: end; flex-wrap: wrap; }
.inline-form label { min-width: 160px; flex: 1; }
.user-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.user-actions .inline-form { flex-wrap: nowrap; }
.user-actions input { width: 11rem; }
.checkout-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.lookup-section { display: grid; align-content: start; gap: .65rem; }
.lookup-options { display: grid; max-height: 16rem; gap: .45rem; overflow-y: auto; }
.lookup-option { display: grid; padding: .7rem .8rem; grid-template-columns: auto 1fr; align-items: center; gap: .65rem; border: 1px solid var(--border); border-radius: 10px; background: var(--control-bg); cursor: pointer; }
.lookup-option:hover, .lookup-option:has(input:checked) { border-color: var(--primary); background: rgb(var(--primary-rgb) / 7%); }
.lookup-option input { width: auto; accent-color: var(--primary); }
.lookup-option strong, .lookup-option small { display: block; }
.lookup-option small { margin-top: .15rem; color: var(--text-muted); }
.lookup-empty { margin: 0; padding: .8rem; border-radius: 10px; color: var(--text-muted); background: rgb(var(--primary-rgb) / 5%); }
.checkout-submit { display: flex; grid-column: 1 / -1; align-items: end; justify-content: flex-end; gap: .75rem; flex-wrap: wrap; }
.checkout-submit label { min-width: 250px; }
.empty-state { padding: 4rem 1rem; text-align: center; color: var(--text-muted); }
.empty-state strong { display: block; margin-bottom: .5rem; color: var(--text); font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-size: 1.5rem; font-weight: 400; }
.loading-card { display: grid; min-height: 50vh; place-items: center; color: var(--text-muted); }
.pagination { display: flex; margin-top: 1.5rem; justify-content: center; gap: .5rem; }

.flash {
  position: fixed;
  top: 1rem;
  left: 50%;
  z-index: 100;
  max-width: calc(100vw - 2rem);
  padding: .8rem 1.1rem;
  border-radius: 10px;
  color: var(--on-primary);
  background: var(--primary-hover);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -1rem);
  transition: opacity .2s, transform .2s;
}
.flash.is-visible { opacity: 1; transform: translate(-50%, 0); }
.flash--error { background: var(--danger); }

@media (max-width: 920px) {
  .login-layout { grid-template-columns: 1fr; }
  .login-story { min-height: 46vh; padding: 2rem; }
  .story-copy h1 { font-size: clamp(3rem, 12vw, 5rem); }
  .story-note { display: none; }
  .login-panel { padding: 3rem 1.5rem; }
  .app-shell { display: block; }
  .sidebar { width: min(86vw, 290px); position: fixed; left: 0; transform: translateX(-105%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.is-open { transform: translateX(0); }
  .mobile-header { display: flex; padding: 1rem 1.25rem; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); background: var(--surface); }
  .detail-grid, .management-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .content { padding: 1.4rem 1rem 3rem; }
  .page-header { align-items: start; flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .search-form { flex-direction: column; }
  .book-grid { grid-template-columns: 1fr; }
  .checkout-form { grid-template-columns: 1fr; }
  .checkout-submit { grid-column: auto; align-items: stretch; flex-direction: column; }
  .checkout-submit label { min-width: 0; }
}
