/* =============================================================
   Signal Theatre — Component Stylesheet
   Self-contained styles for the .ecp-* Signal Theatre component.
   Drop this file in any page that uses SignalTheatre.js.

   Design tokens are consumed from the host page's :root if they
   exist, with safe fallbacks scoped inside .ecp-wrap so the
   component works stand-alone too.
   ============================================================= */

/* ── Theming Layer ───────────────────────────────────────────
   Override any of these on a per-page basis by declaring them
   on the host element or in a page-level style block:

       #my-demo-mount {
           --ecp-brand: #38bdf8;
       }
   ──────────────────────────────────────────────────────────── */
.ecp-wrap {
    /* Colors — cascade from host page tokens where available */
    --ecp-bg:        var(--surface, #111720);
    --ecp-text:      var(--text, #e6ecf2);
    --ecp-muted:     var(--muted, #a5b1bd);
    --ecp-brand:     var(--brand, #14b8a6);
    --ecp-border:    var(--border, #233041);
    --ecp-danger:    var(--danger, #ef4444);
    --ecp-warning:   var(--warning, #f59e0b);
    --ecp-success:   var(--success, #10b981);
    --ecp-radius:    var(--radius, 16px);
    --ecp-radius-sm: var(--radius-sm, 8px);
    --ecp-shadow-lg: var(--shadow-lg, 0 20px 60px rgba(0,0,0,.35));

    /* Spacing — cascade from host page tokens */
    --ecp-sp2: var(--space-2, .5rem);
    --ecp-sp3: var(--space-3, .75rem);
    --ecp-sp4: var(--space-4, 1rem);
    --ecp-sp5: var(--space-5, 1.25rem);
    --ecp-sp6: var(--space-6, 1.5rem);

    /* Typography */
    --ecp-text-xs: var(--text-xs, .8rem);
    --ecp-text-sm: var(--text-sm, .9rem);
    --ecp-text-lg: var(--text-lg, 1.125rem);
}


/* ── Outer Wrapper ───────────────────────────────────────────── */
.ecp-wrap {
    background: var(--ecp-bg);
    border: 1px solid var(--ecp-border);
    border-radius: var(--ecp-radius);
    overflow: hidden;
    box-shadow: var(--ecp-shadow-lg);
    margin-top: var(--ecp-sp6);
    display: flex;
    flex-direction: column;
    position: relative;
    color: var(--ecp-text);
}

.ecp-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 300px;
    color: var(--ecp-muted);
    font-style: italic;
}


/* ── Header ──────────────────────────────────────────────────── */
.ecp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--ecp-sp4) var(--ecp-sp5);
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--ecp-border);
    flex-wrap: wrap;
    gap: var(--ecp-sp4);
}

.ecp-header-left {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ecp-persona {
    font-size: var(--ecp-text-sm);
    font-weight: 700;
    color: var(--ecp-text);
}

.ecp-badges {
    display: flex;
    align-items: center;
    gap: var(--ecp-sp2);
    flex-wrap: wrap;
}

.ecp-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.ecp-badge-hazard {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.ecp-badge-network {
    background: rgba(255, 255, 255, 0.05);
    color: var(--ecp-muted);
    border: 1px solid var(--ecp-border);
    text-transform: none;
    letter-spacing: normal;
    font-weight: 500;
}


/* ── Playback Controls ───────────────────────────────────────── */
.ecp-controls {
    display: flex;
    align-items: center;
    gap: var(--ecp-sp4);
    flex: 1;
    justify-content: flex-end;
}

.ecp-play-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--ecp-brand);
    border: none;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    box-shadow: 0 0 15px rgba(20, 184, 166, 0.3);
    flex-shrink: 0;
}

.ecp-play-btn:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.ecp-play-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.ecp-time-display {
    font-size: var(--ecp-text-xs);
    color: var(--ecp-muted);
    min-width: 75px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.ecp-scrubber-wrap {
    flex: 1;
    max-width: 300px;
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    position: relative;
    cursor: pointer;
}

.ecp-scrubber-fill {
    height: 100%;
    background: var(--ecp-brand);
    border-radius: 3px;
    width: 0%;
}

.ecp-scrubber-handle {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: white;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    left: 0%;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.2s;
}

.ecp-scrubber-wrap:hover .ecp-scrubber-handle {
    opacity: 1;
}


/* ── Main Layout ─────────────────────────────────────────────── */
.ecp-main {
    display: flex;
    flex: 1;
    border-bottom: 1px solid var(--ecp-border);
    /* Large enough to hold most cards without shift. Only the critical-risk retained
       card (with divergence + PCT badge) triggers a ~20-40px growth. */
    min-height: 460px;
}

@media (max-width: 900px) {
    .ecp-main {
        flex-direction: column;
    }
}

.ecp-waveform-wrap {
    flex: 6;
    padding: 0;
    background: rgba(0, 0, 0, 0.1);
    position: relative;
    border-right: 1px solid var(--ecp-border);
    display: flex;
    align-items: stretch;
    overflow: hidden;
}

@media (max-width: 900px) {
    .ecp-waveform-wrap {
        height: 220px;
        border-right: none;
        border-bottom: 1px solid var(--ecp-border);
    }
}

.ecp-waveform-wrap::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 60px;
    background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.2));
    pointer-events: none;
}

@media (max-width: 900px) {
    .ecp-waveform-wrap::after {
        display: none;
    }
}

.ecp-waveform-container {
    width: 100%;
    height: 100%;
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.ecp-waveform-container::-webkit-scrollbar {
    display: none;
}

.ecp-signal-panel {
    flex: 4;
    padding: var(--ecp-sp4);
    background: rgba(255, 255, 255, 0.01);
    display: flex;
    flex-direction: column;
    /* height locked by SignalTheatre.js via computePanelMinHeight() — no layout shift */
    overflow-y: auto;
    overflow-x: hidden;
}


.ecp-transcript-wrap {
    background: rgba(0, 0, 0, 0.05);
    padding: var(--ecp-sp3) var(--ecp-sp5);
    max-height: 140px;
    overflow-y: auto;
    border-bottom: 1px solid var(--ecp-border);
}

.ecp-footer {
    padding: var(--ecp-sp4) var(--ecp-sp5);
    font-size: var(--ecp-text-xs);
    color: var(--ecp-muted);
    line-height: 1.6;
}


/* ── Signal Card ─────────────────────────────────────────────── */
.ecp-signal-card {
    display: flex;
    flex-direction: column;
    gap: var(--ecp-sp4);
    animation: ecpFadeInRight 0.3s ease-out forwards;

    /* Final Polish */
    background: rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: var(--ecp-sp5);
    border-radius: var(--ecp-radius-sm);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}


/* ── Panel State Classes (State Machine) ─────────────────────── */
.ecp-panel--idle .ecp-signal-muted   { opacity: 0.6; font-style: italic; }
.ecp-panel--agent .ecp-signal-muted  { opacity: 0.8; font-weight: 500; }

.ecp-panel--listening {
    border: 1px dashed rgba(20, 184, 166, 0.3);
    border-radius: var(--ecp-radius-sm);
    background: rgba(20, 184, 166, 0.02);
    animation: ecpPulseBorder 2s infinite ease-in-out;
}

@keyframes ecpPulseBorder {
    0%, 100% { border-color: rgba(20, 184, 166, 0.2); }
    50%       { border-color: rgba(20, 184, 166, 0.5); }
}

.ecp-panel--listening-critical {
    border: 1px dashed rgba(239, 68, 68, 0.4);
    background: rgba(239, 68, 68, 0.03);
    animation: ecpPulseBorderCritical 1.5s infinite ease-in-out;
}

@keyframes ecpPulseBorderCritical {
    0%, 100% { border-color: rgba(239, 68, 68, 0.3); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
    50%       { border-color: rgba(239, 68, 68, 0.6); box-shadow: 0 0 10px 0 rgba(239, 68, 68, 0.1); }
}

.ecp-panel--analysing {
    position: relative;
    overflow: hidden;
}

.ecp-panel--analysing::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.05), transparent);
    transform: translateX(-100%);
    animation: ecpShimmer 0.8s infinite;
}

@keyframes ecpShimmer {
    100% { transform: translateX(100%); }
}

.ecp-panel--retained {
    opacity: 0.85;
    filter: saturate(0.9);
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.ecp-panel--exiting {
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.2s ease-in;
}

.ecp-retained-badge {
    position: absolute;
    top: 10px;
    right: 12px;
    font-size: 8px;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ecp-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    opacity: 0.8;
}

.ecp-panel--ended {
    position: relative;
}

.ecp-ended-overlay {
    position: absolute;
    inset: 0;
    background: rgba(11, 15, 20, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--ecp-sp6);
    z-index: 10;
    animation: ecpFadeIn 0.5s ease-out forwards;
}

@keyframes ecpFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}


/* ── Signal Muted State ──────────────────────────────────────── */
.ecp-signal-muted {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--ecp-muted);
    font-style: italic;
    opacity: 0.4;
    font-size: var(--ecp-text-sm);
    text-align: center;
}


