/* ================================================================
   39 Cheval Place — Portal FOUNDATION stylesheet
   ================================================================
   Register A (admin/tool): flat, dense, cool-grey + blue, radius 0.
   The dark navy "ink" chrome (header, login) is the one permitted
   deviation — it carries the project identity.

   THIS FILE OWNS THE TOKEN LAYER. Per-page stylesheets
   (portal-doors.css, portal-timeline.css, …) CONSUME tokens and must
   never redefine :root.

   Load order:  shared-base.css -> portal.css -> portal-<page>.css
   shared-base.css (symlink, never edit) provides
     html,body{overflow-x:clip}  and  @media(max-width:640px){table{display:block;overflow-x:auto}}
   — the second rule is why every mobile table pattern here re-declares
   `display:block` on the table AND tbody (see .dtable).

   Sections
     1  Tokens
     2  Reset & base type
     3  Layout (.container)
     4  Chrome: header + nav (ink)
     5  Page head, hints, section heads
     6  Ref codes
     7  Cards & sections (bubble-free)
     8  Tables — desktop
     9  Tables — the ONE canonical mobile pattern (.dtable + .m-* slots)
    10  Numbers / mono / truncation utilities
    11  Badges & chips
    12  Pills, pill strips, subnav
    13  Buttons
    14  Forms
    15  Modal / bottom sheet
    16  Banners & empty states
    17  Progress
    18  Gantt
    19  Comments
    20  File tiles (drawings)
    21  Galleries & lightbox
    22  Drop zone (uploads)
    23  Pager
    24  404
    25  Misc utilities
    26  Responsive: nav breakpoint, tap-target floor, iOS input guard
   ================================================================ */


/* ================================================================
   1  TOKENS — single source of truth
   ----------------------------------------------------------------
   Neutrals are the canonical register-A GRAY ramp (matches
   haugnes.net/www/css/style.css). The portal previously ran gray AND
   Tailwind-slate simultaneously; every slate step maps onto the gray
   step of the same index.
   ================================================================ */
:root {
    /* ---- Surfaces & borders (light -> dark) ---- */
    --c-surface:       #fff;
    --c-surface-2:     #f9fafb;
    --c-bg:            #f3f4f6;
    --c-border:        #e5e7eb;
    --c-border-soft:   #f0f1f3;   /* PORTAL: row hairline, lighter than --c-border */
    --c-border-strong: #d1d5db;

    /* ---- Text ramp (faint -> darkest) ---- */
    --c-text-faint:    #9ca3af;   /* em-dash placeholders, tiny slot labels ONLY */
    --c-text-muted:    #6b7280;   /* real secondary text: instructions, meta */
    --c-text-3:        #4b5563;
    --c-text-2:        #374151;
    --c-text-strong:   #1f2937;
    --c-text:          #111827;

    /* ---- Accent ---- */
    --c-primary:       #2563eb;
    --c-primary-hover: #1d4ed8;
    --c-primary-ring:  rgba(37,99,235,.15);
    --c-primary-lt:    #3b82f6;   /* PORTAL: brighter blue that reads on dark ink */

    /* ---- Status. Red = FAILURE ONLY. Money/pending/caution = amber. ---- */
    --c-danger:        #dc2626;
    --c-danger-bright: #ef4444;   /* rules & bars only (gantt today line) */
    --c-danger-dark:   #b91c1c;   /* danger-button hover */
    --c-warn:          #b45309;
    --c-warn-bright:   #f59e0b;   /* bars & fills only */
    --c-ok:            #16a34a;   /* fills & bars: bright green, on a tinted pill */
    --c-ok-text:       #15803d;   /* green TEXT on --c-bg (4.6:1); --c-ok is only 3.0:1 */
    --c-ok-dark:       #047857;   /* gantt actual bars */
    --c-info:          #2563eb;
    --c-excel:         #217346;   --c-excel-hover: #1a5c38;
    --c-word:          #2b579a;   --c-word-hover:  #1f4270;

    /* ---- Semantic chips: pastel bg + dark fg, one pair per status ---- */
    --chip-ok-bg:      #dcfce7;   --chip-ok-fg:      #166534;
    --chip-warn-bg:    #fef3c7;   --chip-warn-fg:    #92400e;
    --chip-danger-bg:  #fee2e2;   --chip-danger-fg:  #991b1b;
    --chip-info-bg:    #dbeafe;   --chip-info-fg:    #1e40af;
    --chip-accent-bg:  #ede9fe;   --chip-accent-fg:  #5b21b6;
    --chip-indigo-bg:  #e0e7ff;   --chip-indigo-fg:  #3730a3;
    --chip-neutral-bg: #f3f4f6;   --chip-neutral-fg: #4b5563;   /* not_started / TBC */

    /* ---- Soft callout / row-tint backgrounds ---- */
    --soft-ok:     #ecfdf5;  --soft-warn:   #fffbeb;  --soft-danger: #fef2f2;
    --soft-info:   #eff6ff;  --soft-accent: #faf5ff;
    /* Row tints, aliased so pages read semantically */
    --c-ok-bg:   var(--soft-ok);
    --c-warn-bg: var(--soft-warn);

    /* ---- PORTAL ONLY: dark chrome "ink" (header bar, login, register) ---- */
    --c-ink:         #1a1a2e;   /* header bar + login backdrop */
    --c-ink-2:       #232338;   /* raised ink: dropdown menu, login sign-in panel */
    --c-ink-3:       #2c2c44;   /* ink hover fill / input fill on ink */
    --c-ink-border:  #33334d;   /* hairline on ink */
    --c-ink-text:    #f3f4f6;   /* primary text on ink */
    --c-ink-muted:   #cbd5e1;   /* nav links, secondary text on ink */
    --c-ink-faint:   #8b93ad;   /* labels / tertiary on ink */
    --c-ink-ok:      #34d399;
    --c-ink-warn:    #fcd34d;
    --c-ink-danger:  #fca5a5;
    --c-ink-hover:   rgba(255,255,255,.06);
    --c-ink-active:  rgba(59,130,246,.14);
    --c-ink-sunken:  rgba(0,0,0,.28);   /* recessed fill inside the mobile nav drawer */
    /* Translucent tints that cannot be built from a solid token because they have
       to let the ink backdrop through: the login/register error band and the
       survey-grid hairline on the login brand panel. */
    --c-ink-danger-bg: rgba(220,38,38,.14);
    --c-ink-grid:      rgba(255,255,255,.035);
    --c-ink-scrim:   rgba(0,0,0,.45);   /* control chip floating over a photograph */
    --c-scrim:       rgba(0,0,0,.5);
    --c-scrim-soft:  rgba(0,0,0,.5);    /* control fill floating over a photo */
    --c-scrim-heavy: rgba(0,0,0,.92);
    --c-white:       #fff;              /* pure white: text/icons on ink or a photo */
    --c-photo-stage: #000;              /* stage behind a full-size image */

    /* ---- Type: the 7-step scale + one display step ---- */
    --text-2xs: .68rem; --text-xs: .72rem; --text-sm: .8rem; --text-base: .85rem;
    --text-md:  .9rem;  --text-lg: .95rem; --text-xl: 1.1rem;
    --text-2xl: 1.35rem;          /* login h1 / 404 h1 only */
    --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, monospace;

    /* ---- Spacing / shape / elevation ---- */
    --sp-1: .25rem; --sp-2: .5rem; --sp-3: .75rem; --sp-4: 1rem; --sp-5: 1.25rem; --sp-6: 1.5rem;
    --radius: 0;                  /* the one flat-vs-soft decision */
    --radius-pill: 9999px;        /* genuine pills only */
    --shadow-sm:  0 1px 3px rgba(0,0,0,.08);
    --shadow-md:  0 4px 16px rgba(0,0,0,.12);
    --shadow-ink: 0 10px 26px rgba(0,0,0,.4);

    /* ---- Layout metrics (were magic numbers in six places) ---- */
    --h-header:    44px;          /* desktop header height */
    --h-header-sm: 52px;          /* mobile header height (clears the 42px hamburger) */
    --w-page:      1400px;
    --tap:         40px;          /* minimum tap target */
    --tap-lg:      44px;          /* comfortable tap target for row actions */
    --nav-bp:      1000px;        /* documentation only: mobile-nav breakpoint */
}


/* ================================================================
   2  RESET & BASE TYPE
   ================================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* No scroll-behavior:smooth — /drawings anchors span an 11,000px page and a
       multi-second animated jump cannot be skipped and fights Home/End. */
}
@media (prefers-reduced-motion: no-preference) {
    /* deliberately empty — smooth scrolling stays off by choice, not by accident */
}

body {
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: 1.55;
    color: var(--c-text);
    background: var(--c-bg);
    min-height: 100dvh;
}

img { max-width: 100%; height: auto; display: block; }
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 1px; }
[hidden] { display: none !important; }

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--c-text);
}
h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }


/* ================================================================
   3  LAYOUT
   ================================================================ */
.container {
    max-width: var(--w-page);
    margin: 0 auto;
    padding: 14px 20px 40px;
}


/* ================================================================
   4  CHROME — header + nav (ink register)
   ----------------------------------------------------------------
   DOM comes from portal_header() and must not change:
     header.portal-header > a.portal-logo
                          > button.portal-nav-toggle > span x3
                          > nav.portal-nav#portalNav
                              > a.nav-link[.active][.nav-signout]
                              > div.nav-group[.active][.open]
                                  > button.nav-group-btn > svg.nav-caret
                                  > div.nav-group-menu > a.nav-sublink[.active]
   Desktop (>1000px): one dense row, tabs with a 2px active underline. The nav
   is overflow-x:auto so a future extra tab scrolls instead of being CLIPPED by
   shared-base's overflow-x:clip (the old 769-1000px dead zone where Sign out
   was unreachable).
   Mobile (<=1000px): hamburger + full-width slide-down drawer, accordion groups.
   ================================================================ */
.portal-header {
    background: var(--c-ink);
    color: var(--c-ink-text);
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 0;
    height: var(--h-header);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--c-ink-border);   /* flat: no drop shadow */
}

/* Legacy header title/address selectors — portal_header() no longer emits them,
   but keep them sane in case any page or an older cached template does. */
.portal-header .site-title { font-size: var(--text-lg); font-weight: 600; color: var(--c-ink-text); letter-spacing: .3px; }
.portal-header .site-title a { color: var(--c-ink-text); text-decoration: none; }
.portal-header .site-address { font-size: var(--text-sm); color: var(--c-ink-faint); margin-left: 12px; }

