/* Global action system: bottom bar / corner buttons, contact and accessibility panels (src/lib/actions.ts),
   plus the visitor's accessibility preferences (data-sfa-* on <html>, set by the inline script in Base.astro).
   Values come from tokens.css. Layers: page content < bar/corner buttons (40) < header (50); panels live in the
   browser's top layer (popover), so no z-index race with menus or modals. */

/* ---------- Phone bar: [contact] [FREE QUOTE] [accessibility] ---------- */
.sfa { position: sticky; bottom: 0; z-index: 40; } /* sticky on the wrapper: its parent is <body>, so it sticks for the whole page */
.sfa-bar { display: grid; grid-template-columns: 48px minmax(0, 1fr) 48px; gap: var(--space-2); align-items: center; padding: var(--space-2) max(var(--space-3), env(safe-area-inset-right, 0px)) calc(var(--space-2) + env(safe-area-inset-bottom, 0px)) max(var(--space-3), env(safe-area-inset-left, 0px)); background: var(--asphalt); border-top: 1px solid var(--steel-line); }
.sfa-quote.sf-btn { box-sizing: border-box; min-height: 48px; padding: 0 var(--space-3); gap: var(--space-2); font-size: 15px; }
.sfa-quote svg { width: 20px; height: 20px; flex: none; }
.sfa-btn { box-sizing: border-box; position: relative; display: inline-grid; place-items: center; width: 48px; height: 48px; padding: 0; border: 1px solid var(--steel-line-strong); border-radius: var(--radius-md); background: var(--asphalt); color: var(--chrome); cursor: pointer; transition: border-color .16s ease, color .16s ease; }
.sfa-btn svg { width: 22px; height: 22px; }
.sfa-btn:hover { border-color: var(--chrome); }
.sfa:has(#sfa-contact:popover-open) .sfa-btn--contact, .sfa:has(#sfa-a11y:popover-open) .sfa-btn--a11y { border-color: var(--force-orange); color: var(--force-orange); }
/* the focused element never sits under the bar (WCAG 2.4.11): anchors and Tab both leave room for it */
@media (max-width: 1023px) and (min-height: 481px) { html { scroll-padding-bottom: 80px; } }
/* a text field has focus on a phone (virtual keyboard up): the bar steps out of the way, back when focus leaves */
@media (max-width: 1023px) {
  body:has(:is(input:not([type="checkbox"], [type="radio"], [type="submit"], [type="button"], [type="file"]), textarea, select):focus) .sfa { position: static; }
  body:has(.sf-mmenu-wrap:not([hidden])) .sfa-bar { display: none; } /* the open menu carries its own CTAs */
}

/* ---------- Desktop and short landscape: two quiet corner buttons, no full-width bar ---------- */
@media (min-width: 1024px), (max-height: 480px) {
  .sfa { position: static; }
  .sfa-bar { display: block; height: 0; padding: 0; border: 0; background: none; }
  .sfa-quote { display: none; } /* the header keeps its Free Quote button */
  .sfa-btn { position: fixed; z-index: 40; bottom: max(20px, env(safe-area-inset-bottom, 0px)); box-shadow: 0 6px 16px rgba(11, 11, 11, .35); }
  .sfa-btn--contact { left: max(20px, env(safe-area-inset-left, 0px)); }
  .sfa-btn--a11y { right: max(20px, env(safe-area-inset-right, 0px)); }
  .sf-footer__bottom { padding-bottom: 64px; } /* the page's last line ends above the corner buttons */
  .sfa-btn::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); padding: 6px 10px; border-radius: var(--radius-sm); background: var(--graphite); color: var(--chrome); font: 700 13px/1.2 var(--font-sans); white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .16s ease; }
  .sfa-btn--contact::after { left: 0; }
  .sfa-btn--a11y::after { right: 0; }
  .sfa-btn:is(:hover, :focus-visible)::after { opacity: 1; }
  .sfa:has(:popover-open) .sfa-btn::after { opacity: 0; }
}
@media (hover: none) { .sfa-btn::after { display: none; } }

