/* ==========================================================================
   Bookshelf theme
   --------------------------------------------------------------------------
   A dark, media-library look in the spirit of the Plex web client. Bootstrap 5
   is the base; everything below overrides its theme through custom properties
   rather than by fighting individual component rules.

   Bootstrap 5.3 reads most of its own colours from --bs-* custom properties,
   so redefining those on :root re-themes the framework's components for free.
   Our own palette lives in --bk-* variables, which the --bs-* ones point at,
   so there is a single place to change a colour.

   Deliberately NOT using Bootstrap's data-bs-theme="dark": that only swaps in
   Bootstrap's own grey ramp. This is a custom palette.
   ========================================================================== */

:root {
  /* ---- Palette ---------------------------------------------------------- */
  --bk-black:        #191a1c;   /* app background, behind everything      */
  --bk-surface:      #1f2326;   /* cards, sidebar                         */
  --bk-surface-2:    #26292d;   /* raised: hover, inputs                  */
  --bk-surface-3:    #303438;   /* borders, dividers, skeletons           */

  --bk-text:         #eaeaea;   /* primary copy                           */
  --bk-text-muted:   #9aa0a6;   /* secondary copy                         */
  --bk-text-faint:   #6f757a;   /* tertiary, timestamps                   */

  /* The single accent. Plex's golden-yellow, used only for primary actions,
     active nav and rating stars -- if everything is accented, nothing is. */
  --bk-accent:       #e5a00d;
  --bk-accent-hover: #f5b62c;
  --bk-accent-dim:   rgba(229, 160, 13, 0.16);
  --bk-on-accent:    #1a1508;   /* text on an accent fill; dark for contrast */

  --bk-danger:       #e5484d;
  --bk-success:      #46a758;
  --bk-info:         #4a9fd5;

  /* ---- Metrics ---------------------------------------------------------- */
  --bk-sidebar-w:        232px;
  --bk-sidebar-w-narrow: 68px;
  --bk-topbar-h:         56px;
  --bk-radius:           6px;
  --bk-radius-lg:        10px;
  --bk-shadow:           0 4px 14px rgba(0, 0, 0, 0.45);
  --bk-shadow-lift:      0 10px 26px rgba(0, 0, 0, 0.6);
  --bk-transition:       140ms ease;

  /* ---- Bootstrap overrides --------------------------------------------- */
  --bs-body-bg: var(--bk-black);
  --bs-body-color: var(--bk-text);
  --bs-body-font-family: "Open Sans", -apple-system, BlinkMacSystemFont,
                         "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --bs-body-font-size: 0.9375rem;
  --bs-emphasis-color: #fff;
  --bs-secondary-color: var(--bk-text-muted);
  --bs-tertiary-color: var(--bk-text-faint);
  --bs-border-color: var(--bk-surface-3);
  --bs-border-radius: var(--bk-radius);
  --bs-link-color: var(--bk-accent);
  --bs-link-hover-color: var(--bk-accent-hover);
  --bs-primary: var(--bk-accent);
  --bs-primary-rgb: 229, 160, 13;
  --bs-secondary-bg: var(--bk-surface-2);
  --bs-tertiary-bg: var(--bk-surface);
  --bs-heading-color: #fff;
  --bs-code-color: #e78ba9;
  --bs-focus-ring-color: var(--bk-accent-dim);
}

/* Native form controls, scrollbars and the like follow the dark scheme. */
:root { color-scheme: dark; }

html, body { overflow-x: hidden; max-width: 100%; }

/* Used in templates to let a flex child shrink below its content width.
   Bootstrap has no such utility, so it must be defined here. */
.min-width-0 { min-width: 0; }

body {
  background-color: var(--bk-black);
  color: var(--bk-text);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { font-weight: 600; letter-spacing: -0.01em; }

::selection { background: var(--bk-accent); color: var(--bk-on-accent); }

/* Visible focus for keyboard users, suppressed for mouse clicks. */
:focus-visible {
  outline: 2px solid var(--bk-accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Custom scrollbars: the default light ones are jarring against near-black. */
* { scrollbar-color: var(--bk-surface-3) transparent; scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--bk-surface-3);
  border-radius: 10px;
  border: 2px solid var(--bk-black);
}
::-webkit-scrollbar-thumb:hover { background: #43484d; }


/* ==========================================================================
   Layout: fixed sidebar + fixed topbar + scrolling content
   ========================================================================== */
.bk-shell { min-height: 100vh; }

.bk-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--bk-sidebar-w);
  background: var(--bk-surface);
  border-right: 1px solid var(--bk-surface-3);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: width var(--bk-transition);
}

.bk-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  height: var(--bk-topbar-h);
  padding: 0 0.875rem;
  flex-shrink: 0;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
}
.bk-brand:hover { color: #fff; }
.bk-brand svg { color: var(--bk-accent); flex-shrink: 0; }
.bk-brand img { flex-shrink: 0; object-fit: contain; }

.bk-nav {
  list-style: none;
  margin: 0;
  padding: 0.5rem 0.5rem 1rem;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
}
.bk-nav-heading {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--bk-text-faint);
  padding: 1rem 0.75rem 0.375rem;
  white-space: nowrap;
  overflow: hidden;
}

