/* ── Series header row ──────────────────────────────────────────── */
.series-header-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem 0.45rem;
  background: #0d1117;
  border: 1px solid rgba(245,166,35,0.45);
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  user-select: none;
  transition: background 0.1s;
}
.series-header-row:hover { background: #111827; }
.series-header-chevron {
  font-size: 0.6rem;
  color: #f5a623;
  transition: transform 0.15s;
  flex-shrink: 0;
}
.series-header-row[data-expanded="1"] .series-header-chevron {
  transform: rotate(90deg);
}
.series-header-name {
  font-size: 0.92rem;
  font-weight: 700;
  color: #f5a623;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.series-open-world-badge {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  color: #38bdf8;
  margin-left: 0.25rem;
  flex-shrink: 0;
}
.series-header-count {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  color: #6b7280;
  line-height: 1;
  flex-shrink: 0;
  white-space: nowrap;
}
.series-edit-btn {
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.1rem 0.25rem;
  border-radius: 4px;
  flex-shrink: 0;
  line-height: 1;
  transition: color 0.15s;
}
.series-edit-btn:hover { color: #f5a623; }
.series-edit-btn[disabled] { opacity: 0.35; cursor: not-allowed; }
.series-edit-btn--admin { color: #f5a623; }
.series-edit-btn--admin:hover { color: #fbbf24; }
.series-del-btn {
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.1rem 0.25rem;
  border-radius: 4px;
  flex-shrink: 0;
  line-height: 1;
  transition: color 0.15s;
}
.series-del-btn:hover { color: #ef4444; }
.series-header-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: rgba(245,166,35,0.5);
  transition: width 0.3s;
  border-radius: 0 2px 0 0;
}

.series-books-group {
  border: 1px solid rgba(245,166,35,0.45);
  border-top: none;
  border-radius: 0 0 6px 6px;
  overflow: hidden;
}
.series-empty-hint {
  padding: 0.6rem 0.9rem;
  font-size: 0.78rem;
  color: #6b7280;
}
.series-browse-btn {
  background: none;
  border: none;
  color: #f5a623;
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}
.series-books-group > .book-item:not(.book-item--container) {
  border-radius: 0;
  border: none;
  border-top: 1px solid #1f2937;
}
.series-books-group > .book-item:not(.book-item--container):first-child { border-top: none; }

.stash-block {
  border: 1px solid rgba(52,211,153,0.55);
  border-radius: 6px;
  overflow: hidden;
  background: rgba(15,27,24,0.35);
}
.stash-header-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem 0.45rem;
  background: #0f1b18;
  border: none;
  border-radius: 0;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  user-select: none;
  transition: background 0.1s;
}
.stash-block > .stash-header-row[data-expanded="1"] {
  border-bottom: 1px solid rgba(52,211,153,0.55);
}
.stash-header-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: rgba(52,211,153,0.5);
  transition: width 0.3s;
  border-radius: 0 2px 0 0;
}
.stash-header-row:hover { background: #13221f; }
.stash-header-chevron {
  font-size: 0.6rem;
  color: #34d399;
  transition: transform 0.15s;
  flex-shrink: 0;
}
.stash-header-row[data-expanded="1"] .stash-header-chevron { transform: rotate(90deg); }
.stash-header-name {
  font-size: 0.92rem;
  font-weight: 700;
  color: #34d399;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stash-header-count {
  display: inline-flex;
  align-items: center;
  font-size: 0.76rem;
  color: #9ca3af;
  line-height: 1;
  white-space: nowrap;
  flex-shrink: 0;
}
.stash-del-btn {
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.1rem 0.25rem;
  border-radius: 4px;
  flex-shrink: 0;
  line-height: 1;
}
.stash-edit-btn {
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.1rem 0.25rem;
  border-radius: 4px;
  flex-shrink: 0;
  line-height: 1;
}
.stash-edit-btn:hover { color: #34d399; }
.stash-del-btn:hover { color: #ef4444; }
.stash-items-group {
  border: none;
  border-radius: 0;
  overflow: visible;
}
.stash-items-group > .series-header-row {
  margin: 0.4rem 0.4rem 0;
  border-radius: 6px 6px 0 0;
}
.stash-items-group > .series-books-group {
  margin: 0 0.4rem 0.4rem;
  border-radius: 0 0 6px 6px;
}
.stash-items-group > .book-item,
.stash-items-group > .book-children-group {
  margin: 0.4rem;
}
.stash-items-group > .book-item:first-child,
.stash-items-group > .series-header-row:first-child {
  margin-top: 0;
}
.stash-items-group > .book-item--container[data-expanded="1"],
.stash-items-group > .book-item--container[data-search-expanded="1"] {
  margin: 0.4rem 0.4rem 0;
}
.stash-items-group > .book-item--container[data-expanded="1"]:first-child,
.stash-items-group > .book-item--container[data-search-expanded="1"]:first-child {
  margin-top: 0;
}
.stash-items-group > .book-children-group {
  margin-top: 0;
}
.stash-items-group > .book-item--container[data-expanded="1"] + .book-children-group,
.stash-items-group > .book-item--container[data-search-expanded="1"] + .book-children-group {
  margin: -1px 0.4rem 0.4rem;
}
.stash-items-group > .series-header-row[data-expanded="1"] + .series-books-group {
  margin-top: 0;
}


/* ── Add-entity modals ────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active {
  display: flex;
}
.modal-inner {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 10px;
  width: min(520px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  padding: 1.2rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
#add-stash-modal,
#edit-stash-modal {
  width: min(560px, 92vw);
  height: min(760px, 88vh);
  max-height: min(760px, 88vh);
  overflow: hidden;
  box-sizing: border-box;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  gap: 0.55rem;
}
#add-stash-modal > *,
#edit-stash-modal > * {
  min-width: 0;
}
#add-stash-modal .input-group:last-of-type,
#edit-stash-modal .input-group:last-of-type {
  grid-row: 3;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#add-stash-modal .auth-error,
#edit-stash-modal .auth-error {
  grid-row: 4;
  flex-shrink: 0;
}
#add-stash-modal .modal-actions,
#edit-stash-modal .modal-actions {
  grid-row: 5;
  margin-top: auto;
  padding-top: 0.65rem;
  flex-shrink: 0;
  background: #111827;
}

.stash-pick-list {
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;
  min-width: 0;
  max-height: none;
  overflow-y: auto;
  border: 1px solid #374151;
  border-radius: 8px;
  background: #0f172a;
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.stash-search-input {
  width: 100%;
  min-width: 0;
  margin: 0 0 0.45rem;
  padding: 0.38rem 0.55rem;
  border: 1px solid #374151;
  border-radius: 7px;
  background: #0b1220;
  color: #d1d5db;
  font: inherit;
}
.stash-search-input:focus {
  outline: none;
  border-color: #6b7280;
  box-shadow: 0 0 0 2px rgba(107,114,128,0.16);
}
.stash-search-input::placeholder {
  color: #6b7280;
}
.stash-pick-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.45rem;
  border-radius: 6px;
  background: #111827;
}
.stash-pick-row--selected {
  background: #15252a;
  box-shadow: inset 0 0 0 1px rgba(16,185,129,0.22);
}
.stash-pick-row:hover { background: #162032; }
.stash-pick-row--series .stash-pick-meta {
  color: #f5a623;
}
.stash-pick-row--anthology .stash-pick-meta {
  color: #a78bfa;
}
.stash-pick-row input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 30px;
  height: 17px;
  margin: 0;
  background: #374151;
  border-radius: 9px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s;
}
.stash-pick-row input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  background: #9ca3af;
  border-radius: 50%;
  transition: transform 0.15s, background 0.15s;
}
.stash-pick-row input[type="checkbox"]:checked {
  background: #10b981;
}
.stash-pick-row input[type="checkbox"]:checked::after {
  transform: translateX(13px);
  background: #fff;
}
.stash-pick-label {
  flex: 1;
  min-width: 0;
  font-size: 0.82rem;
  color: #d1d5db;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stash-pick-meta {
  font-size: 0.7rem;
  color: #6b7280;
  flex-shrink: 0;
}

#books-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#books-list > .series-header-row[data-expanded="1"] + .series-books-group,
#books-list > .book-item--container[data-expanded="1"] + .book-children-group,
#books-list > .book-item--container[data-search-expanded="1"] + .book-children-group {
  margin-top: -0.5rem;
}

.book-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
}
.book-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  flex: 1 1 auto;
  padding-right: 0.75rem;
}

.book-name-text {
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  color: #d1d5db;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.15s;
}
.book-name-text:hover { color: #f5a623; }

.book-name-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}
.book-name-row .book-name-text {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-active-run-badge {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: 0.05rem 0.4rem;
  font-size: 0.66rem;
  font-weight: 700;
  color: #0f172a;
  background: #22d3ee;
  border-radius: 999px;
  letter-spacing: 0.02em;
}

.book-sections {
  display: inline-flex;
  align-items: center;
  font-size: 0.78rem;
  color: #6b7280;
  line-height: 1.1;
}

.book-isbn {
  color: #4b5563;
  font-variant-numeric: tabular-nums;
}

.book-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
  flex-shrink: 0;
}

.book-actions .primary-btn {
  width: 100%;
  padding: 0.2rem 0.5rem;
  font-size: 0.82rem;
}

.book-secondary-actions {
  display: flex;
  gap: 0.25rem;
  width: 100%;
}

.book-edit-btn {
  background: #374151;
  color: #d1d5db;
  border: 1px solid #4b5563;
  border-radius: 7px;
  padding: 0.15rem 0.45rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
  flex: 1;
}
.book-edit-btn:hover { background: #4b5563; }
.book-edit-btn:disabled { opacity: 0.35; cursor: default; }
.book-edit-btn:disabled:hover { background: #374151; }
.book-edit-btn--admin { color: #f5a623; border-color: #92400e; }
.book-edit-btn--admin:hover { background: #422006; }

.book-del-btn {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #6b7280;
  padding: 0.15rem 0.4rem;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.12s;
}
.book-del-btn:hover { background: #7f1d1d; border-color: #991b1b; color: #fca5a5; }

.new-book-form {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.3rem;
}

.new-book-title {
  font-size: 0.8rem;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.new-book-form textarea {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #d1d5db;
  padding: 0.45rem 0.6rem;
  font-size: 0.82rem;
  font-family: inherit;
  resize: vertical;
  line-height: 1.5;
  width: 100%;
  box-sizing: border-box;
}
.new-book-form textarea:focus { outline: none; border-color: #f5a623; }
.new-book-form textarea::placeholder { color: #4b5563; }


/* ── Book title ───────────────────────────────────────────────── */

.book-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-top: -0.5rem;
}

#book-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #f5a623;
  padding: 0.2rem 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

#edit-book-btn {
  background: none;
  border: none;
  color: #4b5563;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  flex-shrink: 0;
  transition: color 0.12s, background 0.12s;
}
#edit-book-btn:hover { color: #f5a623; background: #374151; }
#edit-book-btn.admin-override { color: #f5a623; }
#edit-book-btn.admin-override:hover { color: #fbbf24; background: #422006; }

#pdf-download-btn {
  color: #4b5563;
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: none;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  flex-shrink: 0;
  transition: color 0.12s, background 0.12s;
}
#pdf-download-btn:hover { color: #60a5fa; background: #374151; }

/* ── Edit book modal ──────────────────────────────────────────── */

#edit-book-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}
#edit-book-modal-overlay.active { display: flex; }

#edit-book-modal {
  background: #111827;
  border: 1px solid #374151;
  border-radius: 10px;
  width: min(520px, 92vw);
  max-height: 88vh;
  padding: 1.2rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
  overflow-y: auto;
}

/* ── Book cover upload ────────────────────────────────────────── */

.cover-upload-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.cover-upload-group > label {
  font-size: 0.8rem;
  color: #9ca3af;
}

.optional-hint {
  color: #4b5563;
  font-size: 0.75rem;
}

.cover-preview-wrap {
  width: 100px;
  height: 150px;           /* 2:3 ratio */
  border: 1px solid #374151;
  border-radius: 6px;
  overflow: hidden;
  background: #111827;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cover-preview-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.cover-placeholder {
  font-size: 0.75rem;
  color: #4b5563;
  text-align: center;
}

