/* Persistent floating TVT Support AI assistant (launcher + non-blocking chat panel).
   Loaded on logged-in portal pages via header.ftlh and header-ticket.ftlh.
   Designed for zero layout shift, crisp depth, symmetric anchored transitions, and full keyboard/a11y support. */
.tvt-ai-dock,
.tvt-ai-dock *,
.tvt-ai-dock *::before,
.tvt-ai-dock *::after {
  box-sizing: border-box;
}

.tvt-ai-dock {
  --dock-blue: #0057a6;
  --dock-blue-top: #0c68bd;
  --dock-blue-hover: #004788;
  --dock-ink: #111827;
  --dock-ink-2: #374151;
  --dock-muted: #6b7280;
  --dock-line: rgba(201, 207, 203, .88);
  --dock-surface: #ffffff;
  --dock-ease: cubic-bezier(.22, 1, .36, 1);
  --dock-right: max(22px, env(safe-area-inset-right));
  --dock-bottom: max(88px, env(safe-area-inset-bottom));
  font-family: var(--tvt-font-sans, system-ui, -apple-system, sans-serif);
  -webkit-font-smoothing: antialiased;
}

/* On Support Cases (/cscase/*), lift the launcher cleanly above the bottom-right composer Send button. */
body.os-page .tvt-ai-dock {
  --dock-bottom: max(152px, env(safe-area-inset-bottom));
  --dock-right: max(16px, env(safe-area-inset-right));
}

/* ---------- Floating Launcher: the Tivi mascot alone, draggable ---------- */
.tvt-ai-dock .tvt-ai-fab {
  position: fixed;
  right: var(--dock-right);
  bottom: var(--dock-bottom);
  z-index: 59; /* above the sticky site header so a dragged mascot stays reachable */
  display: block;
  width: 76px;
  height: 75px;
  min-height: 0;
  margin: 0;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: none !important;
  box-shadow: none !important;
  color: inherit !important;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  filter: drop-shadow(0 3px 5px rgba(11, 26, 46, .32)) drop-shadow(0 0 1px rgba(11, 26, 46, .5));
}

.tvt-ai-dock .tvt-ai-fab:focus-visible {
  outline: 2px solid var(--dock-blue) !important;
  outline-offset: 2px !important;
  border-radius: 24px !important;
}

.tvt-ai-dock.is-dragging .tvt-ai-fab {
  cursor: grabbing;
}

.tvt-ai-fab-mascot,
.tvt-ai-fab-fx {
  display: block;
  width: 76px;
  height: 75px;
  pointer-events: none;
  transform-origin: 50% 100%;
}

/* outer span: lean / pendulum tilt set from script; inner span: one-shot keyframe plays */
.tvt-ai-fab-mascot { transition: transform .25s ease-out; will-change: transform; }
.tvt-ai-dock.is-dragging .tvt-ai-fab-mascot { transition: none; transform-origin: 50% 15%; }
.tvt-ai-fab-fx.fx-press { transform: scale(1.06, .9); transition: transform .08s ease-out; }
.tvt-ai-fab-fx.fx-bump { animation: tvt-fx-bump .3s ease-out; }
.tvt-ai-fab-fx.fx-hop { animation: tvt-fx-hop .6s cubic-bezier(.3, 1.2, .5, 1); }
.tvt-ai-fab-fx.fx-release { animation: tvt-fx-release .45s ease-out; }
.tvt-ai-fab-fx.fx-land { animation: tvt-fx-land .5s ease-out; }
.tvt-ai-fab-fx.fx-nudge { animation: tvt-fx-nudge 1s ease-out; }
.tvt-ai-fab-fx.fx-startle { animation: tvt-fx-startle .4s ease-out; }
.tvt-ai-fab-fx.fx-curious { animation: tvt-fx-curious 1.3s ease-in-out; }
.tvt-ai-fab-fx.fx-enter { animation: tvt-fx-enter .8s cubic-bezier(.3, 1.4, .5, 1) both; }
@keyframes tvt-fx-bump { 0%, 100% { transform: none; } 40% { transform: translateY(-6px) scale(1.04); } }
@keyframes tvt-fx-hop { 0% { transform: scale(1.06, .92); } 25% { transform: translateY(-18px) scale(.96, 1.06); } 55% { transform: translateY(0) scale(1.05, .93); } 75% { transform: translateY(-4px); } 100% { transform: none; } }
@keyframes tvt-fx-release { 0% { transform: scale(.96, 1.1); } 45% { transform: scale(1.04, .96); } 75% { transform: scale(.99, 1.02); } 100% { transform: none; } }
@keyframes tvt-fx-land { 0% { transform: translateY(-5px); } 30% { transform: scale(1.1, .88); } 60% { transform: scale(.97, 1.05) translateY(-3px); } 100% { transform: none; } }
@keyframes tvt-fx-nudge { 0%, 100% { transform: none; } 15% { transform: translateY(-14px); } 30% { transform: none; } 45% { transform: translateY(-9px); } 60% { transform: none; } }
@keyframes tvt-fx-startle { 0% { transform: none; } 30% { transform: translateY(-9px) scale(.97, 1.05); } 100% { transform: none; } }
@keyframes tvt-fx-curious { 0%, 100% { transform: none; } 25%, 75% { transform: rotate(9deg); } }
@keyframes tvt-fx-enter { 0% { transform: translateY(130px); opacity: 0; } 55% { transform: translateY(-10px); opacity: 1; } 80% { transform: translateY(3px); } 100% { transform: none; opacity: 1; } }

