/* Sticky call bar 2: a header and a bottom bar that react to what the visitor is doing. No script.

   The header (.cb-head): at the top of the page it shows the name, a line under it (licence, area) and the phone
   number. Once the page is scrolled and it is stuck to the top, it gets shorter, drops the line and keeps the
   number.

   The bottom bar (.cb-foot), phones only: Call, and a second action. While the visitor scrolls down to read, it
   slims to the Call button alone. The moment they scroll back up, or reach the bottom, both buttons are back.
   The phone number is never off the screen.

   Both parts are the browser asking itself "am I stuck?" and "which way did the page last move?". A browser
   that cannot ask shows the header and the bar at full size, always: the same as the first sticky call bar.

   Use either part alone. Set on :root to fit the site:
     --cb-bg, --cb-ink      the header's background and text
     --cb-call, --cb-call-ink   the Call buttons
     --cb-h, --cb-h-stuck   the header's height at the top of the page, and when stuck (4.6rem, 3.2rem) */
:root {
  --cb-bg: #fffdf8;
  --cb-ink: #1f1a17;
  --cb-call: #17603a;
  --cb-call-ink: #fff;
  --cb-h: 4.6rem;
  --cb-h-stuck: 3.2rem;
}

/* The page is the thing that scrolls, so it is the thing the bottom bar asks about. */
html { container-type: scroll-state; container-name: cb-page; }

/* ---- The header ---- */
.cb-head {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--cb-h);           /* the room it takes in the page never changes, so nothing below it jumps */
  container-type: scroll-state;
  container-name: cb-head;
  pointer-events: none;          /* the part it gives up when stuck must not swallow taps */
}
.cb-head-in {                    /* the bar that is seen: this is what gets shorter */
  position: absolute;
  inset: 0 0 auto 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 clamp(1rem, 4vw, 2rem);
  background: var(--cb-bg);
  color: var(--cb-ink);
  border-bottom: 1px solid rgba(0, 0, 0, .1);
  pointer-events: auto;
  overflow: hidden;
  transition: height .25s ease, box-shadow .25s ease;
}
.cb-who { display: grid; min-width: 0; }
.cb-name { font-weight: 800; font-size: 1.1rem; line-height: 1.2; color: inherit; text-decoration: none; letter-spacing: -.01em; transition: font-size .25s ease; }
.cb-extra { font-size: .8rem; line-height: 1.3; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-height: 1.3em; transition: opacity .2s ease, max-height .25s ease; }
.cb-phone {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  min-height: 2.6rem;
  padding: 0 1rem;
  border-radius: 999px;
  font-weight: 700;
  white-space: nowrap;
  text-decoration: none;
  background: var(--cb-call);
  color: var(--cb-call-ink);
}
.cb-phone:focus-visible, .cb-name:focus-visible, .cb-foot :focus-visible { outline: 3px solid var(--cb-call); outline-offset: 3px; box-shadow: 0 0 0 6px #fff; }

@container cb-head scroll-state(stuck: top) {
  .cb-head-in { height: var(--cb-h-stuck); box-shadow: 0 4px 14px rgba(0, 0, 0, .16); }
  .cb-name { font-size: .98rem; }
  .cb-extra { opacity: 0; max-height: 0; }
}

/* ---- The bottom bar: phones only ---- */
.cb-foot {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 60;
  display: none;
  gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgb(20 20 20 / .97);
  box-shadow: 0 -6px 18px rgb(0 0 0 / .18);
  transition: padding .22s ease, background-color .22s ease, box-shadow .22s ease;
}
@media (max-width: 760px) { .cb-foot { display: flex; } }
.cb-foot :is(a, button) {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  min-height: 50px;
  padding: 0 .9rem;
  border-radius: 999px;
  border: 2px solid transparent;
  font: 600 1rem/1 system-ui, sans-serif;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: min-height .22s ease, flex-grow .22s ease, opacity .18s ease, padding .22s ease, border-width .22s ease;
}
.cb-foot .cb-call { background: var(--cb-call); color: var(--cb-call-ink); }
.cb-foot .cb-second { background: transparent; border-color: #eee; color: #eee; overflow: hidden; }

/* Scrolling down to read, with more page still to come: slim to the Call button alone. */
@container cb-page scroll-state((scrolled: block-end) and (scrollable: block-end)) {
  .cb-foot { padding: 6px 12px calc(6px + env(safe-area-inset-bottom)); background: rgb(20 20 20 / .82); box-shadow: none; }
  .cb-foot :is(a, button) { min-height: 40px; }
  .cb-foot .cb-second { flex-grow: 0; flex-basis: 0; padding: 0; border-width: 0; opacity: 0; visibility: hidden; transition: min-height .22s ease, flex-grow .22s ease, opacity .18s ease, padding .22s ease, border-width .22s ease, visibility 0s .22s; }
  .cb-foot { gap: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .cb-head-in, .cb-name, .cb-extra, .cb-foot, .cb-foot :is(a, button) { transition: none; }
}
@media print { .cb-foot { display: none; } .cb-head { position: static; } }