/* "39CH" wordmark */
.portal-logo {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    font-weight: 800;
    font-size: var(--text-xl);
    letter-spacing: .5px;
    line-height: 1;
    flex: 0 0 auto;
    white-space: nowrap;
}
.portal-logo::before {
    content: '';
    display: inline-block;
    width: 3px;
    height: 18px;
    background: var(--c-primary-lt);
    border-radius: var(--radius);
    margin-right: 9px;
}
.portal-logo .lg-39 { color: var(--c-ink-text); }
.portal-logo .lg-ch { color: var(--c-primary-lt); }
.portal-logo:hover { text-decoration: none; }
.portal-logo:hover .lg-39 { color: var(--c-ink-muted); }

/* .portal-here — current page label beside the logo, so the dead dark bar between
   logo and nav carries context and mobile keeps page identity once the H1 scrolls
   away. Emitted by portal_header() once the chrome agent adds it; harmless until. */
.portal-here {
    display: inline-flex;
    align-items: center;
    margin-left: 14px;
    padding-left: 14px;
    border-left: 1px solid var(--c-ink-border);
    font-size: var(--text-sm);
    color: var(--c-ink-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 40vw;
}

/* .nav-user — who is signed in (three external users share this portal, often on
   a site tablet). Sits immediately before Sign out. */
.nav-user {
    display: inline-flex;
    align-items: center;
    font-size: var(--text-xs);
    color: var(--c-ink-faint);
    padding: 0 4px 0 12px;
    white-space: nowrap;
}

.portal-nav {
    display: flex;
    align-items: stretch;
    gap: 0;
    height: 100%;
    margin-left: auto;
    /* MUST stay `visible` on desktop. An overflow value on EITHER axis turns this
       43px-tall bar into a clipping box on BOTH, and the absolutely-positioned
       .nav-group-menu (top:100%, i.e. below the bar) is then clipped away — no
       z-index escapes it. That made /doors, /electrical and /curtains unreachable
       by pointer. The mobile drawer does its own scrolling (see section 26). */
    overflow: visible;
    min-width: 0;
}

.portal-nav .nav-link,
.portal-nav .nav-group-btn {
    color: var(--c-ink-muted);
    font-size: var(--text-sm);
    font-weight: 500;
    padding: 0 12px;
    height: var(--h-header);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
    text-decoration: none;
    background: none;
    border: 0;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    cursor: pointer;
    font-family: inherit;
    transition: color .12s, border-color .12s, background .12s;
}
.portal-nav .nav-link:hover,
.portal-nav .nav-group-btn:hover {
    color: var(--c-ink-text);
    background: var(--c-ink-hover);
    text-decoration: none;
}
.portal-nav .nav-link.active,
.portal-nav .nav-group.active > .nav-group-btn {
    color: var(--c-white);
    border-bottom-color: var(--c-primary-lt);
}
.portal-nav .nav-link[aria-current="page"] { color: var(--c-white); border-bottom-color: var(--c-primary-lt); }

/* Grouped dropdown (Schedules) */
.nav-group { position: relative; display: inline-flex; align-items: stretch; flex-shrink: 0; }

.nav-caret {
    width: 9px; height: 6px;
    fill: none; stroke: currentColor;
    stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
    transition: transform .15s;
    margin-top: 1px;
}
.nav-group.open .nav-caret { transform: rotate(180deg); }

.nav-group-menu {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 190px;
    background: var(--c-ink-2);
    border: 1px solid var(--c-ink-border);
    border-top: 0;
    border-radius: var(--radius);
    box-shadow: var(--shadow-ink);
    display: none;
    flex-direction: column;
    padding: 3px 0;
    z-index: 200;
}
.nav-group.open > .nav-group-menu { display: flex; }

.nav-sublink {
    color: var(--c-ink-muted);
    font-size: var(--text-sm);
    padding: 8px 18px;
    white-space: nowrap;
    text-decoration: none;
    display: block;
    border-left: 2px solid transparent;
    transition: color .12s, background .12s;
}
.nav-sublink:hover { color: var(--c-ink-text); background: var(--c-ink-hover); text-decoration: none; }
.nav-sublink.active,
.nav-sublink[aria-current="page"] {
    color: var(--c-white);
    background: var(--c-ink-active);
    border-left-color: var(--c-primary-lt);
}

/* Sign out sits right, visually separated */
.portal-nav .nav-signout {
    color: var(--c-ink-faint);
    margin-left: 6px;
    padding-left: 14px;
    border-left: 1px solid var(--c-ink-border);
}
.portal-nav .nav-signout:hover { color: var(--c-ink-text); }

/* Hamburger — hidden until the mobile breakpoint */
.portal-nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 42px;
    height: 42px;
    padding: 10px;
    background: none;
    border: 0;
    border-radius: var(--radius);
    cursor: pointer;
    margin-left: auto;
}
.portal-nav-toggle span {
    display: block;
    width: 22px; height: 2px;
    background: var(--c-ink-muted);
    border-radius: var(--radius);
    transition: transform .2s, opacity .2s;
}
.portal-nav-toggle.is-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.portal-nav-toggle.is-open span:nth-child(2) { opacity: 0; }
.portal-nav-toggle.is-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Desktop-only hover dropdown. Breakpoint pairs with the mobile query at 1000px. */
@media (hover: hover) and (min-width: 1001px) {
    .nav-group:hover > .nav-group-menu { display: flex; }
    .nav-group:hover .nav-caret { transform: rotate(180deg); }
}


/* ================================================================
   5  PAGE HEAD / HINTS / SECTION TITLES
   ================================================================ */

/* .page-head — canonical title row: h1, dense meta, actions pushed right.
   .page-title-row is the legacy name still emitted by every template; both
   render identically. At 390px it wraps and the action group takes a full row. */
.page-head,
.page-title-row {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: var(--sp-2) var(--sp-3);
    margin-bottom: var(--sp-3);
}
.page-head h1, .page-title-row h1 { margin: 0; }
.page-title { font-size: var(--text-xl); font-weight: 700; color: var(--c-text); margin: 0; }
.page-head-actions,
.page-title-row .page-head-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }

/* .page-meta — the REPLACEMENT for KPI stat-card bubbles (house law forbids them).
   One dense line of "strong number + muted label" items, colour by semantic token,
   never red for a non-failure. */
.page-meta {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem 1rem;
    font-size: var(--text-sm);
    color: var(--c-text-muted);
    margin: -2px 0 var(--sp-3);
}
.page-meta > * { white-space: nowrap; }
.page-meta strong { color: var(--c-text); font-weight: 600; font-variant-numeric: tabular-nums; }
/* Semantic TEXT on the page background needs the dark step: --c-ok (#16a34a)
   measures 3.0:1 on --c-bg at 12.8px and this is the first number on the page
   on doors / curtains / queries / timeline / building-control. Keep the bright
   green for chip backgrounds, where it sits on a tinted pill. */
.page-meta .m-ok   strong { color: var(--c-ok-text); }
.page-meta .m-warn strong { color: var(--chip-warn-fg); }
.page-meta .m-info strong { color: var(--c-primary); }

/* .page-hint — the instructive one-liner under a title. Replaces four inline-styled
   paragraphs, and uses --c-text-muted (4.9:1) not the old border-grey (1.3:1). */
.page-hint {
    font-size: var(--text-sm);
    color: var(--c-text-muted);
    margin-bottom: var(--sp-3);
    max-width: 96ch;
}
.page-hint a { font-weight: 600; }

/* .sec-title — bubble-free caption row above a table that is not a collapsible
   .section: ref code + title + count pushed right, 2px rule under it. */
.sec-title {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--c-text);
    margin: var(--sp-4) 0 0;
    padding: 6px 0 5px;
    border-bottom: 2px solid var(--c-border);
}
.sec-title .phase-count,
.sec-title .sh-count { margin-left: auto; }


/* ================================================================
   6  REF CODES — canonical (matches haugnes.net)
   ----------------------------------------------------------------
   A bare monospace label, not a boxed chip: it costs no horizontal
   room in a dense header. Note the canonical version has margin-LEFT,
   i.e. it FOLLOWS the heading text. Every template now emits it after
   the title; .ref-code-lead below stays as a compatibility shim only.

   Colour is --c-text-muted, NOT --c-text-faint: on --c-bg the faint
   step measures 2.3:1 at 10.9px, which made every code on the portal
   an invisible grey smudge. The whole point of house law's "a code you
   can name in conversation" is that you can read it. --c-text-muted +
   weight 600 measures ~4.8:1 and still reads as quiet.
   ================================================================ */
.ref-code {
    font-size: var(--text-2xs);
    color: var(--c-text-muted);
    font-family: var(--font-mono);
    letter-spacing: .04em;
    display: inline;
    margin-left: .5rem;
    font-weight: 600;
    user-select: none;
}
/* Ref code that precedes its title (current markup on timeline/drawings/bc). */
.ref-code-lead,
h1 > .ref-code:first-child,
h2 > .ref-code:first-child,
h3 > .ref-code:first-child,
.section-head > .ref-code:first-child,
.sec-title > .ref-code:first-child,
.page-title-row > .ref-code:first-child {
    margin-left: 0;
    margin-right: .5rem;
    order: -1;
    flex: 0 0 auto;
}


/* ================================================================
   7  CARDS & SECTIONS
   ----------------------------------------------------------------
   House law: DATA TABLES ARE FULL-WIDTH WITH NO CARD BUBBLE.
   .card survives for genuine non-table content (tiles, upload rows)
   but is flat: radius 0, no shadow. The three combinations that used
   to wrap tables in a rounded white panel — .card.phase-section and
   .card.category-section — are neutralised to transparent so the
   existing templates become bubble-free with no markup change.
   ================================================================ */
.card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    margin-bottom: 12px;
}
.card-body { padding: 10px 12px; }

/* Bubble-free section wrapper. .phase-section / .category-section are the legacy
   names the templates emit; .section is the canonical one for new markup. */
.section,
.card.phase-section,
.card.category-section,
.phase-section,
.category-section {
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
    margin: 0 0 18px;
}

