/**
 * RAXE Ensemble Voting Visualization — 3-Tier Progressive Disclosure
 * Tier 1: Verdict Banner (always visible)
 * Tier 2: Classifier Rows (visible desktop, toggle mobile)
 * Tier 3: Technical Deep Dive (collapsed by default)
 */

/* ===== Container ===== */
.voting-viz {
    background: var(--color-surface-secondary);
    border: 1px solid var(--color-border-primary);
    border-radius: var(--radius-xl);
    margin-top: var(--space-8);
    overflow: hidden;
    display: none;
}

.voting-viz.active {
    display: block;
    animation: vizFadeIn 0.3s var(--ease-out);
}

@keyframes vizFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ===== Hide old elements that main.js scaffolded ===== */
.voting-viz > .voting-header,
.voting-viz > .voting-comparison-banner,
.voting-viz > .preset-selector,
.voting-viz > .votes-grid,
.voting-viz > .voting-calculation,
.voting-viz > .voting-decision {
    display: none !important;
}


/* =====================================================
 * TIER 1 — Verdict Banner
 * ===================================================== */
.voting-verdict {
    text-align: center;
    padding: var(--space-8) var(--space-6) var(--space-6);
}

/* Dot row */
.verdict-dots {
    display: flex;
    justify-content: center;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.verdict-dots[aria-label] {
    /* aria-label set by JS for screen readers */
}

.vote-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    opacity: 0;
    transform: scale(0.5);
    animation: dotReveal 0.3s var(--ease-spring) forwards;
}

.vote-dot.threat {
    background: var(--sev-critical-text);
}

.vote-dot.safe {
    background: var(--sev-low-text);
}

.vote-dot.abstain {
    background: transparent;
    border: 2px solid var(--text-amber);
}

.vote-dot.review {
    background: transparent;
    border: 2px solid var(--text-amber);
}

/* Stagger delays set inline by JS via animation-delay */

@keyframes dotReveal {
    from { opacity: 0; transform: scale(0.5); }
    to   { opacity: 1; transform: scale(1); }
}

/* Headline */
.verdict-headline {
    font-family: var(--font-head);
    font-size: var(--fs-h3);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    line-height: var(--leading-snug);
    margin: 0 0 var(--space-2);
    opacity: 0;
    animation: fadeUp 0.35s var(--ease-out) 0.5s forwards;
}

.verdict-label {
    font-weight: var(--weight-extrabold);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
}

.verdict-label.threat { color: var(--sev-critical-text); }
.verdict-label.safe   { color: var(--sev-low-text); }
.verdict-label.review { color: var(--text-amber); }

/* Scale pop on the verdict label */
.verdict-label {
    display: inline-block;
    opacity: 0;
    animation: labelPop 0.3s var(--ease-spring) 0.6s forwards;
}

@keyframes labelPop {
    from { opacity: 0; transform: scale(0.85); }
    to   { opacity: 1; transform: scale(1); }
}

/* Subtitle */
.verdict-subtitle {
    font-family: var(--font-body);
    font-size: var(--fs-body-sm);
    color: var(--text-muted);
    line-height: var(--leading-normal);
    margin: 0;
    opacity: 0;
    animation: fadeUp 0.3s var(--ease-out) 0.7s forwards;
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}


/* =====================================================
 * TIER 2 — Classifier Rows
 * ===================================================== */
.voting-tier2 {
    padding: 0 var(--space-6) var(--space-4);
}

/* Mobile toggle button (visible only < 768px) */
.tier2-toggle {
    display: none;
    width: 100%;
    min-height: 44px;
    padding: var(--space-3) var(--space-4);
    background: var(--color-surface-elevated);
    border: 1px solid var(--color-border-primary);
    border-radius: var(--radius-lg);
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: var(--fs-body-sm);
    font-weight: var(--weight-medium);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    transition: var(--transition-ui);
    margin-bottom: var(--space-3);
}

.tier2-toggle:hover {
    color: var(--text-primary);
    border-color: var(--color-border-strong);
    background: var(--color-surface-card);
}

.tier2-toggle:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

.tier2-toggle svg {
    width: 14px;
    height: 14px;
    transition: transform var(--duration-fast) var(--ease-default);
}

.tier2-toggle[aria-expanded="true"] svg {
    transform: rotate(180deg);
}