.tvt-ai-fab-mascot svg.tvt-tivi {
  width: 76px;
  height: 75px;
}

/* measures the safe-area insets for the drag clamp */
.tvt-ai-safe {
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  visibility: hidden;
  pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- Floating Assistant Panel ---------- */
.tvt-ai-panel {
  position: fixed;
  right: var(--dock-right);
  bottom: calc(var(--dock-bottom) + 56px);
  z-index: 58;
  width: min(420px, calc(100vw - 32px));
  height: min(580px, calc(100dvh - 32px));
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(196, 204, 212, .9);
  border-radius: 16px;
  background: var(--dock-surface);
  box-shadow:
    0 24px 64px -16px rgba(15, 23, 42, .22),
    0 8px 20px -8px rgba(15, 23, 42, .10),
    0 0 0 1px rgba(255, 255, 255, .6) inset;
  transform-origin: calc(100% - 22px) 100%;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(.92);
  transition:
    opacity 200ms var(--dock-ease),
    transform 200ms var(--dock-ease),
    width 200ms ease,
    height 200ms ease,
    top 200ms ease,
    visibility 0s linear 200ms;
}

.tvt-ai-dock.is-open .tvt-ai-panel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: scale(1);
  transition:
    opacity 200ms var(--dock-ease),
    transform 220ms var(--dock-ease),
    width 200ms ease,
    height 200ms ease,
    top 200ms ease,
    visibility 0s;
}

/* while the launcher is being dragged the panel follows it directly, without easing */
.tvt-ai-dock.is-dragging .tvt-ai-panel {
  transition: opacity 200ms var(--dock-ease), transform 200ms var(--dock-ease);
}

.tvt-ai-dock.is-wide .tvt-ai-panel {
  width: min(680px, calc(100vw - 32px));
  height: min(720px, calc(100dvh - 32px));
}

/* launcher keeps company while the panel is open: a quieter, smaller Tivi */
.tvt-ai-dock.is-open:not(.is-sheet) .tvt-ai-fab-fx svg.tvt-tivi {
  transform: scale(.8);
  transform-origin: 50% 100%;
}
.tvt-ai-fab-fx svg.tvt-tivi { transition: transform .25s ease-out; }

/* Panel Top Bar */
.tvt-ai-panel-head {
  flex: none;
  height: 48px;
  padding: 0 8px 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border-bottom: 1px solid #e6e9ed;
}