.bk-nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: 1px;
  border-radius: var(--bk-radius);
  color: var(--bk-text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--bk-transition), color var(--bk-transition);
}
.bk-nav-link:hover { background: var(--bk-surface-2); color: var(--bk-text); }
.bk-nav-link svg { flex-shrink: 0; width: 18px; height: 18px; }

/* The accent bar plus fill marks the current section, echoing how Plex
   highlights the active library. */
.bk-nav-link.active {
  background: var(--bk-accent-dim);
  color: var(--bk-accent);
  position: relative;
}
.bk-nav-link.active::before {
  content: "";
  position: absolute;
  left: -0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--bk-accent);
  border-radius: 0 3px 3px 0;
}

.bk-nav-label { overflow: hidden; text-overflow: ellipsis; }

.bk-sidebar-footer {
  padding: 0.5rem;
  border-top: 1px solid var(--bk-surface-3);
  flex-shrink: 0;
}

/* ---- Collapsed (icon-only) state, desktop --------------------------- */
.bk-collapsed .bk-sidebar { width: var(--bk-sidebar-w-narrow); }
.bk-collapsed .bk-nav-label,
.bk-collapsed .bk-nav-heading,
.bk-collapsed .bk-brand span { display: none; }
.bk-collapsed .bk-nav-link { justify-content: center; padding-inline: 0; }
.bk-collapsed .bk-nav-heading { padding: 0.5rem 0; }
.bk-collapsed .bk-main { margin-left: var(--bk-sidebar-w-narrow); }
.bk-collapsed .bk-topbar { left: var(--bk-sidebar-w-narrow); }

/* A tooltip stands in for the hidden label when collapsed. */
.bk-collapsed .bk-nav-link { position: relative; }
.bk-collapsed .bk-nav-link:hover::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--bk-surface-3);
  color: var(--bk-text);
  padding: 0.25rem 0.5rem;
  border-radius: var(--bk-radius);
  font-size: 0.75rem;
  white-space: nowrap;
  box-shadow: var(--bk-shadow);
  z-index: 10;
  pointer-events: none;
}

/* ---- Topbar --------------------------------------------------------- */
.bk-topbar {
  position: fixed;
  top: 0;
  left: var(--bk-sidebar-w);
  right: 0;
  height: var(--bk-topbar-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
  /* Translucent so content scrolling underneath is faintly visible, as in
     Plex's chrome. */
  background: rgba(25, 26, 28, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--bk-surface-3);
  z-index: 1030;
  transition: left var(--bk-transition);
}

.bk-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--bk-radius);
  background: transparent;
  color: var(--bk-text-muted);
  flex-shrink: 0;
  transition: background var(--bk-transition), color var(--bk-transition);
}
.bk-icon-btn:hover { background: var(--bk-surface-2); color: var(--bk-text); }

/* ---- Persistent search --------------------------------------------- */
.bk-search { position: relative; flex: 1 1 auto; min-width: 0; max-width: 460px; }
.bk-search svg {
  position: absolute;
  left: 0.625rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--bk-text-faint);
  pointer-events: none;
}
.bk-search input {
  width: 100%;
  height: 36px;
  padding: 0 0.75rem 0 2.125rem;
  background: var(--bk-surface-2);
  border: 1px solid transparent;
  border-radius: var(--bk-radius);
  color: var(--bk-text);
  font-size: 0.875rem;
  transition: background var(--bk-transition), border-color var(--bk-transition);
}
.bk-search input::placeholder { color: var(--bk-text-faint); }
.bk-search input:focus {
  outline: none;
  background: var(--bk-black);
  border-color: var(--bk-accent);
}

/* ---- Main column --------------------------------------------------- */
.bk-main {
  margin-left: var(--bk-sidebar-w);
  padding-top: var(--bk-topbar-h);
  min-height: 100vh;
  transition: margin-left var(--bk-transition);
}
.bk-content { padding: 1.75rem 1.25rem 4rem; max-width: 1500px; }

.bk-page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}
.bk-page-sub { color: var(--bk-text-muted); margin-bottom: 1.5rem; }

.bk-section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.0625rem;
  font-weight: 600;
  margin: 2rem 0 0.875rem;
}
.bk-section-title .bk-count {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--bk-text-faint);
}


/* ==========================================================================
   Book cards: cover-dominant, actions on hover
   ========================================================================== */
.bk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1.25rem 1rem;
  min-width: 0;
}
.bk-grid-sm { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }

.bk-card-wrap { min-width: 0; }
.bk-card { position: relative; display: block; text-decoration: none;
           min-width: 0; }

