/**
 * Hobbiz custom audio / video players
 * Tokens: --primary-color, messenger --msg-* when available
 */

:root {
  --hb-media-primary: var(--primary-color, #8A2BE2);
  --hb-media-primary-dark: var(--primary-color-dark, #6A1B9A);
  --hb-media-soft: var(--primary-color-light, #E6D5FA);
  --hb-media-ink: #1f1633;
  --hb-media-muted: #6b7280;
  --hb-media-border: var(--border-color, #D1C4E9);
  --hb-media-ease: var(--md-ease-standard, cubic-bezier(0.2, 0, 0, 1));
  --hb-media-dur: var(--md-duration-short3, 150ms);
}

/* ─── Audio ─── */
.hb-audio {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-width: min(240px, 100%);
  max-width: 100%;
  min-height: 56px;
  box-sizing: border-box;
  margin: 0.4rem 0 0;
  padding: 8px 12px;
  border-radius: 14px;
  background: rgba(138, 43, 226, 0.1);
  border: 1px solid rgba(209, 196, 233, 0.75);
  color: var(--hb-media-ink);
}

.hb-audio audio {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  border: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.hb-audio__play {
  flex-shrink: 0;
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--hb-media-primary);
  color: #fff;
  cursor: pointer;
  transition: background var(--hb-media-dur) var(--hb-media-ease),
    transform var(--hb-media-dur) var(--hb-media-ease);
}

.hb-audio__play:hover {
  background: var(--hb-media-primary-dark);
}

.hb-audio__play:active {
  transform: scale(0.96);
}

.hb-audio__play:focus-visible {
  outline: 2px solid var(--hb-media-primary);
  outline-offset: 2px;
}

.hb-audio__play i {
  font-size: 1.15rem;
  line-height: 1;
  margin-left: 2px; /* optical center for play triangle */
  pointer-events: none;
}

.hb-audio__main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 2px 0;
}

.hb-audio__seek {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 18px;
  margin: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.hb-audio__seek::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(138, 43, 226, 0.22);
}

.hb-audio__seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--hb-media-primary);
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(45, 55, 72, 0.25);
  cursor: pointer;
}

.hb-audio__seek::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(138, 43, 226, 0.22);
}

.hb-audio__seek::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--hb-media-primary);
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(45, 55, 72, 0.25);
  cursor: pointer;
}

.hb-audio__seek:focus-visible {
  outline: 2px solid var(--hb-media-primary);
  outline-offset: 2px;
}

.hb-audio__time {
  font-size: 11px;
  line-height: 1.25;
  color: var(--hb-media-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Outgoing / user bubbles */
.message-to .hb-audio,
.message.user .hb-audio {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.28);
  color: #fff;
}

.message-to .hb-audio__play,
.message.user .hb-audio__play {
  background: rgba(255, 255, 255, 0.95);
  color: var(--hb-media-primary);
}

.message-to .hb-audio__play:hover,
.message.user .hb-audio__play:hover {
  background: #fff;
}

.message-to .hb-audio__seek::-webkit-slider-runnable-track,
.message.user .hb-audio__seek::-webkit-slider-runnable-track,
.message-to .hb-audio__seek::-moz-range-track,
.message.user .hb-audio__seek::-moz-range-track {
  background: rgba(255, 255, 255, 0.28);
}

.message-to .hb-audio__seek::-webkit-slider-thumb,
.message.user .hb-audio__seek::-webkit-slider-thumb,
.message-to .hb-audio__seek::-moz-range-thumb,
.message.user .hb-audio__seek::-moz-range-thumb {
  background: #fff;
  border-color: rgba(255, 255, 255, 0.9);
}

.message-to .hb-audio__time,
.message.user .hb-audio__time {
  color: rgba(255, 255, 255, 0.82);
}

/* Messenger bubble sizing when custom audio present */
.dialogspage .message:has(.hb-audio),
.dialogspage .message:has(audio) {
  min-width: min(78%, 280px);
}

.dialogspage .message .hb-audio,
.dialogspage .message-wrapper > .hb-audio,
.dialogspage .message-audio-wrapper .hb-audio {
  width: 100%;
  max-width: 100%;
  min-width: 240px;
  box-sizing: border-box;
}

.new .hb-audio,
.news-audio-wrapper .hb-audio,
.portfolio-audio + .hb-audio,
.audio-content .hb-audio {
  margin-top: 8px;
  max-width: 100%;
}

/* ─── Video overlay (swiper-safe) ─── */
.hb-video-host {
  position: relative;
}

.video-wrapper.hb-video-host,
.messagecontaining.hb-video-host,
.swiper-slide.hb-video-host {
  position: relative;
}

/* Host height follows the video (Swiper autoHeight). Overlay is inset:0 on the same box. */
.video-wrapper.hb-video-host {
  width: 100%;
  background: #0a0a0f;
  overflow: hidden;
}

.video-wrapper.hb-video-host > video {
  width: 100%;
  height: auto;
  min-height: 220px;
  display: block;
  background: #000;
  object-fit: cover;
}

.new .swiper-slide .video-wrapper.hb-video-host > video,
#newslistparent .swiper-slide .video-wrapper.hb-video-host > video,
#chFeedList .swiper-slide .video-wrapper.hb-video-host > video {
  min-height: 220px;
  height: auto !important;
}

