/* =====================================================================
   BookSwapper reskin — modern refresh (additive layer, Phase 1)
   ---------------------------------------------------------------------
   RULES FOR THIS FILE (keep the reskin safe):
   - Only ADD styles here. Never edit style.css / cozy-layout.css / card-*.css.
   - This file loads AFTER style.css and the shell <style> block, so equal
     specificity wins. No !important except where noted.
   - All JS hooks (common.js, card-*.js, messages.html, add/edit-book.html)
     keep working: no selector renames, only visual overrides.
   - i18n untouched: bottom tabs reuse existing keys
     (nav.home, common.search, nav.addBook, nav.messages, nav.myProfile).
   ===================================================================== */

:root {
  --bs-brand: #8a5a2b;
  --bs-brand-dark: #744a22;
  --bs-brand-soft: rgba(138, 90, 43, 0.14);
  --bs-ink: #2b1f14;
  --bs-ink-soft: #3d2c1c;
  --bs-bg: #efe7d6;
  --bs-card: #ffffff;
  --bs-text: #2b1f14;
  --bs-muted: #7a6450;
  --bs-border: #e0d3b8;
  --bs-radius: 14px;
  --bs-radius-sm: 10px;
  --bs-shadow-card: 0 1px 2px rgba(22, 29, 18, 0.06), 0 4px 14px rgba(22, 29, 18, 0.06);
  --bs-tabbar-h: 62px;
  --bs-tab-idle: rgba(240, 240, 240, 0.62);
  --bs-tab-active: #e0a84f; /* warm amber, readable on black */
  --bs-sat: env(safe-area-inset-top, 0px);
  --bs-sab: env(safe-area-inset-bottom, 0px);
}

/* ---------- Top navbar: black + notch padding ----- */
.navbar {
  background-color: #000;
  padding-top: var(--bs-sat);
}

.brand-logo .brand-text {
  letter-spacing: -0.3px;
}

/* Active top-nav link gets a brand underline (progressive enhancement) */
.nav-list a.active-nav {
  box-shadow: inset 0 -3px 0 var(--bs-brand);
}

/* ---------- Shell: make room for notch + bottom tab bar -------------- */
/* NOTE: shell <style> sets #content-frame height/margin with equal
   specificity; these win because reskin.css loads later. */
#content-frame {
  margin-top: calc(48px + var(--bs-sat));
  height: calc(100dvh - 48px - var(--bs-sat));
  background: var(--bs-bg);
}

/* ---------- Top bar (mobile): logo + global search, always visible ----
   Critical geometry (fixed position, heights, iframe offsets) ALSO lives
   in index.html inline <style>; this file adds cosmetics on identical
   values, so layout survives any reskin staleness. */
:root {
  --bs-topbar-h: 56px;
}

.bs-topbar {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 1000;
  display: none; /* mobile only; enabled in media query below */
  background: #000;
  box-sizing: border-box;
  min-height: var(--bs-topbar-h);
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  padding-top: calc(6px + var(--bs-sat));
  border-bottom: 1px solid #222;
}

/* Bottom chrome (mobile): tab bar only */
.bs-bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: none; /* mobile only; enabled in media query below */
  background: #000;
  padding-bottom: var(--bs-sab);
}

/* Big logo on the left; full wordmark at rest. While suggestions are open
   the logo yields entirely — search goes full width so the hint fits.
   Driven by the search bar's own open state (not focus), so every close
   path restores it deterministically. Pure CSS. */
.bs-top-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  color: #f0f0f0;
  text-decoration: none;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  -webkit-tap-highlight-color: transparent;
}

.bs-top-logo img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
}

.bs-top-logo span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 132px;
}

.bs-topbar:has(.navbar-search-bar.has-dropdown) .bs-top-logo {
  display: none;
}

.bs-top-searchslot {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Dismiss affordance (Reddit-style): first element inside the search bar,
   visible only while suggestions are open on mobile. The .bs-topbar
   ancestor gate keeps desktop untouched (there the form lives in .navbar).
   Lives in the shared node, so no mover changes needed. */
#bs-top-back {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  flex-shrink: 0;
  background: none;
  border: 0;
  color: #f0f0f0;
  cursor: pointer;
  border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
}

#bs-top-back:active {
  background: rgba(255, 255, 255, 0.1);
}

#bs-top-back svg {
  width: 20px;
  height: 20px;
}

.bs-topbar .navbar-search-bar.has-dropdown #bs-top-back {
  display: inline-flex;
}

/* Neutralize the navbar-anchored mobile search rules for the moved node */
.bs-topbar .navbar-search {
  position: static;
  max-width: none;
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
  width: 100%;
  flex: 1;
  min-width: 0;
}

/* Dropdown opens DOWNWARD below the top bar, all black to read as one
   sheet with it. Higher specificity than both the base
   (.navbar-search-dropdown) and mobile (fixed top:92px) rules, so no
   !important is needed. Scanner modal is a fixed overlay; unaffected. */
