/* =========================================================
   BOOKVAULT PRODUCTION POLISH
   Loads after themes. Final SaaS visual overrides.
========================================================= */

/* =========================================================
   AI ASSIST CLOSE BUTTON — ALWAYS VISIBLE, ICON ONLY
========================================================= */

html body .bv-side-assist__header {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) 44px !important;
  gap: 14px !important;
  align-items: center !important;
}

html body .bv-side-assist__switcher {
  min-width: 0 !important;
}

html body .bv-side-assist__close,
html body button.bv-side-assist__close,
html body #bvSideAssistClose {
  position: relative !important;

  width: 40px !important;
  height: 40px !important;
  min-width: 40px !important;
  max-width: 40px !important;
  flex: 0 0 40px !important;

  padding: 0 !important;
  margin: 0 !important;

  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;

  border-radius: 14px !important;

  /* High contrast across glass, midnight, and archive */
  background: rgba(255, 255, 255, 0.94) !important;
  border: 1px solid rgba(15, 23, 42, 0.28) !important;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.18) !important;

  /* Kill literal CLOSE text forever */
  color: transparent !important;
  font-size: 0 !important;
  line-height: 0 !important;
  text-indent: -9999px !important;
  text-shadow: none !important;
  overflow: hidden !important;
  white-space: nowrap !important;

  opacity: 1 !important;
  visibility: visible !important;
  z-index: 5 !important;
}

html body .bv-side-assist__close::before,
html body .bv-side-assist__close::after,
html body button.bv-side-assist__close::before,
html body button.bv-side-assist__close::after,
html body #bvSideAssistClose::before,
html body #bvSideAssistClose::after {
  content: "" !important;
  position: absolute !important;
  left: 50% !important;
  top: 50% !important;

  width: 17px !important;
  height: 2.5px !important;

  background: #0f172a !important;
  border-radius: 999px !important;
  transform-origin: center !important;

  display: block !important;
  opacity: 1 !important;
  text-indent: 0 !important;
}

html body .bv-side-assist__close::before,
html body button.bv-side-assist__close::before,
html body #bvSideAssistClose::before {
  transform: translate(-50%, -50%) rotate(45deg) !important;
}

html body .bv-side-assist__close::after,
html body button.bv-side-assist__close::after,
html body #bvSideAssistClose::after {
  transform: translate(-50%, -50%) rotate(-45deg) !important;
}

html body .bv-side-assist__close:hover,
html body button.bv-side-assist__close:hover,
html body #bvSideAssistClose:hover {
  background: var(--bv-accent-primary, #2563eb) !important;
  border-color: var(--bv-accent-primary, #2563eb) !important;
  box-shadow: 0 10px 26px rgba(37, 99, 235, 0.28) !important;
  transform: translateY(-1px) !important;
}

html body .bv-side-assist__close:hover::before,
html body .bv-side-assist__close:hover::after,
html body button.bv-side-assist__close:hover::before,
html body button.bv-side-assist__close:hover::after,
html body #bvSideAssistClose:hover::before,
html body #bvSideAssistClose:hover::after {
  background: #ffffff !important;
}

/* =========================================================
   AI ASSIST HEADER RESPONSIVE SAFETY
========================================================= */

@media (max-width: 720px) {
  html body .bv-side-assist__header {
    grid-template-columns: minmax(0, 1fr) 40px !important;
    gap: 10px !important;
  }

  html body .bv-side-assist__close,
  html body button.bv-side-assist__close,
  html body #bvSideAssistClose {
    width: 38px !important;
    height: 38px !important;
    min-width: 38px !important;
    max-width: 38px !important;
  }
}

/* =========================================================
   GLASS / LIGHT THEME BUTTON READABILITY
========================================================= */

html[data-theme="glass"] body .bv-btn,
html[data-theme="glass"] body button {
  text-shadow: none !important;
}

html[data-theme="glass"] body .bv-side-assist__close,
html[data-theme="pure-minimal"] body .bv-side-assist__close {
  background: #ffffff !important;
  border: 1px solid rgba(37, 99, 235, 0.36) !important;
}

/* =========================================================
   ARCHIVE / DARK THEME CLOSE READABILITY
========================================================= */

html[data-theme="archive-terminal"] body .bv-side-assist__close,
html[data-theme="dark-obsidian"] body .bv-side-assist__close,
html[data-theme="midnight"] body .bv-side-assist__close {
  background: #f8fafc !important;
  border: 1px solid rgba(255, 255, 255, 0.78) !important;
}

