/* =====================================================================
   HTC Field design system
   Source: "HTC Field · PM app prototype" mockup.
   Load AFTER bootstrap.css and style.css.

   1. Tokens (light on :root, dark on body.dark — the existing dark toggle)
   2. Base
   3. hf-* components (new markup)
   4. Bridge: remaps the legacy theme (style.css) and per-page token sets
      (--d-*, --m-*) so pages that were not rewritten still match.
   ===================================================================== */

/* ---------- 1. Tokens ---------- */
:root {
    --brand: #1B5A96; --brand-soft: #E3EDF7; --brand-text: #1B5A96;
    --outer: #D8DFE6; --bg: #EEF1F4; --surface: #FFFFFF; --surface-2: #F5F7F9; --paper: #FFFFFF;
    --ink: #14202B; --muted: #55626F; --line: #D6DEE6; --focus: #1B5A96;
    --amber: #8F4405; --amber-bg: #FCEFD6;
    --red: #B42318; --red-bg: #FCE6E3;
    --green: #14713F; --green-bg: #E0F2E8;
    --slate: #3C4B5A; --slate-bg: #E2E7EC;
    --font: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-head: "Barlow Semi Condensed", "Barlow", system-ui, -apple-system, sans-serif;
    --content-w: 960px;   /* readable column on tablets / desktop; bars stay full width */
    --gutter: max(16px, calc((100vw - var(--content-w)) / 2 + 16px));
    --appbar-h: 64px;
    --safe-t: env(safe-area-inset-top, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
    color-scheme: light;
}
html body.dark {
    --brand: #22609E; --brand-soft: #1A3350; --brand-text: #9CC4EE;
    --outer: #080D12; --bg: #0F161D; --surface: #17212B; --surface-2: #1E2934; --paper: #E9EEF3;
    --ink: #E7EDF3; --muted: #9DABB8; --line: #2C3946; --focus: #9CC4EE;
    --amber: #F2B567; --amber-bg: #38290F;
    --red: #F49A90; --red-bg: #3B1A16;
    --green: #7FD3A3; --green-bg: #11321F;
    --slate: #BCC8D3; --slate-bg: #26323E;
    color-scheme: dark;
}

/* ---------- 2. Base ---------- */
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
html body {
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.4;
    color: var(--ink);
    background: var(--bg) !important;
    min-height: 100vh;
    height: auto;
}
html body h1, html body h2, html body h3, html body h4, html body h5, html body h6,
html body button, html body input, html body select, html body textarea, html body .btn {
    font-family: inherit;
}
html body :focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.hf-muted { color: var(--muted); }
.hf-mt { margin-top: 12px; }
.hf-sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- 3. Components ---------- */

/* app bar */
.hf-appbar {
    position: sticky; top: 0; z-index: 1020;
    background: var(--brand); color: #fff;
    display: flex; align-items: center; gap: 10px;
    padding: calc(10px + var(--safe-t)) 14px 10px;
    min-height: calc(var(--appbar-h) + var(--safe-t));
}
.hf-appbar h1 { font-family: var(--font-head); font-weight: 700; font-size: 22px; margin: 0; line-height: 1.1; color: #fff; }
.hf-appbar.root h1 { font-size: 28px; }
.hf-appbar .hf-titles { min-width: 0; flex: 1; }
.hf-appbar .hf-titles h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hf-appbar .sub { font-size: 14.5px; opacity: .88; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hf-appbar .hf-appbar-actions { display: flex; gap: 8px; margin-left: auto; flex: none; }
.hf-iconbtn {
    width: 44px; height: 44px; flex: none; border-radius: 12px; border: 0;
    background: rgba(255,255,255,.16); color: #fff;
    display: grid; place-items: center; position: relative; text-decoration: none;
}
.hf-iconbtn:hover, .hf-iconbtn:focus { color: #fff; background: rgba(255,255,255,.26); }
.hf-iconbtn .hf-badge { top: -4px; left: auto; right: -4px; }

.hf-main { padding: 16px 16px calc(120px + var(--safe-b)); }
.hf-h2 {
    font-family: var(--font-head); font-weight: 600; font-size: 20px; color: var(--ink);
    margin: 24px 2px 10px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.hf-h2:first-child { margin-top: 4px; }
.hf-h2 .n { font-family: var(--font); font-size: 14px; color: var(--muted); font-weight: 500; }
.hf-ph2 { font-family: var(--font-head); font-weight: 600; font-size: 19px; margin: 0 0 10px; color: var(--ink); }
.hf-empty { margin: 0 2px; color: var(--muted); font-size: 15px; }
.hf-emptybox { background: var(--surface); border: 1px dashed var(--line); border-radius: 14px; padding: 22px 16px; text-align: center; color: var(--muted); }
.hf-loading { color: var(--muted); font-size: 15px; padding: 12px 2px; }

/* counts */
.hf-counts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.hf-count {
    background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
    padding: 10px 4px 9px; text-align: center; min-height: 76px; color: var(--muted);
    text-decoration: none; display: block;
}
.hf-count:hover { color: var(--muted); }
.hf-count b { display: block; font-family: var(--font-head); font-weight: 700; font-size: 30px; line-height: 1; margin-bottom: 4px; color: var(--muted); }
.hf-count span { font-size: 13px; color: var(--muted); line-height: 1.15; display: block; }
.hf-count.hot b { color: var(--amber); }
.hf-count.bad b { color: var(--red); }
.hf-count.ok b { color: var(--brand-text); }

/* cards */
.hf-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.hf-card + .hf-card { margin-top: 10px; }
.hf-card.done { background: var(--surface-2); }
.hf-card.done .hf-cust { color: var(--muted); }
.hf-card.overdue { border-color: var(--red); }
.hf-card-main { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 14px 14px 10px; color: var(--ink); text-decoration: none; }
.hf-card-main:hover { color: var(--ink); }
.hf-when { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.hf-when b { font-family: var(--font-head); font-size: 20px; font-weight: 700; }
.hf-when span { color: var(--muted); font-weight: 600; font-size: 15px; }
.hf-when .hf-tag { margin-left: auto; }
.hf-card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.hf-jobnum { font-size: 13.5px; color: var(--muted); white-space: nowrap; }
.hf-cust { font-family: var(--font-head); font-weight: 600; font-size: 21px; line-height: 1.15; color: var(--ink); }
.hf-line { color: var(--muted); font-size: 15px; margin-top: 2px; }
.hf-warn { color: var(--amber); font-size: 14.5px; font-weight: 600; margin-top: 6px; display: flex; gap: 6px; align-items: center; }
.hf-card-actions { display: flex; gap: 8px; padding: 0 14px 14px; justify-content: flex-end; flex-wrap: wrap; }
.hf-card details.hf-more { border-top: 1px solid var(--line); margin: 0 14px; }
.hf-card details.hf-more > summary {
    list-style: none; cursor: pointer; min-height: 44px; display: flex; align-items: center; justify-content: space-between;
    color: var(--brand-text); font-weight: 600; font-size: 15px;
}
.hf-card details.hf-more > summary::-webkit-details-marker { display: none; }
.hf-card details.hf-more > summary svg { transition: transform .15s; }
.hf-card details[open].hf-more > summary svg { transform: rotate(90deg); }
.hf-card details.hf-more .hf-kv { margin: 0 0 14px; }

.hf-chip {
    display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 600;
    padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
    border: 1px solid var(--line); white-space: nowrap;
}
.hf-chip.amber { background: var(--amber-bg); color: var(--amber); border-color: transparent; }
.hf-chip.red { background: var(--red-bg); color: var(--red); border-color: transparent; }
.hf-chip.green { background: var(--green-bg); color: var(--green); border-color: transparent; }
.hf-chip.blue { background: var(--brand-soft); color: var(--brand-text); border-color: transparent; }
.hf-chip.slate { background: var(--slate-bg); color: var(--slate); border-color: transparent; }

/* buttons */
.hf-btn {
    min-height: 48px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
    background: var(--surface); color: var(--ink); font-weight: 600; font-size: 16px;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center;
    text-decoration: none; cursor: pointer; line-height: 1.15;
}
.hf-btn:hover, .hf-btn:focus { color: var(--ink); background: var(--surface-2); }
.hf-btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.hf-btn.primary:hover, .hf-btn.primary:focus { color: #fff; filter: brightness(1.08); background: var(--brand); }
.hf-btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.hf-btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.hf-btn.block { width: 100%; display: flex; }
.hf-btn.grow { flex: 1; }
.hf-btn.sq { width: 48px; padding: 0; flex: none; }
.hf-btn.sm { min-height: 40px; font-size: 15px; padding: 0 12px; }
.hf-btn:disabled, .hf-btn.disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }
.hf-linkbtn { background: none; border: 0; color: var(--brand-text); font-weight: 600; padding: 10px 0; min-height: 44px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.hf-linkbtn.danger { color: var(--red); }

/* search & filters */
.hf-search { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; min-height: 52px; color: var(--muted); }
.hf-search input { flex: 1; border: 0; background: none; min-height: 48px; font-size: 17px; color: var(--ink); outline: none; }
.hf-search:focus-within { outline: 3px solid var(--focus); outline-offset: 1px; }
.hf-filters { display: flex; gap: 8px; overflow-x: auto; margin: 12px -16px 0; padding: 0 16px 4px; scrollbar-width: none; }
.hf-filters::-webkit-scrollbar { display: none; }
.hf-fchip { flex: none; min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 15px; display: inline-flex; align-items: center; text-decoration: none; }
.hf-fchip .n { color: var(--muted); font-weight: 500; margin-left: 6px; }
.hf-fchip[aria-pressed="true"], .hf-fchip.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.hf-fchip[aria-pressed="true"] .n, .hf-fchip.on .n { color: inherit; opacity: .75; }
.hf-note { font-size: 14px; color: var(--muted); margin: 14px 2px 8px; }
/* Jobs tab: each card sits in a filterable wrapper, so space with gap instead of .hf-card + .hf-card */
.hf-joblist { display: grid; gap: 10px; }
.hf-joblist > [hidden] { display: none; }

.hf-row {
    display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; text-align: left;
    background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; min-height: 58px;
    color: var(--ink); text-decoration: none;
}
.hf-row:hover { color: var(--ink); }
.hf-row + .hf-row { margin-top: 8px; }
.hf-row b { display: block; font-weight: 600; }
.hf-row .hf-line { font-size: 14px; margin: 0; }
.hf-row > svg { flex: none; color: var(--muted); }

/* job hub */
.hf-quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.hf-quick .hf-btn { flex-direction: column; gap: 3px; min-height: 66px; font-size: 14.5px; color: var(--brand-text); }
.hf-quick .hf-btn.disabled { color: var(--muted); }
.hf-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.hf-panel + .hf-panel, .hf-panel + .hf-tasks, .hf-tasks + .hf-panel, .hf-panel + .hf-h2 { margin-top: 12px; }
.hf-panel.amber { background: var(--amber-bg); border-color: var(--amber); }
.hf-hero { width: 100%; aspect-ratio: 16 / 7; object-fit: cover; border-radius: 14px; display: block; margin-bottom: 12px; background: var(--surface-2); }
.hf-phasebar { display: grid; gap: 4px; margin: 12px 0 5px; }
.hf-phasebar div { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.hf-phasebar i { display: block; height: 100%; background: var(--brand-text); }
.hf-phaselabels { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.hf-nextline { margin: 12px 0 0; font-size: 16px; }
.hf-kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 15px; margin: 12px 0 0; }
.hf-kv dt { color: var(--muted); font-weight: 400; }
.hf-kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.hf-kv dd.money { color: var(--green); font-weight: 700; }

.hf-tasks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.hf-task {
    background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 10px; text-align: left;
    min-height: 112px; display: flex; flex-direction: column; gap: 5px; color: var(--ink); text-decoration: none;
}
.hf-task:hover { color: var(--ink); }
.hf-task > svg { color: var(--brand-text); }
.hf-task .tn { font-family: var(--font-head); font-weight: 600; font-size: 19px; line-height: 1.1; margin-top: auto; }
.hf-task .ts { font-size: 13.5px; font-weight: 600; color: var(--muted); display: flex; gap: 4px; align-items: center; line-height: 1.2; }
.hf-task.amber { background: var(--amber-bg); border-color: var(--amber); }
.hf-task.amber .ts, .hf-task.amber > svg { color: var(--amber); }
.hf-task.green .ts { color: var(--green); }
.hf-task.muted { background: var(--surface-2); }
.hf-task.muted > svg { color: var(--muted); }
.hf-task.wide { grid-column: 1 / -1; flex-direction: row; align-items: center; gap: 12px; min-height: 76px; }
.hf-task.wide .tn { margin-top: 0; display: block; }
.hf-task.wide .ts { margin-top: 3px; }

details.hf-panel > summary {
    list-style: none; font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 8px;
    min-height: 30px; cursor: pointer; font-size: 16.5px; color: var(--ink);
}
details.hf-panel > summary::-webkit-details-marker { display: none; }
details.hf-panel > summary svg.chev { color: var(--muted); transition: transform .15s; flex: none; }
details[open].hf-panel > summary svg.chev { transform: rotate(90deg); }
details.hf-panel p { margin: 10px 0 0; color: var(--ink); }
.hf-docs { margin-top: 12px; }
.hf-docs .hf-row { min-height: 52px; }

.hf-addnote { display: flex; gap: 8px; }
.hf-addnote input { flex: 1; }
.hf-acts { list-style: none; margin: 12px 0 0; padding: 0; }
.hf-acts li { padding: 10px 0; border-top: 1px solid var(--line); font-size: 15px; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; }
.hf-acts li .when { color: var(--muted); font-size: 13.5px; white-space: nowrap; }
.hf-acts li .who { font-weight: 600; }
.hf-acts li.step { color: var(--muted); }

/* steps */
.hf-pbar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin: 10px 0 4px; }
.hf-pbar i { display: block; height: 100%; background: var(--brand-text); }
.hf-step { display: flex; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); align-items: flex-start; }
.hf-step:first-of-type { margin-top: 8px; }
.hf-si { width: 28px; height: 28px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 12px; }
.hf-si.done { background: var(--green-bg); color: var(--green); }
.hf-si.next { background: var(--brand); color: #fff; }
.hf-si.todo { border: 2px solid var(--line); }
.hf-step .sn { font-weight: 600; }
.hf-step .sm { font-size: 14px; color: var(--muted); }
.hf-tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 1px 7px; border-radius: 6px; background: var(--brand-soft); color: var(--brand-text); margin-left: 6px; vertical-align: 1px; }
.hf-tag.solid { background: var(--brand); color: #fff; }
.hf-tag.red { background: var(--red-bg); color: var(--red); }

/* photos */
.hf-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.hf-ph {
    aspect-ratio: 1; border-radius: 10px; border: 0; position: relative; display: block; padding: 0; overflow: hidden;
    background: var(--slate-bg); color: var(--slate);
}
.hf-ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hf-ph small { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 7px 5px; font-size: 12px; font-weight: 600; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.55)); text-align: left; }
.hf-ph .hf-ph-del {
    position: absolute; top: 5px; right: 5px; width: 34px; height: 34px; border-radius: 9px; border: 0;
    background: rgba(8,14,20,.6); color: #fff; display: grid; place-items: center;
}
.hf-ph .hf-ph-flag { position: absolute; top: 6px; left: 6px; }
.hf-banner { background: var(--brand-soft); color: var(--brand-text); border-radius: 12px; padding: 12px 14px; font-weight: 500; margin-bottom: 12px; }
.hf-banner.amber { background: var(--amber-bg); color: var(--amber); }
.hf-banner.green { background: var(--green-bg); color: var(--green); }
.hf-banner.red { background: var(--red-bg); color: var(--red); }
.hf-gh { display: flex; justify-content: space-between; align-items: baseline; margin: 18px 2px 8px; }
.hf-gh b { font-family: var(--font-head); font-size: 18px; font-weight: 600; }
.hf-cover { display: flex; gap: 14px; align-items: center; }
.hf-cover .hf-cover-img { width: 76px; height: 76px; border-radius: 12px; object-fit: cover; flex: none; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; color: var(--muted); overflow: hidden; }
.hf-cover .hf-cover-img img { width: 100%; height: 100%; object-fit: cover; }

/* forms */
.hf-lbl { display: block; font-weight: 600; margin: 16px 0 8px; color: var(--ink); }
.hf-lbl:first-child { margin-top: 0; }
.hf-lbl .req { color: var(--red); }
.hf-field { margin-top: 14px; }
.hf-field label { display: block; font-weight: 600; margin-bottom: 6px; }
.hf-input, .hf-main textarea, .hf-main input[type="text"], .hf-main input[type="number"], .hf-main input[type="email"], .hf-main input[type="tel"], .hf-main input[type="date"], .hf-main select {
    width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
    color: var(--ink); min-height: 48px; font-size: 16px;
}
.hf-main textarea { min-height: 92px; resize: vertical; }
.hf-main .is-invalid { border-color: var(--red) !important; }
.hf-hint { font-size: 14px; color: var(--muted); margin: 6px 0 0; }
.hf-valmsg { color: var(--red); font-size: 14px; font-weight: 600; margin-top: 6px; display: none; }

/* segmented control — buttons or radio inputs (input + label) */
.hf-seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.hf-seg > button, .hf-seg > label {
    min-height: 48px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
    font-weight: 600; padding: 0 6px; display: grid; place-items: center; text-align: center; cursor: pointer; margin: 0; line-height: 1.15;
}
.hf-seg > input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.hf-seg > input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }
.hf-seg > button[aria-pressed="true"], .hf-seg > input:checked + label { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.hf-seg > input.pass:checked + label { background: var(--green-bg); color: var(--green); border: 2px solid var(--green); }
.hf-seg > input.fail:checked + label { background: var(--red-bg); color: var(--red); border: 2px solid var(--red); }
.hf-seg > input.na:checked + label { background: var(--surface-2); color: var(--ink); border: 2px solid var(--muted); }
.hf-seg.wrap { grid-auto-flow: row; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.was-validated .hf-seg > input:invalid + label { border-color: var(--red); }

.hf-stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.hf-stepper button { width: 56px; height: 50px; border: 0; background: var(--surface-2); color: var(--ink); display: grid; place-items: center; }
.hf-stepper input { width: 84px !important; min-height: 50px !important; text-align: center; font-weight: 700; font-size: 18px !important; border: 0 !important; border-radius: 0 !important; background: var(--surface) !important; -moz-appearance: textfield; }
.hf-stepper input::-webkit-inner-spin-button, .hf-stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* switch: <label class="hf-switch"><span>Text</span><input type="checkbox"><span class="knob"></span></label> */
.hf-switch {
    display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; background: none; border: 0;
    padding: 12px 0; min-height: 54px; text-align: left; font-weight: 600; color: var(--ink); cursor: pointer; margin: 0; position: relative;
}
.hf-switch + .hf-switch { border-top: 1px solid var(--line); }
.hf-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.hf-switch .knob { width: 50px; height: 30px; border-radius: 15px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.hf-switch .knob::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.hf-switch input:checked + .knob { background: var(--green); }
.hf-switch input:checked + .knob::after { transform: translateX(20px); }
.hf-switch input:focus-visible + .knob { outline: 3px solid var(--focus); outline-offset: 2px; }

.hf-errors { background: var(--red-bg); color: var(--red); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.hf-errors b { display: block; margin-bottom: 4px; }
.hf-errors ul { margin: 0; padding-left: 20px; }

/* uploaded file tiles (measure sheet pages) */
.hf-pgs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.hf-pg { margin: 0; position: relative; }
.hf-pg .hf-pg-img { aspect-ratio: 85 / 110; border-radius: 6px; border: 1px solid var(--line); background: var(--paper); overflow: hidden; display: grid; place-items: center; color: var(--muted); }
.hf-pg .hf-pg-img img { width: 100%; height: 100%; object-fit: cover; }
.hf-pg figcaption { font-size: 12.5px; color: var(--muted); margin-top: 4px; display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }
.hf-pg figcaption svg { color: var(--green); }
.hf-pg .hf-ph-del { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border-radius: 8px; border: 0; background: rgba(8,14,20,.6); color: #fff; display: grid; place-items: center; }
.hf-drop { position: relative; }
.hf-drop input[type=file] { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

/* QC */
.hf-stages { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.hf-stage { border: 0; background: none; text-align: left; padding: 4px 0; font-size: 13.5px; color: var(--muted); min-height: 44px; text-decoration: none; display: block; }
.hf-stage i { display: block; height: 6px; border-radius: 3px; background: var(--line); margin-bottom: 6px; }
.hf-stage.on i, .hf-stage.past i { background: var(--brand-text); }
.hf-stage.on { color: var(--ink); font-weight: 700; }
.hf-ci { padding: 12px 0; border-top: 1px solid var(--line); }
.hf-ci:first-of-type { border-top: 0; padding-top: 0; }
.hf-ci p { margin: 0 0 8px; font-weight: 500; color: var(--ink); }
.hf-ci p .num { color: var(--muted); font-weight: 600; margin-right: 4px; }
.hf-cert { font-size: 16px; line-height: 1.5; margin: 0; }
.hf-sigbox {
    width: 100%; height: 150px; border: 2px dashed var(--line); border-radius: 12px; background: var(--surface-2);
    display: grid; place-items: center; color: var(--muted); margin-top: 6px; overflow: hidden; cursor: pointer;
}
.hf-sigbox img { max-width: 100%; max-height: 100%; background: #fff; }
.hf-sig { width: 100%; height: 240px; border: 2px dashed var(--line); border-radius: 12px; background: #fff; touch-action: none; display: block; }
.hf-sigrow { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }

/* bottom bars */
.hf-tabbar, .hf-actionbar {
    position: fixed; bottom: 0; background: var(--surface); border-top: 1px solid var(--line);
    z-index: 1030; padding-bottom: var(--safe-b);
}
.hf-tabbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
.hf-actionbar { display: flex; gap: 8px; padding: 10px 16px calc(10px + var(--safe-b)); }
.hf-tab {
    background: none; border: 0; min-height: 62px; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; font-size: 13px; color: var(--muted); position: relative; font-weight: 500; text-decoration: none;
}
.hf-tab:hover { color: var(--ink); }
.hf-tab[aria-current="page"] { color: var(--brand-text); font-weight: 700; }
.hf-badge {
    position: absolute; top: 7px; left: calc(50% + 6px); background: var(--red); color: #fff; font-size: 11.5px; font-weight: 700;
    min-width: 19px; height: 19px; border-radius: 10px; display: grid; place-items: center; padding: 0 5px; line-height: 1;
}
body.dark .hf-badge { color: #2A0D09; }

/* sheets (Bootstrap offcanvas-bottom with .hf-sheet) */
.offcanvas.hf-sheet {
    background: var(--surface); color: var(--ink); border: 0 !important; border-radius: 20px 20px 0 0;
    max-width: 640px; margin: 0 auto; height: auto !important; max-height: 90vh;
    padding: 8px 16px calc(18px + var(--safe-b));
}
.offcanvas.hf-sheet .offcanvas-body { padding: 0; overflow: auto; }
.hf-grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.hf-sheet h3 { font-family: var(--font-head); font-weight: 600; font-size: 22px; margin: 0 0 12px; color: var(--ink); }
.hf-sheet-actions { display: flex; gap: 8px; margin-top: 16px; }
.hf-profile { display: flex; gap: 14px; align-items: center; }
.hf-avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-family: var(--font-head); font-weight: 700; font-size: 22px; flex: none; }
.hf-panel ol { margin: 8px 0 0; padding-left: 22px; }
.hf-panel ol li { margin: 4px 0; list-style: decimal; display: list-item; }

/* modal (signature) */
.hf-modal .modal-content { background: var(--surface); color: var(--ink); border: 0; border-radius: 20px; }
.hf-modal .modal-header { border-bottom: 1px solid var(--line); }
.hf-modal .modal-title { font-family: var(--font-head); font-weight: 600; font-size: 22px; }

/* toast */
.hf-toast {
    position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(92px + var(--safe-b)); background: var(--ink); color: var(--surface);
    padding: 12px 16px; border-radius: 12px; z-index: 2000; width: max-content; max-width: min(440px, calc(100% - 32px));
    font-weight: 500; box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
.hf-toast[hidden] { display: none; }

/* upload progress */
.hf-progress { margin-top: 10px; }
.hf-progress .lbl { font-size: 14px; color: var(--muted); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hf-progress .bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.hf-progress .bar i { display: block; height: 100%; width: 0; background: var(--brand-text); transition: width .15s; }
.hf-progress.err .bar i { background: var(--red); }
.hf-progress.err .lbl { color: var(--red); }

/* mic / recording */
.hf-rec { display: none; align-items: center; gap: 8px; color: var(--red); font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.hf-rec .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--red); animation: hf-pulse 1s infinite; }
.hf-mic.recording { color: var(--red); border-color: var(--red); background: var(--red-bg); animation: hf-pulse 1s infinite; }
@keyframes hf-pulse { 0%, 100% { opacity: 1 } 50% { opacity: .45 } }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- 4. Bridge: legacy theme + per-page tokens ---------- */

/* style.css uses "r, g, b" triplets */
html body {
    --theme-color: 27, 90, 150;
    --title-color: 20, 32, 43;
    --content-color: 85, 98, 111;
    --box-bg: 245, 247, 249;
    --line-color: 214, 222, 230;
    --success-color: 20, 113, 63;
    --error-color: 180, 35, 24;
    --white: 255, 255, 255;
    --black: 0, 0, 0;
}
html body.dark {
    --theme-color: 156, 196, 238;
    --title-color: 231, 237, 243;
    --content-color: 157, 171, 184;
    --box-bg: 30, 41, 52;
    --line-color: 44, 57, 70;
    --success-color: 127, 211, 163;
    --error-color: 244, 154, 144;
    --white: 23, 33, 43;
    --black: 255, 255, 255;
}

/* Detail pages (Sales / Installation) — --d-* tokens */
html body {
    --d-brand: var(--brand); --d-brand-light: var(--brand-soft); --d-brand-dark: var(--brand);
    --d-success: var(--green); --d-success-bg: var(--green-bg);
    --d-danger: var(--red); --d-danger-bg: var(--red-bg);
    --d-warning: var(--amber); --d-warning-bg: var(--amber-bg);
    --d-info: var(--brand-text); --d-info-bg: var(--brand-soft);
    --d-surface: var(--surface); --d-bg: var(--bg); --d-border: var(--line);
    --d-text: var(--ink); --d-muted: var(--muted);
    --d-radius: 14px; --d-radius-sm: 10px;
    --d-shadow: 0 0 0 1px var(--line);
    --m-brand: var(--brand); --m-brand-light: var(--brand-soft); --m-brand-dark: var(--brand);
    --m-success: var(--green); --m-success-bg: var(--green-bg); --m-danger: var(--red);
    --m-surface: var(--surface); --m-bg: var(--bg); --m-border: var(--line);
    --m-text: var(--ink); --m-muted: var(--muted);
    --m-radius: 14px; --m-radius-sm: 10px;
    --m-shadow: 0 0 0 1px var(--line);
}
html body.dark {
    --d-brand: var(--brand); --d-brand-light: var(--brand-soft); --d-brand-dark: var(--brand);
    --d-success: var(--green); --d-success-bg: var(--green-bg);
    --d-danger: var(--red); --d-danger-bg: var(--red-bg);
    --d-warning: var(--amber); --d-warning-bg: var(--amber-bg);
    --d-info: var(--brand-text); --d-info-bg: var(--brand-soft);
    --d-surface: var(--surface); --d-bg: var(--bg); --d-border: var(--line);
    --d-text: var(--ink); --d-muted: var(--muted);
    --d-shadow: 0 0 0 1px var(--line);
    --m-brand: var(--brand); --m-brand-light: var(--brand-soft); --m-brand-dark: var(--brand);
    --m-success: var(--green); --m-success-bg: var(--green-bg); --m-danger: var(--red);
    --m-surface: var(--surface); --m-bg: var(--bg); --m-border: var(--line);
    --m-text: var(--ink); --m-muted: var(--muted);
    --m-shadow: 0 0 0 1px var(--line);
}

/* Top bars: template .main-header and the .d-topbar / .m-topbar used by detail pages */
html body .main-header {
    background: var(--brand) !important; box-shadow: none !important;
    padding-top: var(--safe-t) !important; z-index: 1020;
}
html body .main-header .header-panel { min-height: var(--appbar-h); padding: 10px 0 !important; justify-content: flex-start; gap: 10px; }
html body .main-header .custom-container { padding: 0 14px !important; }
html body .main-header .header-panel h3, html body .main-header .header-panel h2 {
    font-family: var(--font-head) !important; font-weight: 700 !important; font-size: 22px !important; line-height: 1.1 !important;
    color: #fff !important; margin: 0 !important; position: static !important; transform: none !important; text-align: left; flex: 1;
}
html body .main-header .header-panel > a, html body .main-header .header-panel > button {
    width: 44px !important; height: 44px !important; border-radius: 12px !important; background: rgba(255,255,255,.16) !important; flex: none;
}
html body .d-topbar, html body .m-topbar {
    background: var(--brand) !important; box-shadow: none !important; min-height: calc(var(--appbar-h) + var(--safe-t));
    padding: calc(10px + var(--safe-t)) 14px 10px !important; gap: 10px !important; max-width: none !important; z-index: 1020;
}
html body .d-topbar h1, html body .m-topbar h1 { font-family: var(--font-head) !important; font-weight: 700 !important; font-size: 22px !important; line-height: 1.1 !important; }
html body .d-topbar .d-back, html body .m-topbar .m-back { width: 44px !important; height: 44px !important; border-radius: 12px !important; background: rgba(255,255,255,.16) !important; }
html body .section-lg-t-space { padding-top: calc(var(--appbar-h) + var(--safe-t) + 16px); }
html body .panel-space { padding-top: 90px !important; }

/* Legacy bottom bars */
html body .d-bottom-bar, html body .m-bottom-bar, html body .fixed-button {
    background: var(--surface) !important; border-top: 1px solid var(--line) !important; box-shadow: none !important; border-radius: 0 !important;
    padding: 10px 16px calc(10px + var(--safe-b)) !important;
}

/* Legacy buttons, inputs, titles */
html body .btn { border-radius: 10px; font-weight: 600; }
html body .theme-btn { background: var(--brand) !important; border: 1px solid var(--brand) !important; color: #fff !important; min-height: 48px; }
html body .outline-btn { background: var(--surface) !important; border: 1px solid var(--line) !important; color: var(--ink) !important; min-height: 48px; }
html body .outline-btn:hover { background: var(--surface-2) !important; }
html body .btn-sm.theme-btn, html body .btn-sm.outline-btn { min-height: 40px; }
html body .m-btn-success, html body .d-btn-primary { border-radius: 10px !important; min-height: 48px; }
html body .form-control, html body .form-select {
    border-radius: 10px; border-color: var(--line); background-color: var(--surface); color: var(--ink); min-height: 48px; font-size: 16px;
}
html body textarea.form-control { min-height: 92px; }
html body .form-control:focus, html body .form-select:focus { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
html body .title h2, html body .title h3, html body .title h5 { font-family: var(--font-head); font-weight: 600; font-size: 20px; color: var(--ink); }
html body .form-section { background: var(--surface) !important; border-color: var(--line) !important; border-radius: 14px !important; }
html body .q-label { color: var(--ink) !important; }
html body .wizard-progress-fill { background: var(--brand-text) !important; }
html body .alert { border-radius: 12px; border: 0; font-weight: 500; }
html body .alert-success { background: var(--green-bg); color: var(--green); }
html body .alert-warning { background: var(--amber-bg); color: var(--amber); }
html body .alert-danger { background: var(--red-bg); color: var(--red); }
html body .alert-info { background: var(--brand-soft); color: var(--brand-text); }
html body .progress { height: 6px; border-radius: 3px; background: var(--line); }
html body .progress-bar { background-color: var(--brand-text); }
html body .modal-content { border-radius: 20px; border: 0; background: var(--surface); color: var(--ink); }
html body .loading { color: var(--muted); }

/* Legacy agenda cards still used by Installer / Sales lists */
html body .pm-evt-card, html body .sa-card { background: var(--surface) !important; border: 1px solid var(--line) !important; border-radius: 14px !important; box-shadow: none !important; transform: none !important; }
html body .pm-evt-title, html body .pm-day-full { color: var(--ink) !important; font-family: var(--font-head); font-size: 19px !important; }
html body .pm-date-block { background: var(--ink) !important; color: var(--surface) !important; border-radius: 10px !important; }
html body .pm-date-block.today-block { background: var(--brand) !important; color: #fff !important; }
html body .pm-oc-val { color: var(--ink) !important; }
html body .pm-proj-link, html body .pm-toggle { color: var(--brand-text) !important; }

/* Legacy sections rendered inside the new root layout */
.hf-main .section-lg-t-space, .hf-main section:not(.hf-panel) { padding-top: 0; }
.hf-main .section-b-space { padding-bottom: 0; }
.hf-main .custom-container { padding: 0; }
.hf-main > .section-lg-t-space:first-child h4 { font-family: var(--font-head); font-size: 22px; font-weight: 700; }
.hf-ph > a { display: block; width: 100%; height: 100%; }
.hf-main .loading { color: var(--muted); padding: 12px 2px; margin: 0 !important; }
.hf-card-aside { float: right; width: 64px; height: 64px; margin: 0 0 6px 12px; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.hf-card-aside img { width: 100% !important; height: 100% !important; max-height: none !important; object-fit: cover; display: block; }
.hf-card-aside .loading { font-size: 0; }
.hf-card-main::after { content: ""; display: block; clear: both; }

/* Detail-page pieces (Sales / Installation) */
html body .d-divider, html body .m-divider {
    font-family: var(--font-head); font-size: 20px; font-weight: 600; letter-spacing: 0; text-transform: none;
    color: var(--ink); padding: 8px 2px 0;
}
html body .d-card-label, html body .m-card-label, html body .d-card-head .d-card-label {
    font-family: var(--font-head); font-size: 19px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--ink);
}
html body .d-info-label, html body .d-meta-label { font-size: 13px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--muted); }
html body .d-info-val, html body .d-meta-val { font-size: 15px; color: var(--ink); }
html body .d-status-chip, html body .d-status-trigger {
    background: rgba(255,255,255,.16) !important; border: 0 !important; border-radius: 12px !important; color: #fff !important;
    min-height: 44px; padding: 0 12px !important; font-size: 14px !important; font-weight: 600 !important; display: inline-flex; align-items: center;
}
html body .d-call-btn { border-radius: 10px; border-color: transparent; min-height: 44px; }
html body .d-upload-zone, html body .m-upload-zone { border-radius: 12px; border-color: var(--line); }

/* Any remaining Bootstrap bottom offcanvas reads as a sheet */
html body .offcanvas-bottom {
    background: var(--surface); color: var(--ink); border: 0; border-radius: 20px 20px 0 0;
    max-width: 640px; margin: 0 auto; height: auto; max-height: 90vh;
}
html body .offcanvas-bottom .offcanvas-title { font-family: var(--font-head); font-weight: 600; font-size: 22px; }

/* Responsive: content sits in a centered column on wide screens; bars span the full width */
.hf-main { max-width: var(--content-w); margin: 0 auto; }
.hf-appbar { padding-left: var(--gutter); padding-right: var(--gutter); }
.hf-actionbar { left: 0; right: 0; padding-left: var(--gutter); padding-right: var(--gutter); }
.hf-tabbar { left: 0; right: 0; }
@media (min-width: 768px) {
    .hf-tabbar { padding-left: var(--gutter); padding-right: var(--gutter); }
    .hf-tasks { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
    .hf-pgs { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
    .hf-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

/* Profile side panel (offcanvas-start) */
.offcanvas.hf-side { background: var(--bg); color: var(--ink); border: 0; width: min(360px, 88vw); }
.offcanvas.hf-side .offcanvas-header { background: var(--brand); color: #fff; padding: calc(14px + var(--safe-t)) 16px 14px; }
.offcanvas.hf-side .offcanvas-header .hf-avatar { background: rgba(255,255,255,.18); }
.offcanvas.hf-side .offcanvas-header .hf-cust, .offcanvas.hf-side .offcanvas-header .hf-line { color: #fff; }
.offcanvas.hf-side .offcanvas-header .hf-line { opacity: .88; }
.offcanvas.hf-side .offcanvas-body { padding: 16px; }
.offcanvas.hf-side .hf-panel + .hf-panel, .offcanvas.hf-side .hf-panel + form { margin-top: 12px; }

/* Install popup: style.css gives it z-index 3, which puts it under the tab / action bars */
html body .addtohome-popup { z-index: 1060 !important; box-shadow: 0 -6px 24px rgba(8,14,20,.18); }
/* homescreen-popup.js shows the button with inline display:inline-block — keep it centered */
html body #installApp:not([style*="none"]) { display: flex !important; align-items: center; justify-content: center; }

/* Floating "Photo" button (Today) */
.hf-fab {
    position: fixed; right: var(--gutter); bottom: calc(78px + var(--safe-b)); z-index: 1031;
    height: 56px; padding: 0 20px 0 16px; border-radius: 28px; border: 0; background: var(--brand); color: #fff;
    font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; box-shadow: 0 4px 14px rgba(10,20,30,.28);
}
.hf-fab:hover, .hf-fab:focus { color: #fff; filter: brightness(1.08); }
.hf-ok { color: var(--green); font-weight: 600; display: flex; gap: 6px; align-items: center; margin: 14px 0 0; }
#qpJobs .hf-row { margin-top: 8px; }
.hf-card-link { display: inline-flex; align-items: center; gap: 2px; margin-top: 8px; color: var(--brand-text); font-weight: 600; font-size: 15px; }
.hf-card-main:hover .hf-card-link { text-decoration: underline; }