.bs-topbar .navbar-search-dropdown {
  position: fixed;
  top: calc(var(--bs-topbar-h) + var(--bs-sat));
  bottom: auto;
  left: 12px;
  right: 12px;
  width: auto;
  transform: none;
  min-width: 0;
  max-height: calc(100dvh - var(--bs-topbar-h) - var(--bs-tabbar-h) - var(--bs-sat) - var(--bs-sab) - 24px);
  background: #000;
  border: 1px solid #222;
  border-top: none;
  border-radius: 0 0 16px 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  padding-bottom: 12px;
}

/* Bar attaches above the downward dropdown: square bottom, round top.
   Same black as the top bar so open search reads as one sheet. */
.bs-topbar .navbar-search-bar.has-dropdown {
  border-radius: 24px 24px 0 0;
  border-bottom: none;
  border-top: 1px solid #222;
  background: #000;
  border-color: #222;
}

.bs-topbar .navbar-search-bar.has-dropdown .navbar-search-btn {
  border-top-right-radius: 24px;
  border-bottom-right-radius: 0;
}

.bs-tabbar {
  background: transparent;
  border-top: 1px solid #222;
}

/* Tab bar hidden while the virtual keyboard is open (toggled by shell JS) */
body.bs-kb-open .bs-tabbar {
  display: none;
}

.bs-tabbar-inner {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: var(--bs-tabbar-h);
  max-width: 640px;
  margin: 0 auto;
}

/* No double-tap-zoom delay on chrome controls (companion to bsStopFling) */
.bs-tabbar a,
.bs-tabbar button,
.bs-topbar a,
.bs-topbar button {
  touch-action: manipulation;
}

.bs-tabbar a,
.bs-tabbar button.bs-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--bs-tab-idle);
  text-decoration: none;
  background: none;
  border: 0;
  font-size: 0.68rem;
  font-weight: 600;
  font-family: inherit;
  text-align: center;
  min-height: 44px; /* touch target */
  cursor: pointer;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.bs-tabbar a svg,
.bs-tabbar button.bs-tab svg {
  width: 22px;
  height: 22px;
}

.bs-tabbar a.active,
.bs-tabbar button.bs-tab.active {
  color: var(--bs-tab-active);
}

.bs-tabbar a.active svg,
.bs-tabbar button.bs-tab.active svg {
  stroke: var(--bs-tab-active);
}

/* Account tab photo (mirrors the old navbar avatar when logged in) */
#bs-account-avatar-img {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

#bs-account-avatar-img[hidden] {
  display: none;
}

.bs-tabbar #bs-account-btn.active #bs-account-avatar-img {
  box-shadow: 0 0 0 2px var(--bs-tab-active);
}

/* Center Add action: the old brown-gradient button (matches .nav-item
   a[href*="add-book"] in style.css), sized to clear the search dock */
.bs-tabbar .bs-fab {
  color: #fff;
}

.bs-tabbar .bs-fab svg {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #75420e 0%, #553b08 100%);
  stroke: #fff;
  padding: 9px;
  box-sizing: border-box;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
}

.bs-tabbar .bs-fab.active {
  color: #fff;
}

.bs-tabbar .bs-fab.active svg {
  stroke: #fff;
}

/* Tab badges: mirrored from the (hidden-on-mobile) top navbar badges */
.bs-tab-badge {
  position: absolute;
  top: 5px;
  right: calc(50% - 22px);
  background: #b42318;
  color: #fff;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  padding: 0 4px;
}

.bs-tab-dot {
  position: absolute;
  top: 9px;
  right: calc(50% - 16px);
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #b42318;
}

/* 7-tab crowding guard: labels truncate instead of wrapping; icons only
   on very narrow screens (<=380px). Badge/dot spans carry no data-i18n,
   so they are unaffected. */
.bs-tabbar-inner > * {
  min-width: 0;
}

.bs-tabbar .bs-tab span[data-i18n] {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

@media screen and (max-width: 380px) {
  .bs-tabbar .bs-tab span[data-i18n] {
    display: block;
    font-size: 0.6rem;
  }
}

/* ---------- Account bottom sheet (mobile) ------------------------------ */
.bs-sheet-overlay[hidden],
.bs-sheet[hidden] {
  display: none;
}

.bs-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1001;
}

.bs-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1002;
  background: #000;
  color: #f0f0f0;
  border-radius: 20px 20px 0 0;
  max-height: 82dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 8px 0 calc(12px + var(--bs-sab));
}

/* Static top block: handle + identity + close. Never scrolls, so the
   header cannot drift or let rows bleed above it (replaces sticky). */
.bs-sheet-top {
  flex-shrink: 0;
  padding-bottom: 6px;
}

/* The only scroller in the sheet (min-height:0 is load-bearing for
   flex-child scrolling). */
.bs-sheet-scroll {
  overflow-y: auto;
  min-height: 0;
}