.tvt-ai-panel-left,
.tvt-ai-panel-right {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.tvt-ai-panel-title {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-left: 6px;
  min-width: 0;
  color: var(--dock-ink);
  font: 600 14px/1.2 var(--tvt-font-sans, system-ui, sans-serif);
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tvt-ai-dock .tvt-ai-hbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  min-height: 0;
  padding: 0 !important;
  margin: 0;
  border: 0 !important;
  border-radius: 8px !important;
  background: transparent !important;
  color: #4b5563 !important;
  text-decoration: none;
  cursor: pointer;
  flex: none;
  transition: background-color 140ms ease, color 140ms ease, transform 90ms ease !important;
}

.tvt-ai-dock .tvt-ai-hbtn:hover {
  background: #eef2f6 !important;
  color: var(--dock-ink) !important;
}

.tvt-ai-dock .tvt-ai-hbtn:active {
  transform: scale(.94) !important;
}

.tvt-ai-dock .tvt-ai-hbtn[aria-expanded="true"] {
  background: #e8f1fa !important;
  color: var(--dock-blue) !important;
}

.tvt-ai-dock .tvt-ai-hbtn:focus-visible {
  outline: 2px solid var(--dock-blue) !important;
  outline-offset: 1px !important;
}

.tvt-ai-dock .tvt-ai-hbtn svg {
  width: 17px;
  height: 17px;
  display: block;
}

/* Panel Body + Lazy Loading State */
.tvt-ai-panel-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #fff;
}

.tvt-ai-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.tvt-ai-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #fff;
  color: var(--dock-muted);
  font-size: 13.5px;
  transition: opacity 180ms ease;
  pointer-events: none;
}

.tvt-ai-loading.is-hidden {
  opacity: 0;
}

.tvt-ai-spinner {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2.5px solid #e5e7eb;
  border-top-color: var(--dock-blue);
  animation: tvt-ai-spin .75s linear infinite;
}

@keyframes tvt-ai-spin {
  to { transform: rotate(360deg); }
}

