/* Base Variables & Reset */
:root {
    /* Perinteinen Theme Colors (Corporate, clean) */
    --p-bg: #f4f6f9;
    --p-text: #2c3e50;
    --p-card-bg: #ffffff;
    --p-accent: #2980b9;
    --p-positive: #27ae60;
    --p-negative: #c0392b;
    --p-font: 'Inter', sans-serif;
    
    /* Kuvitettu Theme Colors (Warm, pastel) */
    --k-bg: #fdf6e3;
    --k-text: #5c4a3d;
    --k-card-bg: #fffbf0;
    --k-accent: #e67e22;
    --k-positive: #2ecc71;
    --k-negative: #e74c3c;
    --k-font: 'Playfair Display', serif;
    
    /* Lasi Theme Colors (Dark, glassmorphism) */
    --l-bg: #0f172a;
    --l-text: #f8fafc;
    --l-card-bg: rgba(30, 41, 59, 0.4);
    --l-card-border: rgba(255, 255, 255, 0.1);
    --l-accent: #8b5cf6;
    --l-positive: #10b981;
    --l-negative: #ef4444;
    --l-font: 'Inter', sans-serif;
    
    --transition-speed: 0.6s;
}

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

body {
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
}

#canvas-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    pointer-events: none;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    position: relative;
    z-index: 10;
}

/* Base structural classes */
header {
    margin-bottom: 2rem;
    text-align: center;
}

h1 {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    font-weight: 800;
    line-height: 1.1;
}

h2 {
    font-size: 1.5rem;
    opacity: 0.8;
    margin-bottom: 2rem;
    font-weight: 400;
    line-height: 1.2;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.kpi-card {
    padding: 1.5rem;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-speed) ease;
    border: 1px solid transparent;
}

.kpi-label {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.7;
    margin-bottom: 0.5rem;
    text-align: center;
    line-height: 1.2;
}

.kpi-value {
    font-size: 1.8rem;
    font-weight: 700;
    text-align: center;
    line-height: 1.2;
}

/* Theme Selector */
.theme-selector {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 3rem;
    padding: 1rem;
    border-radius: 50px;
    background: rgba(0,0,0,0.03);
    max-width: max-content;
    margin-left: auto;
    margin-right: auto;
    border: 1px solid transparent;
}

.theme-btn {
    padding: 0.75rem 2rem;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    transition: all 0.3s ease;
    background: transparent;
    line-height: 1.2;
}

/* Charts and Layout */
#main-content {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 2rem;
    align-items: stretch;
}

@media (max-width: 1024px) {
    #main-content {
        grid-template-columns: 1fr;
        align-items: start;
    }

    /* On tablet/mobile the metrics panel should not be fixed height */
    .metrics-container {
        height: auto !important;
    }

    /* Reduce chart height on tablet */
    .chart-container.primary-chart {
        height: 400px !important;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.2rem;
        margin-bottom: 1.2rem;
    }

    .kpi-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    .kpi-card {
        padding: 1rem;
    }

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

    .theme-selector {
        gap: 0.5rem;
        padding: 0.6rem;
        margin-bottom: 1.5rem;
    }

    .theme-btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }

    /* Reduce chart height on mobile */
    .chart-container.primary-chart {
        height: 300px !important;
    }

    #main-content {
        gap: 1rem;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.6rem;
    }

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

    .kpi-label {
        font-size: 0.75rem;
    }

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

    .theme-btn {
        padding: 0.4rem 0.7rem;
        font-size: 0.8rem;
    }
}

/* iOS Safari fix: background-attachment:fixed causes rendering issues */
@supports (-webkit-touch-callout: none) {
    body.theme-perinteinen,
    body.theme-kuvitettu,
    body.theme-lasi {
        background-attachment: scroll;
    }
}

.chart-container, .metrics-container {
    border-radius: 16px;
    padding: 1.5rem;
    transition: all var(--transition-speed) ease;
    border: 1px solid transparent;
}

.metrics-container {
    height: 100%;
    overflow-y: auto;
    box-sizing: border-box;
}

/* Kuvitettu theme: dark brown text in month details panel */
body.theme-kuvitettu .metrics-container,
body.theme-kuvitettu .metrics-container * {
    color: #3b2507 !important;
}

/* Lasi theme: white text in analysis section */
body.theme-lasi #analysis-section,
body.theme-lasi #analysis-section * {
    color: #ffffff !important;
}

