/* ==========================================================================
   County HUD Demographics Page
   ========================================================================== */

/* --- Get Demos button ---
   Scoped override: this one button tracks the theme Primary Colour instead of
   the global .btn--primary accent. Background, hover, and glow all derive from
   --color-primary so it follows Admin → Theme Settings → Primary Colour. */
#get-demos-btn.btn--primary {
    background-color: var(--color-primary);
    box-shadow: 0 4px 15px color-mix(in srgb, var(--color-primary) 35%, transparent);
}
#get-demos-btn.btn--primary:hover {
    background-color: color-mix(in srgb, var(--color-primary), #000 12%);
    box-shadow: 0 6px 20px color-mix(in srgb, var(--color-primary) 45%, transparent);
}

/* --- Search Bar --- */

.ch-search {
    background: var(--color-secondary);
    color: #fff;
    padding: var(--space-lg);
    border-radius: 8px;
    margin-bottom: var(--space-xl);
}

.ch-search__row {
    display: flex;
    gap: var(--space-md);
    align-items: flex-end;
    flex-wrap: wrap;
}

.ch-search__field {
    flex: 1;
    min-width: 180px;
}

.ch-search__label {
    display: block;
    font-weight: 700;
    font-size: 0.875rem;
    margin-bottom: var(--space-xs);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ch-search select {
    color: var(--color-text-heading);
}

/* --- Loading --- */

.ch-loading {
    display: none;
    text-align: center;
    padding: var(--space-xl);
}

.ch-loading__text {
    font-size: 1.25rem;
    color: var(--color-primary);
}

.ch-loading--sm {
    padding: var(--space-lg);
}

.ch-loading--sm .ch-loading__text {
    font-size: 1rem;
}

/* --- Results Layout --- */

.ch-results {
    display: none;
}

.ch-results__title {
    font-size: 1.5rem;
    color: var(--color-primary);
    margin-bottom: var(--space-lg);
    text-align: center;
}

.ch-columns {
    display: flex;
    gap: var(--space-lg);
    flex-wrap: wrap;
    margin-bottom: var(--space-xl);
}

.ch-column {
    flex: 1;
    min-width: 320px;
}

/* --- Demo Table --- */

.ch-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9375rem;
}

.ch-table thead tr {
    background: var(--color-primary);
    color: #fff;
}

.ch-table--secondary thead tr {
    background: var(--color-primary);
    color: #fff;
}

.ch-table th {
    padding: 6px 12px;
    text-align: left;
}

.ch-table th.text-right {
    text-align: right;
}

.ch-table th.text-center {
    text-align: center;
}

.ch-table td {
    padding: 6px 12px;
}

.ch-table td.text-right {
    text-align: right;
}

.ch-table td.text-center {
    text-align: center;
}

.ch-table td.cell-label {
    font-weight: 600;
    color: var(--color-text-heading);
}

.ch-table td.cell-bold {
    font-weight: 600;
}

.ch-table tbody tr:nth-child(even) {
    background: var(--color-bg);
}

.ch-table tbody tr:nth-child(odd) {
    background: var(--color-bg-alt);
}

/* --- Maps --- */

.ch-map-label {
    font-weight: 700;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-body);
    margin-bottom: var(--space-xs);
}

.ch-map-wrap {
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid var(--color-border);
    margin-bottom: var(--space-md);
}

.ch-map {
    width: 100%;
    height: 300px;
}

/* --- HUD Sections --- */

.ch-hud-section {
    display: none;
    margin-top: var(--space-xl);
}

.ch-hud-section + .ch-hud-section {
    margin-top: var(--space-lg);
}

.ch-hud-section h3 {
    color: var(--color-primary);
    margin-bottom: var(--space-sm);
}

.ch-hud-area {
    color: var(--color-text-body);
    font-size: 0.875rem;
    margin-bottom: var(--space-md);
}

