/* Mobile bottom navigation, More sheet and the filters/contents sheet.
   Markup comes from js/myjs/bottom-nav.js; shared by index.html and the doctrines page,
   so this file must not depend on style.css. */

.bnav,
.bnav-sheet {
  --bnav-bg: #fff;
  --bnav-text: #343d4a;
  --bnav-muted: #6c757d;
  --bnav-accent: #8230b1;
  --bnav-pill: rgba(130, 48, 177, 0.12);
  --bnav-hover: #f3eef7;
  --bnav-border: #e5e7eb;
}
body.dark-mode .bnav,
body.dark-mode .bnav-sheet {
  --bnav-bg: #252525;
  --bnav-text: #e8e5e0;
  --bnav-muted: #9a9aa0;
  --bnav-accent: #c79be6;
  --bnav-pill: rgba(199, 155, 230, 0.16);
  --bnav-hover: #2f2f2f;
  --bnav-border: #333;
}

.bnav,
.bnav-backdrop,
.bnav-sheet,
#secondaryNavContent .sheet-head,
#btnSearchSettings,
#reading-toolbar .rt-mobile-only {
  display: none;
}

@media screen and (max-width: 800px) {
  /* ---- Bottom bar ---- */
  .bnav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1050;
    height: calc(58px + env(safe-area-inset-bottom));
    padding: 0 4px env(safe-area-inset-bottom);
    background: var(--bnav-bg);
    border-top: 1px solid var(--bnav-border);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
    font-family: inherit;
  }
  .bnav-item {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--bnav-muted);
    font: inherit;
    font-size: 11px;
    line-height: 1.2;
    text-decoration: none !important;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .bnav-item svg {
    width: 44px;
    height: 26px;
    padding: 2px 10px;
    border-radius: 13px;
    flex-shrink: 0;
    transition: background-color 0.15s ease;
  }
  .bnav-item span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .bnav-item.active,
  .bnav-item[aria-expanded="true"] {
    color: var(--bnav-accent);
    font-weight: 600;
  }
  .bnav-item.active svg,
  .bnav-item[aria-expanded="true"] svg {
    background: var(--bnav-pill);
  }
  body.bnav-more-open .bnav-item.active:not([aria-expanded]) {
    color: var(--bnav-muted);
    font-weight: normal;
  }
  body.bnav-more-open .bnav-item.active:not([aria-expanded]) svg {
    background: none;
  }

  /* Content must clear the bar on the doctrines page (index pads #regionBodyInner itself). */
  body.doctrines-page,
  body.mcp-page {
    padding-bottom: calc(66px + env(safe-area-inset-bottom));
  }

  /* ---- More sheet ---- */
  .bnav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1045;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
  }
  body.bnav-more-open .bnav-backdrop {
    opacity: 1;
    visibility: visible;
  }
  .bnav-sheet {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(58px + env(safe-area-inset-bottom));
    z-index: 1048;
    max-height: calc(100vh - 140px);
    overflow-y: auto;
    background: var(--bnav-bg);
    color: var(--bnav-text);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.18);
    padding: 6px 0 8px;
    transform: translateY(calc(100% + 70px));
    visibility: hidden;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.25s;
  }
  body.bnav-more-open .bnav-sheet {
    transform: none;
    visibility: visible;
  }
  .bnav-sheet-grip,
  #secondaryNavContent .sheet-grip {
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 2px;
    margin: 4px auto 8px;
    background: var(--bnav-border, #d6dbe1);
  }
  .bnav-sheet-list {
    list-style: none;
    margin: 0;
    padding: 0;
  }
  .bnav-sheet-list a,
  .bnav-sheet-list button {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    min-height: 52px;
    padding: 8px 20px;
    border: 0;
    background: none;
    color: var(--bnav-text);
    font: inherit;
    font-size: 15px;
    text-align: left;
    text-decoration: none !important;
    cursor: pointer;
  }
  .bnav-sheet-list a:active,
  .bnav-sheet-list button:active {
    background: var(--bnav-hover);
  }
  .bnav-sheet-list svg {
    flex-shrink: 0;
    color: var(--bnav-muted);
  }
  .bnav-sheet-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }
  .bnav-sheet-text small {
    color: var(--bnav-muted);
    font-size: 12px;
  }

  /* ---- Filters / contents: the side panel becomes a bottom sheet ---- */
  #regionMain #secondaryNavContent {
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: none !important;
    height: auto !important;
    max-height: 82vh;
    max-height: 82dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0 0 env(safe-area-inset-bottom) !important;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.2) !important;
    transform: translateY(100%);
    visibility: hidden;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.28s !important;
    z-index: 1060;
  }
  body.showSideMenu #regionMain #secondaryNavContent {
    transform: none !important;
    visibility: visible;
  }
  #regionMain #secondaryNavContent #sidebarInner {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    width: 100% !important;
    float: none !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  #secondaryNavContent .sheet-head {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    position: relative;
    flex-shrink: 0;
    min-height: 40px;
    padding: 4px 8px 0;
  }
  #secondaryNavContent .sheet-grip {
    position: absolute;
    left: 50%;
    top: 4px;
    margin: 4px 0 0 -18px;
  }
  #secondaryNavContent .sheet-close {
    border: 0;
    background: none;
    color: #8230b1;
    font: inherit;
    font-weight: 600;
    padding: 6px 10px;
    cursor: pointer;
  }
  body.dark-mode #secondaryNavContent .sheet-close {
    color: #c79be6;
  }
  body.dark-mode #secondaryNavContent .sheet-grip {
    background: #444;
  }
  /* The headings in the panel are sticky for the desktop sidebar; the sheet has its own head. */
  #regionMain #secondaryNavContent h1 {
    position: static;
  }

  /* ---- Search settings button next to the search box ---- */
  #search-form #btnSearchSettings {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
    width: 40px;
    margin: 0 4px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: none;
    color: #4b5563;
    cursor: pointer;
  }
  #search-form #btnSearchSettings[aria-expanded="true"] {
    background: rgba(130, 48, 177, 0.12);
    color: #8230b1;
  }
  #btnSearchSettings .filters-count {
    position: absolute;
    top: 2px;
    right: 1px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: #8230b1;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
  }
  #btnSearchSettings .filters-count[hidden] {
    display: none;
  }
  body.dark-mode #search-form #btnSearchSettings {
    color: #c8c4bd;
  }
  body.dark-mode #search-form #btnSearchSettings[aria-expanded="true"] {
    background: rgba(199, 155, 230, 0.16);
    color: #c79be6;
  }

  /* ---- Reading toolbar: contents instead of wide mode (see reading-toolbar.css) ---- */
  #reading-toolbar .rt-mobile-only {
    display: inline-flex;
  }
}

