* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #f4f6f9;
  color: #1d2733;
}

header {
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  position: relative;
}

header h1 {
  margin: 0;
  font-size: 22px;
}

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

.toolbar input[type="search"] {
  padding: 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  min-width: 240px;
  font-size: 14px;
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.search-wrap input[type="search"] {
  flex: 1;
}

.scan-search-btn {
  padding: 9px 12px;
  font-size: 15px;
  line-height: 1;
}

.btn-icon {
  line-height: 0;
}

.btn-icon svg,
.scan-search-btn svg {
  display: block;
}

.btn.active {
  border-color: #2563eb;
  background: #eff6ff;
  color: #2563eb;
}

.filter-pop {
  position: absolute;
  top: calc(100% - 4px);
  right: 24px;
  width: 340px;
  max-width: calc(100vw - 24px);
  max-height: 62vh;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 12px 34px rgba(15, 23, 42, .18);
  padding: 14px 16px;
  z-index: 60;
  animation: pop .15s ease;
}

.filter-pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

#filterMenu {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 4px 14px;
}

#filterMenu .filter-pop-head {
  flex: 1 0 100%;
}

#filterMenu .filter-group {
  flex: 1 1 160px;
  min-width: 160px;
}

@media (max-width: 520px) {
  #filterMenu {
    display: block;
  }
}

@media (min-width: 900px) {
  #filterMenu {
    width: 460px;
  }
}

.sort-opts {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sort-option {
  text-align: left;
  padding: 8px 10px;
  border: 0;
  background: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: #1e293b;
  width: 100%;
}

.sort-option:hover {
  background: #f1f5f9;
}

.sort-option.active {
  background: #eff6ff;
  color: #2563eb;
  font-weight: 600;
}

.sort-dir {
  margin-top: 10px;
  border-top: 1px solid #e2e8f0;
  padding-top: 10px;
  display: flex;
  justify-content: center;
}

.filter-group h3 {
  margin: 12px 0 6px;
  font-size: 12px;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.chips {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 172px;
  overflow-y: auto;
}

.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  padding: 5px 8px;
  border-radius: 8px;
  cursor: pointer;
}

.chip:hover {
  background: #f1f5f9;
}

.chip input {
  accent-color: #2563eb;
  flex-shrink: 0;
}

.chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip em {
  margin-left: auto;
  font-style: normal;
  color: #94a3b8;
  font-size: 12px;
  flex-shrink: 0;
}

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 24px;
}

.count {
  color: #64748b;
  font-size: 13px;
  margin: 0 0 14px;
}

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

.book {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "thumb info"
    "actions actions";
  gap: 12px 14px;
  align-items: start;
  cursor: pointer;
}

.thumb {
  grid-area: thumb;
  width: 72px;
  height: 100px;
  flex-shrink: 0;
  border-radius: 6px;
  overflow: hidden;
  background: #e8eef5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
}

.thumb[data-cover] {
  position: relative;
  cursor: zoom-in;
}

.cover-zoom {
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: rgba(15, 23, 42, .6);
  color: #fff;
  font-size: 12px;
  line-height: 22px;
  cursor: zoom-in;
}

.thumb[data-cover]:hover .cover-zoom {
  background: rgba(15, 23, 42, .9);
}

.cover-viewer {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  cursor: zoom-out;
}

.cover-viewer img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 8px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, .55);
  background: #fff;
  cursor: zoom-out;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.info {
  grid-area: info;
  flex: 1;
  min-width: 0;
}

.title {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.3;
}

.author {
  color: #475569;
  font-size: 13px;
  margin-top: 2px;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 8px;
  font-size: 12px;
  color: #64748b;
}

.desc {
  margin-top: 8px;
  font-size: 12.5px;
  line-height: 1.4;
  color: #475569;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.actions {
  grid-area: actions;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 6px;
  border-top: 1px solid #eef2f7;
  padding-top: 10px;
}

.empty {
  text-align: center;
  color: #64748b;
  font-size: 15px;
  padding: 40px 0;
}

.btn {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #1d2733;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s;
}

.btn:hover {
  background: #f1f5f9;
}

