/* ============================================
   CSS Variables for Colors
   Using ONLY the approved color palette - no other colors allowed
   ============================================ */
:root {
    /* Primary colors - main UI elements and headings */
    --primary-color: #243C4C;
    --primary-dark: #30525C;
    --primary-medium: #326080;
    --primary-light: #5289AD;
    
    /* Secondary colors - supporting elements */
    --secondary-color: #698696;
    --secondary-light: #5C7E8F;
    --secondary-very-light: #ACBCBF;
    
    /* Accent colors - interactive elements, links, buttons */
    --accent-color: #00ACAC;
    --accent-hover: #4C848D;
    --accent-light: #B5D2E6;
    
    /* Text colors */
    --text-color: #000000;
    --text-dark: #464545;
    --text-medium: #A6A7A2;
    --text-light: #A2A2A2;
    
    /* Background colors */
    --background-color: #FFFFFF;
    --background-alt: #F4FCFB;
    --background-cream: #FFF1E7;
    --background-light: #DFDEDC;
    
    /* Border colors */
    --border-color: #D4DDE2;
    --border-light: #ACBCBF;
    --border-medium: #A6A7A2;
    
    /* Status colors - for badges, alerts, and special states */
    --color-orange: #C35627;
    --color-orange-light: #D6794D;
    --color-brown: #805232;
    --color-brown-light: #DCAA89;
    
    /* Disabled state */
    --color-disabled: #A2A2A2;

    /* Mobile safe-area insets for notches/gesture bars */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
}

/* ============================================
   Dark Mode CSS Variables
   Dark theme color palette based on approved colors
   ============================================ */
[data-theme="dark"] {
    /* Primary colors - adjusted for dark mode */
    --primary-color: #5289AD;
    --primary-dark: #326080;
    --primary-medium: #30525C;
    --primary-light: #243C4C;
    
    /* Secondary colors - adjusted for dark mode */
    --secondary-color: #5C7E8F;
    --secondary-light: #698696;
    --secondary-very-light: #ACBCBF;
    
    /* Accent colors - brighter in dark mode */
    --accent-color: #00ACAC;
    --accent-hover: #4C848D;
    --accent-light: #B5D2E6;
    
    /* Text colors - inverted for dark mode */
    --text-color: #FFFFFF;
    --text-dark: #E0E0E0;
    --text-medium: #B0B0B0;
    --text-light: #808080;
    
    /* Background colors - dark theme */
    --background-color: #1A1A1A;
    --background-alt: #242424;
    --background-cream: #2A2A2A;
    --background-light: #333333;
    
    /* Border colors - adjusted for dark mode */
    --border-color: #404040;
    --border-light: #505050;
    --border-medium: #606060;
    
    /* Status colors - maintained for consistency */
    --color-orange: #C35627;
    --color-orange-light: #D6794D;
    --color-brown: #805232;
    --color-brown-light: #DCAA89;
    
    /* Disabled state */
    --color-disabled: #606060;
}

/* ============================================
   Reset and Base Styles
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--background-color);
    overflow-x: hidden;
}

html,
body {
    min-height: 100%;
}

/* ============================================
   Header and Navigation
   ============================================ */
header {
    position: sticky;
    top: 0;
    background-color: var(--background-color);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
}

