/*
 * Shared tool-suite shell CSS — sidebar nav, main content frame, the
 * search+timeline controls block, the shared detail drawer, the basket
 * tray, and the .leaf-tip hover label shared between Mapping Witches and
 * Reading Leaves. Requires tokens.css to be loaded first.
 *
 * Deliberately scoped to what every tool shares. Each tool's own visual
 * treatment (Throwing Bones' card piles, Mapping's pins, Brimstone's table,
 * Witch Stats' charts, Reading Leaves' canvas, Basket's grid, Data
 * Browser's list) is NOT here — that's built per-tool in Phase 3, in each
 * tool's own stylesheet, reusing the tokens above.
 *
 * Source: build_docs/design_handoff_witch_tools/redesign/tools.html's
 * <style> block. Sidebar is fixed to the right per round 2 (the earlier
 * left/right toggle was dropped). One extension beyond the source file:
 * `.controls-extra` is new here, not in the prototype — it's the slot the
 * standing resolution rule (build_docs/full-rebuild-plan.md) needs so a
 * tool can add its own control alongside search+timeline (Throwing Bones'
 * kept "Tie to Timeline" checkbox is the first user of this).
 *
 * `.filter-panel` (and everything under "Advance Filter panel" below) is
 * also new here, not in the design prototype — the live Advance Filter
 * checkbox-tree panel (event type / person / being / location / source)
 * has no design of its own (found missing while starting Phase 3); built
 * here using the same dark-panel/accordion visual language as the rest of
 * the shell per the standing resolution rule. Shared because both Throwing
 * Bones and Mapping Witches use it.
 */

/* justify-content:center — .main's max-width (below) caps its growth on
   wide viewports; without this, leftover flex space collects entirely on
   one side (row-reverse packs from the end) instead of splitting evenly,
   which reads as the whole shell "floating" off-center (user report,
   2026-09-30). Centering the fixed-sidebar + capped-main unit as a whole
   gives equal margins on both sides instead. */
/* Site-wide header band — mirrors shared/partials/header.php's <header>
   (same colors/type/links), built by tool-shell.js's buildTopNav() since
   tool pages are static HTML with no PHP include. Sits above .shell,
   full-width band with a centered, max-width inner row to match the
   Content Page template's own header row. */
.tool-topbar { background: var(--blue-field); }
/* max-width/padding here must match .shell's own actual rendered width
   (sidebar 260px + .main's max-width:1180px = 1440px, padding:64px to
   match .main's own left padding) — not an independently-chosen 1200px/
   clamp() pair. This band sits centered in the same viewport as .shell
   (also centered, via justify-content:center below), so matching the
   math exactly makes their left edges coincide; anything else drifts the
   wordmark right of the page content under it (user report, 2026-09-30:
   "left-justify... in the Tools screens"). */
