/* app.css — /app pivot-page-only styles, split from styles.css (M8).
   Loaded (after styles.css and reports.css) by index.html only: the filter
   slicers, the reports builder (.rb-*), and the interactive print-preview
   overlay (preview.js). Kept off the other 17 pages that only link styles.css. */

/* ---------- filters bar ---------- */
.filters-bar { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
.filters-bar:empty { display: none; }
.slicer { position: relative; }
.slicer-btn { background: var(--surface); border: 1px solid var(--line-dk); border-radius: 16px; padding: 5px 12px; font-size: var(--fs-md); cursor: pointer; display: flex; align-items: center; gap: 6px; }
.slicer-btn .cap { font-weight: 600; color: var(--heading); }
.slicer-btn .sel { color: var(--muted); }
.slicer-btn.active { border-color: var(--vcg); box-shadow: 0 0 0 1px var(--vcg); }
.slicer-pop { position: absolute; top: 112%; left: 0; z-index: 30; background: var(--elevated); border: 1px solid var(--line-dk); border-radius: 8px; box-shadow: var(--shadow-lg); width: 250px; max-height: 330px; display: flex; flex-direction: column; }
.slicer-pop .search { padding: 7px; border-bottom: 1px solid var(--line); }
.slicer-pop .search input { width: 100%; padding: 5px 7px; border: 1px solid var(--line); border-radius: 5px; }
.slicer-pop .opts { overflow: auto; padding: 4px 0; }
.slicer-pop label { display: flex; gap: 7px; align-items: center; padding: 4px 11px; font-size: var(--fs-md); cursor: pointer; }
.slicer-pop label:hover { background: var(--tint); }
/* FR-020: Excel-style "select only this" — revealed on row hover. */
.slicer-pop .opt-txt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* The colour here was a hardcoded #2563eb: 5.17:1 on the light --elevated but
   only 2.83:1 on the dark one, at 10px. --link is the themed link role and
   clears 4.5:1 in both (5.64:1 / 5.33:1) — and it is the only answer that does
   not put the palette's single blue into a monochrome + copper page. */
.slicer-pop .opt-only { flex: none; font-size: var(--fs-2xs); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--link); background: none; border: 0; padding: 1px 5px; border-radius: var(--radius-sm); cursor: pointer; opacity: 0; }
.slicer-pop label:hover .opt-only { opacity: .85; }
.slicer-pop .opt-only:hover { opacity: 1; background: var(--tint); }
.slicer-pop .foot { display: flex; justify-content: space-between; padding: 7px; border-top: 1px solid var(--line); }
.slicer-pop .foot button { font-size: var(--fs-xs); padding: 4px 9px; border: 1px solid var(--line-dk); background: var(--surface); border-radius: 5px; cursor: pointer; }
.date-slicer-pop { width: 220px; max-height: none; }
.date-presets { display: flex; flex-direction: column; padding: 6px 7px; gap: 3px; border-bottom: 1px solid var(--line); }
.date-preset-btn { text-align: left; background: var(--surface); border: 1px solid transparent; border-radius: 5px; padding: 5px 9px; font-size: var(--fs-md); cursor: pointer; }
.date-preset-btn:hover { background: var(--tint); }
.date-preset-btn.sel { border-color: var(--vcg); color: var(--heading); font-weight: 600; }
.date-custom { display: flex; flex-direction: column; gap: 5px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.date-custom label { display: flex; align-items: center; gap: 7px; font-size: var(--fs-md); }
.date-custom input[type="date"] { flex: 1; padding: 4px 6px; border: 1px solid var(--line-dk); border-radius: 5px; font-size: var(--fs-md); }

/* mode visibility */
.reports-pane { display: none; }
body.mode-reports .ribbon, body.mode-reports .layout { display: none; }
body.mode-reports .reports-pane { display: block; flex: 1; min-height: 0; overflow: auto; padding: 18px 22px 30px; }

/* reports builder */
.rep-build { display: flex; gap: 18px; align-items: flex-start; max-width: var(--content-w-wide); }
.rb-list { flex: 0 0 220px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.rb-list-head { display: flex; align-items: center; justify-content: space-between; padding: 9px 12px; border-bottom: 1px solid var(--line); font-weight: 600; color: var(--heading); font-size: var(--fs-base); }
.rb-list-actions { display: flex; gap: 5px; }
/* A success FILL behind white text, not the pale --ok-fill badge role: --ok-solid
   stays dark in both themes (6.49:1 light / 7.99:1 dark with #fff) the same way
   .toast.ok does. It used to be a hardcoded #2a6e40 that never flipped. */
.rb-btn-run-all { background: var(--ok-solid); border-color: var(--ok-solid); color: #fff; }
.rb-btn-run-all:hover:not(:disabled) { background: var(--ok-solid-hover); }
.rb-item { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px; border: none; border-bottom: 1px solid var(--line); background: var(--surface); cursor: pointer; text-align: left; font-size: 12.5px; }
.rb-item.on { background: var(--surface-3); box-shadow: inset 3px 0 0 var(--vcg); }
.rb-item-nm { font-weight: 600; color: var(--ink); }
.rb-group-hd { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px; background: var(--surface-3); border-bottom: 1px solid var(--line); font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--heading); }
.rb-group-n { flex: 0 0 auto; font-weight: 600; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 0 6px; font-size: var(--fs-2xs); }
.rb-scope-note { padding: 8px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line); color: var(--muted); font-size: var(--fs-xs); line-height: 1.45; }
.rb-scope-note b { color: var(--ink); font-weight: 600; }
.rb-empty { padding: 14px; color: var(--muted); font-size: var(--fs-md); }
.rb-empty-lg { padding: 44px 20px; text-align: center; }
/* #94: view-only lock — reports are editable only after clicking Edit, so an
   out-of-date copy can't be written back over everyone else's reports. */
.rb-lock { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; padding: 9px 12px; background: var(--priority); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); font-size: var(--fs-md); line-height: 1.5; }
.rb-lock-btn { flex: 0 0 auto; }
.rep-build.rb-readonly .rb-editor input:disabled,
.rep-build.rb-readonly .rb-editor select:disabled,
.rep-build.rb-readonly .rb-editor textarea:disabled { background: var(--surface-2); color: var(--muted); cursor: default; }
.rep-build.rb-readonly .rb-editor button:disabled { opacity: .5; cursor: default; }