nav {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Logo alignment - right side */
nav .logo {
    margin-left: auto; /* Push logo to the right */
    margin-right: 0;
}

.logo {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
    position: relative;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    height: 1.5em; /* Fixed height to prevent vertical shift */
    line-height: 1.5em;
    vertical-align: middle;
    gap: 0; /* No gap between base text and role */
    direction: rtl; /* RTL for Persian text */
    text-align: right; /* Align to right for RTL */
}

/* Base text - static, never changes */
.logo-base-text {
    display: inline-block;
    white-space: nowrap;
    flex-shrink: 0; /* Never shrink */
    margin: 0;
    padding: 0;
    direction: rtl; /* RTL for Persian */
}

/* Role container - holds morphing role text, sticks to base text */
.logo-role-container {
    position: relative;
    display: inline-block;
    min-width: 150px; /* Fixed minimum width to prevent shifting */
    text-align: right; /* Right align for RTL */
    overflow: visible; /* Allow subtle blur to show */
    margin-left: 0.5em; /* Small space between base text and role */
    margin-right: 0;
    padding: 0;
    vertical-align: baseline; /* Align with base text */
    direction: rtl; /* RTL for Persian */
}

/* Morphing text elements inside role container */
.logo-text {
    position: absolute;
    right: 0; /* Right align for RTL Persian text */
    top: 0;
    display: inline-block;
    white-space: nowrap;
    will-change: opacity, filter; /* Optimize for animation */
    pointer-events: none; /* Prevent interaction with overlapping text */
    direction: rtl; /* RTL for Persian */
    text-align: right; /* Right align for RTL */
}

.logo-text-1 {
    position: relative;
    opacity: 1;
    filter: none;
    z-index: 2;
}

.logo-text-2 {
    position: absolute;
    right: 0; /* Right align for RTL */
    top: 0;
    opacity: 0;
    filter: blur(100px);
    z-index: 1;
}

/* RTL support for logo */
[dir="rtl"] .logo {
    direction: rtl;
    text-align: right;
}

[dir="rtl"] .logo-base-text {
    direction: rtl;
}

[dir="rtl"] .logo-role-container {
    direction: rtl;
    text-align: right;
}

[dir="rtl"] .logo-text {
    right: 0;
    left: auto;
    direction: rtl;
    text-align: right;
}

.nav-links {
    display: flex;
    list-style: none;
    gap: 2rem;
}

.nav-links a {
    text-decoration: none;
    color: var(--text-color);
    font-weight: 400;
}

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

/* ============================================
   Mobile Menu Toggle
   ============================================ */
.menu-toggle {
    display: none;
    flex-direction: column;
    cursor: pointer;
    gap: 4px;
}

.menu-toggle span {
    width: 25px;
    height: 2px;
    background-color: var(--primary-color);
}

/* ============================================
   Main Content Sections
   ============================================ */
main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
}

.hero {
    min-height: 70vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 4rem 0;
}

.hero h1 {
    font-size: 3.5rem;
    font-weight: 300;
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.hero p {
    font-size: 1.25rem;
    color: var(--text-light);
}

.content-section {
    padding: 4rem 0;
    border-bottom: 1px solid var(--border-color);
}

.content-section:last-of-type {
    border-bottom: none;
}

.content-section h2 {
    font-size: 2.5rem;
    font-weight: 300;
    margin-bottom: 1.5rem;
    color: var(--primary-color);
}

.content-section p {
    font-size: 1.1rem;
    color: var(--text-light);
    line-height: 1.8;
}

/* ============================================
   Footer
   ============================================ */
footer {
    background-color: var(--background-alt);
    padding: 2rem;
    text-align: center;
    margin-top: 4rem;
    border-top: 1px solid var(--border-color);
}

footer p {
    color: var(--text-light);
    font-size: 0.9rem;
}

/* ============================================
   Mobile Touch Optimizations
   ============================================ */
/* Prevent double-tap zoom on buttons and interactive elements */
button,
a,
input[type="button"],
input[type="submit"],
.btn,
.btn-filter,
.menu-toggle {
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0, 172, 172, 0.2);
}

