/* General Body & Typography */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 20px;
    background-color: #f4f7f9; /* Light gray background */
    color: #333; /* Darker text for readability */
    line-height: 1.6;
    direction: rtl; /* Ensuring RTL is set */
}

.container {
    max-width: 700px; /* Slightly wider for better spacing on larger screens */
    margin: 20px auto;
    background-color: #ffffff;
    padding: 20px 30px;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

/* Headings */
h1, h2, h3, h4 {
    color: #2c3e50; /* Dark blue-gray for headings */
    margin-top: 25px;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0e6ed; /* Lighter, softer border */
}
h1#main-title {
    text-align: center;
    border-bottom: none;
    color: #3B82F6; /* Accent color for main title */
    font-size: 2.2em;
    margin-bottom: 15px;
}
h2 { /* Section titles */
    font-size: 1.6em;
    color: #333;
}

/* Progress Indicator */
#progress-indicator {
    text-align: center;
    margin-bottom: 30px;
    font-size: 1em;
    font-weight: 500;
    color: #555;
    background-color: #e9ecef;
    padding: 10px;
    border-radius: 6px;
}

/* Form Sections */
.form-section {
    display: none;
    padding: 25px;
    border: 1px solid #dce4ec; /* Softer border */
    border-radius: 8px;
    margin-bottom: 25px;
    background-color: #fdfdfd; /* Slightly off-white section background */
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}
.form-section.active-section {
    display: block;
}

/* Labels */
label {
    display: block;
    margin-top: 18px;
    margin-bottom: 6px;
    font-weight: 600; /* Bolder labels */
    font-size: 0.95em;
    color: #34495e; /* Slightly desaturated blue */
}
label.inline-label {
    display: inline-block;
    margin-left: 8px; /* Adjusted for RTL */
    margin-right: 0;
    font-weight: normal;
    vertical-align: middle;
}

/* Input Fields, Selects, Textareas */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="date"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 12px 15px; /* Increased padding */
    margin-top: 4px;
    border: 1px solid #ced4da; /* Standard border color */
    border-radius: 6px;
    box-sizing: border-box;
    background-color: #ffffff;
    color: #495057; /* Input text color */
    font-size: 1em;
    transition: border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}
input[type="text"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="date"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
    border-color: #3B82F6; /* Accent color on focus */
    box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.25); /* Focus glow */
    outline: none;
}

input[type="checkbox"] {
    margin-left: 8px; /* Adjusted for RTL */
    margin-right: 0;
    vertical-align: middle;
    width: auto;
    height: 1.1em;
    width: 1.1em;
    accent-color: #3B82F6; /* Modern way to color checkboxes */
}

select[multiple] {
    height: 150px; /* More space for multi-select */
}

small {
    display: block;
    font-size: 0.85em;
    color: #6c757d; /* Softer hint text color */
    margin-top: 5px;
}

.required {
    color: #e74c3c; /* Clearer red for required */
    margin-right: 3px; /* Adjusted for RTL */
    margin-left: 0;
    font-weight: bold;
}

/* Navigation Buttons */
.navigation-buttons {
    display: flex;
    justify-content: space-between;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #e0e6ed;
}

.navigation-buttons button {
    padding: 12px 25px; /* Generous padding */
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.05em;
    font-weight: 600;
    transition: background-color 0.2s ease, transform 0.1s ease;
}
.navigation-buttons button:hover {
    transform: translateY(-2px);
}
.navigation-buttons button:active {
    transform: translateY(0);
}

#prevBtn {
    background-color: #6c757d; /* Gray for previous */
    color: #ffffff;
}
#prevBtn:hover {
    background-color: #5a6268;
}

#nextBtn {
    background-color: #3B82F6; /* Accent blue for next */
    color: #ffffff;
}
#nextBtn:hover {
    background-color: #2563EB; /* Darker blue on hover */
}

/* Additional Questions & Declaration Styling */
.additional-question {
    margin-bottom: 20px;
    padding: 15px;
    background-color: #f8f9fa; /* Light background for these sections */
    border: 1px solid #e9ecef;
    border-radius: 6px;
}
.additional-question textarea {
    width: 100%;
    margin-top: 8px;
}

.declaration {
    margin-top: 25px;
    padding: 15px;
    background-color: #e9f5ff; /* Light blueish background for declaration */
    border: 1px solid #bde0fe;
    border-radius: 6px;
    font-size: 0.9em;
}
.declaration input[type="checkbox"] {
    float: right;
    margin-left: 8px;
    margin-top: 4px;
}
.declaration label {
    font-weight: normal;
    color: #212529;
}
#applicantFullNameDisplay {
    font-weight: bold;
    color: #0056b3;
}