.bk-poster {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: var(--bk-radius);
  overflow: hidden;
  background: var(--bk-surface-2);
  box-shadow: var(--bk-shadow);
  transition: transform var(--bk-transition), box-shadow var(--bk-transition);
}
.bk-poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Books frequently have no cover; a generic solid-color "artwork" (its
   background set inline per book by _poster_fallback.html) beats a broken
   image icon and keeps the grid rhythm intact. The gradient here is only a
   fallback for the rare case something renders this markup without going
   through that macro. */
.bk-poster-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem;
  text-align: center;
  background: linear-gradient(160deg, var(--bk-surface-2), var(--bk-surface));
}
.bk-poster-fallback .bk-fallback-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Keyboard focus still gets a visible lift -- unlike hover, that's an
   accessibility affordance (showing where focus is), not decoration. */
.bk-card:focus-visible .bk-poster {
  transform: translateY(-4px);
  box-shadow: var(--bk-shadow-lift);
}

/* Hover overlay carrying the quick actions. Revealed on hover and, so it is
   reachable without a pointer, on keyboard focus within. */
.bk-poster-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.625rem;
  background: linear-gradient(to top,
              rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.5) 45%, transparent 100%);
  opacity: 0;
  transition: opacity var(--bk-transition);
}
.bk-card:hover .bk-poster-overlay,
.bk-card:focus-within .bk-poster-overlay { opacity: 1; }

/* Touch devices have no hover, so the overlay would be unreachable. */
@media (hover: none) {
  .bk-poster-overlay { opacity: 1; background: linear-gradient(to top,
      rgba(0,0,0,0.85) 0%, transparent 60%); }
}

.bk-quick-actions { display: flex; align-items: center; gap: 0.375rem; }

.bk-quick-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  height: 30px;
  padding: 0 0.5rem;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(4px);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  transition: background var(--bk-transition), transform var(--bk-transition);
}
.bk-quick-btn:hover { background: rgba(255, 255, 255, 0.3); color: #fff; }
.bk-quick-btn-accent { background: var(--bk-accent); color: var(--bk-on-accent); }
.bk-quick-btn-accent:hover {
  background: var(--bk-accent-hover);
  color: var(--bk-on-accent);
  transform: scale(1.05);
}
.bk-quick-btn-round { width: 30px; padding: 0; }

/* A book title rendered as a link anywhere outside a card or the detail
   hero (dashboard rows, history, import results, ...) -- always white,
   regardless of link state, unlike a default anchor. */
.bk-title-link,
.bk-title-link:hover,
.bk-title-link:focus,
.bk-title-link:visited,
.bk-title-link:active {
  color: #fff;
}
.bk-title-link:hover { text-decoration: underline; }

.bk-card-body { padding-top: 0.5rem; }
.bk-card-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #fff;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.bk-card-meta {
  font-size: 0.75rem;
  color: var(--bk-text-faint);
  margin-top: 0.125rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bk-card-author { position: relative; z-index: 1; }
.bk-card-author:hover { color: var(--bk-text); text-decoration: underline; }

/* Corner badge, e.g. reading status on a library card. */
.bk-poster-badge {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  padding: 0.125rem 0.4375rem;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.bk-poster-badge-accent {
  background: var(--bk-accent);
  color: var(--bk-on-accent);
}

/* Small icon-only badges in the poster's upper-right corner -- "you've read
   this" and "a file is uploaded for this book" can both apply to the same
   book at once, so they sit in a flex group rather than each claiming the
   same fixed spot and overlapping. */
.bk-poster-badges-right {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  gap: 0.25rem;
}
.bk-poster-badge-icon {
  display: inline-flex;
  padding: 0.25rem;
  line-height: 0;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  color: #fff;
}
.bk-poster-badge-icon.bk-poster-badge-accent { background: var(--bk-accent); color: var(--bk-on-accent); }
.bk-poster-badge-icon svg { width: 12px; height: 12px; }

/* Thin progress bar pinned to the bottom of a poster. */
.bk-poster-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.2);
}
.bk-poster-progress > span {
  display: block;
  height: 100%;
  background: var(--bk-accent);
}


/* ==========================================================================
   Star rating
   ========================================================================== */
.bk-stars { display: inline-flex; gap: 1px; }
.bk-stars svg { width: 14px; height: 14px; }
.bk-stars .bk-star-on { color: var(--bk-accent); }
.bk-stars .bk-star-off { color: rgba(255, 255, 255, 0.25); }

/* Interactive variant: radio inputs styled as stars, so rating works without
   JavaScript and stays keyboard operable. */
.bk-rate { display: inline-flex; flex-direction: row-reverse; gap: 1px; }
.bk-rate input { position: absolute; opacity: 0; pointer-events: none; }
.bk-rate label {
  cursor: pointer;
  color: rgba(255, 255, 255, 0.25);
  line-height: 1;
  transition: color var(--bk-transition), transform var(--bk-transition);
}
.bk-rate label svg { width: 17px; height: 17px; display: block; }
/* Reverse order means the siblings after a star are the lower ones. */
.bk-rate input:checked ~ label,
.bk-rate label:hover,
.bk-rate label:hover ~ label { color: var(--bk-accent); }
.bk-rate label:hover { transform: scale(1.18); }
.bk-rate input:focus-visible + label { outline: 2px solid var(--bk-accent); }


