/* Base styles */
body {
    font-family: 'Roboto', sans-serif;
    line-height: 1.6;
    color: #333;
    margin: 0;
    padding: 0;
    background-color: #f5f5f5;
    font-size: 0.9rem; /* Reduced font size by 10% */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden; /* Prevent horizontal scrolling */
    width: 100%; /* Ensure body takes full width */
    box-sizing: border-box; /* Include padding in width calculation */
}

/* Apply border-box to all elements */
*, *:before, *:after {
    box-sizing: inherit;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px; /* Reduced side padding */
    width: 100%;
    box-sizing: border-box; /* Include padding in width calculation */
}

/* Adjust main container spacing */
main.container {
    margin-top: 0; /* Remove top margin to avoid interference */
}

/* Header */
header {
    background-color: #2c3e50;
    color: #fff;
    padding: 0.5rem 0;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    /* border-radius: 8px; Removed */
    margin-bottom: 1rem; /* Reduced space below header */
}

header nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    margin: 0;
    font-size: 1.8rem;
}

/* Header styles moved to .nav-links */

header a {
    color: #fff;
    text-decoration: none;
    transition: color 0.3s;
}

header a:hover {
    color: #3498db;
}

header a.active {
    color: #3498db;
    font-weight: 500;
}

/* Hero section */
#hero {
    background-color: #3498db;
    color: #fff;
    padding: 1.2rem 0 0.5rem; /* Increased bottom padding */
    text-align: center;
    border-radius: 8px;
    position: relative;
    width: 100%; /* Full width of container */
    margin-bottom: 0.5rem; /* Add space below hero */
    box-sizing: border-box;
    overflow: hidden; /* Prevent content from causing horizontal scroll */
}

/* Make hero section wider on mobile */
@media (max-width: 768px) {
    #hero {
        width: 100vw; /* Full viewport width */
        border-radius: 0; /* Remove border radius on mobile for full width */
        margin-left: calc(-50vw + 50%); /* Center and extend to full width */
        margin-right: calc(-50vw + 50%); /* Center and extend to full width */
        padding-left: 0; /* Remove padding */
        padding-right: 0; /* Remove padding */
        padding-top: 0.2rem; /* Increase vertical padding */
        padding-bottom: 0.2rem; /* Increase vertical padding */
        position: relative;
        left: 0;
        right: 0;
    }
    
    /* Center the hero content */
    .hero-container {
        width: 100%;
        padding: 0;
        text-align: center;
    }
    
    /* Adjust main container to accommodate the wider hero */
    main.container {
        overflow-x: hidden; /* Hide overflow */
        width: 100%;
        padding: 0 15px;
        position: relative;
    }
}

/* Hero container */
.hero-container {
    position: relative;
    width: 100%;
    padding: 0 20px;
}

/* Labels for both selectors */
.timezone-label, .language-label {
    margin-right: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    color: #fff;
}

/* Selector containers */
#timezone-selector, #language-selector {
    display: flex;
    align-items: center;
}

/* Dropdown styles for both selectors */
#timezone-options, #language-select {
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background-color: rgba(255, 255, 255, 0.9);
    color: #333;
    font-size: 0.85rem;
    cursor: pointer;
}

#hero h2 {
    font-size: 1.8rem; /* Slightly smaller font */
    margin-bottom: 0.2rem; /* Less bottom margin */
    margin-top: 0; /* Remove top margin */
    padding-top: 0; /* Remove top padding */
}

#hero p {
    font-size: 0.9rem; /* Smaller font */
    max-width: 800px;
    margin: 0 auto;
    line-height: 1.4; /* Tighter line height */
}

