/* --- 1. CSS Variables & Themes --- */
:root {
    /* Light Mode Palette */
    --text-primary: #1a1a1a;
    --text-secondary: #555b66;
    --text-link: #2563eb;
    --container-bg: rgba(255, 255, 255, 0.95);
    --card-bg: #ffffff;
    --input-bg: #f8fafc;
    --border-color: #e2e8f0;
    --shadow-color: rgba(0, 0, 0, 0.08);
    --btn-primary-bg: #2563eb;
    --btn-primary-text: #ffffff;
    --accent-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);

    /* Animated Background Variables (Light) */
    --bg-gradient-1: #fdfbfb;
    --bg-gradient-2: #ebedee;
    --bg-gradient-3: #e0c3fc;
}

body.dark-mode {
    /* Dark Mode Palette */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-link: #60a5fa;
    --container-bg: rgba(30, 41, 59, 0.95);
    --card-bg: #0f172a;
    --input-bg: #1e293b;
    --border-color: #334155;
    --shadow-color: rgba(0, 0, 0, 0.5);
    --btn-primary-bg: #3b82f6;
    --btn-primary-text: #ffffff;
    --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);

    /* Animated Background Variables (Dark) */
    --bg-gradient-1: #0f2027;
    --bg-gradient-2: #203a43;
    --bg-gradient-3: #2c5364;
}

