/* Red Barn Donor Assessment Report Styles */

:root {
    /* === TYPOGRAPHY === */
    --font-sans: 'Source Sans 3', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, monospace;
    --font-chart: 'Source Sans 3';  /* Single family for Plotly (no fallback chain) */

    /* === THEMEABLE (safe to override per-client) === */
    --color-brand: #4d7c4f;
    --color-brand-hover: #3d6340;
    --color-brand-subtle: #ecfdf5;
    --color-sidebar-bg: #1c1917;
    --color-sidebar-surface: #292524;
    --color-sidebar-border: #44403c;
    --color-sidebar-hover: #292524;
    --color-sidebar-active: #3d6340;

    /* === FIXED (do not override) === */
    /* Surfaces */
    --color-surface-page: #f5f5f4;
    --color-surface-card: #ffffff;
    --color-surface-muted: #fafaf9;

    /* Text */
    --color-text-primary: #1c1917;
    --color-text-secondary: #57534e;
    --color-text-muted: #a8a29e;
    --color-text-on-dark: #d6d3d1;
    --color-text-muted-on-dark: #78716c;

    /* Borders */
    --color-border: #e7e5e4;
    --color-border-strong: #d6d3d1;

    /* Semantic (independent of brand) */
    --color-success: #16a34a;
    --color-warning: #b45309;
    --color-error: #dc2626;
    --color-info: #0369a1;

    /* === MOTION === */
    --transition-fast: 150ms ease;
    --transition-base: 200ms ease-out;

    /* === SHADOWS === */
    --shadow-xs: 0 1px 2px rgba(28, 25, 23, 0.05);
    --shadow-sm: 0 2px 4px rgba(28, 25, 23, 0.06);
    --shadow-md: 0 4px 8px rgba(28, 25, 23, 0.08);
    --shadow-lg: 0 8px 16px rgba(28, 25, 23, 0.08);
    --shadow-xl: 0 12px 24px rgba(28, 25, 23, 0.10);
    --shadow-focus: 0 0 0 3px rgba(77, 124, 79, 0.15);

    /* === BORDER RADIUS === */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;

    /* === LEGACY ALIASES (for backward compatibility) === */
    /* These map old variable names to new tokens */
    --primary-color: var(--color-brand);
    --primary-light: var(--color-brand-hover);
    --background-color: var(--color-surface-page);
    --content-bg: var(--color-surface-page);
    --text-color: var(--color-text-primary);
    --text-muted: var(--color-text-secondary);
    --border-color: var(--color-border);
    --hover-bg: var(--color-surface-muted);

    /* Legacy header (kept for backward compatibility) */
    --header-bg: var(--color-sidebar-bg);
    --header-text: var(--color-text-on-dark);

    /* Sidebar (aliased to new tokens) */
    --sidebar-bg: var(--color-sidebar-bg);
    --sidebar-text: var(--color-text-on-dark);
    --sidebar-border: var(--color-sidebar-border);
    --sidebar-muted: var(--color-text-muted-on-dark);
    --sidebar-link: var(--color-text-on-dark);
    --sidebar-hover: var(--color-sidebar-hover);
    --sidebar-active: var(--color-sidebar-active);
}

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

html, body {
    overflow-x: hidden;
}

body {
    font-family: var(--font-sans);
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--color-text-primary);
    background-color: var(--color-surface-page);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
}

/* Modern focus states */
:focus-visible {
    outline: 2px solid var(--color-brand);
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

/* Link transitions */
a {
    transition: color var(--transition-fast);
}

/* Header */
header {
    background-color: var(--header-bg);
    color: var(--header-text);
    padding: 1rem 2rem;
}

header nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

header ul {
    list-style: none;
    display: flex;
    gap: 1.5rem;
}

header a {
    color: var(--header-text);
    text-decoration: none;
    opacity: 0.9;
    transition: opacity 0.2s;
}

header a:hover {
    opacity: 1;
}

/* Main Content */
main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Report Content Container */
.report-content {
    max-width: 1400px;
    margin: 0 auto;
}

/* Page Header */
.page-header {
    margin-bottom: 2rem;
}

.page-header h2 {
    color: var(--color-text-primary);
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
}

.page-header p {
    color: var(--color-text-secondary);
}

/* Segment narrative list (bulleted) */
.segment-narrative {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 0 0;
    color: var(--color-text-secondary);
}

.segment-narrative li {
    padding-left: 1rem;
    position: relative;
    margin-bottom: 0.25rem;
}

.segment-narrative li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--color-text-muted);
}

