/* Reverse text direction for Arabic */
html[dir="rtl"] {
    direction: rtl;
    text-align: right;
} 

.hidden {
    display: none !important;
}

/* Modern color palette and variables */
:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --light-color: #ecf0f1;
    --dark-color: #2c3e50;
    --header-text-color: #2c3e50;
    --text-color: #333333;
    --background-color: #f9f9f9;
    --card-background: #ffffff;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --transition-speed: 0.3s;
    --star-color: #f1c40f;
    --star-inactive: #e0e0e0;
    --primary-hover: #c0392b;
    --surface-background: rgba(236, 240, 241, 0.5);
    --surface-over-background: rgba(236, 240, 241, 0.3);
}

[data-theme="dark"] {
    --primary-color: #1f2937;
    --secondary-color: #3b82f6;
    --accent-color: #f43f5e;
    --light-color: #f3f4f6;
    --dark-color: #111827;
    --header-text-color: #f3f4f6;
    --text-color: #e5e7eb;
    --background-color: #0f172a;
    --card-background: #1e293b;
    --shadow-color: rgba(255, 255, 255, 0.05);
    --primary-hover: #a93226;
    --surface-background: rgb(18, 26, 39);
    --surface-over-background: rgba(8, 14, 24, 0.5);
}

/* Base styles */
html {
    box-sizing: border-box;
    scroll-behavior: smooth;
}

* {
    transition: background-color 0.3s ease, color 0.3s ease;
}

*, *:before, *:after {
    box-sizing: inherit;
}

/* html, body {
    height: 100%;
} */

body {
    background: var(--background-color);
    color: var(--text-color);
    font-family: 'Roboto', 'Segoe UI', Arial, sans-serif;
    margin: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-family: 'Montserrat', 'Segoe UI', Arial, sans-serif;
    margin-top: 0;
    color: var(--header-text-color);
}

h1 {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

h2 {
    font-size: 2rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

h3 {
    font-size: 1.75rem;
    font-weight: 600;
    position: relative;
    padding-bottom: 10px;
    margin-bottom: 20px;
}

h3::after {
    content: '';
    position: absolute;
    bottom: 0;
    height: 3px;
    width: 50px;
    background-color: var(--accent-color);
    transition: width var(--transition-speed);
}

html[dir="ltr"] h3::after {
    left: 0;
}

html[dir="rtl"] h3::after {
    right: 0;
}


.page-section:hover h3::after {
    width: 100px;
}

h4 {
    font-size: 1.3rem;
    font-weight: 500;
}

p {
    margin-bottom: 1.5rem;
    font-size: 1rem;
}

a {
    color: var(--secondary-color);
    text-decoration: none;
    transition: color var(--transition-speed);
}

a:hover {
    color: var(--accent-color);
}

/* Header styles */
header {
    background: linear-gradient(rgba(44, 62, 80, 0.8), rgba(44, 62, 80, 0.8)), url(../img/s.png);
    background-size: cover;
    background-position: center;
    color: var(--light-color);
    padding: 120px 0 80px;
    text-align: center;
    position: relative;
    overflow: hidden;
    min-height: 350px; /* Ensure minimum height for header */
    display: flex;
    align-items: center;
    justify-content: center;
}

header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.3) 0%, rgba(231, 76, 60, 0.3) 100%);
    z-index: 1;
}

.title {
    position: relative;
    z-index: 2;
    animation: fadeIn 1s ease-in-out;
    width: 100%;
}

.title h1 {
    color: var(--light-color);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    margin-bottom: 10px;
    display: block; /* Ensure block display */
}

.title h2 {
    color: var(--light-color);
    font-weight: 400;
    opacity: 0.9;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    display: block; /* Ensure block display */
    margin-bottom: 20px; /* Add space below subtitle */
    font-size: 1.8rem; /* Slightly larger for better visibility */
}

/* Navigation */
nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 1000;
    background-color: var(--primary-color);
}

nav ul {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    flex-grow: 1;
    margin: 0;
    padding: 0;
}

nav li {
    list-style-type: none;
    text-align: center;
    font-size: 16px;
    transition: background-color var(--transition-speed);
}

nav a {
    color: var(--light-color);
    display: inline-block;
    padding: 15px 20px;
    text-decoration: none;
    font-weight: 500;
    transition: all var(--transition-speed);
}

nav a:hover {
    color: var(--light-color);
    background-color: var(--secondary-color);
    transform: translateY(-2px);
}

.nav-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#theme-toggle {
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
    border: none;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: var(--light-color);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    box-shadow: 0 2px 10px var(--shadow-color);
    margin: 10px 10px;
}

#theme-toggle:hover {
    transform: scale(1.2);
}  

#menu-toggle {
    display: none;
    width: 100%;
    height: 50px;
    background-color: var(--primary-color);
    border: none;
    cursor: pointer;
    padding: 10px;
}