@media (max-width: 767px) {
    .tier2-toggle {
        display: flex;
    }

    .tier2-content[hidden] {
        display: none;
    }
}

/* Classifier rows container */
.tier2-content {
    display: flex;
    flex-direction: column;
}

/* Individual classifier row */
/* --- Classifier Row ---
   Layout:
     [icon] Name + question        [detail tag]     [VOTE]
            [━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━] 95%
*/

.classifier-row {
    display: grid;
    grid-template-columns: 28px 1fr auto 64px;
    grid-template-rows: auto auto;
    column-gap: var(--space-3);
    row-gap: var(--space-1);
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border-subtle);
    align-items: center;
    opacity: 0;
    animation: rowSlideIn 0.3s var(--ease-out) forwards;
}

.classifier-row:last-child {
    border-bottom: none;
}

@keyframes rowSlideIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Icon: row 1-2, col 1 */
.classifier-icon {
    grid-row: 1 / 3;
    grid-column: 1;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-dim);
    align-self: start;
    margin-top: 2px;
}

.classifier-icon svg {
    width: 14px;
    height: 14px;
}

/* Info wrapper not used in grid — children placed directly */
.classifier-info {
    display: contents;
}

/* Name + question: row 1, col 2 */
.classifier-meta {
    grid-row: 1;
    grid-column: 2;
    min-width: 0;
}

.classifier-name {
    font-family: var(--font-body);
    font-size: var(--fs-body-sm);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    line-height: 1.3;
}

.classifier-question {
    font-family: var(--font-body);
    font-size: 11px;
    color: var(--text-dim);
    line-height: 1.3;
}

/* Detail tag (Jailbreak, Instruction Override): row 1, col 3 */
.classifier-detail {
    grid-row: 1;
    grid-column: 3;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.04);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    align-self: center;
}

/* Vote badge: row 1, col 4 — right-aligned */
.classifier-vote {
    grid-row: 1;
    grid-column: 4;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    padding: 3px 0;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    text-align: center;
}

.classifier-vote.vote-threat {
    background: rgba(248, 113, 113, 0.15);
    color: var(--sev-critical-text);
    border: 1px solid var(--sev-critical-border);
}

.classifier-vote.vote-safe {
    background: rgba(52, 211, 153, 0.12);
    color: var(--sev-low-text);
    border: 1px solid var(--sev-low-border);
}

.classifier-vote.vote-abstain,
.classifier-vote.vote-review {
    background: rgba(245, 158, 11, 0.12);
    color: var(--text-amber);
    border: 1px solid var(--border-amber);
}

/* Result wrapper — children placed in grid via display:contents */
.classifier-result {
    display: contents;
}

/* Bar: row 2, col 2-3 */
.classifier-bar {
    grid-row: 2;
    grid-column: 2 / 4;
    height: 3px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 2px;
    overflow: hidden;
}

.classifier-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.5s var(--ease-out);
}

.classifier-row[data-vote="threat"] .classifier-bar-fill {
    background: linear-gradient(90deg, rgba(239, 68, 68, 0.3), var(--sev-critical-text));
}

.classifier-row[data-vote="safe"] .classifier-bar-fill {
    background: linear-gradient(90deg, rgba(16, 185, 129, 0.3), var(--sev-low-text));
}

