/**
 * WA Government Contracts Sankey Diagram
 * Styles for the interactive visualization
 */

/* ============================================
   Variables
   ============================================ */

:root {
    --ink: #1a1a1a;
    --paper: #fbfdfb;
    --accent: #2d6a4f;
    --eucalyptus: #5b8a72;
    --ocean: #4a7c94;
    --ochre: #c85a3e;
    --sand: #d9c6a3;
    --muted: #5b615c;

    /* Budget bin colors */
    --bin-micro: #d9c6a3;
    --bin-small: #5b8a72;
    --bin-medium: #4a7c94;
    --bin-large: #c85a3e;
}

/* ============================================
   Reset & Base
   ============================================ */

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

body {
    font-family: 'JetBrains Mono', monospace;
    background: var(--paper);
    color: var(--ink);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* ============================================
   Sankey Container
   ============================================ */

#sankey-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    cursor: grab;
}

#sankey-container:active {
    cursor: grabbing;
}

#sankey {
    display: block;
}

/* ============================================
   Overlay System
   ============================================ */

.overlay {
    position: absolute;
    z-index: 100;
    pointer-events: none;
}

/* ============================================
   Back Link
   ============================================ */

.back-link {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 200;
    font-size: 0.75rem;
    color: rgba(0, 0, 0, 0.5);
    text-decoration: none;
    transition: color 0.2s ease;
}

.back-link:hover {
    color: var(--accent);
}

/* ============================================
   Header & Title Card
   ============================================ */

.header {
    top: 50px;
    left: 20px;
    right: 20px;
    z-index: 150;
}

.title-card {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    padding: 20px 24px;
    display: inline-block;
    pointer-events: auto;
    max-width: 400px;
}

.title-card h1 {
    font-family: 'Instrument Serif', serif;
    font-size: 1.8rem;
    font-weight: 400;
    margin-bottom: 4px;
    color: var(--accent);
}

.title-card .subtitle {
    font-size: 0.75rem;
    color: var(--muted);
    font-weight: 300;
}

.title-meta {
    margin-top: 12px;
    display: flex;
    gap: 16px;
    font-size: 0.65rem;
    color: var(--muted);
}

.attribution {
    font-weight: 300;
}

.methods-link {
    color: var(--accent);
    text-decoration: none;
    transition: opacity 0.2s;
}

.methods-link:hover {
    opacity: 0.7;
}

/* ============================================
   Loading Overlay
   ============================================ */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--paper);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-text {
    margin-top: 16px;
    font-size: 0.75rem;
    color: var(--muted);
}

/* ============================================
   Zoom Controls
   ============================================ */

