/* ============================================================================
   Legal-basis browser + Budget browser — supporting-document feel.
   Visual rationale: paper / official-document tone. Warm off-white surfaces,
   restrained mauve-on-rose palette, monospace numerals for ordinance codes
   so they read as catalogue entries, not lifestyle cards. Reuses existing
   brand tokens — no new colours invented.
   ============================================================================ */

/* ---- Index grid -------------------------------------------------------- */
.legal-basis-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--sp-4);
}

.legal-basis-card {
  display: flex;
}
.legal-basis-card__link {
  flex: 1;
  text-decoration: none;
  color: inherit;
  background: linear-gradient(180deg, #fffaf6 0%, #fff5ee 100%);
  border: 1px solid var(--ivory-300);
  border-left: 3px solid var(--rose-500);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  transition: border-color var(--motion-fast) var(--ease-standard),
              box-shadow var(--motion-fast) var(--ease-standard),
              transform var(--motion-fast) var(--ease-standard);
}
.legal-basis-card__link:hover {
  border-color: var(--rose-300);
  box-shadow: 0 8px 18px -10px rgba(60, 28, 38, 0.18);
  transform: translateY(-1px);
}
.legal-basis-card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.legal-basis-card__stem {
  font-family: var(--font-mono);
  font-size: var(--fs-18);
  font-weight: 600;
  color: var(--mauve-900);
  letter-spacing: 0.01em;
}
.legal-basis-card__decade {
  font-size: var(--fs-12);
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.legal-basis-card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.legal-basis-card__tag {
  font-size: var(--fs-11);
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--rose-50);
  color: var(--rose-700, #a8470a);
  font-weight: 500;
  white-space: nowrap;
}
/* Per-program tag tints — restrained, all in the warm rose/mauve family */
.legal-basis-card__tag--aics           { background: var(--rose-50);   color: var(--rose-700, #a8470a); }
.legal-basis-card__tag--osca_senior    { background: #fff3e6;          color: #b56a1c; }
.legal-basis-card__tag--pwd            { background: #fde9d9;          color: #8a3a0a; }
.legal-basis-card__tag--solo_parent    { background: #fde7ee;          color: #b03366; }
.legal-basis-card__tag--vawc_women     { background: #fde2ec;          color: #ad2553; }
.legal-basis-card__tag--disaster       { background: #f4e4d4;          color: #7e360a; }
.legal-basis-card__tag--children_youth { background: #f0eadf;          color: #604c2c; }
.legal-basis-card__tag--indigent       { background: #ece5dd;          color: #5a4a36; }
.legal-basis-card__tag--fourps         { background: #f3e6e2;          color: #8a3a39; }

.legal-basis-card__footer {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: var(--fs-12);
  color: var(--text-muted);
  margin-top: auto;
}
.legal-basis-card__cta {
  font-weight: 600;
  color: var(--rose-700, #a8470a);
}

/* ---- Detail page ------------------------------------------------------- */
.centerpiece-hero--compact {
  padding: var(--sp-5) var(--sp-6);
}
.legal-basis-actions .btn { white-space: nowrap; }

.legal-basis-detail {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.85fr);
  gap: var(--sp-5);
  margin-bottom: var(--sp-6);
}
@media (max-width: 1024px) {
  .legal-basis-detail { grid-template-columns: 1fr; }
}

.legal-basis-detail__txt,
.legal-basis-detail__pdf {
  background: #fff;
  border: 1px solid var(--ivory-300);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: 0 1px 0 rgba(255,255,255,0.8) inset, 0 1px 2px rgba(60,28,38,0.04);
}
.legal-basis-detail__txt-head,
.legal-basis-detail__pdf-head {
  margin-bottom: var(--sp-3);
}
.legal-basis-detail__txt-head h2,
.legal-basis-detail__pdf-head h2 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: var(--fs-20);
  color: var(--mauve-900);
  font-weight: 500;
}
.legal-basis-detail__pre {
  font-family: var(--font-mono);
  font-size: var(--fs-13);
  line-height: 1.65;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--text-primary);
  background: #fffefb;
  padding: var(--sp-4);
  border: 1px solid var(--ivory-200);
  border-radius: var(--r-md);
  max-height: 70vh;
  overflow-y: auto;
}
.legal-basis-detail__pre mark,
.legal-basis-detail__pre mark.lb-mark {
  background: #ffe28a;
  color: var(--mauve-900);
  padding: 0 2px;
  border-radius: 2px;
  scroll-margin-block: 30vh;
}
/* Active (currently-focused) match — slightly stronger so the user can see
   which one Enter / ↓ jumped to. */
.legal-basis-detail__pre mark.lb-mark--active {
  background: #ffb84d;
  box-shadow: 0 0 0 2px rgba(168, 71, 10, 0.35);
}

/* Highlight search wrap + match-count pill */
.lb-search-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.lb-search-input {
  height: 36px;
  max-width: 240px;
  padding-right: 64px; /* room for the count pill */
}
.lb-match-count {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: var(--fs-11);
  color: var(--text-muted);
  background: var(--ivory-100, #f5ebe0);
  padding: 2px 6px;
  border-radius: 999px;
  pointer-events: none;
}
.lb-match-count--zero { color: #b91c1c; background: #fde2e2; }

#lb-prev-match, #lb-next-match {
  min-width: 32px;
  padding: 0 8px;
  font-family: var(--font-mono);
}
#lb-prev-match[disabled], #lb-next-match[disabled] { opacity: 0.45; cursor: not-allowed; }

/* Original-PDF embed — <object> with <iframe> + textual fallback inside */
.legal-basis-detail__pdf-frame {
  width: 100%;
  height: 70vh;
  min-height: 540px;
  border: 1px solid var(--ivory-300);
  border-radius: var(--r-md);
  background: #fafafa;
  display: block;
}
/* When <object> is itself an inline element it can collapse on some browsers.
   Force block flow + a sane minimum so the fallback never shows just an icon. */
object.legal-basis-detail__pdf-frame { overflow: hidden; }
.legal-basis-detail__pdf-fallback {
  padding: var(--sp-5);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--fs-13);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  align-items: center;
  justify-content: center;
  min-height: 200px;
}
.legal-basis-detail__pdf-fallback p { margin: 0; }

/* ---- Budget table ------------------------------------------------------ */

/* Horizontal scroll wrapper. Fixes the right-edge clipping of peso amounts
   on narrower viewports — the table forces its full width via `min-width`,
   and the wrapper handles overflow with a visible scrollbar. */
.budget-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* Subtle gradient fade on the right edge tells users content continues */
  background:
    linear-gradient(to right, transparent calc(100% - 24px), rgba(168, 71, 10, 0.05));
  border-radius: var(--r-md);
}

/* ---------------------------------------------------------------------- */
/* Dual / floating scrollbar — pinned to viewport top so users don't have
   to scroll to the bottom of a long table to find the horizontal scroll.
   The dual-scrollbar.js script syncs its scrollLeft with the table.    */
/* ---------------------------------------------------------------------- */
.dual-scrollbar {
  /* Hidden by default — the JS adds .dual-scrollbar--active when overflow exists */
  display: none;
  position: sticky;
  top: 0;            /* JS overrides with the topbar height at runtime */
  z-index: 6;        /* below sidebar/topbar but above table content */
  height: 14px;
  overflow-x: auto;
  overflow-y: hidden;
  background: rgba(255, 255, 255, 0.92);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--ivory-200);
  border-radius: 0;
  margin-bottom: 4px;
  /* Subtle drop shadow indicates "this is a floating control" */
  box-shadow: 0 2px 6px -3px rgba(60, 28, 38, 0.12);
}
.dual-scrollbar--active {
  display: block;
}
.dual-scrollbar__inner {
  height: 1px;       /* just enough to give the scrollbar something to scroll */
  pointer-events: none;
}
/* Style the scrollbar itself with brand colours */
.dual-scrollbar::-webkit-scrollbar         { height: 12px; }
.dual-scrollbar::-webkit-scrollbar-track   { background: var(--ivory-100); }
.dual-scrollbar::-webkit-scrollbar-thumb   {
  background: var(--rose-300);
  border-radius: 6px;
  border: 2px solid rgba(255,255,255,0.7);
}
.dual-scrollbar::-webkit-scrollbar-thumb:hover { background: var(--rose-500); }
.dual-scrollbar { scrollbar-color: var(--rose-300) var(--ivory-100); scrollbar-width: thin; }

@media print {
  .dual-scrollbar { display: none !important; }
}
.table--budget {
  min-width: 1100px;
  table-layout: auto;
}

/* Column widths so values don't truncate */
.table--budget .col-program { width: 90px; }
.table--budget .col-code    { width: 170px; white-space: nowrap; }
.table--budget .col-label   { min-width: 280px; }
.table--budget .col-money   { width: 140px; }
.table--budget .col-total   { width: 160px; padding-right: var(--sp-4); }

.table--budget tbody tr.table__row--total {
  background: var(--rose-50);
  font-weight: 600;
}
.table--budget td.num,
.table--budget th.num {
  text-align: right;
  font-family: var(--font-mono);
  white-space: nowrap;          /* never wrap peso amounts */
  font-variant-numeric: tabular-nums;
}

/* The Total column is the headline — emphasise it */
.table--budget td.col-total,
.table--budget th.col-total {
  background: linear-gradient(180deg, #fffaf6 0%, #fff5ee 100%);
  border-left: 1px solid var(--ivory-200);
}
.table--budget td.col-total strong {
  color: var(--mauve-900);
}

/* Sticky label column when scrolling — keeps "what is this row" visible */
.table--budget .col-label {
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 1;
  box-shadow: 1px 0 0 var(--ivory-200);
}
.table--budget tbody tr.table__row--total .col-label {
  background: var(--rose-50);
}

.table-toolbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.table-toolbar__hint { color: var(--text-muted); font-size: var(--fs-12); }

@media (max-width: 720px) {
  /* On phones, drop the sticky-label trick (too narrow to be useful) */
  .table--budget .col-label { position: static; box-shadow: none; }
  .table-toolbar__hint { display: none; }
}

/* ---- Print stylesheet -------------------------------------------------- */
@media print {
  .sidebar, .topbar, .filter-bar, .legal-basis-actions,
  .pagadian-map-card, [data-action="print"], .no-print { display: none !important; }
  .app-shell { display: block !important; background: #fff !important; }
  .main { padding: 0 !important; background: #fff !important; }
  body { background: #fff !important; }
  .centerpiece-hero { background: #fff !important; box-shadow: none !important; padding: 0 0 12pt !important; }

  .legal-basis-grid {
    display: block;
  }
  .legal-basis-card {
    page-break-inside: avoid;
    margin-bottom: 8pt;
  }
  .legal-basis-card__link {
    background: #fff !important;
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    border-left: 3px solid #a8470a !important;
  }

  .legal-basis-detail {
    grid-template-columns: 1fr !important;
  }
  .legal-basis-detail__pdf { display: none !important; }
  .legal-basis-detail__pre {
    max-height: none !important;
    overflow: visible !important;
    background: #fff !important;
    border: 0 !important;
    padding: 0 !important;
    font-size: 10pt !important;
  }

  .table--budget { font-size: 10pt; }
  .table--budget tbody tr { page-break-inside: avoid; }

  /* Print header on every page */
  @page {
    size: Letter;
    margin: 0.5in 0.5in 0.6in 0.5in;
  }
}

@media (prefers-reduced-motion: reduce) {
  .legal-basis-card__link { transition: none; }
  .legal-basis-card__link:hover { transform: none; }
}
