/* Universal Box-Sizing for better layout control */
*, *::before, *::after {
    box-sizing: border-box;
}

/* Base body styles to prevent overflow */
body {
    overflow-x: hidden; /* Prevent horizontal scroll */
    margin: 0;
    padding: 0;
    font-family: 'Inter', Arial, sans-serif;
    background-color: #f8fafc;
}

/* Container for the entire plugin */
#remote-job-finder {
    max-width: 1200px;
    margin: 30px auto; /* Increased margin for better spacing */
    padding: 30px; /* Increased padding */
    background-color: #f8fafc; /* Lighter background */
    border-radius: 16px; /* More rounded corners */
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08); /* Softer, more prominent shadow */
    color: #333;
}

/* Search form styling */
.job-search-form {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 40px; /* Increased margin */
    align-items: center;
    justify-content: center;
    background-color: #ffffff;
    padding: 25px; /* Increased padding */
    border-radius: 12px; /* More rounded */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08); /* Softer shadow */
}

.job-search-form input[type="text"],
.job-search-form input[type="number"] {
    flex: 1 1 220px; /* Allows inputs to grow/shrink, with a base width */
    padding: 14px 18px; /* Larger input padding */
    border: 1px solid #e2e8f0; /* Lighter border color */
    border-radius: 10px; /* More rounded */
    font-size: 16px;
    outline: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.job-search-form input[type="text"]:focus,
.job-search-form input[type="number"]:focus {
    border-color: #3b82f6; /* Blue focus border - overridden by customizer */
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2); /* Blue glow on focus - overridden by customizer */
}

.job-search-form button {
    padding: 14px 30px; /* Larger button padding */
    background-color: #2563eb; /* Stronger blue - overridden by customizer */
    color: white; /* Overridden by customizer */
    border: none;
    border-radius: 10px; /* More rounded */
    cursor: pointer;
    font-size: 17px; /* Slightly larger font */
    font-weight: bold;
    flex-shrink: 0;
    transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
    box-shadow: 0 6px 15px rgba(37, 99, 235, 0.3); /* Stronger shadow - overridden by customizer */
}

.job-search-form button:hover {
    background-color: #1d4ed8; /* Darker blue on hover - overridden by customizer */
    transform: translateY(-3px); /* More pronounced lift */
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.4); /* Overridden by customizer */
}

/* Loading spinner */
.job-loading-spinner {
    display: none;
    width: 60px;
    height: 60px;
    border: 6px solid #e2e8f0; /* Lighter spinner base */
    border-top: 6px solid #3b82f6; /* Blue spinner color - could be overridden by customizer if desired */
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 50px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Job card display */
#job-listings {
    display: flex;
    flex-direction: column;
    gap: 20px; /* Increased gap between cards */
    margin-top: 30px;
}

.job-card {
    background-color: #ffffff;
    border: 1px solid #f0f0f0; /* Lighter border */
    border-radius: 12px; /* More rounded */
    padding: 20px 25px; /* Increased padding */
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08); /* More prominent shadow */
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    justify-content: space-between;
    align-items: center; /* Center items vertically */
    cursor: pointer;
    position: relative;
    width: 100%;
    /* Ensure no horizontal overflow */
    overflow: hidden;
}

.job-card:hover {
    transform: translateY(-6px); /* More pronounced lift */
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12); /* Stronger hover shadow */
}

.job-card-main-content {
    display: flex;
    align-items: center; /* Center avatar and text info vertically */
    flex-grow: 1;
}

.company-avatar {
    width: 52px; /* Slightly larger avatar */
    height: 52px;
    border-radius: 50%;
    background-color: #f0f4f8; /* Softer background color */
    color: #4a5568; /* Darker text for initials */
    border: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1em; /* Larger font for 2 letters */
    font-weight: 700; /* Bolder font */
    margin-right: 20px; /* More spacing */
    flex-shrink: 0;
    overflow: hidden;
}

.company-avatar img.company-logo {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 50%;
}

.job-text-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    /* Added min-width to prevent content shrinking too much on smaller screens */
    min-width: 0; 
}

