/**
 * @file
 * CIF Portfolio Dashboard Styles - Optimized & Fully Responsive
 * 
 * Location: modules/custom/portfolio_overview/css/dashboard.css
 */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    color: #1f2937;
    line-height: 1.6;
    overflow-x: hidden;
}

.dashboard {
    max-width: 100%;
    margin: 0;
    padding: 0;
}

/* Hero Section */
.hero {
    background: linear-gradient(135deg, #003366 0%, #0056b3 100%);
    border-radius: 0;
    padding: clamp(2rem, 5vw, 3rem) clamp(1rem, 3vw, 2rem);
    color: white;
    text-align: center;
    margin-bottom: 0;
    box-shadow: 0 10px 40px rgba(0, 51, 102, 0.3);
    position: relative;
    overflow: hidden;
}

.hero::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    animation: pulse 15s ease-in-out infinite;
    pointer-events: none;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 0.3; }
    50% { transform: scale(1.1); opacity: 0.5; }
}

.hero-content {
    position: relative;
    z-index: 1;
}

.hero h1 {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.hero-subtitle {
    font-size: clamp(0.875rem, 2vw, 1.125rem);
    opacity: 0.9;
    margin-bottom: 2rem;
}

.hero-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: clamp(1rem, 2vw, 1.5rem);
    margin-top: 2rem;
}

.hero-stat {
    text-align: center;
    padding: 0.5rem;
}

.hero-stat-value {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    font-weight: 700;
    display: block;
    margin-bottom: 0.25rem;
    color: #fe850b;
    text-shadow: 0 2px 10px rgba(254, 133, 11, 0.3);
}

.hero-stat-label {
    font-size: clamp(0.75rem, 1.5vw, 0.875rem);
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Filter Bar */
.filter-bar {
    background: white;
    border-radius: 0;
    padding: clamp(1rem, 2vw, 1.5rem);
    margin-bottom: 0;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.07);
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: flex-end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1 1 180px;
    min-width: 150px;
}

.filter-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-select {
    padding: 0.625rem 1rem;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 0.875rem;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}

.filter-select:hover {
    border-color: #fe850b;
}

.filter-select:focus {
    outline: none;
    border-color: #fe850b;
    box-shadow: 0 0 0 3px rgba(254, 133, 11, 0.1);
}

.filter-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    flex: 1 1 100%;
}

.btn {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.875rem;
    white-space: nowrap;
    flex: 1 1 auto;
    min-width: 120px;
}

.btn-primary {
    background: #fe850b;
    color: white;
}

.btn-primary:hover,
.btn-primary:focus {
    background: #e57609;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(254, 133, 11, 0.3);
}

.btn-secondary {
    background: #f3f4f6;
    color: #6b7280;
}

.btn-secondary:hover,
.btn-secondary:focus {
    background: #e5e7eb;
}

.btn-export {
    background: #003366;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-export:hover,
.btn-export:focus {
    background: #00509e;
}

/* Metric Cards */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 0;
    margin-bottom: 0;
}

.metric-card {
    background: white;
    border-radius: 0;
    padding: clamp(1rem, 2vw, 1.5rem);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    border-right: 1px solid #e5e7eb;
    border-bottom: 1px solid #e5e7eb;
}

.metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(180deg, #fe850b, #ffa500);
}

.metric-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
    z-index: 1;
}

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

.metric-icon {
    font-size: clamp(1.5rem, 3vw, 2rem);
    opacity: 0.8;
}

.metric-value {
    font-size: clamp(1.5rem, 3vw, 2rem);
    font-weight: 700;
    color: #003366;
    margin-bottom: 0.25rem;
    word-break: break-word;
}

.metric-label {
    font-size: 0.875rem;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metric-subtext {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 0.5rem;
}

/* Section Headers */
.section {
    margin-bottom: 0;
    padding: clamp(1rem, 3vw, 2rem);
    background: white;
    border-bottom: 1px solid #e5e7eb;
}

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

.section-title-group {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.section-title {
    font-size: clamp(1.25rem, 3vw, 1.5rem);
    font-weight: 700;
    color: #1f2937;
}

.section-badge {
    background: #fe850b;
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0;
    border-bottom: 2px solid #e5e7eb;
    background: white;
    padding: 0 clamp(1rem, 2vw, 2rem);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.tabs::-webkit-scrollbar {
    height: 4px;
}

.tabs::-webkit-scrollbar-thumb {
    background: #e5e7eb;
    border-radius: 2px;
}

.tab {
    padding: 0.75rem 1.5rem;
    border: none;
    background: none;
    cursor: pointer;
    font-weight: 600;
    color: #6b7280;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
    position: relative;
    top: 2px;
    white-space: nowrap;
    flex-shrink: 0;
}

.tab:hover,
.tab:focus {
    color: #003366;
}

.tab.active {
    color: #003366;
    border-bottom-color: #fe850b;
}

/* Chart Containers */
.chart-container {
    background: white;
    border-radius: 0;
    padding: clamp(1rem, 3vw, 2rem);
    box-shadow: none;
    margin-bottom: 0;
    border-bottom: 1px solid #e5e7eb;
}

.chart-title {
    font-size: clamp(1rem, 2vw, 1.25rem);
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: #1f2937;
}

canvas {
    max-height: 400px;
    width: 100% !important;
    height: auto !important;
}

/* Grid Layouts */
.two-col-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    margin-bottom: 0;
}

@media (min-width: 768px) {
    .two-col-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .two-col-grid .chart-container:first-child {
        border-right: 1px solid #e5e7eb;
    }
}

/* Sankey Container */
#sankey-container {
    min-height: 400px;
    height: clamp(400px, 50vh, 600px);
    position: relative;
    overflow: hidden;
}

#sankey-container svg {
    width: 100%;
    height: 100%;
}

