/**
 * Lecteur : shell (#player-container, top, card), erreur record, contrôles, volume, timeline, pistes / segments.
 * Dépend de design-system.css + style.css.
 */

#player-container {
    height: 90vh;
    width: 90vw;
    background-color: var(--ro-colors-bg-container);
    margin: auto;
    border-radius: var(--ro-radii-md);
    display: flex;
    flex-direction: column;
    padding: var(--ro-size-6);
    gap: var(--ro-size-2);
    box-shadow: var(--ro-shadow);
    border: 1px solid var(--ro-colors-border-light);
    min-height: 0;
}

#player-top {
    flex-shrink: 0;
}

#launcher-container {
    height: 30px;
}

.player-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.player-top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Même gabarit que les boutons icône (recherche, ⋮) : ro-btn + pictos 18×18 */
.player-top-actions > a.btn[data-ro-shape="icon"] {
    flex-shrink: 0;
    text-decoration: none;
}

.player-top-actions > a.btn[data-ro-shape="icon"] img {
    width: 18px;
    height: 18px;
    display: block;
    object-fit: contain;
    flex-shrink: 0;
    pointer-events: none;
}

.player-call-ids-popover-wrap {
    position: relative;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
}

.player-call-ids-popover-wrap > .btn[data-ro-shape="icon"] {
    flex-shrink: 0;
}

.player-call-ids-info-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1.5px solid currentColor;
    box-sizing: border-box;
    font-size: 11px;
    font-weight: 700;
    font-style: italic;
    line-height: 1;
    font-family: Georgia, "Times New Roman", serif;
    opacity: 0.9;
}

