:root {
  color-scheme: light;
}
#books-tabbed-card.auto-height-tabbed-card {
  max-width: none;
  width: calc(100% - 24px);
  margin-inline: auto;
  border: 0;
  border-radius: 0;
}
#books-tabbed-card.auto-height-tabbed-card > .card-header {
  padding-inline: 0;
  background: #f6f8fa;
}
#books-tabbed-card.auto-height-tabbed-card > .tab-content > #app > .container {
  max-width: none;
}
#books-tabbed-card.auto-height-tabbed-card .nav-link {
  padding-inline: 10px;
}
@media (min-width: 992px) {
  #books-tabbed-card.auto-height-tabbed-card {
    width: calc(100% - 100px);
  }
  #books-tabbed-card.auto-height-tabbed-card .nav-link {
    padding-inline: 20px;
  }
}
body {
  background: #f6f8fa;
  color: #24292f;
}
.book-cover {
  height: 200px;
  object-fit: contain;
  background: #eef2f6;
}
.book-placeholder {
  height: 200px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #e5edfa, #c9d9f0);
  font-size: 4rem;
  color: #315780;
}
.markdown-body {
  background: white;
  color: #24292f;
  max-width: 980px;
  padding: 32px;
  margin: auto;
  min-height: 45vh;
}
.markdown-body img {
  height: auto;
  max-width: 100%;
  cursor: zoom-in;
}
.markdown-body pre {
  overflow: auto;
}
.markdown-body table {
  display: block;
  overflow: auto;
}
.chapter-panel {
  max-height: calc(100vh - 140px);
  overflow: auto;
}
.chapter-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 42px;
}
.chapter-row a {
  overflow-wrap: anywhere;
}
.chapter-row.drop-before {
  border-top: 4px solid #0d6efd;
}
.chapter-row.drop-after {
  border-bottom: 4px solid #0d6efd;
}
.chapter-row.drop-child {
  background: #cfe2ff;
}
#source.editor-source {
  font-family: ui-monospace, Consolas, monospace;
  height: 100%;
  min-height: 0;
  resize: none;
  overflow: auto;
  tab-size: 2;
}
.editor-preview {
  max-height: none;
  overflow: visible;
}
.toolbar .btn {
  min-height: 38px;
}
.reader-layout {
  max-width: none;
  margin: auto;
}
.reader-layout .markdown-body {
  max-width: none;
}
.reader-layout article.bg-white.border.rounded {
  border: 0 !important;
  border-radius: 0 !important;
}
@media (min-width: 768px) {
  .reader-layout #read-toc {
    border: 0 !important;
    border-radius: 0 !important;
  }
}
#zoom-stage {
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
#zoom-image {
  max-width: none;
  max-height: none;
  transform-origin: center;
  user-select: none;
  pointer-events: none;
}
.tree-actions .btn {
  min-width: 35px;
}
.sidebar-link.active {
  font-weight: bold;
  background: #e7f1ff;
}
.cover-small {
  width: 70px;
  height: 90px;
  object-fit: contain;
}
@media (max-width: 767px) {
  .markdown-body {
    padding: 20px 14px;
  }

  .chapter-panel {
    max-height: none;
  }
  .editor-preview {
    max-height: none;
  }
  .toolbar {
    gap: 3px !important;
  }
  .navbar-brand {
    font-size: 1rem;
  }
}

.admin-topbar {
  padding: 0;
  background: #000;
  color: #fff;
  box-shadow: 0 2px 4px #00000018;
}
.admin-topbar > .container {
  max-width: none;
  padding-inline: 12px;
}
.admin-topbar .brand {
  padding: 0;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: #fff;
  font-size: 1.35rem;
  font-weight: 800;
}
.admin-topbar .nav-link {
  color: #fff;
  border: 1px solid #fff9;
  border-radius: 0.375rem;
  padding: 0.375rem 0.75rem;
  background: transparent;
}
.admin-topbar .nav-link:hover,
.admin-topbar .nav-link:focus-visible {
  color: #fff;
  background: #ffffff26;
}
.admin-topbar .nav-link.active {
  color: #fff;
  background: #0d6efd;
  border-color: #0d6efd;
}
.topbar-user {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: 0.25rem;
  white-space: nowrap;
  padding-left: 0.75rem;
  border-left: 1px solid #fff8;
  font-weight: 600;
}
.portal-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  padding: 0 0.4rem;
  color: #fff;
}
.portal-link:hover,
.portal-link:focus-visible {
  color: #fff;
  background: #ffffff26;
}
.portal-link svg {
  width: 21px;
  height: 21px;
  fill: currentColor;
}
@media (max-width: 991.98px) {
  .admin-topbar .brand {
    font-size: 1.1rem;
  }
  .admin-topbar .brand img {
    width: 34px;
    height: 34px;
  }
  .topbar-user {
    border-left: 0;
    padding-left: 0.75rem;
  }
}