/* KPI Cards */
.kpi-cards {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.kpi-card {
    flex: 1;
    min-width: 120px;
    background: var(--color-surface-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1rem;
    text-align: center;
    overflow: hidden;
}

.kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-text-primary);
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.kpi-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-top: 0.375rem;
}

.kpi-sublabel {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}

.kpi-positive {
    color: var(--color-success);
}

.kpi-negative {
    color: var(--color-error);
}

/* KPI YoY (embedded within card, secondary styling) */
.kpi-yoy {
    font-size: 0.8125rem;
    margin-top: 0.25rem;
}

.kpi-yoy-positive {
    color: var(--color-success);
}

.kpi-yoy-negative {
    color: var(--color-error);
}

/* Filter Controls block wrapper (adds spacing below) */
.filter-controls-block {
    margin-bottom: 1.5rem;
}

.filter-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.toggle-control {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--color-text-primary);
    background: var(--color-surface-card);
    padding: 0.625rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    transition: border-color var(--transition-fast);
}

.toggle-control:hover {
    border-color: var(--color-brand);
}

.toggle-control input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
    accent-color: var(--color-brand);
}

/* Filter Panel */
.filter-panel {
    background: var(--color-surface-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1rem 1.5rem;
    margin-bottom: 2rem;
}

.filter-row {
    display: flex;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-group--toggles {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
}

.filter-group--toggles .filter-title {
    margin-bottom: 0.25rem;
}

.filter-group--toggles .toggle-label {
    margin-left: 0;
}

.filter-group label {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    font-weight: 500;
}

.filter-group select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    background-color: var(--color-surface-card);
    cursor: pointer;
    transition: border-color var(--transition-fast),
                box-shadow var(--transition-fast);
}

.filter-group select:hover {
    border-color: var(--color-border-strong);
}

.filter-group select:focus {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: var(--shadow-focus);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.toggle-label input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
    accent-color: var(--color-brand);
}

/* Table year filter checkboxes */
.table-year-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: center;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    cursor: pointer;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
    accent-color: var(--color-brand);
}

/* Form utility classes */
.form-input,
.form-select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--color-text-primary);
    background: var(--color-surface-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    transition: border-color var(--transition-fast),
                box-shadow var(--transition-fast);
}

.form-input:hover,
.form-select:hover {
    border-color: var(--color-border-strong);
}

.form-input:focus,
.form-select:focus,
.form-input:focus-visible,
.form-select:focus-visible {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: var(--shadow-focus);
}

.form-input::placeholder {
    color: var(--color-text-muted);
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2357534e' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    padding-right: 2rem;
}

.form-checkbox {
    width: 1rem;
    height: 1rem;
    accent-color: var(--color-brand);
    cursor: pointer;
}

.form-label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-primary);
}

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.form-check .form-label {
    margin-bottom: 0;
    font-weight: 400;
    cursor: pointer;
}