/* Custom Select Arrow (RTL aware) */
select:not([multiple]) {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%2334495e%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E');
    background-repeat: no-repeat;
    background-position: left 15px top 50%; /* Adjusted for RTL */
    background-size: 10px auto;
    padding-left: 40px; /* Make space for arrow on the left for RTL */
    padding-right: 15px;
}

/* Hide number input spinners */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type=number] {
  -moz-appearance: textfield; /* Firefox */
}

/* Specific field notes and adjustments */
#journey_date_page0 + small { /* For date constraint hints */
    background-color: #fffbe6; /* Light yellow background for important notes */
    padding: 5px 8px;
    border-radius: 4px;
    border: 1px solid #ffe58f;
    color: #8a6d3b;
}
#passport_expiry_date + small {
     background-color: #fffbe6;
    padding: 5px 8px;
    border-radius: 4px;
    border: 1px solid #ffe58f;
    color: #8a6d3b;
}

/* AI Help Icon (dynamically added by JS) */
.ai-help-icon {
    cursor: pointer;
    margin-left: 8px; /* For RTL, icon is to the left of label text */
    margin-right: 0px;
    font-size: 0.8em;
    color: #3B82F6; /* Accent color */
    font-weight: bold;
    border: 1px solid #3B82F6;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
    vertical-align: middle; /* Align with label text */
}
.ai-help-icon:hover {
    background-color: #3B82F6;
    color: white;
}

/* --- ENHANCED AI Help Modal Styles --- */

.ai-modal {
    display: none; /* MODIFIED: Ensures it's hidden by default */
    position: fixed; 
    z-index: 1000; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    /* overflow: auto; */ /* Flex centering handles overflow better if modal content itself scrolls */
    background-color: rgba(44, 62, 80, 0.65); 
    direction: rtl;
    /* Flexbox for centering will be applied via .visible class */
    padding: 20px; 
    box-sizing: border-box;
}

/* NEW CLASS: To make the modal visible and apply flex for centering */
.ai-modal.visible {
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-modal-content {
    background-color: #ffffff; 
    padding: 0; 
    border: none; 
    width: 100%; 
    max-width: 550px; 
    border-radius: 10px; 
    box-shadow: 0 10px 35px rgba(0, 0, 0, 0.2); 
    position: relative;
    text-align: right;
    overflow: hidden; 
    display: flex; 
    flex-direction: column;
    max-height: 90vh; /* Ensure modal doesn't exceed viewport height */
}

.ai-modal-header {
    background-color: #3B82F6; 
    color: #ffffff;
    padding: 18px 25px; 
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; 
}

#aiModalTitle {
    margin: 0;
    color: #ffffff; 
    font-size: 1.35em; 
    font-weight: 600;
    line-height: 1.3;
    border-bottom: none; 
    padding-bottom: 0; 
}

.ai-modal-close {
    color: #ffffff;
    opacity: 0.8;
    font-size: 24px; 
    font-weight: normal; 
    line-height: 1;
    background: none;
    border: none;
    padding: 5px; 
    cursor: pointer;
    transition: opacity 0.2s ease;
    margin-right: -10px; 
}
.ai-modal-close:hover {
    opacity: 1;
}

.ai-modal-body {
    padding: 20px 25px 25px; 
    overflow-y: auto; /* Allows body to scroll if content is too long */
    flex-grow: 1; 
}

#aiModalStaticContext {
    margin-bottom: 20px; 
    font-size: 0.9em; 
    color: #454f5b; 
    background-color: #f7f9fa; 
    padding: 12px 18px;
    border-radius: 6px;
    border: 1px solid #e6eaf0; 
    line-height: 1.6;
}
#aiModalStaticContext strong { 
    color: #3B82F6;
    font-weight: 600;
}

.ai-modal-label { 
    display: block;
    margin-top: 0; 
    margin-bottom: 10px; 
    font-weight: 600;
    font-size: 1em; 
    color: #34495e; 
}

.ai-modal-textarea,
textarea#aiFieldSpecificQuestion { 
    width: 100%;
    padding: 12px 15px; 
    margin-top: 0; 
    margin-bottom: 20px; 
    border: 1px solid #ced4da; 
    border-radius: 6px;
    box-sizing: border-box;
    font-size: 1em; 
    line-height: 1.6; 
    resize: vertical; 
    min-height: 80px; 
}
.ai-modal-textarea:focus,
textarea#aiFieldSpecificQuestion:focus { 
    border-color: #3B82F6;
    box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.25);
    outline: none;
}