.classifier-row[data-vote="abstain"] .classifier-bar-fill {
    background: linear-gradient(90deg, rgba(245, 158, 11, 0.2), #fbbf24);
}

/* Percentage: row 2, col 4 — right of bar */
.classifier-pct {
    grid-row: 2;
    grid-column: 4;
    font-family: var(--font-mono);
    font-size: var(--fs-label);
    font-weight: var(--weight-semibold);
    color: var(--text-muted);
    text-align: center;
}

/* Responsive */
@media (max-width: 767px) {
    .classifier-row {
        grid-template-columns: 28px 1fr auto;
        grid-template-rows: auto auto auto;
    }

    .classifier-vote {
        grid-column: 3;
    }

    .classifier-detail {
        grid-row: 2;
        grid-column: 2 / 4;
    }

    .classifier-bar {
        grid-row: 3;
        grid-column: 2 / 3;
    }

    .classifier-pct {
        grid-row: 3;
        grid-column: 3;
    }

    .classifier-question {
        display: none;
    }
}


/* =====================================================
 * TIER 3 — Technical Deep Dive (collapsed by default)
 * ===================================================== */
.voting-tier3 {
    padding: 0 var(--space-6) var(--space-6);
}

/* Toggle button */
.tier3-toggle {
    display: flex;
    width: 100%;
    padding: var(--space-3) var(--space-4);
    background: transparent;
    border: 1px solid var(--color-border-primary);
    border-radius: var(--radius-lg);
    color: var(--text-dim);
    font-family: var(--font-body);
    font-size: var(--fs-caption);
    font-weight: var(--weight-medium);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    transition: var(--transition-ui);
}

.tier3-toggle:hover {
    color: var(--text-muted);
    border-color: var(--color-border-strong);
    background: var(--color-surface-elevated);
}

.tier3-toggle:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

.tier3-toggle svg {
    width: 14px;
    height: 14px;
    transition: transform var(--duration-fast) var(--ease-default);
}

.tier3-toggle[aria-expanded="true"] svg {
    transform: rotate(180deg);
}

/* Tier 3 content panel */
.tier3-content {
    margin-top: var(--space-4);
}

.tier3-content[hidden] {
    display: none;
}

/* Preset selector (relocated to Tier 3) */
.tier3-presets {
    padding: var(--space-4) 0;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: var(--space-4);
}

.tier3-presets-label {
    display: block;
    font-size: var(--fs-label);
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    margin-bottom: var(--space-3);
}

.tier3-preset-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.tier3-preset-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: var(--space-2) var(--space-3);
    min-height: 36px;
    background: var(--color-surface-elevated);
    border: 1px solid var(--color-border-primary);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: var(--fs-caption);
    font-weight: var(--weight-medium);
    cursor: pointer;
    transition: var(--transition-ui);
}

.tier3-preset-btn:hover {
    background: var(--color-surface-card);
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.tier3-preset-btn:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

.tier3-preset-btn.active {
    background: rgba(56, 189, 248, 0.12);
    border-color: var(--cyan);
    color: var(--cyan);
    box-shadow: var(--shadow-glow-cyan);
}

.tier3-preset-btn svg {
    width: 14px;
    height: 14px;
}

.tier3-preset-btn .preset-icon {
    font-size: 0.875rem;
    line-height: 1;
}

/* Weighted scores + Decision rules grid */
.tier3-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}

@media (max-width: 768px) {
    .tier3-grid {
        grid-template-columns: 1fr;
    }
}

/* Calc section (shared with old structure — reused names) */
.tier3-calc-section {
    background: var(--color-surface-card);
    border: 1px solid var(--color-border-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
}

.tier3-calc-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-family: var(--font-body);
    font-size: var(--fs-body-sm);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    margin-bottom: var(--space-4);
}

.tier3-calc-title svg {
    width: 16px;
    height: 16px;
    color: var(--cyan);
}

/* Weighted scores */
.tier3-scores {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.tier3-score-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    background: var(--color-surface-elevated);
    border-radius: var(--radius-md);
}

.tier3-score-label {
    font-family: var(--font-body);
    font-size: var(--fs-body-sm);
    font-weight: var(--weight-medium);
}

.tier3-score-label.threat { color: var(--sev-critical-text); }
.tier3-score-label.safe   { color: var(--sev-low-text); }
.tier3-score-label.abstain { color: var(--text-amber); }

.tier3-score-value {
    font-family: var(--font-mono);
    font-size: var(--fs-body-sm);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
}

.tier3-score-heads {
    font-size: var(--fs-micro);
    color: var(--text-dim);
    margin-top: 1px;
}

/* Ratio */
.tier3-ratio {
    margin-top: var(--space-4);
    padding: var(--space-3);
    background: var(--color-surface-elevated);
    border-radius: var(--radius-md);
    text-align: center;
}

.tier3-ratio-label {
    font-size: var(--fs-label);
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    margin-bottom: 2px;
}

.tier3-ratio-value {
    font-family: var(--font-mono);
    font-size: 1.25rem;
    font-weight: var(--weight-black);
    color: var(--text-primary);
}

.tier3-ratio-threshold {
    font-size: var(--fs-label);
    color: var(--text-muted);
    margin-top: 2px;
}