/* Match NobiPhoto's anonymous landing card without narrowing reading pages. */
body.guest-shelf { min-height: 100vh; background: #eef4f8; color: #343a40; }
.guest-shelf .admin-topbar { display: none; }
.guest-shelf-card { max-width: 1050px; background: #fff; border-radius: 28px; box-shadow: 0 20px 50px #1b3b5a1a; }
.guest-brand { color: #343a40; font-size: 1.35rem; font-weight: 800; }
@media (max-width: 575.98px) {
  .guest-shelf-card { border-radius: 20px; }
  .guest-brand { font-size: 1.1rem; }
}

.home-return { display:inline-flex; align-items:center; justify-content:center; flex:0 0 38px; width:38px; height:38px; color:#0089b2; text-decoration:none; }
.home-return:hover,.home-return:focus-visible { color:#006b8e; }
.home-return svg { width:24px; height:24px; fill:currentColor; }
@media(max-width:575.98px) { .home-return { width:34px; height:34px; flex-basis:34px; } }

/* Match NobiPhoto desktop topbar spacing; keep the Books mobile collapse. */
.admin-topbar .nav-link { white-space: nowrap; }
.portal-link { text-decoration: none; flex-shrink: 0; }
@media (max-width: 991.98px) {
  .admin-topbar > .container { padding-top: .25rem !important; padding-bottom: .25rem !important; gap: .5rem !important; }
  #topnav { padding-bottom: .25rem; }
  .books-tabbed-view #topnav { padding-bottom: 0; }
  .topbar-user { margin-left: 0; max-width: 100%; }
  #username { overflow: hidden; text-overflow: ellipsis; }
}

/* NobiPhoto mobile layout: identity on row one, visible pills on row two. */
@media (max-width: 575px) {
  .admin-topbar .container { position: relative; gap: .5rem !important; padding-top: .25rem !important; padding-bottom: .25rem !important; }
  .admin-topbar .brand { max-width: 54%; font-size: 1.1rem; }
  .admin-topbar .brand img { width: 34px; height: 34px; }
  .admin-topbar .topbar-menu { width: 100%; margin-left: 0 !important; padding-bottom: 0 !important; }
  .books-tabbed-view .admin-topbar .topbar-menu { width: auto; margin-left: auto !important; }
  .admin-topbar .topbar-menu > .nav { width: 100%; margin-left: 0 !important; justify-content: flex-start !important; gap: .375rem !important; }
  .admin-topbar .nav-link { min-height: 40px; padding: .35rem .55rem; font-size: .875rem; display: inline-flex; align-items: center; }
  .admin-topbar .topbar-user { position: absolute; top: .25rem; right: .75rem; max-width: 42%; min-height: 34px; margin-left: 0; padding-left: .5rem; border-left: 1px solid #fff8; font-size: .875rem; }
  .admin-topbar .topbar-user > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .admin-topbar .portal-link { width: auto; height: 34px; flex: 0 0 auto; }
}

/* Remove stacked mobile reading gutters; keep preview and editor spacing. */
@media (max-width: 767.98px) {
  #app.reader-view { padding-top: .5rem !important; }
}

/* Focus has one 12px outer inset; normal reader/editor spacing stays intact. */
body.focus-reading { background: #fff; }
body.focus-reading .admin-topbar,
body.focus-reading #books-tab-header,
body.focus-reading #nobi-version,
body.focus-reading .reader-toolbar { display: none !important; }
body.focus-reading #books-tabbed-card.auto-height-tabbed-card,
body.focus-reading #books-tabbed-card {
  width: 100%; max-width: none; margin: 0 !important; border: 0; border-radius: 0;
}
body.focus-reading #books-tab-content,
body.focus-reading #app { padding: 0 !important; margin: 0; }
body.focus-reading .reader-layout {
  width: 100%; padding: 12px 12px calc(80px + env(safe-area-inset-bottom, 0px));
}
body.focus-reading .reader-layout > .row { margin: 0; --bs-gutter-x: 0; --bs-gutter-y: 0; }
body.focus-reading .reader-layout > .row > aside { width: 0; padding: 0; }
body.focus-reading .reader-layout > .row > .col-md-9 { width: 100%; padding: 0; margin-top: 0; }
body.focus-reading .reader-layout article > h2 { padding-inline: 0 !important; }
body.focus-reading .reader-layout .markdown-body { padding-inline: 0; margin-inline: 0; width: 100%; }
body.focus-reading #read-toc { --bs-offcanvas-width: min(400px, 100vw); }
body.focus-reading #focus-reading-controls {
  position: fixed; right: max(12px, env(safe-area-inset-right, 0px));
  bottom: calc(12px + env(safe-area-inset-bottom, 0px)); z-index: 1030;
}
body.focus-reading #focus-reading-controls .btn { min-height: 44px; }

/* Shared reading/management shelf cards; text continues below the framed cover. */
.reading-book-card { cursor: pointer; }
.reading-book-layout { display: flow-root; }
.reading-book-cover {
  float: left; display: block; width: 38%; max-width: 120px;
  margin: 0 1rem .75rem 0;
}
.reading-book-cover img, .reading-book-placeholder {
  display: block; width: 100%; object-fit: contain; background: transparent;
  border: 1px solid #c6cbd2; border-left: 4px solid #a6afb9; border-bottom: 3px solid #b7bfc8;
  border-radius: 2px; box-shadow: 3px 3px 0 #e5e8ec, 5px 5px 9px #00000020;
}
.reading-book-cover img { height: auto; }
.reading-book-placeholder {
  height: 170px;
}
.reading-book-placeholder { display: grid; place-items: center; font-size: 3rem; color: #6c757d; }
/* Keep the complete heading beside the cover; prose below may wrap around it. */
.reading-book-heading { display: flow-root; min-width: 0; overflow-wrap: anywhere; }
.reading-book-title { min-width: 0; overflow-wrap: anywhere; }
.reading-book-title a {
  display: block; white-space: normal; overflow-wrap: anywhere;
}
.reading-book-meta { min-width: 0; margin-top: .75rem; overflow-wrap: anywhere; }
.reading-book-meta > div { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: .35rem; margin-bottom: .25rem; }
.reading-book-meta dt { flex: 0 0 auto; font-weight: 400; white-space: nowrap; }
.reading-book-meta dd { flex: 0 1 auto; min-width: 0; margin: 0; overflow-wrap: anywhere; }
.reading-book-meta time { white-space: nowrap; }
.reading-book-description { white-space: pre-line; overflow-wrap: anywhere; }
@media (min-width: 768px) {
  .reading-book-cover { width: 40%; max-width: none; }
  .reading-book-placeholder { height: 220px; }
}


@media (min-width: 992px) {
  .guest-shelf .guest-shelf-card { max-width: none; width: calc(100% - 100px); }
}


/* Masonry spans follow each card's natural height; no fixed card height. */
#books.books-masonry {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px;
  margin: 0; align-items: start;
}
#books.books-masonry > div { width: 100%; padding: 0; margin: 0; min-width: 0; }
#books.books-masonry > p { grid-column: 1 / -1; }
#books.books-masonry.masonry-ready { grid-auto-rows: 1px; row-gap: 0; grid-auto-flow: row dense; }
@media (min-width: 992px) {
  #books.books-masonry { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1400px) {
  #books.books-masonry { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* Editor-only viewport workspace. The shared tab card retains natural height. */
#editor-workspace { height: max(180px, calc(100dvh - 220px)); min-height: 0; margin-top: 0; }
#editor-workspace > * { margin-top: 0; min-height: 0; height: 100%; }
.editor-main { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.editor-controls { flex: 0 1 auto; min-height: 0; max-height: calc(100% - 96px); overflow-y: auto; overflow-x: hidden; }
.editor-panes { flex: 1 1 0; min-height: 0; }
.editor-panes > div { height: 100%; min-height: 0; }
#preview-pane { display: flex; flex-direction: column; }
#preview-pane > p { flex: 0 0 auto; }
#preview-pane .editor-preview { flex: 1 1 0; min-height: 0; overflow: auto; }
#edit-chapter-sidebar .offcanvas-body { flex: 1 1 0; min-height: 0; overflow: hidden; }
#edit-chapter-sidebar .offcanvas-body > :not(.chapter-panel) { flex-shrink: 0; }
#edit-chapter-sidebar .chapter-panel { flex: 1 1 0; min-height: 0; max-height: none; overflow-y: auto; }
@media (min-width: 992px) {
  #edit-chapter-sidebar { display: flex; flex-direction: column; height: 100%; }
}
@media (max-width: 991.98px) {
  #editor-workspace > .editor-chapters-column { width: 0; height: 0; padding: 0; }
  #edit-chapter-sidebar { --bs-offcanvas-width: min(360px, 100vw); }
}

/* Icon-only editing controls retain native keyboard/select behavior. */
.editor-icon-button { width: 44px; height: 44px; min-height: 44px; flex-shrink: 0; }
.editor-icon-button svg { flex-shrink: 0; }

/* One toolbar row: scroll controls locally instead of wrapping or widening the page. */
.editor-controls #toolbar {
  max-width: 100%; min-width: 0; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;
  padding: 2px 2px 6px; overscroll-behavior-x: contain; touch-action: pan-x pan-y;
}
.editor-controls #toolbar > * { flex-shrink: 0; }

.editor-toolbar-hint { display: none; }
@media (max-width: 991.98px) {
  .editor-toolbar-hint.has-overflow { display: flex; align-items: center; justify-content: space-between; gap: 4px; font-size: .75rem; }
  .editor-toolbar-hint > span { white-space: nowrap; }
  .editor-toolbar-hint [aria-hidden] { width: 16px; flex: 0 0 16px; text-align: center; }
}

.editor-title-row .form-control { min-width: 0; }

#chapter-title { background-color: #fff9db; }

#source.editor-source { background-color: #fff9db; }
#preview-pane, #preview.editor-preview { background-color: #fff; }

/* Account switches retain Bootstrap focus and disabled states. */
.account-status-switch .form-check-input:checked { background-color: #198754; border-color: #198754; }