html[data-theme="archive-terminal"] body .bv-side-assist__close::before,
html[data-theme="archive-terminal"] body .bv-side-assist__close::after,
html[data-theme="dark-obsidian"] body .bv-side-assist__close::before,
html[data-theme="dark-obsidian"] body .bv-side-assist__close::after,
html[data-theme="midnight"] body .bv-side-assist__close::before,
html[data-theme="midnight"] body .bv-side-assist__close::after {
  background: #020617 !important;
}
/* =========================================================
   AI STATUS / TYPING NOTICE READABILITY
   Fixes "Isolating OCR from the crop..." in dark/archive themes.
========================================================= */

html body .bv-ai-typing,
html body #bvAITyping,
html body #bvAIFocusTyping {
  background: rgba(255, 255, 255, 0.96) !important;
  color: #0f172a !important;
  border-top: 1px solid rgba(15, 23, 42, 0.12) !important;
  border-bottom: 1px solid rgba(15, 23, 42, 0.12) !important;
  padding: 10px 18px !important;
  font-size: 13px !important;
  font-style: italic !important;
  font-weight: 600 !important;
  line-height: 1.45 !important;
  text-shadow: none !important;
}

/* Archive/dark themes: make it look like a readable system strip */
html[data-theme="archive-terminal"] body .bv-ai-typing,
html[data-theme="archive-terminal"] body #bvAITyping,
html[data-theme="archive-terminal"] body #bvAIFocusTyping,
html[data-theme="midnight"] body .bv-ai-typing,
html[data-theme="midnight"] body #bvAITyping,
html[data-theme="midnight"] body #bvAIFocusTyping,
html[data-theme="dark-obsidian"] body .bv-ai-typing,
html[data-theme="dark-obsidian"] body #bvAITyping,
html[data-theme="dark-obsidian"] body #bvAIFocusTyping {
  background: #f8fafc !important;
  color: #0f172a !important;
  border-top: 1px solid rgba(255, 255, 255, 0.7) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.7) !important;
}

/* Glass theme: keep it soft but readable */
html[data-theme="glass"] body .bv-ai-typing,
html[data-theme="glass"] body #bvAITyping,
html[data-theme="glass"] body #bvAIFocusTyping {
  background: rgba(255, 255, 255, 0.82) !important;
  color: #1e293b !important;
  backdrop-filter: blur(10px) !important;
  -webkit-backdrop-filter: blur(10px) !important;
}
/* =========================================================
   AI ASSIST PANEL LAYOUT FIX
   Prevents double scrollbars and input/chat overlap.
========================================================= */

/* The side assistant itself should not be the scroll container */
html body .bv-side-assist {
  overflow: hidden !important;
}

/* Active view becomes a clean vertical app shell */
html body .bv-side-assist__view.is-active {
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

/* AI toolbar stays at the top */
html body .bv-ai-toolbar {
  flex: 0 0 auto !important;
}

/* Chat area is the only main scroll region */
html body .bv-ai-chat,
html body #bvAIChat {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;

  /* Give the last message breathing room above input bar */
  padding-bottom: 36px !important;
  box-sizing: border-box !important;
}

/* The typing/status line should not create awkward overlap */
html body .bv-ai-typing,
html body #bvAITyping {
  flex: 0 0 auto !important;
  min-height: 38px !important;
  box-sizing: border-box !important;
}

/* Input bar is always a clean bottom row */
html body .bv-ai-inputbar {
  flex: 0 0 auto !important;
  position: sticky !important;
  bottom: 0 !important;
  z-index: 20 !important;
  box-sizing: border-box !important;
}

/* Prevent the input itself from pushing beyond the side panel */
html body .bv-ai-inputbar input,
html body #bvAIInput {
  min-width: 0 !important;
  width: 100% !important;
  box-sizing: border-box !important;
}

/* Prevent SEND from becoming too large or misaligned */
html body .bv-ai-inputbar button,
html body #bvAISend {
  flex: 0 0 auto !important;
  min-width: 92px !important;
  white-space: nowrap !important;
}

/* Cleaner scrollbar inside the assistant chat only */
html body .bv-ai-chat::-webkit-scrollbar,
html body #bvAIChat::-webkit-scrollbar {
  width: 10px !important;
}

html body .bv-ai-chat::-webkit-scrollbar-track,
html body #bvAIChat::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.12) !important;
}

html body .bv-ai-chat::-webkit-scrollbar-thumb,
html body #bvAIChat::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.72) !important;
  border-radius: 999px !important;
  border: 2px solid transparent !important;
  background-clip: padding-box !important;
}

/* Archive mode: prevent bottom area from looking detached/overlapped */
html[data-theme="archive-terminal"] body .bv-ai-inputbar,
html[data-theme="archive-terminal"] body .bv-ai-typing,
html[data-theme="archive-terminal"] body #bvAITyping {
  border-left: 0 !important;
  border-right: 0 !important;
}