/* ---------- Panels ---------- */
.sfa-panel { --sfa-off: calc(72px + env(safe-area-inset-bottom, 0px)); position: fixed; inset: auto; bottom: var(--sfa-off); margin: 0; padding: 0; box-sizing: border-box; max-height: calc(100dvh - var(--sfa-off) - 72px); overflow: auto; overscroll-behavior: contain; border: 1px solid var(--steel-line); border-radius: var(--radius-md); background: linear-gradient(var(--force-orange), var(--force-orange)) 0 0 / 64px 4px no-repeat, var(--asphalt); color: var(--chrome); font-family: var(--font-sans); box-shadow: var(--shadow-badge); opacity: 0; transform: translateY(8px); transition: opacity .16s ease, transform .16s ease, overlay .16s allow-discrete, display .16s allow-discrete; }
.sfa-panel:popover-open { opacity: 1; transform: none; }
@starting-style { .sfa-panel:popover-open { opacity: 0; transform: translateY(8px); } }
.sfa-panel--contact { left: 8px; width: min(320px, calc(100vw - 16px)); }
.sfa-panel--a11y { right: 8px; width: min(340px, calc(100vw - 16px)); }
@media (min-width: 1024px), (max-height: 480px) {
  .sfa-panel { --sfa-off: calc(80px + env(safe-area-inset-bottom, 0px)); max-height: calc(100dvh - var(--sfa-off) - 16px); }
  .sfa-panel--contact { left: 20px; width: 280px; }
  .sfa-panel--a11y { right: 20px; width: 330px; }
}
.sfa-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-2); padding: var(--space-5) var(--space-2) var(--space-3) var(--space-5); }
.sfa-title { margin: 0; font-family: var(--font-display); font-size: 20px; font-weight: 900; font-style: italic; line-height: 1.1; text-transform: uppercase; }
.sfa-sub { margin: 6px 0 0; font-size: 13px; line-height: 1.45; color: var(--steel); }
.sfa-x { box-sizing: border-box; flex: none; display: inline-grid; place-items: center; width: 44px; height: 44px; margin-top: -10px; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--steel); cursor: pointer; }
.sfa-x:hover { color: var(--chrome); }
.sfa-x svg { width: 20px; height: 20px; }

/* contact rows: the site's estimate-card pattern (44px tile + bold label + muted line) */
.sfa-list { margin: 0; padding: 0 0 var(--space-2); list-style: none; }
.sfa-row { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: var(--space-4); align-items: center; padding: var(--space-3) var(--space-5); border-top: 1px solid var(--steel-line); color: var(--chrome); text-decoration: none; transition: background-color .16s ease; }
/* page CSS sets a:hover{color:ink} (0,1,1): on this dark panel that hid the labels, so the row keeps its colours */
.sfa-panel .sfa-row, .sfa-panel .sfa-row:hover { color: var(--chrome); }
@media (hover: hover) { .sfa-row:hover { background: var(--steel-panel); } }
.sfa-row b { display: block; font-family: var(--font-display); font-size: 16px; font-weight: 800; font-style: italic; letter-spacing: .02em; text-transform: uppercase; }
.sfa-row small { display: block; margin-top: 2px; font-size: 13px; line-height: 1.4; color: var(--steel); }
.sfa-nw { white-space: nowrap; }
.sfa-tile { display: grid; place-items: center; width: 44px; height: 44px; border-radius: var(--radius-md); background: var(--graphite); color: var(--force-orange); }
.sfa-tile svg { width: 22px; height: 22px; }
.sfa-row--quote .sfa-tile { background: var(--force-orange); color: var(--on-orange); }
.sfa-row--wa .sfa-tile { color: #25d366; }

/* accessibility controls */
.sfa-size { display: grid; grid-template-columns: minmax(0, 1fr) 44px 56px 44px; align-items: center; gap: var(--space-1); padding: var(--space-3) var(--space-5); border-top: 1px solid var(--steel-line); font-size: 15px; font-weight: 700; }
.sfa-step { box-sizing: border-box; display: inline-grid; place-items: center; width: 44px; height: 44px; border: 1px solid var(--steel-line-strong); border-radius: var(--radius-md); background: transparent; color: var(--chrome); cursor: pointer; }
.sfa-step:hover:not(:disabled) { border-color: var(--chrome); }
.sfa-step:disabled { opacity: .4; cursor: default; }
.sfa-step svg { width: 18px; height: 18px; }
.sfa-out { text-align: center; font-variant-numeric: tabular-nums; color: var(--force-orange); }
.sfa-togs { display: grid; border-top: 1px solid var(--steel-line); }
.sfa-tog { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); min-height: 48px; padding: var(--space-2) var(--space-5); border: 0; border-bottom: 1px solid var(--steel-line); background: transparent; color: var(--chrome); font: 600 15px/1.3 var(--font-sans); text-align: start; cursor: pointer; }
@media (hover: hover) { .sfa-tog:hover { background: var(--steel-panel); } }
.sfa-sw { position: relative; flex: none; width: 36px; height: 20px; border: 1px solid var(--steel-line-strong); border-radius: var(--radius-pill); background: var(--graphite); transition: background-color .16s ease, border-color .16s ease; }
.sfa-sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--steel); transition: transform .16s ease, background-color .16s ease; }
.sfa-tog[aria-pressed="true"] .sfa-sw { background: var(--force-orange); border-color: var(--force-orange); }
.sfa-tog[aria-pressed="true"] .sfa-sw::after { transform: translateX(16px); background: var(--asphalt); }
@media not (any-pointer: fine) { .sfa-tog[data-pref="cursor"] { display: none; } } /* touch-only screens have no pointer to enlarge */
.sfa-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3) var(--space-4); padding: var(--space-4) var(--space-5) var(--space-5); font-size: 14px; }
.sfa-foot .sf-link { display: inline-block; padding-block: 6px; background-position: 0 calc(100% - 6px); }
.sfa-note { flex-basis: 100%; margin: 0; font-size: 12px; color: var(--steel); }
/* inside the scrolling panel an outer focus ring is clipped at the sides: draw it inset; the panel itself takes
   focus without a ring when opened by mouse or touch */
