/* General styles */
body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    margin: 0;
    padding: 0;
    direction: rtl;
}


header {
    background-color: #175559;
    color: #fff;
    padding: 20px 10px;
    position: relative;
    display: flex;
    justify-content: center;
}

.header-content {
    max-width: 800px;
    display: flex;
    align-items: center;
    flex-direction: row-reverse; /* Ensures the text appears on the right, logo on the left */
    width: 100%;
    position: relative;
}

#logo {
    height: 95px;
    padding-right: 10px;
    margin-left: 10px;
}

.header-text {
    flex-grow: 1;
    text-align: right;
}

h1 {
    font-size: 24px;
    /*margin-top: 10px;*/
}

form {
    justify-content: center;
    background-color: #fff;
    margin: 20px auto;
    padding: 20px;
    max-width: 800px;
    border-radius: 5px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.section {
    border-top: 1px solid #ddd;
    padding-top: 20px;
    margin-top: 10px;
    padding-bottom: 0px;
}

.form-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start; /* Ensure elements don't spread out too much */
    margin-bottom: 15px;
    width: 100%;
    box-sizing: border-box;
}

.form-group label {
    margin-right: 10px;
}

.form-group input {
    flex: 1;
}

.main-label {
    display: block; /* Forces the label to be on its own line */
    width: 100%;    /* Ensures it takes full width */
}
.yesnolabel {
    margin-left: 80px;
}
/* Specific styling for radio buttons */
.form-group.radio-group {
    display: inline-flex; /* Keep radios and labels on the same line */
    align-items: center;
    justify-content: flex-start;
    flex-wrap: nowrap; /* Prevent wrapping */
}

.form-group.radio-group p {
    display: inline-flex;
    align-items: center;
    margin: 5px 0; /* Adjust margin as needed */
    width: auto; /* Prevent p tags from taking full width */
    justify-content: center
}

.form-group.radio-group input[type="radio"] {
    margin-left: 5px;
    margin-right: 5px;
    width: auto; /* Prevent radio buttons from stretching */
}

.form-group.radio-group label {
    margin-right: 5px; /* Space between label and next item */
    display: inline-flex;
    align-items: center;
}

label {
    display: inline-block;
    margin-bottom: 5px;
    font-weight: bold;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="tel"] {
    width: calc(100% - 10px);
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    font-size: 16px;
    text-align: center;
    margin-left: 7px;
    margin-right: 7px;
}

/* Red border and label text when invalid */
input.invalid-input {
    border-color: #ff0000;
    color: #ff0000;
}

input[type="checkbox"],
input[type="radio"] {
    margin-left: 0px;
    margin-right: 30px;
}

.submit-button {
    background-color: #175559;
    color: white;
    padding: 10px 50px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 18px;
    display: block;
    align-self: center;
}

.submit-button:hover {
    background-color: #555;
}

.centered-underline {
    text-align: center;
    text-decoration: underline;
    margin-bottom: 20px;
}

/* Adjust spacing for radio groups with yes/no options */
.form-group.radio-group {
    justify-content: flex-start;
}

.form-group.radio-group label,
.form-group.radio-group input {
    flex: 0 0 auto; /* Prevent them from taking full width */
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        text-align: center;
    }

    #logo {
        height: 70px;
        margin: 0 auto 10px;
    }

    .form-group {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .name-group {
        gap: 15px;
    }

    .form-group.radio-group, 
    fieldset.form-group {
        flex-direction: row;
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: 15px;
    }

    .form-group.radio-group p {
        display: inline-flex;
        align-items: center;
        margin: 5px 0;
        width: auto;
        min-width: 120px;
    }

    .form-group.radio-group input[type="radio"],
    .form-group.radio-group label {
        width: auto;
        margin-right: 8px;
    }

    input[type="text"],
    input[type="number"],
    input[type="date"],
    input[type="email"],
    input[type="tel"] {
        width: 100%;
        margin: 5px 0;
        padding: 12px;
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .submit-button {
        width: 100%;
        font-size: 16px;
        padding: 12px 0;
        margin-top: 10px;
    }

    /* Better tooltip positioning on mobile */
    .invalid-tooltip::after {
        position: fixed;
        bottom: auto;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        max-width: 280px;
        white-space: normal;
    }

    /* Auto-save indicator adjustment for mobile */
    #autosave-indicator {
        top: 10px;
        right: 10px;
        left: auto;
        bottom: auto;
        font-size: 16px;
        padding: 6px;
        border-radius: 18px;
    }
}