/* Focus modal uses same stable layout */
html body #bvAIFocusModal .bv-ai-chat,
html body #bvAIFocusChat {
  min-height: 0 !important;
  overflow-y: auto !important;
  padding-bottom: 36px !important;
}
/* =========================================================
   AI INPUT ROW — FORCE SAME LINE
   Keeps prompt input and SEND button aligned in all themes.
========================================================= */

html body .bv-ai-inputbar {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto !important;
  gap: 12px !important;
  align-items: stretch !important;
  width: 100% !important;
  box-sizing: border-box !important;
}

html body .bv-ai-inputbar input,
html body #bvAIInput {
  grid-column: 1 !important;
  width: 100% !important;
  min-width: 0 !important;
  height: 54px !important;
  box-sizing: border-box !important;
}

html body .bv-ai-inputbar button,
html body #bvAISend {
  grid-column: 2 !important;
  width: auto !important;
  min-width: 112px !important;
  height: 54px !important;
  padding: 0 26px !important;
  box-sizing: border-box !important;
  white-space: nowrap !important;
  align-self: stretch !important;
}

/* Prevent archive theme from turning SEND into a full-width block */
html[data-theme="archive-terminal"] body .bv-ai-inputbar button,
html[data-theme="archive-terminal"] body #bvAISend {
  width: auto !important;
  min-width: 112px !important;
}
/* =========================================================
   AI INPUT BAR FINAL FIX
   Overrides .bv-action-bar so input + SEND stay on one row.
========================================================= */

html body .bv-side-assist .bv-ai-inputbar.bv-action-bar {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: stretch !important;
  justify-content: flex-start !important;
  gap: 12px !important;
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

html body .bv-side-assist .bv-ai-inputbar.bv-action-bar > input#bvAIInput {
  flex: 1 1 auto !important;
  width: auto !important;
  min-width: 0 !important;
  max-width: none !important;
  height: 54px !important;
  margin: 0 !important;
  box-sizing: border-box !important;
}

html body .bv-side-assist .bv-ai-inputbar.bv-action-bar > button#bvAISend {
  flex: 0 0 112px !important;
  width: 112px !important;
  min-width: 112px !important;
  max-width: 112px !important;
  height: 54px !important;
  margin: 0 !important;
  padding: 0 18px !important;
  box-sizing: border-box !important;
  white-space: nowrap !important;
  align-self: stretch !important;
}

/* Keep it usable on narrow screens */
@media (max-width: 560px) {
  html body .bv-side-assist .bv-ai-inputbar.bv-action-bar {
    gap: 8px !important;
  }

  html body .bv-side-assist .bv-ai-inputbar.bv-action-bar > button#bvAISend {
    flex-basis: 88px !important;
    width: 88px !important;
    min-width: 88px !important;
    max-width: 88px !important;
    padding: 0 12px !important;
  }
}
/* =========================================================
   AI INPUT BAR — BALANCED ROW LAYOUT
   Makes input + SEND fit neatly across the panel.
========================================================= */

html body .bv-side-assist .bv-ai-inputbar.bv-action-bar {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) 96px !important;
  gap: 10px !important;
  align-items: center !important;

  width: 100% !important;
  max-width: 100% !important;
  padding: 14px 16px !important;
  margin: 0 !important;
  box-sizing: border-box !important;
}

html body .bv-side-assist .bv-ai-inputbar.bv-action-bar > input#bvAIInput {
  grid-column: 1 !important;
  width: 100% !important;
  min-width: 0 !important;
  height: 50px !important;
  margin: 0 !important;
  padding: 0 18px !important;
  box-sizing: border-box !important;
}

html body .bv-side-assist .bv-ai-inputbar.bv-action-bar > button#bvAISend {
  grid-column: 2 !important;
  width: 96px !important;
  min-width: 96px !important;
  max-width: 96px !important;
  height: 50px !important;
  margin: 0 !important;
  padding: 0 14px !important;
  box-sizing: border-box !important;
  white-space: nowrap !important;
  text-align: center !important;
  justify-content: center !important;
}

/* Archive terminal: keep the same geometry, just preserve the theme look */
html[data-theme="archive-terminal"] body .bv-side-assist .bv-ai-inputbar.bv-action-bar {
  grid-template-columns: minmax(0, 1fr) 96px !important;
  gap: 10px !important;
}

html[data-theme="archive-terminal"] body .bv-side-assist .bv-ai-inputbar.bv-action-bar > button#bvAISend {
  width: 96px !important;
  min-width: 96px !important;
  max-width: 96px !important;
}