/* Overlay covers the frame; play is centered, bar is pinned to the bottom. */
.hb-video {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: block;
  pointer-events: none;
  opacity: 1;
  transition: opacity var(--hb-media-dur) var(--hb-media-ease);
}

.hb-video.hb-video--playing:not(:hover):not(:focus-within) {
  opacity: 0;
}

.hb-video.hb-video--playing:not(:hover):not(:focus-within) .hb-video__play-center {
  opacity: 0;
  pointer-events: none;
}

.hb-video__play-center,
.hb-video__play,
.hb-video__seek,
.hb-video__bar {
  pointer-events: auto;
}

.hb-video__play-center {
  position: absolute;
  left: 50%;
  /* Sit above the bottom bar so the two plays never overlap */
  top: calc(50% - 26px);
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(138, 43, 226, 0.92);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(45, 55, 72, 0.28);
  transition: background var(--hb-media-dur) var(--hb-media-ease),
    transform var(--hb-media-dur) var(--hb-media-ease),
    opacity var(--hb-media-dur) var(--hb-media-ease);
  z-index: 4;
}

.hb-video__play-center:hover {
  background: var(--hb-media-primary-dark);
}

.hb-video__play-center:active {
  transform: translate(-50%, -50%) scale(0.96);
}

.hb-video__play-center:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.hb-video__play-center i {
  font-size: 1.5rem;
  line-height: 1;
  margin-left: 3px;
  pointer-events: none;
}

.hb-video.hb-video--playing .hb-video__play-center {
  opacity: 0;
  pointer-events: none;
}

.hb-video.hb-video--loading .hb-video__play-center,
.hb-audio.hb-audio--loading .hb-audio__play {
  opacity: 0.7;
  pointer-events: none;
}

.hb-video.hb-video--loading .hb-video__play-center i,
.hb-audio.hb-audio--loading .hb-audio__play i {
  animation: hb-media-pulse 0.9s ease-in-out infinite;
}

@keyframes hb-media-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.92); }
}

.hb-video__bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 28px 12px 12px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.78) 55%);
  pointer-events: auto;
  min-height: 56px;
  box-sizing: border-box;
}

.hb-video__play {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  cursor: pointer;
  transition: background var(--hb-media-dur) var(--hb-media-ease);
}

.hb-video__play:hover {
  background: rgba(255, 255, 255, 0.3);
}

.hb-video__play:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.hb-video__play i {
  font-size: 1.05rem;
  line-height: 1;
  margin-left: 2px;
  pointer-events: none;
}

.hb-video__seek {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 0;
  height: 18px;
  margin: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.hb-video__seek::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
}

.hb-video__seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -4px;
  border-radius: 50%;
  background: #fff;
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.hb-video__seek::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
}

.hb-video__seek::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.hb-video__seek:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.hb-video__time {
  flex-shrink: 0;
  font-size: 11px;
  line-height: 1.2;
  color: rgba(255, 255, 255, 0.92);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 4.75rem;
  text-align: right;
}

/* Keep video element sizing; controls removed by JS */
.hb-video-host > video,
.messagecontaining.hb-video-host > video {
  position: relative;
  z-index: 1;
}

.messagecontaining.hb-video-host {
  position: relative;
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .hb-audio__play,
  .hb-video,
  .hb-video__play-center,
  .hb-video__play {
    transition: none;
  }

  .hb-video.hb-video--loading .hb-video__play-center i,
  .hb-audio.hb-audio--loading .hb-audio__play i {
    animation: none;
  }
}