.bs-sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
  margin: 4px auto 8px;
}

.bs-sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 8px 0 16px;
  font-weight: 800;
}

.bs-sheet-identity {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  color: #f0f0f0;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

#bs-sheet-username {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Avatar slot mirrors .profile-avatar in style.css (circle, ring) */
.bs-sheet-avatar {
  width: 40px;
  height: 40px;
  background-color: #444;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.bs-sheet-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  border: 1px solid #857768;
  box-sizing: border-box;
}

.bs-sheet-close {
  border: 0;
  background: none;
  font-size: 1.5rem;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
  color: rgba(240, 240, 240, 0.7);
}

.bs-sheet-section {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(240, 240, 240, 0.55);
  padding: 10px 16px 2px;
}

.bs-sheet-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  box-sizing: border-box;
  padding: 12px 16px;
  min-height: 52px;
  color: #f0f0f0;
  text-decoration: none;
  background: none;
  border: 0;
  font-size: 0.95rem;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: var(--bs-radius-sm);
  -webkit-tap-highlight-color: transparent;
}

.bs-sheet-row:active {
  background: rgba(143, 209, 79, 0.18);
}

.bs-sheet-row svg {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

/* Navigation affordance: chevron on every row except the Logout action */
.bs-sheet-row:not(#bs-logout-btn)::after {
  content: "";
  width: 9px;
  height: 9px;
  border-top: 2px solid rgba(240, 240, 240, 0.4);
  border-right: 2px solid rgba(240, 240, 240, 0.4);
  transform: rotate(45deg);
  margin-left: auto;
  flex-shrink: 0;
}

/* Destructive Logout action */
#bs-logout-btn {
  color: #ff6b61;
}

/* Red dot overlays the row icon's top corner (mirrors the tab badge):
   out of flow, so the chevron keeps its own margin-left:auto untouched.
   inset-inline-start tracks the icon side in RTL. */
.bs-sheet-row:has(.bs-row-dot) {
  position: relative;
}

.bs-row-dot {
  position: absolute;
  inset-inline-start: 12px;
  top: 9px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #b42318;
  flex-shrink: 0;
}

.bs-row-dot[hidden] {
  display: none;
}

/* Bottom-chrome auth gating (data-gate, owned by the shell script).
   Deliberately NOT .logged-in-only/.guest-only: setupNavbar() writes inline
   display:block on those classes, which would break these flex layouts. */
[data-gate].bs-off {
  display: none;
}

.bs-sheet-divider {
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  margin: 6px 16px;
}

@media screen and (max-width: 768px) {
  /* Top navbar fully retired on mobile; bottom chrome owns navigation */
  .navbar {
    display: none;
  }

  .bs-bottom {
    display: block;
  }

  .bs-topbar {
    display: flex;
  }

  /* Mobile shell: iframe sits below the fixed top bar (notch-aware) and
     above the bottom tab bar + home-indicator area. (Same values as the
     inline <style> in index.html — duplicated, not derived.) */
  #content-frame {
    margin-top: calc(var(--bs-topbar-h) + var(--bs-sat));
    height: calc(100dvh - var(--bs-topbar-h) - var(--bs-tabbar-h) - var(--bs-sat) - var(--bs-sab));
  }
}

/* Very narrow screens: tighten chrome so logo text + search both fit */
@media screen and (max-width: 380px) {
  .bs-top-logo {
    font-size: 0.95rem;
  }
  .bs-topbar {
    gap: 8px;
    padding-left: 10px;
    padding-right: 10px;
  }
}

@media screen and (min-width: 769px) {
  .bs-bottom,
  .bs-topbar,
  .bs-sheet,
  .bs-sheet-overlay {
    display: none;
  }
}

/* ---------- Modern-refresh card polish -------------------------------- */
.card-new {
  border-radius: var(--bs-radius);
  box-shadow: var(--bs-shadow-card);
  border: 1px solid var(--bs-border);
  overflow: hidden;
}

.card-lite {
  border-radius: var(--bs-radius-sm);
  box-shadow: var(--bs-shadow-card);
}

/* Friendlier filter chips / bubbles (cozy layout + listing pages) */
.filter-chip,
.filter-bubble-btn,
.chip {
  border-radius: 999px;
}

/* Primary actions in brand green (additive: only elements that opt in
   via .bs-btn-primary keep working with old handlers) */
.bs-btn-primary {
  background: var(--bs-brand);
  color: #fff;
  border: 0;
  border-radius: var(--bs-radius-sm);
  padding: 0.65rem 1.1rem;
  font-weight: 700;
  min-height: 44px;
  cursor: pointer;
}

.bs-btn-primary:active {
  background: var(--bs-brand-dark);
}

/* ---------- Mobile input zoom guard (iOS zooms <16px inputs) ---------- */
@media screen and (max-width: 768px) {
  input,
  select,
  textarea {
    font-size: 16px;
  }
}