/* Ensure minimum touch target size (44x44px recommended by Apple/Google) */
button,
.btn,
.btn-filter,
.nav-links a {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Improve text selection on mobile */
body {
    -webkit-touch-callout: default;
    -webkit-user-select: text;
    user-select: text;
}

/* Prevent text selection on buttons */
button,
.btn {
    -webkit-user-select: none;
    user-select: none;
}

/* ============================================
   Responsive Design - Mobile First Approach
   ============================================ */

/* Large Tablet / Small Desktop (1024px and below) */
@media (max-width: 1024px) {
    nav {
        padding: 1rem 1.5rem;
    }
    
    .nav-links {
        gap: 1.5rem;
    }
}

/* Mobile: stack nav menu items in one vertical column */
@media (max-width: 768px) {
    .menu-toggle {
        display: flex;
        padding: 8px;
        min-width: 44px;
        min-height: 44px;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        gap: 4px;
        z-index: 1001;
    }

    .menu-toggle span {
        display: block;
        width: 25px;
        height: 2px;
        background-color: var(--primary-color);
        transition: all 0.3s ease;
    }

    .menu-toggle.active span:nth-child(1) {
        transform: rotate(45deg) translate(5px, 5px);
    }

    .menu-toggle.active span:nth-child(2) {
        opacity: 0;
    }

    .menu-toggle.active span:nth-child(3) {
        transform: rotate(-45deg) translate(7px, -6px);
    }

    .nav-links {
        position: fixed;
        top: calc(60px + var(--safe-area-top));
        left: -100%;
        width: 100%;
        height: calc(100dvh - 60px - var(--safe-area-top));
        background-color: var(--background-color);
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        padding-top: 2rem;
        padding-bottom: max(1rem, var(--safe-area-bottom));
        gap: 1.5rem;
        transition: left 0.3s ease;
        z-index: 999;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
        overflow-y: auto;
    }

    .nav-links.active {
        left: 0;
        display: flex;
        flex-direction: column;
        flex-wrap: nowrap;
        justify-content: flex-start;
        align-items: stretch;
        padding: 1rem;
        gap: 0.75rem;
        height: calc(100dvh - 60px - var(--safe-area-top));
        overflow-y: auto;
    }

    .nav-links.active li {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .nav-links.active a,
    .nav-links.active .nav-btn-logout,
    .nav-links.active .nav-user-info {
        width: 80%;
        text-align: center;
    }

    .nav-links.active .nav-btn-logout {
        justify-content: center;
    }

    .nav-links.active .nav-user-info {
        padding: 12px 20px;
    }

    [dir="rtl"] .nav-links.active {
        flex-direction: column;
    }
}

/* Tablet Styles (768px and below) */
@media (max-width: 768px) {
    /* Navigation improvements */
    nav {
        padding-top: max(1rem, var(--safe-area-top));
        padding-right: max(1rem, var(--safe-area-right));
        padding-bottom: 1rem;
        padding-left: max(1rem, var(--safe-area-left));
        position: relative;
    }
    
    /* Larger touch targets for mobile navigation */
    .nav-links a {
        font-size: 1.1rem;
        padding: 12px 20px;
        width: 80%;
        text-align: center;
        border-radius: 8px;
        transition: background-color 0.3s ease;
    }
    
    .nav-links a:active {
        background-color: var(--background-alt);
    }

    /* Typography adjustments */
    .hero h1 {
        font-size: 2.5rem;
    }

    .hero p {
        font-size: 1.1rem;
    }

    .content-section {
        padding: 3rem 0;
    }

    .content-section h2 {
        font-size: 2rem;
    }

    main {
        padding: 0 1rem;
    }
    
    /* Form improvements for mobile */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px; /* Prevents zoom on iOS when focusing */
        padding: 12px 16px;
        min-height: 44px;
    }
    
    /* Button improvements */
    button,
    .btn,
    .btn-filter {
        padding: 14px 20px;
        font-size: 1rem;
        min-height: 48px;
    }
    
    /* Card and container spacing */
    .form-card,
    .profile-card,
    .post-card {
        padding: 20px;
        margin-bottom: 15px;
    }
    
    /* Table improvements */
    table {
        font-size: 0.9rem;
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Mobile Styles (480px and below) */
@media (max-width: 480px) {
    /* Typography */
    .hero {
        min-height: 60vh;
        padding: 2rem 0;
    }

    .hero h1 {
        font-size: 2rem;
        line-height: 1.2;
    }

    .hero p {
        font-size: 1rem;
    }

    .content-section {
        padding: 2rem 0;
    }

    .content-section h2 {
        font-size: 1.75rem;
    }

    .content-section p {
        font-size: 1rem;
    }

    /* Navigation */
    nav {
        padding-top: max(0.75rem, var(--safe-area-top));
        padding-right: max(1rem, var(--safe-area-right));
        padding-bottom: 0.75rem;
        padding-left: max(1rem, var(--safe-area-left));
    }

    .logo {
        font-size: 1.25rem;
    }
    
    .nav-links {
        padding-top: 1.5rem;
        gap: 1rem;
    }
    
    .nav-links a {
        font-size: 1rem;
        padding: 14px 20px;
        width: 90%;
    }
    
    /* Buttons - even larger on small screens */
    button,
    .btn,
    .btn-filter {
        padding: 16px 24px;
        font-size: 1.05rem;
        min-height: 50px;
        margin-bottom: 0;
    }

    .btn,
    .btn-filter,
    .dashboard-nav-links button,
    .portal-nav-links button {
        width: 100%;
        margin-bottom: 10px;
    }
    
    /* Form inputs - full width on mobile */
    .form-group input,
    .form-group select,
    .form-group textarea {
        width: 100%;
        font-size: 16px;
        padding: 14px 16px;
    }
    
    /* Cards - less padding on small screens */
    .form-card,
    .profile-card,
    .post-card {
        padding: 15px;
        border-radius: 8px;
    }
    
    /* Grid layouts - single column on mobile */
    .form-grid,
    .profile-info,
    .post-card-content {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    /* Dashboard improvements */
    .dashboard-header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .dashboard-nav-links {
        flex-direction: column;
        width: 100%;
        gap: 10px;
    }
    
    .dashboard-nav-links a,
    .dashboard-nav-links button {
        width: 100%;
        text-align: center;
        padding: 12px;
    }
}

/* Landscape orientation on mobile devices */
@media (max-width: 768px) and (orientation: landscape) {
    .nav-links {
        height: calc(100dvh - 60px - var(--safe-area-top));
        padding-top: 1rem;
    }
    
    .hero {
        min-height: 50vh;
        padding: 2rem 0;
    }
    
    /* Map container adjustments for landscape */
    .map-container {
        height: 60vh !important;
        min-height: 400px;
    }
    
    .filters-section-standalone,
    .listings-section-standalone {
        max-height: 50vh;
    }
}

/* Very small screens (360px and below) */
@media (max-width: 360px) {
    .logo {
        font-size: 1.1rem;
    }
    
    .hero h1 {
        font-size: 1.75rem;
    }
    
    button,
    .btn,
    .btn-filter {
        padding: 14px 20px;
        font-size: 0.95rem;
    }
    
    .form-card,
    .profile-card {
        padding: 12px;
    }
}


/* ============================================
   Theme Toggle Button - Auto-hide with hover reveal
   ============================================ */
.theme-toggle {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    background-color: var(--background-color);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

/* When the toggle sits inside the nav links menu, it should flow as a list item */
.nav-links .theme-toggle {
    position: relative;
    top: auto;
    left: auto;
    transform: none;
}

/* Only show the toggle when the nav menu is open */
.nav-links:not(.active) .theme-toggle {
    display: none;
}

/* Show button on hover with scale effect */
.theme-toggle:hover {
    transform: translateX(-50%) scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    border-color: var(--accent-color);
}

/* Dark mode specific adjustments for toggle button */
[data-theme="dark"] .theme-toggle {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.theme-toggle:active {
    transform: translateX(-50%) scale(0.95);
}

.theme-toggle svg {
    width: 24px;
    height: 24px;
    fill: var(--text-color);
    transition: fill 0.3s ease;
}

.theme-toggle:hover svg {
    fill: var(--accent-color);
}

/* Keep button visible when it's focused (keyboard navigation) */
.theme-toggle:focus {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Hide sun icon in dark mode, show moon icon */
[data-theme="dark"] .theme-toggle .sun-icon {
    display: none;
}

[data-theme="dark"] .theme-toggle .moon-icon {
    display: block;
}

/* Hide moon icon in light mode, show sun icon */
.theme-toggle .sun-icon {
    display: block;
}

.theme-toggle .moon-icon {
    display: none;
}

/* ============================================
   Country Switcher (in Filters Section)
   ============================================ */
/* Country switcher is now part of the filters section */
/* Styles are defined in index.html inline styles */

/* ============================================
   RTL (Right-to-Left) Support
   ============================================ */
[dir="rtl"] {
    direction: rtl;
    text-align: right;
}

[dir="rtl"] .nav-links {
    flex-direction: row-reverse;
}

[dir="rtl"] .listings-sidebar {
    border-left: none;
    border-right: 1px solid var(--border-color);
}

[dir="rtl"] .filter-group input,
[dir="rtl"] .filter-group select,
[dir="rtl"] .country-switcher {
    text-align: right;
}

[dir="rtl"] .listing-card-header {
    flex-direction: row-reverse;
}

/* In RTL, keep content on visual left of image */
[dir="rtl"] .listing-card-row {
    flex-direction: row-reverse;
}

[dir="rtl"] .listings-header {
    flex-direction: row-reverse;
}

[dir="rtl"] .dashboard-header-content,
[dir="rtl"] .portal-header-content {
    flex-direction: row-reverse;
}

[dir="rtl"] .dashboard-nav-links,
[dir="rtl"] .portal-nav-links {
    flex-direction: row-reverse;
}

[dir="rtl"] .form-actions {
    flex-direction: row-reverse;
}

[dir="rtl"] .actions-bar {
    flex-direction: row-reverse;
}

[dir="rtl"] table {
    direction: rtl;
}

[dir="rtl"] th,
[dir="rtl"] td {
    text-align: right;
}

/* ============================================
   Accessibility - Focus States
   ============================================ */
a:focus,
button:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.theme-toggle:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* ============================================
   Leaflet Attribution - Custom Text
   ============================================ */
.leaflet-control-attribution .map-attribution {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