/* Timeline */
.timeline-container {
    padding: clamp(1rem, 3vw, 2rem) 0;
    position: relative;
}

.timeline-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    align-items: center;
    flex-wrap: wrap;
}

.timeline-play-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background: #fe850b;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.timeline-play-btn:hover,
.timeline-play-btn:focus {
    background: #e57609;
    transform: scale(1.1);
}

.timeline-slider {
    flex: 1;
    min-width: 150px;
    height: 8px;
    border-radius: 4px;
    background: #e5e7eb;
    position: relative;
    cursor: pointer;
}

.timeline-progress {
    height: 100%;
    background: linear-gradient(90deg, #003366, #fe850b);
    border-radius: 4px;
    transition: width 0.3s;
    width: 0;
}

.timeline-year {
    font-size: clamp(1.25rem, 3vw, 1.5rem);
    font-weight: 700;
    color: #003366;
    min-width: 80px;
    text-align: center;
}

/* Comparison Mode */
.comparison-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: clamp(1rem, 2vw, 1.5rem);
}

@media (min-width: 768px) {
    .comparison-grid {
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    }
}

.comparison-card {
    background: #f9fafb;
    border-radius: 8px;
    padding: clamp(1rem, 2vw, 2rem);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.comparison-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #e5e7eb;
}

.comparison-title {
    font-size: clamp(1rem, 2vw, 1.25rem);
    font-weight: 700;
    color: #003366;
}

.comparison-stats {
    display: grid;
    gap: 1rem;
}

.comparison-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: white;
    border-radius: 8px;
    gap: 1rem;
}

.comparison-stat-label {
    font-size: 0.875rem;
    color: #6b7280;
}

.comparison-stat-value {
    font-size: clamp(1rem, 2vw, 1.125rem);
    font-weight: 700;
    color: #003366;
    white-space: nowrap;
}

/* Map Container */
#map-container {
    height: clamp(300px, 50vh, 600px);
    border-radius: 0;
    overflow: hidden;
    box-shadow: none;
    width: 100%;
}

/* Recent Projects */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: clamp(1rem, 2vw, 1.5rem);
}

.project-card {
    background: #f9fafb;
    border-radius: 8px;
    padding: clamp(1rem, 2vw, 1.5rem);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    cursor: pointer;
    border-left: 4px solid #fe850b;
}

.project-card:hover,
.project-card:focus {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}

.project-title {
    font-size: clamp(1rem, 2vw, 1.125rem);
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: #1f2937;
    line-height: 1.4;
}

.project-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.project-tag {
    background: white;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    color: #6b7280;
}

.project-value {
    font-size: clamp(1rem, 2vw, 1.25rem);
    font-weight: 700;
    color: #16a34a;
}

