/*
  ======================================================
  Global Emotions Index - Refreshed Stylesheet (2025)
  Author: Nadim.pro
  ======================================================
*/

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&family=Inter:wght@400;500;700&display=swap');

/* --- CSS Variables (Theme) --- */
:root {
    /* Colors */
    --color-background: #1A202C; /* Deep Slate */
    --color-surface: #2D3748;    /* Lighter Slate */
    --color-border: #4A5568;     /* Gray Slate */
    --color-primary-text: #F7FAFC; /* Bright White */
    --color-secondary-text: #A0AEC0; /* Lighter Gray */
    --color-accent: #4FD1C5;      /* Vibrant Teal */
    --color-accent-hover: #81E6D9; /* Lighter Teal */
    --color-success: #68D391;     /* Green */
    --color-danger: #FC8181;      /* Red */

    /* Typography */
    --font-primary: 'Cairo', 'Inter', sans-serif;
    --font-secondary: 'Inter', sans-serif;

    /* Sizing & Radius */
    --border-radius: 12px;
    --sidebar-width: 400px;

    /* Transitions & Shadows */
    --transition-fast: 0.2s ease-in-out;
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -2px rgba(0, 0, 0, 0.1);
}

/* --- Base & Reset --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-primary);
    background-color: var(--color-background);
    color: var(--color-primary-text);
    overflow: hidden;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3 {
    font-weight: 700;
    line-height: 1.3;
    color: var(--color-primary-text);
}

p {
    color: var(--color-secondary-text);
    margin-bottom: 1rem;
}

a {
    color: var(--color-accent);
    text-decoration: none;
    transition: color var(--transition-fast);
}
a:hover {
    color: var(--color-accent-hover);
}

/* --- App Layout --- */
#app-container, #stats-page-container {
    opacity: 0;
    animation: fadeIn 0.8s ease-out forwards;
}
@keyframes fadeIn {
    to { opacity: 1; }
}

#app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* --- Sidebar --- */
#sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--color-background);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    z-index: 1002;
    transition: transform 0.3s ease-in-out;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}
.sidebar-content::-webkit-scrollbar { width: 6px; }
.sidebar-content::-webkit-scrollbar-track { background: transparent; }
.sidebar-content::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }

.sidebar-header { margin-bottom: 24px; }
.sidebar-header .logo { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.sidebar-header h1 { font-size: 1.6rem; }
.sidebar-header .subtitle { font-size: 0.95rem; margin-bottom: 0; }

/* --- Emotion Selector --- */
#emotion-selector { margin-bottom: 24px; }
.emotions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
    gap: 12px;
}
.emo-btn {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-primary-text);
    padding: 12px;
    border-radius: var(--border-radius);
    font-size: 2.2rem; /* Larger emoji */
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    aspect-ratio: 1 / 1;
}
.emo-btn span {
    font-size: 0.8rem;
    font-weight: 500;
    font-family: var(--font-secondary);
}
.emo-btn:hover {
    transform: translateY(-5px);
    border-color: var(--color-accent);
    box-shadow: var(--shadow-lg);
    background-color: #354153;
}
.emo-btn:active {
    transform: translateY(-2px) scale(0.98);
}

/* --- Card Elements --- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 20px;
}
.card h2 {
    margin-top: 0;
    padding-bottom: 12px;
    font-size: 1.1rem;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 16px;
}

/* --- Timeline --- */
#timeline {
    list-style: none;
    height: 250px;
    overflow-y: auto;
    padding-right: 10px; /* Space for scrollbar */
}
#timeline::-webkit-scrollbar { display: none; }
#timeline { -ms-overflow-style: none; scrollbar-width: none; }
#timeline li {
    padding: 12px 4px;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
}
#timeline li:last-child { border-bottom: none; }
#timeline li .loc { font-weight: bold; color: var(--color-primary-text); }

/* --- Stats Page Link --- */
.stats-link-container { margin-top: auto; }
.stats-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    transition: all var(--transition-fast);
}
.stats-link:hover {
    border-color: var(--color-accent);
    background-color: #354153;
}

/* --- Footer --- */
.sidebar-footer {
    padding: 20px 24px;
    text-align: center;
    border-top: 1px solid var(--color-border);
}
.sidebar-footer p { font-size: 0.85rem; margin: 0; }

/* --- Main Map Area --- */
#map-container {
    flex: 1;
    position: relative;
    height: 100vh;
}
#map {
    height: 100%;
    width: 100%;
    background-color: #11151C;
}

