:root {
  color-scheme: light;
  --bg: #f6f4ee;
  --surface: #fffdf8;
  --surface-2: #f1ede3;
  --ink: #17211d;
  --muted: #68736e;
  --line: #dcd6c9;
  --green: #24483d;
  --green-2: #19362f;
  --blue: #315a70;
  --gold: #b9852f;
  --rose: #8f3848;
  --danger: #b42318;
  --shadow: 0 18px 44px rgba(33, 39, 34, .11);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(180deg, rgba(36, 72, 61, .08), transparent 310px),
    var(--bg);
  color: var(--ink);
}

body, button, input, textarea { letter-spacing: 0; }

h1, h2, h3, p { margin-top: 0; }

h1, h2, h3 {
  font-family: Georgia, "Times New Roman", serif;
  color: var(--ink);
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.6rem);
  line-height: 1;
}

h2 {
  margin: 0;
  font-size: 1.55rem;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: white;
  padding: 10px 15px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: transform .16s ease, background .16s ease, box-shadow .16s ease;
}

button:hover {
  background: var(--green-2);
  box-shadow: 0 8px 18px rgba(25, 54, 47, .18);
  transform: translateY(-1px);
}

button.secondary {
  background: #ebe5d9;
  color: #2d332f;
  border: 1px solid var(--line);
  box-shadow: none;
}

button.secondary:hover { background: #e2dacb; }
button.danger { background: var(--danger); }
button:disabled {
  cursor: not-allowed;
  opacity: .48;
  transform: none;
  box-shadow: none;
}

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  outline: none;
}

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

input:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(49, 90, 112, .15);
}

label {
  display: grid;
  gap: 7px;
  color: #2f3834;
  font-size: .92rem;
  font-weight: 800;
}

label span {
  display: flex;
  align-items: center;
  gap: 8px;
}

label input[type="checkbox"] {
  width: 17px;
  height: 17px;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 430px);
  gap: 24px;
  align-items: end;
  padding: 24px clamp(18px, 4vw, 48px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand-block {
  display: flex;
  gap: 16px;
  align-items: center;
  min-width: 0;
}

.brand-block > div { min-width: 0; }

.brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 0 17px, rgba(255,255,255,.28) 17px 20px, transparent 20px),
    linear-gradient(135deg, var(--green), var(--blue));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25), 0 12px 24px rgba(36,72,61,.18);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: .72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.eyebrow.dark { color: var(--gold); }

.session-actions, .login-panel, .panel, .overview {
  background: rgba(255, 253, 248, .94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.session-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  min-width: 0;
}

.top-nav {
  display: flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.top-nav button {
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}

.top-nav button.active {
  background: var(--green);
  color: white;
}

.session-actions strong {
  display: block;
  margin-bottom: 3px;
}

.session-actions small {
  display: block;
  color: var(--muted);
  font-weight: 800;
}

.row, .actions, .toolbar, .toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.layout {
  display: block;
  padding: 22px clamp(18px, 4vw, 48px) 48px;
}

.layout.locked {
  opacity: .48;
  pointer-events: none;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.summary-view.active {
  display: grid;
  gap: 22px;
}

.overview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
}

.metric {
  padding: 18px 20px;
  border-right: 1px solid var(--line);
}

.metric:last-child { border-right: 0; }

.metric span {
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.2rem;
  line-height: 1;
}

.metric small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-weight: 800;
}

.panel { padding: 20px; }

.section-heading { margin-bottom: 16px; }

.section-copy,
.summary-copy {
  margin: 8px 0 0;
  max-width: 760px;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.5;
}

.form-panel {
  max-width: 980px;
  margin: 0 auto;
}

.summary-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 560px);
  gap: 22px;
  align-items: stretch;
}

.summary-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.action-tile {
  min-height: 148px;
  display: grid;
  align-content: end;
  justify-items: start;
  gap: 8px;
  padding: 18px;
  text-align: left;
}

.action-tile span {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.55rem;
  line-height: 1.05;
}

.action-tile small {
  color: rgba(255,255,255,.82);
  font-weight: 800;
  line-height: 1.35;
}

.secondary-tile {
  background: var(--blue);
}

.secondary-tile:hover {
  background: #24485b;
}

form {
  display: grid;
  gap: 14px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field-grid.three { grid-template-columns: 1.2fr .7fr .7fr; }

details {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 13px;
  background: #fbf8ef;
}

details > * + * { margin-top: 12px; }

summary {
  color: var(--rose);
  cursor: pointer;
  font-weight: 900;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  padding-top: 10px;
  background: linear-gradient(transparent, var(--surface) 34%);
}

.catalog-panel {
  min-width: 0;
  max-width: 1240px;
  margin: 0 auto;
}

.toolbar {
  justify-content: space-between;
  align-items: end;
  margin-bottom: 16px;
}

.toolbar-actions {
  justify-content: flex-end;
  max-width: 820px;
}

.toolbar-actions input {
  flex: 1 1 320px;
  min-width: min(420px, 100%);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
}

.segmented button {
  min-height: 40px;
  border-radius: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  padding: 9px 11px;
}

.segmented button:last-child { border-right: 0; }

.segmented button.active {
  background: var(--green);
  color: white;
}

.books {
  display: grid;
  gap: 14px;
}

.book-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 124px;
  gap: 16px;
  align-items: start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 6px solid var(--green);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 12px 28px rgba(33, 39, 34, .08);
}