#menu-toggle svg {
    width: 30px;
    height: 30px;
    fill: var(--light-color);
    transition: transform var(--transition-speed);
}

#menu-toggle:hover svg {
    transform: scale(1.1);
}

#language-switcher {
    background-color: var(--primary-color);
    color: var(--light-color);
    border: none;
    font-size: 1rem;
    padding: 10px 15px;
    margin-left: auto;
    margin-right: 15px;
    border-radius: 4px;
    font-weight: 500;
    appearance: none;
    cursor: pointer;
    transition: background-color var(--transition-speed);
}

#language-switcher:hover {
    background-color: var(--secondary-color);
}

/* Hide dropdown arrow in Safari and Edge */
#language-switcher::-ms-expand {
    display: none;
}
#language-switcher::-webkit-inner-spin-button,
#language-switcher::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.language-dropdown {
    margin-inline-start: auto;
    display: flex;
    align-items: center;
    position: relative;
}

.language-dropdown button {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--light-color);
}

#flag-options {
    position: absolute;
    top: 120%;
    right: 0;
    background-color: var(--primary-color);
    list-style: none;
    padding: 0.3rem;
    margin: 0;
    border-radius: 6px;
    box-shadow: 0 4px 10px var(--shadow-color);
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    z-index: 999;
}

html[dir="rtl"] #flag-options {
    right: auto;
    left: 0;
}

#flag-options li {
    cursor: pointer;
    font-size: 1.5rem;
    padding: 5px 10px;
    border-radius: 4px;
    transition: background-color var(--transition-speed);
}

#flag-options li:hover {
    background-color: var(--secondary-color);
}

#selected-flag {
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
    border: none;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: var(--light-color);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    box-shadow: 0 2px 10px var(--shadow-color);
    margin: 10px 1px;
}

#selected-flag:hover {
    transform: scale(1.2);
}


#selected-flag.fi {
    font-size: 1.5rem;
    width: 100%;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--light-color); /* or white */
}  

/* Content wrapper */
.content-wrapper {
    max-width: 1200px;
    width: 90%;
    margin: 0 auto;
    padding: 40px 0;
    flex: 1 0 auto;
}

/* Section styles */
.page-section {
    margin-bottom: 60px;
    padding: 30px;
    background-color: var(--card-background);
    border-radius: 8px;
    box-shadow: 0 5px 15px var(--shadow-color);
    transition: transform var(--transition-speed), box-shadow var(--transition-speed);
}

.page-section:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px var(--shadow-color);
}

/* Skills and Interests */
dl {
    margin: 0;
}

dt {
    font-weight: 700;
    color: var(--header-text-color);
    margin-top: 15px;
    font-size: 1.1rem;
}

dd {
    margin-left: 0;
    margin-bottom: 15px;
}

.page-section ul {
    margin: 0;
    padding: 0 20px;
}

.page-section li {
    margin-bottom: 8px;
}

/* Star Rating System */
.skills-legend {
    background-color: var(--surface-background);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 25px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 15px;
}

.skill-name .fa-github {
    color: black;
    font-size: 20px;
    margin-right: 5px;
    vertical-align: middle;
}

[data-theme="dark"] .skill-name .fa-github {
    color: white
}

[data-theme="dark"] .skill-name .dark-logo {
    filter: invert(1) saturate(0);
}

.skills-legend p {
    margin: 0;
    font-weight: 600;
    margin-right: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.star-rating {
    display: flex;
    gap: 2px;
}

.star-rating i {
    color: var(--star-color);
    font-size: 1rem;
}

.star-rating i.far {
    color: var(--star-inactive);
}

.skill-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.skill-item {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background-color: var(--surface-over-background);
    border-radius: 6px;
    transition: transform var(--transition-speed), background-color var(--transition-speed);
}

.skill-item:hover {
    transform: translateX(5px);
    background-color: rgba(236, 240, 241, 0.6);
}

.skill-name {
    font-weight: 500;
}

/* Projects section */
#projects-section ul {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 30px;
    padding: 0;
    margin: 20px 0;
}

.project {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    background-color: var(--card-background);
    color: var(--text-color);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 5px 15px var(--shadow-color);
    transition: transform var(--transition-speed), box-shadow var(--transition-speed);
    list-style-type: none;
    height: 100%;
}

.project:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px var(--shadow-color);
}

.project h4 {
    color: var(--header-text-color);
    margin: 0;
    padding: 15px 20px;
    background-color: var(--surface-background);
    border-bottom: 2px solid var(--secondary-color);
}

.project figure {
    margin: 0;
    padding: 0;
    overflow: hidden;
    text-align: center;
    background-color: var(--primary-color);
}

.project img {
    width: 100%;
    height: auto;
    object-fit: cover;
    transition: transform var(--transition-speed);
}

.project:hover img {
    transform: scale(1.05);
}

.project figcaption {
    padding: 10px;
    font-style: italic;
    color: var(--light-color);
    background-color: rgba(44, 62, 80, 0.8);
}

