/* FURAI LAB — shared site widgets: personal-data consent banner + contact FAB.
 *
 * This file is loaded by every page (public/<lang>/index.html,
 * <lang>/pricing/, <lang>/vpn/ and the Function-rendered docs pages in
 * functions/_lib/doc-page.ts). It deliberately uses ONLY the design tokens
 * that all of those pages define: --bg, --fg, --fg-dim, --accent, --line,
 * --sans. Card/nav tokens (--card-bg, --nav-bg, ...) exist on the landing and
 * pricing pages but NOT on /vpn/ or the docs pages, so they are off limits
 * here — a widget that borrows one renders unstyled on half the site.
 *
 * Colour trick used throughout: on the accent-filled surfaces the text colour
 * is var(--bg), not a literal. Light theme is dark indigo on near-white, dark
 * theme is light indigo on near-black, so one rule stays legible in both.
 * Same approach as the existing .skip-link.
 */

/* Height of the visible consent banner, written by furai-widgets.js so the
 * FAB can lift itself clear of it instead of guessing a fixed offset. */
:root {
  --furai-consent-h: 0px;
  --furai-safe-b: env(safe-area-inset-bottom, 0px);
}

/* ---------------------------------------------------------------- FAB ---- */

.furai-fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + var(--furai-safe-b) + var(--furai-consent-h));
  z-index: 50;
  display: flex;
  flex-direction: column;
  /* The panel opens above the button and hangs from its right edge, so the
   * two stay flush against the same side of the screen. */
  align-items: flex-end;
  gap: 10px;
  font-family: var(--sans);
  transition: bottom 0.28s cubic-bezier(0.2, 0.7, 0.3, 1), opacity 0.2s ease;
}

/* The mobile menu is a full-screen overlay at z-index 9 on the landing and
 * pricing pages. The FAB sits above it, so it has to step aside while the
 * menu is open or it floats over the navigation. */
body.menu-open .furai-fab {
  opacity: 0;
  pointer-events: none;
}

/* 4px corners and a 1px accent edge, matching .cta-primary and .doc-link on
 * the rest of the site — the pill shape read as a bolted-on third-party
 * widget. The fill is a translucent accent over a blurred backdrop rather
 * than the flat one those buttons use: this thing floats over live content,
 * so it should look like glass sitting on the page, not a sticker.
 * The solid background is declared first as the fallback for engines
 * without color-mix. */
.furai-fab__btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 12px 20px 12px 16px;
  border: 1px solid var(--accent);
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
  border-radius: 4px;
  background: var(--accent);
  background: color-mix(in srgb, var(--accent) 78%, transparent);
  backdrop-filter: blur(20px) saturate(200%);
  -webkit-backdrop-filter: blur(20px) saturate(200%);
  color: var(--bg);
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 6px 20px rgba(0, 0, 0, 0.18),
    0 1px 2px rgba(0, 0, 0, 0.12);
  transition: transform 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

.furai-fab__btn:hover {
  transform: translateY(-2px);
  background: color-mix(in srgb, var(--accent) 92%, transparent);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    0 10px 26px rgba(0, 0, 0, 0.22),
    0 1px 2px rgba(0, 0, 0, 0.12);
}

.furai-fab__btn:active { transform: translateY(0); }

.furai-fab__btn svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
  flex-shrink: 0;
}

/* The bubble icon rotates into a cross when the panel is open — one control,
 * two states, no second button to explain. */
.furai-fab__btn .furai-fab__ico-close { display: none; }
.furai-fab[data-open="true"] .furai-fab__btn .furai-fab__ico-open { display: none; }
.furai-fab[data-open="true"] .furai-fab__btn .furai-fab__ico-close { display: block; }