/* .section-head — a strong horizontal rule with the ref code, title, count and
   caret sitting ON it. This is what a section header looks like without a bubble.
   Sticky under the chrome so the floor/phase name stays visible while scrolling a
   long schedule. .phase-header / .category-header are the legacy aliases.

   ONE component. `.group-head` (drawings categories, cgi floors) used to be
   a second, lighter variant — 32px with a 1px hairline and a smaller caret
   glyph — which made /drawings and /cgi read as a weaker product than the
   schedule pages. It is now an alias: same height, same 2px ink rule, same
   caret. Only the count/source slot differs. */
.section-head,
.phase-header,
.category-header,
.group-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 0 6px;
    margin: 0;
    background: var(--c-bg);
    border: 0;
    border-bottom: 2px solid var(--c-ink);
    border-radius: 0;
    cursor: pointer;
    user-select: none;
    position: sticky;
    top: var(--h-header);
    z-index: 20;
}
.section-head:hover,
.phase-header:hover,
.category-header:hover,
.group-head:hover { background: var(--c-bg); }

/* .sh-title / .gh-title — the heading TEXT, wrapped in its own span so
   (a) the ref code is not :first-child (which would fire the .ref-code-lead
   shim and glue it to the title) and (b) a long floor or board name clips
   instead of pushing the ref code and the count off the sticky row.
   Every page's section heading uses this; do not duplicate it per page. */
.sh-title, .gh-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.section-head h2, .phase-header h2, .category-header h2, .group-head h2,
.section-head .phase-title, .phase-header .phase-title {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--c-text);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.phase-title { flex: 0 1 auto; }

/* Caret. .sh-caret is canonical; .phase-toggle-icon is the legacy name.
   ONE glyph portal-wide: &#9660; (BLACK DOWN-POINTING TRIANGLE). It is the
   only affordance saying "this section collapses", so it is --c-text-muted,
   not --c-text-faint (2.3:1 — not there at all on a phone in daylight). */
.sh-caret,
.phase-toggle-icon {
    font-size: var(--text-2xs);
    color: var(--c-text-muted);
    transition: transform .15s;
    display: inline-block;
    flex: 0 0 auto;
    line-height: 1;
}
.section.collapsed .sh-caret,
.phase-section.collapsed .phase-toggle-icon,
.category-section.collapsed .sh-caret { transform: rotate(-90deg); }