@media (max-width: 480px) {
    .form-group.radio-group p {
        display: inline-flex; /* Ensure the radio and label stay on the same line */
        align-items: center;
        margin: 5px 0;
        width: auto; /* Prevent block behavior */
    }

    .form-group.radio-group input[type="radio"],
    .form-group.radio-group label {
        width: auto; /* Prevent full width for radio and label */
        margin-right: 10px;
    }

    input[type="text"],
    input[type="number"],
    input[type="date"],
    input[type="email"],
    input[type="tel"] {
        font-size: 12px;
        padding: 5px;
    }

    .submit-button {
        font-size: 12px;
        padding: 8px;
    }
}

/* Accessibility and validation styles */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus management for accessibility */
input:focus,
button:focus,
textarea:focus {
    outline: 2px solid #175559;
    outline-offset: 2px;
}

/* Skip to content link for screen readers */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #175559;
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 1000;
}

.skip-link:focus {
    top: 6px;
}

/* Enhanced validation styles */
.invalid-input {
    border: 2px solid #dc3545 !important;
    background-color: #fff5f5;
    animation: shake 0.3s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.invalid-tooltip {
    position: relative;
}

.invalid-tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: #dc3545;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.invalid-tooltip::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    border: 5px solid transparent;
    border-top-color: #dc3545;
    opacity: 0;
    transition: opacity 0.3s;
}

.invalid-tooltip:hover::after,
.invalid-tooltip:focus::after {
    opacity: 1;
}

.invalid-tooltip:hover::before,
.invalid-tooltip:focus::before {
    opacity: 1;
}

.valid-input {
    border: 2px solid #28a745 !important;
    background-color: #f8fff8;
    animation: glow 0.5s ease-in-out;
}

@keyframes glow {
    0% { box-shadow: 0 0 0 rgba(40, 167, 69, 0); }
    50% { box-shadow: 0 0 20px rgba(40, 167, 69, 0.3); }
    100% { box-shadow: 0 0 0 rgba(40, 167, 69, 0); }
}

/* Fieldset styles for better accessibility */
fieldset {
    border: none;
    padding: 0;
    margin: 0;
}

legend {
    font-weight: bold;
    margin-bottom: 10px;
}

/* Loading and progress styles */
#progress-container {
    opacity: 0;
    transition: opacity 0.3s ease;
}

#progress-container.show {
    opacity: 1;
}

/* Auto-save indicator - elegant and subtle */
#autosave-indicator {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(40, 167, 69, 0.15);
    padding: 10px;
    border-radius: 20px;
    opacity: 0;
    transform: translateY(-5px) scale(0.9);
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    backdrop-filter: blur(8px);
    box-shadow: 0 2px 12px rgba(40, 167, 69, 0.1);
    z-index: 1000;
    pointer-events: none;
    border: 1px solid rgba(40, 167, 69, 0.2);
    color: rgba(40, 167, 69, 0.8);
}

#autosave-indicator svg {
    display: block;
    width: 16px;
    height: 16px;
}

#autosave-indicator.show {
    opacity: 0.7;
    transform: translateY(0) scale(1);
}

/* Form completion progress */
.form-progress {
    background: linear-gradient(45deg, #175559, #2a7a7f);
    color: white;
    padding: 10px;
    text-align: center;
    border-radius: 5px;
    margin-bottom: 20px;
}

/* Smooth transitions for conditional sections */
.form-group,
#spouseDetails,
#marrieddate,
#expectedreturndatediv,
#foreigncitizendetails,
#acqforeigncitizendetails,
#processforeigncitizendetails,
#workvisadetails,
#yearapt,
#rentaldates,
#taxyear,
#source,
#incomelocation,
#explainstatus {
    transition: all 0.3s ease;
    overflow: hidden;
}

/* Fade-in animation for newly shown sections */
.fade-in {
    animation: fadeInSlide 0.4s ease-out forwards;
}

@keyframes fadeInSlide {
    from {
        opacity: 0;
        max-height: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        max-height: 500px;
        transform: translateY(0);
    }
}

/* Better button states */
.submit-button:disabled,
.submit-button.submitting {
    background-color: #ccc !important;
    cursor: not-allowed !important;
    opacity: 0.6 !important;
    pointer-events: none !important;
    transform: none !important;
}

.submit-button.submitting {
    position: relative;
}

.submit-button.submitting::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: inherit;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.7; }
}

.submit-button:not(:disabled):not(.submitting):hover {
    background-color: #2a7a7f;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}