/* --- Map Controls --- */
#map-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(26, 32, 44, 0.8);
    backdrop-filter: blur(8px);
    padding: 10px 15px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    z-index: 1000;
    box-shadow: var(--shadow-md);
}
.switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-size: 0.9rem;
    font-family: var(--font-secondary);
}
.switch input { display: none; }
.slider {
    width: 40px;
    height: 22px;
    border-radius: 11px;
    background-color: var(--color-border);
    transition: var(--transition-fast);
    position: relative;
}
.slider::before {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: white;
    transition: var(--transition-fast);
}
.switch input:checked + .slider { background-color: var(--color-accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* --- Mobile Sidebar Toggle --- */
#sidebar-toggle-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 1003;
    background-color: rgba(26, 32, 44, 0.8);
    backdrop-filter: blur(8px);
    border: 1px solid var(--color-border);
    color: var(--color-primary-text);
    width: fit-content;
    height: 44px;
    border-radius: var(--border-radius);
    cursor: pointer;
    display: none; /* Hidden on large screens */
    align-items: center;
    justify-content: center;
    padding: 10px;
}

/* --- Loader --- */
#loader {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(26, 32, 44, 0.9);
    backdrop-filter: blur(5px);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0; visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}
#loader.visible { opacity: 1; visibility: visible; }
.spinner {
    width: 50px; height: 50px;
    border: 4px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Pulse Animation on Map --- */
.pulse-icon {
    width: 28px; height: 28px;
    border-radius: 50%;
    border: 4px solid white;
    background-color: var(--color-accent);
    box-shadow: 0 0 15px var(--color-accent), 0 0 30px var(--color-accent), 0 0 45px var(--color-accent);
    animation: pulse-glow 2s ease-out infinite;
}
@keyframes pulse-glow {
    0% { transform: scale(0.6); opacity: 0.7; }
    70% { opacity: 1; }
    100% { transform: scale(3.2); opacity: 0; }
}

/* --- Placeholder --- */
.placeholder-glow .placeholder {
    background-color: currentColor;
    opacity: 0.2;
    min-height: 1.2em;
    animation: placeholder-glow 2s ease-in-out infinite;
}
.placeholder.col-12 { width: 100%; }
@keyframes placeholder-glow { 50% { opacity: 0.1; } }


/*
  ==============================================
  STATS PAGE SPECIFIC STYLES
  ==============================================
*/
.stats-header {
    padding: 60px 24px;
    background-color: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    text-align: center;
}
.stats-header h1 {
    font-size: 2.8rem;
    color: var(--color-primary-text);
}
.stats-header p {
    font-size: 1.2rem;
    color: var(--color-secondary-text);
    max-width: 600px;
    margin: 10px auto 0;
}
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 24px;
    padding: 10px 20px;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background-color: var(--color-background);
}
.back-link:hover {
    border-color: var(--color-accent);
}

.stats-main {
    padding: 24px;
    max-width: 1600px;
    margin: 0 auto;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
}
.kpi-card {
    padding: 24px;
    text-align: center;
    margin-bottom: 0; /* Override default card margin */
}
.kpi-card .value {
    font-size: 3rem;
    font-weight: 700;
    color: var(--color-accent);
    font-family: var(--font-secondary);
}
.kpi-card .label {
    font-size: 1rem;
    color: var(--color-secondary-text);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 24px;
}

.chart-container {
    height: 350px;
    padding-top: 10px;
}

.full-width {
    grid-column: 1 / -1;
}


/* --- Responsive Design --- */
@media (max-width: 1024px) {
    :root { --sidebar-width: 320px; }
    .emotions-grid { grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); }
}

@media (max-width: 768px) {
    body { overflow: auto; }
    #sidebar {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        width: 300px;
        transform: translateX(100%);
        box-shadow: var(--shadow-lg);
        border-right: none;
        border-left: 1px solid var(--color-border);
    }
    #sidebar.open {
        transform: translateX(0);
    }
    #sidebar-toggle-btn {
        display: flex;
    }
    .stats-header h1 { font-size: 2rem; }
    .stats-header p { font-size: 1rem; }
    .stats-main { padding: 16px; }
    .stats-grid { gap: 16px; }
    .leaflet-bottom {
       bottom: 50px !important;
    }

    #map-controls {
        bottom: 60px !important;
    }

}