.book-main {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  min-width: 0;
}

.book-card h3 {
  flex-basis: 100%;
  margin: 2px 0 2px;
  font-size: 1.5rem;
  line-height: 1.15;
}

.category, .status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: .72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.category {
  background: #edf3f4;
  color: var(--blue);
}

.status {
  background: #eef6ee;
  color: var(--green);
}

.status.loaned {
  background: #fff1e7;
  color: var(--rose);
}

.meta, .locator, .loan, .provenance, .summary {
  flex-basis: 100%;
  margin: 0;
}

.meta, .locator, .loan, .provenance {
  color: var(--muted);
  font-weight: 800;
}

.locator { color: var(--green); }

.summary {
  max-width: 78ch;
  color: #3b4440;
  line-height: 1.55;
  white-space: pre-wrap;
}

.qr-wrap {
  display: grid;
  justify-items: center;
  gap: 6px;
}

.qr {
  width: 112px;
  height: 112px;
  border: 8px solid white;
  border-radius: 8px;
  box-shadow: 0 10px 22px rgba(23, 33, 29, .14);
}

.qr-wrap small {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
}

.actions {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 28px;
  background: #fbf8ef;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}

.login-shell {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 410px);
  gap: 22px;
  align-items: stretch;
}

.login-brand {
  min-height: 520px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(160deg, rgba(36, 72, 61, .9), rgba(49, 90, 112, .82)),
    var(--green);
  box-shadow: var(--shadow);
}

.login-brand .brand-mark {
  margin-bottom: auto;
  background:
    linear-gradient(90deg, transparent 0 17px, rgba(255,255,255,.3) 17px 20px, transparent 20px),
    linear-gradient(135deg, #fffdf8, #d7e7df);
}

.login-brand .eyebrow,
.login-brand h1,
.login-brand .login-copy {
  color: #fffdf8;
}

.login-copy {
  max-width: 520px;
  margin: 16px 0 0;
  line-height: 1.55;
  font-weight: 700;
}

.login-panel {
  align-self: center;
  padding: 24px;
}

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

.login-divider {
  height: 1px;
  margin: 20px 0 14px;
  background: var(--line);
}

.register-panel {
  border: 0;
  padding: 0;
  background: transparent;
}

.register-panel summary {
  width: max-content;
}

.register-panel form { margin-top: 14px; }

.form-status {
  min-height: 22px;
  margin: 16px 0 0;
  color: var(--rose);
  font-weight: 800;
}

.public-book {
  max-width: 880px;
  margin: 34px auto;
  padding: 0 18px;
}

.public-book > a {
  display: inline-flex;
  margin-bottom: 14px;
  color: var(--green);
  font-weight: 900;
  text-decoration: none;
}

.public-book article {
  display: grid;
  gap: 12px;
  padding: 26px;
}

.public-book h1 {
  font-size: clamp(2rem, 6vw, 4.2rem);
}

@media (max-width: 1080px) {
  .app-header, .layout, .login-shell { grid-template-columns: 1fr; }
  .form-panel { position: static; }
  .toolbar { align-items: stretch; }
  .toolbar-actions { justify-content: flex-start; max-width: none; }
  .login-brand { min-height: 360px; }
}

@media (max-width: 760px) {
  .app-header { padding: 18px; }
  h1 { font-size: 2rem; }
  .session-actions {
    align-items: stretch;
    flex-wrap: wrap;
  }
  .session-actions > div { flex: 1 1 170px; }
  .top-nav {
    order: 3;
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    display: grid;
  }
  .top-nav button { padding-inline: 6px; }
  .layout { padding: 18px 14px 36px; }
  .overview { grid-template-columns: 1fr 1fr; }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n + 2) { border-bottom: 1px solid var(--line); }
  .field-grid, .field-grid.three { grid-template-columns: 1fr; }
  .book-card { grid-template-columns: 1fr; }
  .qr { width: 144px; height: 144px; }
  .segmented { width: 100%; }
  .summary-panel, .summary-actions { grid-template-columns: 1fr; }
  .action-tile { min-height: 132px; }
  .login-page { padding: 14px; }
  .login-brand, .login-panel { padding: 20px; }
  .login-brand { min-height: 300px; }
}

@media print {
  body { background: white; }
  .app-header, .form-panel, .toolbar, .actions, .overview { display: none; }
  .layout { display: block; padding: 0; }
  .panel, .book-card { box-shadow: none; }
  .book-card { break-inside: avoid; }
}