.project p {
    padding: 15px 20px;
    flex-grow: 1;
    font-size: 0.95rem;
}

.project a {
    display: block;
    margin: 0 20px 20px;
    padding: 8px 15px;
    background-color: var(--secondary-color);
    color: var(--light-color);
    border-radius: 4px;
    font-weight: 500;
    transition: background-color var(--transition-speed), transform var(--transition-speed);
}

.project a:hover {
    background-color: var(--accent-color);
    transform: translateY(-2px);
}

/* Formation section */
.main-formation {
    margin-bottom: 30px;
}

.online-courses h4 {
    margin-top: 0;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--shadow-color);
}

/* Contact section */
#contact-section ul {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding: 0;
    margin: 20px 0;
}

#contact-section li {
    list-style-type: none;
}

#contact-section a {
    display: inline-block;
    padding: 12px 25px;
    background-color: var(--secondary-color);
    color: var(--light-color);
    border-radius: 4px;
    font-weight: 500;
    transition: background-color var(--transition-speed), transform var(--transition-speed);
}

#contact-section a:hover {
    background-color: var(--accent-color);
    transform: translateY(-3px);
    box-shadow: 0 4px 8px var(--shadow-color);
}

/* Footer */
footer {
    background: var(--primary-color);
    color: var(--light-color);
    text-align: center;
    padding: 20px 0;
    margin-top: 40px;
}

html[dir="rtl"] .pgp-info {
    direction: ltr;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.8s ease-in-out;
}

html[dir="rtl"] .skills-container,
html[dir="rtl"] .page-section,
html[dir="rtl"] .project,
html[dir="rtl"] .contact-section {
    text-align: right;
}


/* Media Queries */
@media screen and (max-width: 768px) {
    header {
        padding: 80px 0 60px;
    }
    
    h1 {
        font-size: 2.5rem;
    }
    
    h2 {
        font-size: 1.8rem;
    }
    
    .content-wrapper {
        width: 95%;
        padding: 20px 0;
    }
    
    .page-section {
        padding: 20px;
    }
    
    #projects-section ul {
        grid-template-columns: 1fr;
    }
    
    .skills-legend {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .legend-item {
        width: 100%;
    }


    .nav-controls {
        position: absolute;
        top: 10px;
        right: 10px;
        flex-direction: row;
    }
}

@media screen and (max-width: 500px) {
    nav {
        position: relative;
        flex-direction: column;
    }

    .nav-controls {
        position: static;
        justify-content: center;
        flex-direction: row; /* or column if you want them stacked */
        margin-top: 10px;
        display: none;
    }
    
    .footer-theme-toggle {
        display: block;
    }
    
    nav ul {
        flex-direction: column;
        align-items: center;
    }

    
    nav li {
        width: 100%;
    }
    
    nav a {
        width: 100%;
        display: block;
        text-align: center;
    }

    #menu-toggle {
        display: inline-block;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    h2 {
        font-size: 1.5rem;
    }
    
    .page-section {
        padding: 15px;
    }
    
    .skill-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .language-dropdown {
        display: none;
        position: fixed;
        bottom: 70px; /* above the globe button */
        right: 15px;
        flex-direction: row;
        align-items: flex-end;
        background-color: var(--primary-color);
        border-radius: 8px;
        padding: 8px 12px;
        box-shadow: 0 -2px 10px var(--shadow-color);
        z-index: 999;
        max-width: 90vw; /* prevent overflow */
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }

    html[dir="rtl"] .language-dropdown {
        right: auto;
        left: 15px;
    }
    
    .language-dropdown.visible {
        display: flex;
    }
    
    #selected-flag {
        width: 48px;
        height: 48px;
        background-color: var(--primary-color);
        border: none;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 10px var(--shadow-color);
        padding: 0;
        font-size: 1.4rem;
        cursor: pointer;
        z-index: 2;
    }

    #selected-flag:hover {
        transform: scale(1.2);
    }

    #language-toggle {
        position: fixed;
        bottom: 15px;
        right: 15px;
        background-color: var(--primary-color);
        color: var(--light-color);
        border: none;
        padding: 12px;
        border-radius: 50%;
        font-size: 1.4rem;
        z-index: 1000;
        cursor: pointer;
        box-shadow: 0 2px 10px var(--shadow-color);
    }

    html[dir="rtl"] #language-toggle {
        right: auto;
        left: 15px;
    }
    
    #flag-options {
        /* display: none; */
        flex-direction: column-reverse; /* opens upward */
        background-color: var(--primary-color);
        border-radius: 8px;
        padding: 8px;
        box-shadow: 0 4px 10px var(--shadow-color);
        transform: translateY(calc(-100% - 90px));
    }
    
    #flag-options.visible {
        display: flex;
    }
    
    #flag-options li {
        list-style: none;
        cursor: pointer;
        font-size: 1.4rem;
    }
}