/**
 * PhilPapers Visualizations - Colorful & Graphic-Heavy
 */

.philpapers-viz {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    max-width: 1200px;
    margin: 0 auto;
}

.viz-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 20px;
}

.viz-card {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 16px;
    padding: 24px;
    color: white;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.viz-card.wide {
    margin-bottom: 20px;
}

.viz-card h4 {
    margin: 0 0 20px 0;
    font-size: 1.1em;
    font-weight: 600;
    background: linear-gradient(90deg, #6366f1, #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Donut Chart */
.donut-container {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto 15px;
}

.donut {
    width: 100%;
    height: 100%;
}

.donut-progress {
    animation: donutFill 1.5s ease-out forwards;
}

@keyframes donutFill {
    from { stroke-dasharray: 0 314; }
}

.donut-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.donut-value {
    display: block;
    font-size: 2em;
    font-weight: bold;
    background: linear-gradient(90deg, #6366f1, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.donut-label {
    font-size: 0.7em;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.donut-info {
    text-align: center;
    font-size: 0.85em;
    color: #94a3b8;
}

/* Pie Chart */
.pie-svg {
    width: 100px;
    height: 100px;
    margin: 0 auto 15px;
    display: block;
}

.pie-segment {
    transition: transform 0.2s;
    transform-origin: center;
}

.pie-segment:hover {
    transform: scale(1.05);
}

.pie-legend {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.pie-legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75em;
    color: #94a3b8;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* Gauge */
.gauge-container {
    text-align: center;
    margin-bottom: 10px;
}

.gauge {
    width: 120px;
    height: 70px;
    margin: 0 auto;
}

.gauge-needle {
    animation: needleSwing 1s ease-out forwards;
    transform-origin: 60px 60px;
}

@keyframes needleSwing {
    from { transform: rotate(-90deg); }
}

.gauge-value {
    font-size: 1.8em;
    font-weight: bold;
    background: linear-gradient(90deg, #22c55e, #10b981);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.gauge-label {
    text-align: center;
    font-size: 0.85em;
    color: #94a3b8;
}

/* Horizontal Bars */
.h-bar-row {
    display: grid;
    grid-template-columns: 140px 1fr 50px;
    gap: 12px;
    align-items: center;
    margin-bottom: 8px;
}

.h-bar-label {
    font-size: 0.8em;
    color: #cbd5e1;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.h-bar-track {
    height: 20px;
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
    overflow: hidden;
}

.h-bar-fill {
    height: 100%;
    border-radius: 10px;
    animation: barGrow 0.8s ease-out forwards;
    box-shadow: 0 0 10px currentColor;
}

@keyframes barGrow {
    from { width: 0 !important; }
}

.h-bar-value {
    font-size: 0.8em;
    font-weight: 600;
    color: #e2e8f0;
}

/* Radar Chart */
.radar-svg {
    width: 100%;
    max-width: 200px;
    display: block;
    margin: 0 auto;
}

.radar-legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 15px;
}

.radar-legend span {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8em;
    color: #94a3b8;
}

/* Bubble Chart */
.bubble-svg {
    width: 100%;
    max-width: 200px;
    display: block;
    margin: 0 auto;
}

.bubble {
    transition: r 0.2s, opacity 0.2s;
}

.bubble:hover {
    opacity: 1 !important;
}

.bubble-label {
    text-align: center;
    font-size: 0.85em;
    color: #94a3b8;
    margin-top: 15px;
}

/* Consensus Cards */
.consensus-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
}

.consensus-card {
    background: rgba(255,255,255,0.05);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    border: 2px solid transparent;
    transition: transform 0.2s, border-color 0.2s;
}

.consensus-card:hover {
    transform: translateY(-3px);
}

.consensus-card.match {
    border-color: #22c55e;
}

.consensus-card.diverge {
    border-color: #ef4444;
}

.consensus-icon {
    font-size: 1.5em;
    margin-bottom: 8px;
}

.consensus-card.match .consensus-icon { color: #22c55e; }
.consensus-card.diverge .consensus-icon { color: #ef4444; }

.consensus-title {
    font-weight: 600;
    font-size: 0.9em;
    margin-bottom: 12px;
    color: #e2e8f0;
}

.consensus-compare {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.consensus-side {
    text-align: center;
}

.consensus-pct {
    font-size: 1.4em;
    font-weight: bold;
}

.consensus-side.ai .consensus-pct {
    color: #6366f1;
}

.consensus-side.human .consensus-pct {
    color: #10b981;
}

.consensus-answer {
    font-size: 0.7em;
    color: #94a3b8;
    margin: 4px 0;
}

.consensus-who {
    font-size: 0.65em;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #64748b;
}

.consensus-vs {
    color: #475569;
    font-size: 0.8em;
}

/* Stacked Bars */
.stack-row {
    display: grid;
    grid-template-columns: 150px 1fr;
    gap: 12px;
    align-items: center;
    margin-bottom: 6px;
}

.stack-label {
    font-size: 0.75em;
    color: #cbd5e1;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stack-bar {
    display: flex;
    height: 18px;
    border-radius: 9px;
    overflow: hidden;
    background: rgba(255,255,255,0.05);
}

.stack-seg {
    height: 100%;
    transition: width 0.5s ease-out;
}

.stack-seg:hover {
    filter: brightness(1.2);
}

/* Model Bars */
.model-bar-row {
    display: grid;
    grid-template-columns: 130px 1fr 50px;
    gap: 12px;
    align-items: center;
    margin-bottom: 10px;
}

.model-bar-name {
    font-size: 0.75em;
    color: #cbd5e1;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.model-bar-track {
    height: 24px;
    background: rgba(255,255,255,0.1);
    border-radius: 12px;
    overflow: hidden;
}

.model-bar-fill {
    height: 100%;
    border-radius: 12px;
    animation: barGrow 1s ease-out forwards;
    position: relative;
}

.model-bar-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(to bottom, rgba(255,255,255,0.2), transparent);
    border-radius: 12px 12px 0 0;
}

.model-bar-pct {
    font-size: 0.85em;
    font-weight: 600;
    color: #e2e8f0;
}

/* Heatmap */
.heatmap-scroll {
    overflow-x: auto;
    padding-bottom: 10px;
}

.heatmap-svg {
    display: block;
}

.heatmap-svg rect {
    transition: opacity 0.2s;
}

.heatmap-svg rect:hover {
    opacity: 0.8;
    stroke: white;
    stroke-width: 2;
}

.heatmap-scale {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-top: 15px;
    font-size: 0.75em;
    color: #94a3b8;
}

.scale-gradient {
    width: 100px;
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, hsl(0, 70%, 50%), hsl(60, 70%, 50%), hsl(120, 70%, 50%));
}

/* Grid Layouts */
.viz-row.two-col {
    grid-template-columns: repeat(2, 1fr);
}

.viz-row.three-col {
    grid-template-columns: repeat(3, 1fr);
}

/* Provider Comparison */
.provider-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 15px;
}

.provider-card {
    background: rgba(255,255,255,0.05);
    border-radius: 12px;
    border: 2px solid;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.provider-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
}

.provider-card.google { border-color: #4285f4; }
.provider-card.openai { border-color: #10a37f; }
.provider-card.anthropic { border-color: #d97706; }
.provider-card.xai { border-color: #8b5cf6; }

.provider-header {
    padding: 12px 16px;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}

.provider-card.google .provider-header { background: linear-gradient(135deg, #4285f4, #34a853); }
.provider-card.openai .provider-header { background: linear-gradient(135deg, #10a37f, #1a7f64); }
.provider-card.anthropic .provider-header { background: linear-gradient(135deg, #d97706, #b45309); }
.provider-card.xai .provider-header { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }

.provider-name {
    font-weight: 600;
}

.provider-count {
    font-size: 0.75em;
    opacity: 0.9;
    font-weight: 400;
}

.provider-positions {
    padding: 12px 16px;
    max-height: 200px;
    overflow-y: auto;
}

.provider-pos-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 0.8em;
}

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

.pos-topic,
.provider-pos-topic {
    color: #94a3b8;
}

.pos-answer,
.provider-pos-answer {
    color: #e2e8f0;
    font-weight: 500;
    text-align: right;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* School Comparison - Paginated 3x3 Grid */
.school-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.school-section-header h4 {
    margin: 0;
}

.school-pagination {
    display: flex;
    gap: 6px;
    align-items: center;
}

.page-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.15);
    color: #94a3b8;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8em;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.page-btn:hover:not(.disabled) {
    background: rgba(99, 102, 241, 0.3);
    border-color: #6366f1;
    color: #e2e8f0;
}

.page-btn.active {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-color: transparent;
    color: white;
}

.page-btn.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.school-grid-3x3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.school-cell {
    background: rgba(255,255,255,0.03);
    border-radius: 12px;
    padding: 14px;
    border: 1px solid rgba(255,255,255,0.06);
    transition: transform 0.2s, box-shadow 0.2s;
}

.school-cell:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

.school-cell.agree {
    border-left: 3px solid #22c55e;
}

.school-cell.disagree {
    border-left: 3px solid #ef4444;
}

.school-cell-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    cursor: help;
}

.school-cell-topic {
    font-weight: 600;
    color: #e2e8f0;
    font-size: 0.85em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60%;
}

.school-cell-badge {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    font-size: 0.65em;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 10px;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.school-cell-bars {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.school-bar-row.compact {
    display: grid;
    grid-template-columns: 55px 1fr 36px;
    gap: 6px;
    align-items: center;
}

.school-cell-footnote {
    margin-top: 6px;
    font-size: 0.65em;
    color: #ef4444;
    opacity: 0.8;
}

.school-cell-footnote strong {
    color: #f87171;
}

.school-bars {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.school-bar-row {
    display: grid;
    grid-template-columns: 100px 1fr 60px;
    gap: 10px;
    align-items: center;
}

.school-label,
.school-bar-name {
    font-size: 0.7em;
    color: #94a3b8;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.school-bar-track {
    height: 14px;
    background: rgba(255,255,255,0.08);
    border-radius: 7px;
    overflow: hidden;
}

.school-bar-fill {
    height: 100%;
    border-radius: 7px;
    animation: barGrow 0.8s ease-out forwards;
    position: relative;
}

.school-pct,
.school-bar-value {
    font-size: 0.7em;
    font-weight: 600;
    color: #cbd5e1;
}

/* School Legend */
.school-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.school-legend span {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75em;
    color: #94a3b8;
}

/* Scrollable Results Table */
.results-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 20px 0;
    border-radius: 12px;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.results-table-wrapper table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    font-size: 0.85em;
}

.results-table-wrapper th {
    position: sticky;
    top: 0;
    background: linear-gradient(135deg, #1e1e3a 0%, #1a2540 100%);
    color: #c4b5fd;
    font-weight: 600;
    padding: 12px 14px;
    text-align: center;
    border-bottom: 2px solid rgba(99, 102, 241, 0.3);
    white-space: nowrap;
    font-size: 0.9em;
}

.results-table-wrapper th:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    text-align: left;
    min-width: 180px;
    background: linear-gradient(135deg, #1e1e3a 0%, #1a2540 100%);
}

.results-table-wrapper td {
    padding: 10px 14px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    color: #e2e8f0;
    white-space: nowrap;
}

.results-table-wrapper td:first-child {
    position: sticky;
    left: 0;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    text-align: left;
    font-weight: 500;
    color: #cbd5e1;
    cursor: help;
    z-index: 1;
}

.results-table-wrapper tr:hover td {
    background: rgba(99, 102, 241, 0.08);
}

.results-table-wrapper tr:hover td:first-child {
    background: linear-gradient(135deg, #222248 0%, #1d2d50 100%);
}

.results-table-wrapper::-webkit-scrollbar {
    height: 8px;
}

.results-table-wrapper::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.05);
    border-radius: 4px;
}

.results-table-wrapper::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.4);
    border-radius: 4px;
}

.results-table-wrapper::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.6);
}

/* Provider Radar */
.provider-radar-container {
    position: relative;
}

.provider-radar-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    margin-top: 15px;
}

.provider-radar-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75em;
    color: #94a3b8;
}

.provider-radar-legend-item .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.provider-radar-legend-item .dot.google { background: #4285f4; }
.provider-radar-legend-item .dot.openai { background: #10a37f; }
.provider-radar-legend-item .dot.anthropic { background: #d97706; }
.provider-radar-legend-item .dot.xai { background: #8b5cf6; }

/* Responsive */
@media (max-width: 900px) {
    .viz-row,
    .viz-row.two-col,
    .viz-row.three-col {
        grid-template-columns: 1fr;
    }

    .h-bar-row, .stack-row, .model-bar-row {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .h-bar-label, .stack-label, .model-bar-name {
        text-align: left;
    }

    .consensus-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .provider-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .school-grid-3x3 {
        grid-template-columns: repeat(2, 1fr);
    }

    .school-bar-row {
        grid-template-columns: 80px 1fr 50px;
    }

    .school-bar-row.compact {
        grid-template-columns: 45px 1fr 32px;
    }
}

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

    .provider-grid {
        grid-template-columns: 1fr;
    }

    .school-grid-3x3 {
        grid-template-columns: 1fr;
    }

    .school-bar-row {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .school-bar-name,
    .school-label {
        text-align: left;
    }

    .school-legend {
        flex-direction: column;
        align-items: center;
    }

    .school-section-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* Light mode override */
@media (prefers-color-scheme: light) {
    .viz-card {
        background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
        color: #1e293b;
        box-shadow: 0 10px 40px rgba(0,0,0,0.1);
    }

    .donut-label, .donut-info, .gauge-label, .bubble-label,
    .pie-legend-item, .radar-legend span, .consensus-answer,
    .h-bar-label, .stack-label, .model-bar-name, .heatmap-scale,
    .provider-pos-topic, .pos-topic, .school-bar-name, .school-label,
    .provider-radar-legend-item, .school-legend span {
        color: #64748b;
    }

    .h-bar-value, .model-bar-pct, .consensus-title, .h-bar-label,
    .stack-label, .model-bar-name, .provider-pos-answer, .pos-answer,
    .school-topic-name, .school-bar-value, .school-pct,
    .school-cell-topic {
        color: #334155;
    }

    .consensus-card, .provider-card, .school-topic, .school-cell {
        background: rgba(0,0,0,0.03);
    }

    .h-bar-track, .model-bar-track, .stack-bar, .school-bar-track {
        background: rgba(0,0,0,0.08);
    }

    .heatmap-svg text {
        fill: #334155;
    }

    .provider-positions {
        border-top: 1px solid rgba(0,0,0,0.05);
    }

    .provider-pos-row {
        border-bottom-color: rgba(0,0,0,0.05);
    }

    .school-legend {
        border-top-color: rgba(0,0,0,0.1);
    }

    .page-btn {
        background: rgba(0,0,0,0.05);
        border-color: rgba(0,0,0,0.1);
        color: #64748b;
    }

    .page-btn:hover:not(.disabled) {
        background: rgba(99, 102, 241, 0.15);
        color: #4338ca;
    }

    .school-cell {
        border-color: rgba(0,0,0,0.06);
    }

    .school-cell.agree {
        border-left-color: #16a34a;
    }

    .school-cell.disagree {
        border-left-color: #dc2626;
    }

    .school-cell-footnote {
        color: #dc2626;
    }

    .school-cell-footnote strong {
        color: #b91c1c;
    }

    .results-table-wrapper {
        background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
        box-shadow: 0 10px 40px rgba(0,0,0,0.1);
    }

    .results-table-wrapper th {
        background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
        color: #4338ca;
        border-bottom-color: rgba(99, 102, 241, 0.2);
    }

    .results-table-wrapper th:first-child {
        background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
    }

    .results-table-wrapper td {
        color: #334155;
        border-bottom-color: rgba(0,0,0,0.04);
    }

    .results-table-wrapper td:first-child {
        background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
        color: #475569;
    }

    .results-table-wrapper tr:hover td {
        background: rgba(99, 102, 241, 0.06);
    }

    .results-table-wrapper tr:hover td:first-child {
        background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
    }

    .results-table-wrapper::-webkit-scrollbar-track {
        background: rgba(0,0,0,0.03);
    }

    .results-table-wrapper::-webkit-scrollbar-thumb {
        background: rgba(99, 102, 241, 0.3);
    }
}