.job-card .job-title-link {
    margin: 0;
    font-size: 1.3em; /* Slightly larger title */
    font-weight: 800;
    line-height: 1.3;
    color: #1a202c; /* Darker title color */
    text-decoration: none;
    display: block;
    /* Ensure title can wrap if long */
    word-wrap: break-word; 
    overflow-wrap: break-word;
}

.job-card .job-title-link:hover {
    text-decoration: underline;
    color: #2563eb; /* Blue on hover - overridden by customizer */
}

.job-card .company-name {
    font-size: 1em; /* Slightly larger company name */
    color: #4a5568; /* Darker grey */
    margin-top: 4px; /* Adjusted spacing */
    margin-bottom: 0;
    line-height: 1.5;
    display: block;
}

.job-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 10px; /* Increased gap */
    margin-top: 15px; /* More spacing */
}

.job-location-badge,
.job-salary-badge {
    background-color: #edf2f7; /* Very light background */
    border: 1px solid #cbd5e0; /* Subtle border */
    border-radius: 6px; /* Slightly more rounded */
    padding: 6px 12px; /* Larger padding */
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #4a5568;
    font-size: 0.85em; /* Slightly larger font */
    font-weight: 500;
    white-space: nowrap; /* Prevent badge text from wrapping */
}

.job-location-badge i,
.job-salary-badge i {
    color: #64748b; /* Darker icon color */
}

.job-card-right-section {
    display: flex;
    flex-direction: row;
    align-items: center; /* Vertically center tags and time */
    gap: 20px; /* Increased gap */
    flex-shrink: 0;
    margin-left: auto;
}

.job-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px; /* Increased gap */
    justify-content: flex-end;
    margin-top: 0; /* Align with avatar/title top */
    /* Ensure tags don't overflow */
    max-width: 150px; /* Give tags a max width on desktop */
    justify-content: flex-end; /* Align tags to the right within their space */
}

