/* Host page + widget: TT Norms Pro (host zelf @font-face / licentie indien nodig) */
:root {
  --sophie-font-sans: "TT Norms Pro", "TT Norms", ui-sans-serif, system-ui, -apple-system,
    "Segoe UI", Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.demo-page {
  max-width: 42rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 6rem;
  font-family: var(--sophie-font-sans);
  font-optical-sizing: auto;
  line-height: 1.6;
  color: #0d0d0d;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.demo-page h1 {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 0.75rem;
}

/* Sophie widget — chatbalk gecentreerd onderaan; paneel direct erboven (zelfde "rij") */
.ccw {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(6px, env(safe-area-inset-bottom, 6px));
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  pointer-events: none;
  font-family: var(--sophie-font-sans);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Direct zichtbaar — geen scroll-trigger of vertraging */
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.5s cubic-bezier(0.22, 1, 0.36, 1), transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.ccw--visible {
  opacity: 1;
  transform: translateY(0);
}

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

  .ccw__panel {
    animation: none !important;
  }

  .ccw__launcher-wave {
    animation: none !important;
  }

  .ccw__launcher-copy {
    transition: none !important;
    transform: none !important;
    filter: none !important;
  }

  .ccw__hold-recording span {
    animation: none !important;
  }

  .ccw.is-hold-recording .ccw__hold-recording {
    animation: none !important;
  }

  .ccw.is-open .ccw__panel {
    opacity: 1;
    transform: none;
  }
}

.ccw * {
  box-sizing: border-box;
}

.ccw__launcher {
  pointer-events: auto;
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: auto;
  min-width: 0;
  min-height: 52px;
  padding: 6px 8px 6px 10px;
  margin: 0;
  border: none;
  border-radius: 9999px;
  /* Apple Liquid Glass — transparante glaslaag over de pagina-achtergrond */
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(28px) saturate(200%) brightness(1.08);
  -webkit-backdrop-filter: blur(28px) saturate(200%) brightness(1.08);
  color: rgba(17, 24, 39, 0.82);
  font-family: var(--sophie-font-sans);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.018em;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  /* Glasrand + specular inset + diepte-schaduw */
  box-shadow:
    /* Heldere bovenrand — licht dat weerkaatst op het glas */
    0 1.5px 0 rgba(255, 255, 255, 0.72) inset,
    /* Donkere onderrand — glasdikte, kleine schaduwkant */
    0 -0.5px 0 rgba(0, 0, 0, 0.07) inset,
    /* Dunne witte glasrand rondom */
    0 0 0 1px rgba(255, 255, 255, 0.30),
    /* Zachte diepteschaduw */
    0 8px 32px rgba(0, 0, 0, 0.12),
    0 2px 10px rgba(0, 0, 0, 0.07);
  transition:
    width 0.46s cubic-bezier(0.22, 1, 0.36, 1),
    min-width 0.46s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.28s ease,
    transform 0.46s cubic-bezier(0.22, 1, 0.36, 1),
    background 0.22s ease,
    backdrop-filter 0.22s ease,
    box-shadow 0.22s ease,
    color 0.15s ease;
  --ccw-glow-x: 50%;
  --ccw-glow-y: 50%;
}

.ccw__launcher:hover {
  background: rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(32px) saturate(220%) brightness(1.10);
  -webkit-backdrop-filter: blur(32px) saturate(220%) brightness(1.10);
  color: rgba(17, 24, 39, 0.90);
  box-shadow:
    0 1.5px 0 rgba(255, 255, 255, 0.78) inset,
    0 -0.5px 0 rgba(0, 0, 0, 0.07) inset,
    0 0 0 1px rgba(255, 255, 255, 0.40),
    0 10px 40px rgba(0, 0, 0, 0.14),
    0 3px 12px rgba(0, 0, 0, 0.08);
}

.ccw__launcher:active {
  background: rgba(255, 255, 255, 0.26);
  backdrop-filter: blur(28px) saturate(200%) brightness(1.06);
  -webkit-backdrop-filter: blur(28px) saturate(200%) brightness(1.06);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.62) inset,
    0 -0.5px 0 rgba(0, 0, 0, 0.07) inset,
    0 0 0 1px rgba(255, 255, 255, 0.28),
    0 4px 16px rgba(0, 0, 0, 0.09);
  transform: scale(0.984);
  transition-duration: 0.08s;
}

/* focus-visible handled below with Liquid Glass ring */

.ccw__launcher-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: left;
  padding-left: 3.5%;
  color: inherit;
}