/* Same glass, same 6px radius the project cards use. */
.furai-fab__panel {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 296px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 62%, transparent);
  backdrop-filter: blur(24px) saturate(190%);
  -webkit-backdrop-filter: blur(24px) saturate(190%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    0 14px 40px rgba(0, 0, 0, 0.18),
    0 2px 6px rgba(0, 0, 0, 0.08);
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(10px) scale(0.96);
  transition: opacity 0.18s ease, transform 0.18s cubic-bezier(0.2, 0.7, 0.3, 1);
}

.furai-fab__panel[hidden] { display: none; }

.furai-fab[data-open="true"] .furai-fab__panel {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.furai-fab__hint {
  padding: 8px 12px 6px;
  color: var(--fg-dim);
  font-size: 12px;
  line-height: 1.4;
  letter-spacing: 0.02em;
}

.furai-fab__item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 4px;
  color: var(--fg);
  text-decoration: none;
  transition: background-color 0.15s ease;
}

.furai-fab__item:hover { background: color-mix(in srgb, var(--fg) 7%, transparent); }

.furai-fab__icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
}

.furai-fab__icon svg { width: 18px; height: 18px; fill: #fff; }

/* Channel marks keep their own colours — recognition is the whole job of
 * this control, and a monochrome Telegram bird helps nobody. */
.furai-fab__icon--tg { background: #229ED9; }
.furai-fab__icon--wa { background: #25D366; }

.furai-fab__text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.furai-fab__text b { font-size: 14px; font-weight: 600; line-height: 1.2; }
.furai-fab__text small {
  color: var(--fg-dim);
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ------------------------------------------------------------ CONSENT ---- */

.furai-consent {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--furai-safe-b));
  z-index: 60;
  width: min(640px, calc(100vw - 40px));
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.2), 0 2px 8px rgba(0, 0, 0, 0.08);
  opacity: 0;
  transform: translate(-50%, 16px);
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.2, 0.7, 0.3, 1);
}

.furai-consent[hidden] { display: none; }
.furai-consent[data-shown="true"] { opacity: 1; transform: translate(-50%, 0); }

.furai-consent__title {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.furai-consent__text {
  margin: 0;
  color: var(--fg-dim);
  font-size: 13.5px;
  line-height: 1.55;
}

.furai-consent__text a {
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--line);
}

.furai-consent__text a:hover { text-decoration-color: var(--accent); }

.furai-consent__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.furai-consent__btn {
  padding: 10px 20px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: filter 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.furai-consent__btn--accept { background: var(--accent); color: var(--bg); }
.furai-consent__btn--accept:hover { filter: brightness(1.12); }

.furai-consent__btn--decline {
  background: transparent;
  color: var(--fg-dim);
  border-color: var(--line);
}

.furai-consent__btn--decline:hover { color: var(--fg); border-color: var(--fg-dim); }

/* Footer link to the policy, added to the .legal row on the landing and
 * pricing pages. Lives here so the rule ships once instead of six times. */
footer .legal a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--line);
}

footer .legal a:hover { text-decoration-color: var(--accent); }

/* ------------------------------------------------------------- MOBILE ---- */

@media (max-width: 640px) {
  /* On a phone the button spans the full width of the viewport gutter —
   * a thumb-sized target that needs no aiming — and the channel panel
   * stacks above it at the same width. */
  .furai-fab { left: 16px; right: 16px; bottom: calc(16px + var(--furai-safe-b) + var(--furai-consent-h)); align-items: stretch; }
  .furai-fab__btn { justify-content: center; padding: 14px 20px; }
  .furai-fab__panel { border-radius: 6px; }
  .furai-fab__panel { width: 100%; max-width: none; }
  .furai-consent { width: calc(100vw - 24px); bottom: calc(12px + var(--furai-safe-b)); padding: 18px; border-radius: 16px; }
  .furai-consent__actions { flex-direction: column-reverse; }
  .furai-consent__btn { width: 100%; padding: 12px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .furai-fab,
  .furai-fab__btn,
  .furai-fab__panel,
  .furai-consent { transition: none; }
}