/* Narrow panel fallback */
@media (max-width: 560px) {
  html body .bv-side-assist .bv-ai-inputbar.bv-action-bar {
    grid-template-columns: minmax(0, 1fr) 82px !important;
    gap: 8px !important;
    padding: 12px !important;
  }

  html body .bv-side-assist .bv-ai-inputbar.bv-action-bar > button#bvAISend {
    width: 82px !important;
    min-width: 82px !important;
    max-width: 82px !important;
    padding: 0 10px !important;
  }
}
/* =========================================================
   AI INPUT BAR — FINAL BALANCED CONTROL ROW
   Input and SEND button same height, visually aligned.
========================================================= */

html body .bv-side-assist .bv-ai-inputbar.bv-action-bar {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) 150px !important;
  gap: 14px !important;
  align-items: stretch !important;

  width: 100% !important;
  max-width: 100% !important;
  padding: 16px 18px !important;
  margin: 0 !important;
  box-sizing: border-box !important;
}

html body .bv-side-assist .bv-ai-inputbar.bv-action-bar > input#bvAIInput {
  grid-column: 1 !important;
  width: 100% !important;
  min-width: 0 !important;
  height: 58px !important;
  min-height: 58px !important;
  max-height: 58px !important;
  margin: 0 !important;
  padding: 0 20px !important;
  box-sizing: border-box !important;
  align-self: stretch !important;
}

html body .bv-side-assist .bv-ai-inputbar.bv-action-bar > button#bvAISend {
  grid-column: 2 !important;
  width: 150px !important;
  min-width: 150px !important;
  max-width: 150px !important;
  height: 58px !important;
  min-height: 58px !important;
  max-height: 58px !important;
  margin: 0 !important;
  padding: 0 20px !important;
  box-sizing: border-box !important;
  align-self: stretch !important;

  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;

  white-space: nowrap !important;
  text-align: center !important;
}

/* Archive terminal: preserve same control geometry */
html[data-theme="archive-terminal"] body .bv-side-assist .bv-ai-inputbar.bv-action-bar {
  grid-template-columns: minmax(0, 1fr) 150px !important;
  gap: 14px !important;
}

html[data-theme="archive-terminal"] body .bv-side-assist .bv-ai-inputbar.bv-action-bar > button#bvAISend {
  width: 150px !important;
  min-width: 150px !important;
  max-width: 150px !important;
}

/* Narrow panel fallback */
@media (max-width: 560px) {
  html body .bv-side-assist .bv-ai-inputbar.bv-action-bar {
    grid-template-columns: minmax(0, 1fr) 112px !important;
    gap: 10px !important;
    padding: 14px !important;
  }

  html body .bv-side-assist .bv-ai-inputbar.bv-action-bar > input#bvAIInput,
  html body .bv-side-assist .bv-ai-inputbar.bv-action-bar > button#bvAISend {
    height: 54px !important;
    min-height: 54px !important;
    max-height: 54px !important;
  }

  html body .bv-side-assist .bv-ai-inputbar.bv-action-bar > button#bvAISend {
    width: 112px !important;
    min-width: 112px !important;
    max-width: 112px !important;
    padding: 0 14px !important;
  }
}
/* =========================================================
   TOP NAV STABILITY
   Prevent battery animation from pushing Theme selector down.
========================================================= */

html body #mainNav {
  display: flex !important;
  align-items: center !important;
  flex-wrap: nowrap !important;
  gap: 10px !important;
}

/* Keep the wallet/battery widget width stable while balance animates */
html body #master-battery-btn,
html body .bv-wallet-widget {
  flex: 0 0 auto !important;
  width: 150px !important;
  min-width: 150px !important;
  max-width: 150px !important;
  box-sizing: border-box !important;
  overflow: hidden !important;
}

/* Prevent credit number text from expanding/collapsing the nav */
html body .bv-wallet-text {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: flex-start !important;
  min-width: 74px !important;
  max-width: 74px !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  font-variant-numeric: tabular-nums !important;
}

/* Keep the battery body itself fixed */
html body .bv-battery {
  flex: 0 0 52px !important;
  width: 52px !important;
  min-width: 52px !important;
  max-width: 52px !important;
}

/* Keep logout/userbar stable */
html body #bv-auth-userbar {
  flex: 0 0 auto !important;
  max-width: 280px !important;
  min-width: 0 !important;
}

/* Keep the theme selector block from dropping down */
html body #mainNav > div:last-child {
  flex: 0 0 auto !important;
  white-space: nowrap !important;
}