.btn.primary {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

.btn.primary:hover {
  background: #1d4ed8;
}

.btn.small {
  padding: 6px 10px;
  font-size: 13px;
}

.btn.danger {
  border-color: #fca5a5;
  color: #b91c1c;
}

.btn.danger:hover {
  background: #fef2f2;
}

[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 30px 16px;
  overflow-y: auto;
  z-index: 50;
}

.modal-card {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  padding: 20px;
  animation: pop .15s ease;
}

@keyframes pop {
  from { transform: translateY(-8px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
}

.x {
  border: none;
  background: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: #64748b;
  padding: 0 4px;
}

form label {
  display: block;
  font-size: 13px;
  color: #475569;
  font-weight: 500;
  margin-bottom: 10px;
}

form input[type="text"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 400;
}

form textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 400;
  font-family: inherit;
  resize: vertical;
  box-sizing: border-box;
}

.cover-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.cover-row label {
  flex: 1;
  margin-bottom: 0;
}

.cover {
  width: 56px;
  height: 80px;
  object-fit: cover;
  border-radius: 6px;
  background: #e8eef5;
  cursor: zoom-in;
}

.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.foot-left {
  margin-right: auto;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.no-title {
  color: #94a3b8;
  font-style: italic;
}

.detail-card {
  max-width: 560px;
}

.detail-body {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.detail-cover {
  width: 120px;
  height: 170px;
  flex-shrink: 0;
  object-fit: cover;
  border-radius: 8px;
  background: #e8eef5;
}

.detail-main {
  flex: 1;
  min-width: 0;
}

.detail-title {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
}

.detail-author {
  color: #475569;
  font-size: 14px;
  margin-top: 4px;
}

.detail-desc {
  margin-top: 16px;
  font-size: 14px;
  line-height: 1.5;
  color: #334155;
  white-space: pre-wrap;
}

.lookup-msg {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  background: #f1f5f9;
}

.lookup-msg .ok { color: #15803d; }
.lookup-msg .warn { color: #b45309; }

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #cbd5e1;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin .8s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.scan-card {
  max-width: 520px;
}

.scan-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.scan-tabs .tab {
  flex: 1;
  padding: 9px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
}

.scan-tabs .tab.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

.scan-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#scanner-region {
  width: 100%;
}

#scanner-region video {
  width: 100%;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
}

#scanner-region img {
  border-radius: 10px;
  border: 1px solid #e2e8f0;
}

.hint {
  color: #64748b;
  font-size: 13px;
  text-align: center;
  margin: 0;
}

.file-btn {
  cursor: pointer;
  border: 2px dashed #cbd5e1;
  border-radius: 10px;
  padding: 26px 30px;
  color: #2563eb;
  font-weight: 600;
  font-size: 15px;
  text-align: center;
}

.file-btn input {
  display: none;
}

.file-btn:hover {
  border-color: #2563eb;
  background: #eff6ff;
}

.scan-msg {
  margin-top: 10px;
  color: #b91c1c;
  font-size: 14px;
  text-align: center;
}

.dup-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.dup-card {
  display: flex;
  gap: 10px;
  align-items: center;
  text-align: left;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 8px;
  margin-top: 10px;
}

.dup-cover {
  width: 42px;
  height: 58px;
  object-fit: cover;
  border-radius: 4px;
  background: #e8eef5;
  flex-shrink: 0;
}

.dup-cover-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.dup-info {
  min-width: 0;
}

.dup-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  color: #0f172a;
}

.dup-author {
  font-size: 12.5px;
  color: #475569;
  margin-top: 2px;
}

.manual-scan {
  margin-top: 14px;
  border-top: 1px solid #e2e8f0;
  padding-top: 12px;
}

.manual-scan label {
  display: block;
  font-size: 13px;
  color: #475569;
  font-weight: 500;
  margin-bottom: 6px;
}

.manual-row {
  display: flex;
  gap: 8px;
}

.manual-row input {
  flex: 1;
  padding: 9px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
}

@media (max-width: 480px) {
  .detail-body {
    flex-direction: column;
    align-items: center;
  }

  .detail-cover {
    width: 140px;
    height: 200px;
  }

  .filter-pop {
    right: 12px;
    left: 12px;
    width: auto;
  }
}