/* ===== CSS Reset & Base Styles ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #d32f2f;
    --primary-dark: #b71c1c;
    --primary-light: #ff6659;
    --secondary-color: #1976d2;
    --text-primary: #212121;
    --text-secondary: #757575;
    --text-light: #9e9e9e;
    --background: #ffffff;
    --surface: #fafafa;
    --border: #e0e0e0;
    --shadow-light: 0 2px 8px rgba(0, 0, 0, 0.05);
    --shadow-medium: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-heavy: 0 8px 24px rgba(0, 0, 0, 0.12);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --header-height: 132px;
    --top-ad-height: 60px;
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
}

body {
    font-family: 'Inter', 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text-primary);
    background-color: var(--background);
    line-height: 1.5;
    overflow-x: hidden;
}

/* ===== Typography ===== */
h1, h2, h3 {
    font-weight: 600;
    line-height: 1.2;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.5rem; margin-bottom: 1rem; }
h3 { font-size: 1.25rem; }

p {
    margin-bottom: 1rem;
}

a {
    color: var(--secondary-color);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--primary-color);
}

/* ===== Header & Advertisement ===== */
.main-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background-color: var(--background);
    box-shadow: var(--shadow-light);
    transition: transform var(--transition-normal);
}

/* Top Header Ad */
.header-ad {
    background: linear-gradient(90deg, #f5f5f5, #fafafa);
    border-bottom: 1px solid var(--border);
    height: var(--top-ad-height);
    overflow: hidden;
    transition: height var(--transition-normal), opacity var(--transition-normal);
}

.header-ad.hidden {
    height: 0;
    opacity: 0;
    border-bottom: none;
}

.ad-content {
    position: relative;
    max-width: 1200px;
    margin: 0 auto;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.ad-content.vertical {
    flex-direction: column;
    justify-content: center;
    padding: 20px 10px;
}

.ad-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ad-placeholder {
    background: linear-gradient(135deg, #e0e0e0, #f0f0f0);
    border: 1px dashed #bdbdbd;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    text-align: center;
    padding: 12px 24px;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 728px;
}

.ad-content.vertical .ad-placeholder {
    max-width: 160px;
    height: 600px;
    padding: 20px;
    writing-mode: vertical-rl;
    text-orientation: mixed;
}

.ad-close {
    position: absolute;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 1rem;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--transition-fast);
}

.ad-close:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

/* Primary Navigation */
.primary-nav {
    border-bottom: 1px solid var(--border);
    background-color: var(--background);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    color: var(--primary-color);
    font-size: 1.8rem;
}

.brand-name {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-icon-btn {
    background: none;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.nav-icon-btn:hover {
    background-color: var(--surface);
}

/* Category Navigation */
.category-nav-container {
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
    position: relative;
}

.category-nav {
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
}

.category-scroll-wrapper {
    display: flex;
    gap: 2px;
    padding: 0 40px;
    overflow-x: auto;
    scroll-behavior: smooth;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.category-scroll-wrapper::-webkit-scrollbar {
    display: none;
}

.category-btn {
    background: none;
    border: none;
    padding: 12px 20px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition-fast);
    position: relative;
}

.category-btn:hover {
    color: var(--text-primary);
    background-color: rgba(0, 0, 0, 0.02);
}

.category-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    font-weight: 600;
}

.scroll-btn {
    position: absolute;
    top: 0;
    height: 100%;
    width: 40px;
    background-color: var(--surface);
    border: none;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: background-color var(--transition-fast);
}

.scroll-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.scroll-left {
    left: 0;
    box-shadow: 8px 0 12px -8px rgba(0, 0, 0, 0.1) inset;
}

.scroll-right {
    right: 0;
    box-shadow: -8px 0 12px -8px rgba(0, 0, 0, 0.1) inset;
}

/* ===== Main Content Layout ===== */
.content-wrapper {
    display: grid;
    grid-template-columns: 1fr minmax(0, 800px) 1fr;
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 16px;
    gap: 24px;
}

/* Sidebars */
.sidebar {
    position: relative;
}

.sticky-ad {
    position: sticky;
    top: calc(var(--header-height) + 20px);
    display: flex;
    justify-content: center;
}

/* News Feed */
.news-feed {
    min-width: 0; /* Prevents grid overflow */
}

.feed-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.feed-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.control-btn {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 16px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all var(--transition-fast);
}

.control-btn:hover {
    background-color: #f0f0f0;
    border-color: #bdbdbd;
}

.control-btn.active {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.view-toggle {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.view-toggle .control-btn {
    border: none;
    border-radius: 0;
    padding: 8px 12px;
}

/* ===== News Cards ===== */
.news-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.news-cards.list-view {
    grid-template-columns: 1fr;
}

.news-card {
    background-color: var(--surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-light);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
    cursor: pointer;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.news-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-medium);
}

.card-image {
    width: 100%;
    height: 180px;
    object-fit: cover;
    display: block;
    background-color: #e0e0e0;
}

.card-content {
    padding: 20px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.card-title {
    font-size: 1.15rem;
    font-weight: 600;
    line-height: 1.4;
    margin-bottom: 10px;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-description {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 16px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    flex-grow: 1;
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
}

.card-source {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-time {
    font-size: 0.8rem;
    color: var(--text-light);
}

.list-view .news-card {
    flex-direction: row;
}

.list-view .card-image {
    width: 200px;
    height: auto;
    flex-shrink: 0;
}

/* ===== Skeleton Loader ===== */
.skeleton-loader {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.skeleton-card {
    background-color: var(--surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-light);
    height: 380px;
    display: flex;
    flex-direction: column;
}

.skeleton-image {
    width: 100%;
    height: 180px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

.skeleton-text-container {
    padding: 20px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.skeleton-title,
.skeleton-desc,
.skeleton-source {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 4px;
}

.skeleton-title {
    height: 24px;
    width: 80%;
}

.skeleton-desc {
    height: 16px;
    width: 100%;
}

.skeleton-desc:nth-child(3) {
    width: 70%;
}

.skeleton-source {
    height: 14px;
    width: 40%;
    margin-top: auto;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===== Error State ===== */
.error-state {
    text-align: center;
    padding: 60px 20px;
    display: none;
}

.error-icon {
    font-size: 3rem;
    color: #ff9800;
    margin-bottom: 20px;
}

.error-state h3 {
    margin-bottom: 12px;
    color: var(--text-primary);
}

.error-state p {
    color: var(--text-secondary);
    max-width: 500px;
    margin: 0 auto 24px;
}

.retry-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 12px 28px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: background-color var(--transition-fast);
}

.retry-btn:hover {
    background-color: var(--primary-dark);
}

/* ===== Load More Button ===== */
.load-more-container {
    text-align: center;
    margin: 40px 0;
}

.load-more-btn {
    background-color: transparent;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 32px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    transition: all var(--transition-normal);
}

.load-more-btn:hover {
    border-color: var(--primary-color);
    background-color: rgba(211, 47, 47, 0.05);
    color: var(--primary-color);
}

/* ===== Footer ===== */
.main-footer {
    margin-top: 60px;
    border-top: 1px solid var(--border);
}

.footer-ad {
    background-color: var(--surface);
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.footer-ad .ad-content {
    padding: 0;
}

.footer-ad .ad-placeholder {
    max-width: 970px;
    min-height: 90px;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 30px 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.footer-links {
    margin-top: 16px;
}

.footer-links a {
    color: var(--text-secondary);
    margin: 0 8px;
}

.footer-links a:hover {
    color: var(--primary-color);
}

/* ===== Back to Top Button ===== */
.back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-medium);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all var(--transition-normal);
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    background-color: var(--primary-dark);
    transform: translateY(-3px);
}

/* ===== Responsive Design ===== */
@media (max-width: 1100px) {
    .content-wrapper {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
    }

    .news-cards {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }
}

@media (max-width: 768px) {
    :root {
        --header-height: 116px;
    }

    .nav-container {
        padding: 0 16px;
    }

    .brand-name {
        font-size: 1.3rem;
    }

    .category-btn {
        padding: 10px 16px;
        font-size: 0.9rem;
    }

    .scroll-btn {
        display: none;
    }

    .category-scroll-wrapper {
        padding: 0 16px;
    }

    .content-wrapper {
        padding: 16px;
    }

    .feed-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .feed-controls {
        width: 100%;
        justify-content: space-between;
    }

    .news-cards {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .skeleton-loader {
        grid-template-columns: 1fr;
    }

    .list-view .news-card {
        flex-direction: column;
    }

    .list-view .card-image {
        width: 100%;
        height: 180px;
    }

    .ad-content.vertical .ad-placeholder {
        writing-mode: horizontal-tb;
        height: auto;
        max-width: 100%;
    }

    .back-to-top {
        bottom: 20px;
        right: 20px;
        width: 44px;
        height: 44px;
    }
}

@media (max-width: 480px) {
    .header-ad .ad-placeholder {
        padding: 8px 16px;
        font-size: 0.8rem;
        min-height: 40px;
    }

    .ad-close {
        right: 8px;
    }

    .category-btn {
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    .card-content {
        padding: 16px;
    }

    .card-title {
        font-size: 1.05rem;
    }

    .card-description {
        font-size: 0.9rem;
    }
}