.tool-topbar-inner {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 16px 40px;
  padding: 24px 64px; max-width: 1440px; margin: 0 auto;
}
.tool-topbar-word { font-size: 13px; font-weight: 700; letter-spacing: .2em; text-transform: uppercase; color: var(--on-dark); }
.tool-topbar-inner nav { display: flex; flex-wrap: wrap; gap: 24px; font-size: 13px; font-weight: 500; }
.tool-topbar-inner nav a { color: var(--gold-eyebrow); }
.tool-topbar-inner nav a:hover { color: #FFFFFF; }
.tool-topbar-inner nav a.on { color: var(--on-dark); }

.shell { display: flex; min-height: 100vh; justify-content: center; }
.shell.sidebar-right { flex-direction: row-reverse; }

/* sidebar */
/* Sticky, not static (user request, 2026-09-27): the tool nav should stay
   reachable while .main's own content scrolls, instead of scrolling away
   with the page. height+overflow-y let the sidebar scroll internally on
   its own if a viewport is ever too short for its full contents (nav +
   credit) to fit. */
.sidebar { flex: 0 0 260px; background: var(--ink-2); color: var(--on-dark); padding: 36px 28px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .back { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--on-dark-2); }
.sidebar .back:hover { color: var(--gold-eyebrow); }
.sidebar .wordmark { margin-top: 18px; font-size: 15px; font-weight: 700; letter-spacing: .02em; line-height: 1.3; color: var(--on-dark); }
.sidebar nav { margin-top: 44px; display: flex; flex-direction: column; }
.sidebar nav button {
  all: unset; cursor: pointer; padding: 16px 0; border-top: 1px solid #4A3A28;
  display: flex; flex-direction: column; gap: 5px; transition: transform 200ms, color 200ms;
}
.sidebar nav button:last-child { border-bottom: 1px solid #4A3A28; }
.sidebar nav button .name { font-size: 20px; font-weight: 600; letter-spacing: -.02em; color: var(--on-dark-2); }
.sidebar nav button .desc { font-size: 12.5px; line-height: 1.45; color: #8B7C63; max-width: 200px; }
.sidebar nav button.on .name { color: var(--gold-eyebrow); }
.sidebar nav button:hover .name { color: var(--on-dark); transform: none; }
.sidebar nav button:hover { transform: translateX(6px); }
.sidebar .credit { margin-top: auto; font-size: 12px; line-height: 1.5; color: #6E6046; }

/* Narrow-viewport shell (client request, 2026-10-04): .shell had NO
   breakpoint at all - the sidebar's fixed 260px flex-basis never
   relinquished width, so on any phone-width screen .main was squeezed
   into a ~230px column regardless of which tool was loaded (confirmed
   live: page titles wrapped letter-by-letter, search/timeline controls
   clipped mid-word). This is the single shared fix every tool page needs
   - each tool's own canvas/interaction behavior below this width is a
   separate, tool-specific follow-up, not solved by this alone. Collapses
   the sidebar into a horizontal, scrollable tab strip (descriptions
   dropped - they're exactly what a vertical nav has room for and a
   horizontal one doesn't) instead of a toggleable drawer: simpler, no
   new JS state, and the tool list is short enough (7) to fit as tabs.
   768px (not the site's 900px breakpoint elsewhere) because tool-shell's
   OWN content - search+timeline's flex-wrap, the 320px search-wrap
   minimum - already reflows reasonably down to roughly there. */
@media (max-width: 768px) {
  .tool-topbar-inner { padding: 18px 20px; gap: 10px 24px; }
  .shell, .shell.sidebar-right { flex-direction: column; min-height: 0; }
  .sidebar {
    flex: 0 0 auto; position: static; height: auto; width: 100%;
    padding: 16px 20px;
  }
  .sidebar .wordmark { display: none; }
  .sidebar nav {
    margin-top: 0; flex-direction: row; flex-wrap: nowrap; overflow-x: auto;
    gap: 2px; -webkit-overflow-scrolling: touch;
  }
  .sidebar nav button {
    flex: 0 0 auto; padding: 10px 14px; border-top: none !important; border-bottom: 2px solid transparent;
    white-space: nowrap;
  }
  .sidebar nav button .name { font-size: 14px; }
  .sidebar nav button .desc { display: none; }
  .sidebar nav button.on { border-bottom-color: var(--gold-eyebrow); }
  .sidebar nav button:hover { transform: none; }
  .sidebar .credit { display: none; }
  .main { max-width: none; padding: 28px 20px 60px; }
  .tool-title { font-size: 32px; }
  .tool-desc { font-size: 16px; }
}

/* main */
.main { flex: 1; min-width: 0; padding: 56px 64px 100px; max-width: 1180px; }
.tool-title { margin: 14px 0 0; font-size: 52px; font-weight: 600; letter-spacing: -.03em; color: var(--ink); }
.tool-desc { margin: 16px 0 0; font-size: 18px; line-height: 1.55; color: var(--ink-soft); max-width: 620px; }

.placeholder { margin-top: 64px; padding-top: 36px; border-top: 2px solid var(--desk); max-width: 520px; }
.placeholder .note { font-size: 15px; line-height: 1.6; color: var(--ink-mid); }

/* shared controls: search + timeline (+ optional per-tool extra control) */
.controls { margin-top: 44px; display: flex; flex-direction: column; gap: 26px; }
.controls-top { display: flex; flex-wrap: wrap; gap: 28px; align-items: flex-end; }
.search-wrap { flex: 1 1 320px; }
.search-wrap label, .range-wrap label { display: block; font-size: 1.3rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-mid); margin-bottom: 8px; }
.search-input-row { position: relative; }
.search-wrap input {
  width: 100%; border: 0; border-bottom: 2px solid var(--ink); background: transparent;
  font: inherit; font-size: 20px; padding: 6px 92px 6px 2px; color: var(--ink);
}
.search-wrap input:focus { outline: none; border-color: var(--rust); }
.search-clear {
  all: unset; position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  cursor: pointer; padding: 6px 14px; border-radius: 20px; font-size: 12px;
  font-weight: 600; background: var(--desk); color: var(--ink); white-space: nowrap;
}
.search-clear:hover { background: var(--ochre-field); }

/* Active-filter chips (user request, 2026-09-30) - shows what's currently
   narrowing the result set (Advance Filter checkboxes, or a filter a
   drawer card's "View in..." link pre-applied) and lets each one be
   cleared individually. See tool-shell.js's buildFilterChips(). */
.active-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-top: -4px; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 6px 5px 12px;
  border-radius: 14px; background: var(--ink-2); color: var(--on-dark); font-size: 12.5px; font-weight: 600;
}
.filter-chip-x {
  all: unset; cursor: pointer; width: 16px; height: 16px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; font-size: 10px; color: var(--on-dark-2);
}
.filter-chip-x:hover { background: rgba(255,255,255,.18); color: var(--on-dark); }

.range-wrap { flex: 1 1 100%; font-size: 1.4rem; }
.range-vals { text-align: center; font-size: 1.2rem; font-weight: 700; color: var(--ink); margin-bottom: 10px; }
.range-track { position: relative; height: 46px; }
.track-bg {
  position: absolute; inset: 0; background: #DED0B8; border-radius: 8px; overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.15);
}
.track-fill { position: absolute; top: 0; bottom: 0; border-radius: 8px; }
.range-track input[type=range] {
  position: absolute; top: 0; left: 0; width: 100%; height: 46px; margin: 0;
  -webkit-appearance: none; appearance: none; background: transparent; pointer-events: none;
}
.range-track input[type=range]::-webkit-slider-runnable-track { background: transparent; }
.range-track input[type=range]::-moz-range-track { background: transparent; }
.range-track input[type=range]::-webkit-slider-thumb {
  pointer-events: auto; -webkit-appearance: none; appearance: none;
  width: 15px; height: 54px; border-radius: 6px; background: var(--paper);
  border: 2px solid var(--ink); cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,.4); margin-top: 0;
}
.range-track input[type=range]::-moz-range-thumb {
  pointer-events: auto; width: 15px; height: 54px; border-radius: 6px; background: var(--paper);
  border: 2px solid var(--ink); cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.range-vals { margin-top: 8px; font-size: 1.2rem; font-weight: 600; color: var(--ink); white-space: nowrap; }
.count { flex: 0 0 auto; align-self: flex-end; font-size: 13px; color: var(--ink-mid); padding-bottom: 10px; }

/* per-tool extension slot (new — not in the design prototype, see file header) */
.controls-extra { flex: 0 0 auto; align-self: flex-end; display: flex; align-items: center; gap: 8px; padding-bottom: 10px; }
.controls-extra label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-mid); cursor: pointer; user-select: none; }