/* ==========================================================================
   Detail page: backdrop + poster + metadata
   ========================================================================== */
.bk-detail-hero { position: relative; margin: -1.75rem -1.25rem 0; }

/* The cover, blurred and darkened, doubles as the backdrop -- books have no
   separate landscape art the way films do. */
.bk-detail-backdrop {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--bk-surface);
}
.bk-detail-backdrop img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: blur(28px) saturate(1.4) brightness(0.42);
  transform: scale(1.15);
}
.bk-detail-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom,
              rgba(25, 26, 28, 0.55) 0%,
              rgba(25, 26, 28, 0.85) 55%,
              var(--bk-black) 100%);
}

/* Share/recommend/more-actions, upper-right of the whole hero. top/right
   match .bk-detail-inner's own padding (2.5rem/1.25rem below) so these
   align with the poster and title's top edge, not the hero's bare edge.
   z-index is required, not just DOM order: .bk-detail-inner below is also
   `position: relative` with the default z-index:auto, comes later in the
   DOM, and spans the full width of the hero (including this corner) --
   without this, it silently painted on top and ate every click here even
   though nothing was visibly drawn over the buttons. */
.bk-detail-corner-actions {
  position: absolute;
  top: 2.5rem;
  right: 1.25rem;
  z-index: 2;
  display: flex;
  gap: 0.375rem;
}
.bk-detail-corner-actions .bk-icon-btn {
  border-radius: var(--bk-radius);
  /* A solid chip, not a low-opacity tint -- the latter was nearly the same
     color as the backdrop's own darkening gradient at this spot and read as
     no background at all. */
  background: var(--bk-surface-2);
  color: #fff;
}
.bk-detail-corner-actions .bk-icon-btn:hover { background: var(--bk-surface-3); }

.bk-detail-inner {
  position: relative;
  display: flex;
  gap: 1.75rem;
  padding: 2.5rem 1.25rem 1.75rem;
}
.bk-detail-poster {
  /* Fixed height, not width: every cover is the same height regardless of
     its own aspect ratio, with width following from the standard 2:3
     poster ratio -- height is the constraint here, not the flex-basis. */
  flex: 0 0 auto;
  height: 400px;
  aspect-ratio: 2 / 3;
  border-radius: var(--bk-radius-lg);
  overflow: hidden;
  box-shadow: var(--bk-shadow-lift);
  position: relative;
  background: var(--bk-surface-2);
}
.bk-detail-poster img { width: 100%; height: 100%; object-fit: cover; }
.bk-poster-zoom {
  position: absolute;
  right: 0.5rem;
  bottom: 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(25, 26, 28, 0.6);
  color: #fff;
}
.bk-poster-zoom:hover { background: rgba(25, 26, 28, 0.85); }

.bk-detail-info { flex: 1; min-width: 0; padding-top: 0.25rem; }
.bk-detail-title {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: #fff;
  margin-bottom: 0.25rem;
}
.bk-detail-subtitle {
  font-size: 1.0625rem;
  color: var(--bk-text-muted);
  margin-bottom: 0.75rem;
}

/* Dot-separated facts, the way Plex lays out year / rating / duration. */
.bk-facts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  color: var(--bk-text-muted);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}
.bk-facts > * { display: inline-flex; align-items: center; gap: 0.3125rem; }
.bk-facts .bk-dot { color: var(--bk-surface-3); }

.bk-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}
.bk-summary {
  color: var(--bk-text);
  line-height: 1.6;
  max-width: 70ch;
  white-space: pre-line;
}

/* Metadata as label/value rows. */
.bk-meta-grid {
  display: grid;
  grid-template-columns: minmax(96px, auto) 1fr;
  gap: 0.5rem 1.25rem;
  font-size: 0.875rem;
}
.bk-meta-grid dt { color: var(--bk-text-faint); font-weight: 500; }
.bk-meta-grid dd { color: var(--bk-text); margin: 0; }

/* ---- Cast-style author row ------------------------------------------ */
.bk-people { display: flex; gap: 1rem; flex-wrap: wrap; }
.bk-person { width: 96px; text-align: center; text-decoration: none; }
.bk-person-avatar {
  width: 72px;
  height: 72px;
  margin: 0 auto 0.5rem;
  border-radius: 50%;
  background: linear-gradient(150deg, var(--bk-surface-2), var(--bk-surface-3));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--bk-text-muted);
  transition: transform var(--bk-transition), color var(--bk-transition);
}
.bk-person:hover .bk-person-avatar {
  transform: scale(1.06);
  color: var(--bk-accent);
}
.bk-person-name {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--bk-text);
  line-height: 1.3;
  overflow-wrap: break-word;
}
.bk-person-role { display: block; font-size: 0.6875rem; color: var(--bk-text-faint); }