.tier3-ratio-threshold.met     { color: var(--sev-low-text); }
.tier3-ratio-threshold.not-met { color: var(--sev-critical-text); }

/* Decision rules */
.tier3-rules {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.tier3-rule {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--color-surface-elevated);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--color-border-primary);
}

.tier3-rule.passed {
    border-left-color: #10b981;
}

.tier3-rule.failed {
    border-left-color: var(--text-muted);
    opacity: 0.6;
}

.tier3-rule.deciding {
    border-left-color: var(--cyan);
    background: rgba(56, 189, 248, 0.08);
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.15);
}

.tier3-rule-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: var(--fs-label);
}

.tier3-rule.passed .tier3-rule-icon {
    background: rgba(16, 185, 129, 0.2);
    color: var(--sev-low-text);
}

.tier3-rule.failed .tier3-rule-icon {
    background: rgba(100, 100, 100, 0.2);
    color: var(--text-muted);
}

.tier3-rule.deciding .tier3-rule-icon {
    background: rgba(56, 189, 248, 0.2);
    color: var(--cyan);
}

.tier3-rule-content {
    flex: 1;
    min-width: 0;
}

.tier3-rule-name {
    font-family: var(--font-body);
    font-size: var(--fs-body-sm);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    margin-bottom: 1px;
}

.tier3-rule.failed .tier3-rule-name {
    color: var(--text-body);
}

.tier3-rule-details {
    font-size: var(--fs-micro);
    color: var(--text-muted);
    line-height: var(--leading-normal);
}

/* Per-head weight breakdown */
.tier3-weights {
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-subtle);
}

.tier3-weights-title {
    font-size: var(--fs-label);
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    margin-bottom: var(--space-3);
}

.tier3-weight-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-1) 0;
}

.tier3-weight-head {
    font-family: var(--font-body);
    font-size: var(--fs-caption);
    color: var(--text-muted);
    min-width: 120px;
}

.tier3-weight-bar {
    flex: 1;
    height: 6px;
    background: var(--color-surface-elevated);
    border-radius: 3px;
    overflow: hidden;
}

.tier3-weight-fill {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--cyan), var(--magenta));
    transition: width 0.4s var(--ease-out);
}

.tier3-weight-value {
    font-family: var(--font-mono);
    font-size: var(--fs-caption);
    color: var(--text-dim);
    min-width: 30px;
    text-align: right;
}

/* Deciding rule footer */
.tier3-deciding-rule {
    margin-top: var(--space-4);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-subtle);
    font-size: var(--fs-caption);
    color: var(--text-dim);
    text-align: center;
}

.tier3-deciding-rule strong {
    color: var(--text-body);
}


/* =====================================================
 * Voting header — mobile flex-wrap
 * ===================================================== */
@media (max-width: 768px) {
    .voting-header {
        flex-wrap: wrap;
        gap: var(--space-3);
    }
}

/* Small phone overrides */
@media (max-width: 480px) {
    .voting-verdict {
        padding: var(--space-6) var(--space-4) var(--space-4);
    }

    .voting-tier2 {
        padding: 0 var(--space-4) var(--space-3);
    }

    .voting-tier3 {
        padding: 0 var(--space-4) var(--space-4);
    }

    .tier3-preset-buttons {
        gap: var(--space-1);
    }

    .tier3-preset-btn {
        font-size: var(--fs-micro);
        padding: var(--space-1) var(--space-2);
        min-height: 32px;
    }
}

/* =====================================================
 * Transition state (when changing presets)
 * ===================================================== */
.voting-viz.transitioning .vote-dot,
.voting-viz.transitioning .verdict-headline,
.voting-viz.transitioning .verdict-label,
.voting-viz.transitioning .verdict-subtitle,
.voting-viz.transitioning .classifier-row {
    animation: none;
    opacity: 1;
    transform: none;
}


/* =====================================================
 * Reduced motion
 * ===================================================== */
@media (prefers-reduced-motion: reduce) {
    .vote-dot,
    .verdict-headline,
    .verdict-label,
    .verdict-subtitle,
    .classifier-row {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }

    .tier2-toggle svg,
    .tier3-toggle svg {
        transition: none;
    }

    .classifier-bar-fill,
    .tier3-weight-fill {
        transition: none;
    }
}