/* Count, pushed right */
.sh-count,
.phase-count,
.category-source {
    margin-left: auto;
    font-size: var(--text-xs);
    color: var(--c-text-muted);
    font-weight: 400;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.section-body, .phase-body { padding: 0; }
.section.collapsed > .section-body,
.phase-section.collapsed .phase-body,
.category-section.collapsed .category-body { display: none; }

/* Group description: it used to be a fourth stacked line in a 118px header.
   Now it is one clipped inline item after the title. Pages should move it into
   title= on the h2; until then it is hidden on the phone. */
.category-desc {
    order: 1;
    flex: 1 1 auto;
    min-width: 0;
    margin: 0 0 0 10px;
    font-size: var(--text-xs);
    color: var(--c-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.category-source { order: 2; max-width: 34ch; overflow: hidden; text-overflow: ellipsis; }
/* The section title itself must clip, never wrap a 32px header to three lines. */
.section-head > h2, .phase-header > h2, .category-header > h2, .group-head > h2 {
    flex: 0 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* .group-head extras — the source string and count slots that only the
   tile/gallery groups carry. The BOX is .section-head above; only these two
   slots are page-family specific. */
.group-head h3 { font-size: var(--text-lg); margin: 0; }
.group-head .gh-count { margin-left: auto; font-size: var(--text-xs); color: var(--c-text-muted); font-variant-numeric: tabular-nums; }
.group-head .gh-src { font-size: var(--text-xs); color: var(--c-text-muted); }
/* 17 group heads on /drawings carry a long source string ("Studio Kyson
   (761-23 series)") — it must clip, never wrap the row onto three lines. */
.group-head .gh-src { flex: 0 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group-head:hover h2 { color: var(--c-primary); }


/* ================================================================
   8  TABLES — desktop
   ----------------------------------------------------------------
   Full width, flat, dense, no wrapper bubble. Hierarchy of rules:
     2px --c-ink   = section boundary (.section-head)
     1px --c-border      = column headers
     1px --c-border-soft = data rows
   ================================================================ */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* MUST be positioned. A position:absolute descendant (e.g. the .sr-only
       "Actions" label in the last <th>) is NOT clipped by an overflow ancestor
       that is not its containing block — it escaped and made the DOCUMENT
       141px wider than a 660px window on /doors and /electrical. */
    position: relative;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-base);
    /* The section wrapper is transparent now (no card bubble), so the TABLE owns
       the white surface. Set it here rather than per-cell: a per-td background
       makes any mobile "row becomes a block" layout render as ragged white
       boxes instead of one clean sheet. */
    background: var(--c-surface);
}

thead th {
    background: var(--c-surface-2);
    color: var(--c-text-muted);
    font-weight: 600;
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: .4px;
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid var(--c-border);
    white-space: nowrap;
}

tbody td {
    padding: 5px 10px;
    border-bottom: 1px solid var(--c-border-soft);
    vertical-align: top;
}
tbody tr:last-child td { border-bottom: 1px solid var(--c-border); }
tbody tr:hover td { background: var(--c-surface-2); }

/* .dtable — THE house data table. table-layout:fixed is what makes every
   floor/phase section on a page share identical column boundaries (today each
   sibling table auto-sizes independently and headers drift up to 40px).
   Each page declares ONE width set via <col> and reuses it in all its sections.
   Its mobile behaviour is section 9. */
.dtable {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: var(--text-base);
    background: var(--c-surface);
}
.dtable thead th {
    background: var(--c-surface-2);
    color: var(--c-text-muted);
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid var(--c-border);
    white-space: nowrap;
}
/* NOTE for page stylesheets: this selector is (0,1,2), so a single-class
   per-cell override (`.pk-charge{padding-right:18px}`) silently loses. Write
   per-cell padding with two classes: `.pk-table .pk-charge{…}`. */
.dtable tbody td {
    padding: 5px 10px;
    border-bottom: 1px solid var(--c-border-soft);
    vertical-align: top;
}
/* .tbl / .tbl-stack are aliases for .dtable so either naming works. */
.tbl { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: var(--text-base); }

/* Legacy column-width helpers (timeline template). Prefer <col> widths on .dtable. */
.col-title    { min-width: 160px; }
.col-floor    { min-width: 60px; }
.col-status   { min-width: 80px; }
.col-progress { min-width: 90px; }
.col-dates    { min-width: 130px; white-space: nowrap; font-size: var(--text-sm); }
.col-assignee { min-width: 80px; font-size: var(--text-sm); }

/* Secondary text. THE single highest-value legibility fix in this pass:
   .text-muted used to be #cbd5e1 — a border grey at ~1.3:1 on the page
   background — and it carried every page's instruction paragraph. */
.text-muted { color: var(--c-text-muted); }
.text-faint { color: var(--c-text-faint); }

.milestone-title { font-weight: 500; color: var(--c-text); }
.milestone-desc  { font-size: var(--text-sm); color: var(--c-text-muted); margin-top: 3px; line-height: 1.4; }

/* Tender/table separator row (drawings) */
.tender-table-wrap { overflow-x: auto; padding: 0 0 12px; }
.tender-table-wrap table { font-size: var(--text-base); }
.tender-separator td {
    padding: 8px 10px 6px;
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--c-text-muted);
    background: var(--c-surface-2);
    text-transform: uppercase;
    letter-spacing: .3px;
    border-bottom: 1px solid var(--c-border);
}


/* ================================================================
   9  TABLES — the ONE canonical mobile pattern
   ----------------------------------------------------------------
   At <=640px each <tr> of a .dtable becomes a fixed 2-line (optionally
   3-line) 12-column grid row — NOT a card. No margin between rows, no
   border except a 1px hairline, no radius. A 45-row table lands at
   ~48px per row instead of 200-350px.

   Slots (add the class to the <td>):
     .m-key   line 1 cols 1-4    short identity code (D-B-01, B-3, EXG-01)
     .m-pri   line 1 cols 4-10   primary label (room, description, title)
     .m-chip  line 1 cols 10-13  status chip, right-aligned (max ~88px wide)
     .m-act   line 1 cols 10-13  action button(s), right-aligned
                                 (a row uses m-chip OR m-act, not both)
     For rows that need BOTH a chip and two 44px actions, the canonical
     split is  m-key 1/7 · m-chip 7/9 (justify-self:start) · m-act 9/13
     — declared identically in portal-doors.css and portal-electrical.css.
     .m-s1..4 line 2, four equal muted tabular slots (s4 right-aligned)
     .m-note  line 3, full width, clamped to 2 lines
     .m-off   hidden on mobile — move its content into title= on a surviving cell
   Add .m-nokey to the table when rows have no short code (timeline).

   Labels are OFF by default (td::before{content:none}) — the absence of
   exactly that rule is what broke the doors page, where an invisible
   80px ::before box indented every ID and location. Only .m-s* slots
   opt back in, via data-label.

   BREAKPOINT IS 640px, matching shared-base.css. Anything at 768px
   creates an untested 641-768px state where the table is display:table
   while its rows are display:block.
   ================================================================ */
@media (max-width: 640px) {
    /* Mandatory: neutralise shared-base's `table{display:block;overflow-x:auto}`.
       Without display:block on tbody too, the browser wraps tbody in an anonymous
       shrink-to-fit table box and rows render ~304px wide inside a 390px screen. */
    .dtable, .dtable tbody,
    .tbl-stack, .tbl-stack tbody {
        display: block;
        width: 100%;
        overflow: visible;
    }
    .dtable thead, .tbl-stack thead { display: none; }

    .dtable tbody tr,
    .tbl-stack tbody tr {
        display: grid;
        grid-template-columns: repeat(12, 1fr);
        column-gap: 8px;
        row-gap: 1px;
        align-items: baseline;
        padding: 6px 2px;
        min-height: var(--tap-lg);
        margin: 0;
        border: 0;
        border-bottom: 1px solid var(--c-border);
        background: transparent;
        border-radius: 0;
    }
    .dtable tbody td,
    .tbl-stack tbody td {
        display: block;
        padding: 0;
        border: 0;
        min-width: 0;
        background: transparent;
    }
    .dtable tbody td::before,
    .tbl-stack tbody td::before { content: none; }

    /* The row rule is drawn ONCE by the <tr> above. Section 8's
       `tbody tr:last-child td{border-bottom:1px solid …}` is (0,1,3) and beats
       the `border:0` reset above (0,1,2), so without this every cell of the LAST
       row painted its own short hairline at its own content height — read as a
       broken strikethrough on 5 of the 12 pages. */
    .dtable tbody tr:last-child td,
    .tbl-stack tbody tr:last-child td { border-bottom: 0; }

    /* HARDENING — any justify-self:end slot must be allowed to shrink.
       A grid item with `white-space:nowrap` and no `min-width:0` sizes to
       max-content and grows LEFTWARD out of its track, painting on top of the
       cell to its left (overflow:hidden on the neighbour cannot save it,
       because the offender's own box is the thing that is too wide). This one
       line is what stops the /timeline Edit Log and the pill columns from
       overlapping. Max supported pill width in the .m-chip slot is ~88px. */
    .dtable .m-chip, .dtable .m-act, .dtable .m-s4,
    .tbl-stack .m-chip, .tbl-stack .m-act, .tbl-stack .m-s4 { min-width: 0; }

    /* Line 1 */
    .dtable .m-key, .tbl-stack .m-key {
        grid-row: 1; grid-column: 1 / 4;
        font-weight: 700; font-size: var(--text-base); color: var(--c-text);
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .dtable .m-pri, .tbl-stack .m-pri {
        grid-row: 1; grid-column: 4 / 10;
        font-weight: 600; font-size: var(--text-base); color: var(--c-text);
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .dtable.m-nokey .m-pri, .tbl-stack.m-nokey .m-pri { grid-column: 1 / 10; }
    /* 3 tracks (~90px at 390px), not 2 (~57px): "Satisfactory" is 82px,
       "Conditional" 76px, "Submitted" 76px — all of which overflowed a 2-track
       slot. Rows WITH actions use the documented split instead:
         m-key 1/7 · m-chip 7/9 (justify-self:start) · m-act 9/13
       which is what /doors and /electrical declare, so the two match. */
    .dtable .m-chip, .tbl-stack .m-chip { grid-row: 1; grid-column: 10 / 13; justify-self: end; }
    .dtable .m-act,  .tbl-stack .m-act  {
        grid-row: 1; grid-column: 10 / 13; justify-self: end;
        display: flex; gap: 4px; align-items: center;
    }

    /* Line 2 — four equal muted tabular slots */
    .dtable .m-s1, .tbl-stack .m-s1 { grid-row: 2; grid-column: 1 / 4; }
    .dtable .m-s2, .tbl-stack .m-s2 { grid-row: 2; grid-column: 4 / 7; }
    .dtable .m-s3, .tbl-stack .m-s3 { grid-row: 2; grid-column: 7 / 10; }
    .dtable .m-s4, .tbl-stack .m-s4 { grid-row: 2; grid-column: 10 / 13; justify-self: end; }
    .dtable .m-s1, .dtable .m-s2, .dtable .m-s3, .dtable .m-s4,
    .tbl-stack .m-s1, .tbl-stack .m-s2, .tbl-stack .m-s3, .tbl-stack .m-s4 {
        font-size: var(--text-xs);
        color: var(--c-text-muted);
        font-variant-numeric: tabular-nums;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
        text-align: left;
    }
    /* Tiny inline label, only where the page supplies data-label */
    .dtable tbody td[class*="m-s"][data-label]::before,
    .tbl-stack tbody td[class*="m-s"][data-label]::before {
        content: attr(data-label) ' ';
        color: var(--c-text-faint);
        font-size: var(--text-2xs);
        text-transform: uppercase;
        margin-right: 3px;
    }

    /* Line 3 — clamped note */
    .dtable .m-note, .tbl-stack .m-note {
        grid-row: 3; grid-column: 1 / 13;
        font-size: var(--text-xs);
        color: var(--c-text-muted);
        display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
        overflow: hidden;
    }

    /* Columns not worth phone space */
    .dtable .m-off, .tbl-stack .m-off { display: none; }

    /* An em-dash placeholder earns a column on the desktop table (it tells you
       "nothing recorded" rather than leaving a hole) but not a LINE on a phone:
       a row with no dates, assignee or percentage rendered "—  —  —" as a whole
       second line. Drop the glyph and the slots collapse, so the row becomes a
       single 44px line. Convention applies to every page. */
    .dtable td[class*="m-s"] > .text-faint,
    .tbl-stack td[class*="m-s"] > .text-faint { display: none; }

    /* .m-full — an occasional cell that needs its own full-width line
       (grid-row auto keeps it after whatever came before). */
    .dtable .m-full, .tbl-stack .m-full { grid-column: 1 / 13; }
}

/* .defrow — the same idea for hand-built lists that are NOT tables
   (uploads rows, parking requests, bc visits). Line 1 = identifier +
   chip; following lines = ' · '-joined meta; actions become a full-width
   40px button row. Used by the utility pages instead of a sideways scroll. */
.defrow { display: none; }
@media (max-width: 640px) {
    .defrow {
        display: block;
        padding: 6px 0;
        border-bottom: 1px solid var(--c-border);
    }
    .defrow-top { display: flex; align-items: baseline; gap: 8px; }
    .defrow-id {
        flex: 1; min-width: 0;
        font-weight: 600; font-size: var(--text-base); color: var(--c-text);
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .defrow-meta {
        font-size: var(--text-xs); color: var(--c-text-muted);
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
        font-variant-numeric: tabular-nums;
    }
    .defrow-actions { display: flex; gap: 6px; margin-top: 5px; }
    .defrow-actions .btn { flex: 1; justify-content: center; min-height: var(--tap); }
    .defrow-hide-desktop { display: block; }
}
.defrow-only-mobile { display: none; }
@media (max-width: 640px) { .defrow-only-mobile { display: block; } .defrow-only-desktop { display: none; } }


/* ================================================================
   10  NUMBERS / MONO / TRUNCATION
   ----------------------------------------------------------------
   House law: money, dimensions and codes right-aligned + tabular.
   Unit lives in the column header, never repeated per cell.
   Delete the per-page .num copies in portal-electrical.css and
   portal-curtains.css once pages are migrated.
   ================================================================ */
td.num, th.num, .num {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}
/* `.dtable thead th{text-align:left}` in section 8 is (0,1,2) and out-specifies
   `th.num` (0,1,1), so every numeric column header rendered LEFT-aligned over
   right-aligned cells. Restated here at matching specificity. Page stylesheets
   must NOT carry their own `.xx-table thead th.num` copy. */
.dtable thead th.num,
.tbl thead th.num,
.tbl-stack thead th.num { text-align: right; }
.mono { font-family: var(--font-mono); font-size: var(--text-sm); }
.nowrap { white-space: nowrap; }

/* .clip / .cell-cap — cap a long DB string to one line; the contract is that
   every use ALSO emits title="<full text>". .cell-cap-2 clamps to two lines. */
.clip,
.cell-cap {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.clip { max-width: 22rem; }
.cell-cap-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    white-space: normal;
}


/* ================================================================
   11  BADGES & CHIPS
   ----------------------------------------------------------------
   One pill geometry, six semantic colour pairs. The existing class
   NAMES are all preserved so no template or JS changes; only the
   declarations move onto tokens — and the ones that were red for a
   non-failure move to amber.
   ================================================================ */
.badge, .chip {
    display: inline-block;
    font-size: var(--text-xs);
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    line-height: 1.4;
    white-space: nowrap;
}

/* Semantic set — use these for anything new */
.chip-ok      { background: var(--chip-ok-bg);      color: var(--chip-ok-fg); }
.chip-warn    { background: var(--chip-warn-bg);    color: var(--chip-warn-fg); }
.chip-danger  { background: var(--chip-danger-bg);  color: var(--chip-danger-fg); }
.chip-info    { background: var(--chip-info-bg);    color: var(--chip-info-fg); }
.chip-neutral { background: var(--chip-neutral-bg); color: var(--chip-neutral-fg); }
.chip-accent  { background: var(--chip-accent-bg);  color: var(--chip-accent-fg); }
/* aliases used by portal-electrical.css's provenance chips */
.chip--ok { background: var(--chip-ok-bg); color: var(--chip-ok-fg); }
.chip--warn { background: var(--chip-warn-bg); color: var(--chip-warn-fg); }
.chip--info { background: var(--chip-info-bg); color: var(--chip-info-fg); }

/* Status badges (existing names) mapped onto the semantic pairs */
.badge-completed    { background: var(--chip-ok-bg);      color: var(--chip-ok-fg); }
.badge-in_progress  { background: var(--chip-info-bg);    color: var(--chip-info-fg); }
.badge-delayed      { background: var(--chip-danger-bg);  color: var(--chip-danger-fg); }  /* genuine failure */
.badge-not_started  { background: var(--chip-neutral-bg); color: var(--chip-neutral-fg); }
.badge-on_hold      { background: var(--chip-warn-bg);    color: var(--chip-warn-fg); }
.badge-floor        { background: var(--chip-info-bg);    color: var(--chip-info-fg); font-weight: 500; }
/* NEW: "pending / not yet decided / queued" gets an amber home so red can stay
   reserved for failure. Consumers: curtains TBC, doors Differs + fire rating,
   electrical "to delete". */
.badge-tbc          { background: var(--chip-warn-bg);    color: var(--chip-warn-fg); }

/* Event types */
.badge-meeting    { background: var(--chip-info-bg);    color: var(--chip-info-fg); }
.badge-parking    { background: var(--chip-warn-bg);    color: var(--chip-warn-fg); }
.badge-site_visit { background: var(--chip-ok-bg);      color: var(--chip-ok-fg); }
.badge-delivery   { background: var(--chip-warn-bg);    color: var(--chip-warn-fg); }
.badge-deadline   { background: var(--chip-warn-bg);    color: var(--chip-warn-fg); }  /* a deadline is caution, not failure */
.badge-other      { background: var(--chip-neutral-bg); color: var(--chip-neutral-fg); }

.event-past { opacity: .55; }


/* ================================================================
   12  PILLS, PILL STRIPS, SUBNAV
   ================================================================ */
.filter-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.filter-pill {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0 12px;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--c-text-3);
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-pill);   /* genuine pill */
    text-decoration: none;
    transition: color .12s, border-color .12s, background .12s;
    cursor: pointer;
    white-space: nowrap;
}
.filter-pill:hover { color: var(--c-text); border-color: var(--c-border-strong); text-decoration: none; }
.filter-pill.active { background: var(--c-text-strong); color: var(--c-surface); border-color: var(--c-text-strong); }
.filter-pill .fp-count { margin-left: 5px; opacity: .65; font-variant-numeric: tabular-nums; }

/* .pill-strip — OPT-IN horizontal scroller for a genuinely long pill row (a
   17-category filter would otherwise wrap to nine rows).
   It is deliberately NOT applied to .filter-pills any more: its only consumers
   are /timeline (6 pills = 510px) and /queries (3), and clipping them to a
   362px strip put "Not Started" and "On Hold" — 18 of 28 milestones — off
   screen with no hint they existed. Two rows of pills cost ~46px; being unable
   to reach a filter costs the page. Pills WRAP by default. */
@media (max-width: 640px) {
    .filter-pills { flex-wrap: wrap; row-gap: 6px; }
    .pill-strip {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 4px;
        /* A right-edge fade so the cut reads as "more this way". */
        mask-image: linear-gradient(to right, #000 88%, transparent);
        -webkit-mask-image: linear-gradient(to right, #000 88%, transparent);
    }
    .pill-strip::-webkit-scrollbar { height: 0; }
    .pill-strip .filter-pill { scroll-snap-align: start; flex: 0 0 auto; }
}

/* .subnav — the canonical house sub-tab bar (submenu standard). .tab-nav /
   .tab-link are kept as thin aliases so portal-timeline.js's class toggling
   keeps working until the timeline markup migrates. */
.subnav,
.tab-nav {
    display: flex;
    gap: .25rem;
    border-bottom: 2px solid var(--c-border);
    margin-bottom: 12px;
    position: sticky;
    top: var(--h-header);
    background: var(--c-bg);
    z-index: 10;
    padding-top: .25rem;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}
.subnav-link,
.tab-link {
    /* inline-flex + min-height so a tab is a legal 40px tap target: as a plain
       inline anchor it measured 38px. */
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    padding: .5rem .75rem;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--c-text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color .1s, border-color .1s;
    white-space: nowrap;
    flex-shrink: 0;
    background: none;
    border-left: 0; border-right: 0; border-top: 0;
    cursor: pointer;
}
.subnav-link:hover, .tab-link:hover { color: var(--c-text-strong); text-decoration: none; }
.subnav-link.active, .tab-link.active { color: var(--c-primary); border-bottom-color: var(--c-primary); }
.subnav-count { font-size: var(--text-xs); opacity: .6; margin-left: .25rem; }
.subnav-link.active .subnav-count { opacity: .8; }
/* .subnav-secondary / .subnav-static — use one of these on any page that ALSO
   has sticky .section-heads. Both stick to top:var(--h-header) and .section-head
   (z-index 20) paints over the tab bar (z-index 10), so the two fight for the
   same 44px band; the heads win and the tab bar has to scroll away. */
.subnav-secondary { position: static; z-index: auto; border-bottom-width: 1px; }
.subnav-static, .subnav.subnav-static { position: static; z-index: auto; }


/* ----------------------------------------------------------------
   12b  CONTROL STRIP — the search + filter band
   ----------------------------------------------------------------
   A flat full-width band (hairline top and bottom, no bubble, no radius)
   holding a page's search box + filters + live count. Shared by /drawings,
   /cgi and /images and available to any list page.
   Markup contract: `<div class="ctl-strip filter-row">` so the input geometry
   and the <=640px 16px iOS-zoom guard come from section 14/26.
   At 390px the search takes its own full row and the remaining controls share
   the second — nothing is ever squeezed below its tap size.
   ---------------------------------------------------------------- */
.ctl-strip {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
    padding: 7px 0;
    margin: 0 0 10px;
    border-top: 1px solid var(--c-border);
    border-bottom: 1px solid var(--c-border);
}
/* Desktop only: a tighter control height than the 40px phone tap floor
   section 26 enforces at <=640px. Expressed as a min-width query so it can
   never beat that floor regardless of stylesheet load order. */
@media (min-width: 641px) {
    .ctl-strip input,
    .ctl-strip select { min-height: 30px; }
}
.ctl-search { flex: 1 1 16rem; min-width: 0; max-width: 26rem; }
.ctl-select { flex: 0 1 auto;  min-width: 0; max-width: 17rem; }
/* Label + toggle pills, kept out of .filter-pills so they are never turned into
   a scrolling strip. */
.ctl-seg   { display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto; }
/* .ctl-field — a labelled single input (the two date pickers on /images). */
.ctl-field { display: inline-flex; align-items: center; gap: 5px; flex: 0 1 auto; min-width: 0; }
.ctl-field input { min-width: 0; }
/* The two date pickers travel together: on a phone they share ONE row. */
.ctl-dates { display: inline-flex; align-items: center; gap: 8px; flex: 0 1 auto; min-width: 0; }
.ctl-label {
    font-size: var(--text-2xs);
    color: var(--c-text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
    white-space: nowrap;
}
.ctl-count {
    margin-left: auto;
    font-size: var(--text-xs);
    color: var(--c-text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
@media (max-width: 640px) {
    .ctl-search { flex: 1 1 100%; max-width: none; }
    .ctl-select { flex: 1 1 45%;  max-width: none; }
    .ctl-dates  { flex: 1 1 100%; }
    .ctl-dates .ctl-field { flex: 1 1 45%; }
    .ctl-field input { flex: 1 1 auto; }
    .ctl-count  { flex: 0 0 auto; }
}


/* ================================================================
   13  BUTTONS — ONE family, one radius
   ----------------------------------------------------------------
   (portal.css used to define .btn twice with different geometry;
   the first block was dead.)
   ================================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: .4rem .9rem;
    min-height: 32px;
    font-size: var(--text-base);
    font-weight: 600;
    font-family: inherit;
    color: var(--c-surface);
    background: var(--c-primary);
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--c-primary-hover); color: var(--c-surface); text-decoration: none; }
.btn:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--c-primary); color: var(--c-surface); }
.btn-primary:hover { background: var(--c-primary-hover); }
.btn-sm { padding: .25rem .6rem; min-height: 28px; font-size: var(--text-sm); }
.btn-outline {
    background: var(--c-surface);
    color: var(--c-text-2);
    border-color: var(--c-border-strong);
}
.btn-outline:hover { background: var(--c-bg); color: var(--c-text); }
.btn-danger { background: var(--c-danger); color: var(--c-surface); }
.btn-danger:hover { background: var(--c-danger-dark); }

/* .btn-icon — icon-only row action at a legal touch size (44x44 on mobile).
   Replaces the dead .action-cell sizing in portal-doors.css. */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    min-height: 32px;
    padding: 0;
    border-radius: var(--radius);
    font-size: var(--text-md);
    line-height: 1;
}

/* Downloads: Excel green, Word blue — always with an icon (www/icons2/). */
.btn-excel {
    display: inline-flex; align-items: center; gap: 5px;
    padding: .35rem .7rem; min-height: 30px;
    background: var(--c-excel); color: var(--c-surface);
    border: 1px solid var(--c-excel); border-radius: var(--radius);
    font-size: var(--text-sm); font-weight: 600;
    text-decoration: none; white-space: nowrap;
}
.btn-excel:hover { background: var(--c-excel-hover); border-color: var(--c-excel-hover); color: var(--c-surface); text-decoration: none; }
.btn-word {
    display: inline-flex; align-items: center; gap: 5px;
    padding: .35rem .7rem; min-height: 30px;
    background: var(--c-word); color: var(--c-surface);
    border: 1px solid var(--c-word); border-radius: var(--radius);
    font-size: var(--text-sm); font-weight: 600;
    text-decoration: none; white-space: nowrap;
}
.btn-word:hover { background: var(--c-word-hover); border-color: var(--c-word-hover); color: var(--c-surface); text-decoration: none; }
.btn-excel img, .btn-word img { height: 15px; width: 15px; display: block; }

/* HJS's own button class (hjs.js confirm dialogs) — keep it on the house look */
.hjs-btn { border-radius: var(--radius); font-family: inherit; }


/* ================================================================
   14  FORMS
   ----------------------------------------------------------------
   ONE definition (there used to be two: one inside a media query,
   one outside). The 16px mobile font-size is the iOS zoom-on-focus
   guard and is deliberately NOT tokenised — see section 26.
   ================================================================ */
.form-group { margin-bottom: var(--sp-3); }
.form-group label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--c-text-2);
    margin-bottom: 3px;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: .4rem .55rem;
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius);
    font-size: var(--text-base);
    font-family: inherit;
    color: var(--c-text);
    background: var(--c-surface);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 2px var(--c-primary-ring);
}
.form-row { display: flex; gap: var(--sp-3); }
.form-row .form-group { flex: 1; }

/* Inline filter row (images, future list pages) */
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-row input, .filter-row select {
    padding: .3rem .5rem;
    font-size: var(--text-base);
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius);
    font-family: inherit;
    background: var(--c-surface);
    color: var(--c-text);
}
.filter-row label { font-size: var(--text-2xs); color: var(--c-text-muted); text-transform: uppercase; letter-spacing: .03em; }

/* Date edit inputs (timeline edit log) */
.edit-dates-row {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 8px; padding: 6px 0;
    border-bottom: 1px solid var(--c-border);
}
.edit-dates-row label { font-size: var(--text-xs); color: var(--c-text-muted); font-weight: 600; }
.date-edit {
    padding: 3px 6px;
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius);
    font-size: var(--text-sm);
    font-family: inherit;
    width: 140px;
    background: var(--c-surface);
    color: var(--c-text);
}
.date-edit:focus { outline: none; border-color: var(--c-primary); }


/* ================================================================
   15  MODAL / BOTTOM SHEET
   ----------------------------------------------------------------
   ONE implementation. Both templates/portal-doors.tpl and
   templates/portal-electrical.tpl carry inline <style> copies of the
   mobile sheet override fighting this with !important — delete them;
   nothing here needs !important because there is only one definition.
   Toggle with the `hidden` attribute (see [hidden] in section 2)
   rather than inline style.display.
   ================================================================ */
.modal {
    position: fixed;
    inset: 0;
    background: var(--c-scrim);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-content {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: var(--sp-5);
    width: 100%;
    max-width: 480px;
    margin: 1rem;
    box-shadow: var(--shadow-md);
    max-height: 90vh;
    overflow-y: auto;
}
.modal-content h3 { margin: 0 0 var(--sp-3); font-size: var(--text-xl); }
.modal-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-4); }

/* .modal-note — the small explanatory line under a modal title.
   .modal-foot — the "Recorded as <user>" / "Editing as <user>" line.
   Both replaced inline-styled paragraphs; they belong here, not per page. */
.modal-note { font-size: var(--text-sm); color: var(--c-text-muted); margin-bottom: var(--sp-3); }
.modal-note strong { color: var(--c-text); font-variant-numeric: tabular-nums; }
.modal-foot { font-size: var(--text-xs); color: var(--c-text-muted); margin-top: var(--sp-2); }

/* .modal-sheet is implicit: at <=500px every .modal becomes a bottom sheet. */
@media (max-width: 500px) {
    .modal { align-items: flex-end; }
    .modal-content {
        padding: var(--sp-3);
        margin: 0;
        border-radius: 0;          /* flat, even as a sheet */
        max-width: 100%;
        width: 100%;
        max-height: 92dvh;
    }
    /* An 11-field sheet is taller than the viewport. Pin the title and the
       action row so Save/Cancel are visible the moment it opens and the title
       says what you are editing while you scroll — /electrical's Save used to
       sit at y=873 in an 844px viewport with no visible way out. Applies to
       every modal so the three field pages behave identically. */
    .modal-content > h3 {
        position: sticky;
        top: 0;
        z-index: 2;
        background: var(--c-surface);
        padding-bottom: 4px;
        border-bottom: 1px solid var(--c-border);
    }
    .modal-content > .modal-actions {
        position: sticky;
        bottom: 0;
        z-index: 2;
        margin-top: var(--sp-2);
        padding: 8px 0 2px;
        background: var(--c-surface);
        border-top: 1px solid var(--c-border);
    }
    .modal-content h3 { font-size: var(--text-md); margin-bottom: .4rem; }
    .modal-content .form-group { margin-bottom: .4rem; }
    .modal-content .form-group label { font-size: var(--text-2xs); }
    /* 16px is the iOS zoom-on-focus guard — do not tokenise. */
    .modal-content input, .modal-content select, .modal-content textarea {
        font-size: 16px;
        padding: .35rem .4rem;
    }
    .modal-content .form-row { flex-direction: column; gap: .3rem; }
    .modal-actions { gap: .4rem; }
    .modal-actions .btn { flex: 1; }
}


/* ================================================================
   16  BANNERS & EMPTY STATES
   ----------------------------------------------------------------
   House law forbids alert()/confirm(), so inline banners are the only
   feedback channel. Empty states are INSTRUCTIVE: one-line explainer
   plus an inline CTA, in a dense row — not 48px of centred whitespace.
   ================================================================ */
.banner {
    display: flex;
    gap: var(--sp-2);
    align-items: flex-start;
    padding: .5rem .75rem;
    font-size: var(--text-base);
    border-left: 3px solid var(--c-border-strong);
    border-radius: var(--radius);
    margin-bottom: var(--sp-3);
    background: var(--c-surface-2);
    color: var(--c-text-2);
}
.banner-ok,
.banner-success { background: var(--soft-ok);     border-left-color: var(--c-ok);      color: var(--chip-ok-fg); }
.banner-warn    { background: var(--soft-warn);   border-left-color: var(--c-warn-bright); color: var(--chip-warn-fg); }
.banner-danger,
.banner-error   { background: var(--soft-danger); border-left-color: var(--c-danger);  color: var(--chip-danger-fg); }
.banner-info    { background: var(--soft-info);   border-left-color: var(--c-primary); color: var(--chip-info-fg); }
/* -success / -error are the names HJS.banner(msg, type, {classBase}) generates,
   so the documented classBase route styles correctly instead of silently
   rendering an unstyled band.
   GOTCHA: HJS.banner() only clears el.style.display. A banner element that
   starts with the `hidden` ATTRIBUTE stays invisible because
   [hidden]{display:none!important} keeps winning — set `el.hidden = false`
   immediately before calling it (see portal-parking.js / portal-queries.js). */

/* .notice — a flat full-width intro band (no bubble, no radius) for the
   explanatory paragraph some pages open with. */
.notice {
    padding: 8px 0;
    border-top: 1px solid var(--c-border);
    border-bottom: 1px solid var(--c-border);
    margin-bottom: var(--sp-3);
    font-size: var(--text-sm);
    color: var(--c-text-2);
}
.notice p { margin-bottom: 4px; }
.notice p:last-child { margin-bottom: 0; }

/* Instructive empty states */
.empty {
    padding: var(--sp-4) 0;
    color: var(--c-text-muted);
    font-size: var(--text-base);
    max-width: 60ch;
}
.empty a { color: var(--c-primary); font-weight: 600; }

/* .empty-row — a single dense in-table/in-list empty row. */
.empty-row {
    padding: 10px 12px;
    font-size: var(--text-sm);
    color: var(--c-text-muted);
    border-bottom: 1px solid var(--c-border);
    display: flex;
    align-items: center;
    flex-wrap: wrap;          /* the inline CTA drops to its own row at 390px */
    gap: 10px;
    min-height: var(--tap);
}
.empty-row a {
    color: var(--c-primary); font-weight: 600; cursor: pointer;
    white-space: nowrap;      /* never split the CTA across two lines */
    display: inline-flex; align-items: center; min-height: var(--tap);
}

/* Legacy .empty-state — was 48px of centred padding inside a card bubble
   (half a phone screen). Restyled to the dense left-aligned form; the class
   stays because portal-timeline.tpl and portal-drawings.tpl still emit it. */
.empty-state {
    text-align: left;
    padding: var(--sp-4) 0;
    color: var(--c-text-muted);
    font-size: var(--text-base);
    max-width: 60ch;
}
.empty-state p { margin-bottom: var(--sp-3); }
.empty-state p:last-child { margin-bottom: 0; }
.card.empty-state { background: transparent; border: 0; }


/* ================================================================
   17  PROGRESS
   ================================================================ */
/* .pct-inline — the preferred form: a right-aligned tabular number with a 2px
   status-coloured underline at width:var(--pct). Set --pct and --pct-color
   inline per row. 0% should render a muted em-dash and no bar. */
.pct-inline {
    position: relative;
    display: block;
    text-align: right;
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
    color: var(--c-text);
    padding-bottom: 3px;
}
/* The empty TRACK. Without it the fill reads as a stray dash floating to the
   left of the number in a narrow right-aligned cell, detached from it. */
.pct-inline::before {
    content: '';
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 2px;
    background: var(--c-border);
}
.pct-inline::after {
    content: '';
    position: absolute;
    left: 0; bottom: 0;
    height: 2px;
    width: var(--pct, 0%);
    background: var(--pct-color, var(--c-info));
    border-radius: 0;
}

/* Legacy bar (timeline.php still builds it). Flattened: radius 0, shorter. */
.pct-bar {
    position: relative;
    background: var(--c-border);
    border-radius: var(--radius);
    height: 14px;
    min-width: 70px;
    overflow: hidden;
}
.pct-fill { height: 100%; border-radius: var(--radius); transition: width .3s ease; }
.pct-fill-completed   { background: var(--c-ok); }
.pct-fill-in_progress { background: var(--c-primary-lt); }
.pct-fill-delayed     { background: var(--c-danger-bright); }
.pct-fill-not_started { background: var(--c-border-strong); }
.pct-fill-on_hold     { background: var(--c-warn-bright); }
.pct-fill-danger      { background: var(--c-danger); }
.pct-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-2xs);
    font-weight: 600;
    color: var(--c-text-2);
}