/* ---- Horizontal scrolling shelf ------------------------------------- */
.bk-shelf {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding-bottom: 0.5rem;
  /* Bleed to the viewport edge so the row reads as continuing off-screen. */
  margin-inline: -1.25rem;
  padding-inline: 1.25rem;
  scrollbar-width: thin;
}
.bk-shelf > * { flex: 0 0 140px; scroll-snap-align: start; }
.bk-shelf-item-current { position: relative; }
.bk-shelf-item-current .bk-poster { outline: 2px solid var(--bk-accent); }

/* My Library dashboard rows: cover as a left column, info beside it, at
   every width -- narrower on phones so the info column stays usable. */
.bk-dashboard-row-poster { width: 64px; }
@media (min-width: 576px) {
  .bk-dashboard-row-poster { width: 84px; }
}


/* ==========================================================================
   Bootstrap component overrides
   ========================================================================== */
.card {
  --bs-card-bg: var(--bk-surface);
  --bs-card-border-color: var(--bk-surface-3);
  --bs-card-cap-bg: transparent;
  border-radius: var(--bk-radius-lg);
}

.btn { --bs-btn-font-weight: 600; border-radius: var(--bk-radius); }
.btn-primary {
  --bs-btn-bg: var(--bk-accent);
  --bs-btn-border-color: var(--bk-accent);
  --bs-btn-color: var(--bk-on-accent);
  --bs-btn-hover-bg: var(--bk-accent-hover);
  --bs-btn-hover-border-color: var(--bk-accent-hover);
  --bs-btn-hover-color: var(--bk-on-accent);
  --bs-btn-active-bg: var(--bk-accent-hover);
  --bs-btn-active-border-color: var(--bk-accent-hover);
  --bs-btn-active-color: var(--bk-on-accent);
  --bs-btn-disabled-bg: var(--bk-surface-3);
  --bs-btn-disabled-border-color: var(--bk-surface-3);
  --bs-btn-disabled-color: var(--bk-text-faint);
}
.btn-outline-primary {
  --bs-btn-color: var(--bk-accent);
  --bs-btn-border-color: rgba(229, 160, 13, 0.5);
  --bs-btn-hover-bg: var(--bk-accent);
  --bs-btn-hover-border-color: var(--bk-accent);
  --bs-btn-hover-color: var(--bk-on-accent);
}
.btn-secondary, .btn-outline-secondary {
  --bs-btn-bg: var(--bk-surface-2);
  --bs-btn-border-color: var(--bk-surface-3);
  --bs-btn-color: var(--bk-text);
  --bs-btn-hover-bg: var(--bk-surface-3);
  --bs-btn-hover-border-color: #454b50;
  --bs-btn-hover-color: #fff;
}
.btn-outline-danger {
  --bs-btn-color: #ff8b8f;
  --bs-btn-border-color: rgba(229, 72, 77, 0.45);
  --bs-btn-hover-bg: var(--bk-danger);
  --bs-btn-hover-border-color: var(--bk-danger);
  --bs-btn-hover-color: #fff;
}

.form-control, .form-select {
  background-color: var(--bk-surface-2);
  border-color: var(--bk-surface-3);
  color: var(--bk-text);
}
.form-control:focus, .form-select:focus {
  background-color: var(--bk-black);
  border-color: var(--bk-accent);
  color: var(--bk-text);
  box-shadow: 0 0 0 3px var(--bk-accent-dim);
}
.form-control::placeholder { color: var(--bk-text-faint); }
.form-control:disabled { background-color: var(--bk-surface); }
.form-label { font-size: 0.8125rem; font-weight: 600; color: var(--bk-text-muted); }
.form-text { color: var(--bk-text-faint); font-size: 0.75rem; }
.form-check-input { background-color: var(--bk-surface-2); border-color: var(--bk-surface-3); }
.form-check-input:checked {
  background-color: var(--bk-accent);
  border-color: var(--bk-accent);
}
.input-group-text {
  background-color: var(--bk-surface-2);
  border-color: var(--bk-surface-3);
  color: var(--bk-text-muted);
}

.list-group {
  --bs-list-group-bg: var(--bk-surface);
  --bs-list-group-color: var(--bk-text);
  --bs-list-group-border-color: var(--bk-surface-3);
  --bs-list-group-action-hover-bg: var(--bk-surface-2);
  --bs-list-group-action-hover-color: #fff;
  --bs-list-group-active-bg: var(--bk-accent);
  --bs-list-group-active-border-color: var(--bk-accent);
  --bs-list-group-active-color: var(--bk-on-accent);
}