/* ── Emotion Block ───────────────────────────────────────────── */
.ecp-emotion-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ecp-emotion-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--ecp-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.ecp-emotion-value {
    font-size: var(--ecp-text-lg);
    font-weight: 800;
    color: var(--ecp-text);
}


/* ── Paralinguistic Pill Events ──────────────────────────────── */
.ecp-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ecp-pill-event {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--ecp-border);
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    color: var(--ecp-brand);
    animation: ecpPillDrip 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes ecpPillDrip {
    from { opacity: 0; transform: scale(0.8) translateY(-5px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}


/* ── Gauge Bars ──────────────────────────────────────────────── */
.ecp-gauges {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--ecp-sp4);
}

.ecp-gauge-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ecp-gauge-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ecp-gauge-label {
    font-size: 9px;
    font-weight: 700;
    color: var(--ecp-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.ecp-gauge-value {
    font-size: 11px;
    font-weight: 700;
    color: var(--ecp-text);
}

.ecp-gauge-bar-wrap {
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    overflow: hidden;
}

.ecp-gauge-bar-fill {
    height: 100%;
    width: 0%;
    transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}


/* ── Divergence Card ─────────────────────────────────────────── */
.ecp-divergence-card {
    background: rgba(239, 68, 68, 0.03);
    border: 1px solid rgba(239, 68, 68, 0.12);
    border-radius: var(--ecp-radius-sm);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 4px;
    position: relative;
}

.ecp-divergence-card::before {
    content: 'CONFLICT DETECTED';
    position: absolute;
    top: -8px;
    right: 10px;
    background: #ef4444;
    color: white;
    font-size: 8px;
    font-weight: 800;
    padding: 1px 6px;
    border-radius: 2px;
}

.ecp-divergence-row {
    display: flex;
    gap: 10px;
    font-size: 11px;
    line-height: 1.5;
}

.ecp-divergence-icon {
    flex-shrink: 0;
    font-size: 14px;
    opacity: 0.8;
}

.ecp-divergence-text {
    color: var(--ecp-muted);
}

.ecp-divergence-text strong {
    color: var(--ecp-text);
    font-size: 10px;
    display: block;
    margin-bottom: 2px;
    font-weight: 700;
    text-transform: uppercase;
}


/* ── PCT Goal Conflict Badge ─────────────────────────────────── */
.ecp-pct-badge {
    margin-top: 0;
    padding: 8px 12px;
    background: rgba(20, 184, 166, 0.06);
    border-radius: var(--ecp-radius-sm);
    font-size: 10px;
    font-weight: 700;
    color: var(--ecp-brand);
    text-align: center;
    border: 1px solid rgba(20, 184, 166, 0.15);
    letter-spacing: 0.02em;
}

.ecp-pulse-danger {
    animation: ecpPulseDanger 2s infinite;
}

@keyframes ecpPulseDanger {
    0%   { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    70%  { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}


/* ── Transcript ──────────────────────────────────────────────── */
.ecp-transcript-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ecp-transcript-line {
    display: flex;
    gap: 12px;
    padding: 6px 8px;
    border-radius: var(--ecp-radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    opacity: 0.3;
    border-left: 2px solid transparent;
}

.ecp-transcript-line:hover {
    background: rgba(255, 255, 255, 0.05);
}

.ecp-transcript-line.active {
    opacity: 1;
    background: rgba(255, 255, 255, 0.03);
    border-left-color: var(--ecp-brand);
    transform: scale(1.01);
}

.ecp-transcript-line.past {
    opacity: 0.6;
}

.ecp-transcript-line.active.critical {
    border-left-color: var(--ecp-danger);
    background: rgba(239, 68, 68, 0.05);
}

.ecp-line-time {
    font-size: 10px;
    color: var(--ecp-muted);
    font-weight: 600;
    width: 35px;
    flex-shrink: 0;
    margin-top: 2px;
}

.ecp-line-speaker {
    font-size: 10px;
    font-weight: 700;
    width: 60px;
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.ecp-line-text {
    font-size: 11px;
    line-height: 1.4;
    color: var(--ecp-text);
}


/* ── Transcript Toggle (mobile) ──────────────────────────────── */
.ecp-transcript-toggle {
    display: none;
}


/* ── Scenario Selector ───────────────────────────────────────── */
.ecp-selector {
    display: flex;
    gap: var(--ecp-sp3);
    margin-bottom: var(--ecp-sp6);
    justify-content: center;
}

.ecp-selector-btn {
    padding: 8px 16px;
    border-radius: var(--ecp-radius-sm);
    font-size: 12px;
    font-weight: 600;
    background: var(--ecp-bg);
    border: 1px solid var(--ecp-border);
    color: var(--ecp-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.ecp-selector-btn.active {
    background: rgba(20, 184, 166, 0.1);
    border-color: var(--ecp-brand);
    color: var(--ecp-brand);
}

.ecp-selector-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}


/* ── Keyframe Animations ─────────────────────────────────────── */
@keyframes ecpFadeInRight {
    from { opacity: 0; transform: translateX(15px); }
    to   { opacity: 1; transform: translateX(0); }
}


/* ── Nav Button (Replay, etc.) ───────────────────────────────── */
.ecp-nav-btn {
    background: var(--ecp-brand);
    color: #031a17;
    border: none;
    padding: 8px 20px;
    border-radius: 99px;
    font-weight: 700;
    cursor: pointer;
    transition: filter 0.2s;
}

.ecp-nav-btn:hover {
    filter: brightness(1.1);
}


/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 767px) {
    .ecp-header {
        padding: var(--ecp-sp4);
    }

    .ecp-controls {
        flex-wrap: wrap;
    }

    .ecp-scrubber-wrap {
        order: 3;
        width: 100%;
        max-width: none;
        margin-top: var(--ecp-sp2);
    }

    .ecp-waveform-wrap {
        padding: var(--ecp-sp4);
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .ecp-waveform-container {
        min-width: 600px;
    }

    .ecp-transcript-wrap {
        display: none;
        max-height: 200px;
    }

    .ecp-transcript-wrap.is-visible {
        display: block;
    }

    .ecp-transcript-toggle {
        display: block;
        width: 100%;
        padding: 12px;
        background: rgba(255, 255, 255, 0.03);
        border: none;
        border-bottom: 1px solid var(--ecp-border);
        color: var(--ecp-brand);
        font-size: 10px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.1em;
        cursor: pointer;
    }

    .ecp-signal-panel {
        padding: var(--ecp-sp4);
        min-height: auto;
    }

    .ecp-gauges {
        grid-template-columns: 1fr;
    }
}
