/* ==========================================================================
   Zoning Regulations — additions to the Environmental Services system
   (../comprehensive-plan/css/plan.css: tokens, chrome, reader;
    ../land-use/css/regs.css: legal outline, regulation tables, sidebar)
   ========================================================================== */

/* ---------- section headings carry their number ---------- */
.zoning h2, .zoning h3, .zoning li[id], .zoning .tbl[id] { scroll-margin-top: 96px; }
.zoning h2 .secno { color: var(--pri-purple); margin-right: 6px; font-variant-numeric: tabular-nums; }

/* ---------- outline: an item can hold paragraphs, lists, tables, figures ---------- */
.doc.zoning ol.legal > li { grid-template-columns: 2.7em minmax(0, 1fr); }
.doc.zoning .legal__t > p { margin: 0; }
.doc.zoning .legal__t > p + p,
.doc.zoning .legal__t > ol.legal { margin-top: 10px; }
.doc.zoning .legal__t > .fig { margin-top: 16px; }
.doc.zoning .legal__t > .fig + p { margin-top: 16px; }
.doc.zoning ol.legal--bullets .legal__m { font-weight: 700; text-align: center; padding-right: 0; }
.doc.zoning ol.legal--d1 > li, .doc.zoning ol.legal--d2 > li, .doc.zoning ol.legal--d3 > li { font-size: 15px; }

/* cross-references to sections, articles and tables */
.doc a.xref {
  color: var(--pri-purple); text-decoration: underline;
  text-decoration-thickness: 1px; text-underline-offset: 2px;
}
.doc a.xref:hover { color: var(--outline-active); text-decoration-thickness: 2px; }
.doc :target { animation: zflash 1.6s ease-out; }
@keyframes zflash { from { background: var(--surface-yellow); } to { background: transparent; } }
@media (prefers-reduced-motion: reduce) { .doc :target { animation: none; } }

/* ---------- tables ---------- */
.tbl--reg thead th { background: var(--surface-grey); vertical-align: bottom; }
.tbl--reg thead th[colspan] { text-align: center; }
.tbl--reg tr.tbl__group th {
  background: var(--surface-purple); color: var(--outline-active);
  font-weight: 700; text-align: left;
}
.tbl--reg td.c { text-align: center; white-space: nowrap; }
.tbl--reg tbody th[scope="row"] { font-weight: 500; }
.tbl--reg .tbl__note { margin-top: 8px; }
.tbl--reg .tbl__note + .tbl__note { margin-top: 2px; }
/* wide matrices (Table 4.1, 11.1): keep the row label visible while scrolling */
.tbl--wide tbody th[scope="row"], .tbl--wide thead tr:first-child th:first-child {
  position: sticky; left: 0; z-index: 1; background: var(--white);
  box-shadow: 1px 0 0 var(--outline-var);
}
.tbl--wide thead tr:first-child th:first-child { background: var(--surface-grey); }
.tbl--reg .tbl__legend .tbl__note:first-child { margin-top: 8px; }

/* Desktop: a wide matrix that fits the reading column (zoning.js adds .tbl--fit
   and works out the margin that lines it up with <main>) spans the whole column, so
   every district column shows without a sideways scroll. While the table is on
   screen its header row pins under the docbar and its key pins to the bottom of
   the window; both let go once the table has scrolled past. Narrower screens,
   and matrices too wide even for the full column, keep the scrolling box. */