/* ---- Recent searches under the search box (phones) ---- */
.recent-searches[hidden] {
  display: none !important;
}
@media screen and (max-width: 800px) {
  #search-form {
    position: relative;
  }
  .recent-searches {
    position: absolute;
    top: 100%;
    left: 0.5rem;
    right: 0.5rem;
    z-index: 1040;
    max-height: 60vh;
    overflow-y: auto;
    margin-top: 4px;
    background: #fff;
    color: #343d4a;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  }
  .recent-searches-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 8px 4px 16px;
    color: #6c757d;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }
  .recent-searches-head button {
    border: 0;
    background: none;
    color: #8230b1;
    font: inherit;
    font-size: 13px;
    text-transform: none;
    letter-spacing: 0;
    padding: 4px 8px;
    cursor: pointer;
  }
  .recent-searches ul {
    list-style: none;
    margin: 0;
    padding: 0 0 4px;
  }
  .recent-searches li {
    display: flex;
    align-items: center;
  }
  .recent-searches li button {
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
  }
  .recent-searches li button[data-q] {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 6px 8px 6px 16px;
    text-align: left;
    font-size: 15px;
  }
  .recent-searches li button[data-q] svg {
    flex-shrink: 0;
    color: #9aa1ab;
  }
  .recent-searches li button[data-q] span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .recent-searches .recent-remove {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    color: #9aa1ab;
    font-size: 20px;
    line-height: 1;
  }
  .recent-searches li button:active {
    background: #f3eef7;
  }
  body.dark-mode .recent-searches {
    background: #252525;
    color: #e8e5e0;
    border-color: #333;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  }
  body.dark-mode .recent-searches-head button {
    color: #c79be6;
  }
  body.dark-mode .recent-searches li button:active {
    background: #2f2f2f;
  }
}

/* ---- Compact search settings panel (phones) ---- */
.search-settings[hidden] {
  display: none !important;
}
@media screen and (max-width: 800px) {
  .search-settings {
    position: absolute;
    top: 100%;
    left: 0.5rem;
    right: 0.5rem;
    z-index: 1041;
    max-height: calc(100vh - 160px);
    overflow-y: auto;
    margin-top: 4px;
    padding: 12px 14px 10px;
    background: #fff;
    color: #343d4a;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    font-size: 14px;
  }
  .search-settings .ss-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
  }
  .search-settings .ss-row-types {
    align-items: flex-start;
  }
  .search-settings .ss-label {
    flex: 0 0 44px;
    color: #6c757d;
    font-size: 12px;
    font-weight: 600;
  }
  .search-settings .ss-row-types .ss-label {
    padding-top: 6px;
  }
  .search-settings .ss-seg {
    flex: 1 1 auto;
    display: flex;
    gap: 3px;
    padding: 3px;
    border-radius: 9px;
    background: rgba(52, 61, 74, 0.08);
  }
  .search-settings .ss-seg button {
    flex: 1 1 0;
    padding: 5px 4px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
  }
  .search-settings .ss-seg button[aria-pressed="true"] {
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
    font-weight: 600;
  }
  .search-settings .ss-years {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .search-settings .ss-years input {
    width: 76px;
    padding: 5px 8px;
    border: 1px solid #d6dbe1;
    border-radius: 7px;
    background: #fff;
    color: inherit;
    font: inherit;
    font-size: 16px; /* no zoom-on-focus in iOS Safari */
  }
  .search-settings .ss-chips {
    flex: 1 1 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .search-settings .ss-chip {
    padding: 5px 10px;
    border: 1px solid #d6dbe1;
    border-radius: 999px;
    background: #fff;
    color: #6c757d;
    font: inherit;
    font-size: 13px;
    line-height: 1.2;
    cursor: pointer;
  }
  .search-settings .ss-chip[aria-pressed="true"] {
    border-color: transparent;
    background: rgba(130, 48, 177, 0.12);
    color: #6a2491;
    font-weight: 600;
  }
  .search-settings .ss-off .ss-chips {
    opacity: 0.45;
  }
  .search-settings .ss-note {
    margin: -4px 0 8px 54px;
    color: #6c757d;
    font-size: 12px;
  }
  .search-settings .ss-foot {
    display: flex;
    justify-content: space-between;
    padding-top: 8px;
    border-top: 1px solid #eef0f3;
  }
  .search-settings .ss-foot button {
    padding: 6px 4px;
    border: 0;
    background: none;
    color: #6c757d;
    font: inherit;
    cursor: pointer;
  }
  .search-settings .ss-foot .ss-done {
    color: #8230b1;
    font-weight: 600;
  }
  body.dark-mode .search-settings {
    background: #252525;
    color: #e8e5e0;
    border-color: #333;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  }
  body.dark-mode .search-settings .ss-seg {
    background: rgba(255, 255, 255, 0.07);
  }
  body.dark-mode .search-settings .ss-seg button[aria-pressed="true"] {
    background: #3a4150;
    color: #fff;
    box-shadow: none;
  }
  body.dark-mode .search-settings .ss-years input,
  body.dark-mode .search-settings .ss-chip {
    background: #2a2a2a;
    border-color: #3d3d3d;
    color: #c8c4bd;
  }
  body.dark-mode .search-settings .ss-chip[aria-pressed="true"] {
    border-color: transparent;
    background: rgba(199, 155, 230, 0.18);
    color: #e2c8f3;
  }
  body.dark-mode .search-settings .ss-foot {
    border-top-color: #333;
  }
  body.dark-mode .search-settings .ss-foot .ss-done {
    color: #c79be6;
  }
}

/* style.css darkens every "#search-form button:hover", and the hover sticks after a tap
   on touch screens; the dropdowns live inside #search-form, so keep their own colours. */
@media screen and (max-width: 800px) {
  #search-form .search-settings button:hover,
  #search-form .recent-searches button:hover {
    background-color: transparent;
  }
  #search-form .search-settings .ss-seg button[aria-pressed="true"]:hover,
  #search-form .search-settings .ss-chip:hover {
    background-color: #fff;
  }
  #search-form .search-settings .ss-chip[aria-pressed="true"]:hover {
    background-color: rgba(130, 48, 177, 0.12);
  }
  body.dark-mode #search-form .search-settings .ss-seg button[aria-pressed="true"]:hover {
    background-color: #3a4150;
  }
  body.dark-mode #search-form .search-settings .ss-chip:hover {
    background-color: #2a2a2a;
  }
  body.dark-mode #search-form .search-settings .ss-chip[aria-pressed="true"]:hover {
    background-color: rgba(199, 155, 230, 0.18);
  }
}
