/*
 * cubitdocs layout chrome. Loads AFTER cubitstyle.css so the source's
 * topic-body styles win. Scope new selectors to .cd-* to avoid stomping
 * on cubitstyle.css ownership of body content.
 */

:root {
  --cd-mobile-bar-h: 3.25rem;     /* top bar height when sidebar collapses */
  --cd-sidebar-w: 17.5rem;
  --cd-content-max-w: 60rem;      /* reading-column cap on .cd-topic */
  --cd-content-pad-x: 2rem;
  --cd-content-pad-y: 1.5rem;
  --cd-fg: #1a1a1a;
  --cd-fg-muted: #555;
  --cd-bg: #ffffff;
  --cd-bg-sidebar: #f6f7f9;
  --cd-border: #e3e4e6;
  --cd-accent: #0a64a8;
  --cd-accent-hover: #084c80;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--cd-bg);
  color: var(--cd-fg);
}

/* cubitstyle.css forces `body { position:absolute; top:1em; left:1em;
   width:500px; }` — sized for the legacy single-column layout. Reset it
   so our shell can use the full viewport. Body typography/colors from
   cubitstyle.css are inherited by .cd-topic descendants unaffected. */
body {
  position: static;
  top: auto;
  left: auto;
  width: auto;
}

/* Sidebar "top" groups the brand block, search trigger, and (mobile-only)
   the nav toggle. On desktop these stack vertically; on mobile this entire
   block pins to the top of the viewport as a horizontal bar with the TOC
   beneath it sliding away. */
.cd-sidebar-top {
  border-bottom: 1px solid var(--cd-border);
}

.cd-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 10px;
  text-decoration: none;
  color: var(--cd-fg);
}
.cd-brand-logo {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
}
.cd-brand-text {
  display: block;
  min-width: 0;
}
.cd-brand-name {
  display: block;
  font-weight: 600;
  font-size: 18px;
  line-height: 1.2;
  white-space: nowrap;
}
.cd-brand-version {
  display: block;
  font-size: 12px;
  color: var(--cd-fg-muted);
  margin-top: 2px;
}

/* Search trigger sits right under the brand. The trigger looks like a search
   input; clicking it (or hitting Cmd/Ctrl+K) opens the centered modal. Both
   engines (pagefind Component UI + minisearch) mount inside this slot. */
.cd-sidebar-search {
  padding: 0 12px 12px;
}

.cd-sidebar-search pagefind-modal-trigger {
  display: block;
  width: 100%;
}

/* MiniSearch trigger button. Styled to look like an input; the kbd hint sits
   on the right edge. */
.cd-sidebar-search .cd-search-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 6px 10px;
  font: inherit;
  text-align: left;
  color: var(--cd-fg-muted);
  background: var(--cd-bg);
  border: 1px solid var(--cd-border);
  border-radius: 6px;
  cursor: pointer;
}
.cd-sidebar-search .cd-search-trigger:hover {
  border-color: var(--cd-accent);
}
.cd-sidebar-search .cd-search-trigger kbd {
  font: 11px ui-monospace, monospace;
  background: var(--cd-bg-sidebar);
  border: 1px solid var(--cd-border);
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--cd-fg-muted);
}

