/* Widget nổi premium — chat + top cùng bên phải, không đè nhau */
.kv-float-widgets {
  position: fixed;
  inset: 0;
  z-index: 880;
  pointer-events: none;
}

:root {
  --kv-fab-right: max(0.85rem, env(safe-area-inset-right, 0));
  --kv-fab-gap: 0.75rem;
  --kv-fab-size: 2.5rem;
  --kv-fab-chat-size: var(--kv-fab-size);
  --kv-fab-top-size: var(--kv-fab-size);
}

/* ========== Chat hub (phải) ========== */
.kv-float-hub {
  position: fixed;
  right: var(--kv-fab-right);
  left: auto;
  bottom: calc(2.25rem + env(safe-area-inset-bottom, 0));
  pointer-events: auto;
  z-index: 882;
}

.kv-float-hub__panel {
  position: absolute;
  right: calc(100% + 0.65rem);
  left: auto;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  opacity: 0;
  visibility: hidden;
  transform: translateX(10px) scale(0.92);
  transform-origin: right bottom;
  transition: opacity 0.28s ease, transform 0.28s ease, visibility 0.28s;
  pointer-events: none;
}

.kv-float-hub.is-open .kv-float-hub__panel,
.kv-float-hub:hover .kv-float-hub__panel,
.kv-float-hub:focus-within .kv-float-hub__panel {
  opacity: 1;
  visibility: visible;
  transform: translateX(0) scale(1);
  pointer-events: auto;
}

.kv-float-hub__item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 9.5rem;
  padding: 0.42rem 0.42rem 0.42rem 0.85rem;
  border-radius: 999px;
  background: #fff;
  color: #0f172a;
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  box-shadow:
    0 10px 28px rgba(15, 23, 42, 0.14),
    0 0 0 1px rgba(15, 23, 42, 0.06);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.kv-float-hub__item:hover {
  transform: translateX(-4px);
  box-shadow:
    0 14px 32px rgba(15, 23, 42, 0.18),
    0 0 0 1px rgba(15, 23, 42, 0.08);
}

.kv-float-hub__item--zalo:hover {
  box-shadow:
    0 14px 32px rgba(0, 104, 255, 0.22),
    0 0 0 1px rgba(0, 104, 255, 0.15);
}

.kv-float-hub__item--facebook:hover {
  box-shadow:
    0 14px 32px rgba(24, 119, 242, 0.22),
    0 0 0 1px rgba(24, 119, 242, 0.15);
}