/* Responsive adjustments for hero section */
@media (max-width: 768px) {
    #hero {
        padding: 0.5rem 0;
        margin-top: 0.3rem;
    }
    
    /* Fix the conflicting positioning of timezone and language wrappers */
    .timezone-wrapper, .language-wrapper {
        position: static;
        margin: 3px auto;
        justify-content: center;
    }
    
    /* Move selectors to header instead of absolute positioning in hero */
    .selectors-row {
        width: 100%;
        justify-content: center;
        margin: 0.3rem 0;
    }
    
    /* Make hero text more compact on mobile */
    #hero h2 {
        font-size: 0.7rem; /* Further reduced font size */
        margin-bottom: 0.3rem;
        padding: 0 15px;
        /* Allow text to wrap to ensure full visibility */
        overflow: visible;
        white-space: normal; /* Allow wrapping */
        max-width: 100%;
        box-sizing: border-box;
        line-height: 1.2; /* Tighter line height */
    }
    
    #hero p {
        font-size: 0.65rem; /* Smaller font */
        padding: 0 15px;
        margin-bottom: 0.2rem;
        /* Allow text to wrap to ensure full visibility */
        overflow: visible;
        white-space: normal; /* Allow wrapping */
        max-width: 100%;
        line-height: 1.2; /* Tighter line height */
    }
}

/* Further compact hero for smaller screens */
@media (max-width: 480px) {
    #hero {
        padding: 0.4rem 0;
    }
    
    #hero h2 {
        font-size: 0.65rem; /* Further reduced font size */
        white-space: normal; /* Allow wrapping */
        overflow: visible;
        padding: 0 15px; /* Increase padding to prevent text from touching edges */
        box-sizing: border-box;
        line-height: 1.2; /* Tighter line height */
    }
    
    #hero p {
        font-size: 0.6rem; /* Smaller font */
        line-height: 1.2;
        white-space: normal; /* Allow wrapping */
        overflow: visible;
        padding: 0 15px;
    }
}

/* Articles section */
#articles {
    padding: 0; /* Remove top/bottom padding again */
    min-height: 700px; /* Minimum height to prevent shrinking */
    max-height: calc(100vh - 10rem); /* Reduced max-height by 2rem */
    overflow-y: auto;
    margin-bottom: 1rem; /* Add space below articles */
}

#articles h2 {
    text-align: center;
    margin-bottom: 1rem;
}

.articles-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
    margin-top: 1rem;
    min-height: 600px; /* Minimum height to prevent shrinking */
    width: 100%;
    box-sizing: border-box;
}

.article {
    background-color: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s, box-shadow 0.3s;
    cursor: pointer; /* Make it clear that the article is clickable */
    display: flex;
    flex-direction: column;
    height: 350px; /* Fixed height for all article boxes */
}

.article:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.article-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden; /* Hide overflow content */
    padding: 1rem;
}

.article-image {
    height: 150px; /* Fixed height */
    overflow: hidden;
    background-color: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0; /* Prevent image from shrinking */
}

.article-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}

.article:hover .article-image img {
    transform: scale(1.05);
}

/* Debug border to see if images are loading */
.article-image {
    border: 1px solid #ddd;
}

