/**
 * RCV Demo Widget Styles
 * Standalone widget version for embedding
 */

:root {
    --rcv-primary: #4269FF;
    --rcv-primary-dark: #3254CC;
    --rcv-text: #32373c;
    --rcv-text-light: #595959;
    --rcv-background: #f0f0f0;
    --rcv-border: #dedede;
    --rcv-white: #ffffff;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: Arial, -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--rcv-text);
    background: transparent;
    margin: 0;
    padding: 8px;
    display: flex;
    justify-content: center;
}

.rcv-widget {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
}

/* Voting Mode Toggle */
.voting-mode-toggle {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 16px;
    background: var(--rcv-background);
    padding: 3px;
    border-radius: 6px;
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
}

.mode-btn {
    flex: 1;
    padding: 7px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    background: transparent;
    color: var(--rcv-text-light);
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s;
}

.mode-btn:hover:not(.active) {
    background: rgba(0, 0, 0, 0.05);
}

.mode-btn.active {
    background: #10b981;
    color: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#rcv-mode-btn:hover:not(.active) {
    background: rgba(16, 185, 129, 0.1);
}

#wta-mode-btn.active {
    background: #ef4444;
}

#wta-mode-btn:hover:not(.active) {
    background: rgba(239, 68, 68, 0.1);
}

/* Interactive Demo */
.rcv-demo {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 24px;
    background: var(--rcv-white);
    padding: 24px;
    align-items: stretch;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.demo-ballot,
.demo-results {
    display: flex;
    flex-direction: column;
}

.demo-ballot h3,
.demo-results h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--rcv-text);
    margin-bottom: 10px;
    text-align: center;
}

.demo-ballot h3 {
    margin-bottom: 12px;
}

.demo-results h3 {
    margin-bottom: 6px;
}

.ballot-instructions {
    color: var(--rcv-text-light);
    font-size: 0.9rem;
    margin-bottom: 12px;
    text-align: center;
}

.candidate-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.candidate-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--rcv-background);
    border: 2px solid var(--rcv-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.candidate-item:hover:not(.locked) {
    border-color: var(--rcv-primary);
    box-shadow: 0 2px 8px rgba(66, 105, 255, 0.2);
}

.candidate-item.unranked .rank-badge {
    background: var(--rcv-border);
    color: var(--rcv-text-light);
}

.candidate-item.unranked .rank-badge::after {
    content: '?';
}

.candidate-item.ranked {
    border-color: var(--rcv-primary);
    background: rgba(66, 105, 255, 0.05);
}

.candidate-item.locked {
    cursor: default;
    opacity: 0.8;
}

.rank-badge {
    width: 26px;
    height: 26px;
    background: var(--rcv-primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.candidate-icon {
    font-size: 1.4rem;
}

.candidate-name {
    flex: 1;
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--rcv-text);
}

/* Results Display */
.results-display {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.results-placeholder {
    color: var(--rcv-text);
    text-align: center;
    padding: 16px;
    background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%);
    border-left: 3px solid var(--rcv-primary);
    border-radius: 0 6px 6px 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    line-height: 1.8;
}

.results-placeholder::before {
    content: '🗳️';
    font-size: 2rem;
    margin-bottom: 6px;
}

.election-info {
    text-align: center;
    /* Match spacing of ballot-instructions to align purple container with candidate list */
    min-height: 30px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.election-info:not(:empty) {
    margin-bottom: 6px;
}

.election-info p {
    margin: 2px 0;
    color: var(--rcv-text);
    font-size: 0.85rem;
}

.round-result {
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--rcv-border);
}

.round-result:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.round-result h4 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--rcv-primary);
    margin-bottom: 10px;
    text-align: center;
}

.vote-bar {
    margin-bottom: 8px;
}

.bar-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 0.9rem;
    color: var(--rcv-text);
}

.bar-track {
    height: 24px;
    background: var(--rcv-background);
    border-radius: 5px;
    overflow: hidden;
    position: relative;
}

.bar-fill {
    height: 100%;
    background: var(--rcv-primary);
    border-radius: 5px;
    transition: width 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}