/* Bug fix (user report, iPad, 2026-10-09): touch-dragging the drawer
   scrolled the page underneath instead. Two causes, both needed - a
   fixed-position overflow:auto panel doesn't reliably take over touch
   scrolling on iOS Safari without -webkit-overflow-scrolling:touch, and
   even once it does, overscroll-behavior:contain stops the gesture
   "chaining" through to the body once the drawer hits the end of its
   own scroll range. body.drawer-open below (toggled by openDrawer/
   closeDrawer in tool-shell.js) is the other half - the body was never
   actually locked while the drawer was open, so there was a second,
   independent route for the gesture to reach it. */
body.drawer-open { overflow: hidden; }
/* shared detail drawer */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 540px; max-width: 92vw;
  background: var(--ink-2); color: var(--on-dark); padding: 44px 40px;
  transform: translateX(100%); transition: transform 320ms cubic-bezier(.2,.8,.2,1);
  box-shadow: -24px 0 60px rgba(0,0,0,.3); z-index: 20; overflow-y: auto;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.drawer.open { transform: translateX(0); }
.drawer .close { all: unset; cursor: pointer; font-size: 13px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--on-dark-2); }
.drawer .close:hover { color: var(--gold-eyebrow); }
.drawer .deyebrow { margin-top: 28px; font-size: 12px; font-weight: 700; letter-spacing: .18em; text-transform: uppercase; color: var(--gold-eyebrow); }
.drawer h2 { margin: 10px 0 0; font-size: 26px; font-weight: 600; letter-spacing: -.02em; line-height: 1.15; color: var(--on-dark); }
.drawer .meta { margin-top: 10px; font-size: 13px; color: var(--on-dark-2); line-height: 1.6; }
.drawer .full { margin-top: 16px; font-size: 15px; line-height: 1.6; color: var(--on-dark); }
/* User request, 2026-10-12: each drawer card is shown as a whole card -
   the same portrait shape as a Throwing Bones deck card (400:515, bones.css
   --card-w/--card-h) with the art zoomed past its own drawn frame exactly
   as the deck does it (bones.css .card .cart img: cover + scale(1.55)) -
   rather than a landscape slice. The text column is at least as tall as
   the card so the card never shows below the scrim as an "L", and is ~10%
   narrower so more of the card shows on the left. --entry-inset is the
   old 140px inset plus 10% of the text column's old width; the drawer's
   content width is min(540px, 92vw) - 80px of padding, written out in
   absolute units so the same value works for the block's padding and the
   scrim's offset (a % would resolve differently in each). The thumb keeps
   a fixed height rather than stretching with the text (2026-10-09 fix),
   so long entries just extend the block below it. */