.article-text {
    padding: 1rem;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.article h3 {
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
    line-height: 1.4;
    height: 2.8rem; /* Fixed height for 2 lines */
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2; /* Limit to 2 lines */
    -webkit-box-orient: vertical;
}

.article h3 a {
    color: #2c3e50;
    text-decoration: none;
    transition: color 0.3s;
}

.article h3 a:hover {
    color: #3498db;
}

.article p {
    margin-bottom: 0.5rem;
    color: #666;
    flex-grow: 1;
}

.article .summary {
    font-size: 0.8rem;
    color: #666;
    margin-top: 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    height: 3.6rem; /* Fixed height for 3 lines */
    margin-bottom: 0.5rem; /* Consistent margin */
}

.article .date {
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 5px;
    font-style: italic;
    height: 1.2rem; /* Fixed height */
    overflow: hidden;
}

.article .source {
    font-size: 0.9rem;
    color: #666;
    margin-top: auto;
    margin-bottom: 0;
    padding: 8px 0;
    border-top: 1px solid #eee;
    font-weight: 500;
    display: flex;
    align-items: center;
    height: 2rem; /* Fixed height */
    overflow: hidden;
}

.article .source::before {
    content: "📰";
    margin-right: 5px;
    font-size: 1rem;
}

/* Placeholder image */
.placeholder-img {
    background-color: #f0f0f0;
    border: 1px solid #ddd;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 1.2rem;
}

.placeholder-img::before {
    content: "No Image";
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0; /* Remove default margin */
    gap: 0.5rem;
}

.top-pagination {
    /* Further reduce space above top pagination visually */
    margin-top: 0.5rem;
    margin-bottom: 1rem; /* Add space below top pagination */
}

.bottom-pagination {
    margin-top: 1rem;
    position: relative; /* Ensure consistent positioning */
    z-index: 10; /* Ensure it's above other elements */
    padding-top: 1rem; /* Add padding to create space */
    border-top: 1px solid #eee; /* Add a subtle separator */
}

.pagination-btn {
    background-color: #3498db;
    color: #fff;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.pagination-btn:hover {
    background-color: #2980b9;
}

.pagination-btn.disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.page-controls {
    display: flex;
    align-items: center;
    margin: 0 1rem;
}

.page-indicator {
    font-weight: bold;
    margin-right: 1rem;
}

.page-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.page-selector input {
    width: 60px;
    padding: 0.3rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    text-align: center;
    font-size: 0.9rem;
}

.page-selector button {
    padding: 0.3rem 0.6rem;
    font-size: 0.9rem;
    min-width: 40px;
}

/* Pagination responsive adjustments */
@media (max-width: 768px) {
    .pagination {
        gap: 0.4rem;
        flex-wrap: wrap;
        justify-content: center;
        overflow: visible; /* Ensure container isn't clipped */
    }
    
    .pagination-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.85rem;
        flex: 1; /* Make buttons distribute space equally */
        text-align: center; /* Center text within buttons */
    }
    
    .page-controls {
        flex-direction: column;
        gap: 0.5rem;
        margin: 0.5rem;
    }
    
    .page-indicator {
        margin-right: 0;
        font-size: 0.9rem;
    }
    
    .page-selector input {
        width: 50px;
        padding: 0.25rem;
    }
    
    .page-selector button {
        padding: 0.25rem 0.5rem;
        min-width: 35px;
    }
}

/* Further optimize pagination for very small screens */
@media (max-width: 480px) {
    .pagination {
        gap: 0.1rem; /* Reduce gap */
        margin: 1rem 0;
        justify-content: center; /* Center items */
    }
    
    .pagination-btn {
        padding: 0.35rem 0.3rem; /* Reduced horizontal padding */
        font-size: 0.8rem;
    }
    
    .page-controls {
        margin: 0.3rem;
    }
    
    .page-selector {
        gap: 0.3rem;
    }
    
    .page-selector input {
        width: 40px;
    }
    
    .page-selector button {
        padding: 0.25rem 0.4rem;
        min-width: 30px;
    }
}

/* Extreme small screen adjustments */
@media (max-width: 375px) {
    .pagination-btn {
        padding: 0.3rem 0.2rem; /* Reduced horizontal padding */
        font-size: 0.75rem;
    }
    
    .page-indicator {
        font-size: 0.8rem;
    }
    
    .page-selector input {
        width: 35px;
        font-size: 0.8rem;
    }
}

/* Footer */
footer {
    background-color: #2c3e50;
    color: #fff;
    padding: 1rem 0;
    text-align: center;
    margin-top: auto;
    width: 100%;
}

/* Loading message */
#loading-message {
    text-align: center;
    padding: 2rem;
    font-size: 1.2rem;
    color: #666;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .articles-container {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    }
    
    /* Make header more compact on mobile */
    header {
        padding: 0.3rem 0;
        margin-bottom: 0.3rem;
    }
    
    header nav {
        flex-direction: column;
        padding: 0;
    }
    
    header h1 {
        font-size: 1.4rem;
        margin-bottom: 0.3rem;
    }
    
    header ul {
        margin: 0.3rem 0;
        padding: 0;
        display: flex;
        justify-content: center;
    }
    
    header li {
        margin: 0 0.7rem;
    }
    
    /* Make hero section more compact */
    #hero {
        padding: 0.7rem 0;
        margin-top: 0.3rem;
    }
    
    #hero h2 {
        font-size: 1.4rem;
        margin-bottom: 0.3rem;
    }
}

/* Additional header optimizations for smaller screens */
@media (max-width: 480px) {
    header h1 {
        font-size: 1.2rem;
    }
    
    header li {
        margin: 0 0.5rem;
    }
    
    header a {
        font-size: 0.85rem;
    }
    
    .selectors-row {
        margin: 0.3rem 0;
        gap: 8px;
    }
}