/* Default tag styling */
.job-tag {
    background-color: #f0f4f8; /* Light default background for tags */
    border: 1px solid #cbd5e0; /* Border for tags */
    color: #4a5568; /* Darker tag text */
    padding: 5px 12px; /* Larger padding */
    border-radius: 18px; /* More pill-shaped */
    font-size: 0.8em;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden; /* Hide overflow if tag text is too long */
    text-overflow: ellipsis; /* Add ellipsis for long tag text */
    flex-shrink: 0; /* Prevent tags from shrinking */
    transition: background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

/* Dynamic Tag Colors - These classes will be added by JavaScript */
.tag-color-0 { background-color: #ffe0b2; color: #e65100; border-color: #ffcc80; } /* Orange Light */
.tag-color-1 { background-color: #c8e6c9; color: #2e7d32; border-color: #a5d6a7; } /* Green Light */
.tag-color-2 { background-color: #bbdefb; color: #1976d2; border-color: #90caf9; } /* Blue Light */
.tag-color-3 { background-color: #e1bee7; color: #8e24aa; border-color: #ce93d8; } /* Purple Light */
.tag-color-4 { background-color: #ffcdd2; color: #d32f2f; border-color: #ef9a9a; } /* Red Light */
.tag-color-5 { background-color: #e0f2f7; color: #00838f; border-color: #b2ebf2; } /* Cyan Light */
.tag-color-6 { background-color: #f8bbd0; color: #ad1457; border-color: #f48fb1; } /* Pink Light */
.tag-color-7 { background-color: #fff9c4; color: #c0ca33; border-color: #fff59d; } /* Lime Light */


.job-post-time {
    font-size: 0.85em; /* Slightly larger font */
    color: #718096; /* Darker grey */
    white-space: nowrap;
    margin-top: 0; /* Align with other elements */
    flex-shrink: 0; /* Prevent time from shrinking */
}

/* Load More Button */
#load-more-jobs-btn {
    display: block;
    margin: 40px auto 30px auto; /* More spacing */
    padding: 15px 35px; /* Larger button */
    background-color: #2563eb; /* Overridden by customizer */
    color: white; /* Overridden by customizer */
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
    box-shadow: 0 6px 15px rgba(37, 99, 235, 0.3); /* Overridden by customizer */
}

#load-more-jobs-btn:hover {
    background-color: #1d4ed8; /* Overridden by customizer */
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.4); /* Overridden by customizer */
}

/* No results message */
.no-results {
    text-align: center;
    font-size: 1.2em; /* Slightly larger */
    color: #666;
    margin-top: 60px; /* More spacing */
}

/* --- Modal Styles --- */
/* Increased specificity and !important to ensure modal is hidden by default */
body #job-details-modal.modal {
    display: none !important; /* Hidden by default, takes precedence */
    position: fixed; /* Stay in place */
    z-index: 1000; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: hidden; /* Prevent page scroll when modal is open */
    background-color: rgba(0,0,0,0.6); /* Black w/ opacity */
    justify-content: center;
    align-items: center;
    padding: 10px;
    box-sizing: border-box;
}

/* When modal is open, ensure it displays flex */
body.modal-open #job-details-modal.modal {
    display: flex !important;
}


.modal-content {
    background-color: #fefefe;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    position: relative;
    transform: scale(0.95);
    opacity: 0;
    animation: openModal 0.3s forwards cubic-bezier(0.2, 0.8, 0.2, 1);

    /* Desktop styles for modal-content */
    width: 90%;
    max-width: 1000px; /* Max width for desktop modal */
    height: 80vh; /* Fixed height for desktop */
    max-height: 800px;
    display: flex; /* Use flex for desktop partitions */
    flex-direction: column;
    overflow: hidden; /* Content inside handles its own scroll */
    padding: 20px 30px 30px 30px; /* Adjust padding: top, right, bottom, left */
}

/* Desktop Modal Header (Logo + Apply Button) */
.modal-header-desktop {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-right: 70px; /* Increased space for the close button */
    padding-top: 10px; /* Space from the top of the modal */
    padding-left: 10px; /* Added left padding */
}

.modal-company-logo-desktop-container {
    height: 60px; /* Fixed height for logo container */
    width: 150px; /* Fixed width for consistent spacing */
    display: flex;
    align-items: center;
    justify-content: flex-start;
    background-color: #fff; /* Background for placeholder text visibility */
    border-radius: 8px;
    overflow: hidden; /* Hide overflow if logo is too big */
}

.modal-company-logo {
    max-height: 100%;
    max-width: 100%; /* Allow logo to take full width of container */
    object-fit: contain;
    border-radius: 8px; /* Slightly rounded corners for logos */
}


.modal-desktop-layout {
    display: flex;
    flex-grow: 1; /* Allow to take remaining height */
    overflow: hidden; /* Control content overflow within this flex item */
}

.modal-details-pane {
    flex: 0 0 35%; /* Fixed width for details on desktop */
    padding-right: 20px;
    border-right: 1px solid #eee;
    overflow-y: auto; /* Make details pane scrollable if content overflows */
    padding-bottom: 20px; /* Add padding for scrollable content */
    /* Add some visual styling */
    background-color: #fcfcfc;
    border-radius: 8px;
    padding-top: 10px;
    padding-left: 10px; /* Added left padding */
}

.modal-description-pane {
    flex: 1; /* Take remaining space */
    padding-left: 20px;
    overflow-y: auto; /* Make description pane scrollable */
    padding-bottom: 20px; /* Add padding for scrollable content */
    /* Add some visual styling */
    padding-top: 10px;
}

.modal .apply-button {
    display: inline-block;
    background-color: #2563eb; /* Overridden by customizer */
    color: white; /* Overridden by customizer */
    padding: 10px 20px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: bold;
    transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
    box-shadow: 0 4px 8px rgba(37, 99, 235, 0.2); /* Overridden by customizer */
    margin-top: 0; /* Reset margin from general button style */
}

.modal .apply-button:hover {
    background-color: #1d4ed8; /* Overridden by customizer */
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(37, 99, 235, 0.3); /* Overridden by customizer */
}

.modal-mobile-layout {
    display: none; /* Hidden on desktop */
}

@keyframes openModal {
    from {
        transform: scale(0.95);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal .close-button {
    color: #aaa;
    position: absolute; /* Changed to absolute for desktop */
    top: 15px;
    right: 20px;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s ease;
    z-index: 10; /* Ensure it's above other content */
    background-color: rgba(255,255,255,0.7); /* Slightly visible background for tap target */
    border-radius: 50%;
    width: 40px; /* Make it a clear circular target */
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.modal .close-button:hover,
.modal .close-button:focus {
    color: #333;
    text-decoration: none;
    background-color: rgba(255,255,255,0.9);
}

.modal h2 {
    font-size: 1.8em; /* Slightly smaller for modal */
    color: #1a202c;
    margin-top: 0;
    margin-bottom: 10px;
    line-height: 1.2;
}

.modal p {
    margin-bottom: 8px; /* Reduced margin */
    color: #4a5568;
    line-height: 1.5;
}

.modal #modal-job-company {
    font-weight: bold;
    color: #1a202c;
    font-size: 1.05em;
    margin-bottom: 15px;
}

/* Stylish Country Info in Modal */
.modal #modal-job-location,
.modal #modal-job-location-mobile {
    font-weight: 600; /* Make it bolder */
    color: #3b82f6; /* Use a blue color */
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px; /* Space between icon and text */
}

.modal #modal-job-location i,
.modal #modal-job-location-mobile i {
    color: #3b82f6; /* Blue icon color */
    font-size: 1.1em;
}


.modal #modal-job-salary {
    font-style: italic;
    color: #64748b;
    margin-bottom: 15px;
}
.modal #modal-job-source {
    font-size: 0.9em;
    color: #718096;
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px dashed #eee;
}


.modal #modal-job-description {
    color: #4a5568;
    font-size: 0.95em;
    line-height: 1.7;
    padding-top: 15px; /* Added padding to top of description */
}

/* Ensure images within description are responsive */
.modal #modal-job-description img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 10px 0;
}