.vote-bar.eliminated .bar-fill {
    background: #ef4444;
}

.vote-bar.winner .bar-fill {
    background: #10b981;
}

.vote-bar.wta-no-majority-winner .bar-fill {
    background: #ef4444;
}

.vote-bar.wta-no-majority-winner .winner-badge {
    background: #ef4444;
}

.winner-badge,
.eliminated-badge {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.65rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 3px;
}

.winner-badge {
    background: #10b981;
    color: white;
}

.eliminated-badge {
    background: #ef4444;
    color: white;
}

.round-explanation {
    background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%);
    border-left: 3px solid var(--rcv-primary);
    padding: 10px 12px;
    margin-top: 10px;
    border-radius: 0 6px 6px 0;
    animation: slideDown 0.6s ease-out;
}

.round-explanation.rcv-success {
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    border-left-color: #10b981;
}

.round-note {
    font-size: 0.9rem;
    color: var(--rcv-text);
    margin: 5px 0;
    line-height: 1.4;
}

.round-note:first-child {
    margin-top: 0;
}

.round-note:last-child {
    margin-bottom: 0;
}

.winner-message {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    padding: 16px 20px;
    border-radius: 6px;
    text-align: center;
    animation: scaleIn 1s cubic-bezier(0.22, 1, 0.36, 1);
    margin-top: 14px;
}

.round-result + .winner-message {
    margin-top: 14px;
}

