:root {
  --bg: #fffdf4;
  --text: #1a1a1a;
  --muted: #6f6f6f;
  --border: #e8e8e8;
  --accent: #f7e731;
  --soft: #f6f6f6;
}
.card-tags summary { min-height:44px; cursor:pointer; }
.welcome {grid-column:1/-1;text-align:center;padding:clamp(24px,6vw,64px);border-radius:14px;background:#fff;box-shadow:0 8px 30px #00000008;}
.welcome .btn {min-height:52px;margin:8px;max-width:100%;}
.empty {grid-column:1/-1;}
.install-box {padding:16px;text-align:center;}
.auth-body {flex-direction:column;}
.install-box:has(button[hidden]):has(p[hidden]) {display:none;}
.install-help {padding:16px;background:var(--bg);border-radius:12px;overflow-wrap:anywhere;}
.book-room {margin:.5rem 0;color:var(--muted);overflow-wrap:anywhere;}
#hand-borrowed[aria-pressed="true"],#hand-lent[aria-pressed="true"] {background:var(--accent);}
.card-tags[open] .tag-pill { animation: reveal-tags .18s ease-out; }
@keyframes reveal-tags { from { opacity:0;transform:translateY(-5px); } to {opacity:1;transform:translateY(0);} }
.hand-row {display:flex;align-items:center;gap:12px;flex-wrap:wrap;padding:16px;margin-bottom:12px;background:white;border-radius:12px;}
.hand-row img {width:60px;height:85px;object-fit:contain;}
.hand-row strong {flex:1 1 180px;overflow-wrap:anywhere;}
.hand-row .input {max-width:180px;}

* {
  box-sizing: border-box;
}
.combo,
.menu-wrap {
  position: relative;
  min-width: 0;
  max-width: 100%;
}
.popup {
  position: absolute;
  z-index: 40;
  top: 100%;
  left: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 25px #0002;
  padding: 8px;
  min-width: 220px;
  width: max-content;
  max-width: min(360px, calc(100vw - 40px));
  max-height: 300px;
  overflow: auto;
}
.combo-options {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}
.combo-option {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  white-space: normal;
  overflow-wrap: anywhere;
  padding: 10px;
  border: 0;
  background: transparent;
  text-align: left;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}
.combo-option:hover,
.combo-option[aria-selected="true"],
.combo-option[aria-current] {
  background: #fff8b4;
  border-radius: 8px;
}
.account-group {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  max-width: 100%;
  min-width: 0;
}
.account-group .popup {
  left: auto;
  right: 0;
}
.fold {
  margin: 12px 0;
  padding: 10px;
  border: 1px solid var(--border);
  box-shadow: none;
}
.fold summary {
  min-height: 44px;
}
.chip-list,
.suggestions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.suggestions p {
  flex-basis: 100%;
  margin-bottom: 0;
}
.loan-status {
  background: var(--accent);
  border-radius: 8px;
  overflow-wrap: anywhere;
}
.qr-panel {
  max-width: 100%;
  padding: 12px;
  background: var(--soft);
  border-radius: 12px;
}
.qr-panel video {
  width: 100%;
  max-height: 280px;
}
.qr-panel label {
  display: block;
}
.card-extras > p {
  color: var(--muted);
}
@media (max-width: 480px) {
  .account-group {
    width: 100%;
  }
  .account-group .user-email {
    flex-basis: 100%;
    overflow-wrap: anywhere;
  }
  .popup {
    max-width: calc(100vw - 40px);
  }
  .qr-panel {
    width: 100%;
  }
}
.catalog-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin: 16px 0;
}
.catalog-toolbar .input {
  width: auto;
  max-width: 100%;
}
.tag-pill {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  max-width: 100%;
  overflow-wrap: anywhere;
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 6px 10px;
  margin: 3px;
  font: inherit;
  cursor: pointer;
}
.tag-pill[aria-pressed="true"],
.btn[aria-pressed="true"] {
  border: 2px solid var(--text);
}
.card-extras {
  overflow-wrap: anywhere;
  min-width: 0;
}
.profile-wrap {
  max-width: 760px;
}
.profile-wrap section,
details {
  padding: 20px;
  margin: 16px 0;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 16px #0000000a;
}
summary {
  cursor: pointer;
  min-height: 44px;
  padding: 8px;
}
button,
.btn,
input:not([type="checkbox"]),
select {
  min-height: 44px;
}
button,
.btn,
.book-card {
  transition:
    background 0.15s,
    transform 0.15s,
    box-shadow 0.15s;
}
button:hover,
.btn:hover {
  background: #f3edbe;
}
.profile-wrap label {
  display: block;
  margin-top: 12px;
}
.profile-wrap a {
  overflow-wrap: anywhere;
  max-width: 100%;
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
.pagination {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 2rem;
}
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Inter",
    -apple-system,
    "Segoe UI",
    Roboto,
    Arial,
    sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* Шапка */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1.1rem 2rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
}

.logo {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}
.logo .dot {
  background: var(--accent);
  border-radius: 50%;
  padding: 0 0.18em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  flex: 1 1 48rem;
  min-width: 0;
}
.header-actions .input {
  width: auto;
}
#search-input {
  flex: 1 1 16rem;
}
#cabinet-filter {
  flex: 0 1 10rem;
}
.user-email {
  font-size: 0.88rem;
  color: var(--muted);
  min-width: 0;
  overflow-wrap: anywhere;
}

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 2rem 4rem;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
  gap: 1.25rem;
}