/* --- 2. Global Animations & Layout --- */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text-primary);
    margin: 0;
    padding-bottom: 50px;
    transition: color 0.3s ease;
    background: linear-gradient(-45deg, var(--bg-gradient-1), var(--bg-gradient-2), var(--bg-gradient-3), var(--bg-gradient-1));
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    min-height: 100vh;
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* --- NAVBAR STYLES --- */
.navbar {
    background-color: var(--container-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 25px 0;
    box-shadow: 0 4px 20px var(--shadow-color);
    transition: padding 0.3s ease, background-color 0.3s ease;
}

.navbar.scrolled {
    padding: 10px 0;
    background-color: rgba(255, 255, 255, 0.98);
}
body.dark-mode .navbar.scrolled {
    background-color: rgba(15, 23, 42, 0.98);
}

.nav-container {
    max-width: 1000px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
}

.nav-logo-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.logo-img {
    height: 45px;
    width: 45px;
    object-fit: cover;
    border-radius: 50%;
    transition: height 0.3s ease, width 0.3s ease;
    border: 1px solid var(--border-color);
}

.navbar.scrolled .logo-img {
    height: 30px;
    width: 30px;
}

.nav-logo-text {
    font-size: 22px;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.nav-links { display: flex; align-items: center; gap: 25px; }
.nav-links a {
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 600;
    transition: color 0.2s;
    font-size: 15px;
}
.nav-links a:hover { color: var(--text-link); }

/* Main Container */
.container {
    max-width: 900px;
    margin: 40px auto;
    background-color: var(--container-bg);
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 10px 40px var(--shadow-color);
    backdrop-filter: blur(5px);
    border: 1px solid var(--border-color);
}

.blog-article-container { max-width: 800px; }

h1 { color: var(--text-primary); margin-top: 0; letter-spacing: -0.5px; }
.subtitle { color: var(--text-secondary); font-size: 1.1rem; line-height: 1.5; }

/* --- 3. Form & Inputs --- */
#search-form { display: flex; flex-direction: column; gap: 20px; margin-top: 30px; }

input, select {
    padding: 14px 16px;
    border: 2px solid var(--border-color);
    background-color: var(--input-bg);
    color: var(--text-primary);
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.3s ease;
    outline: none;
}

input:focus, select:focus {
    border-color: var(--text-link);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.main-search { display: grid; grid-template-columns: 2fr 1fr; gap: 15px; }
@media (max-width: 600px) { .main-search { grid-template-columns: 1fr; } }

/* Advanced Filters */
.advanced-filters-container {
    background-color: var(--input-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    transition: 0.3s;
}
.advanced-filters-container[open] { border-color: var(--text-link); box-shadow: 0 4px 12px var(--shadow-color); }
summary {
    font-weight: 700;
    cursor: pointer;
    padding: 15px 20px;
    background-color: var(--input-bg);
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    list-style: none;
    transition: background 0.2s;
}
summary:hover { background-color: var(--border-color); color: var(--text-primary); }
summary::after { content: '▼'; font-size: 12px; transition: transform 0.3s; }
details[open] summary::after { transform: rotate(180deg); }
details[open] summary { border-bottom: 1px solid var(--border-color); color: var(--text-link); }
.filters-grid {
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    background-color: var(--container-bg);
}
.filter-group label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
.input-pair { display: flex; gap: 10px; }

/* Buttons */
button {
    padding: 14px 28px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s, filter 0.2s;
}
button:active { transform: scale(0.98); }
.primary-btn { background: var(--accent-gradient); color: white; box-shadow: 0 4px 15px rgba(37, 99, 235, 0.3); }
.primary-btn:hover { filter: brightness(1.1); box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4); }
.secondary-btn { background-color: transparent; border: 2px solid var(--border-color); color: var(--text-secondary); }
.secondary-btn:hover { background-color: var(--border-color); color: var(--text-primary); }
.submission-row { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 10px; gap: 20px; flex-wrap: wrap; }

/* Cards */
.channel-card, .blog-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}
@media(min-width: 600px) { .channel-card { flex-direction: row; align-items: center; } }
.channel-card:hover, .blog-card:hover { transform: translateY(-3px); box-shadow: 0 10px 25px var(--shadow-color); border-color: var(--text-link); }
.channel-card img { width: 70px; height: 70px; border-radius: 50%; object-fit: cover; border: 3px solid var(--input-bg); margin-right: 20px; margin-bottom: 10px; }
.channel-info h3 { margin: 0 0 5px 0; }
.channel-info a, .blog-card h2 a { text-decoration: none; color: var(--text-primary); font-weight: 800; font-size: 1.2rem; transition: color 0.2s; }
.channel-info a:hover, .blog-card h2 a:hover { color: var(--text-link); }
.channel-stats { display: flex; gap: 15px; flex-wrap: wrap; margin-top: 10px; }
.stat-item { background: var(--input-bg); padding: 4px 10px; border-radius: 20px; font-size: 13px; font-weight: 600; color: var(--text-secondary); border: 1px solid var(--border-color); }

/* Blog & AI */
.blog-grid { display: grid; gap: 20px; margin-top: 20px; }
.blog-date { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 10px; display: block; }
.read-more { display: inline-block; margin-top: 15px; color: var(--text-link); font-weight: 700; text-decoration: none; }
.blog-content { font-size: 1.1rem; line-height: 1.8; color: var(--text-primary); }
.blog-content h2 { color: var(--text-link); margin-top: 40px; }
.blog-content ul { padding-left: 20px; color: var(--text-secondary); }
#ai-summary-container { background: linear-gradient(to right, rgba(37, 99, 235, 0.05), rgba(139, 92, 246, 0.05)); border: 1px solid var(--text-link); border-radius: 12px; padding: 25px; margin: 30px 0; }
.ai-header h3 { margin: 0; background: var(--accent-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; font-size: 1.4rem; }
.ad-slot { text-align: center; margin: 20px 0; padding: 10px; border: 1px dashed var(--border-color); color: var(--text-secondary); font-size: 12px; min-height: 90px; background: var(--bg-color); }

/* --- 4. THEME TOGGLE SWITCH (Emoji) --- */
.theme-switch-wrapper { display: flex; align-items: center; margin-left: 20px; }
.theme-switch { position: relative; display: inline-block; width: 54px; height: 28px; }
.theme-switch input { opacity: 0; width: 0; height: 0; }

.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #cbd5e1; transition: .4s; border-radius: 34px; }
.slider:before {
    position: absolute;
    content: "☀️";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

input:checked + .slider { background-color: var(--text-link); }
input:checked + .slider:before {
    transform: translateX(26px);
    content: "🌙";
    background-color: #fff;
}

/* Utilities */
.hidden { display: none; }
#loader { margin: 20px auto; border: 4px solid var(--border-color); border-top: 4px solid var(--text-link); border-radius: 50%; width: 30px; height: 30px; animation: spin 1s linear infinite; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.error-text { color: #e74c3c; text-align: center; font-weight: bold; }

/* --- 5. ANALYTICS MODAL --- */
.modal {
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    display: none; /* Hidden by default */
    justify-content: center;
    align-items: center;
}

.modal.active { display: flex; }

.modal-content {
    background-color: var(--card-bg);
    padding: 30px;
    border-radius: 16px;
    width: 90%;
    max-width: 800px; /* Wider for better chart */
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
    z-index: 10001;
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    color: var(--text-secondary);
    cursor: pointer;
}
.close-modal:hover { color: var(--text-primary); }

.modal-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 15px;
    margin-top: 15px;
}

.modal-stat-box {
    background: var(--input-bg);
    padding: 15px;
    border-radius: 10px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.modal-stat-box .label { display: block; font-size: 12px; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 5px; }
.modal-stat-box .value { font-size: 18px; font-weight: 800; color: var(--text-primary); }

.chart-container { position: relative; height: 350px; width: 100%; }

/* --- NEW CHART CONTROLS --- */
.chart-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

.time-filters { display: flex; gap: 5px; background: var(--input-bg); padding: 4px; border-radius: 8px; border: 1px solid var(--border-color); }
.time-btn {
    background: transparent;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text-secondary);
    font-weight: 600;
}
.time-btn.active { background: var(--card-bg); color: var(--text-link); box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.time-btn:hover:not(.active) { color: var(--text-primary); }

.metric-toggles { display: flex; gap: 15px; font-size: 14px; font-weight: 600; color: var(--text-secondary); }
.metric-toggles label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