.round-result:has(+ .winner-message) {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

.winner-message.wta-no-majority {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white !important;
    text-align: left;
    padding: 10px 14px;
}

.winner-message.wta-no-majority h3,
.winner-message.wta-no-majority p {
    color: white !important;
}

.wta-results-list {
    list-style-type: disc;
    padding-left: 20px;
    margin: 4px 0 0 0;
    text-align: left;
}

.wta-results-list li {
    color: white;
    margin: 2px 0;
    line-height: 1.3;
    font-size: 0.95rem;
}

.round-explanation.wta-warning {
    border-left-color: #ef4444;
    background: linear-gradient(135deg, #fecaca 0%, #fca5a5 100%);
}

.round-explanation.wta-warning .round-note {
    color: #7f1d1d;
}

/* Vote Split Analysis */
.vote-split-analysis {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 2px solid #f59e0b;
    border-radius: 6px;
    padding: 8px 12px;
    margin-top: 10px;
    margin-bottom: 10px;
    text-align: center;
    animation: slideDown 0.6s ease-out;
}

.vote-split-analysis h4 {
    font-size: 1.3rem;
    color: #92400e;
    margin-bottom: 4px;
}

.vote-split-analysis p {
    color: #78350f;
    margin: 2px 0 0 0;
    font-size: 0.9rem;
}

.coalition-bar {
    background: var(--rcv-white);
    border-radius: 5px;
    height: 24px;
    position: relative;
    margin: 6px 0;
    overflow: hidden;
    border: 2px solid #d97706;
}

.coalition-fill {
    height: 100%;
    background: linear-gradient(90deg, #f97316 0%, #fb923c 100%);
    border-radius: 3px;
    transition: width 1s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.coalition-label {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-weight: 700;
    color: #78350f;
    font-size: 0.85rem;
    text-shadow: 0 1px 2px rgba(255,255,255,0.8);
}

.split-conclusion {
    font-weight: 600;
    font-size: 0.85rem !important;
}

.split-points {
    list-style-type: disc;
    padding-left: 20px;
    margin: 4px 0;
    text-align: left;
}

.split-points li {
    color: #78350f;
    margin: 2px 0;
    line-height: 1.3;
    font-size: 0.95rem;
    font-weight: normal;
}

.rcv-note {
    font-size: 0.75rem !important;
    color: #92400e !important;
    margin-top: 8px !important;
}

.winner-message h3 {
    font-size: 1.3rem;
    margin-bottom: 4px;
    color: white;
}

.winner-message p {
    font-size: 0.9rem;
}

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

@keyframes scaleIn {
    0% {
        opacity: 0;
        transform: scale(0.8);
    }
    60% {
        transform: scale(1.02);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-25px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Buttons */
.btn-primary {
    padding: 12px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    background: var(--rcv-primary);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}

.btn-primary:hover {
    background: var(--rcv-primary-dark);
}

.btn-primary.disabled,
.btn-primary:disabled {
    background: #a0aec0;
    cursor: not-allowed;
    opacity: 0.7;
}

.btn-primary.disabled:hover,
.btn-primary:disabled:hover {
    background: #a0aec0;
}

.btn-secondary {
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    background: linear-gradient(135deg, var(--rcv-primary) 0%, var(--rcv-primary-dark) 100%);
    color: white;
    border: 2px solid var(--rcv-primary);
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    margin-top: 12px;
    animation: fadeIn 0.5s ease-out;
}

.btn-secondary:hover {
    background: linear-gradient(135deg, var(--rcv-primary-dark) 0%, #2845a6 100%);
    color: white;
}

.btn-secondary.rcv-solution-btn {
    background: linear-gradient(135deg, var(--rcv-primary) 0%, var(--rcv-primary-dark) 100%);
    color: white;
    border-color: var(--rcv-primary);
}

.btn-secondary.rcv-solution-btn:hover {
    background: linear-gradient(135deg, var(--rcv-primary-dark) 0%, #2845a6 100%);
    border-color: var(--rcv-primary-dark);
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(66, 105, 255, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(66, 105, 255, 0);
    }
}

/* Round Navigation */
.round-navigation {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 12px;
}

.round-nav-btn {
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    background: white;
    color: var(--rcv-primary);
    border: 2px solid var(--rcv-primary);
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s;
    animation: fadeIn 0.5s ease-out;
}

.round-nav-btn:hover {
    background: var(--rcv-primary);
    color: white;
}

.round-nav-btn.primary {
    background: var(--rcv-primary);
    color: white;
}

.round-nav-btn.primary:hover {
    background: var(--rcv-primary-dark);
    border-color: var(--rcv-primary-dark);
}

/* Responsive */
@media (max-width: 700px) {
    .rcv-demo {
        grid-template-columns: 1fr;
        padding: 24px;
    }

    .demo-results {
        border-top: 1px solid var(--rcv-border);
        padding-top: 24px;
        align-items: center;
    }

    .demo-results h3,
    .election-info,
    .results-display,
    .btn-secondary {
        max-width: 400px;
        width: 100%;
    }

    /* Compact winner message and sliced campaigns on mobile */
    .winner-message {
        padding: 12px 14px;
        margin-top: 10px;
    }

    .winner-message h3 {
        font-size: 1.1rem;
        margin-bottom: 2px;
    }

    .winner-message p {
        font-size: 0.85rem;
    }

    .wta-results-list {
        padding-left: 18px;
        margin: 2px 0 0 0;
    }

    .wta-results-list li {
        font-size: 0.85rem;
        margin: 1px 0;
        line-height: 1.25;
    }

    .vote-split-analysis {
        padding: 10px 12px;
        margin-top: 10px;
    }

    .vote-split-analysis h4 {
        font-size: 0.95rem;
        margin-bottom: 4px;
    }

    .vote-split-analysis ul {
        padding-left: 18px;
        margin: 2px 0 0 0;
    }

    .vote-split-analysis li {
        font-size: 0.85rem;
        margin: 1px 0;
        line-height: 1.25;
    }

}

@media (max-width: 430px) {
    body {
        padding: 6px;
    }

    .rcv-demo {
        padding: 16px;
        gap: 16px;
    }

    .voting-mode-toggle {
        max-width: 100%;
    }
}

@media (max-width: 400px) {
    .rcv-demo {
        padding: 14px;
    }

    .candidate-item {
        padding: 12px;
        gap: 10px;
    }

    .candidate-icon {
        font-size: 1.25rem;
    }

    .candidate-name {
        font-size: 0.9rem;
    }

    .rank-badge {
        width: 24px;
        height: 24px;
        font-size: 0.8rem;
    }

    .round-navigation {
        margin-top: 16px;
        padding-top: 12px;
    }

    .round-nav-btn {
        padding: 8px 14px;
        font-size: 0.85rem;
    }
}
