/**
 * UNCDF Donor Revenue Chart - Updated Styles
 * Changes: White background, removed type breakdown, fixed mobile layout, FontAwesome icons
 */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #ffffff; /* Solid white background */
    color: #1e293b;
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 40px 20px;
}

/* ===================================
   PAGE HEADER
   =================================== */

.page-header {
    text-align: center;
    margin-bottom: 40px;
}

.page-header h1 {
    font-size: 42px;
    font-weight: bold;
    color: #1e293b;
    margin-bottom: 8px;
}

.page-header p {
    font-size: 18px;
    color: #64748b;
}

/* ===================================
   STATS GRID (MATCHES KPI CONTAINER)
   =================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin: 0px 5px 40px 5px;
}

/* ===================================
   STAT CARD (MATCHES KPI CARD PATTERN)
   =================================== */

.stat-card {
    position: relative;
    padding: 40px 32px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    cursor: pointer;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

/* Animated gradient background pseudo-element (matches KPI::before) */
.stat-card::before {
    content: '';
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity 0.4s ease;
    z-index: 0;
}

/* Color-specific gradients */
.stat-card.blue::before {
    background: linear-gradient(135deg, #0468B1 0%, #1e40af 100%);
}

.stat-card.green::before {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.stat-card.purple::before {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
}

.stat-card.orange::before {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

/* Hover state - fade in gradient background */
.stat-card:hover::before {
    opacity: 1;
}

/* Enhanced hover elevation and shadow (matches KPI:hover) */
.stat-card:hover {
    transform: translateY(-8px);
}

.stat-card.blue:hover {
    box-shadow: 0 16px 32px rgba(4, 104, 177, 0.3);
}

.stat-card.green:hover {
    box-shadow: 0 16px 32px rgba(16, 185, 129, 0.3);
}

.stat-card.purple:hover {
    box-shadow: 0 16px 32px rgba(139, 92, 246, 0.3);
}

.stat-card.orange:hover {
    box-shadow: 0 16px 32px rgba(245, 158, 11, 0.3);
}

/* ===================================
   STAT LABEL (MATCHES KPI LABEL)
   =================================== */

.stat-label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #64748b;
    margin-bottom: 12px;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1;
}

.stat-card:hover .stat-label {
    color: rgba(255, 255, 255, 0.95);
}

/* ===================================
   STAT VALUE (MATCHES KPI VALUE)
   =================================== */

.stat-value {
    font-size: 48px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 8px;
    line-height: 1;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1;
}

.stat-card:hover .stat-value {
    color: white;
    transform: scale(1.05);
}

/* ===================================
   STAT DESCRIPTION (MATCHES KPI DESCRIPTION)
   =================================== */

.stat-description {
    font-size: 13px;
    color: #94a3b8;
    font-weight: 500;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1;
}

.stat-card:hover .stat-description {
    color: rgba(255, 255, 255, 0.9);
}

/* ===================================
   CONTROLS
   =================================== */

.controls {
    background: white;
    padding: 24px;
    margin-bottom: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border-radius: 12px 12px 0 0;
}

.control-group {
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
}

.btn-group {
    display: flex;
    gap: 8px;
}

.btn {
    padding: 10px 20px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    background: white;
    color: #475569;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn:hover {
    border-color: #0468B1;
    color: #0468B1;
}

.btn.active {
    background: #0468B1;
    border-color: #0468B1;
    color: white;
}

.btn-secondary {
    background: #64748b;
    border-color: #64748b;
    color: white;
}

.btn-secondary:hover {
    background: #475569;
    border-color: #475569;
}

/* ===================================
   CONSOLIDATION TOGGLE
   =================================== */

.consolidation-toggle {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.consolidation-toggle .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.consolidation-toggle .btn.active {
    background: #0468B1;
    border-color: #0468B1;
    color: white;
    box-shadow: 0 2px 8px rgba(4, 104, 177, 0.2);
}

.consolidation-toggle .btn:not(.active):hover {
    background: #f8fafc;
    border-color: #0468B1;
    color: #0468B1;
    transform: translateY(-1px);
}

/* Consolidation button icons */
.consolidation-toggle .btn i {
    font-size: 14px;
}

/* ===================================
   FONTAWESOME ICON SPACING IN BUTTONS
   =================================== */

.btn i {
    margin-right: 6px;
    font-size: 0.9em;
}

/* Ensure icons align properly */
.btn i.fa-solid,
.btn i.fa-regular,
.btn i.fa-brands {
    vertical-align: middle;
}

/* ===================================
   FILTERS
   =================================== */

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-group label {
    font-size: 14px;
    font-weight: 600;
    color: #475569;
    white-space: nowrap;
}

select {
    padding: 10px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    background: white;
    color: #475569;
    font-size: 14px;
    cursor: pointer;
    transition: border-color 0.2s;
}

select:hover,
select:focus {
    border-color: #0468B1;
    outline: none;
}

input[type="text"] {
    flex: 1;
    min-width: 200px;
    padding: 10px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s;
}

input[type="text"]:focus {
    border-color: #0468B1;
    outline: none;
}

input[type="text"]::placeholder {
    color: #94a3b8;
}

/* ===================================
   CONTROL HELP TEXT
   =================================== */

.control-help-text {
    font-size: 12px;
    color: #64748b;
    margin-top: 12px;
    line-height: 1.5;
}

.control-help-text strong {
    color: #475569;
    font-weight: 600;
}

/* ===================================
   LOADING STATE
   =================================== */

.loading {
    display: none;
    text-align: center;
    padding: 80px 40px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.loading.show {
    display: block;
}

.loading h2 {
    font-size: 24px;
    color: #1e293b;
    margin-bottom: 8px;
}

.loading p {
    font-size: 16px;
    color: #64748b;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #e2e8f0;
    border-top-color: #0468B1;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

/* ===================================
   TWO-COLUMN CHART LAYOUT
   =================================== */

.chart-layout {
    display: flex;
    gap: 24px;
    margin-bottom: 32px;
    align-items: flex-start;
}

.chart-column {
    flex: 0 0 70%;
    min-width: 0;
}

.sidebar-column {
    flex: 0 0 calc(30% - 24px);
    position: sticky;
    top: 20px;
    max-height: 80vh;
    overflow-y: auto;
}

/* ===================================
   CHART CONTAINER
   =================================== */

.chart-container {
    background: white;
    padding: 40px;
    margin-top: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border-radius: 0 0 12px 12px;
    overflow-x: auto;
    overflow-y: auto;
    max-height: 80vh;
}

#chart {
    min-height: 400px;
    width: 100%;
    position: relative;
}

/* ===================================
   SIDEBAR DONOR DETAIL CARD
   =================================== */

.donor-detail-card {
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.donor-detail-card.empty {
    opacity: 0.6;
}

.donor-detail-header {
    padding: 24px;
    background: linear-gradient(135deg, #0468B1 0%, #1e40af 100%);
    color: white;
    position: relative;
}

.donor-flag-container {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

.donor-flag {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.donor-name {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
    margin: 0;
}

.donor-type {
    display: inline-block;
    padding: 4px 12px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    margin-top: 8px;
}

.donor-detail-body {
    padding: 24px;
}

.donor-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    border-bottom: 1px solid #e2e8f0;
}

.donor-stat-row:last-of-type {
    border-bottom: none;
}

.donor-stat-label {
    font-size: 13px;
    color: #64748b;
    font-weight: 600;
}

.donor-stat-value {
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
}

.donor-stat-value.highlight {
    color: #0468B1;
}

.donor-meta {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e2e8f0;
}

.donor-meta-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 13px;
}

.donor-meta-item:last-child {
    margin-bottom: 0;
}

.donor-meta-label {
    color: #64748b;
    font-weight: 600;
}

.donor-meta-value {
    color: #1e293b;
    font-weight: 500;
    text-align: right;
}

/* Bar highlight state */
.bar-highlighted {
    opacity: 1 !important;
    filter: brightness(1.1);
}

.bar-dimmed {
    opacity: 0.3 !important;
}

/* ===================================
   OLD TOOLTIP (HIDDEN)
   =================================== */

.tooltip,
#tooltip {
    display: none !important;
}

/* ===================================
   DONOR TOOLTIP CONTAINER (INLINE VERSION)
   =================================== */

.donor-tooltip-container {
    background: white;
    border-left: 4px solid #0468B1;
    padding: 20px 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 0; /* No margin - chart will add spacing */
    min-height: 120px;
    display: flex;
    align-items: center;
    transition: all 0.3s ease;
}

/* Empty state */
.donor-tooltip-container.empty {
    background: #f8fafc;
    border-left-color: #cbd5e1;
}

.donor-tooltip-container.empty .tooltip-content {
    opacity: 0.5;
}

/* Tooltip content wrapper */
.tooltip-content {
    width: 100%;
    padding: 15px;
}

/* Empty state message */
.tooltip-empty {
    text-align: center;
    color: #94a3b8;
    font-size: 14px;
    font-style: italic;
}

.tooltip-empty i {
    font-size: 24px;
    margin-bottom: 8px;
    display: block;
}

/* Tooltip header */
.tooltip-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid #e2e8f0;
}

.tooltip-org-info {
    flex: 1;
}

.tooltip-org-name {
    font-size: 20px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 4px;
}

.tooltip-donor-id {
    font-size: 12px;
    color: #64748b;
    font-family: 'Courier New', monospace;
    font-weight: 600;
}

.tooltip-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #dbeafe;
    color: #1e40af;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

.tooltip-badge i {
    font-size: 14px;
}

/* Parent org indicator */
.tooltip-parent-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: #f0fdf4;
    color: #15803d;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 8px;
}

.tooltip-parent-indicator i {
    font-size: 12px;
}

/* Tooltip body */
.tooltip-body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

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

.tooltip-stat-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
}

.tooltip-stat-value {
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
}

.tooltip-stat-value.highlight {
    color: #0468B1;
}

/* Child organizations section */
.tooltip-children {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e2e8f0;
}

.tooltip-children-header {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
    margin-bottom: 12px;
}

.tooltip-children-header i {
    margin-right: 6px;
    color: #0468B1;
}

.tooltip-child-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tooltip-child-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #f8fafc;
    border-radius: 6px;
    border-left: 3px solid #0468B1;
}

.tooltip-child-name {
    font-size: 13px;
    color: #475569;
    font-weight: 600;
    flex: 1;
}

.tooltip-child-revenue {
    font-size: 13px;
    font-weight: 700;
    color: #0468B1;
    margin-left: 12px;
}

/* Metadata section */
.tooltip-metadata {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    padding-top: 12px;
    border-top: 1px solid #e2e8f0;
}

.tooltip-meta-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tooltip-meta-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #94a3b8;
}

.tooltip-meta-value {
    font-size: 13px;
    color: #475569;
    font-weight: 600;
}

/* Legacy compatibility - keep old class names working */
.donor-flag-container {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

.donor-flag {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.donor-name {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.3;
    margin: 0;
}

.donor-type {
    display: inline-block;
    padding: 4px 12px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    margin-top: 8px;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
}

.empty-state i {
    font-size: 48px;
    color: #cbd5e1;
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 18px;
    font-weight: 700;
    color: #64748b;
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    color: #94a3b8;
    line-height: 1.6;
}

/* Bar interaction states */
.bar-highlighted {
    opacity: 1 !important;
    filter: brightness(1.1);
}

.bar-dimmed {
    opacity: 0.3 !important;
}

/* ===================================
   LEGEND
   =================================== */

.donor-legend {
    background: white;
    padding: 24px;
    margin-bottom: 32px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border-radius: 12px;
}

.donor-legend h3 {
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 16px;
}

.legend-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.legend-item span {
    font-size: 14px;
    color: #475569;
    font-weight: 500;
}

/* ===================================
   DISCLAIMER
   =================================== */

.disclaimer {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 24px;
    font-size: 14px;
    color: #475569;
    line-height: 1.7;
}

.disclaimer h4 {
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 16px;
}

.disclaimer p {
    margin-bottom: 12px;
}

.disclaimer ul {
    margin: 12px 0 12px 24px;
}

.disclaimer li {
    margin-bottom: 8px;
}

.disclaimer a {
    color: #0468B1;
    text-decoration: none;
    font-weight: 600;
}

.disclaimer a:hover {
    text-decoration: underline;
}

.last-updated {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e2e8f0;
    font-size: 13px;
    color: #64748b;
}

/* ===================================
   FLAG ICONS
   =================================== */

.flag-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* ===================================
   RESPONSIVE DESIGN
   =================================== */

@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .chart-column {
        flex: 0 0 65%;
    }
    
    .sidebar-column {
        flex: 0 0 calc(35% - 24px);
    }
}

@media (max-width: 768px) {
    .page-header h1 {
        font-size: 32px;
    }
    
    .stat-value {
        font-size: 36px;
    }
    
    .stat-label {
        font-size: 11px;
        letter-spacing: 0.8px;
    }
    
    .control-group {
        flex-direction: column;
        align-items: stretch;
    }
    
    .btn-group {
        width: 100%;
    }
    
    .btn {
        flex: 1;
    }
    
    /* Icon spacing adjustment for mobile */
    .btn i {
        margin-right: 4px;
    }
    
    input[type="text"] {
        width: 100%;
    }
    
    .chart-container {
        padding: 20px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    /* Mobile layout - card below chart, not floating */
    .chart-layout {
        flex-direction: column;
        gap: 24px;
    }
    
    .chart-column {
        flex: 1;
        width: 100%;
    }
    
    .sidebar-column {
        position: relative;
        width: 100%;
        max-height: none;
        transform: none;
        transition: none;
        z-index: auto;
        background: transparent;
        padding: 0;
        top: auto;
    }
    
    .donor-detail-card {
        border-radius: 12px;
        max-height: none;
        overflow-y: visible;
    }
}
