/* CVU Intelligence Report shared stylesheet.
 * Ported from cvu_intelligence_generator.py::_shared_css().
 * All rules scoped under .cvu-intel to avoid leaking into the rest of the theme.
 */

.cvu-intel {
    --cvu-bg: var(--neutral-900, #171717);
    --cvu-surface: var(--neutral-800, #1E1E1E);
    --cvu-text-primary: var(--neutral-25, #FCFCFC);
    --cvu-text-secondary: var(--neutral-500, #A0A0A0);
    --cvu-accent: var(--green-500, #B4E817);
    --cvu-border: rgba(255, 255, 255, 0.08);
    background: var(--cvu-bg);
    color: var(--cvu-text-primary);
    line-height: 1.6;
    font-size: 1.3em;
}

/* Light mode — toggled by cvuIntelToggleTheme(). Overrides the CSS custom
 * properties above so every scoped rule re-themes by inheritance. A darker
 * brand-green accent (#3F5400) is used because the bright lime
 * #B4E817 fails AA contrast on a white surface. */
.cvu-intel.is-light {
    --cvu-bg: #FCFCFC;
    --cvu-surface: #FFFFFF;
    --cvu-text-primary: #171717;
    --cvu-text-secondary: #525252;
    --cvu-accent: #66CC00;
    --cvu-border: rgba(0, 0, 0, 0.12);
}
.cvu-intel.is-light tr:nth-child(even) { background: rgba(0, 0, 0, 0.025); }
.cvu-intel.is-light tr:hover { background: rgba(0, 0, 0, 0.04); }
/* Team-item hover defaults to a near-black wash that's invisible on dark bg
 * but goes opaque on light bg. Override to a subtle dark tint instead. */
.cvu-intel.is-light .team-item:hover { background: rgba(0, 0, 0, 0.05); }
.cvu-intel.is-light .ms-panel { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); }
.cvu-intel.is-light .cvu-intel-popup .leaflet-popup-content-wrapper {
    background: #FFFFFF; color: #171717; border-color: rgba(0, 0, 0, 0.12);
}
.cvu-intel.is-light .cvu-intel-popup .leaflet-popup-tip { background: #FFFFFF; }
.cvu-intel.is-light .cvu-intel-popup a { color: #66CC00; }
.cvu-intel.is-light .cvu-intel-lightbox-overlay { background: rgba(0, 0, 0, 0.5); }
.cvu-intel.is-light .cvu-intel-lightbox-content {
    background: var(--cvu-surface); border-color: var(--cvu-border);
}
.cvu-intel.is-light .cvu-intel-lightbox-title { color: var(--cvu-accent); }
.cvu-intel.is-light .cvu-intel-lightbox-list a {
    color: var(--cvu-text-primary); border-bottom-color: var(--cvu-border);
}
.cvu-intel.is-light .cvu-intel-lightbox-list a:hover {
    background: var(--cvu-bg); color: var(--cvu-accent);
}
.cvu-intel.is-light .cvu-intel-lightbox-close { color: var(--cvu-accent); }

/* Theme toggle button. Lives inside the always-dark .article-header, so its
 * own styling stays dark regardless of report theme state. Sun icon shows
 * when in dark mode (suggesting "switch to light"); moon shows in light. */
.cvu-intel-theme-toggle {
    display: inline-flex; align-items: center; gap: 8px;
    /* Hold to content width — some theme rules force buttons to 100% */
    width: max-content; max-width: 100%;
    background: transparent; color: #FCFCFC;
    border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 999px;
    padding: 6px 14px; font-size: 0.85em; font-family: inherit;
    cursor: pointer; transition: background-color .15s, border-color .15s;
}
.cvu-intel-theme-toggle:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.45);
}
.cvu-intel-theme-toggle:focus-visible {
    outline: 2px solid #B4E817; outline-offset: 2px;
}
.cvu-intel-theme-toggle__icon-moon { display: none; }
.cvu-intel-theme-toggle[aria-pressed="true"] .cvu-intel-theme-toggle__icon-sun { display: none; }
.cvu-intel-theme-toggle[aria-pressed="true"] .cvu-intel-theme-toggle__icon-moon { display: inline; }

.cvu-intel section { margin-bottom: 50px; }
.cvu-intel section h2 {
    font-size: 1.6em; color: var(--cvu-accent); margin-bottom: 20px;
    border-bottom: 1px solid var(--cvu-border); padding-bottom: 10px;
}

/* Summary cards */
.cvu-intel .summary-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px; margin-bottom: 30px;
}
.cvu-intel .summary-card {
    background: var(--cvu-surface); border: 1px solid var(--cvu-border);
    padding: 20px; border-radius: 8px;
}
.cvu-intel .summary-label { color: var(--cvu-text-secondary); font-size: 1.2em; margin-bottom: 8px; }
.cvu-intel .summary-value { font-size: 1.6em; color: var(--cvu-accent); font-weight: bold; }
/* Urban Center links inside summary cards: grey text, green accent underline. */
.cvu-intel .summary-card a {
    color: var(--cvu-text-secondary);
    text-decoration: underline;
    text-decoration-color: var(--cvu-accent);
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}
.cvu-intel .summary-card a:hover { color: var(--cvu-text-primary); }

/* Charts */
.cvu-intel .charts-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 30px;
    margin-bottom: 30px;
}
/* Stack to single column once the 2-col layout starts compressing each chart
 * below a comfortable width. Threshold tuned for the WP container so each
 * stacked chart gets the full container width rather than a squeezed half. */
@media (max-width: 1100px) {
    .cvu-intel .charts-grid { grid-template-columns: 1fr; }
}
.cvu-intel .chart-container {
    background: var(--cvu-surface); border: 1px solid var(--cvu-border);
    padding: 25px; border-radius: 8px; position: relative; height: 520px;
    display: flex;
    flex-direction: column;
}
.cvu-intel .chart-canvas-wrap {
    position: relative;
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
}
.cvu-intel .chart-canvas-wrap > canvas,
.cvu-intel .chart-canvas-wrap > div[data-engine="echarts"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}
.cvu-intel .chart-title {
    font-size: 17px; color: var(--cvu-accent); margin-bottom: 15px; font-weight: bold;
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    /* Reserve clearance for the absolutely-positioned PNG/SVG export buttons
     * at top-right (~98px wide + 10px offset). Without this, filter controls
     * in the title row collide with them. */
    padding-right: 95px;
}
.cvu-intel .chart-toggle-btn {
    font-size: 0.75em; padding: 3px 10px; font-weight: normal;
    background: var(--cvu-bg); color: var(--cvu-text-primary);
    border: 1px solid var(--cvu-border); border-radius: 4px;
    cursor: pointer;
}
.cvu-intel .chart-toggle-btn:hover { border-color: var(--cvu-accent); color: var(--cvu-accent); }
.cvu-intel .chart-toggle-btn.active {
    background: var(--cvu-accent); color: var(--cvu-bg); border-color: var(--cvu-accent);
}
.cvu-intel .chart-height-filter-label {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 0.75em; font-weight: normal; color: var(--cvu-text-secondary);
}
.cvu-intel .chart-height-filter {
    width: 70px; padding: 3px 6px;
    background: var(--cvu-bg); color: var(--cvu-text-primary);
    border: 1px solid var(--cvu-border); border-radius: 4px;
    font-size: 1em; font-family: inherit;
}
.cvu-intel .chart-height-filter:focus {
    outline: none; border-color: var(--cvu-accent);
}
.cvu-intel .chart-status-filter-label {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 0.75em; font-weight: normal; color: var(--cvu-text-secondary);
}
.cvu-intel .chart-status-filter {
    padding: 3px 6px;
    background: var(--cvu-bg); color: var(--cvu-text-primary);
    border: 1px solid var(--cvu-border); border-radius: 4px;
    font-size: 1em; font-family: inherit;
    max-width: 160px;
}
.cvu-intel .chart-status-filter:focus {
    outline: none; border-color: var(--cvu-accent);
}
.cvu-intel .chart-export-btns {
    position: absolute; top: 10px; right: 10px; display: flex; gap: 6px;
}
.cvu-intel .chart-export-btns button {
    background: var(--cvu-bg); color: var(--cvu-accent); border: 1px solid var(--cvu-border);
    padding: 3px 8px; border-radius: 4px; cursor: pointer; font-size: 0.75em;
}
.cvu-intel .chart-export-btns button:hover { background: var(--cvu-accent); color: var(--cvu-bg); }
.cvu-intel .chart-caption {
    flex: 0 0 auto;
    margin: 8px 0 0;
    font-size: 0.72em;
    font-style: italic;
    line-height: 1.4;
    color: var(--cvu-text-secondary);
}

/* Analysis (editable WYSIWYG content) */
.cvu-intel .analysis-box {
    background: var(--cvu-surface); border: 1px solid var(--cvu-border);
    padding: 25px; border-radius: 8px; line-height: 1.8; margin-bottom: 30px;
}
.cvu-intel .analysis-box p { margin-bottom: 15px; color: var(--cvu-text-primary); font-size: 16px; }
.cvu-intel .analysis-box strong { color: var(--cvu-accent); }
/* In-text hyperlinks: keep body-text color (legible in both modes),
 * accent-green underline to signal interactivity in the brand colour. */
.cvu-intel .analysis-box a {
    color: inherit;
    text-decoration: underline;
    text-decoration-color: var(--cvu-accent);
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}
.cvu-intel .analysis-box a:hover {
    text-decoration-thickness: 2px;
}

/* Team cards */
.cvu-intel .team-section {
    background: var(--cvu-surface); border: 1px solid var(--cvu-border);
    padding: 25px; border-radius: 8px; margin-bottom: 30px;
}
.cvu-intel .team-category { margin-bottom: 25px; }
.cvu-intel .team-category h4 { color: var(--cvu-accent); margin-bottom: 10px; font-size: 1.05em; }
.cvu-intel .team-list {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 15px;
}
.cvu-intel .team-item {
    background: var(--cvu-bg); padding: 12px; border-left: 3px solid var(--cvu-accent);
    border-radius: 4px; cursor: pointer; transition: background 0.2s;
}
.cvu-intel .team-item:hover { background: #252525; }
.cvu-intel .team-item-name { color: var(--cvu-text-primary); font-weight: bold; }
.cvu-intel .team-item-count { color: var(--cvu-text-secondary); font-size: 0.9em; }
.cvu-intel .team-filter { display: flex; gap: 10px; align-items: center; margin-bottom: 15px; }
.cvu-intel .team-filter label { color: var(--cvu-text-secondary); font-size: 0.9em; }
.cvu-intel .team-filter select {
    background: var(--cvu-bg); color: var(--cvu-text-primary);
    border: 1px solid var(--cvu-border); border-radius: 6px; padding: 6px 10px; font-size: 0.9em;
}

/* Buildings table */
.cvu-intel .table-section {
    background: var(--cvu-surface); border: 1px solid var(--cvu-border);
    padding: 25px; border-radius: 8px; overflow-x: auto;
}
.cvu-intel .table-controls {
    display: flex; flex-wrap: wrap; gap: 15px; align-items: center; margin-bottom: 20px;
}
.cvu-intel .table-controls input {
    width: 100%; max-width: 300px; padding: 10px 15px; background: var(--cvu-bg);
    border: 1px solid var(--cvu-border); color: var(--cvu-text-primary);
    border-radius: 4px; font-size: 1em;
}
.cvu-intel .table-controls input::placeholder { color: var(--cvu-text-secondary); }
.cvu-intel .table-controls select {
    padding: 8px 12px; background: var(--cvu-bg); border: 1px solid var(--cvu-border);
    color: var(--cvu-text-primary); border-radius: 4px; font-size: 0.9em;
}
.cvu-intel .table-controls button {
    background: var(--cvu-accent); color: var(--cvu-bg); border: none;
    padding: 8px 16px; border-radius: 4px; cursor: pointer; font-weight: bold; font-size: 0.9em;
}
.cvu-intel .table-controls button:hover { opacity: 0.85; }
.cvu-intel .filter-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 15px; }
.cvu-intel .filter-row select {
    padding: 6px 10px; background: var(--cvu-bg); border: 1px solid var(--cvu-border);
    color: var(--cvu-text-primary); border-radius: 4px; font-size: 0.85em;
}
.cvu-intel .filter-row label {
    color: var(--cvu-text-secondary); font-size: 0.85em; margin-right: 4px;
}
.cvu-intel .pagination {
    display: flex; align-items: center; gap: 10px; margin-top: 15px; justify-content: center;
}
.cvu-intel .pagination button {
    background: var(--cvu-bg); color: var(--cvu-accent); border: 1px solid var(--cvu-border);
    padding: 6px 14px; border-radius: 4px; cursor: pointer; font-size: 0.9em;
}
.cvu-intel .pagination button:hover { background: var(--cvu-accent); color: var(--cvu-bg); }
.cvu-intel .pagination button:disabled { opacity: 0.3; cursor: default; }
.cvu-intel .pagination span { color: var(--cvu-text-secondary); font-size: 0.9em; }
.cvu-intel table { width: 100%; border-collapse: collapse; font-size: 0.85em; }
.cvu-intel th {
    background: var(--cvu-bg); color: var(--cvu-accent); padding: 12px;
    text-align: left; border-bottom: 1px solid var(--cvu-border); cursor: pointer; user-select: none;
}
.cvu-intel th:hover { background: #252525; }
.cvu-intel td { padding: 12px; border-bottom: 1px solid var(--cvu-border); color: var(--cvu-text-primary); }
.cvu-intel tr:nth-child(even) { background: rgba(255, 255, 255, 0.02); }
.cvu-intel tr:hover { background: rgba(180, 232, 23, 0.03); }
.cvu-intel td.num { text-align: right; font-family: monospace; font-size: 1em;}
.cvu-intel td a { color: var(--cvu-accent); text-decoration: none; }
.cvu-intel td a:hover { text-decoration: underline; }

/* Leaflet map */
.cvu-intel #buildingMap {
    height: 500px; width: 100%; border-radius: 12px;
    border: 1px solid var(--cvu-border); margin-top: 15px;
}
.cvu-intel .map-section { margin: 30px 0 50px; }
.cvu-intel .cvu-map-caption {
    color: var(--cvu-text-secondary);
    font-size: 1.08em;
    margin-bottom: 18px;
}
.cvu-intel .map-filters {
    display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 8px;
}
.cvu-intel .map-filters label { color: var(--cvu-text-secondary); font-size: 0.85em; }
.cvu-intel .ms-dropdown { position: relative; display: inline-block; }
.cvu-intel .ms-toggle {
    background: var(--cvu-surface); color: var(--cvu-text-primary);
    border: 1px solid var(--cvu-border); border-radius: 6px; padding: 5px 10px;
    font-size: 0.85em; cursor: pointer; min-width: 100px;
    display: flex; align-items: center; justify-content: space-between; gap: 6px;
}
.cvu-intel .ms-toggle::after { content: '▼'; font-size: 0.6em; color: var(--cvu-text-secondary); }
.cvu-intel .ms-panel {
    display: none; position: absolute; top: 100%; left: 0; z-index: 500;
    background: var(--cvu-surface); border: 1px solid var(--cvu-border); border-radius: 8px;
    margin-top: 4px; max-height: 220px; overflow-y: auto; min-width: 160px;
    padding: 4px 0; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}
.cvu-intel .ms-panel.open { display: block; }
.cvu-intel .ms-panel label {
    display: flex; align-items: center; gap: 8px; padding: 5px 12px;
    font-size: 0.85em; color: var(--cvu-text-primary); cursor: pointer; white-space: nowrap;
}
.cvu-intel .ms-panel label:hover { background: var(--cvu-bg); }
.cvu-intel .ms-panel input[type=checkbox] { accent-color: var(--cvu-accent); }
.cvu-intel .ms-actions {
    display: flex; gap: 8px; padding: 6px 12px; border-top: 1px solid var(--cvu-border);
}
.cvu-intel .ms-actions button {
    background: none; border: none; color: var(--cvu-accent);
    font-size: 0.8em; cursor: pointer; padding: 0;
}
.cvu-intel .ms-actions button:hover { text-decoration: underline; }
.cvu-intel .map-marker-count {
    color: var(--cvu-text-secondary); font-size: 0.85em; margin-left: auto;
}
.cvu-intel .map-legend {
    display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px;
    font-size: 1.02em; color: var(--cvu-text-secondary);
}
.cvu-intel .map-legend-item { display: flex; align-items: center; gap: 5px; }
.cvu-intel .map-legend-dot {
    width: 12px; height: 12px; border-radius: 50%; display: inline-block;
}

/* Leaflet popup styling */
.cvu-intel-popup .leaflet-popup-content-wrapper {
    background: #1E1E1E; color: #FCFCFC; border: 1px solid #2A2A2A;
}
.cvu-intel-popup .leaflet-popup-tip { background: #1E1E1E; }
.cvu-intel-popup a { color: #B4E817; }

/* Lightbox for team firm building lists */
.cvu-intel-lightbox-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.8); z-index: 1000;
    justify-content: center; align-items: center;
}
.cvu-intel-lightbox-overlay.open { display: flex; }
.cvu-intel-lightbox-content {
    background: #1E1E1E; border: 1px solid #2A2A2A; border-radius: 12px;
    padding: 30px; max-width: 600px; width: 90%;
    max-height: 80vh; overflow-y: auto; position: relative;
}
.cvu-intel-lightbox-close {
    position: absolute; top: 12px; right: 16px; background: none; border: none;
    color: #B4E817; font-size: 1.5em; cursor: pointer;
}
.cvu-intel-lightbox-close:hover { color: #FCFCFC; }
.cvu-intel-lightbox-title {
    color: #B4E817; font-size: 1.2em; font-weight: bold;
    margin-bottom: 15px; padding-right: 30px;
}
.cvu-intel-lightbox-list a {
    color: #FCFCFC; text-decoration: none; display: block;
    padding: 8px 12px; border-bottom: 1px solid #2A2A2A; font-size: 1.2em;
}
.cvu-intel-lightbox-list a:hover { background: #171717; color: #B4E817; }

/* Download PDF button */
.cvu-intel-pdf-bar {
    display: flex; justify-content: flex-end; padding: 16px 0 0;
}
.cvu-intel-pdf-btn {
    background: var(--cvu-accent); color: var(--cvu-bg); border: none;
    padding: 10px 18px; border-radius: 6px; cursor: pointer;
    font-weight: bold; font-size: 0.95em;
    display: inline-flex; align-items: center; gap: 8px;
}
.cvu-intel-pdf-btn:hover { opacity: 0.88; }

/* ===========================================================
 * Print stylesheet — invoked by browser "Save as PDF" / Print
 * Tells the browser to honour the dark theme (so the printout
 * matches the screen), hides interactive chrome, and inserts
 * page breaks before each major section so the PDF flows cleanly.
 * =========================================================== */
@media print {
    /* Honour background colours so the theme persists in Save-as-PDF.
     * Without this, Chrome strips backgrounds by default. */
    .cvu-intel,
    .cvu-intel * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Force light mode for the PDF regardless of the on-screen toggle state.
     * Nobody wants to print a black background. Overriding the CSS custom
     * properties handles every var-driven surface and text colour in one
     * shot; ECharts is colour-baked-into-SVG so charts are themed in JS
     * (see beforeprint listener in intelligence.js). */
    .cvu-intel {
        --cvu-bg: #FFFFFF !important;
        --cvu-surface: #FFFFFF !important;
        --cvu-text-primary: #171717 !important;
        --cvu-text-secondary: #525252 !important;
        --cvu-accent: #66CC00 !important;
        --cvu-border: rgba(0, 0, 0, 0.12) !important;
    }
    /* Article-header above the report content is normally always dark. Flip
     * it to a light header for the printed cover so the whole document
     * shares one paper-friendly palette. */
    .article-header.bg-dark { background-color: #FFFFFF !important; }
    .article-header .inverse-text,
    .article-header .parent-crumb,
    .article-header .current-crumb { color: #171717 !important; }
    .article-header__eyebrow-group_divider { background: rgba(0, 0, 0, 0.2) !important; }

    /* Hide WP chrome by explicit selectors. Do NOT use `body > *:not(...)`
     * because in this theme the report is wrapped inside .main-wrapper,
     * not a direct child of body — hiding .main-wrapper blanks the page. */
    body > header,
    header.navigation, header.site-header, #masthead,
    .footer, footer.footer, footer.site-footer, #colophon,
    .navigation__wrapper, .site-banner, .breadcrumbs,
    #wpadminbar, .skip-link,
    .cookies-banner, .cookie-notice {
        display: none !important;
    }

    /* Strip backgrounds and padding from the structural wrappers so they
     * don't reserve full-viewport blank pages around the report. */
    html, body, .main-wrapper {
        background: #FFFFFF !important;
        margin: 0 !important;
        padding: 0 !important;
        min-height: 0 !important;
        height: auto !important;
    }

    /* Hide interactive controls inside the report */
    .cvu-intel .table-controls,
    .cvu-intel .filter-row,
    .cvu-intel .pagination,
    .cvu-intel .team-filter,
    .cvu-intel .map-filters,
    .cvu-intel-pdf-bar,
    .cvu-intel-theme-toggle,
    .cvu-intel .chart-export-btns,
    .cvu-intel .chart-toggle-btn,
    .cvu-intel .chart-height-filter-label,
    .cvu-intel .chart-status-filter-label {
        display: none !important;
    }

    /* Hide the map section entirely — Leaflet tiles are loaded as background
     * images and browsers skip those when printing, so the live map renders
     * blank. The online version is the right place to interact with it. */
    .cvu-intel .map-section { display: none !important; }

    /* Hide the building database table from PDF.
     * The table is JS-paginated (only 20 rows live in the DOM at any moment),
     * so printing it would only ever show a single page anyway. Staff can use
     * the "Export CSV" button on the online report to get the full table. */
    .cvu-intel .cvu-intel-table-section { display: none !important; }

    /* Force charts into a single column for print. The on-screen 2-column
     * grid leaves each chart too narrow for legible axes/legends, and Chrome
     * was clipping/overlapping them at PDF time. One per row gives every
     * chart full content width and predictable break behaviour. */
    .cvu-intel .charts-grid {
        display: block !important;
        gap: 0 !important;
        margin-bottom: 18px !important;
    }
    /* Chart containers: comfortable single-column height (~half a letter
     * page) so two fit per page without splitting. break-inside + the
     * margin-based separator keep the title locked to its chart. */
    .cvu-intel .chart-container {
        height: 440px !important;
        margin-bottom: 20px !important;
        break-inside: avoid !important;
        page-break-inside: avoid !important;
        -webkit-column-break-inside: avoid !important;
        overflow: hidden !important;
    }

    /* Avoid splitting analysis prose, team cards, and team category blocks
     * across pages where possible. */
    .cvu-intel .analysis-box,
    .cvu-intel .team-category,
    .cvu-intel .team-item,
    .cvu-intel .summary-card {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* Force a page break before each top-level section AFTER the first so
     * Executive Summary, Visual Analytics, GHSL Analysis, and Team Analysis
     * each start cleanly. */
    .cvu-intel section + section {
        break-before: page;
        page-break-before: always;
    }

    /* Tighter header for print */
    .article-header { padding: 12px 0 !important; }
}