/* ================================================================
   18  GANTT
   ================================================================ */
.gantt-section { margin-top: var(--sp-4); }
.gantt-section .phase-header { cursor: default; }
.gantt-container { overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 0 0 var(--sp-4); }
.gantt-chart { position: relative; min-width: 900px; padding: 0 20px 20px; background: var(--c-surface); }

.gantt-header { position: relative; height: 34px; border-bottom: 1px solid var(--c-border); }
.gantt-month {
    position: absolute; top: 0; height: 100%;
    display: flex; align-items: center; justify-content: center;
    font-size: var(--text-xs); font-weight: 600;
    color: var(--c-text-muted);
    text-transform: uppercase; letter-spacing: .3px;
    border-left: 1px solid var(--c-border);
}
.gantt-month:first-child { border-left: none; }

.gantt-grid { position: absolute; top: 34px; left: 20px; right: 20px; bottom: 20px; pointer-events: none; z-index: 1; }
.gantt-grid-line { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--c-border-soft); }

/* A rule line, not a status — red is correct here. */
.gantt-today { position: absolute; top: 34px; bottom: 20px; width: 2px; background: var(--c-danger-bright); z-index: 5; opacity: .6; }
.gantt-today::before {
    content: 'Today';
    position: absolute; top: -17px; left: -16px;
    font-size: var(--text-2xs); font-weight: 700;
    color: var(--c-danger-bright);
    text-transform: uppercase; white-space: nowrap;
}