@media screen and (min-width: 1024px) {
  .doc.zoning .tbl--fit {
    margin-left: var(--tbl-shift, 0px);
    width: var(--tbl-width, auto);
  }
  .doc.zoning .tbl--fit .tbl__scroll { overflow: visible; }
  .doc.zoning .tbl--fit .tbl__scroll:has(+ .tbl__legend) { border-radius: var(--radius) var(--radius) 0 0; border-bottom: 0; }
  .doc.zoning .tbl--fit thead th {
    position: sticky; top: var(--tbl-stick-top, 65px); z-index: 2;
    box-shadow: inset 0 -1px 0 var(--outline);
  }
  .doc.zoning .tbl--fit thead tr:first-child th:first-child { left: auto; z-index: 3; }
  .doc.zoning .tbl--fit tbody th[scope="row"] { position: static; box-shadow: none; }
  .doc.zoning .tbl--fit thead tr:first-child th:first-child { border-top-left-radius: calc(var(--radius) - 1px); }
  .doc.zoning .tbl--fit thead tr:first-child th:last-child { border-top-right-radius: calc(var(--radius) - 1px); }
  .doc.zoning .tbl--fit .tbl__legend {
    position: sticky; bottom: 0; z-index: 4;
    display: flex; flex-wrap: wrap; gap: 2px 28px;
    margin-top: 0; padding: 10px 16px 12px;
    background: var(--white);
    border: 1px solid var(--outline); border-top: 2px solid var(--outline-active);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: 0 -6px 16px rgba(16, 16, 29, .08);
  }
  .doc.zoning .tbl--fit .tbl__legend .tbl__note { margin: 0; }
}

/* ---------- figures: one row of photos / diagrams, as placed in the PDF ---------- */
.zfig { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; }
.zfig .fig__frame { flex: 0 1 auto; max-width: min(100%, 420px); background: var(--white); }
.zfig .fig__frame img { width: auto; max-width: 100%; max-height: 300px; }
.zfig--2 .fig__frame, .zfig--3 .fig__frame { max-width: min(100%, 320px); }

/* ---------- index page ---------- */
.banner__lede {
  max-width: 760px; margin: 14px 0 0; color: rgba(255, 255, 255, .88);
  font-size: 18px; line-height: 29px;
}
.zgrid { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.zcard .toc-card__body .h4 { font-size: 20px; line-height: 26px; font-weight: 600; color: var(--ink); }
.zcard .toc-card__foot { display: flex; align-items: center; justify-content: space-between; margin-top: auto; }
.zcard__meta { font-size: 13px; line-height: 18px; color: var(--grey); }
.zindex {
  background: var(--white); border: 1px solid var(--outline); border-radius: var(--radius);
  padding: 28px 32px;
}
.zindex ol { list-style: none; margin: 0; padding: 0; columns: 3; column-gap: 40px; }
.zindex > ol > li { break-inside: avoid; margin: 0 0 22px; font-size: 15px; line-height: 22px; }
.zindex > ol > li > a { font-weight: 700; color: var(--ink); }
.zindex ul { list-style: none; margin: 8px 0 0; padding: 0; }
.zindex ul li { font-size: 14px; line-height: 21px; margin-top: 4px; }
.zindex ul a { color: var(--grey); }
.zindex a:hover { color: var(--pri-purple); text-decoration: underline; }
@media (max-width: 1100px) { .zindex ol { columns: 2; } }
@media (max-width: 700px) {
  .zindex { padding: 20px; }
  .zindex ol { columns: 1; }
  .banner__lede { font-size: 16px; line-height: 26px; }
}

/* ---------- narrow screens: deep outlines must not eat the measure ---------- */
@media (max-width: 760px) {
  .doc.zoning ol.legal > li { grid-template-columns: 2.1em minmax(0, 1fr); }
  .doc.zoning .legal__t > ol.legal { margin-left: -0.9em; }
}
@media print {
  .tbl--wide tbody th[scope="row"] { position: static; box-shadow: none; }
  .doc :target { animation: none; }
}

/* ---------- district / overlay code lists ---------- */
.doc .codes {
  display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0 20px;
  margin: 16px 0 0; padding: 4px 0; border-top: 1px solid var(--outline-var); border-bottom: 1px solid var(--outline-var);
}
.doc .codes dt { font-weight: 700; color: var(--outline-active); padding: 6px 0; }
.doc .codes dd { margin: 0; padding: 6px 0; color: #2c2c3a; }
.doc .codes dt:not(:first-of-type), .doc .codes dt:not(:first-of-type) + dd { border-top: 1px solid var(--outline-var); }
.tbl--reg thead th { text-align: left; }
.tbl--reg thead th.c { text-align: center; }
