/* ═══════════════════════════════════════════════════════════
   OPTG Audio Player — Professional Voice Message Player
   Compatible with RISE CRM / RTL / Dark & Light modes
   ═══════════════════════════════════════════════════════════ */

:root {
  --oap-bg: #f0f2f5;
  --oap-bg-me: #e1f3fb;
  --oap-border: rgba(0,0,0,0.06);
  --oap-btn-bg: #FF9800;
  --oap-btn-hover: #e68900;
  --oap-btn-fg: #fff;
  --oap-wave: #b0bec5;
  --oap-progress: #FF9800;
  --oap-cursor: #FF9800;
  --oap-time: #546e7a;
  --oap-speed-bg: rgba(0,0,0,0.06);
  --oap-speed-fg: #455a64;
  --oap-loading-color: #FF9800;
  --oap-radius: 14px;
  --oap-shadow: 0 1px 4px rgba(0,0,0,0.08);
  --oap-height: 36px;
}

/* Dark mode */
[data-bs-theme="dark"] .optg-audio-player,
.dark-mode .optg-audio-player {
  --oap-bg: #2a2d35;
  --oap-bg-me: #1e3a4a;
  --oap-border: rgba(255,255,255,0.06);
  --oap-wave: #546e7a;
  --oap-progress: #FF9800;
  --oap-time: #90a4ae;
  --oap-speed-bg: rgba(255,255,255,0.08);
  --oap-speed-fg: #b0bec5;
}

/* ── Base container ───────────────────────────────────────── */
.optg-audio-player {
  display: inline-flex;
  align-items: center;
  background: var(--oap-bg);
  border: 1px solid var(--oap-border);
  border-radius: var(--oap-radius);
  padding: 8px 12px 8px 10px;
  box-shadow: var(--oap-shadow);
  min-width: 260px;
  max-width: 380px;
  width: 100%;
  gap: 10px;
  transition: box-shadow 0.2s;
  position: relative;
  margin: 4px 0;
  box-sizing: border-box;
  direction: ltr;  /* keep player LTR internally always */
}
.optg-audio-player:hover {
  box-shadow: 0 3px 10px rgba(0,0,0,0.12);
}
.optg-audio-player.playing {
  box-shadow: 0 2px 8px rgba(255,152,0,0.22);
  border-color: rgba(255,152,0,0.3);
}

/* "sent by me" variant — inside chat-me */
.chat-me .optg-audio-player {
  background: var(--oap-bg-me);
}

/* ── Play/Pause Button ────────────────────────────────────── */
.optg-ap-btn {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--oap-btn-bg);
  color: var(--oap-btn-fg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  padding: 0;
  outline: none;
  position: relative;
  z-index: 1;
}
.optg-ap-btn:hover {
  background: var(--oap-btn-hover);
}
.optg-ap-btn:active {
  transform: scale(0.93);
}
.optg-ap-btn svg {
  width: 16px;
  height: 16px;
  fill: #fff;
  pointer-events: none;
  flex-shrink: 0;
}
.optg-ap-btn .pause-icon { display: none; }
.optg-ap-btn .play-icon  { display: block; }
.playing .optg-ap-btn .pause-icon { display: block; }
.playing .optg-ap-btn .play-icon  { display: none; }

/* Loading spinner inside button */
.optg-ap-btn.loading::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: oap-spin 0.7s linear infinite;
}
.optg-ap-btn.loading svg { opacity: 0; }

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

/* ── Body (waveform + time) ───────────────────────────────── */
.optg-ap-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* ── Waveform container ───────────────────────────────────── */
.optg-ap-waveform {
  height: var(--oap-height);
  width: 100%;
  cursor: pointer;
  border-radius: 4px;
  overflow: hidden;
}

/* Skeleton bars while loading */
.optg-ap-waveform.oap-skeleton {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 0;
}
.optg-ap-waveform.oap-skeleton::before {
  content: '';
  flex: 1;
  height: 100%;
  background: repeating-linear-gradient(
    90deg,
    var(--oap-wave) 0,
    var(--oap-wave) 3px,
    transparent 3px,
    transparent 5px
  );
  border-radius: 2px;
  animation: oap-pulse 1.4s ease-in-out infinite;
}
@keyframes oap-pulse {
  0%,100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* ── Time row ─────────────────────────────────────────────── */
.optg-ap-time-row {
  display: flex;
  align-items: center;
  font-size: 11px;
  color: var(--oap-time);
  font-family: 'Cairo', 'Segoe UI', monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.2px;
}
.optg-ap-sep { margin: 0 2px; opacity: 0.5; }

/* ── Speed button ─────────────────────────────────────────── */
.optg-ap-speed {
  flex-shrink: 0;
  background: var(--oap-speed-bg);
  color: var(--oap-speed-fg);
  border: none;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 7px;
  cursor: pointer;
  min-width: 32px;
  text-align: center;
  transition: background 0.15s, color 0.15s;
  font-family: 'Cairo', monospace;
  outline: none;
  letter-spacing: 0.3px;
}
.optg-ap-speed:hover {
  background: rgba(255,152,0,0.15);
  color: var(--oap-btn-bg);
}
.optg-ap-speed.active-speed {
  background: rgba(255,152,0,0.18);
  color: var(--oap-btn-bg);
}

/* ── Download link ────────────────────────────────────────── */
.optg-ap-dl {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: var(--oap-time);
  opacity: 0.6;
  transition: opacity 0.15s;
  text-decoration: none;
  cursor: pointer;
}
.optg-ap-dl:hover { opacity: 1; color: var(--oap-btn-bg); }
.optg-ap-dl svg { width: 14px; height: 14px; }

/* ── Error state ──────────────────────────────────────────── */
.optg-audio-player.oap-error .optg-ap-waveform {
  display: none;
}
.optg-ap-err-msg {
  display: none;
  font-size: 11px;
  color: #e74c3c;
  flex: 1;
  text-align: center;
}
.oap-error .optg-ap-err-msg { display: block; }
.oap-error .optg-ap-body { justify-content: center; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 480px) {
  .optg-audio-player {
    min-width: 220px;
    max-width: 100%;
  }
}

/* ── In message rows (chat) ───────────────────────────────── */
.message-images .optg-audio-player {
  max-width: 320px;
}

/* ── Animation: fade in ───────────────────────────────────── */
.optg-audio-player {
  animation: oap-fadein 0.25s ease;
}
@keyframes oap-fadein {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── WaveSurfer overrides ─────────────────────────────────── */
.optg-ap-waveform wave {
  border-radius: 4px;
}
.optg-ap-waveform canvas {
  border-radius: 4px;
}

/* ── Tooltip on hover ─────────────────────────────────────── */
.optg-ap-speed[title] {
  position: relative;
}