.badge { font-weight: 600; letter-spacing: 0.01em; }
.text-bg-light { background-color: var(--bk-surface-3) !important; color: var(--bk-text) !important; }
.text-bg-secondary { background-color: var(--bk-surface-3) !important; color: var(--bk-text) !important; }
.text-bg-success { background-color: var(--bk-success) !important; color: #fff !important; }

.alert {
  border: 1px solid transparent;
  border-radius: var(--bk-radius);
  background: var(--bk-surface);
  color: var(--bk-text);
  border-left-width: 3px;
}
.alert-success { border-left-color: var(--bk-success); }
.alert-danger  { border-left-color: var(--bk-danger); }
.alert-warning { border-left-color: var(--bk-accent); }
.alert-info    { border-left-color: var(--bk-info); }
.btn-close { filter: invert(1) grayscale(1) brightness(1.6); }

.nav-pills {
  --bs-nav-pills-link-active-bg: var(--bk-accent);
  --bs-nav-pills-link-active-color: var(--bk-on-accent);
  --bs-nav-link-color: var(--bk-text-muted);
  --bs-nav-link-hover-color: var(--bk-text);
  gap: 0.25rem;
}
.nav-pills .nav-link { border-radius: 999px; font-size: 0.8125rem; font-weight: 600; }
.nav-pills .nav-link:not(.active):hover { background: var(--bk-surface-2); }

.pagination {
  --bs-pagination-bg: var(--bk-surface);
  --bs-pagination-color: var(--bk-text-muted);
  --bs-pagination-border-color: var(--bk-surface-3);
  --bs-pagination-hover-bg: var(--bk-surface-2);
  --bs-pagination-hover-color: var(--bk-text);
  --bs-pagination-hover-border-color: var(--bk-surface-3);
  --bs-pagination-active-bg: var(--bk-accent);
  --bs-pagination-active-border-color: var(--bk-accent);
  --bs-pagination-active-color: var(--bk-on-accent);
  --bs-pagination-disabled-bg: var(--bk-surface);
  --bs-pagination-disabled-color: var(--bk-text-faint);
  --bs-pagination-disabled-border-color: var(--bk-surface-3);
}

.breadcrumb { --bs-breadcrumb-divider-color: var(--bk-text-faint); font-size: 0.8125rem; }
.breadcrumb-item a { color: var(--bk-text-muted); text-decoration: none; }
.breadcrumb-item a:hover { color: var(--bk-accent); }
.breadcrumb-item.active { color: var(--bk-text-faint); }

.progress { background-color: var(--bk-surface-3); }
.progress-bar { background-color: var(--bk-accent); }

.dropdown-menu {
  --bs-dropdown-bg: var(--bk-surface-2);
  --bs-dropdown-border-color: var(--bk-surface-3);
  --bs-dropdown-color: var(--bk-text);
  --bs-dropdown-link-color: var(--bk-text);
  --bs-dropdown-link-hover-bg: var(--bk-surface-3);
  --bs-dropdown-link-hover-color: #fff;
  --bs-dropdown-divider-bg: var(--bk-surface-3);
  box-shadow: var(--bk-shadow);
}

.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--bk-text);
  --bs-table-border-color: var(--bk-surface-3);
  --bs-table-hover-bg: var(--bk-surface-2);
  --bs-table-hover-color: var(--bk-text);
}

fieldset.bk-fieldset {
  border: 1px solid var(--bk-surface-3);
  border-radius: var(--bk-radius-lg);
  padding: 1rem 1.25rem;
}
fieldset.bk-fieldset legend {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--bk-text-muted);
  padding-inline: 0.5rem;
  width: auto;
  float: none;
}


/* ==========================================================================
   Stat tiles
   ========================================================================== */
.bk-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.875rem;
  margin-bottom: 1.75rem;
}
.bk-stat {
  background: var(--bk-surface);
  border: 1px solid var(--bk-surface-3);
  border-radius: var(--bk-radius-lg);
  padding: 1rem 1.125rem;
}
.bk-stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
  color: #fff;
}
.bk-stat-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--bk-text);
  margin-top: 0.25rem;
}
.bk-stat-hint { font-size: 0.75rem; color: var(--bk-text-faint); }
.bk-stat-accent .bk-stat-value { color: var(--bk-accent); }


/* ==========================================================================
   Empty states
   ========================================================================== */
.bk-empty {
  text-align: center;
  padding: 3.5rem 1.25rem;
  border: 1px dashed var(--bk-surface-3);
  border-radius: var(--bk-radius-lg);
  background: rgba(31, 35, 38, 0.4);
}
.bk-empty svg { color: var(--bk-surface-3); margin-bottom: 1rem; }
/* Inside a page section rather than standing in for the whole page. */
.bk-empty-compact { padding: 1.75rem 1rem; }
.bk-empty-compact svg { margin-bottom: 0.5rem; }
.bk-empty-compact h2 { font-size: 0.9375rem; }
.bk-empty-compact p { font-size: 0.8125rem; margin-bottom: 0.75rem; }
.bk-empty h2 { font-size: 1.0625rem; margin-bottom: 0.375rem; }
.bk-empty p { color: var(--bk-text-muted); margin-bottom: 1.25rem; }