.ch-source {
    color: var(--color-text-body);
    font-size: 0.75rem;
    margin-top: var(--space-xs);
    font-style: italic;
}

.ch-source a {
    color: var(--color-secondary);
}

/* --- Income Limit Year Block (JS-generated) --- */

.ch-il-block {
    margin-bottom: var(--space-lg);
}

.ch-il-block h3 {
    color: var(--color-primary);
    margin-bottom: var(--space-xs);
}

.ch-il-median {
    color: var(--color-text-body);
    font-size: 0.875rem;
    margin-bottom: var(--space-md);
}

/* --- Auth Gate --- */

.ch-auth-gate {
    background: var(--color-bg-alt);
    padding: var(--space-lg);
    border-radius: 8px;
    text-align: center;
    margin-top: var(--space-xl);
    color: var(--color-text-body);
}

.ch-auth-gate a {
    color: var(--color-primary);
    font-weight: 700;
}

/* --- Utility --- */

.ch-nowrap {
    white-space: nowrap;
}

.ch-overflow-x {
    overflow-x: auto;
}

/* --- Results header (title + print button) --- */

.ch-results__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.ch-results__header .ch-results__title {
    flex: 1;
    margin-bottom: 0;
}

/* --- Custom AMHI panel --- */

.ch-amhi-panel {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-md);
    background: var(--color-bg-alt);
    padding: var(--space-md);
    border-radius: 8px;
    margin-bottom: var(--space-lg);
}

.ch-amhi-panel__label {
    font-weight: 700;
    color: var(--color-text-heading);
}

.ch-amhi-inputs {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.ch-amhi-input {
    width: 5rem;
    text-align: right;
}

.ch-amhi-pct {
    margin-right: var(--space-sm);
    color: var(--color-text-body);
}

.ch-amhi-subhead {
    color: var(--color-primary);
    font-size: 1.05rem;
    margin: var(--space-lg) 0 var(--space-sm);
}

/* --- Print branding header (screen-hidden, shown when printing) --- */

.ch-print-brand {
    display: none;
}

/* --- Print ("Printer Friendly") --- */

@media print {
    body.ch-page .site-header,
    body.ch-page .site-footer,
    body.ch-page .flash-messages,
    body.ch-page .ch-search,
    body.ch-page .ch-map-wrap,
    body.ch-page .ch-map-label,
    body.ch-page .ch-no-print,
    body.ch-page #loading,
    body.ch-page #hud-loading {
        display: none !important;
    }

    body.ch-page #main-content {
        margin: 0;
        padding: 0;
    }

    body.ch-page .ch-results {
        display: block !important;
    }

    body.ch-page .ch-columns {
        display: block;
    }

    /* Branding header on the printout */
    body.ch-page .ch-print-brand {
        display: flex;
        align-items: center;
        gap: var(--space-md);
        border-bottom: 3px solid var(--color-primary);
        padding-bottom: 8px;
        margin-bottom: 16px;
    }

    body.ch-page .ch-print-brand__logo {
        height: 48px;
        width: auto;
    }

    body.ch-page .ch-print-brand__title {
        font-size: 1.1rem;
        font-weight: 700;
        color: var(--color-primary);
    }

    /* Kill horizontal scrollbars and let wide tables fit the page */
    body.ch-page .ch-overflow-x {
        overflow: visible !important;
    }

    body.ch-page .ch-table {
        font-size: 8.5pt;
        table-layout: fixed;
        width: 100%;
    }

    body.ch-page .ch-table th,
    body.ch-page .ch-table td {
        padding: 3px 4px;
        word-break: break-word;
    }

    /* Force header-row green + striping to render on paper */
    body.ch-page .ch-table thead tr,
    body.ch-page .ch-table--secondary thead tr,
    body.ch-page .ch-table tbody tr:nth-child(even),
    body.ch-page .ch-table tbody tr:nth-child(odd) {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    body.ch-page .ch-hud-section,
    body.ch-page .ch-il-block,
    body.ch-page table {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}