.kv-float-hub__icon {
  flex-shrink: 0;
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 999px;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.kv-float-hub__icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

.kv-float-hub__text {
  white-space: nowrap;
}

.kv-float-hub__trigger {
  position: relative;
  flex-shrink: 0;
  width: var(--kv-fab-chat-size);
  height: var(--kv-fab-chat-size);
  border: 0;
  border-radius: 999px;
  padding: 0;
  cursor: pointer;
  background: transparent;
  color: #fff;
  isolation: isolate;
}

.kv-float-hub__trigger-ring {
  position: absolute;
  inset: -3px;
  border-radius: 999px;
  background: conic-gradient(from 180deg, #ffc617, #00c46a, #006b3f, #ffc617);
  animation: kv-hub-spin 4s linear infinite;
  z-index: 0;
}

.kv-float-hub__trigger-inner {
  position: absolute;
  inset: 2px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #00a85a 0%, #006b3f 55%, #004d2e 100%);
  box-shadow:
    0 10px 26px rgba(0, 107, 63, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
  z-index: 1;
  transition: transform 0.2s ease;
}

.kv-float-hub__trigger-icon {
  width: 1.05rem;
  height: 1.05rem;
}

.kv-float-hub__trigger-label {
  position: absolute;
  right: calc(100% + 0.5rem);
  left: auto;
  bottom: 50%;
  transform: translateY(50%);
  padding: 0.3rem 0.6rem;
  border-radius: 0.4rem;
  background: rgba(0, 77, 46, 0.92);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.kv-float-hub:hover .kv-float-hub__trigger-label,
.kv-float-hub.is-open .kv-float-hub__trigger-label {
  opacity: 1;
}

.kv-float-hub__trigger:hover .kv-float-hub__trigger-inner,
.kv-float-hub.is-open .kv-float-hub__trigger-inner {
  transform: scale(1.05);
}

.kv-float-hub.is-open .kv-float-hub__item {
  animation: kv-hub-item-in 0.35s ease both;
}

.kv-float-hub.is-open .kv-float-hub__item:nth-child(2) {
  animation-delay: 0.06s;
}

@media (hover: hover) {
  .kv-float-hub:hover .kv-float-hub__item {
    animation: kv-hub-item-in 0.35s ease both;
  }
  .kv-float-hub:hover .kv-float-hub__item:nth-child(2) {
    animation-delay: 0.06s;
  }
}

/* ========== Gọi ngay desktop — cùng hàng với chat, lệch trái ========== */
.kv-float-call {
  display: none;
  position: fixed;
  right: calc(var(--kv-fab-right) + var(--kv-fab-chat-size) + var(--kv-fab-gap));
  left: auto;
  bottom: calc(2.25rem + env(safe-area-inset-bottom, 0));
  width: 3.15rem;
  height: 3.15rem;
  border-radius: 999px;
  place-items: center;
  color: #fff;
  text-decoration: none;
  background: linear-gradient(145deg, #00a85a 0%, #006b3f 100%);
  box-shadow: 0 10px 26px rgba(0, 107, 63, 0.35);
  pointer-events: auto;
  z-index: 881;
  transition: transform 0.2s ease;
}

.kv-float-call i {
  font-size: 1.3rem;
}

.kv-float-call__label {
  position: absolute;
  right: calc(100% + 0.45rem);
  left: auto;
  top: 50%;
  transform: translateY(-50%);
  padding: 0.28rem 0.55rem;
  border-radius: 0.35rem;
  background: rgba(0, 77, 46, 0.92);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.kv-float-call:hover .kv-float-call__label {
  opacity: 1;
}

.kv-float-call:hover {
  transform: scale(1.06);
}

/* ========== Nút TOP — ngay trên chat, cách một khoảng vừa phải ========== */
.kv-float-top {
  position: fixed;
  right: var(--kv-fab-right);
  left: auto;
  bottom: calc(2.25rem + var(--kv-fab-chat-size) + var(--kv-fab-gap) + env(safe-area-inset-bottom, 0));
  width: var(--kv-fab-top-size);
  height: var(--kv-fab-top-size);
  border: 0;
  border-radius: 999px;
  padding: 0;
  cursor: pointer;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.88);
  background: transparent;
  isolation: isolate;
  z-index: 883;
  transition:
    opacity 0.32s ease,
    transform 0.32s cubic-bezier(0.34, 1.4, 0.64, 1),
    visibility 0.32s;
}

.kv-float-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.kv-float-top__glow {
  position: absolute;
  inset: -6px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(0, 0, 0, 0.18) 0%, rgba(0, 0, 0, 0) 70%);
  opacity: 0.85;
  animation: kv-top-glow 2.4s ease-in-out infinite;
  z-index: 0;
}

.kv-float-top__ring {
  position: absolute;
  inset: -3px;
  border-radius: 999px;
  background: conic-gradient(from 0deg, #3a3a3a, #111, #3a3a3a, #000, #3a3a3a);
  z-index: 1;
}

.kv-float-top__inner {
  position: absolute;
  inset: 3px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #2a2a2a 0%, #111 45%, #000 100%);
  color: #fff;
  box-shadow:
    0 12px 28px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  z-index: 2;
  transition: transform 0.22s ease;
}

.kv-float-top__inner i {
  font-size: 1.05rem;
  line-height: 1;
  animation: kv-top-bounce 2s ease-in-out infinite;
}

.kv-float-top__text {
  position: absolute;
  right: calc(100% + 0.35rem);
  left: auto;
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
  font-size: 0.42rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #111;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
  z-index: 3;
  white-space: nowrap;
  opacity: 0.85;
}

.kv-float-top:hover .kv-float-top__inner {
  transform: scale(1.08);
}

.kv-float-top:active .kv-float-top__inner {
  transform: scale(0.96);
}

/* Pulse gọi ngay (menu mobile + desktop call) */
.kv-call-pulse {
  position: relative;
  isolation: isolate;
}

.kv-call-pulse::before,
.kv-call-pulse::after {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 999px;
  border: 2px solid rgba(0, 168, 84, 0.5);
  animation: kv-call-ring 2s ease-out infinite;
  pointer-events: none;
  z-index: -1;
}

.kv-call-pulse::after {
  animation-delay: 1s;
}

.kv-app-nav__call-btn.kv-call-pulse::before,
.kv-app-nav__call-btn.kv-call-pulse::after {
  inset: -6px;
  border-color: rgba(255, 255, 255, 0.45);
}

/* ========== Mobile — chat + top bên phải, cách nhau rõ ràng ========== */
@media (max-width: 1023px) {
  :root {
    --kv-fab-right: max(0.65rem, env(safe-area-inset-right, 0));
    --kv-fab-gap: 0.85rem;
    --kv-fab-size: 2.35rem;
  }

  .kv-float-hub {
    bottom: calc(4.85rem + env(safe-area-inset-bottom, 0));
    z-index: 860;
  }

  .kv-float-top {
    bottom: calc(4.85rem + var(--kv-fab-chat-size) + var(--kv-fab-gap) + env(safe-area-inset-bottom, 0));
    z-index: 859;
  }

  .kv-float-top__inner i {
    font-size: 1.2rem;
  }

  .kv-float-top__text {
    display: none;
  }

  .kv-float-hub__trigger-icon {
    width: 1rem;
    height: 1rem;
  }

  .kv-float-hub__trigger-label {
    display: none;
  }

  /* Panel mở lên trên nút chat */
  .kv-float-hub__panel {
    right: 0;
    left: auto;
    bottom: calc(100% + 0.55rem);
    transform: translateY(8px) scale(0.92);
    transform-origin: right bottom;
  }

  .kv-float-hub.is-open .kv-float-hub__panel,
  .kv-float-hub:hover .kv-float-hub__panel,
  .kv-float-hub:focus-within .kv-float-hub__panel {
    transform: translateY(0) scale(1);
  }
}

@media (min-width: 1024px) {
  .kv-float-call {
    display: grid;
  }

  /* Desktop: top sát trên chat; call nằm trái chat cùng hàng */
  .kv-float-call {
    right: calc(var(--kv-fab-right) + var(--kv-fab-chat-size) + var(--kv-fab-gap));
    bottom: calc(2.25rem + env(safe-area-inset-bottom, 0));
  }

  .kv-float-top {
    bottom: calc(2.25rem + var(--kv-fab-chat-size) + var(--kv-fab-gap) + env(safe-area-inset-bottom, 0));
  }
}

@media (prefers-reduced-motion: reduce) {
  .kv-float-hub__trigger-ring,
  .kv-float-top__glow,
  .kv-float-top__inner i,
  .kv-call-pulse::before,
  .kv-call-pulse::after {
    animation: none !important;
  }
}

@keyframes kv-hub-spin {
  to { transform: rotate(360deg); }
}

@keyframes kv-hub-item-in {
  from {
    opacity: 0;
    transform: translateX(12px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes kv-top-glow {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.08); }
}

@keyframes kv-top-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

@keyframes kv-call-ring {
  0% { transform: scale(1); opacity: 0.75; }
  100% { transform: scale(1.55); opacity: 0; }
}