/* Prevent body scrolling when modal is open */
body.modal-open {
    overflow: hidden;
}


/* Responsive adjustments */
@media (max-width: 768px) {
    #remote-job-finder {
        padding: 10px; /* Reduced padding for very small screens */
        margin: 10px auto;
    }
    .job-search-form {
        flex-direction: column;
        align-items: stretch;
        padding: 15px;
        gap: 10px;
    }
    .job-search-form input { /* Target inputs specifically */
        width: 100%;
        flex: auto;
        padding: 8px 10px; /* Further reduced padding for mobile inputs */
        font-size: 13px; /* Further reduced font size */
        max-height: 50px;
    }
    .job-search-form button {
        width: 100%;
        flex: auto;
        padding: 10px 15px; /* Further reduced padding for mobile button */
        font-size: 15px; /* Further reduced font size */
    }
    #job-listings {
        gap: 15px;
    }
    .job-card {
        flex-direction: column; /* Stack elements on small screens */
        align-items: flex-start;
        padding: 15px;
    }
    .job-card-main-content {
        width: 100%; /* Take full width on mobile */
        margin-bottom: 15px; /* Space between main content and right section */
        /* Ensure content doesn't overflow horizontally within the card */
        flex-wrap: wrap; /* Allow avatar and text info to wrap if needed */
    }
    .job-text-info {
        min-width: unset; /* Remove min-width for mobile */
        width: calc(100% - 68px); /* Give remaining space to text info, account for avatar width + margin */
    }
    .company-avatar {
        width: 48px; /* Slightly adjusted avatar size */
        height: 48px;
        margin-right: 15px;
    }
    .job-card .job-title-link {
        font-size: 1.1em; /* Smaller title font for mobile */
        line-height: 1.3;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    .job-card .company-name {
        font-size: 0.85em; /* Smaller company name font for mobile */
        margin-top: 3px;
    }
    .job-badges {
        margin-top: 10px;
        gap: 8px;
        width: 100%; /* Take full width on mobile */
        justify-content: flex-start;
    }
    .job-location-badge, .job-salary-badge {
        padding: 4px 8px;
        font-size: 0.7em;
    }

    .job-card-right-section {
        flex-direction: column; /* Stack tags and time */
        align-items: flex-start; /* Align tags and time to left */
        width: 100%;
        margin-left: 0;
        margin-top: 15px; /* Added space to separate from main content */
        border-top: 1px solid #eee; /* Visual separation */
        padding-top: 15px;
    }
    .job-card-tags {
        justify-content: flex-start; /* Align tags to left on mobile */
        margin-top: 0;
        max-width: 100%; /* Tags can use full width */
    }
    .job-tag {
        font-size: 0.7em; /* Smaller tag font for mobile */
        padding: 4px 10px;
        border-radius: 15px;
    }
    .job-post-time {
        align-self: flex-start; /* Align time to left on mobile */
        margin-top: 10px; /* Space above time */
        font-size: 0.75em;
    }

    /* Modal Mobile Specific Styles */
    .modal-content {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0; /* No rounded corners on full-screen mobile modal */
        padding: 15px; /* Adjusted padding for mobile modal content */
        flex-direction: column; /* Stack content vertically */
        overflow-y: auto; /* Make entire modal content scrollable */
    }

    .modal .close-button {
        position: sticky; /* Make sticky on mobile */
        top: 0; /* Stick to the top of the scrollable content */
        right: 0; /* Stick to the right */
        float: right; /* Position it to the right within the flow of content */
        font-size: 28px; /* Slightly smaller for mobile */
        padding: 5px; /* Added padding to make it easier to tap */
        background-color: rgba(255,255,255,0.9); /* More opaque background */
        border-radius: 50%;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 5px rgba(0,0,0,0.2);
        z-index: 100; /* Ensure it's always on top */
        /* Adjust margin to pull it into the corner of the scrollable area and provide space */
        margin: -5px -5px 10px auto; /* Fine-tuned margin for mobile sticky button */
    }
    
    .modal-header-desktop {
        display: none; /* Hide desktop header elements on mobile */
    }

    .modal-apply-link-top-container {
        display: none; /* Hide desktop apply link container */
    }

    .modal-desktop-layout {
        display: none; /* Hide desktop two-pane layout */
    }

    .modal-mobile-layout {
        display: flex; /* Show mobile layout */
        flex-direction: column;
        flex-grow: 1;
        width: 100%;
        padding-top: 0; /* Content flows after sticky close button */
        padding-bottom: 0;
    }

    .modal-company-logo-mobile-container {
        height: 60px; /* Fixed height for logo container */
        width: 100%; /* Take full width on mobile */
        display: flex;
        align-items: center;
        justify-content: center; /* Center the logo */
        margin-bottom: 15px; /* Space below the logo */
        background-color: #fff; /* Background for placeholder text visibility */
        border-radius: 8px;
        overflow: hidden;
    }

    .modal #modal-job-title-mobile {
        font-size: 1.4em; /* Adjusted for mobile */
        margin-bottom: 8px;
    }

    .modal #modal-job-company-mobile {
        font-size: 0.95em;
        margin-bottom: 10px;
    }
    .modal #modal-job-location-mobile,
    .modal #modal-job-salary-mobile,
    .modal #modal-job-source-mobile {
        font-size: 0.85em;
        margin-bottom: 5px;
    }

    .modal #modal-job-apply-link-mobile-top {
        width: 100%;
        text-align: center;
        margin-top: 15px; /* Space after job details */
        margin-bottom: 20px;
        padding: 12px 20px;
        font-size: 1em;
    }

    .modal #modal-job-description-mobile {
        margin-top: 15px;
        padding-top: 15px;
        border-top: 1px solid #eee;
        flex-grow: 1; /* Allow description to take available space */
        overflow: visible; /* Content overflow handled by modal-content */
        -webkit-overflow-scrolling: touch; /* Smooth scrolling for iOS */
    }

    .modal #modal-job-apply-link-mobile-bottom {
        width: 100%;
        text-align: center;
        margin-top: 25px; /* More space before bottom apply button */
        padding: 12px 20px;
        font-size: 1em;
        flex-shrink: 0; /* Prevent it from shrinking */
    }

    body.modal-open {
        overflow: hidden; /* Ensure page behind modal doesn't scroll */
    }
}