/* Smaller screens can wrap only when truly needed */
@media (max-width: 900px) {
  html body #mainNav {
    flex-wrap: wrap !important;
  }

  html body #master-battery-btn,
  html body .bv-wallet-widget {
    width: 140px !important;
    min-width: 140px !important;
    max-width: 140px !important;
  }
}
/* =========================================================
   WALLET HOVER EXPAND — NO NAV LAYOUT SHIFT
   Battery stays locked in the nav, but expands visually on hover.
========================================================= */

html body #master-battery-btn.bv-wallet-widget {
  position: relative !important;
  flex: 0 0 92px !important;
  width: 92px !important;
  min-width: 92px !important;
  max-width: 92px !important;
  height: 38px !important;

  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;

  overflow: visible !important;
  z-index: 30 !important;
}

/* The battery itself remains stable */
html body #master-battery-btn .bv-battery {
  flex: 0 0 58px !important;
  width: 58px !important;
  min-width: 58px !important;
  max-width: 58px !important;
}

/* Hide credit text by default without removing it */
html body #master-battery-btn .bv-wallet-text {
  position: absolute !important;
  right: 0 !important;
  top: 50% !important;
  transform: translateY(-50%) translateX(12px) scaleX(0.92) !important;

  opacity: 0 !important;
  pointer-events: none !important;

  min-width: 96px !important;
  max-width: 140px !important;
  white-space: nowrap !important;

  background: var(--bv-bg-panel, #fff) !important;
  color: var(--bv-text-main, #111) !important;
  border: 1px solid var(--bv-border-main, rgba(0,0,0,.2)) !important;
  border-radius: 10px !important;
  padding: 7px 10px !important;
  box-shadow: 0 10px 24px rgba(0,0,0,.18) !important;

  transition:
    opacity 160ms ease,
    transform 160ms ease !important;
}

/* Fancy reveal on hover/focus, but no layout push */
html body #master-battery-btn:hover .bv-wallet-text,
html body #master-battery-btn:focus-within .bv-wallet-text {
  opacity: 1 !important;
  transform: translateY(-50%) translateX(108px) scaleX(1) !important;
}

/* Keep the liquid fill animation alive */
html body #master-battery-btn .bv-battery-level {
  transition: width 700ms ease, background-color 250ms ease !important;
}

/* Prevent the theme section from being pushed */
html body #mainNav {
  flex-wrap: nowrap !important;
  align-items: center !important;
}

html body #bv-auth-userbar {
  flex: 0 0 auto !important;
}

html body #themeSwitcher {
  min-width: 150px !important;
}


/* =========================================================
   C10 SYSTEM STATUS / DEBUG PANEL
========================================================= */

html body .bv-system-panel {
  margin-top: 18px !important;
}

html body .bv-system-summary {
  margin: 16px 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 14px !important;
  flex-wrap: wrap !important;
}

html body .bv-system-health {
  display: inline-flex !important;
  align-items: center !important;
  gap: 10px !important;
  padding: 10px 14px !important;
  border-radius: 999px !important;
  border: 1px solid rgba(148, 163, 184, 0.42) !important;
  background: rgba(15, 23, 42, 0.06) !important;
}

html body .bv-system-health span {
  opacity: 0.72 !important;
  font-size: 12px !important;
  text-transform: uppercase !important;
  letter-spacing: 0.08em !important;
}

html body .bv-system-health-ok strong {
  color: #16a34a !important;
}

html body .bv-system-health-attention strong {
  color: #f59e0b !important;
}

html body .bv-system-generated {
  font-size: 12px !important;
  color: var(--bv-text-subtle, rgba(148, 163, 184, 0.9)) !important;
}

html body .bv-system-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)) !important;
  gap: 14px !important;
  margin-top: 16px !important;
}

html body .bv-system-card {
  border: 1px solid rgba(148, 163, 184, 0.28) !important;
  border-radius: 16px !important;
  padding: 14px !important;
  background: rgba(255, 255, 255, 0.06) !important;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.08) !important;
  min-width: 0 !important;
}

html body .bv-system-card-title {
  margin-bottom: 10px !important;
  font-weight: 800 !important;
  text-transform: uppercase !important;
  letter-spacing: 0.06em !important;
  font-size: 12px !important;
  color: var(--bv-text-main, inherit) !important;
}

html body .bv-system-row {
  display: grid !important;
  grid-template-columns: minmax(90px, 0.82fr) minmax(0, 1.18fr) !important;
  gap: 10px !important;
  padding: 7px 0 !important;
  border-top: 1px solid rgba(148, 163, 184, 0.16) !important;
  font-size: 12px !important;
}