/* Narrative section */
.narrative {
    background: var(--color-surface-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.narrative h3 {
    color: var(--color-brand);
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.narrative p {
    color: var(--color-text-secondary);
    margin: 0;
}

/* Chart Container */
.chart-container {
    background: var(--color-surface-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    margin-bottom: 2rem;
}

#giving-chart,
#avg-chart,
#butterfly-chart,
#concentration-chart,
#composition-chart,
#revenue-composition-chart {
    width: 100%;
    height: 400px;
}

/* Side-by-side charts */
.chart-row {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-half {
    flex: 1;
    background: var(--color-surface-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    min-width: 0;
}

.chart-half > div {
    width: 100%;
    height: 300px;
}

/* Data Table */
.data-table {
    background: var(--color-surface-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
}

.table-wrapper {
    overflow-x: auto;
    position: relative; /* helps sticky header rendering in scrolling context */
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.table-header-left h3,
.table-header h3 {
    color: var(--color-brand);
    font-size: 1.25rem;
    margin: 0;
}

.table-subtitle {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    margin: 0.25rem 0 0 0;
}

.filter-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-controls label {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

.filter-controls select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    background-color: var(--color-surface-card);
    cursor: pointer;
    transition: border-color var(--transition-fast),
                box-shadow var(--transition-fast);
}

.filter-controls select:hover {
    border-color: var(--color-border-strong);
}

.filter-controls select:focus {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: var(--shadow-focus);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
    font-size: 0.875rem;
}

/* Min-width for data-heavy tables (prioritization has its own) */
.data-table table {
    min-width: 800px;
}

/* Sticky headers - opt-in via .sticky-header class or table-specific rules */

th, td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

th {
    background-color: var(--color-surface-muted);
    font-weight: 600;
    color: var(--color-text-primary);
}

/* Column group headers */
th.column-group {
    text-align: center;
    border-bottom: 2px solid var(--color-border);
    background-color: var(--color-surface-muted);
}

/* Sub-header row */
thead tr:nth-child(2) th {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text-secondary);
}

/* Row hover scoped to data tables (not global to avoid affecting tables in cards) */
.data-table tbody tr {
    transition: background-color var(--transition-fast);
}

.data-table tbody tr:hover {
    background-color: var(--color-surface-muted);
}

/* Numeric column alignment utility */
.col-numeric {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Right-align numeric columns for specific report tables */
#band-table td:nth-child(n+3),
#band-table thead tr:nth-child(2) th,
#band-matrix td:nth-child(n+2),
#band-matrix th:nth-child(n+2),
.giving-table td:nth-child(n+2) {
    text-align: right;
}

/* Combined total column emphasis */
td.combined-total {
    font-weight: 600;
    background-color: var(--color-surface-muted);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.25;
    text-decoration: none;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background-color var(--transition-fast),
                border-color var(--transition-fast),
                color var(--transition-fast);
}

.btn:focus-visible {
    outline: 2px solid var(--color-brand);
    outline-offset: 2px;
}

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

/* Primary button - brand green */
.btn-primary,
.btn--primary {
    background-color: var(--color-brand);
    color: #fff;
    border-color: var(--color-brand);
}

.btn-primary:hover:not(:disabled),
.btn--primary:hover:not(:disabled) {
    background-color: var(--color-brand-hover);
    border-color: var(--color-brand-hover);
}

/* Secondary button - outlined */
.btn-secondary,
.btn--secondary {
    background-color: var(--color-surface-card);
    color: var(--color-text-primary);
    border-color: var(--color-border);
}

.btn-secondary:hover:not(:disabled),
.btn--secondary:hover:not(:disabled) {
    background-color: var(--color-surface-muted);
    border-color: var(--color-border-strong);
}

/* Ghost button - minimal */
.btn--ghost {
    background: transparent;
    color: var(--color-text-secondary);
    border-color: transparent;
}

.btn--ghost:hover:not(:disabled) {
    background: var(--color-surface-muted);
    color: var(--color-text-primary);
}

/* Size variants */
.btn-sm,
.btn--sm {
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
}

.btn--lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem;
    color: var(--color-text-secondary);
    font-size: 0.875rem;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.4;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

/* Semantic badge variants */
.badge--success { background: #ecfdf5; color: #047857; }
.badge--warning { background: #fffbeb; color: #b45309; }
.badge--error   { background: #fef2f2; color: #b91c1c; }
.badge--info    { background: #f0f9ff; color: #0369a1; }
.badge--neutral { background: var(--color-surface-muted); color: var(--color-text-secondary); }

/* Priority band badges */
.badge--high { background: #fef2f2; color: #dc2626; }
.badge--medium { background: #fffbeb; color: #d97706; }
.badge--low { background: #f0fdf4; color: #16a34a; }

/* Segment badges (MECE taxonomy) */
.badge--champions { background: #d1fae5; color: #059669; }
.badge--loyal { background: #dbeafe; color: #2563eb; }
.badge--potential_loyalists { background: #ede9fe; color: #7c3aed; }
.badge--recent_one_time { background: #cffafe; color: #0891b2; }
.badge--at_risk { background: #fef3c7; color: #d97706; }
.badge--dormant_high_value { background: #fee2e2; color: #dc2626; }
.badge--dormant { background: #f3f4f6; color: #4b5563; }
.badge--dormant_limited_giving { background: #f9fafb; color: #9ca3af; }

/* Suppression status badges */
.badge--deceased { background: #6b7280; color: #fff; }
.badge--hard-optout { background: #dc2626; color: #fff; }
.badge--bounce { background: #f97316; color: #fff; }
.badge--data-quality { background: #eab308; color: #1f2937; }
.badge--internal-policy { background: #3b82f6; color: #fff; }
.badge--unknown { background: #e5e7eb; color: #6b7280; }
.badge--anonymous { background: #8b5cf6; color: #fff; }

/* Donor flags container (below location in donor cell) */
.donor-flags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.25rem;
}

.donor-flags .badge {
    font-size: 0.625rem;
    padding: 0.0625rem 0.375rem;
}

/* ==========================================================================
   Prioritization Table - Fixed Layout with Semantic Column Classes
   ========================================================================== */

/* Fixed table layout for predictable column widths */
.prioritization-table {
    table-layout: fixed;
    width: 100%;
    min-width: 1300px;
    border-collapse: separate;
    border-spacing: 0;
}

/* Column widths via colgroup */
.prioritization-table col.col-priority { width: 110px; }
.prioritization-table col.col-segment { width: 120px; }
.prioritization-table col.col-donor { width: 280px; }
.prioritization-table col.col-last-gift { width: 100px; }
.prioritization-table col.col-days-ago { width: 65px; }
.prioritization-table col.col-giving-2yr { width: 95px; }
.prioritization-table col.col-lifetime { width: 95px; }
.prioritization-table col.col-relationship-state { width: 190px; }
.prioritization-table col.col-observed-signals { width: 210px; }

/* Row dividers via box-shadow (reliable across browsers) */
.prioritization-table tbody td {
    border-bottom: none;
}

.prioritization-table tbody tr {
    box-shadow: inset 0 -1px 0 var(--color-border);
}

.prioritization-table tbody tr:last-child {
    box-shadow: none;
}

/* Sticky header with proper background and shadow */
.prioritization-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--color-surface-muted);
    border-bottom: 2px solid var(--color-border);
    white-space: nowrap;
}

/* Typography classes */
.col-num {
    text-align: center;
}

.col-nowrap {
    white-space: nowrap;
    text-align: center;
}

.text-muted {
    color: var(--color-text-muted);
}

/* Priority cell - inner wrapper for flex layout */
.cell-priority__inner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.priority-score-muted {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    cursor: help;
}

/* Donor cell - left-aligned, stacked layout */
.cell-donor {
    text-align: left;
}

.cell-donor__inner {
    display: block;
    min-width: 0; /* Allow truncation */
}

.donor-name {
    display: block;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.donor-location {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.donor-stream {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

/* Salesforce deep-link (EN-016) */
.donor-sf-link {
    display: inline-block;
    margin-top: 0.0625rem;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    text-decoration: none;
}

.donor-sf-link:hover {
    color: var(--color-brand);
    text-decoration: underline;
}

.donor-sf-link:focus-visible {
    outline: 2px solid var(--color-brand);
    outline-offset: 2px;
    border-radius: 3px;
}

/* Segment cell - centered, allow badge to wrap */
.cell-segment {
    text-align: center;
}

.cell-segment .badge {
    white-space: normal;
    line-height: 1.3;
    text-align: center;
    display: inline-block;
}

/* Relationship State cell */
.cell-relationship-state {
    text-align: left;
}

/* Left-justified header for Relationship State column */
.prioritization-table .th-relationship-state {
    text-align: left;
}

/* Observed Signals cell - left-aligned */
.cell-observed-signals {
    text-align: left;
}

/* Observed Signals list */
.signals-list {
    list-style: none;
    padding: 0;
    margin: 0;
    text-align: left;
}

.signals-list li {
    position: relative;
    padding-left: 0.9rem;
    line-height: 1.35;
    margin-bottom: 0.2rem;
    text-align: left;
}

.signals-list li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.72em;
    width: 0.45rem;
    height: 1px;
    background: currentColor;
    opacity: 0.6;
}

/* Score-based color gradient: 1 (red) → 5 (green), 0 = warning (gray) */
/* ::before uses currentColor so inherits automatically */
.signals-list li.signal-score-0 { color: #6b7280; }  /* gray - data quality issue */
.signals-list li.signal-score-1 { color: #dc2626; }  /* red */
.signals-list li.signal-score-2 { color: #ea580c; }  /* orange */
.signals-list li.signal-score-3 { color: #ca8a04; }  /* yellow/amber */
.signals-list li.signal-score-4 { color: #65a30d; }  /* lime */
.signals-list li.signal-score-5 { color: #16a34a; }  /* green */

.signals-more {
    color: var(--color-text-secondary);
    font-style: italic;
}

.signals-more::before {
    content: none;
}

/* Segment checkboxes */
.segment-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: center;
}

/* Row hover */
.prioritization-table tbody tr:hover {
    background-color: var(--color-surface-muted);
}

/* Pagination Controls */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 0;
    border-top: 1px solid var(--color-border);
    margin-top: 1rem;
    flex-wrap: wrap;
}

.pagination__info {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.pagination__controls {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.pagination__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.375rem 0.625rem;
    font-size: 0.8125rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface-card);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: background-color var(--transition-fast),
                border-color var(--transition-fast),
                color var(--transition-fast);
    min-width: 2rem;
}

.pagination__btn:hover:not(:disabled) {
    background: var(--color-surface-muted);
    border-color: var(--color-border-strong);
    color: var(--color-text-primary);
}

.pagination__btn:disabled,
.pagination__btn--disabled {
    opacity: 0.4;
    color: var(--color-text-muted);
    cursor: not-allowed;
    user-select: none;
}

.pagination__btn--disabled:hover {
    background: var(--color-surface-card);
    border-color: var(--color-border);
}

.pagination__page {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    padding: 0 0.5rem;
}

.pagination__size {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.pagination__size-label {
    color: var(--color-text-muted);
}

.pagination__size-select {
    padding: 0.375rem 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    background: var(--color-surface-card);
    cursor: pointer;
    transition: border-color var(--transition-fast),
                box-shadow var(--transition-fast);
}

.pagination__size-select:hover {
    border-color: var(--color-border-strong);
}

.pagination__size-select:focus {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: var(--shadow-focus);
}

/* Table Toolbar (title left, controls right) */
.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.5rem 0;
    margin-bottom: 0.5rem;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.table-toolbar__header {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.table-toolbar__title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-brand);
    margin: 0;
}

.table-toolbar__subtitle {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    margin: 0;
}

.table-toolbar__controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.table-toolbar__info {
    color: var(--color-text-muted);
}

.table-toolbar__pagination {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.table-toolbar__pagination .pagination__btn {
    padding: 0.25rem 0.5rem;
    min-width: 1.5rem;
    font-size: 0.875rem;
}

.table-toolbar__pagination .pagination__page {
    padding: 0 0.375rem;
    font-size: 0.8125rem;
}

.table-toolbar__size {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.table-toolbar__size-label {
    color: var(--color-text-muted);
    font-size: 0.8125rem;
}

.table-toolbar__export {
    white-space: nowrap;
}

/* Sortable Table Headers */
th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 1.25rem;
}

th.sortable:hover {
    background-color: var(--color-surface-muted);
}

th.sortable .sort-indicator {
    position: absolute;
    right: 0.375rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.625rem;
    color: var(--color-text-muted);
}

th.sortable .sort-indicator::after {
    content: "▲▼";
    font-size: 0.55rem;
    opacity: 0.35;
    display: inline-block;
    transform: translateY(-1px);
}

th.sortable.sorted .sort-indicator::after {
    opacity: 1;
    color: var(--color-brand);
}

th.sortable.sorted--asc .sort-indicator::after {
    content: '\25B2';
}

th.sortable.sorted--desc .sort-indicator::after {
    content: '\25BC';
}

/* ==========================================================================
   Revenue Intelligence Components
   ========================================================================== */

/* Stream Summary Cards (Individual, Grant, Special Account) */
.stream-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.stream-card {
    background: var(--color-surface-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1rem 1.25rem;
    border-top: 3px solid var(--color-border);
}

/* Stream-specific accent colors (top border) */
.stream-card--individual { border-top-color: #0d9488; }  /* Teal 600 */
.stream-card--grant { border-top-color: #d97706; }       /* Amber 600 */
.stream-card--special_account,
.stream-card--special-account,
.stream-card--special { border-top-color: #7c3aed; }  /* Violet 600 */

.stream-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

.stream-card__title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0;
}

.stream-card__change {
    font-size: 0.75rem;
    font-weight: 500;
}

.stream-card__revenue {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text-primary);
    line-height: 1.2;
    margin-bottom: 0.75rem;
    font-variant-numeric: tabular-nums;
}

.stream-card__metrics {
    display: flex;
    gap: 1rem;
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

.stream-card__metric {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.stream-card__metric-label {
    color: var(--color-text-muted);
    font-size: 0.8125rem;
}

.stream-card__metric-value {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--color-text-primary);
    font-variant-numeric: tabular-nums;
}

/* Analysis Grid (Bridge left, Concentration right) */
.analysis-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.analysis-grid__left,
.analysis-grid__right {
    background: var(--color-surface-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
    min-width: 0; /* Prevent overflow in grid */
}

.analysis-section__title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0 0 1rem 0;
}

/* Bridge Waterfall Chart Container */
.bridge-chart {
    width: 100%;
    height: 280px;
}

/* Bridge Formula Row */
.bridge-formula {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem;
    margin-top: 1rem;
    background: var(--color-surface-muted);
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
}

.bridge-formula__item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.bridge-formula__label {
    color: var(--color-text-secondary);
}

.bridge-formula__value {
    font-weight: 600;
    color: var(--color-text-primary);
}

.bridge-formula__operator {
    color: var(--color-text-muted);
    font-weight: 500;
    padding: 0 0.25rem;
}

.bridge-formula__equals {
    color: var(--color-text-muted);
    font-weight: 600;
    padding: 0 0.5rem;
}

/* Concentration Bars (CSS-based, no chart library) */
.concentration-bars {
    margin-bottom: 1.5rem;
}

.concentration-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.625rem;
}

.concentration-bar:last-child {
    margin-bottom: 0;
}

.concentration-bar__label {
    flex-shrink: 0;
    width: 50px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    text-align: right;
}

.concentration-bar__track {
    flex: 1;
    height: 20px;
    background: var(--color-surface-muted);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.concentration-bar__fill {
    height: 100%;
    background: var(--color-brand);
    border-radius: var(--radius-sm);
    transition: width var(--transition-base);
}

.concentration-bar__value {
    flex-shrink: 0;
    width: 45px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text-primary);
    font-variant-numeric: tabular-nums;
}

/* Stream Mix Chart */
.stream-mix-chart {
    width: 100%;
    height: 200px;
    margin-top: 1rem;
}

/* Trend Cards (Sparklines) */
.trend-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.trend-card {
    background: var(--color-surface-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1rem;
}

.trend-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.trend-card__title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin: 0;
}

.trend-card__delta {
    font-size: 0.8125rem;
    font-weight: 500;
}

.trend-card__value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text-primary);
    line-height: 1.2;
    margin-bottom: 0.5rem;
    font-variant-numeric: tabular-nums;
}

.trend-card__sparkline {
    width: 100%;
    height: 80px;
}

/* Footer Stats */
.footer-stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
    padding: 1rem;
    margin-top: 1rem;
    border-top: 1px solid var(--color-border);
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
}

.footer-stat {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.footer-stat__label {
    color: var(--color-text-muted);
}

.footer-stat__value {
    font-weight: 600;
    color: var(--color-text-primary);
    font-variant-numeric: tabular-nums;
}

/* Revenue Page Header with Period Selector */
.revenue-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.revenue-header__title {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0;
}

.revenue-header__subtitle {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    margin-top: 0.25rem;
}

.revenue-header__title,
.revenue-header__subtitle {
    min-width: 0; /* Prevent overflow with long text */
}

.revenue-header__controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Stream Filter Dropdown (HTMX) */
.stream-filter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stream-filter__label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-secondary);
}

/* Section Header with Filter */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.section-header__title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0;
}

/* ================================================================
   Login / Pending Approval Pages
   ================================================================ */

.login-page {
    background-color: var(--color-surface-page);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-container {
    width: 100%;
    max-width: 440px;
    padding: 1rem;
}

.login-card {
    background: var(--color-surface-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.login-card h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: 0.5rem;
}

.login-card p {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    margin-bottom: 1.5rem;
}

.btn-login {
    display: inline-block;
    width: 100%;
    padding: 0.75rem 1.5rem;
    background-color: var(--color-brand);
    color: #ffffff;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.btn-login:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

@media (hover: hover) {
    .btn-login:hover {
        background-color: var(--color-brand-hover);
    }
}

/* Logout form in header dropdown — matches .user-menu-dropdown a in app.css */
.logout-form {
    margin: 0;
    padding: 0;
}

.logout-form button {
    background: none;
    border: none;
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-family: inherit;
    color: var(--color-text-primary);
    text-decoration: none;
    cursor: pointer;
}

.logout-form button:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

@media (hover: hover) {
    .logout-form button:hover {
        background-color: var(--color-surface-muted);
    }
}

/* Revenue Intelligence Responsive */
@media (max-width: 1100px) {
    .stream-cards {
        grid-template-columns: 1fr;
    }

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

    .trend-cards {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 850px) {
    .stream-card__revenue {
        font-size: 1.25rem;
    }

    .trend-card__value {
        font-size: 1.1rem;
    }

    .footer-stats {
        flex-wrap: wrap;
        gap: 1rem;
    }

    .bridge-formula {
        font-size: 0.75rem;
    }
}

@media (max-width: 600px) {
    .revenue-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .footer-stats {
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
    }

    .bridge-formula {
        flex-direction: column;
        gap: 0.25rem;
    }

    .bridge-formula__operator,
    .bridge-formula__equals {
        display: none;
    }
}

/* Responsive */
@media (max-width: 1400px) {
    .kpi-value {
        font-size: 1.25rem;
    }
}

@media (max-width: 1100px) {
    .kpi-value {
        font-size: 1.1rem;
    }
}

@media (max-width: 900px) {
    .kpi-value {
        font-size: 1rem;
    }
}

@media (max-width: 850px) {
    header nav {
        flex-direction: column;
        gap: 1rem;
    }

    main {
        padding: 1rem;
    }

    .kpi-cards {
        gap: 0.75rem;
    }

    .kpi-card {
        min-width: calc(50% - 0.5rem);
        padding: 0.75rem;
    }

    .kpi-value {
        font-size: 0.9rem;
    }

    .chart-container,
    .data-table,
    .chart-half {
        padding: 1rem;
    }

    .chart-row {
        flex-direction: column;
    }

    #giving-chart,
    #avg-chart,
    #butterfly-chart,
    #concentration-chart,
    #composition-chart,
    #revenue-composition-chart,
    .chart-half > div {
        height: 300px;
    }

    table {
        font-size: 0.75rem;
    }

    th, td {
        padding: 0.35rem 0.5rem;
    }

    th.column-group {
        font-size: 0.75rem;
    }

    thead tr:nth-child(2) th {
        font-size: 0.7rem;
    }
}

@media (max-width: 600px) {
    .kpi-card {
        min-width: 100%;
    }

    .kpi-value {
        font-size: 1.1rem;
    }

    #giving-chart,
    #avg-chart,
    #butterfly-chart,
    #concentration-chart,
    #composition-chart,
    #revenue-composition-chart,
    .chart-half > div {
        height: 250px;
    }

    .chart-container,
    .data-table {
        margin-left: -1rem;
        margin-right: -1rem;
        border-radius: 0;
    }

    table {
        min-width: auto;
        font-size: 0.65rem;
    }

    th, td {
        padding: 0.25rem 0.35rem;
    }
}

/* Prioritization table responsive - tighter padding, keep horizontal scroll */
@media (max-width: 1400px) {
    .prioritization-table th,
    .prioritization-table td {
        padding: 0.375rem 0.5rem;
    }

    .table-subtitle,
    .table-toolbar__subtitle {
        display: none;
    }
}

/* Accessibility: Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