.drawer {
  --entry-thumb-w: 220px;
  --entry-thumb-h: calc(var(--entry-thumb-w) * 515 / 400);
  --entry-inset: calc(140px + (min(540px, 92vw) - 220px) * .1);
}
.drawer .entry-block { position: relative; padding: 20px 0 20px var(--entry-inset); border-top: 1px solid #4A3A28; }
.drawer .entry-block:first-of-type { border-top: 0; }
.drawer .entry-thumb {
  position: absolute; left: 0; top: 20px; height: var(--entry-thumb-h); width: var(--entry-thumb-w); border-radius: 6px; overflow: hidden;
}
.drawer .entry-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center; transform: scale(1.55); }
.drawer .entry-text { position: relative; z-index: 1; min-height: var(--entry-thumb-h); }
.drawer .entry-text::before {
  content: ''; position: absolute; left: calc(-1 * var(--entry-inset)); top: -20px; bottom: -20px; width: var(--entry-thumb-w); z-index: -1; pointer-events: none;
  background: linear-gradient(to right, transparent 0, transparent calc(var(--entry-inset) - 52px), var(--ink-2) var(--entry-inset), var(--ink-2) 100%);
}
/* "View in Throwing Bones/Mapping Witches/Reading Leaves" per-card links
   (user request, 2026-09-30) — see tool-shell.js's buildCardLinks(). */
.drawer .entry-links { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 8px 16px; }
.drawer .entry-links a { font-size: 12px; font-weight: 700; letter-spacing: .04em; color: var(--gold-eyebrow); }
.drawer .entry-links a:hover { color: var(--on-dark); }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); opacity: 0; pointer-events: none; transition: opacity 320ms; z-index: 19; }
.backdrop.open { opacity: 1; pointer-events: auto; }

/* basket tray + card-select toggle (shared: reached from any tool per the
   design doc's "extending selection to other tools" note; Throwing Bones
   is the first/primary user per Phase 3) */
.basket-tray { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(120%); opacity: 0; pointer-events: none; background: var(--ink-2); color: var(--on-dark); border-radius: 30px; padding: 12px 12px 12px 22px; display: flex; align-items: center; gap: 18px; box-shadow: 0 10px 30px rgba(0,0,0,.35); transition: transform 220ms, opacity 220ms; z-index: 50; }
.basket-tray.show { transform: translateX(-50%) translateY(0); opacity: 1; pointer-events: auto; }
.basket-tray .bt-info { font-size: 13.5px; font-weight: 600; white-space: nowrap; }
.basket-tray .bt-actions { display: flex; gap: 8px; }
.basket-tray button { all: unset; cursor: pointer; padding: 8px 16px; border-radius: 20px; font-size: 12.5px; font-weight: 600; }
#btView { background: var(--gold-eyebrow); color: var(--ink-2); }
#btClear { background: transparent; color: var(--on-dark-2); }
#btClear:hover { color: var(--on-dark); }

/* Only ever shown inside the shared drawer now (user request, 2026-09-27:
   the grid tile's own copy of this icon was unclear and was removed —
   see throwing-bones/js/bones.js's wireGrid). '+' by default makes it
   obvious this ADDS the card to the basket before it's ever clicked,
   not just an unlabeled circle; ".on" (already added) switches to a
   checkmark. */