/* MiniSearch modal: centered <dialog>, scrolls internally. */
dialog.cd-search-modal {
  width: min(720px, 92vw);
  max-height: 80vh;
  padding: 0;
  border: 1px solid var(--cd-border);
  border-radius: 10px;
  background: var(--cd-bg);
  color: var(--cd-fg);
  box-shadow: 0 12px 48px rgba(0,0,0,0.18);
}
dialog.cd-search-modal::backdrop {
  background: rgba(0,0,0,0.35);
}
.cd-search-modal-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--cd-border);
}
.cd-search-modal-header input {
  width: 100%;
  font: 16px / 1.4 inherit;
  padding: 8px 10px;
  border: 1px solid var(--cd-border);
  border-radius: 6px;
  background: var(--cd-bg);
  color: var(--cd-fg);
  outline: none;
}
.cd-search-modal-header input:focus {
  border-color: var(--cd-accent);
}
.cd-search-modal-body {
  max-height: calc(80vh - 110px);
  overflow-y: auto;
  padding: 6px 14px 12px;
}
.cd-search-status {
  font-size: 12px;
  color: var(--cd-fg-muted);
  padding: 6px 0;
}
.cd-search-results {
  list-style: none;
  margin: 0;
  padding: 0;
}
.cd-search-hit {
  border-radius: 6px;
  margin-bottom: 6px;
}
.cd-search-hit.cd-active,
.cd-search-hit:hover {
  background: var(--cd-bg-sidebar);
}
.cd-search-hit-card {
  display: flex;
  gap: 12px;
  padding: 10px;
  text-decoration: none;
  color: inherit;
  align-items: flex-start;
}
.cd-search-hit-img {
  flex: 0 0 64px;
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--cd-bg-sidebar);
}
.cd-search-hit-meta { min-width: 0; flex: 1; }
.cd-search-hit-title {
  font-weight: 600;
  color: var(--cd-accent);
}
.cd-search-hit-excerpt {
  font-size: 13px;
  color: var(--cd-fg-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.cd-search-subs {
  list-style: none;
  margin: 0 0 6px 0;
  padding: 0 12px 6px 86px;  /* line up with title (after the 64px thumb + gap) */
  font-size: 13px;
}
.cd-search-subs a {
  color: var(--cd-fg-muted);
  text-decoration: none;
}
.cd-search-subs a:hover { color: var(--cd-accent); }

/* Matched-term highlight inside search excerpts and sub-result headings.
   Browser default for <mark> is bright yellow; tone down to the accent at
   low alpha so it reads as emphasis, not a warning. */
.cd-search-results mark {
  background: rgba(10, 100, 168, 0.18);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

.cd-toggle-sidebar {
  display: none;        /* desktop hides it — TOC is always open */
  background: transparent;
  border: 1px solid var(--cd-border);
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 18px;
}

.cd-shell {
  display: flex;
  min-height: 100vh;
}

.cd-sidebar {
  width: var(--cd-sidebar-w);
  flex: 0 0 var(--cd-sidebar-w);
  background: var(--cd-bg-sidebar);
  border-right: 1px solid var(--cd-border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.cd-sidebar-inner {
  padding: 12px;
  font-size: 13px;
  line-height: 1.45;
}

.cd-toc-list {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.cd-toc-list .cd-toc-list {
  padding-left: 14px;
}

.cd-toc-item > .cd-toc-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  margin: 1px 0;
  border-radius: 4px;
  border-left: 3px solid transparent;  /* reserved space for the current marker */
  /* Pull the marker flush with the left edge of the row, undoing the
     border's contribution to the layout so unselected rows align with
     the selected one. */
  margin-left: -3px;
}

.cd-toc-page > .cd-toc-row:hover {
  background: rgba(0, 0, 0, 0.04);
}

.cd-toc-page > .cd-toc-row.cd-current {
  border-left-color: var(--cd-accent);
  background: rgba(10, 100, 168, 0.07);
}

.cd-toc-toggle {
  cursor: pointer;
  width: 14px;
  height: 14px;
  display: inline-block;
  flex: 0 0 14px;
  user-select: none;
  text-align: center;
  color: var(--cd-fg-muted);
  font-size: 11px;
}

.cd-toc-toggle.cd-leaf {
  visibility: hidden;
}

/* cubitstyle.css declares `a:link {color:#0000ff}` and `a:visited
   {color:#551a8b}` at (0,1,1) specificity. Our class-only rules at (0,1,0)
   lose to it, which is why sidebar anchors were rendering as default browser
   blue/purple. Scope a sidebar-wide override at matching specificity so
   every anchor in the sidebar (brand + TOC links) reads as plain text by
   default; explicit state classes below bump higher to win. */
.cd-sidebar a:link,
.cd-sidebar a:visited {
  color: var(--cd-fg);
  text-decoration: none;
}

.cd-toc-link {
  flex: 1;
  min-width: 0;
}

.cd-toc-link.cd-current,
.cd-toc-link.cd-current:link,
.cd-toc-link.cd-current:visited {
  color: var(--cd-accent);
  font-weight: 600;
}

.cd-toc-book > .cd-toc-row > .cd-toc-label {
  font-weight: 600;
  color: var(--cd-fg);
  cursor: pointer;
}

.cd-toc-item.cd-collapsed > .cd-toc-list {
  display: none;
}

.cd-content {
  flex: 1;
  min-width: 0;
  padding: var(--cd-content-pad-y) var(--cd-content-pad-x);
}

/* Cap reading width for long-form prose, but keep the topic flush against
   the sidebar instead of centering it (margin-right: auto, not margin: 0
   auto). On wide monitors the right-hand whitespace grows; on narrower
   ones the topic naturally shrinks under the cap. */
.cd-topic {
  max-width: var(--cd-content-max-w);
  margin-right: auto;
}

.cd-topic img {
  max-width: 100%;
  height: auto;
}

/* Mobile: the sidebar's top block becomes a sticky horizontal top bar
   (brand + search + hamburger always visible); the TOC tree slides down
   beneath it when the hamburger is tapped. */
@media (max-width: 720px) {
  .cd-shell { flex-direction: column; }

  .cd-sidebar {
    position: sticky;
    top: 0;
    width: 100%;
    flex: 0 0 auto;
    height: auto;
    max-height: 100vh;
    overflow: visible;
    border-right: none;
    border-bottom: 1px solid var(--cd-border);
    z-index: 9;
    background: var(--cd-bg);
  }

  .cd-sidebar-top {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    min-height: var(--cd-mobile-bar-h);
  }

  /* Brand collapses to a single inline line on mobile so the search bar
     has room to breathe. */
  .cd-brand { padding: 0; gap: 6px; }
  .cd-brand-logo { width: 20px; height: 20px; }
  .cd-brand-name { font-size: 14px; }
  .cd-brand-version { display: none; }

  .cd-sidebar-search { padding: 0; }

  .cd-toggle-sidebar { display: inline-block; }

  /* TOC is hidden by default on mobile; slides into view as a dropdown when
     the hamburger toggles .cd-open on the sidebar. */
  .cd-sidebar-inner {
    display: none;
    max-height: calc(100vh - var(--cd-mobile-bar-h));
    overflow-y: auto;
    border-top: 1px solid var(--cd-border);
  }
  .cd-sidebar.cd-open .cd-sidebar-inner { display: block; }

  .cd-content { padding: 16px; }
}