html body .bv-system-row span {
  color: var(--bv-text-subtle, rgba(148, 163, 184, 0.9)) !important;
}

html body .bv-system-row strong {
  min-width: 0 !important;
  overflow-wrap: anywhere !important;
  font-family: "Courier Prime", ui-monospace, SFMono-Regular, Menlo, monospace !important;
  font-weight: 700 !important;
}

html body .bv-system-raw {
  margin-top: 8px !important;
  max-height: 360px !important;
  overflow: auto !important;
  white-space: pre-wrap !important;
  border-radius: 14px !important;
  border: 1px solid rgba(148, 163, 184, 0.28) !important;
  background: rgba(2, 6, 23, 0.72) !important;
  color: #e2e8f0 !important;
  padding: 14px !important;
  font-size: 12px !important;
}


/* =========================================================
   C13 SESSION EXPIRED / UNAUTHORIZED UX
========================================================= */

html body .bv-session-expired-banner {
  display: none;
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 32px));
  z-index: 999999;
  pointer-events: none;
}

html body .bv-session-expired-card {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.96);
  color: #f8fafc;
  border: 1px solid rgba(248, 250, 252, 0.22);
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.32);
}

html body .bv-session-expired-title {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

html body .bv-session-expired-text {
  font-size: 13px;
  line-height: 1.35;
  opacity: 0.86;
}

html body .gatekeeper-overlay.bv-session-expired-open {
  display: flex !important;
}

html body #auth-error {
  white-space: pre-wrap;
}

@media (max-width: 640px) {
  html body .bv-session-expired-card {
    align-items: stretch;
    flex-direction: column;
  }

  html body .bv-session-expired-card .bv-btn {
    width: 100%;
  }
}


/* =========================================================
   C14 AUTO RESTORE PROMPT WHEN CLOUD > LOCAL
========================================================= */

html body .bv-system-summary-topline {
  width: 100% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 14px !important;
  flex-wrap: wrap !important;
}

html body .bv-cloud-restore-prompt {
  width: 100% !important;
  margin-top: 14px !important;
  padding: 16px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 16px !important;
  border-radius: 18px !important;
  border: 1px solid rgba(245, 158, 11, 0.38) !important;
  background: rgba(245, 158, 11, 0.10) !important;
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.08) !important;
}

html body .bv-cloud-restore-title {
  font-size: 13px !important;
  font-weight: 900 !important;
  text-transform: uppercase !important;
  letter-spacing: 0.08em !important;
  color: #b45309 !important;
  margin-bottom: 5px !important;
}

html body .bv-cloud-restore-text {
  font-size: 13px !important;
  line-height: 1.42 !important;
  color: var(--bv-text-main, inherit) !important;
  max-width: 760px !important;
}

html body .bv-cloud-restore-counts {
  margin-top: 6px !important;
  font-size: 12px !important;
  color: var(--bv-text-subtle, rgba(100, 116, 139, 0.95)) !important;
  font-family: "Courier Prime", ui-monospace, SFMono-Regular, Menlo, monospace !important;
}

html body .bv-cloud-restore-prompt.is-restoring {
  opacity: 0.72 !important;
  pointer-events: none !important;
}

@media (max-width: 720px) {
  html body .bv-cloud-restore-prompt {
    align-items: stretch !important;
    flex-direction: column !important;
  }

  html body .bv-cloud-restore-prompt .bv-btn {
    width: 100% !important;
  }
}


/* =========================================================
   C18 CLEAN RESTORE STATUS FORMATTING
========================================================= */

html body .bv-restore-status-clean {
  white-space: pre-line !important;
  display: block !important;
  margin-top: 10px !important;
  line-height: 1.55 !important;
  font-family: "Courier Prime", ui-monospace, SFMono-Regular, Menlo, monospace !important;
  font-size: 12px !important;
  color: var(--bv-text-main, inherit) !important;
}


/* =========================================================
   C21 PRODUCTION READINESS POLISH
========================================================= */

html body .bv-system-card:first-child {
  border-color: rgba(34, 197, 94, 0.28) !important;
  background: rgba(34, 197, 94, 0.055) !important;
}

html body .bv-system-card strong {
  text-transform: none !important;
}


/* =========================================================
   C23 SNAPSHOT IMPORT SUMMARY
========================================================= */
html body .bv-snapshot-import-summary {
  white-space: pre-wrap !important;
  margin: 0 !important;
  padding: 12px 14px !important;
  border-radius: 12px !important;
  border: 1px solid var(--bv-border-subtle, rgba(148, 163, 184, 0.32)) !important;
  background: rgba(15, 23, 42, 0.08) !important;
  color: var(--bv-text-main, inherit) !important;
  font-family: "Courier Prime", monospace !important;
  font-size: 12px !important;
  line-height: 1.5 !important;
}

