/* =====================================================================
   Dark theme + the theme switch.

   Loaded LAST on every page (after landing/document/aggregate/... css), so
   these rules win over the light defaults.

   How the theme is chosen (see js/theme.js and the inline <head> snippet):
     · the visitor's choice — "auto" (default), "light" or "dark" — is kept in
       localStorage ("legaldb.theme");
     · "auto" follows the system setting (prefers-color-scheme), live;
     · the resolved theme is written to <html data-theme="light|dark"> by a
       tiny inline script BEFORE the stylesheets paint, so a dark page never
       flashes white. With JavaScript off the page stays light.

   Most colours are CSS variables shared by landing.css and document.css
   (same names), so the dark palette is mostly one block of values. The rules
   after it cover colours the stylesheets hard-code.
   ===================================================================== */

/* Same content width on every page. Pages taller than the window (home, lists)
   get a page scrollbar; the ruling page never scrolls as a whole (its panes do),
   so it has none. Without this the page was ~15 px wider there and the whole top
   bar shifted sideways when moving between pages. "stable" keeps the scrollbar's
   space on every page, scrollbar or not. (Chrome/Edge draw the PAGE scrollbar on
   the right even in RTL; that is the browser's choice, not ours.) */
html { scrollbar-gutter: stable; }

:root[data-theme="dark"] {
  color-scheme: dark;            /* native form controls, scrollbars, date pickers */

  --bg: #0f1216;
  --surface: #161a20;
  --surface-2: #1e232b;

  --text: #e6e8eb;
  --text-muted: #a4a9b1;
  --text-dim: #6e747d;

  --border: #2b313a;
  --border-light: #232830;

  --accent: #3db2ff;
  --accent-light: #12304a;
  --accent-dark: #7cc9ff;        /* hover state: lighter, not darker, on dark */
  --accent-soft: #2f6f99;

  --lizzy: #c48ae8;
  --lizzy-light: #2a1c37;
  --lizzy-dark: #dcb3f5;
  --lizzy-border: #5b3d75;
  --gold: var(--lizzy);
  --gold-light: var(--lizzy-light);

  /* Citation pills (document.css) */
  --ref-bg: #2a1c37;
  --ref-text: #d6a8f2;
  --ref-bg-hover: #3a2650;
  --ref-active: #9a52d4;
}

/* ---------- surfaces the stylesheets hard-code white ---------- */
[data-theme="dark"] body { background: var(--bg); color: var(--text); }

[data-theme="dark"] header.site-header,
[data-theme="dark"] .site-header { background: rgba(22, 26, 32, 0.94); }

[data-theme="dark"] #par-popover,
[data-theme="dark"] #entity-popover {
  background: rgba(22, 26, 32, 0.98);
  border-color: var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.35);
}

[data-theme="dark"] .lizzyHighlightToolbar {
  background-color: var(--surface);
  border-color: var(--border);
}

/* The PDF page itself stays white: it is the document. Only the frame around it
   darkens, and it already is dark grey (#525659). */

/* ---------- messages ---------- */
[data-theme="dark"] .error-box {
  background: #3a1d1d; border-color: #6b2f2f; color: #f3c4c4;
}
[data-theme="dark"] .search-msg.error {
  background: #3a1d1d; border-color: #6b2f2f; color: #f3c4c4;
}

/* ---------- greens: law references, "party" tags ---------- */
[data-theme="dark"] .leg-ref           { color: #6fcf97; }
[data-theme="dark"] .leg-ref:hover     { color: #8ee0ae; }
[data-theme="dark"] .leg-ref.inferred  { color: #5fae84; }
[data-theme="dark"] .agg-kind.party,
[data-theme="dark"] .entity-icon.party { background: #173226; color: #6fcf97; }

/* ---------- scrollbars drawn as dark-on-light ---------- */
/* (The PDF viewer's scrollbar is light in both themes: see document.css.) */
[data-theme="dark"] .pop-body { scrollbar-color: rgba(255, 255, 255, 0.28) transparent; }
[data-theme="dark"] .pop-body::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.28); }

/* ---------- shadows: invisible on dark, make them deeper ---------- */
[data-theme="dark"] .search,
[data-theme="dark"] .doc-ask { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); }
[data-theme="dark"] .filter-popover { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55); }

/* =====================================================================
   The switch — a round icon button in the header (all page types).
   One icon per state; theme.js sets data-pref on <html>.
   ===================================================================== */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  /* A direct child of the header, after the right-hand nav cluster. The auto margin
     takes the free space before it, so it sits at the visual LEFT edge (RTL end) —
     beside the home page's filter button, which follows it. */
  width: 34px; height: 34px; padding: 0; margin-inline-start: auto;
  flex-shrink: 0;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text-muted);
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
/* Home page: the filter button comes BEFORE the switch, so the switch keeps the
   far-left spot it has on every other page. The free space then goes before the
   filter button instead, and the switch sits 8px to its left. */
.site-header > .filter-toggle { margin-inline-start: auto; }
.filter-toggle ~ .theme-toggle { margin-inline-start: 8px; }
/* The filter popover was anchored 20px from the left, under the filter button;
   the button is now one switch (34px + 8px) further right. Desktop only — on
   phones the popover is a full-width bottom sheet (responsive.css). */