.ai-modal-button,
button#askAiFieldSpecificBtn { 
    background-color: #3B82F6; 
    color: #ffffff;
    padding: 12px 20px; 
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.05em; 
    font-weight: 600; 
    width: 100%;
    margin-top: 0; 
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px; 
    transition: background-color 0.2s ease, transform 0.1s ease;
}
.ai-modal-button:hover,
button#askAiFieldSpecificBtn:hover {
    background-color: #2563EB; 
    transform: translateY(-1px); 
}
.ai-modal-button .spinner,
button#askAiFieldSpecificBtn .spinner {
    border-left-color: #ffffff; 
    width: 18px; 
    height: 18px;
    border-width: 3px; 
}

/* Spinner (general definition) */
.spinner {
    border: 3px solid rgba(0,0,0,.1); 
    width: 20px; 
    height: 20px; 
    border-radius: 50%;
    border-left-color: #3B82F6; 
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Utility to hide text but keep for screen readers */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* NEW: Generic hidden class */
.hidden {
    display: none !important; /* !important to ensure it overrides other display styles if specificity conflicts arise */
}

/* AI Answer Box - Enhanced for clarity and consistency */
.ai-answer-box {
    background-color: #e9f5ff; 
    border: 1px solid #bde0fe; 
    border-radius: 6px; 
    padding: 18px; 
    margin-top: 20px; 
    font-size: 0.95em; 
    line-height: 1.7;
    color: #334155; 
    text-align: right;
}
/* .ai-answer-box.hidden is already handled by the generic .hidden class above */

.ai-answer-box p { 
    margin-bottom: 0.75em; 
}
.ai-answer-box p:last-child {
    margin-bottom: 0;
}
.ai-answer-box strong { 
    color: #2c3e50; 
    font-weight: 600;
}
.ai-answer-box ul, .ai-answer-box ol {
    padding-right: 20px; 
    margin-top: 0.5em;
    margin-bottom: 0.75em;
}
.ai-answer-box li {
    margin-bottom: 0.3em;
}

/* Add these rules to the end of your style.css file */

/* For tablets and larger mobile phones (screens up to 768px wide) */
@media (max-width: 768px) {
    body {
        padding: 10px; /* Reduce body padding */
    }

    .container {
        padding: 20px 15px; /* Reduce horizontal padding for the main form container */
        margin: 10px auto;   /* Optionally reduce top/bottom margin for the container */
    }

    h1#main-title {
        font-size: 1.8em; /* Slightly smaller main title for better fit */
    }

    h2 { /* Section titles */
        font-size: 1.4em; /* Slightly smaller section titles */
    }

    /* Optional: Slightly reduce font size for form elements and labels if needed */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="date"],
    input[type="number"],
    select,
    textarea,
    label {
        font-size: 0.95em;
    }

    .navigation-buttons button {
        padding: 10px 15px; /* Adjust button padding */
        font-size: 1em;     /* Adjust button font size */
    }

    /* Adjustments for select dropdown arrow if it looks off */
    select:not([multiple]) {
        background-position: left 12px top 50%; /* Ensure arrow is positioned well */
        padding-left: 35px; /* Adjust padding to make space for the arrow */
    }
}

/* For smaller mobile phones (screens up to 480px wide) */
@media (max-width: 480px) {
    body {
        padding: 5px; /* Further reduce body padding for very small screens */
    }

    .container {
        padding: 15px 10px; /* Further reduce horizontal padding for the form container */
    }

    /* Optional: Further reduce font size for form elements and labels if still cramped */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="date"],
    input[type="number"],
    select,
    textarea,
    label {
        font-size: 0.9em;
    }
    
    h1#main-title {
        font-size: 1.6em;
    }

    h2 { /* Section titles */
        font-size: 1.3em;
    }

    /* Fine-tune select dropdown arrow for very small screens */
    select:not([multiple]) {
        background-position: left 10px top 50%;
        padding-left: 30px;
    }

    /* Ensure AI help icon doesn't cause layout issues if label text is long */
    .ai-help-icon {
        margin-left: 5px; /* Slightly reduce space next to label for RTL */
        /* Optionally adjust size if it feels too large:
        width: 16px;
        height: 16px;
        font-size: 0.7em;
        */
    }
}