.bk-auth-card {
  max-width: 400px;
  margin: 3rem auto;
  background: var(--bk-surface);
  border: 1px solid var(--bk-surface-3);
  border-radius: var(--bk-radius-lg);
  padding: 2rem;
  box-shadow: var(--bk-shadow);
}


/* ==========================================================================
   Library controls: status icons, rating stars, recommend toggle
   ========================================================================== */
.bk-status-icons { display: inline-flex; flex-wrap: wrap; gap: 0.25rem; }

.bk-status-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--bk-surface-3);
  border-radius: 999px;
  background: var(--bk-surface-2);
  color: var(--bk-text-muted);
  transition: background var(--bk-transition), color var(--bk-transition),
              border-color var(--bk-transition);
}
.bk-status-icon-btn svg { width: 16px; height: 16px; }
.bk-status-icon-btn:hover { background: var(--bk-surface-3); color: var(--bk-text); }
.bk-status-icon-btn.active {
  background: var(--bk-accent);
  border-color: var(--bk-accent);
  color: var(--bk-on-accent);
}
/* Recommended uses its own colour so it reads as a distinct flag rather than
   one more (mutually exclusive) status value next to it. */
.bk-recommend-btn.active {
  background: var(--bk-success);
  border-color: var(--bk-success);
  color: #fff;
}

/* Toggled by a click on the Read status icon (library-controls.js). Sits
   inline in the same flex row as the rest of the status icons, so revealing
   it pushes whatever comes after (Want to reread, then rating/recommend
   outside this row) to the right rather than overlapping anything. */
.bk-inline-read-date { display: inline-flex; }
.bk-inline-read-date input[type="date"] { width: 9.5rem; }


/* ==========================================================================
   Book detail: file-format availability chips (see catalog/_files.html)
   ========================================================================== */
.bk-file-formats { display: inline-flex; flex-wrap: wrap; gap: 0.625rem; }
.bk-file-format-chip { position: relative; display: inline-flex; }

/* Delete overlaps the chip's corner, revealed the same way _card.html
   reveals its own hover actions -- on hover, on keyboard focus within (so
   it's reachable without a pointer), and always on a touch device, which
   has no hover to reveal it with. */
.bk-file-format-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  opacity: 0;
  transition: opacity var(--bk-transition);
}
.bk-file-format-chip:hover .bk-file-format-delete,
.bk-file-format-chip:focus-within .bk-file-format-delete { opacity: 1; }
@media (hover: none) {
  .bk-file-format-delete { opacity: 1; }
}
.bk-file-format-delete-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: 2px solid var(--bk-surface);
  border-radius: 999px;
  background: var(--bk-danger);
  color: #fff;
}
.bk-file-format-delete-btn svg { width: 10px; height: 10px; }


/* ==========================================================================
   Bulk upload: dropzone + staged-files table
   ========================================================================== */
.bk-dropzone {
  position: relative;
  border: 2px dashed var(--bk-surface-3);
  border-radius: var(--bk-radius-lg);
  background: rgba(31, 35, 38, 0.4);
  padding: 3.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--bk-transition), background var(--bk-transition);
}
.bk-dropzone:hover { border-color: #454b50; }
.bk-dropzone:focus-visible { outline: 2px solid var(--bk-accent); outline-offset: 3px; }
.bk-dropzone-active {
  border-color: var(--bk-accent);
  background: var(--bk-accent-dim);
}
.bk-dropzone-inner { pointer-events: none; }
.bk-dropzone-inner svg {
  width: 40px;
  height: 40px;
  color: var(--bk-text-faint);
  margin-bottom: 0.75rem;
}
.bk-dropzone-title { font-size: 1.0625rem; font-weight: 600; margin-bottom: 0.25rem; }
.bk-dropzone-sub { color: var(--bk-text-muted); font-size: 0.8125rem; margin-bottom: 1.25rem; }
.bk-dropzone-actions {
  display: flex;
  justify-content: center;
  gap: 0.625rem;
  pointer-events: auto;
}
/* Real <input>, invisibly stretched over the whole zone so it is the actual
   click target and keeps native file-picker behaviour/accessibility. */
.bk-dropzone-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* Sized for a card (the book detail page's Files card), not a full-width
   upload page -- same element, smaller padding and icon. */
.bk-dropzone-compact { padding: 1.25rem 1rem; }
.bk-dropzone-compact .bk-dropzone-inner svg {
  width: 26px;
  height: 26px;
  margin-bottom: 0.375rem;
}
.bk-dropzone-compact .bk-dropzone-title { font-size: 0.875rem; }
.bk-dropzone-compact .bk-dropzone-sub { font-size: 0.75rem; margin-bottom: 0; }

#staged-files-table th {
  color: var(--bk-text-faint);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom-width: 1px;
}
#staged-files-table td { vertical-align: middle; }

.bk-upload-progress { display: flex; align-items: center; min-width: 0; }
.bk-upload-progress .progress {
  flex: 1 1 auto;
  height: 6px;
  min-width: 60px;
}
.bk-progress-indeterminate .progress-bar {
  width: 40% !important;
  animation: bk-progress-indeterminate 1.1s ease-in-out infinite;
}
@keyframes bk-progress-indeterminate {
  0%   { margin-left: 0%; }
  50%  { margin-left: 60%; }
  100% { margin-left: 0%; }
}


/* ==========================================================================
   History: vertical timeline, grouped by book
   ========================================================================== */
.bk-history-timeline {
  position: relative;
  padding-left: 1.5rem;
  border-left: 2px solid var(--bk-surface-3);
}

.bk-history-book {
  position: relative;
  padding-bottom: 1.75rem;
}
.bk-history-book::before {
  content: "";
  position: absolute;
  left: -1.9375rem;
  top: 0.25rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--bk-accent);
  box-shadow: 0 0 0 3px var(--bk-black);
}