@media (min-width: 641px) {
  .theme-toggle ~ .filter-popover { left: 62px; }
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent-soft, #71C6FF); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle svg { width: 18px; height: 18px; display: none; }

/* The icon shows the CURRENT theme: sun when light, moon when dark. A click switches. */
:root:not([data-theme="dark"]) .theme-toggle .ti-light,
:root[data-theme="dark"]       .theme-toggle .ti-dark { display: block; }

/* =====================================================================
   Bookmarks ("סימניות", js/bookmarks.js): the header button, next to the
   theme switch, and the panel it opens. Saved in the browser only.
   ===================================================================== */
.bm-toggle {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0; margin-inline-start: 8px; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text-muted); cursor: pointer;
}
.bm-toggle:hover { color: var(--accent); border-color: var(--accent-soft, #71C6FF); }
.bm-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.bm-toggle.has-current { color: var(--lizzy, #8A21C4); }
.bm-toggle.has-current svg path { fill: currentColor; }
.bm-count {
  position: absolute; top: -5px; inset-inline-end: -5px;
  min-width: 16px; height: 16px; padding: 0 4px; box-sizing: border-box; border-radius: 999px;
  background: var(--accent); color: #fff; font: 700 10px/16px var(--font-body, "Noto Sans Hebrew", sans-serif);
  text-align: center;
}
.bm-count[hidden] { display: none; }
/* The filter panel is anchored under the filter button, which this button moved one
   place to the right on the list pages (filter button, theme switch, bookmarks). */
@media (min-width: 641px) {
  .filter-toggle ~ .bm-toggle ~ .filter-popover { left: 104px; }
}

.bm-panel {
  position: fixed; z-index: 400; box-sizing: border-box; max-height: min(70vh, 560px);
  display: flex; flex-direction: column; gap: 10px; padding: 14px;
  direction: rtl; text-align: start;
  font-family: var(--font-body, "Noto Sans Hebrew", sans-serif); font-size: 13px; line-height: 1.5;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(17, 17, 17, 0.14);
}
.bm-panel[hidden] { display: none; }
[data-theme="dark"] .bm-panel { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55); }
.bm-panel button { font: inherit; cursor: pointer; }
.bm-panel :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.bm-head { display: flex; align-items: center; justify-content: space-between; font-size: 15px; }
.bm-x, .bm-del {
  flex: none; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 6px;
  background: transparent; color: var(--text-muted); font-size: 12px;
}
.bm-x:hover, .bm-del:hover { background: var(--surface-2); color: var(--text); }
.bm-save {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 36px; padding: 0 12px;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  font-weight: 500;
}
.bm-save:hover { border-color: var(--accent); color: var(--accent); }
.bm-save.is-saved { color: var(--lizzy, #8A21C4); }
.bm-save.is-saved svg path { fill: currentColor; }
.bm-notice {
  padding: 12px; border-radius: 10px; background: var(--surface-2);
  border: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px;
}
.bm-notice p { margin: 0; color: var(--text-muted); }
.bm-notice-actions { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.bm-primary {
  min-height: 34px; padding: 0 14px; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 700;
}
.bm-primary:hover { background: var(--accent-dark, #0B78D0); }
.bm-link { border: 0; background: transparent; color: var(--text-muted); padding: 4px; }
.bm-link:hover { color: var(--text); text-decoration: underline; }
.bm-error { margin: 0; color: #b3261e; }
.bm-empty, .bm-foot { margin: 0; color: var(--text-muted); }
.bm-foot { font-size: 11.5px; padding-top: 8px; border-top: 1px solid var(--border); }
.bm-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; min-height: 0; }
.bm-list li { display: flex; align-items: center; gap: 4px; }
.bm-list li + li { border-top: 1px solid var(--border); }
.bm-item {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; padding: 8px 4px;
  text-align: start; border: 0; border-radius: 6px; background: transparent; color: var(--text);
}
.bm-item:hover .bm-item-title { color: var(--accent); }
.bm-item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.bm-item-meta { font-size: 11.5px; color: var(--text-muted); }

/* The ruling page's own "save" button (data-bm-save) in its saved state. */
.doc-meta .bookmark-btn[data-bm-save] { cursor: pointer; }
.doc-meta .bookmark-btn.bookmarked { color: var(--lizzy, #8A21C4); border-color: var(--lizzy-border, #D0A6E7); }
.doc-meta .bookmark-btn.bookmarked svg path { fill: currentColor; }

/* The bookmark mark on a ruling in a list (js/bookmarks.js decorate()): a small button at the
   end of the row, or in the card's row of badges. Faint until the row is hovered; filled
   purple when the ruling is saved. */
.bm-mark {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 6px; cursor: pointer;
  color: var(--text-dim, #9aa0a6); opacity: 0.75;
  transition: color 0.12s, opacity 0.12s, background 0.12s;
}
a:hover > .bm-mark, a:hover .head > .bm-mark, .sr-card:hover .bm-mark { opacity: 1; color: var(--text-muted); }
.bm-mark:hover { background: var(--lizzy-light, #F3E9F9); color: var(--lizzy, #8A21C4) !important; opacity: 1; }
.bm-mark:focus-visible { outline: 2px solid var(--lizzy, #8A21C4); outline-offset: 2px; opacity: 1; }
.bm-mark.bookmarked { color: var(--lizzy, #8A21C4) !important; opacity: 1; }
.bm-mark.bookmarked svg path { fill: currentColor; }
/* Search result card: at the far end of the badges row (after the materiality bars when
   the card has them). */
.sr-card-top > .bm-mark { margin-inline-start: auto; }
.sr-card-top > .sr-mat ~ .bm-mark { margin-inline-start: 0; }
/* Home page card and list rows: vertically centred at the row's end. */
.result-card > .bm-mark, .dl-row > .bm-mark, .ct-row > .bm-mark, .pt-row > .bm-mark { align-self: center; }