.zoom-controls {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.zoom-btn {
    width: 40px;
    height: 40px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    font-size: 1.25rem;
    color: var(--ink);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.zoom-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.zoom-btn:active {
    transform: scale(0.95);
}

.zoom-reset {
    font-size: 1rem;
}

/* ============================================
   Legend
   ============================================ */

.legend {
    bottom: 20px;
    left: 20px;
    z-index: 150;
}

.legend-card {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    padding: 16px 20px;
    pointer-events: auto;
    min-width: 180px;
}

.legend-title {
    font-size: 0.7rem;
    font-weight: 400;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 12px;
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.7rem;
    color: var(--ink);
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    flex-shrink: 0;
}

.legend-color.micro {
    background: var(--bin-micro);
}

.legend-color.small {
    background: var(--bin-small);
}

.legend-color.medium {
    background: var(--bin-medium);
}

.legend-color.large {
    background: var(--bin-large);
}

.legend-divider {
    height: 1px;
    background: rgba(0, 0, 0, 0.1);
    margin: 12px 0;
}

.legend-actions {
    display: flex;
    gap: 6px;
}

.legend-btn {
    flex: 1;
    padding: 6px 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.6rem;
    color: var(--muted);
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.legend-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.legend-instructions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.instruction {
    font-size: 0.65rem;
    color: var(--muted);
    font-weight: 300;
}

.legend-stats {
    display: flex;
    gap: 20px;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-value {
    font-size: 1rem;
    font-weight: 400;
    color: var(--accent);
}

.stat-label {
    font-size: 0.6rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ============================================
   Popover
   ============================================ */

.popover {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 500;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 16px;
    padding: 24px;
    max-width: 600px;
    width: calc(100% - 40px);
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.popover.hidden {
    display: none;
}

.popover-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
    gap: 16px;
}

.popover-header h3 {
    font-family: 'Instrument Serif', serif;
    font-size: 1.4rem;
    font-weight: 400;
    color: var(--accent);
    line-height: 1.2;
}

.popover-close {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    font-size: 1.25rem;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.popover-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: var(--ink);
}

.popover-stats {
    display: flex;
    gap: 24px;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.popover-stats .stat-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.popover-stats .stat-value {
    font-size: 1.25rem;
    font-weight: 400;
    color: var(--accent);
}

.popover-stats .stat-label {
    font-size: 0.65rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.popover-content {
    overflow-y: auto;
    flex: 1;
}

.contract-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.contract-item {
    padding: 12px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.contract-title {
    font-size: 0.8rem;
    color: var(--ink);
    line-height: 1.4;
    margin-bottom: 8px;
}

.contract-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}

.contract-agency {
    font-size: 0.65rem;
    color: var(--muted);
    flex: 1;
}

.contract-value {
    font-size: 0.75rem;
    color: var(--accent);
    font-weight: 400;
    white-space: nowrap;
}

.contract-ref {
    font-size: 0.6rem;
    color: var(--muted);
    font-weight: 300;
}

.more-contracts {
    text-align: center;
    font-size: 0.7rem;
    color: var(--muted);
    padding: 12px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: 8px;
}

.more-contracts-btn {
    width: 100%;
    padding: 12px 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--accent);
    background: rgba(45, 106, 79, 0.1);
    border: 1px solid var(--accent);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.more-contracts-btn:hover {
    background: var(--accent);
    color: white;
}

/* ============================================
   Sankey Styles (D3)
   ============================================ */

.node rect {
    transition: opacity 0.2s;
}

.node rect:hover {
    opacity: 0.8;
}

.node.agency rect {
    cursor: pointer;
}

.node-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    fill: var(--ink);
    pointer-events: none;
    transition: fill 0.2s, font-weight 0.2s;
}

.node-label[cursor="pointer"] {
    pointer-events: auto;
}

.node-label[cursor="pointer"]:hover {
    fill: var(--accent);
    font-weight: 400;
}

.node-label.root {
    font-family: 'Instrument Serif', serif;
    font-size: 14px;
    fill: var(--accent);
}

.node-label.bin {
    font-size: 11px;
    font-weight: 400;
}

.expand-indicator {
    font-size: 8px;
    fill: var(--muted);
    cursor: pointer;
    transition: fill 0.2s, transform 0.2s;
}

.expand-indicator:hover {
    fill: var(--accent);
}

.link {
    fill: none;
    stroke-opacity: 0.3;
    transition: stroke-opacity 0.2s;
}

.link:hover {
    stroke-opacity: 0.5;
}

/* ============================================
   Popover Backdrop
   ============================================ */

.popover-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    z-index: 400;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.popover-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

/* ============================================
   Mobile Responsive
   ============================================ */

@media (max-width: 768px) {
    .back-link {
        top: 12px;
        left: 12px;
    }

    .header {
        top: 40px;
        left: 12px;
        right: 12px;
    }

    .title-card {
        padding: 16px 18px;
        max-width: none;
        width: 100%;
    }

    .title-card h1 {
        font-size: 1.4rem;
    }

    .title-card .subtitle {
        font-size: 0.7rem;
    }

    .title-meta {
        flex-direction: column;
        gap: 4px;
    }

    .legend {
        bottom: 12px;
        left: 12px;
        right: 80px;
    }

    .legend-card {
        padding: 12px 16px;
    }

    .legend-instructions {
        display: none;
    }

    .zoom-controls {
        bottom: 12px;
        right: 12px;
    }

    .zoom-btn {
        width: 44px;
        height: 44px;
    }

    .popover {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        transform: none;
        max-width: none;
        width: 100%;
        border-radius: 20px 20px 0 0;
        max-height: 70vh;
        padding: 20px;
    }

    .popover-header h3 {
        font-size: 1.2rem;
    }
}

@media (max-width: 480px) {
    .legend-stats {
        flex-direction: column;
        gap: 8px;
    }

    .popover-stats {
        flex-wrap: wrap;
        gap: 16px;
    }
}