.bk-history-book-title {
  font-weight: 600;
  color: #fff;
  text-decoration: none;
  margin-right: 0.5rem;
}
.bk-history-book-title:hover { color: #fff; text-decoration: underline; }

.bk-history-actions {
  list-style: none;
  margin: 0.625rem 0 0;
  padding-left: 1.25rem;
  border-left: 1px solid var(--bk-surface-3);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.bk-history-actions li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--bk-text-muted);
}
.bk-history-action-icon {
  display: inline-flex;
  color: var(--bk-text-faint);
  flex-shrink: 0;
}
.bk-history-action-icon svg { width: 14px; height: 14px; }


/* ==========================================================================
   Mobile: sidebar becomes an off-canvas drawer plus a bottom bar
   ========================================================================== */
.bk-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1035;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--bk-transition);
}

.bk-bottom-nav { display: none; }

@media (max-width: 991.98px) {
  .bk-sidebar {
    transform: translateX(-100%);
    width: 264px;
    box-shadow: var(--bk-shadow-lift);
    transition: transform var(--bk-transition);
  }
  /* The drawer is open, so its labels must show even if the desktop
     "collapsed" preference is set. */
  .bk-drawer-open .bk-sidebar { transform: translateX(0); width: 264px; }
  .bk-drawer-open .bk-nav-label,
  .bk-drawer-open .bk-nav-heading,
  .bk-drawer-open .bk-brand span { display: revert; }
  .bk-drawer-open .bk-nav-link { justify-content: flex-start; padding-inline: 0.75rem; }
  .bk-drawer-open .bk-scrim { opacity: 1; pointer-events: auto; }

  .bk-main,
  .bk-collapsed .bk-main { margin-left: 0; padding-bottom: 4.25rem; }
  .bk-topbar,
  .bk-collapsed .bk-topbar { left: 0; padding-inline: 0.75rem; }
  .bk-content { padding: 1.25rem 0.875rem 3rem; }

  .bk-detail-hero { margin-inline: -0.875rem; }
  .bk-detail-corner-actions { top: 1.5rem; right: 0.875rem; }
  .bk-detail-inner {
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1.5rem 0.875rem;
  }
  /* height: auto is required, not cosmetic -- the base rule above fixes
     height: 400px, and with *both* width and height explicit/definite,
     aspect-ratio has nothing left to compute: the poster rendered at this
     narrower mobile width but the desktop height, several times taller
     than the intended 2:3 ratio. Freeing height lets aspect-ratio derive
     it from the new width instead. */
  .bk-detail-poster { flex-basis: auto; width: 150px; height: auto; }
  .bk-detail-title { font-size: 1.5rem; }
  .bk-facts, .bk-detail-actions, .bk-people { justify-content: center; }
  .bk-summary { text-align: left; }
  .bk-meta-grid { text-align: left; grid-template-columns: 1fr; gap: 0.125rem 0; }
  .bk-meta-grid dt { margin-top: 0.5rem; }
  .bk-shelf { margin-inline: -0.875rem; padding-inline: 0.875rem; }

  /* Bottom bar mirrors the primary destinations for thumb reach. */
  .bk-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3.75rem;
    display: flex;
    align-items: stretch;
    background: rgba(31, 35, 38, 0.97);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--bk-surface-3);
    z-index: 1039;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bk-bottom-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.1875rem;
    color: var(--bk-text-faint);
    text-decoration: none;
    font-size: 0.625rem;
    font-weight: 600;
  }
  .bk-bottom-link.active { color: var(--bk-accent); }
  .bk-bottom-link svg { width: 21px; height: 21px; }

  .bk-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 1rem 0.75rem; }
  .bk-search { max-width: none; }
  .bk-stats { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 575.98px) {
  .bk-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bk-page-title { font-size: 1.25rem; }
  .bk-stat-value { font-size: 1.375rem; }
}

/* Respect a user's reduced-motion preference. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .bk-card:focus-visible .bk-poster { transform: none; }
}