/* =========================================================
   C25: Account / Credits / Payment Status Panel
========================================================= */
.bv-account-panel-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(8px);
}

.bv-account-panel-overlay.is-active {
  display: flex;
}

.bv-account-panel {
  width: min(760px, 96vw);
  max-height: 88vh;
  overflow: auto;
  border: 1px solid var(--bv-border-main, rgba(255,255,255,0.16));
  border-radius: 18px;
  background: var(--bv-bg-panel, #111827);
  color: var(--bv-text-main, #f8fafc);
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.45);
  padding: 22px;
}

.bv-account-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.bv-account-panel h2 {
  margin: 2px 0 0;
}

.bv-account-kicker,
.bv-account-label {
  font-family: 'Courier Prime', monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bv-text-subtle, rgba(255,255,255,0.62));
}

.bv-account-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.bv-account-card {
  border: 1px solid var(--bv-border-subtle, rgba(255,255,255,0.12));
  border-radius: 14px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.045);
}

.bv-account-value {
  margin-top: 8px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
}

.bv-account-banner {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.16);
  font-size: 13px;
  line-height: 1.45;
}

.bv-account-banner--success {
  background: rgba(46, 204, 113, 0.13);
}

.bv-account-banner--cancelled {
  background: rgba(255, 193, 7, 0.13);
}

.bv-account-help,
.bv-account-support {
  margin-top: 14px;
  padding: 13px 14px;
  border-radius: 12px;
  background: rgba(110, 191, 252, 0.08);
  border: 1px solid rgba(110, 191, 252, 0.18);
  color: var(--bv-text-main, #f8fafc);
  font-size: 13px;
  line-height: 1.5;
}

.bv-account-help code {
  font-family: 'Courier Prime', monospace;
  font-size: 12px;
}

.bv-account-actions {
  margin-top: 16px;
}

@media (max-width: 720px) {
  .bv-account-grid {
    grid-template-columns: 1fr;
  }

  #bvAccountStatusBtn {
    padding-left: 10px;
    padding-right: 10px;
  }
}

/* =========================================================
   C26: Cleaner pre-login protected fetch suppression
========================================================= */
body.bv-prelogin-fetch-guarded #auth-error:empty::after {
  content: "Protected app data will load after login.";
  display: block;
  margin-top: 8px;
  color: var(--bv-text-subtle, rgba(255,255,255,0.62));
  font-size: 12px;
  line-height: 1.4;
}

/* =========================================================
   C27: Book card metadata editor polish
========================================================= */
#bookList.bv-c27-book-list {
  display: block;
  margin-top: 18px;
}

.bv-c27-book-card {
  position: relative;
  isolation: isolate;
  display: grid !important;
  grid-template-columns: 88px minmax(0, 1fr) auto !important;
  align-items: center !important;
  gap: 14px !important;
  width: 100%;
  min-height: 86px;
  margin: 10px 0 !important;
  padding: 12px 14px !important;
  border: 1px solid var(--bv-border-subtle, rgba(255,255,255,0.14)) !important;
  border-radius: 16px !important;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.075), rgba(255,255,255,0.025)) !important;
  box-shadow: 0 10px 28px rgba(0,0,0,0.10);
  overflow: visible !important;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.bv-c27-book-card:hover {
  transform: translateY(-1px);
  border-color: rgba(90, 125, 255, 0.35) !important;
  box-shadow: 0 14px 34px rgba(0,0,0,0.16);
}

.bv-c27-book-card.bv-c27-needs-review::before {
  content: "Needs metadata";
  position: absolute;
  top: -9px;
  left: 108px;
  z-index: 2;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 193, 7, 0.16);
  border: 1px solid rgba(255, 193, 7, 0.28);
  color: var(--bv-text-main, #111827);
  font-family: 'Courier Prime', monospace;
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.bv-c27-book-card.bv-c27-editing,
.bv-c27-book-card.bv-c27-editing-pending {
  border-color: rgba(69, 116, 255, 0.55) !important;
  box-shadow: 0 0 0 4px rgba(69, 116, 255, 0.10), 0 14px 34px rgba(0,0,0,0.16);
}

.bv-c27-book-card.bv-c27-saving::after {
  content: "Saving metadata…";
  position: absolute;
  right: 14px;
  bottom: -10px;
  z-index: 3;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(46, 204, 113, 0.16);
  border: 1px solid rgba(46, 204, 113, 0.28);
  font-family: 'Courier Prime', monospace;
  font-size: 10px;
}

.bv-c27-thumb {
  width: 76px !important;
  height: 62px !important;
  object-fit: cover !important;
  border-radius: 10px !important;
  border: 1px solid rgba(0,0,0,0.12) !important;
  background:
    linear-gradient(135deg, rgba(69, 116, 255, 0.12), rgba(255,255,255,0.10)) !important;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18);
}