.gantt-body { position: relative; z-index: 2; }
.gantt-row { display: flex; align-items: center; height: 30px; border-bottom: 1px solid var(--c-border-soft); }
.gantt-row:hover { background: var(--c-surface-2); }
.gantt-row-label {
    width: 200px; min-width: 200px;
    font-size: var(--text-sm); color: var(--c-text-2);
    padding-right: 12px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.gantt-row-bars { flex: 1; position: relative; height: 100%; }
.gantt-bar-planned {
    position: absolute; top: 6px; height: 18px;
    border-radius: var(--radius);
    opacity: .35; cursor: pointer; transition: opacity .15s; min-width: 4px;
}
.gantt-bar-planned:hover { opacity: .55; }
.gantt-bar-actual { position: absolute; top: 8px; height: 14px; border-radius: var(--radius); opacity: .85; min-width: 4px; }

.gantt-bar-completed          { background: var(--c-ok); }
.gantt-bar-in_progress        { background: var(--c-primary-lt); }
.gantt-bar-delayed            { background: var(--c-danger-bright); }
.gantt-bar-not_started        { background: var(--c-text-faint); }
.gantt-bar-on_hold            { background: var(--c-warn-bright); }
.gantt-bar-actual-completed   { background: var(--c-ok-dark); }
.gantt-bar-actual-in_progress { background: var(--c-primary-hover); }
.gantt-bar-actual-delayed     { background: var(--c-danger); }
.gantt-bar-actual-not_started { background: var(--c-text-muted); }
.gantt-bar-actual-on_hold     { background: var(--c-warn); }

.gantt-tooltip {
    position: fixed;
    background: var(--c-text);
    color: var(--c-surface-2);
    font-size: var(--text-sm);
    padding: 7px 10px;
    border-radius: var(--radius);
    pointer-events: none;
    z-index: 200;
    max-width: 280px;
    line-height: 1.45;
    box-shadow: var(--shadow-md);
}
.gantt-tooltip strong { display: block; margin-bottom: 2px; }
.gantt-tooltip .tooltip-dates { color: var(--c-text-faint); font-size: var(--text-xs); }


/* ================================================================
   19  COMMENTS
   ================================================================ */
.comment-dot {
    font-size: var(--text-2xs);
    background: var(--c-primary);
    color: var(--c-surface);
    border-radius: var(--radius-pill);   /* genuine pill */
    padding: 1px 5px;
    margin-left: 6px;
    vertical-align: middle;
}
.milestone-row[data-id] { cursor: pointer; }
/* Press feedback on the ROW, not its cells: once each <tr> is a grid row on the
   phone, a per-cell fill shows the 8px column-gap through as white vertical
   stripes across the tinted row. */
.milestone-row[data-id]:active { background: var(--soft-info); }
.comment-row td { background: var(--c-surface-2); border-top: none; padding: var(--sp-3) var(--sp-4); }
.comment-thread { margin-bottom: var(--sp-2); max-height: 300px; overflow-y: auto; }
.comment { padding: .35rem 0; border-bottom: 1px solid var(--c-border); }
.comment:last-child { border-bottom: none; }
.comment strong { font-size: var(--text-base); }
.comment p { margin: .15rem 0 0; font-size: var(--text-base); color: var(--c-text-2); }
.comment-input { display: flex; gap: .4rem; }
.comment-field {
    flex: 1;
    padding: .4rem .55rem;
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius);
    font-size: var(--text-base);
    font-family: inherit;
    background: var(--c-surface);
    color: var(--c-text);
}
.comment-field:focus { outline: none; border-color: var(--c-primary); }


