:root {
    --brand-red: #e63946;
    --brand-teal: #457b9d;
    --brand-light: #f1faee;
    --brand-dark: #1d3557;
    --brand-accent: #a8dadc;
    --gradient-primary: linear-gradient(135deg, #1d3557 0%, #457b9d 100%);
    --gradient-secondary: linear-gradient(135deg, #e63946 0%, #f1faee 100%);
    --text-primary: #1d3557;
    --text-secondary: #4a5568;
    --text-light: #718096;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Barlow', sans-serif;
    background-color: var(--brand-light);
    color: var(--text-primary);
    background-image: radial-gradient(var(--brand-teal) 1px, transparent 0);
    background-size: 40px 40px;
    background-position: -19px -19px;
    overflow-x: hidden;
    max-width: 100vw;
}

.hero-gradient {
    background: var(--gradient-primary);
}

.card-gradient {
    background: linear-gradient(135deg, rgba(255,255,255,0.95) 0%, rgba(241,250,238,0.95) 100%);
}

/* Logo styling */
.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: brightness(0) saturate(100%) invert(25%) sepia(80%) saturate(2000%) hue-rotate(340deg) brightness(90%) contrast(90%);
}

.logo-fallback {
    display: none;
    font-weight: bold;
    color: var(--brand-red);
}

.region-card {
    transition: all 0.3s ease;
    border-left: 4px solid;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.region-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
}

.region-card:active {
    transform: translateY(-2px);
}

.pulse-animation {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.glow {
    box-shadow: 0 0 15px rgba(168, 218, 220, 0.5);
}

.fade-in {
    animation: fadeIn 1s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.stagger-animation > * {
    opacity: 0;
    animation: fadeIn 0.5s ease-in forwards;
}

.stagger-animation > *:nth-child(1) { animation-delay: 0.1s; }
.stagger-animation > *:nth-child(2) { animation-delay: 0.2s; }
.stagger-animation > *:nth-child(3) { animation-delay: 0.3s; }
.stagger-animation > *:nth-child(4) { animation-delay: 0.4s; }
.stagger-animation > *:nth-child(5) { animation-delay: 0.5s; }
.stagger-animation > *:nth-child(6) { animation-delay: 0.6s; }
.stagger-animation > *:nth-child(7) { animation-delay: 0.7s; }

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: var(--brand-light);
}
::-webkit-scrollbar-thumb {
    background: var(--brand-teal);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--brand-red);
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Tabs styling */
.tab-button {
    transition: all 0.3s ease;
    min-height: 44px;
    min-width: 44px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    border: none;
    background: none;
}

.tab-button.active {
    background-color: var(--brand-teal);
    color: white;
}

.tab-button:focus {
    outline: 2px solid var(--brand-teal);
    outline-offset: 2px;
}

.division-list {
    max-height: 300px;
    overflow-y: auto;
}

/* Loading states */
.loading-spinner {
    border: 2px solid #f3f3f3;
    border-top: 2px solid var(--brand-teal);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#loading-overlay {
    backdrop-filter: blur(4px);
}

/* Mobile optimized styles */
.mobile-optimized .tab-button {
    padding: 12px 16px;
    font-size: 14px;
}

.mobile-optimized .region-card {
    padding: 12px;
}

/* Focus styles for accessibility */
button:focus-visible,
a:focus-visible,
.tab-button:focus-visible,
.region-card:focus-visible {
    outline: 2px solid var(--brand-teal);
    outline-offset: 2px;
}

/* Error state */
.error-state {
    background-color: #fee2e2;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 1rem;
    border-radius: 0.5rem;
    text-align: center;
}

.error-state i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .fade-in,
    .stagger-animation > *,
    .region-card,
    .pulse-animation,
    .loading-spinner {
        animation: none;
        transition: none;
    }
    
    .region-card:hover {
        transform: none;
    }
}

/* Responsive Design */
@media (max-width: 1536px) {
    .max-w-7xl {
        max-width: 1280px;
    }
}

@media (max-width: 1280px) {
    .max-w-7xl {
        max-width: 1024px;
    }
}

@media (max-width: 1024px) {
    .lg\:col-span-2 {
        grid-column: span 1;
    }
    
    .grid-cols-1.lg\:grid-cols-3 {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
    
    .max-w-7xl {
        max-width: 768px;
    }
}

@media (max-width: 768px) {
    .header-stats {
        flex-direction: row;
        justify-content: center;
        gap: 0.5rem;
    }
    
    .hero-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    
    .hero-stats > div {
        min-width: auto;
        flex: none;
    }
    
    .desktop-nav {
        display: none;
    }
    
    .map-container {
        height: 300px !important;
        min-height: 300px;
    }
    
    .region-cards {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .info-cards {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .footer-content {
        grid-template-columns: 1fr;
        gap: 2rem;
        text-align: center;
    }
    
    .hero-title {
        font-size: 1.75rem !important;
        line-height: 1.2;
    }
    
    .hero-subtitle {
        font-size: 1rem !important;
        line-height: 1.4;
    }
    
    /* Improved spacing for mobile */
    .space-y-8 > * + * {
        margin-top: 1.5rem;
    }
    
    /* Better tab buttons for touch */
    .tab-button {
        padding: 12px 16px;
        font-size: 14px;
    }
    
    /* Adjust padding for mobile */
    .px-4.sm\:px-6.lg\:px-8 {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    .p-4.md\:p-6 {
        padding: 1rem;
    }
}

@media (max-width: 640px) {
    /* Extra small devices */
    .hero-stats {
        grid-template-columns: 1fr;
    }
    
    .hero-title {
        font-size: 1.5rem !important;
    }
    
    .hero-subtitle {
        font-size: 0.9rem !important;
    }
    
    /* Stack header elements vertically */
    .flex.flex-col.sm\:flex-row {
        gap: 1rem;
    }
    
    /* Better chart container */
    .population-chart-container {
        height: 180px !important;
    }
    
    /* Better region card text sizing */
    .region-card h3 {
        font-size: 1rem;
        line-height: 1.3;
    }
    
    .region-card p {
        font-size: 0.875rem;
        line-height: 1.4;
    }
    
    .header-stats {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .map-container {
        height: 250px !important;
    }
}

@media (max-width: 480px) {
    /* Small mobile devices */
    .map-container {
        height: 220px !important;
        min-height: 220px;
    }
    
    .hero-stats > div {
        padding: 0.75rem;
    }
    
    /* Adjust font sizes for very small screens */
    .text-3xl {
        font-size: 1.5rem;
    }
    
    .text-2xl {
        font-size: 1.25rem;
    }
    
    .text-xl {
        font-size: 1.125rem;
    }
    
    .text-lg {
        font-size: 1rem;
    }
    
    /* Improve touch targets */
    button, .tab-button, [onclick] {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Extra small devices (phones under 375px) */
@media (max-width: 374px) {
    .map-container {
        height: 200px !important;
        min-height: 200px;
    }
    
    .hero-title {
        font-size: 1.25rem !important;
    }
    
    .hero-subtitle {
        font-size: 0.8rem !important;
    }
    
    .region-cards {
        gap: 0.5rem;
    }
    
    .region-card {
        padding: 0.75rem;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .region-card:hover {
        transform: none;
    }
    
    button, .tab-button, .touch-optimized {
        min-height: 44px;
        min-width: 44px;
        touch-action: manipulation;
    }
    
    /* Improve touch targets for interactive elements */
    .region-card, .info-cards > div {
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
}

/* Large screen optimizations */
@media (min-width: 1920px) {
    .max-w-7xl {
        max-width: 1536px;
    }
    
    body {
        font-size: 16px;
        line-height: 1.6;
    }
}

/* Ensure images and canvas are responsive */
img, canvas, video {
    max-width: 100%;
    height: auto;
}

/* Improve text readability on small screens */
@media (max-width: 768px) {
    body {
        font-size: 14px;
        line-height: 1.5;
    }
    
    h1 {
        font-size: 1.75rem;
        line-height: 1.2;
    }
    
    h2 {
        font-size: 1.5rem;
        line-height: 1.3;
    }
    
    h3 {
        font-size: 1.25rem;
        line-height: 1.3;
    }
    
    p {
        line-height: 1.5;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .hero-gradient {
        background: #000000;
    }
    
    .card-gradient {
        background: #ffffff;
        border: 2px solid #000000;
    }
    
    .logo-img {
        filter: brightness(0) saturate(100%) invert(0%);
    }
}

/* Print styles */
@media print {
    .hero-gradient {
        background: #1d3557 !important;
        -webkit-print-color-adjust: exact;
        color-adjust: exact;
    }
    
    .card-gradient {
        background: white !important;
        -webkit-print-color-adjust: exact;
        color-adjust: exact;
        border: 1px solid #000000;
    }
    
    .map-container {
        display: none;
    }
    
    #loading-overlay {
        display: none !important;
    }
}