/* Mobile article card improvements */
@media (max-width: 480px) {
    .articles-container {
        grid-template-columns: 1fr;
        gap: 1.5rem;
        margin-top: 1.5rem;
    }
    
    /* Optimize article card spacing */
    .article {
        height: 320px; /* Fixed height for mobile */
    }
    
    .article-image {
        height: 140px; /* Slightly smaller image height */
    }
    
    .article-text {
        padding: 0.8rem;
    }
    
    .article h3 {
        font-size: 1rem;
        line-height: 1.3;
        margin-bottom: 0.4rem;
        /* Prevent text overflow */
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2; /* Limit to 2 lines */
        -webkit-box-orient: vertical;
    }
    
    .article .date {
        font-size: 0.75rem;
        margin-bottom: 0.3rem;
    }
    
    .article p {
        font-size: 0.85rem;
        margin-bottom: 0.4rem;
        /* Prevent text overflow */
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 3; /* Limit to 3 lines */
        -webkit-box-orient: vertical;
    }
    
    .article .source {
        font-size: 0.8rem;
        padding: 6px 0;
    }
    
    .article .source::before {
        font-size: 0.9rem;
    }
}

/* Very small screen article optimizations */
@media (max-width: 375px) {
    .articles-container {
        gap: 1.2rem;
    }
    
    .article {
        height: 300px; /* Fixed height for very small screens */
    }
    
    .article-image {
        height: 130px;
    }
    
    .article-text {
        padding: 0.7rem;
    }
    
    .article h3 {
        font-size: 0.95rem;
        -webkit-line-clamp: 2;
    }
    
    .article p {
        font-size: 0.8rem;
        -webkit-line-clamp: 2;
    }
}


/* Current timezone display (hidden by default) */
#current-timezone {
    font-weight: bold;
    font-size: 0.9rem;
    display: none;
}

/* Container for right-aligned nav items */
.nav-right {
    display: flex;
    align-items: center;
    gap: 20px; /* Space between nav links and selectors */
}

/* Navigation links container */
.nav-links ul {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-links li {
    margin-left: 1.5rem;
}

/* Selectors row in header */
.selectors-row {
    display: flex;
    align-items: center;
    gap: 15px; /* Space between selectors */
}

/* Selectors in header */
.timezone-wrapper, .language-wrapper {
    display: flex;
    align-items: center;
}

/* Labels for selectors */
.timezone-label, .language-label {
    margin-right: 8px;
    font-size: 0.9rem; /* Match navigation links */
    color: #fff;
}

/* Selector dropdowns */
#timezone-options, #language-select {
    padding: 2px 5px;
    border-radius: 3px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background-color: rgba(255, 255, 255, 0.9);
    color: #333;
    font-size: 0.85rem; /* Match navigation links */
    cursor: pointer;
}

/* Responsive adjustments for nav */
@media (max-width: 768px) {
    /* Improve header layout */
    header {
        padding: 0.3rem 0;
        width: 100%;
        overflow: hidden; /* Prevent horizontal scrolling */
    }
    
    header h1 {
        font-size: 1.3rem;
        text-align: center;
        width: 100%;
        margin-bottom: 0.3rem;
    }
    
    header nav {
        padding: 0 5px; /* Reduced padding */
        width: 100%;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    .nav-right {
        flex-direction: column;
        align-items: center;
        width: 100%;
        gap: 5px;
    }
    
    .nav-links {
        width: 100%;
        margin-bottom: 0.2rem;
        text-align: center;
    }
    
    .nav-links ul {
        margin: 0.2rem 0;
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.3rem;
        padding: 0;
    }
    
    .nav-links li {
        margin: 0 0.4rem;
    }
    
    .selectors-row {
        margin-top: 0.2rem;
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
        width: 100%;
    }
    
    /* Ensure timezone and language selectors are aligned */
    .timezone-wrapper, .language-wrapper {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 28px; /* Fixed height for alignment */
    }
    
    /* Make selectors more compact */
    .timezone-label, .language-label {
        font-size: 0.75rem;
        margin-right: 4px;
    }
    
    #timezone-options, #language-select {
        max-width: 110px;
        font-size: 0.75rem;
        padding: 1px 3px;
    }
}