.rb-editor { flex: 1; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 14px 16px; min-width: 0; }
.rb-ed-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.rb-name { flex: 1; font-size: var(--fs-lg); font-weight: 600; padding: 6px 10px; border: 1px solid var(--line-dk); border-radius: var(--radius); color: var(--ink); }
.rb-ed-actions { display: flex; gap: 6px; }
.rb-cols { display: flex; gap: 18px; align-items: flex-start; }
.rb-form { flex: 1; min-width: 0; }
.rb-previewwrap { flex: 0 0 296px; }

.rb-fs { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }
.rb-fs legend { font-size: var(--fs-xs); font-weight: 700; color: var(--heading); text-transform: uppercase; letter-spacing: .04em; padding: 0 6px; }
.rb-hint { text-transform: none; font-weight: 400; color: var(--muted); }
.rb-fld { display: flex; flex-direction: column; gap: 3px; font-size: var(--fs-xs); color: var(--muted); margin-bottom: 8px; }
.rb-fld select, .rb-fld input { padding: 5px 8px; border: 1px solid var(--line-dk); border-radius: 5px; font-size: 12.5px; color: var(--ink); }
.rb-fld.rb-inline { flex-direction: row; align-items: center; gap: 6px; }
.rb-grow { flex: 1; } .rb-grow input { width: 100%; }
.rb-margins { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.rb-mg-lbl { font-size: var(--fs-xs); color: var(--muted); font-weight: 600; }
.rb-margins label { display: flex; align-items: center; gap: 4px; font-size: var(--fs-xs); color: var(--muted); }
.rb-margins input { width: 58px; padding: 4px 6px; border: 1px solid var(--line-dk); border-radius: 5px; }
.rb-cell { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 6px; }
.rb-cell > span { width: 46px; font-size: var(--fs-xs); color: var(--muted); text-transform: capitalize; padding-top: 6px; }
.rb-cell textarea { flex: 1; padding: 5px 8px; border: 1px solid var(--line-dk); border-radius: 5px; font-size: var(--fs-md); font-family: inherit; resize: vertical; }
.rb-chk { display: flex; align-items: center; gap: 6px; font-size: var(--fs-md); margin: 6px 0; color: var(--ink); }
.rb-pn { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.rb-tokens { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin-top: 4px; }
.rb-tok-lbl { font-size: var(--fs-xs); color: var(--muted); margin-right: 2px; }
.rb-tok { font-size: var(--fs-xs); padding: 2px 7px; border: 1px solid var(--line-dk); border-radius: 12px; background: var(--chip); cursor: pointer; color: var(--heading); font-family: ui-monospace, monospace; }
.rb-tok:hover { background: var(--vcg-d); color: #fff; border-color: var(--vcg); }   /* #F8: fill behind white text */
.rb-tip { font-size: var(--fs-xs); color: var(--muted); margin: 8px 0 0; line-height: 1.45; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 7px 9px; }
.rb-tip b { color: var(--ink); }
.rb-combined-section { border-left: 2px solid var(--line-dk); margin: 8px 0 4px; padding: 4px 0 4px 10px; }
.rb-combined-lbl { font-size: var(--fs-2xs); font-weight: 700; color: var(--heading); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }

/* report filters (FR-70) */
.rb-rfilters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.rb-rf-empty { font-size: var(--fs-sm); color: var(--muted); font-style: italic; padding: 2px 0; }
.rb-rf-row { border: 1px solid var(--line-dk); border-radius: 7px; padding: 8px 9px; background: var(--surface-2); }
.rb-rf-head { display: flex; align-items: center; gap: 6px; }
.rb-rf-field { flex: 1; min-width: 0; padding: 5px 8px; border: 1px solid var(--line-dk); border-radius: 5px; font-size: 12.5px; color: var(--ink); }
.rb-rf-mode { padding: 5px 6px; border: 1px solid var(--line-dk); border-radius: 5px; font-size: var(--fs-md); color: var(--ink); }
.rb-rf-del { border: 1px solid var(--line-dk); background: var(--surface); border-radius: 5px; cursor: pointer; padding: 4px 7px; font-size: var(--fs-md); line-height: 1; }
.rb-rf-del:hover { background: var(--danger-fill); border-color: var(--danger-line); }
.rb-rf-search { margin-top: 7px; }
.rb-rf-search input { width: 100%; padding: 4px 8px; border: 1px solid var(--line-dk); border-radius: 5px; font-size: var(--fs-md); box-sizing: border-box; }
.rb-rf-vals { margin-top: 6px; max-height: 168px; overflow-y: auto; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); padding: 4px 2px; }
.rb-rf-opt { display: flex; align-items: center; gap: 7px; padding: 2px 7px; font-size: var(--fs-md); color: var(--ink); cursor: pointer; border-radius: var(--radius-sm); }
.rb-rf-opt:hover { background: var(--surface-3); }
.rb-rf-opt input { margin: 0; }
.rb-rf-opt span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rb-rf-count { font-size: var(--fs-xs); color: var(--muted); margin-top: 5px; }
.rb-rf-more { font-size: var(--fs-xs); color: var(--muted); font-style: italic; padding: 4px 7px; }
.rb-rf-hint, .rb-rf-novals { font-size: var(--fs-sm); color: var(--muted); font-style: italic; margin-top: 7px; }

/* report preview */
.rep-prev-lbl { font-size: var(--fs-xs); color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.rep-preview { background: #fff; border: 1px solid var(--line-dk); box-shadow: var(--shadow); }
.rep-prev-landscape { aspect-ratio: 11 / 8.5; }
.rep-prev-portrait { aspect-ratio: 8.5 / 11; }
.rep-prev-page { width: 100%; height: 100%; display: flex; flex-direction: column; padding: 9px 11px; position: relative; box-sizing: border-box; }
.rep-prev-hd { border-bottom: 1.5px solid var(--vcg); padding-bottom: 5px; }
.rep-prev-body { flex: 1; display: flex; align-items: center; justify-content: center; color: #b3bcc2; font-size: var(--fs-xs); border: 1px dashed var(--line-dk); margin: 7px 0; }
.rep-prev-ft { border-top: 1px solid var(--line-dk); padding-top: 4px; }
.rep-prev-pn { position: absolute; bottom: 2px; font-size: 7px; color: #777; }
.rep-prev-pn-center { left: 0; right: 0; text-align: center; }
.rep-prev-pn-left { left: 11px; } .rep-prev-pn-right { right: 11px; }
/* preview cells reuse .pb/.pf (which are print-only) — give them on-screen styling */
.rep-prev-hd .pb { display: flex; justify-content: space-between; gap: 8px; font-size: 7px; color: #333; }
.rep-prev-hd .pb-c { text-align: center; flex: 1; }
.rep-prev-hd .pb-r { text-align: right; }
.rep-prev-hd .pb-em { font-size: var(--fs-2xs); font-weight: 700; color: var(--vcg-dd); display: block; }
.rep-prev-hd .pb-logo { height: 13px; }
.rep-prev-ft .pf { display: flex; justify-content: space-between; gap: 8px; font-size: 6.5px; color: #555; }
.rep-prev-ft .pf-c { text-align: center; flex: 1; }
.rep-prev-ft .pf-r { text-align: right; }

@media print { .sidenav, .topnav, .megamenu { display: none !important; } }

/* ============================================================
   INTERACTIVE PRINT PREVIEW OVERLAY  (preview.js)
   ============================================================ */

/* Full-screen backdrop */
.prev-overlay {
  position: fixed; inset: 0; z-index: var(--z-overlay);
  background: rgba(20, 28, 36, 0.72);
  backdrop-filter: blur(3px);
  display: flex; overflow: hidden;
}

/* Two-column layout: controls | paper stage */
.prev-ui { display: flex; width: 100%; height: 100%; min-width: 0; }

/* ---------- Left control panel -------------------------------------------- */
.prev-controls {
  flex: 0 0 272px; background: var(--elevated);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  overflow-y: auto; min-height: 0;
}
.prev-ctrl-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--elevated); z-index: 2;
}
.prev-ctrl-title { font-weight: 700; font-size: 14px; color: var(--heading); }
.prev-close-x {
  border: none; background: none; font-size: 24px; line-height: 1;
  cursor: pointer; color: var(--muted); padding: 0 2px;
}
.prev-close-x:hover { color: var(--ink); }

.prev-ctrl-sec { padding: 13px 16px; border-bottom: 1px solid var(--line); }
.prev-ctrl-lbl {
  font-size: 10.5px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; margin-bottom: 9px;
}

/* Dataset selector */
.prev-dataset-sel {
  width: 100%; padding: 5px 8px; border: 1px solid var(--line-dk);
  border-radius: 5px; font-size: var(--fs-md); background: var(--bg);
  color: var(--ink); cursor: pointer; outline-color: var(--vcg);
}

/* Orientation toggle */
.prev-segs { display: flex; border: 1px solid var(--line-dk); border-radius: 7px; overflow: hidden; }
.prev-seg {
  flex: 1; border: none; background: var(--surface); padding: 6px 10px;
  font-size: var(--fs-md); cursor: pointer; color: var(--heading);
  border-left: 1px solid var(--line-dk);
}
.prev-seg:first-child { border-left: none; }
.prev-seg:hover:not(.on) { background: var(--tint); }
.prev-seg.on { background: var(--vcg-d); color: #fff; font-weight: 600; }

/* Font size */
.prev-slider-row { display: flex; align-items: center; gap: 8px; }
.prev-slider { flex: 1; accent-color: var(--vcg); }
.prev-num-in {
  width: 54px; padding: 4px 6px; border: 1px solid var(--line-dk);
  border-radius: 5px; font-size: var(--fs-md); text-align: right;
}
.prev-unit { font-size: var(--fs-xs); color: var(--muted); }

/* Margin inputs — cross layout */
.prev-mg-layout { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.prev-mg-row { display: flex; align-items: center; gap: 6px; }
.prev-mg-sides { display: flex; align-items: center; gap: 6px; width: 100%; }
.prev-mg-side-item { display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 1; }
.prev-mg-page-icon { font-size: 20px; color: var(--line-dk); flex: 0 0 auto; }
.prev-mg-lbl { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.prev-mg-in {
  width: 64px; padding: 4px 6px; border: 1px solid var(--line-dk);
  border-radius: 5px; font-size: var(--fs-md); text-align: right;
}

/* Tip text */
.prev-tip { font-size: var(--fs-xs); color: var(--muted); margin-top: 7px; line-height: 1.5; }

/* Bottom actions */
.prev-ctrl-actions {
  margin-top: auto; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 8px;
  border-top: 1px solid var(--line);
}
.prev-stat { padding: 6px 16px 10px; font-size: var(--fs-xs); color: var(--muted); }

/* ---------- Right stage (paper view) -------------------------------------- */
.prev-stage {
  flex: 1; background: #4a5568;
  overflow: auto; display: flex; flex-direction: column;
  align-items: center; padding: 20px 24px 24px; min-width: 0;
}
/* .82 alpha over the #4a5568 stage = 5.69:1; at .55 it was 3.54:1. */
.prev-ruler-hint {
  font-size: var(--fs-xs); color: rgba(255,255,255,.82); margin-bottom: 14px;
  text-align: center; flex: 0 0 auto;
}
.prev-paper-wrap { position: relative; flex-shrink: 0; }

/* The paper itself — pixel dimensions set by JS via transform: scale() */
.prev-paper {
  position: relative; background: #fff;
  box-shadow: 0 6px 40px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.35);
  display: flex; flex-direction: column;
  overflow: hidden; /* clips content to page boundary */
}

/* Header / footer areas inside the paper */
.prev-hd, .prev-ft {
  flex: 0 0 auto; overflow: hidden; box-sizing: border-box;
  display: flex; align-items: center; background: #fff;
  position: relative; z-index: 2;
}
.prev-hd { border-bottom: 2px solid var(--vcg); }
.prev-ft { border-top: 1px solid var(--line-dk); }

/* Reuse .pb / .pf html in the on-screen preview (print-only by default) */
.prev-hd .pb {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 8px; color: #222; width: 100%; align-items: center;
}
.prev-hd .pb-l { flex: 1; text-align: left; line-height: 1.35; }
.prev-hd .pb-c { flex: 1.2; text-align: center; }
.prev-hd .pb-r { flex: 1; text-align: right; }
.prev-hd .pb-em { font-size: var(--fs-xs); font-weight: 700; color: var(--vcg-dd); display: block; }
.prev-hd .pb-logo { height: 18px; max-width: 100%; }
.prev-ft .pf {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 7.5px; color: #555; width: 100%;
}
.prev-ft .pf-l { flex: 1; text-align: left; line-height: 1.3; }
.prev-ft .pf-c { flex: 1.2; text-align: center; }
.prev-ft .pf-r { flex: 1; text-align: right; }

/* Content area — scrollable, so all rows are reachable */
.prev-body { flex: 1 1 auto; overflow: auto; box-sizing: border-box; }
.prev-body-inner { min-height: 100%; }

/* Override sticky thead inside the preview so headers stay at top of .prev-body */
.prev-pivot thead th { position: sticky; top: 0; }

/* Mirror the print output: allow text to wrap in the preview so narrow columns
   look exactly like they will on the PDF page. */
.prev-pivot th,
.prev-pivot td {
  white-space: normal !important;
  overflow-wrap: anywhere;
  word-break: break-word;
  vertical-align: top;
}

/* ---------- Margin drag handles ------------------------------------------- */
/* .pmh-h = horizontal line (top/bottom edges)
   .pmh-v = vertical line (left/right edges)   */
.pmh {
  position: absolute; z-index: 10;
  display: flex; align-items: center; justify-content: center;
}
.pmh-h {
  left: 0; right: 0; height: 18px;
  cursor: ns-resize; transform: translateY(-50%);
}
.pmh-v {
  top: 0; bottom: 0; width: 18px;
  cursor: ew-resize; transform: translateX(-50%);
}

/* The visible line */
.pmh-line { position: absolute; background: rgba(59,130,246,.55); }
.pmh-h .pmh-line { left: 0; right: 0; height: 1.5px; top: 50%; }
.pmh-v .pmh-line { top: 0; bottom: 0; width: 1.5px; left: 50%; }

/* Label bubble */
/* 9.5px white on rgba(59,130,246,.88) was 3.68:1; the deeper blue is 6.7:1. */
.pmh-lbl {
  position: absolute;
  background: rgba(29,78,216,.92); color: #fff;
  border-radius: var(--radius-sm); padding: 2px 6px;
  font-size: 9.5px; font-weight: 700;
  white-space: nowrap; pointer-events: none;
  line-height: 1.4; box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.pmh-h .pmh-lbl { top: 50%; transform: translateY(-50%); right: 12px; }
.pmh-v .pmh-lbl { left: 50%; transform: translateX(-50%); bottom: 16px; }

/* Hover: brighten line + label */
.pmh:hover .pmh-line { background: rgba(59,130,246,.9); }
.pmh:hover .pmh-lbl  { background: rgb(23,60,168); }

/* Active drag: show a faint full-span guide across the whole paper */
body.prev-dragging { cursor: grabbing !important; }
body.prev-dragging * { cursor: grabbing !important; }