.player-call-ids-popover {
    position: absolute;
    z-index: 50;
    top: calc(100% + 8px);
    right: 0;
    min-width: min(320px, calc(90vw - 48px));
    max-width: min(420px, calc(90vw - 32px));
    padding: 12px 14px;
    background: var(--ro-colors-bg-container, #fff);
    border: 1.5px solid var(--ro-colors-border-light, #e2ddf5);
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(45, 30, 80, 0.12);
}

.player-call-ids-popover__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 13px;
    line-height: 1.35;
}

.player-call-ids-popover__row + .player-call-ids-popover__row {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--ro-colors-border-light, #e2ddf5);
}

.player-call-ids-popover__line {
    flex: 1;
    min-width: 0;
}

.player-call-ids-popover__key {
    font-weight: 600;
    color: var(--ro-colors-text-secondary, #666);
    margin-right: 4px;
}

.player-call-ids-popover__value {
    font-size: 12px;
    font-weight: 500;
    word-break: break-all;
}

.player-call-ids-popover__copy {
    flex-shrink: 0;
}

.player-call-ids-popover__copy:disabled {
    opacity: 0.38;
    pointer-events: none;
}

#call-header {
    display: flex;
    margin-top: 16px;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.player-record-error {
    flex-shrink: 0;
    text-align: center;
    padding: 24px 16px;
    font-size: 15px;
    font-weight: 600;
    color: var(--ro-colors-danger-hover);
}

/* ── Card ── */
.card {
    padding: 0 28px 22px;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.card > .controls-bar,
.card > .timeline-wrapper {
    flex-shrink: 0;
}

/* ── Controls bar ── */
.controls-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    justify-content: space-between;
}
.controls-bar-left {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 2px;
}

/* Desktop : les 5 contrôles après lecture restent en ligne ; le bouton ⋮ est masqué. */
.controls-bar-more-btn {
    display: none !important;
}

.controls-bar-secondary {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 2px;
}

/* Libellés : visibles dans le menu mobile, masqués visuellement sur desktop (accessibilité conservée). */
.controls-bar-control {
    display: contents;
}

.controls-bar-control__label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Masqué par défaut ; évite les fuites tant que le parent n’est pas en inline-flex (desktop). */
.controls-bar-hover-tip {
    display: none;
}

/* Petit écran : ⋮ ouvre un panneau avec reculer / avancer / volume / mono / vitesse. */
@media screen and (max-width: 720px) {
    .controls-bar-left {
        position: relative;
        flex-wrap: nowrap;
    }

    .controls-bar-more-btn {
        display: flex !important;
    }

    .controls-bar-secondary {
        display: none;
        position: absolute;
        top: calc(100% + 6px);
        left: 0;
        z-index: 60;
        flex-direction: column;
        flex-wrap: nowrap;
        align-items: stretch;
        gap: 6px;
        padding: 10px;
        background: var(--ro-colors-bg-container, #fff);
        border: 1px solid var(--ro-colors-border-regular, #dfe3f3);
        border-radius: var(--ro-radii-md, 8px);
        box-shadow: var(--ro-shadow, 1px 6px 20px 0 rgba(18, 18, 18, 0.1));
    }

    .controls-bar-left.is-controls-more-open .controls-bar-secondary {
        display: flex;
    }

    .controls-bar-control:has(> .btn-download-record[hidden]) {
        display: none !important;
    }

    .controls-bar-control {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .controls-bar-control__label {
        position: static;
        width: auto;
        height: auto;
        margin: 0;
        overflow: visible;
        flex: 1;
        min-width: 0;
        text-align: left;
        font-size: var(--ro-fs-text-sm, 0.875rem);
        font-weight: var(--ro-fw-bolder, 500);
        color: var(--ro-colors-text-secondary, #646e7d);
        line-height: 1.3;
    }
    .controls-bar-secondary .controls-bar-control .btn[data-ro-shape="icon"],
    .controls-bar-secondary .controls-bar-control .btn-mono-stereo,
    .controls-bar-secondary .controls-bar-control .btn-speed {
        flex: 1;
        min-width: 0;
        width: auto;
        min-height: 40px;
        justify-content: flex-start;
        align-items: center;
        padding: 0 8px;
        gap: 10px;
    }

    /* Colonne fixe 20px (icône / St·Mo / vitesse) pour aligner les libellés dans le menu. */
    .controls-bar-secondary .controls-bar-control .btn > svg:first-child,
    .controls-bar-secondary .controls-bar-control .btn > i.ro-icon:first-child {
        flex: 0 0 20px;
        min-width: 20px;
        box-sizing: content-box;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .controls-bar-secondary .controls-bar-control .btn-mono-stereo > .btn-mono-stereo__label:first-child {
        flex: 0 0 20px;
        width: 20px;
        min-width: 20px;
        height: 20px;
        margin: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 11px;
    }

    .controls-bar-secondary .controls-bar-control .btn-speed > .btn-speed__label:first-child {
        flex: 0 0 20px;
        width: 20px;
        min-width: 20px;
        height: 20px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        font-weight: 600;
    }

    .controls-bar-secondary .controls-bar-control--volume .player-volume-wrap {
        flex: 1;
        min-width: 0;
        justify-content: stretch;
    }

    .controls-bar-secondary .player-volume-wrap {
        width: 100%;
        justify-content: center;
    }

    .controls-bar-secondary .player-volume-wrap > .btn {
        width: 100%;
    }

    .controls-bar-secondary .player-volume-popover {
        left: 0;
        right: 0;
        transform: none;
        width: 100%;
        max-width: none;
    }

    .controls-bar-hover-tip {
        display: none !important;
    }
}

/* Desktop : tooltips au survol (même rendu que .playhead-tooltip), sans dupliquer le layout mobile du menu ⋮. */
@media screen and (min-width: 721px) {
    .controls-bar-secondary .controls-bar-control {
        display: inline-flex;
        position: relative;
        align-items: center;
    }

    .controls-bar-hover-tip {
        display: block;
        transition: opacity 0.15s, visibility 0s;
        visibility: hidden;
        opacity: 0;
        position: absolute;
        bottom: calc(100% + 6px);
        left: 50%;
        transform: translateX(-50%);
        background: #1a1a2e;
        color: #fff;
        font-size: 11px;
        font-weight: 600;
        padding: 3px 7px;
        border-radius: 5px;
        white-space: nowrap;
        pointer-events: none;
        user-select: none;
        z-index: 80;
    }

    .controls-bar-hover-tip::after {
        content: '';
        position: absolute;
        bottom: -4px;
        left: 50%;
        transform: translateX(-50%);
        border: 4px solid transparent;
        border-bottom: none;
        border-top-color: #1a1a2e;
    }

    .controls-bar-secondary .controls-bar-control:hover .controls-bar-hover-tip,
    .controls-bar-secondary .controls-bar-control:focus-within .controls-bar-hover-tip {
        opacity: 1;
        visibility: visible;
    }
}

.player-volume-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.player-volume-popover {
    position: absolute;
    z-index: 40;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    min-width: 160px;
    padding: 12px 14px;
    background: #fff;
    border: 1.5px solid #e2ddf5;
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(45, 30, 80, 0.12);
}

.player-volume-label {
    display: none;
    font-size: 11px;
    font-weight: 600;
    color: #666;
    margin-bottom: 8px;
    letter-spacing: 0.02em;
}

.player-volume-range {
    --vol-pct: 100%;
    display: block;
    width: 100%;
    height: 6px;
    margin: 0;
    cursor: pointer;
    accent-color: var(--ro-colors-product-webapp-500);
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
}

.player-volume-range::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(
        90deg,
        var(--ro-colors-product-webapp-500) 0%,
        var(--ro-colors-product-webapp-500) var(--vol-pct),
        #e2ddf5 var(--vol-pct),
        #e2ddf5 100%
    );
}

.player-volume-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    margin-top: -5px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--ro-colors-product-webapp-500);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.player-volume-range::-moz-range-track {
    height: 6px;
    border-radius: 3px;
    background: #e2ddf5;
}

.player-volume-range::-moz-range-progress {
    height: 6px;
    border-radius: 3px;
    background: var(--ro-colors-product-webapp-500);
}

.player-volume-range::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--ro-colors-product-webapp-500);
    cursor: pointer;
}

.btn-mono-stereo {
    min-width: 36px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #555;
}

.btn-mono-stereo:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-mono-stereo[aria-pressed="true"] {
    background: #ede9fe;
    color: var(--ro-colors-product-webapp-700);
}

.btn {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #555;
    transition: background .15s;
}

.btn:hover {
    background: #f3f0fb;
}

.btn svg {
    width: 16px;
    height: 16px;
}

/* play button — purple background */
.btn-play {
    background: var(--ro-colors-product-webapp-500);
    color: #fff;
    border-radius: 9px;
}

.btn-play:hover {
    background: var(--ro-colors-product-webapp-700);
}

.btn-play.is-loading {
    position: relative;
    pointer-events: none;
    cursor: wait;
}

.btn-play.is-loading::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    box-sizing: border-box;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: player-record-spin 0.65s linear infinite;
}

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

/* speed selector */
.speed-select {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 10px;
    height: 34px;
    border: 1.5px solid #e2ddf5;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: #333;
    cursor: pointer;
    background: #fff;
    transition: border-color .15s;
}

.speed-select:hover {
    border-color: var(--ro-colors-product-webapp-500);
}

.speed-select svg {
    width: 12px;
    height: 12px;
    color: #888;
}

/* timestamp */
.timestamp {
    margin-left: auto;
    font-size: 16px;
    font-weight: 500;
    color: #888;
}

.timestamp .current {
    color: var(--ro-colors-product-webapp-500);
    font-weight: 600;
}

.btn-download-record:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* ── Waveform / timeline area ── */
.timeline-wrapper {
    padding-top: 20px;
    position: relative;
}

/* progress bar (background track) */
.progress-track {
    position: relative;
    height: 12px;
    background: #eee;
    border-radius: 6px;
    cursor: pointer;
}

.progress-fill {
    width: 0%;
    height: 100%;
    background: var(--ro-colors-business-outgoing-hover-light);
    border-radius: 2px;
    pointer-events: none;
}

/* playhead thumb */
.progress-track.is-disabled {
    cursor: not-allowed;
    opacity: 0.45;
    pointer-events: none;
}

.player-no-record .btn-play,
.player-audio-error .btn-play {
    opacity: 0.6;
}

.btn-speed {
    min-width: 44px;
    width: auto;
    padding: 0 8px;
    font-size: 12px;
    font-weight: 600;
    color: #333;
}

/* Playhead masqué jusqu’au chargement du média (.record-ready sur #timeline) */
#timeline:not(.record-ready) .playhead,
#timeline:not(.record-ready) .playhead-line {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

#timeline.record-ready .playhead,
#timeline.record-ready .playhead-line {
    visibility: visible;
    opacity: 1;
    transition: opacity 0.2s ease;
}

#timeline.record-ready .playhead {
    pointer-events: auto;
}