.bv-c27-thumb-broken {
  opacity: 0.42;
  filter: grayscale(1);
}

.bv-c27-thumb-broken::after {
  content: "PDF";
}

.bv-c27-book-card .bv-btn,
.bv-c27-book-card button {
  min-height: 38px;
  white-space: nowrap;
}

.bv-c27-book-card .bv-c27-btn-open {
  font-weight: 700;
}

.bv-c27-book-card .bv-c27-btn-delete {
  opacity: 0.86;
}

.bv-c27-book-card .bv-c27-btn-delete:hover {
  border-color: rgba(255, 92, 92, 0.45) !important;
}

.bv-c27-select-box {
  width: 18px !important;
  height: 18px !important;
  accent-color: #4574ff;
  cursor: pointer;
}

.bv-c27-meta-input {
  min-height: 38px !important;
  border-radius: 10px !important;
  margin: 4px 4px 4px 0 !important;
}

#bookList .bv-c27-book-card strong,
#bookList .bv-c27-book-card b {
  font-size: 15px;
  line-height: 1.25;
}

#bookList .bv-c27-book-card small,
#bookList .bv-c27-book-card .section-subtitle,
#bookList .bv-c27-book-card .bv-subtle {
  opacity: 0.78;
}

@media (max-width: 900px) {
  .bv-c27-book-card {
    grid-template-columns: 64px minmax(0, 1fr) !important;
  }

  .bv-c27-thumb {
    width: 58px !important;
    height: 72px !important;
  }

  .bv-c27-book-card .bv-action-bar,
  .bv-c27-book-card > div:last-child {
    grid-column: 1 / -1;
  }
}

/* =========================================================
   C28: Non-alert Toast UI
========================================================= */
.bv-toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}

.bv-toast {
  pointer-events: auto;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 28px;
  gap: 10px;
  align-items: start;
  width: 100%;
  padding: 13px 12px;
  border-radius: 16px;
  border: 1px solid var(--bv-border-main, rgba(255,255,255,0.16));
  background:
    linear-gradient(135deg, rgba(20, 24, 35, 0.96), rgba(17, 24, 39, 0.94));
  color: #f8fafc;
  box-shadow: 0 18px 52px rgba(0,0,0,0.34);
  opacity: 0;
  transform: translateY(10px) scale(0.985);
  transition: opacity 0.18s ease, transform 0.18s ease;
  backdrop-filter: blur(12px);
}

.bv-toast.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.bv-toast.is-leaving {
  opacity: 0;
  transform: translateY(8px) scale(0.985);
}

.bv-toast-icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  font-family: 'Courier Prime', monospace;
  font-weight: 700;
  background: rgba(110, 191, 252, 0.16);
  border: 1px solid rgba(110, 191, 252, 0.28);
}

.bv-toast-title {
  font-family: 'Courier Prime', monospace;
  font-size: 11px;
  line-height: 1.2;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(248, 250, 252, 0.72);
  margin-bottom: 4px;
}

.bv-toast-message {
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}

.bv-toast-close {
  appearance: none;
  border: 0;
  background: transparent;
  color: rgba(248, 250, 252, 0.72);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  padding: 0;
  width: 26px;
  height: 26px;
  border-radius: 999px;
}

.bv-toast-close:hover {
  background: rgba(255,255,255,0.10);
  color: #ffffff;
}

.bv-toast--success .bv-toast-icon {
  background: rgba(46, 204, 113, 0.18);
  border-color: rgba(46, 204, 113, 0.34);
}

.bv-toast--error .bv-toast-icon {
  background: rgba(255, 92, 92, 0.20);
  border-color: rgba(255, 92, 92, 0.38);
}

.bv-toast--warning .bv-toast-icon {
  background: rgba(255, 193, 7, 0.20);
  border-color: rgba(255, 193, 7, 0.38);
}

.bv-toast--loading .bv-toast-icon {
  background: rgba(160, 174, 192, 0.18);
  border-color: rgba(160, 174, 192, 0.34);
}

@media (max-width: 720px) {
  .bv-toast-region {
    right: 12px;
    bottom: 12px;
    width: calc(100vw - 24px);
  }

  .bv-toast {
    grid-template-columns: 30px minmax(0, 1fr) 26px;
    border-radius: 14px;
  }
}