.ccw__launcher-copy {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  vertical-align: top;
  transition:
    opacity 340ms ease,
    transform 340ms ease,
    filter 340ms ease;
}

.ccw__hold-recording {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #0a84ff;
  color: #ffffff;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.42) inset,
    0 0 0 0 rgba(10, 132, 255, 0.34);
}

.ccw__hold-recording span {
  width: 3px;
  height: 9px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.92;
  transform-origin: 50% 50%;
  animation: ccw-hold-recording-bars 0.92s ease-in-out infinite;
}

.ccw__hold-recording span:nth-child(2) {
  animation-delay: 0.12s;
}

.ccw__hold-recording span:nth-child(3) {
  animation-delay: 0.24s;
}

.ccw__hold-recording span:nth-child(4) {
  animation-delay: 0.36s;
}

@keyframes ccw-hold-recording-bars {
  0%,
  100% {
    transform: scaleY(0.54);
  }
  50% {
    transform: scaleY(1.62);
  }
}

.ccw__launcher-copy.is-leaving {
  opacity: 0;
  transform: translateY(-6px);
  filter: blur(0.4px);
}

.ccw__launcher-copy.is-entering {
  opacity: 0;
  transform: translateY(6px);
  filter: blur(0.4px);
}

.ccw__launcher::after {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

/* Liquid Glass specular highlight — lichtreflectie bovenaan het glas */
.ccw__launcher::before {
  content: '';
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
  border-radius: inherit;
  background: linear-gradient(
    162deg,
    rgba(255, 255, 255, 0.54) 0%,
    rgba(255, 255, 255, 0.20) 34%,
    rgba(255, 255, 255, 0.04) 56%,
    transparent 70%
  );
  pointer-events: none;
  z-index: 0;
}

.ccw__launcher::after {
  content: "↑";
  background: #111827;
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
}

/* Liquid Glass focus ring (toegankelijkheid) */
.ccw__launcher:focus-visible {
  box-shadow:
    0 1.5px 0 rgba(255, 255, 255, 0.72) inset,
    0 -0.5px 0 rgba(0, 0, 0, 0.07) inset,
    0 0 0 1px rgba(255, 255, 255, 0.30),
    0 0 0 3px rgba(17, 24, 39, 0.20),
    0 8px 32px rgba(0, 0, 0, 0.12);
}

.ccw__launcher-wave {
  display: none;
  transform-origin: 70% 70%;
}

/* Desktop open: paneel boven launcher (geen fullscreen) */
.ccw.is-open {
  bottom: max(
    calc(12px * 1.2),
    calc(env(safe-area-inset-bottom, 10px) * 1.2)
  );
}

.ccw.is-open .ccw__launcher {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  margin: 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.ccw__panel {
  --ccw-panel-w: min(910px, calc(100vw - 38px));
  --ccw-bar-stack: 96px;
  display: none;
  position: relative;
  pointer-events: auto;
  flex-shrink: 0;
  width: var(--ccw-panel-w);
  height: min(
    686px,
    calc(100dvh - var(--ccw-bar-stack) - 28px),
    calc(var(--ccw-panel-w) / 1.314)
  );
  min-height: min(
    468px,
    calc(var(--ccw-panel-w) * 1.279),
    calc(100dvh - var(--ccw-bar-stack) - 32px)
  );
  max-height: calc(100dvh - var(--ccw-bar-stack) - 24px);
  border-radius: 14px;
  overflow: hidden;
  padding: 0;
  background: #ffffff;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border: 1px solid #e5e7eb;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.35) inset,
    0 24px 64px rgba(0, 0, 0, 0.12),
    0 10px 24px rgba(0, 0, 0, 0.06);
  opacity: 0;
  transform: translateY(12px) scale(0.97);
  transform-origin: 50% 100%;
}

.ccw.is-open .ccw__panel {
  display: flex;
  flex-direction: column;
  animation: ccw-panel-open 0.34s cubic-bezier(0.32, 0.92, 0.32, 1.02) forwards;
}

.ccw.is-open.is-closing .ccw__panel {
  animation: ccw-panel-close 180ms ease-in forwards;
}

@keyframes ccw-panel-open {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes ccw-panel-close {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
}

.ccw__frame {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

@media (max-width: 640px) {
  .ccw {
    bottom: max(6px, env(safe-area-inset-bottom, 6px));
    gap: 10px;
  }

  .ccw__launcher {
    max-width: calc((100vw - 24px) * 0.8);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  .ccw.is-hold-recording .ccw__launcher {
    background: rgba(255, 255, 255, 0.30);
    color: rgba(17, 24, 39, 0.94);
    transform: translateY(-2px) scale(1.02);
    box-shadow:
      0 1.5px 0 rgba(255, 255, 255, 0.78) inset,
      0 -0.5px 0 rgba(0, 0, 0, 0.08) inset,
      0 0 0 1px rgba(255, 255, 255, 0.48),
      0 14px 48px rgba(10, 132, 255, 0.22),
      0 0 0 8px rgba(10, 132, 255, 0.08);
  }

  .ccw.is-hold-recording .ccw__launcher::after {
    display: none;
  }

  .ccw.is-hold-recording .ccw__hold-recording {
    display: inline-flex;
    animation: ccw-hold-recording-pulse 1.45s ease-in-out infinite;
  }

  @keyframes ccw-hold-recording-pulse {
    0%,
    100% {
      box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.42) inset,
        0 0 0 0 rgba(10, 132, 255, 0.28);
    }
    50% {
      box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.42) inset,
        0 0 0 9px rgba(10, 132, 255, 0);
    }
  }

  /* Mobiel open: volledig scherm + morph van launcher */
  .ccw.is-opening,
  .ccw.is-open {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding-top: env(safe-area-inset-top, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    gap: 0;
    justify-content: stretch;
    align-items: stretch;
  }

  .ccw.is-opening .ccw__panel,
  .ccw.is-open .ccw__panel {
    --ccw-panel-w: 100%;
    --ccw-bar-stack: 0px;
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border: none;
    box-shadow: none;
    transform: none;
    transform-origin: 50% 100%;
    animation: none;
  }

  .ccw.is-opening .ccw__panel {
    opacity: 0;
    animation: ccw-panel-morph-in 0.48s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }

  .ccw.is-open:not(.is-closing) .ccw__panel {
    opacity: 1;
    animation: none;
  }

  .ccw.is-opening .ccw__launcher,
  .ccw.is-open .ccw__launcher {
    position: fixed;
    left: 50%;
    bottom: max(6px, env(safe-area-inset-bottom, 6px));
    z-index: 100000;
    margin: 0;
    transform: translateX(-50%);
    width: var(--ccw-morph-width, min(80vw, 910px)) !important;
    min-width: var(--ccw-morph-width, min(80vw, 910px)) !important;
  }

  .ccw.is-opening .ccw__launcher-text,
  .ccw.is-opening .ccw__launcher::after {
    opacity: 0;
    transition: opacity 0.18s ease;
  }

  .ccw.is-open:not(.is-opening) .ccw__launcher {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
      opacity 0.24s ease,
      width 0.46s cubic-bezier(0.22, 1, 0.36, 1),
      min-width 0.46s cubic-bezier(0.22, 1, 0.36, 1),
      visibility 0s linear 0.24s;
  }
}

/* Achtergrond niet scrollen zolang chat open is (desktop + mobiel) */
body.ccw-chat-open {
  overflow: hidden;
  overscroll-behavior: none;
}

@media (max-width: 640px) {
  body.ccw-chat-open {
    position: fixed;
    left: 0;
    right: 0;
    width: 100%;
    height: 100%;
  }

  .ccw.is-open .ccw__panel,
  .ccw.is-opening .ccw__panel {
    touch-action: pan-y;
    overscroll-behavior: contain;
  }
}

@keyframes ccw-panel-morph-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  @media (max-width: 640px) {
    .ccw.is-opening .ccw__panel {
      animation: none;
      opacity: 1;
    }

    .ccw.is-opening .ccw__launcher-text,
    .ccw.is-opening .ccw__launcher::after {
      transition: none;
    }
  }
}

/* Mobiel: launcher krimpt terug na sluiten — veer-easing voor leuk "snap" gevoel */
.ccw--shrinking .ccw__launcher {
  transition:
    width 0.62s cubic-bezier(0.34, 1.42, 0.64, 1),
    min-width 0.62s cubic-bezier(0.34, 1.42, 0.64, 1),
    max-width 0.62s cubic-bezier(0.34, 1.42, 0.64, 1),
    opacity 0.28s ease,
    transform 0.62s cubic-bezier(0.34, 1.42, 0.64, 1),
    background 0.22s ease,
    backdrop-filter 0.22s ease,
    box-shadow 0.22s ease,
    color 0.15s ease !important;
}

/* Verberg chatbalk zolang het mobiele hoofdmenu open is */

body.nav-menu-open #corner-chat-widget {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  transform: translateY(16px) !important;
  transition-duration: 0.2s !important;
}