.playhead {
    position: absolute;
    top: calc(50% - 12px);
    left: 0%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    background: var(--ro-colors-product-webapp-500);
    border-radius: 50%;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, .18);
    cursor: grab;
    transition: box-shadow 0.15s, opacity 0.2s ease;
}

.playhead:hover {
    box-shadow: 0 0 0 6px rgba(124, 58, 237, .18);
}

.timeline-wrapper:hover .playhead-tooltip {
    opacity: 1;
    visibility: visible;
}

/* time tooltip above playhead */
.playhead-tooltip {
    transition: opacity 0.15s, visibility 0s;
    visibility: hidden;
    opacity: 0;
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: #1a1a2e;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 7px;
    border-radius: 5px;
    white-space: nowrap;
    pointer-events: none;
    user-select: none;
}

.playhead-tooltip::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-bottom: none;
    border-top-color: #1a1a2e;
}

/* vertical playhead line that extends through speaker rows */
.playhead-line {
    position: absolute;
    top: 12px;
    left: 0%;
    transform: translateX(-50%);
    width: 1.5px;
    height: calc(100% - 12px);
    background: var(--ro-colors-product-webapp-500);
    pointer-events: none;
    z-index: 1;
    transition: opacity 0.2s ease;
}

/* ── Speaker rows ── */
.speaker-row {
    display: flex;
    align-items: flex-start;
    margin-top: 10px;
    position: relative;
    flex-direction: column;
    width: 100%;
}

.speaker-label {
    font-size: 12px;
    font-weight: 600;
    user-select: none;
    pointer-events: none;
    padding-left: 10px;
    flex-shrink: 0;
}

/* segments track */
.segments-track {
    position: relative;
    background: #eee;
    border-radius: 6px;
    overflow: visible;
    height: 12px;
    width: 100%;
    margin-top: 4px;

}

.segment {
    position: absolute;
    height: 100%;
    border-radius: 6px;
    top: 0;
    cursor: pointer;
}

.segment:hover {
    opacity: 0.8;
}

.agent .segment {
    background: var(--ro-colors-success);
}
.agent .speaker-label {
    color: var(--ro-colors-success);
}

.client .segment {
    background: var(--ro-colors-business-outgoing);
}
.client .speaker-label {
    color: var(--ro-colors-business-outgoing);
}

@media screen and (max-width:767px),
(max-height:600px) {
    #player-container {
        height: 100vh;
        width: 100vw;
        box-shadow: none;
        border-radius: 0;
    }
    .card {
        padding: 0 16px 16px;
    }
}

@media screen and (max-width:500px) {
    .card {
        padding: 0;
    }
    #player-container {
        padding: var(--ro-size-3) var(--ro-size-3) var(--ro-size-6);
    }
}