/* ================================================================
   20  FILE TILES (drawings)
   ----------------------------------------------------------------
   Flat tile: white surface, 1px border, radius 0, a 3px left border
   coloured by file type, two lines of text. The old tile was #f8fafc
   on a white card on a grey page — three near-identical greys, which
   is why the catalogue read as washed out.
   At 390px: 2 columns, min-height 44px.
   ================================================================ */
.drawing-grid,
.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 8px;
    padding: 10px 0 4px;
    /* minmax(0,…) everywhere below: a grid item whose children are nowrap has a
       large min-content size, and a bare `1fr` (= minmax(auto,1fr)) lets it push
       the track — and the page — wider than the viewport. */
}

.drawing-item,
.file-tile {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    min-height: var(--tap-lg);
    padding: 6px 8px 6px 9px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-left: 3px solid var(--c-text-faint);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--c-text);
    transition: border-color .12s, background .12s;
}
.drawing-item:hover,
.file-tile:hover {
    border-color: var(--c-primary);
    background: var(--soft-info);
    text-decoration: none;
}
.file-tile.ft-pdf   { border-left-color: var(--c-text-3); }
.file-tile.ft-img   { border-left-color: var(--chip-info-fg); }
.file-tile.ft-xlsx  { border-left-color: var(--c-excel); }
.file-tile.ft-dwg   { border-left-color: var(--chip-accent-fg); }

/* Type token replaces the emoji glyph (which ignored the colour anyway, and was
   red — a reserved colour). Monospace, uppercase, tabular. */
.file-type,
.drawing-icon {
    flex: 0 0 auto;
    font-family: var(--font-mono);
    font-size: var(--text-2xs);
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--c-text-muted);
    width: 34px;
    text-align: center;
}
.drawing-icon.icon-img { color: var(--chip-info-fg); }
.file-thumb { flex: 0 0 auto; width: 40px; height: 28px; object-fit: cover; border: 1px solid var(--c-border); }