.card-select { position: absolute; top: 6px; left: 6px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255,255,255,.85); background: rgba(26,20,16,.55); z-index: 3; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.card-select::after { content: '\002B'; color: #fff; font-size: 15px; font-weight: 700; line-height: 1; }
.card-select.on { background: var(--rust); border-color: var(--rust); }
.card-select.on::after { content: '\2713'; font-size: 12px; }

/* shared hover label — used by Mapping Witches and Reading Leaves */
.leaf-tip { position: absolute; z-index: 7; pointer-events: none; opacity: 0; transform: translate(-50%, calc(-100% - 14px)); transition: opacity 80ms; background: var(--ink-2); color: var(--on-dark); padding: 7px 10px; border-radius: 3px; max-width: 240px; box-shadow: 0 4px 12px rgba(0,0,0,.3); }
.leaf-tip.show { opacity: 1; }
.leaf-tip .lt-kind { font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--gold-eyebrow); margin-bottom: 2px; }
.leaf-tip .lt-name { font-size: 13px; line-height: 1.3; text-wrap: pretty; }

/* Advance Filter panel — shared between Throwing Bones and Mapping Witches.
   No design reference exists for this screen (see file header) — styled to
   match the drawer's dark-panel language rather than invented from scratch. */
.filter-open-btn { all: unset; cursor: pointer; padding: 11px 20px; border-radius: 20px; font-size: 13px; font-weight: 600; background: var(--desk); color: var(--ink); white-space: nowrap; }
.filter-open-btn:hover { background: var(--ochre-field); }
.filter-open-btn.active { background: var(--ink); color: var(--paper); }

.filter-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 480px; max-width: 92vw;
  background: var(--ink-2); color: var(--on-dark); padding: 36px 32px;
  transform: translateX(100%); transition: transform 320ms cubic-bezier(.2,.8,.2,1);
  box-shadow: -24px 0 60px rgba(0,0,0,.3); z-index: 21; overflow-y: auto;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  display: flex; flex-direction: column;
}
.filter-panel.open { transform: translateX(0); }
.filter-panel .fp-head { display: flex; align-items: baseline; justify-content: space-between; }
.filter-panel .fp-title { font-size: 20px; font-weight: 600; color: var(--on-dark); }
.filter-panel .fp-close { all: unset; cursor: pointer; font-size: 13px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--on-dark-2); }
.filter-panel .fp-close:hover { color: var(--gold-eyebrow); }

.fp-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 24px; }
.fp-tabs button { all: unset; cursor: pointer; padding: 7px 13px; border-radius: 14px; font-size: 12px; font-weight: 600; color: var(--on-dark-2); background: rgba(255,255,255,.06); }
.fp-tabs button.on { background: var(--rust); color: #fff; }
.fp-tabs button .fp-tab-count { margin-left: 5px; opacity: .75; }

.fp-category { display: none; margin-top: 20px; flex: 1; min-height: 0; flex-direction: column; }
.fp-category.on { display: flex; }
.fp-search {
  all: unset; box-sizing: border-box; width: 100%; margin-bottom: 12px; padding: 8px 10px;
  border-radius: 6px; background: rgba(255,255,255,.07); color: var(--on-dark); font-size: 13px;
}
.fp-search::placeholder { color: var(--on-dark-2); }
.fp-parent { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid #4A3A28; font-weight: 700; font-size: 13px; }
.fp-list { overflow-y: auto; flex: 1; min-height: 0; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.fp-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 13.5px; color: var(--on-dark-2); }
.fp-item input, .fp-parent input { width: 16px; height: 16px; accent-color: var(--rust); }
.fp-anon { margin-top: 10px; padding-top: 10px; border-top: 1px solid #4A3A28; display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--on-dark-2); }

.fp-foot { display: flex; gap: 10px; margin-top: 24px; padding-top: 20px; border-top: 1px solid #4A3A28; }
.fp-foot button { all: unset; cursor: pointer; padding: 10px 20px; border-radius: 20px; font-size: 13px; font-weight: 600; }
.fp-apply { background: var(--gold-eyebrow); color: var(--ink-2); }
.fp-reset { background: transparent; color: var(--on-dark-2); }
.fp-reset:hover { color: var(--on-dark); }