/* Карточка книги */
.book-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  cursor: pointer;
  background: var(--bg);
  min-width: 0;
  overflow-wrap: anywhere;
  transition: border-color 0.15s ease;
}
.book-card:hover {
  border-color: var(--text);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px #00000012;
}

.book-cover {
  display: block;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: contain;
  border-radius: 8px;
  background: var(--soft);
}
.cover-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
}

.book-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.25;
}
.book-author {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}
.book-desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.book-place {
  margin-top: auto;
  align-self: flex-start;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--accent);
  border-radius: 12px;
  padding: 0.2rem 0.55rem;
  max-width: 100%;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  line-height: 1.4;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.card-actions .btn {
  flex: 1 1 auto;
}

/* Кнопки */
.btn {
  font-family: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  background: transparent;
  color: var(--text);
  min-width: 0;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  transition: background 0.15s ease;
}
.btn:hover {
  background: var(--soft);
}
.btn-primary {
  background: var(--text);
  color: #fff;
}
.btn-primary:hover {
  background: #000;
}
.btn-secondary {
  background: var(--accent);
  border-color: var(--accent);
}
.btn-danger {
  border-color: #d33;
  color: #d33;
}
.btn-danger:hover {
  background: #fdeeee;
}
.btn-small {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}
.btn-wide {
  width: 100%;
  margin-top: 1rem;
}
.btn[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn:focus-visible,
a:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
}

/* Поля */
.input {
  font-family: inherit;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  background: var(--bg);
  color: var(--text);
  width: 100%;
  min-width: 0;
  max-width: 100%;
}
.input:focus {
  outline: none;
  border-color: var(--text);
}
textarea.input {
  display: block;
  resize: vertical;
}
input[type="file"].input {
  overflow: hidden;
}

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin: 0.8rem 0 0.3rem;
}
.hint {
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1.1em;
  margin-top: 0.3rem;
  overflow-wrap: anywhere;
}
.error-msg {
  color: #c22222;
  font-size: 0.85rem;
  min-height: 1.2em;
  margin: 0.5rem 0;
  overflow-wrap: anywhere;
}
.success-msg {
  color: #1a7f37;
  font-size: 0.85rem;
  margin: 0.5rem 0;
  word-break: break-word;
}
.empty {
  color: var(--muted);
  padding: 2rem 0;
  grid-column: 1 / -1;
  overflow-wrap: anywhere;
}
.muted {
  color: var(--muted);
}

/* Страницы входа / регистрации */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1rem;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  min-width: 0;
  overflow-wrap: anywhere;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem;
  background: var(--bg);
}
.auth-card .logo {
  margin-bottom: 1.2rem;
}
.auth-card h2 {
  margin: 0 0 0.8rem;
  font-size: 1.3rem;
  font-weight: 800;
}
.auth-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  justify-content: space-between;
  margin-top: 1.1rem;
  font-size: 0.9rem;
}
.auth-links a {
  color: var(--text);
}
.link-word {
  word-break: break-all;
}

/* Модалка */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 4vh 1rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 100;
}
.modal-overlay.open {
  display: flex;
}
body.modal-open {
  overflow: hidden;
}

.modal-content {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  min-width: 0;
  padding: 1.4rem 1.5rem 1.6rem;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.modal-head h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  min-width: 0;
  overflow-wrap: anywhere;
}
.modal-head .btn {
  flex-shrink: 0;
}

.form-row {
  display: flex;
  gap: 0.8rem;
}
.form-col {
  flex: 1;
  min-width: 0;
}
.isbn-row {
  display: flex;
  gap: 0.5rem;
}
.isbn-row .input {
  flex: 1 1 0;
  width: 0;
}
.isbn-row .btn {
  flex: 0 0 auto;
}

.cover-preview {
  display: block;
  margin-top: 0.8rem;
  max-width: min(160px, 100%);
  max-height: 240px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.modal-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.2rem;
}
.modal-actions .btn {
  flex: 1;
  padding: 0.65rem;
}

/* Адаптивность */
@media (max-width: 640px) {
  .header {
    padding: 1rem;
  }
  /* A tall sticky toolbar would hide much of a small/zoomed viewport. */
  .header {
    position: static;
  }
  .wrap {
    padding: 1rem 1rem 3rem;
  }
  .books-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr));
    gap: 0.9rem;
  }
  .book-card {
    padding: 0.75rem;
  }
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  .modal-actions {
    flex-direction: column;
  }
  .modal-overlay {
    padding: 1rem 0.75rem;
  }
  .modal-content {
    padding: 1rem;
  }
  .auth-links {
    flex-direction: column;
    gap: 0.4rem;
  }
  .header-actions {
    width: 100%;
  }
  #search-input {
    flex: 1 1 100%;
    width: 100%;
  }
  #cabinet-filter {
    flex: 1 1 8rem;
  }
  .user-email {
    flex: 1 1 10rem;
  }
  .auth-card {
    padding: 1.5rem;
  }
  .input {
    font-size: 1rem;
  }
}

@media (max-height: 500px) {
  .header {
    position: static;
  }
  .auth-body {
    align-items: flex-start;
  }
}

#install-guide h2 { font-size: 1.1rem; margin: 1.5rem 0 .75rem; }
.install-steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
  gap: 1rem 2rem;
  padding-inline-start: 1.75rem;
}
.install-steps li::marker { font-weight: 700; }
.install-steps img { display: block; width: 100%; max-width: 320px; height: auto; margin-top: .6rem; }