.drawing-info, .file-tile-info { flex: 1; min-width: 0; }
.drawing-label {
    font-size: var(--text-sm);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.drawing-number { font-family: var(--font-mono); color: var(--c-text-muted); margin-right: 5px; }
.drawing-meta {
    font-size: var(--text-xs);
    color: var(--c-text-muted);
    font-variant-numeric: tabular-nums;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* .ft-stack — two-line tile with the type token inline on the meta line.
   The horizontal .file-tile above spends a 34px gutter on the type; the
   drawing catalogue's names are 40-60 chars ("LIV-0284-CO5-Rev4 Window
   Treatment Schedule") and cannot afford a quarter of a 232px tile. */
.file-tile.ft-stack {
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    gap: 1px;
    padding: 5px 8px 5px 9px;
}
.ft-stack .drawing-label { font-size: var(--text-base); font-weight: 600; color: var(--c-text); }
.ft-stack .file-type {
    display: inline;
    width: auto;
    text-align: left;
    margin-right: 5px;
    color: var(--c-text-3);
}
.file-tile.ft-img .file-type { color: var(--chip-info-fg); }


/* ================================================================
   21  GALLERIES & LIGHTBOX
   ----------------------------------------------------------------
   One grid + one card for both /images (photos, 3:2) and /cgi
   (renders, 16:10 via .gallery-grid--wide). Fixed two-line info block
   so rows never go ragged. At <=500px: 2 columns.
   ================================================================ */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
}
.gallery-grid--wide { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.img-card, .media-card { min-width: 0; }

.img-card, .media-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: border-color .12s;
}
.img-card:hover, .media-card:hover { border-color: var(--c-primary); }
.img-card img, .media-card img {
    width: 100%;
    aspect-ratio: 3 / 2;
    height: auto;
    object-fit: cover;
    object-position: center;
    display: block;
}
.gallery-grid--wide .media-card img { aspect-ratio: 16 / 10; }
.img-info, .media-card-info { padding: 5px 7px; }
.img-desc, .media-desc {
    font-size: var(--text-sm);
    font-weight: 500;
    line-height: 1.3;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.img-meta, .media-meta {
    font-size: var(--text-xs);
    color: var(--c-text-muted);
    margin-top: 1px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* .lightbox — ONE overlay for both galleries. Flat, dark scrim, radius 0.
   Close only on the scrim / the x / Escape, never on a click that lands on the
   image. 44px targets; at <=640px the arrows become 48px edge zones. */
.lightbox {
    position: fixed;
    inset: 0;
    background: var(--c-scrim-heavy);
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
}
.lightbox-panel {
    position: relative;
    background: var(--c-photo-stage);
    padding: 8px;
    border-radius: 0;
    max-width: 96vw;
    max-height: 92dvh;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.lightbox-panel img { max-width: 100%; max-height: 80dvh; width: auto; object-fit: contain; margin: 0 auto; }
.lightbox-close {
    position: absolute;
    top: 4px; right: 6px;
    width: var(--tap-lg); height: var(--tap-lg);
    display: flex; align-items: center; justify-content: center;
    background: var(--c-scrim-soft);
    border: 0; border-radius: var(--radius);
    color: var(--c-white); font-size: var(--text-xl); line-height: 1; cursor: pointer;
}
/* Prev/next. The glyph MUST sit on an ink chip: as a bare white ❮ ❯ painted
   straight onto the photograph it disappeared over pale plasterboard on
   /images and a marble highlight on /cgi — i.e. the only way to move between
   images vanished at random. Matches the ✕ control, which already had a
   backing. 44x44 hit box, radius 0. */
.lightbox-nav {
    position: absolute; top: 50%;
    transform: translateY(-50%);
    width: var(--tap-lg); height: var(--tap-lg);
    display: flex; align-items: center; justify-content: center;
    background: var(--c-ink-scrim); border: 0; border-radius: var(--radius);
    cursor: pointer;
    color: var(--c-white); font-size: var(--text-2xl); line-height: 1;
}
.lightbox-nav:hover { background: var(--c-scrim-heavy); }
.lightbox-prev { left: 6px; }
.lightbox-next { right: 6px; }
.lightbox-bar {
    display: flex; align-items: center; gap: 12px;
    font-size: var(--text-xs); color: var(--c-ink-muted);
    padding: 0 2px;
}
.lightbox-bar a { color: var(--c-primary-lt); }
.lightbox-count { font-variant-numeric: tabular-nums; margin-left: auto; }
/* Caption bar: ONE row at any width. A 60-character AI description otherwise
   wrapped it to three lines on a phone and pushed the counter and the
   full-size link onto their own lines. */
.lightbox-bar .lb-title {
    flex: 1 1 auto; min-width: 0;
    color: var(--c-white);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lightbox-bar .lb-sub {
    flex: 0 1 auto; min-width: 0;
    color: var(--c-ink-faint);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lightbox-bar a, .lightbox-bar .lightbox-count { flex: 0 0 auto; white-space: nowrap; }
@media (max-width: 640px) {
    .lightbox-panel { max-width: 100vw; padding: 4px; }
    /* Caption takes line 1; date, full-size link and counter share line 2. */
    .lightbox-bar { gap: 2px 8px; flex-wrap: wrap; }
    .lightbox-bar .lb-title { flex: 1 1 100%; }
}


/* ================================================================
   22  DROP ZONE (uploads)
   ----------------------------------------------------------------
   Dense horizontal band (~72px), not 190px of empty dashes around an
   emoji. "browse" is a real .btn, not an 18px underlined label.
   NO dashed border: dashes-round-an-emoji is the upload cliche and reads
   as decoration, not as a control. Flat solid band + a 3px accent edge.
   (Both `.drag-over` — /uploads' own class — and `.drag` — the class
   HJS.wireDrop sets — are styled, so either wiring works.)
   ================================================================ */
.drop-zone, .dropzone {
    border: 1px solid var(--c-border-strong);
    border-left: 3px solid var(--c-primary);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin: 0 0 var(--sp-3);
    text-align: left;
    cursor: default;      /* only the button and a real drop are actions */
    transition: border-color .15s, background .15s;
    background: var(--c-surface);
}
/* Drag feedback has to be unmissable mid-drag: fill + accent border all round. */
.drop-zone.drag-over, .drop-zone.drag,
.dropzone.drag-over, .dropzone.is-drag, .dropzone.drag {
    border-color: var(--c-primary);
    border-left-color: var(--c-primary);
    background: var(--soft-info);
}
.drop-zone-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.drop-icon { font-size: var(--text-2xl); line-height: 1; flex: 0 0 auto; color: var(--c-text-muted); margin: 0; }
.drop-prompt { font-size: var(--text-base); font-weight: 600; color: var(--c-text); }
.drop-hint { font-size: var(--text-xs); color: var(--c-text-muted); }
/* "browse" — keep the class, but it should be marked up as .btn.btn-outline too. */
.drop-link {
    display: inline-flex; align-items: center;
    min-height: var(--tap);
    padding: 0 14px;
    color: var(--c-primary);
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius);
    background: var(--c-surface);
}
.drop-link:hover { background: var(--c-bg); text-decoration: none; }

/* Per-file upload progress rows */
.upload-row {
    display: flex; align-items: center; gap: 10px;
    padding: 5px 0;
    border-bottom: 1px solid var(--c-border-soft);
    font-size: var(--text-base);
}
.upload-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-size { color: var(--c-text-muted); font-size: var(--text-xs); min-width: 60px; text-align: right; font-variant-numeric: tabular-nums; }
.upload-bar { flex: 0 0 120px; height: 5px; background: var(--c-border); border-radius: var(--radius); overflow: hidden; }
.upload-fill { height: 100%; background: var(--c-primary); border-radius: var(--radius); width: 0; transition: width .2s; }
.upload-fill.is-done  { background: var(--c-ok); }
.upload-fill.is-error { background: var(--c-danger); }
.upload-status { font-size: var(--text-xs); color: var(--c-text-muted); min-width: 50px; }


/* ================================================================
   23  PAGER — real-URL pagination, rendered above AND below a grid
   ================================================================ */
.pager, .pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 0;
    font-size: var(--text-sm);
    flex-wrap: wrap;
}
.pager a, .pager span, .pagination a, .pagination span {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: var(--tap); padding: 0 10px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: var(--c-surface);
    color: var(--c-text-2);
    text-decoration: none;
}
.pager a:hover, .pagination a:hover { border-color: var(--c-primary); color: var(--c-primary); text-decoration: none; }
.pager .pg-now, .pagination .pg-now {
    font-weight: 600; color: var(--c-text);
    border-color: transparent; background: transparent;
    font-variant-numeric: tabular-nums;
}
/* .pg-off — an inert Newer/Older end-stop, so the pager does not jump about
   when you reach page 1. Deliberately low contrast: it is genuinely inert. */
.pager .pg-off, .pagination .pg-off {
    color: var(--c-text-faint);
    border-color: var(--c-border);
    background: var(--c-surface-2);
}


/* ================================================================
   24  404 — instructive, not a dead end
   ================================================================ */
.page-404 { padding: var(--sp-6) 0; max-width: 52ch; }
.page-404 h1 { font-size: var(--text-2xl); color: var(--c-text); margin-bottom: 4px; }
.page-404 .p404-code { font-size: var(--text-sm); color: var(--c-text-muted); font-variant-numeric: tabular-nums; }
.page-404 p { font-size: var(--text-base); color: var(--c-text-2); margin: var(--sp-3) 0; }
.page-404 .p404-links { display: flex; flex-wrap: wrap; gap: 6px 8px; font-size: var(--text-base); }


/* ================================================================
   25  MISC UTILITIES
   ================================================================ */
.hidden { display: none !important; }
.right { text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
/* Body scroll lock while the mobile nav drawer is open (portal-nav.js toggles it) */
body.nav-locked { overflow: hidden; }


/* ================================================================
   26  RESPONSIVE
   ================================================================ */

/* ---- Mobile nav: hamburger + drawer up to 1000px --------------------
   Was 768px, which left a 769-1000px dead zone: the nav is a fixed
   813px row, shared-base's overflow-x:clip clipped its right edge, and
   with no scroll container "Parking", "Building Control" and Sign out
   were invisible AND unreachable — sign-out impossible in a 900px window. */
@media (max-width: 1000px) {
    .portal-header {
        padding: 0 12px;
        height: var(--h-header-sm);
        flex-wrap: nowrap;
    }
    .portal-header .site-title { font-size: var(--text-md); }
    .portal-header .site-address { display: none; }
    .portal-here { max-width: 45vw; }
    /* The wordmark is the "back to the project" link; as a bare inline-flex
       anchor its hit box was 18px tall inside a 52px bar. */
    .portal-logo { min-height: var(--tap); padding-right: 6px; }

    .portal-nav-toggle { display: flex; }

    .portal-nav {
        display: none;
        position: fixed;
        top: var(--h-header-sm);
        left: 0; right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        margin: 0;
        height: auto;
        max-height: calc(100dvh - var(--h-header-sm));
        overflow-y: auto;
        overflow-x: hidden;
        background: var(--c-ink);
        border-top: 1px solid var(--c-ink-border);
        border-bottom: 1px solid var(--c-ink-border);
        box-shadow: var(--shadow-ink);
        padding: 2px 0 8px;
        z-index: 150;
    }
    .portal-nav.open { display: flex; }

    .portal-nav .nav-link,
    .portal-nav .nav-group-btn {
        width: 100%;
        height: auto;
        min-height: 46px;
        padding: 11px 16px;
        font-size: var(--text-md);
        justify-content: space-between;
        border-bottom: 1px solid var(--c-ink-border);
        border-left: 3px solid transparent;
    }
    .portal-nav .nav-link:hover,
    .portal-nav .nav-group-btn:hover { background: var(--c-ink-hover); }

    .portal-nav .nav-link.active,
    .portal-nav .nav-group.active > .nav-group-btn {
        border-bottom-color: var(--c-ink-border);
        border-left-color: var(--c-primary-lt);
        background: var(--c-ink-active);
    }

    /* Group expands inline (accordion) instead of floating */
    .nav-group { flex-direction: column; width: 100%; }
    .nav-group-menu {
        position: static;
        min-width: 0;
        border: 0;
        box-shadow: none;
        background: var(--c-ink-sunken);
        padding: 0;
    }
    .nav-sublink {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding: 11px 16px 11px 32px;
        font-size: var(--text-md);
        border-left: 3px solid transparent;
        border-bottom: 1px solid var(--c-ink-border);
    }
    .nav-sublink:last-child { border-bottom: 0; }
    .nav-sublink.active { border-left-color: var(--c-primary-lt); }

    .nav-user {
        order: 90;
        min-height: 40px;
        padding: 10px 16px;
        border-top: 1px solid var(--c-ink-border);
        font-size: var(--text-sm);
        color: var(--c-ink-faint);
    }
    .portal-nav .nav-signout {
        order: 99;
        margin-left: 0;
        padding-left: 16px;
        border-left: 3px solid transparent;
        border-top: 1px solid var(--c-ink-border);
        color: var(--c-ink-muted);
    }

    /* Sticky section heads sit under the taller mobile bar */
    .section-head, .phase-header, .category-header,
    .group-head, .subnav, .tab-nav { top: var(--h-header-sm); }

    /* Dimming scrim behind the open drawer, so the drawer reads as being OVER the
       page rather than part of it. Toggled by portal-nav.js via body.nav-locked
       (which also stops the page scrolling). No extra markup.
       z-index 90, NOT 140: .portal-header is z-index 100 and therefore its own
       stacking context, so the drawer's z-index 150 is scoped INSIDE it — a
       scrim above 100 paints over the whole header, drawer included, and the
       sublinks stop being hit-testable. It only has to cover page content
       (z-index auto), so 90 is correct. */
    body.nav-locked::after {
        content: '';
        position: fixed;
        inset: var(--h-header-sm) 0 0;
        background: var(--c-scrim);
        z-index: 90;
    }
}

/* ---- Tablet / small desktop ---- */
@media (max-width: 768px) {
    .container { padding: 12px 14px 32px; }
    h1 { font-size: var(--text-xl); }
    .drawing-grid, .tile-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
    .drawing-label, .drawing-meta { min-width: 0; }
    /* The Gantt is NOT hidden here any more. portal-timeline.css gives it a
       104px sticky label column and a 720px canvas, which works fine at 390px
       (one swipe shows six months) and is the most useful thing on the phone.
       The .gantt-* geometry it relies on (--g-label, .gantt-scale-row /
       .gantt-corner / .gantt-overlay, sticky .gantt-row-label, the deliberate
       z-index:auto on .gantt-row) lives in portal-timeline.css section 5 and
       should be lifted here if a second page ever needs a chart. */
    .gantt-row-label { width: 140px; min-width: 140px; }
}

/* ---- Phone: tap-target floor + iOS zoom guard ----------------------
   One block fixes every under-40px control measured in the audit:
   timeline's 33px +Add buttons and 32px filter pills, doors' 36x39 /
   38x41 row actions, electrical's 36x33 / 38x33, queries' 38px Send
   reply, curtains' 33px Excel link. */
@media (max-width: 640px) {
    .btn, .btn-sm, .btn-excel, .btn-word {
        min-height: var(--tap-lg);
        display: inline-flex;
        align-items: center;
    }
    .btn-icon { width: var(--tap-lg); height: var(--tap-lg); font-size: var(--text-xl); }
    .filter-pill { min-height: var(--tap); padding: 0 14px; }
    .drop-link { min-height: var(--tap-lg); }

    /* iOS Safari zooms the viewport when a focused input is under 16px, and the
       user then has to pinch back — 12 times on the /parking form. This is a
       HARD 16px, deliberately not a token. */
    .form-group input, .form-group select, .form-group textarea,
    .filter-row input, .filter-row select,
    .comment-field, .date-edit, .q-reply-input {
        font-size: 16px;
        min-height: var(--tap);
    }
    .date-edit { width: 100%; }
    .form-row { flex-direction: column; gap: var(--sp-2); }

    .page-head-actions, .page-title-row .page-head-actions { flex: 1 1 100%; margin-left: 0; }
    .sec-title { font-size: var(--text-md); }
    /* A collapsed group head IS the navigation of /drawings and /cgi on a phone
       (17 of them, everything starts collapsed), so it needs a real tap box. */
    .section-head, .phase-header, .category-header, .group-head {
        padding: 9px 0 8px;
        min-height: var(--tap);
        align-items: center;
    }
    .category-desc { display: none; }
    .category-source { max-width: 22ch; font-size: var(--text-2xs); }
    /* 17 group heads at 390px: the source string has no room beside the title. */
    .group-head .gh-src { display: none; }
}

@media (max-width: 500px) {
    .gallery-grid, .gallery-grid--wide { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
    .drawing-grid, .tile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
    .upload-bar { flex: 0 0 60px; }
}
