:root {
  color-scheme: light;
  --bg: #f5f2ec;
  --surface: #fffdfa;
  --surface-strong: #f0ebe2;
  --ink: #24211e;
  --muted: #706a62;
  --line: #ddd5c9;
  --accent: #245b54;
  --accent-strong: #17413c;
  --accent-soft: #d7e6df;
  --warn: #a9462a;
  --shadow: 0 18px 45px rgba(47, 41, 34, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(36, 33, 30, 0.45);
}

.mobile-header {
  display: none;
}

.menu-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  place-content: center;
  gap: 5px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.menu-button span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--ink);
  border-radius: 999px;
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(460px, 100%);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand--auth {
  margin-bottom: 22px;
}

.auth-form h2,
.auth-form p {
  margin: 0;
}

.auth-form h2 {
  font-size: 1.25rem;
}

.auth-form p {
  margin-top: 6px;
  margin-bottom: 16px;
  color: var(--muted);
  line-height: 1.45;
}

.auth-form .button {
  width: 100%;
  margin-top: 16px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 28px;
  background: #ebe4d8;
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

.brand__mark {
  display: grid;
  width: 52px;
  height: 68px;
  place-items: center;
  color: #fff;
  font-weight: 800;
  background: linear-gradient(145deg, var(--accent), #6f3d4b);
  border-radius: 6px 2px 2px 6px;
  box-shadow: inset -8px 0 rgba(255, 255, 255, 0.12);
}

.brand h1,
.brand p,
.panel h2,
.empty-state h2,
.dialog-header h2 {
  margin: 0;
}

.brand h1 {
  font-size: 1.35rem;
  line-height: 1.15;
}

.brand p,
.field span,
.stats-grid span,
.empty-state p,
.book-card__meta,
.scanner__actions p {
  color: var(--muted);
}

.brand p {
  margin-top: 4px;
  font-size: 0.92rem;
}

.panel {
  padding: 18px;
  background: rgba(255, 253, 250, 0.74);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel h2 {
  margin-bottom: 12px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.current-user {
  display: grid;
  gap: 3px;
  margin-bottom: 12px;
}

.current-user strong {
  line-height: 1.25;
}

.current-user span,
.user-list {
  color: var(--muted);
  font-size: 0.88rem;
}

.compact-form {
  display: grid;
  gap: 12px;
}

.compact-form .field + .field {
  margin-top: 0;
}

.button--full {
  width: 100%;
}

.user-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.user-list__item {
  display: grid;
  gap: 2px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.user-list__item strong {
  color: var(--ink);
  font-size: 0.9rem;
}

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

.stats-grid div {
  padding: 12px 10px;
  background: var(--surface);
  border-radius: 6px;
  border: 1px solid var(--line);
}

.stats-grid strong,
.stats-grid span {
  display: block;
}

.stats-grid strong {
  font-size: 1.32rem;
  line-height: 1;
}

.stats-grid span {
  margin-top: 2px;
  font-size: 0.78rem;
}

.field {
  display: grid;
  gap: 7px;
}

.field + .field {
  margin-top: 14px;
}

.field span {
  font-size: 0.86rem;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

.field textarea {
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 91, 84, 0.15);
}

.main {
  padding: 28px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 14px;
  margin-bottom: 20px;
}

.isbn-form {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.field--isbn {
  width: min(330px, 100%);
}

.button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 6px;
  min-height: 42px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  font-weight: 800;
}

.button--primary {
  color: #fff;
  background: var(--accent);
}

.button--primary:hover {
  background: var(--accent-strong);
}

.button--secondary {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: #b8d2c8;
}

.button--ghost {
  color: var(--ink);
  background: transparent;
  border-color: var(--line);
}

.scanner {
  display: grid;
  grid-template-columns: minmax(260px, 440px) 1fr;
  gap: 18px;
  align-items: center;
  margin-bottom: 22px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.scanner[hidden] {
  display: none;
}

.scanner__video-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 10;
  background: #161513;
  border-radius: 8px;
}

.scanner video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner__target {
  position: absolute;
  inset: 28%;
  border: 2px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.22);
}

.scanner__actions {
  display: grid;
  gap: 12px;
  justify-items: start;
}

.lookup-result {
  display: grid;
  grid-template-columns: minmax(92px, 132px) 1fr auto;
  gap: 16px;
  align-items: center;
  margin-bottom: 22px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.lookup-result__cover {
  display: grid;
  min-height: 152px;
  place-items: center;
  overflow: hidden;
  background: #d6d0c7;
  border-radius: 6px;
}

.lookup-result__cover img {
  width: 100%;
  height: 176px;
  object-fit: cover;
}

.lookup-result__body {
  min-width: 0;
}

.lookup-result__body h2,
.lookup-result__body p {
  margin: 0;
}

.lookup-result__body h2 {
  font-size: 1.15rem;
  line-height: 1.25;
}

.lookup-result__body p {
  margin-top: 7px;
  color: var(--muted);
  line-height: 1.4;
}

.lookup-result__actions {
  display: grid;
  gap: 8px;
  min-width: 190px;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
}

.book-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 390px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.book-card__cover {
  display: grid;
  min-height: 210px;
  place-items: center;
  background: #d6d0c7;
}

.book-card__cover img {
  width: 100%;
  height: 230px;
  object-fit: cover;
}

.book-card__placeholder {
  display: grid;
  width: 104px;
  height: 148px;
  place-items: center;
  padding: 12px;
  color: #fff;
  font-weight: 900;
  text-align: center;
  background: linear-gradient(145deg, #6f3d4b, var(--accent));
  border-radius: 6px 2px 2px 6px;
}

.book-card__body,
.book-card__actions {
  padding: 14px;
}

.book-card__title {
  margin: 0 0 7px;
  font-size: 1.02rem;
  line-height: 1.25;
}

.book-card__meta {
  margin: 0 0 10px;
  font-size: 0.9rem;
  line-height: 1.35;
}

.book-card__isbn {
  display: inline-block;
  padding: 4px 7px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 800;
}

.book-card__actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  border-top: 1px solid var(--line);
  background: #faf7f1;
}

.status-button {
  display: inline-flex;
  min-width: 0;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-button.is-active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.status-button--edit {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: #b8d2c8;
}

.icon-button {
  width: 42px;
  padding: 0;
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
  font-size: 1.35rem;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 170px);
  text-align: center;
  padding: 32px;
}

.empty-state[hidden] {
  display: none;
}

.empty-state__cover {
  display: flex;
  align-items: end;
  gap: 8px;
  margin-bottom: 20px;
}

.empty-state__cover span {
  display: block;
  width: 44px;
  border-radius: 6px 2px 2px 6px;
  background: var(--accent);
}

.empty-state__cover span:nth-child(1) {
  height: 120px;
  background: #6f3d4b;
}

.empty-state__cover span:nth-child(2) {
  height: 150px;
}

.empty-state__cover span:nth-child(3) {
  height: 100px;
  background: #8a6a3f;
}

.empty-state h2 {
  font-size: clamp(1.6rem, 4vw, 3rem);
  max-width: 720px;
}

.empty-state p {
  max-width: 680px;
  margin: 12px auto 0;
  font-size: 1.05rem;
  line-height: 1.55;
}

.book-dialog {
  width: min(720px, calc(100vw - 28px));
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.book-dialog::backdrop {
  background: rgba(36, 33, 30, 0.45);
}

.book-form {
  padding: 20px;
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-header {
  margin-bottom: 18px;
}

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

.form-grid .field + .field {
  margin-top: 0;
}

.dialog-actions {
  margin-top: 18px;
}

.dialog-actions > div {
  display: flex;
  gap: 10px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  color: #fff;
  background: var(--ink);
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(86vw, 340px);
    overflow-y: auto;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    box-shadow: var(--shadow);
    transform: translateX(-104%);
    transition: transform 200ms ease;
  }

  .app-shell.is-drawer-open .sidebar {
    transform: translateX(0);
  }

  .mobile-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: -28px -28px 20px;
    padding: 14px 18px;
    background: rgba(245, 242, 236, 0.95);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(10px);
  }

  .mobile-header div {
    display: grid;
    gap: 2px;
    min-width: 0;
  }

  .mobile-header strong,
  .mobile-header span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-header span {
    color: var(--muted);
    font-size: 0.86rem;
  }

  .toolbar,
  .scanner,
  .lookup-result {
    grid-template-columns: 1fr;
  }

  .lookup-result__actions {
    min-width: 0;
  }

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

  .isbn-form {
    align-items: stretch;
  }

  .isbn-form .button,
  .toolbar > .button {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .main {
    padding: 18px;
  }

  .sidebar {
    padding: 18px;
  }

  .mobile-header {
    margin: -18px -18px 18px;
  }

  .brand {
    align-items: start;
  }

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

  .field--isbn {
    width: 100%;
  }

  .lookup-result__cover {
    min-height: 180px;
  }

  .dialog-header,
  .dialog-actions,
  .dialog-actions > div {
    align-items: stretch;
    flex-direction: column;
  }

  .dialog-actions .button,
  .dialog-actions .icon-button {
    width: 100%;
  }
}