.sfa-panel :focus-visible { outline-offset: -4px !important; }
.sfa-panel:focus { outline: none; }
.sfa-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { .sfa-panel, .sfa-btn, .sfa-sw, .sfa-sw::after { transition: none; } }

/* ---------- Visitor preferences (only what this panel sets; browser and OS settings keep working) ---------- */
/* text size: body copy, labels and fields grow; headings are already large; layout boxes keep their width */
html[data-sfa-size="1"] { --sfa-z: 1.15; }
html[data-sfa-size="2"] { --sfa-z: 1.3; }
html[data-sfa-size="3"] { --sfa-z: 1.5; }
html[data-sfa-size] :is(main, footer) :is(p, dd, dt, figcaption, blockquote, td, th, summary, h3, h4, h5, h6, input, select, textarea, label:not(:has(input, select, textarea)), li:not(:has(p, li, label, h3, h4))) { zoom: var(--sfa-z); }

/* high contrast: the brand palette with muted greys and hairlines pushed to full strength */
html[data-sfa-contrast] { --steel: #e6e7e8; --chrome: #ffffff; --steel-line: #8a8c90; --steel-line-strong: #c9cacc; --ink: #000000; --ink-muted: #1c1c22; --hairline: #55565c; --control-border: #1c1c22; --orange-text: #9a3412; --overlay: rgba(11, 11, 11, .82); }
html[data-sfa-contrast] :is(main, footer) a:not(.sf-btn) { text-decoration: underline; text-underline-offset: 3px; }

/* readable font: the system UI face, upright (the brand display face is a condensed italic) */
html[data-sfa-font] { --font-display: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
html[data-sfa-font] :not(em, i, cite) { font-style: normal !important; }

/* text spacing: the WCAG 1.4.12 values */
html[data-sfa-spacing] body :not(svg, svg *) { line-height: 1.5 !important; letter-spacing: .12em !important; word-spacing: .16em !important; }
html[data-sfa-spacing] body p { margin-block-end: 2em; }

/* highlight links: every text link underlined in gold; buttons keep their shape */
html[data-sfa-links] a:not(.sf-btn, .sfa-row) { text-decoration: underline 2px !important; text-decoration-color: var(--sun-gold) !important; text-underline-offset: 4px !important; }
html[data-sfa-links] a.sf-btn { outline: 2px dashed var(--sun-gold); outline-offset: 2px; }

/* reduce motion: same result as the device setting (motion.js stays off; see Base.astro) */
html[data-sfa-motion] *, html[data-sfa-motion] *::before, html[data-sfa-motion] *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }

/* stronger focus: thick gold ring with a dark halo, visible on orange, black and white */
html[data-sfa-focus] :focus-visible { outline: 4px solid var(--sun-gold) !important; outline-offset: 3px !important; box-shadow: 0 0 0 7px var(--asphalt) !important; }

/* large cursor: pointing devices only */
@media (any-pointer: fine) {
  html[data-sfa-cursor], html[data-sfa-cursor] * { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 24 24'%3E%3Cpath d='M4 2l15 11-7 1 4 8-3 1-4-8-5 5z' fill='%23000' stroke='%23fff' stroke-width='1.5' stroke-linejoin='round'/%3E%3C/svg%3E") 6 3, auto !important; }
  html[data-sfa-cursor] :is(a, button, summary, label, select, [role="button"]), html[data-sfa-cursor] :is(a, button, summary, label, select, [role="button"]) * { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 24 24'%3E%3Cpath d='M4 2l15 11-7 1 4 8-3 1-4-8-5 5z' fill='%23ff7f00' stroke='%23000' stroke-width='1.5' stroke-linejoin='round'/%3E%3C/svg%3E") 6 3, pointer !important; }
}