/* Additional adjustments for very small screens */
@media (max-width: 375px) {
    header h1 {
        font-size: 1.1rem;
        margin-bottom: 0.2rem;
    }
    
    .nav-links li {
        margin: 0 0.2rem;
    }
    
    .nav-links a {
        font-size: 0.8rem;
    }
    
    .timezone-label, .language-label {
        font-size: 0.7rem;
    }
    
    #timezone-options, #language-select {
        max-width: 90px;
        font-size: 0.7rem;
    }
    
    /* Abbreviate labels on very small screens */
    .timezone-label::after {
        content: "TZ:";
    }
    
    .timezone-label span {
        display: none;
    }
    
    .language-label::after {
        content: "Lang:";
    }
    
    .language-label span {
        display: none;
    }
}

/* Translation Progress Popup */
.translation-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(52, 152, 219, 0.9);
    color: white;
    padding: 15px 25px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    text-align: center;
    font-size: 1.1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    animation: fadeIn 0.3s ease-out;
}

/* Translation Error Notification */
.translation-error-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(231, 76, 60, 0.9); /* Red background */
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    text-align: center;
    font-size: 0.9rem;
    max-width: 90%;
    animation: fadeIn 0.3s ease-out, fadeOut 0.3s ease-in 4.7s;
}

.translation-popup .spinner {
    display: inline-block;
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Additional Mobile Optimizations */
@media (max-width: 768px) {
    /* Improve touch targets */
    button,
    select,
    input[type="number"],
    .nav-links a {
        min-height: 36px; /* Minimum touch target size */
    }
    
    /* Prevent text from being too small */
    body {
        font-size: 16px; /* Base font size for better readability */
        -webkit-text-size-adjust: 100%; /* Prevent iOS from auto-adjusting text size */
    }
    
    /* Improve spacing */
    main.container {
        padding: 0 15px;
    }
    
    /* Ensure footer stays at bottom */
    body {
        min-height: 100vh;
        display: flex;
        flex-direction: column;
    }
    
    main {
        flex: 1;
    }
}

/* Fix for very small screens */
@media (max-width: 320px) {
    /* Ultra compact header */
    header {
        padding: 0.2rem 0;
        margin-bottom: 0.2rem;
    }
    
    header h1 {
        font-size: 1rem;
        margin-bottom: 0.1rem;
    }
    
    .nav-links ul {
        margin: 0.1rem 0;
    }
    
    .nav-links li {
        margin: 0 0.15rem;
    }
    
    .nav-links a {
        font-size: 0.75rem;
    }
    
    .selectors-row {
        margin: 0.1rem 0;
        gap: 5px;
    }
    
    /* Ensure timezone and language selectors are aligned and compact */
    .timezone-wrapper, .language-wrapper {
        height: 24px; /* Smaller fixed height for alignment */
    }
    
    #timezone-options, #language-select {
        max-width: 80px; /* Limit width to prevent overflow */
        font-size: 0.7rem;
    }
    
    /* Ultra compact hero */
    #hero {
        padding: 0.3rem 0;
    }
    
    #hero h2 {
        font-size: 0.6rem; /* Further reduced font size */
        margin-bottom: 0.1rem;
        white-space: normal; /* Allow wrapping */
        overflow: visible;
        max-width: 100%;
        padding: 0 15px; /* Increase padding to prevent text from touching edges */
        box-sizing: border-box;
        line-height: 1.1; /* Even tighter line height */
    }
    
    #hero p {
        font-size: 0.55rem; /* Smaller font */
        line-height: 1.1;
        white-space: normal; /* Allow wrapping */
        overflow: visible;
        max-width: 100%;
        padding: 0 15px;
    }
    
    /* Other small screen adjustments */
    .article {
        height: 280px; /* Fixed height for the smallest screens */
    }
    
    .article h3 {
        font-size: 0.9rem;
    }
    
    .pagination-btn {
        padding: 0.25rem 0.4rem;
        font-size: 0.7rem;
    }
    
    /* Ensure container doesn't cause horizontal scroll */
    .container {
        padding: 0 10px; /* Further reduce padding */
    }
    
    /* Ensure articles container doesn't cause horizontal scroll */
    .articles-container {
        gap: 1rem; /* Reduce gap to prevent overflow */
    }
}
