/* ========================================
   RUN AUDIO PLAYER — call-recording playbar + speaker lanes
   ========================================

   Shared by the scenario page (Test Geçmişi) and the run popup on the Bulgular
   tab, so the two never drift apart visually. Extracted from scenario.css; the
   markup that goes with it is built by run_audio.js.

   Loaded by BOTH index.html and scenario.html. Keep it free of page-specific
   selectors — anything that only makes sense on one page belongs in that page's
   stylesheet, not here. */

/* Call recording for the selected run — proxied from ElevenLabs on demand, never
   stored, so the row only appears once a run with a conversation_id is selected. */
/* One grid for the player AND the speaker lanes: [button] [track] [time]. The lanes
   reuse column 2, which is what keeps a given timestamp at the same x in the seek bar
   and in the lanes. Laying them out as separate rows drifts them out of register. */
.run-audio-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 12px;
    row-gap: 6px;
    margin: 0 0 12px;
}

.run-audio-row.hidden {
    display: none;
}

.run-audio-row > .run-audio-play { grid-column: 1; }
.run-audio-row > .run-audio-track { grid-column: 2; }
.run-audio-row > .run-audio-time { grid-column: 3; }

.run-audio-row audio {
    display: none;
}

/* Round play/pause button, the anchor of the bar (mirrors the Agent Hub player). */
.run-audio-play {
    position: relative;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    background: var(--text);
    color: #ffffff;
    cursor: pointer;
    transition: var(--transition);
}

.run-audio-play:hover {
    background: var(--text-secondary);
}

/* Play is the resting face; the other two are swapped in by state classes so the
   button never changes size while loading. */
.run-audio-play .icon-pause,
.run-audio-play .run-audio-spinner {
    display: none;
}

.run-audio-row.is-playing .run-audio-play .icon-play {
    display: none;
}

.run-audio-row.is-playing .run-audio-play .icon-pause {
    display: inline-block;
}

.run-audio-row.is-loading .run-audio-play .icon-play,
.run-audio-row.is-loading .run-audio-play .icon-pause {
    display: none;
}

.run-audio-row.is-loading .run-audio-play .run-audio-spinner {
    display: block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #ffffff;
    animation: run-audio-spin 0.7s linear infinite;
}

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

.run-audio-track {
    position: relative;
    flex: 1;
    min-width: 0;
    height: 10px;
    border-radius: 999px;
    background: rgba(46, 55, 40, 0.15);
}

.run-audio-fill {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 0;
    border-radius: 999px;
    background: var(--text);
}

/* A real range input rides invisibly on top of the track: keyboard support and
   drag-to-seek come free, while the visible fill above stays fully styleable. */
.run-audio-seek {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
}

.run-audio-seek:disabled {
    cursor: default;
}

.run-audio-seek::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border: 0;
    border-radius: 50%;
    background: var(--text);
    cursor: pointer;
}

.run-audio-seek::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border: 0;
    border-radius: 50%;
    background: var(--text);
    cursor: pointer;
}

.run-audio-seek:disabled::-webkit-slider-thumb { opacity: 0; }
.run-audio-seek:disabled::-moz-range-thumb { opacity: 0; }

.run-audio-time {
    flex-shrink: 0;
    font-size: 12px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.run-audio-time .run-audio-tot {
    font-weight: 700;
}

.run-audio-msg {
    grid-column: 1 / -1;
    font-size: 12px;
    color: var(--text-muted);
}

/* No error to show: collapse rather than leave an empty grid row behind. */
.run-audio-msg:empty {
    display: none;
}

/* Two-lane turn map under the playbar: one row per speaker, one block per turn.
   Block STARTS are exact (ElevenLabs reports them); block WIDTHS are estimated from
   speech rate, which is why a block is labelled with its start time only.

   display:contents dissolves these two wrappers so the tags and tracks below become
   items of the player grid itself — that is what puts each lane's track in the same
   column as the seek bar. */
.run-audio-timeline,
.run-audio-lane {
    display: contents;
}

.run-audio-timeline.hidden {
    display: none;
}

.run-audio-lane-tag {
    grid-column: 1;
    justify-self: center;
    width: 24px;
    text-align: center;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    border-radius: 5px;
    background: rgba(99, 127, 31, 0.14);
    color: var(--text-secondary);
}

.run-audio-lane-tag.lane-tag-user {
    background: rgba(184, 236, 60, 0.28);
    color: #5f7f1f;
}

.run-audio-lane-track {
    grid-column: 2;
    display: flex;
    min-width: 0;
    height: 9px;
}

.tl-gap {
    display: inline-block;
    height: 100%;
    flex-shrink: 0;
}

.tl-seg {
    position: relative;
    display: inline-block;
    height: 100%;
    flex-shrink: 0;
    cursor: pointer;
}

/* The visible bar is a layer of its own so hover can widen it without disturbing
   the tooltip's anchor. --seg-fill is written from JS as playback advances. */
.tl-seg::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 6px;
    background-color: #cfd6c4;
    background-image: linear-gradient(
        to right,
        rgba(113, 163, 13, 0.6) 0 var(--seg-fill, 0%),
        transparent var(--seg-fill, 0%)
    );
    transition: background-color 0.2s ease, left 0.12s ease, right 0.12s ease;
}

/* Invisible fat handle: short turns are only a few pixels wide, so the pointer needs
   a bigger target than the bar itself. */
.tl-seg::after {
    content: "";
    position: absolute;
    inset: -8px -3px;
}

.tl-seg:hover {
    z-index: 5;
}

.tl-seg:hover::before {
    background-color: #b4bda6;
    left: -3px;
    right: -3px;
}

.tl-seg.tl-seg--active::before {
    background-color: rgba(152, 211, 23, 1);
}

/* Yükseklik sınırı kutunun kendisinde DEĞİL, alıntının üzerinde: kutuyu topluca
   kırpmak, en alta eklenen "ihlal edilen kural" bloğunu — yani ipucundaki en
   önemli bilgiyi — kesiyordu. Artık uzun bir replik kendi içinde kırpılır,
   kural bloğu her zaman tam görünür (bkz. .tl-tip-text). */
.tl-tip {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    width: max-content;
    max-width: 300px;
    padding: 7px 10px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14);
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.45;
    white-space: normal;
    text-align: left;
    pointer-events: none;
}

.tl-seg:hover .tl-tip {
    display: block;
}

/* Repliğin kendisi: uzun bir cevap ipucunu sayfa boyu uzatmasın diye beş satıra
   kırpılır. Kırpılacak bir şey varsa o, alıntının kuyruğudur — konuşmanın
   tamamı zaten transkriptte duruyor. */
.tl-tip-text {
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Speaker + offset, above the quoted line. */
.tl-tip-head {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

/* Same colours as the AJ/MK lane tags and the transcript avatars, so the badge
   reads as "this side of the conversation" without another legend. */
.tl-tip-who {
    padding: 1px 6px;
    border-radius: 5px;
    font-size: 10px;
    font-weight: 700;
    line-height: 15px;
    background: rgba(99, 127, 31, 0.14);
    color: var(--text-secondary);
}

.tl-tip-who.tl-tip-who--user {
    background: rgba(184, 236, 60, 0.28);
    color: #5f7f1f;
}

.tl-tip-time {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
}