/* CTA Section */
.cta-section {
    background: linear-gradient(135deg, #989c9e 0%, #fff 100%);
    border-radius: 0;
    padding: clamp(2rem, 5vw, 3rem) clamp(1rem, 3vw, 2rem);
    text-align: center;
    color: #1f2937;
    margin-top: 0;
}

.cta-title {
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: 700;
    margin-bottom: 1rem;
}

.cta-button {
    display: inline-block;
    background: #003366;
    color: white;
    padding: 1rem 2rem;
    border-radius: 8px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-size: clamp(0.875rem, 2vw, 1rem);
}

.cta-button:hover,
.cta-button:focus {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
    background: #00509e;
}

/* Loading State */
.loading {
    text-align: center;
    padding: 3rem 1rem;
    color: #6b7280;
}

.spinner {
    border: 4px solid #f3f4f6;
    border-top: 4px solid #fe850b;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* PWA Install Banner */
.pwa-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #003366 0%, #0056b3 100%);
    color: white;
    padding: 1rem;
    display: none;
    align-items: center;
    justify-content: space-between;
    z-index: 1000;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
    flex-wrap: wrap;
    gap: 1rem;
}

.pwa-banner.show {
    display: flex;
}

.pwa-content {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
    min-width: 200px;
}

.pwa-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.pwa-text h3 {
    font-size: clamp(0.875rem, 2vw, 1rem);
    margin-bottom: 0.25rem;
}

.pwa-text p {
    font-size: clamp(0.75rem, 1.5vw, 0.875rem);
    opacity: 0.9;
}

.pwa-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.pwa-btn {
    padding: 0.5rem 1rem;
    border: 2px solid white;
    border-radius: 8px;
    background: transparent;
    color: white;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    font-size: 0.875rem;
}

.pwa-btn:hover,
.pwa-btn:focus {
    background: white;
    color: #003366;
}

.pwa-btn-primary {
    background: white;
    color: #003366;
}

.pwa-btn-primary:hover,
.pwa-btn-primary:focus {
    background: #fe850b;
    color: white;
    border-color: #fe850b;
}

/* Tablet Responsive */
@media (max-width: 1024px) {
    .filter-actions {
        width: 100%;
    }
    
    .btn {
        min-width: 100px;
    }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .hero-stats {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .filter-group {
        width: 100%;
        min-width: unset;
    }
    
    .filter-actions {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
        min-width: unset;
    }
    
    .metrics-grid {
        grid-template-columns: 1fr;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .projects-grid {
        grid-template-columns: 1fr;
    }
    
    .timeline-controls {
        gap: 0.75rem;
    }
    
    .timeline-play-btn {
        width: 40px;
        height: 40px;
        font-size: 1.25rem;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .hero-stats {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .comparison-grid {
        grid-template-columns: 1fr;
    }
    
    .pwa-banner {
        flex-direction: column;
        text-align: center;
    }
    
    .pwa-content {
        flex-direction: column;
        text-align: center;
    }
    
    .pwa-actions {
        width: 100%;
    }
    
    .pwa-btn {
        flex: 1;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn,
    .tab,
    .project-card,
    .filter-select {
        min-height: 44px;
        min-width: 44px;
    }
    
    .metric-card:hover {
        transform: none;
    }
    
    .project-card:hover {
        transform: none;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
    }

    .filter-bar,
    .btn,
    .cta-section,
    .pwa-banner,
    .tabs {
        display: none !important;
    }

    .chart-container,
    .section,
    .metric-card {
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #e5e7eb;
    }
    
    .hero {
        box-shadow: none;
    }
    
    #map-container {
        height: 500px;
    }
}

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

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .btn,
    .tab,
    .filter-select {
        border-width: 2px;
    }
    
    .metric-card,
    .project-card,
    .comparison-card {
        border: 2px solid #000;
    }
}

/**
 * CSS for Enhanced Timeline Section
 * Add this to your dashboard.css
 */

/* Timeline Section */
.timeline-section {
  background: white;
  padding: clamp(1.5rem, 3vw, 2rem);
  border-bottom: 1px solid #e5e7eb;
}

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

.timeline-legend {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: #6b7280;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

/* Timeline Visualization */
.timeline-visualization {
  background: #f9fafb;
  padding: 1.5rem;
  border-radius: 8px;
  margin-bottom: 2rem;
}

#timelineChart {
  max-height: 350px;
}

/* Timeline Stats */
.timeline-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.timeline-stat-card {
  background: linear-gradient(135deg, #f9fafb 0%, #ffffff 100%);
  padding: 1.5rem;
  border-radius: 8px;
  border-left: 4px solid #fe850b;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
}

.timeline-stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.timeline-stat-card .stat-value {
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 700;
  color: #003366;
  margin-bottom: 0.5rem;
}

.timeline-stat-card .stat-label {
  font-size: 0.875rem;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Stage Progression */
.stage-progression {
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 2px solid #e5e7eb;
}

.stage-progression h4 {
  font-size: clamp(1.125rem, 2vw, 1.25rem);
  font-weight: 600;
  margin-bottom: 1.5rem;
  color: #1f2937;
}

.stage-progression-bars {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.stage-bar-item {
  background: #f9fafb;
  padding: 1rem;
  border-radius: 8px;
  transition: all 0.3s ease;
}

.stage-bar-item:hover {
  background: #f3f4f6;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.stage-bar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.stage-name {
  font-weight: 600;
  color: #1f2937;
  font-size: 0.9375rem;
}

.stage-count {
  font-size: 0.875rem;
  color: #6b7280;
}

.stage-bar-container {
  background: #e5e7eb;
  height: 24px;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  margin-bottom: 0.5rem;
}

.stage-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #003366, #fe850b);
  border-radius: 12px;
  transition: width 0.6s ease;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 0.75rem;
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.stage-bar-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.stage-investment {
  font-size: 0.875rem;
  font-weight: 600;
  color: #16a34a;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .timeline-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .timeline-legend {
    width: 100%;
    justify-content: flex-start;
  }

  .timeline-stats {
    grid-template-columns: 1fr;
  }

  .stage-bar-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Animation for bar fills */
@keyframes fillBar {
  from {
    width: 0;
  }
}

.stage-bar-fill {
  animation: fillBar 0.8s ease-out;
}