/* Notice/Tooltip Bubble */
.notice-bubble {
    position: fixed;
    z-index: 1000;
    min-width: 250px;
    max-width: 350px;
    padding: 1.2rem;
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, 20px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.notice-bubble.active {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
}

.notice-bubble.hidden {
    display: none;
}

.notice-content {
    font-size: 0.95rem;
    line-height: 1.4;
    font-weight: 500;
    text-align: center;
}

.notice-arrow {
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0; 
    height: 0; 
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
}

/* Utility Colors */
.text-positive { color: var(--p-positive); transition: color var(--transition-speed); }
.text-negative { color: var(--p-negative); transition: color var(--transition-speed); }
body.theme-kuvitettu .text-positive { color: var(--k-positive); }
body.theme-kuvitettu .text-negative { color: var(--k-negative); }
body.theme-lasi .text-positive { color: var(--l-positive); }
body.theme-lasi .text-negative { color: var(--l-negative); }


/* ================= THEME: PERINTEINEN ================= */
body.theme-perinteinen {
    background-color: var(--p-bg);
    background-image: url('assets/perinteinen_bg.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: var(--p-text);
    font-family: var(--p-font);
}
.theme-perinteinen .kpi-card,
.theme-perinteinen .chart-container,
.theme-perinteinen .metrics-container {
    background-color: rgba(253, 250, 245, 0.9); /* Warm white, slightly transparent to let background show through */
    backdrop-filter: blur(5px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    border: 1px solid #e2e8f0;
}
.theme-perinteinen .theme-selector {
    background-color: rgba(253, 250, 245, 0.9);
}
.theme-perinteinen .theme-btn {
    color: var(--p-text);
}
.theme-perinteinen .theme-btn.active,
.theme-perinteinen .theme-btn:hover {
    background-color: var(--p-card-bg);
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    color: var(--p-accent);
}
.theme-perinteinen .notice-bubble {
    background: #fdfaf5; /* Warm white */
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
}
.theme-perinteinen .notice-arrow {
    border-top: 8px solid #fdfaf5;
}

/* ================= THEME: KUVITETTU ================= */
body.theme-kuvitettu {
    background-color: var(--k-bg);
    background-image: url('assets/kuvitettu_bg.jpg?v=2');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: var(--k-text);
    font-family: var(--k-font);
}

body.theme-kuvitettu h1, body.theme-kuvitettu h2, body.theme-kuvitettu .theme-btn {
    font-family: var(--k-font);
}
body.theme-kuvitettu h1, body.theme-kuvitettu h2 {
    color: var(--k-text);
    text-shadow: 
        -1px -1px 0 #fdfbf7,  
         1px -1px 0 #fdfbf7,
        -1px  1px 0 #fdfbf7,
         1px  1px 0 #fdfbf7,
         0px -1px 0 #fdfbf7,
         0px  1px 0 #fdfbf7,
        -1px  0px 0 #fdfbf7,
         1px  0px 0 #fdfbf7;
}
.theme-kuvitettu .kpi-card,
.theme-kuvitettu .chart-container,
.theme-kuvitettu .metrics-container {
    background-color: rgba(255, 251, 240, 0.85); /* Let watercolor show through slightly */
    backdrop-filter: blur(2px);
    border: 1px solid var(--k-text);
    border-radius: 20px;
    box-shadow: 6px 6px 0px var(--k-text), inset 0 0 0 2px var(--k-text);
}
.theme-kuvitettu .theme-selector {
    border: 1px solid var(--k-text);
    background: var(--k-card-bg);
    box-shadow: 4px 4px 0px var(--k-text), inset 0 0 0 2px var(--k-text);
}
.theme-kuvitettu .theme-btn {
    color: var(--k-text);
}
.theme-kuvitettu .theme-btn.active,
.theme-kuvitettu .theme-btn:hover {
    background-color: var(--k-accent);
    color: #fff;
    border-radius: 20px;
}
.theme-kuvitettu .notice-bubble {
    background-color: #fff;
    color: var(--k-text);
    border: 3px solid var(--k-text);
    /* Comic book speech bubble style */
    border-radius: 50% / 30%;
    padding: 1.5rem;
    box-shadow: 4px 4px 0px var(--k-text);
}
.theme-kuvitettu .notice-arrow {
    border-top: 15px solid var(--k-text);
    bottom: -15px;
}
/* inner arrow for border trick */
.theme-kuvitettu .notice-arrow::after {
    content: '';
    position: absolute;
    left: -6px;
    top: -18px;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 12px solid #fff;
}

/* ================= THEME: LASI ================= */
body.theme-lasi {
    background-color: var(--l-bg);
    background-image: url('assets/lasi_bg.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: var(--l-text);
    font-family: var(--l-font);
}
.theme-lasi .theme-selector {
    background: rgba(30, 41, 59, 0.4);
    border: 1px solid var(--l-card-border);
    backdrop-filter: blur(15px);
}
.theme-lasi .kpi-card,
.theme-lasi .chart-container,
.theme-lasi .metrics-container {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.02) 100%);
    border: 1px solid rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}
.theme-lasi .theme-btn {
    color: var(--l-text);
}
.theme-lasi .theme-btn.active,
.theme-lasi .theme-btn:hover {
    background: rgba(139, 92, 246, 0.5); /* Accent color with opacity */
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.4);
}
.theme-lasi .notice-bubble {
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid var(--l-card-border);
    backdrop-filter: blur(15px);
    color: var(--l-text);
    border-radius: 12px;
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.5);
}
.theme-lasi .notice-arrow {
    border-top: 8px solid rgba(139, 92, 246, 0.5);
}