/* ---------- Small screens: launcher size, and the full-screen sheet ---------- */
/* the footer wraps to a taller block below the md breakpoint, so the default spot rises with it */
@media (max-width: 767px) {
  .tvt-ai-dock {
    --dock-bottom: max(112px, env(safe-area-inset-bottom));
  }
  body.os-page .tvt-ai-dock {
    --dock-bottom: max(152px, env(safe-area-inset-bottom));
  }
}
@media (max-width: 640px) {
  .tvt-ai-dock {
    --dock-right: max(16px, env(safe-area-inset-right));
  }
  .tvt-ai-dock .tvt-ai-fab,
  .tvt-ai-fab-mascot,
  .tvt-ai-fab-fx,
  .tvt-ai-fab-mascot svg.tvt-tivi {
    width: 60px;
    height: 59px;
  }
}
/* ai-dock.js adds .is-sheet when a docked panel would not fit beside the launcher */
.tvt-ai-dock.is-sheet .tvt-ai-hbtn[data-dock="wide"] {
  display: none !important;
}
.tvt-ai-dock.is-sheet .tvt-ai-panel,
.tvt-ai-dock.is-sheet.is-wide .tvt-ai-panel {
  inset: 0;
  right: 0;
  bottom: 0;
  left: 0 !important;
  top: 0 !important;
  width: 100% !important;
  height: 100dvh !important;
  max-width: none;
  max-height: none;
  border: 0;
  border-radius: 0;
  transform-origin: center bottom !important;
  transform: translateY(18px);
}
.tvt-ai-dock.is-sheet.is-open .tvt-ai-panel {
  transform: translateY(0);
}
.tvt-ai-dock.is-sheet.is-open .tvt-ai-fab {
  visibility: hidden;
  pointer-events: none;
}
.tvt-ai-dock.is-sheet .tvt-ai-panel-head {
  height: calc(50px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
}

/* ---------- Accessibility Preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  .tvt-ai-panel,
  .tvt-ai-dock .tvt-ai-fab,
  .tvt-ai-dock .tvt-ai-hbtn,
  .tvt-ai-fab-mascot,
  .tvt-ai-fab-fx,
  .tvt-ai-spinner {
    transition: opacity 150ms ease !important;
    animation: none !important;
  }
  .tvt-ai-panel,
  .tvt-ai-fab-mascot,
  .tvt-ai-fab-fx,
  .tvt-ai-dock.is-open:not(.is-sheet) .tvt-ai-fab-fx svg.tvt-tivi {
    transform: none !important;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .tvt-ai-panel-head {
    background: #fff;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

.tvt-ai-fab-mascot svg:not(.tvt-tivi) {
  width: 44px;
  height: 44px;
  margin: 22px 16px;
  color: var(--dock-blue);
}

/* border resize handles on the free edges; active in both compact and wide desktop states */
.tvt-ai-rz { display: none; position: absolute; z-index: 10; touch-action: none; }
.tvt-ai-dock.rz-on .tvt-ai-rz { display: block; }
.tvt-ai-dock.is-sheet .tvt-ai-rz { display: none; }
.tvt-ai-rz-h { top: 14px; bottom: 14px; width: 10px; cursor: ew-resize; }
.tvt-ai-rz-v { left: 14px; right: 14px; height: 10px; cursor: ns-resize; }
.tvt-ai-rz-c { width: 18px; height: 18px; z-index: 11; }
.tvt-ai-rz::after { content: ''; position: absolute; opacity: 0; border-radius: 999px; background: rgba(0, 87, 166, .45); pointer-events: none; transition: opacity 140ms ease; }
.tvt-ai-rz-h::after { top: 50%; transform: translateY(-50%); width: 3px; height: 36px; }
.tvt-ai-rz-v::after { left: 50%; transform: translateX(-50%); height: 3px; width: 36px; }
.tvt-ai-rz-c::after { width: 8px; height: 8px; background: rgba(0, 87, 166, .55); }
.tvt-ai-rz:hover::after, .tvt-ai-dock.is-resizing .tvt-ai-rz:hover::after { opacity: 1; }
.tvt-ai-dock.rz-left .tvt-ai-rz-h, .tvt-ai-dock.rz-left .tvt-ai-rz-c { left: 0; }
.tvt-ai-dock.rz-left .tvt-ai-rz-h::after { left: 2px; }
.tvt-ai-dock.rz-left .tvt-ai-rz-c::after { left: 3px; }
.tvt-ai-dock:not(.rz-left) .tvt-ai-rz-h, .tvt-ai-dock:not(.rz-left) .tvt-ai-rz-c { right: 0; }
.tvt-ai-dock:not(.rz-left) .tvt-ai-rz-h::after { right: 2px; }
.tvt-ai-dock:not(.rz-left) .tvt-ai-rz-c::after { right: 3px; }
.tvt-ai-dock.rz-top .tvt-ai-rz-v, .tvt-ai-dock.rz-top .tvt-ai-rz-c { top: 0; }
.tvt-ai-dock.rz-top .tvt-ai-rz-v::after { top: 2px; }
.tvt-ai-dock.rz-top .tvt-ai-rz-c::after { top: 3px; }
.tvt-ai-dock:not(.rz-top) .tvt-ai-rz-v, .tvt-ai-dock:not(.rz-top) .tvt-ai-rz-c { bottom: 0; }
.tvt-ai-dock:not(.rz-top) .tvt-ai-rz-v::after { bottom: 2px; }
.tvt-ai-dock:not(.rz-top) .tvt-ai-rz-c::after { bottom: 3px; }
.tvt-ai-dock.rz-left.rz-top .tvt-ai-rz-c, .tvt-ai-dock:not(.rz-left):not(.rz-top) .tvt-ai-rz-c { cursor: nwse-resize; }
.tvt-ai-dock.rz-left:not(.rz-top) .tvt-ai-rz-c, .tvt-ai-dock:not(.rz-left).rz-top .tvt-ai-rz-c { cursor: nesw-resize; }
.tvt-ai-dock.is-resizing { user-select: none; -webkit-user-select: none; }
.tvt-ai-dock.is-resizing .tvt-ai-panel { transition: opacity 200ms var(--dock-ease), transform 200ms var(--dock-ease); }
.tvt-ai-dock.is-resizing .tvt-ai-frame { pointer-events: none; }
