/* --- Basic Setup & Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap');

:root {
    --font-main: 'Cairo', sans-serif;
    
    /* Base colors (will be overridden by themes) */
    --color-bg-primary: #f0f2f5;
    --color-bg-secondary: #ffffff;
    --color-text-primary: #1c1e21;
    --color-text-secondary: #555;
    --color-accent-primary: #0d6efd;
    --color-accent-hover: #0b5ed7;
    --color-border: #ddd;
    --shadow-light: 0 2px 8px rgba(0, 0, 0, 0.08);

    --sidebar-width: 260px;
    --header-height: 65px;
}

/* --- Themes --- */
.theme-light-gray {
    --color-bg-primary: #f0f2f5;
    --color-bg-secondary: #ffffff;
    --color-text-primary: #1c1e21;
    --color-text-secondary: #555;
    --color-accent-primary: #0d6efd;
    --color-accent-hover: #0b5ed7;
    --color-border: #ddd;
}
.theme-dark {
    --color-bg-primary: #18191a;
    --color-bg-secondary: #242526;
    --color-text-primary: #e4e6eb;
    --color-text-secondary: #b0b3b8;
    --color-accent-primary: #2d88ff;
    --color-accent-hover: #509dff;
    --color-border: #3a3b3c;
}
.theme-navy {
    --color-bg-primary: #1c2541;
    --color-bg-secondary: #2a3a5e;
    --color-text-primary: #f0f4f8;
    --color-text-secondary: #a9b4c2;
    --color-accent-primary: #00b4d8;
    --color-accent-hover: #90e0ef;
    --color-border: #3a506b;
}
.theme-purple {
    --color-bg-primary: #2c2a4a;
    --color-bg-secondary: #4f4c7a;
    --color-text-primary: #f2f2f2;
    --color-text-secondary: #c0bfd6;
    --color-accent-primary: #9d8df1;
    --color-accent-hover: #b8aef5;
    --color-border: #6a679e;
}
.theme-teal {
    --color-bg-primary: #f0fdfa;
    --color-bg-secondary: #ffffff;
    --color-text-primary: #0f172a;
    --color-text-secondary: #334155;
    --color-accent-primary: #14b8a6;
    --color-accent-hover: #0d9488;
    --color-border: #cbd5e1;
}

/* --- Global Styles --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
body {
    font-family: var(--font-main);
    background-color: var(--color-bg-primary);
    color: var(--color-text-primary);
    display: flex;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow: hidden; /* Prevent body scroll */
}

/* --- 1. Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--color-bg-secondary);
    border-left: 1px solid var(--color-border);
    height: 100vh;
    position: fixed;
    top: 0;
    right: 0;
    padding: 20px 0;
    box-shadow: var(--shadow-light);
    overflow-y: auto;
    transition: transform 0.3s ease, background-color 0.3s ease;
    z-index: 100;
}
.sidebar-header {
    padding: 0 20px 20px 20px;
    text-align: center;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 15px;
}
.sidebar-header h3 {
    color: var(--color-accent-primary);
    font-weight: 700;
}
.sidebar-header h3 i { margin-left: 8px; }

.nav-links { list-style: none; }
.nav-link {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    text-decoration: none;
    color: var(--color-text-secondary);
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.2s ease;
    white-space: nowrap;
}
.nav-link i {
    width: 24px;
    margin-left: 12px;
    font-size: 1.1rem;
}
.nav-link:hover,
.nav-link.active {
    background-color: var(--color-bg-primary);
    color: var(--color-accent-primary);
    border-right: 3px solid var(--color-accent-primary);
    padding-right: 17px; /* 20px - 3px */
}

/* Sidebar Dropdown */
.dropdown .submenu {
    list-style: none;
    padding-right: 30px;
    display: none;
}
.dropdown.open .submenu { display: block; }
.dropdown.open .dropdown-icon { transform: rotate(180deg); }
.dropdown-icon {
    margin-right: auto;
    margin-left: 0;
    font-size: 0.8rem;
    transition: transform 0.2s ease;
}
.submenu .nav-link {
    font-size: 0.9rem;
    padding-top: 8px;
    padding-bottom: 8px;
}

/* --- 2. Main Page Wrapper --- */
.page-wrapper {
    width: calc(100% - var(--sidebar-width));
    margin-right: var(--sidebar-width);
    height: 100vh;
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease, margin-right 0.3s ease;
}

/* --- 3. Main Header --- */
.main-header {
    height: var(--header-height);
    background-color: var(--color-bg-secondary);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
}
.header-left { display: flex; align-items: center; }
.header-right { display: flex; align-items: center; gap: 20px; }

.header-icon-btn {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s ease;
}
.header-icon-btn:hover {
    color: var(--color-text-primary);
    background-color: var(--color-bg-primary);
}

/* Theme Switcher */
.theme-switcher { display: flex; align-items: center; gap: 10px; }
.theme-btn {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--color-border);
    cursor: pointer;
    transition: transform 0.2s ease;
}
.theme-btn:hover { transform: scale(1.15); }
.theme-btn.gray   { background-color: #f0f2f5; }
.theme-btn.dark   { background-color: #18191a; }
.theme-btn.navy   { background-color: #1c2541; }
.theme-btn.purple { background-color: #4f4c7a; }
.theme-btn.teal   { background-color: #14b8a6; }

/* User Area (Auth) */
.user-area { display: flex; align-items: center; gap: 10px; }
.user-info { display: flex; align-items: center; gap: 10px; }
.user-info img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--color-border);
}
.user-info span { font-weight: 600; font-size: 0.9rem; }
.auth-btn {
    text-decoration: none;
    color: var(--color-text-primary);
    background-color: var(--color-bg-primary);
    padding: 8px 15px;
    border-radius: 6px;
    font-weight: 600;
    transition: all 0.2s ease;
    border: 1px solid var(--color-border);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 6px;
}
.auth-btn:hover {
    background-color: var(--color-accent-primary);
    color: #fff;
    border-color: var(--color-accent-primary);
}
.auth-btn.logout:hover {
    background-color: #dc3545; /* Red for logout */
    border-color: #dc3545;
}

/* --- 4. Content Area --- */
.main-content {
    flex-grow: 1;
    overflow: hidden;
    padding: 20px;
}
.content-wrapper {
    width: 100%;
    height: 100%;
}

/* Welcome Message */
.welcome-message {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    text-align: center;
    color: var(--color-text-secondary);
}
.welcome-message h1 {
    color: var(--color-text-primary);
    font-size: 2.5rem;
}
.welcome-message p { font-size: 1.2rem; margin-top: 10px; }
.welcome-icon {
    font-size: 5rem;
    color: var(--color-accent-primary);
    margin-top: 40px;
    opacity: 0.6;
}

/* Iframe Wrapper (Scrollbar Fix) */
.iframe-wrapper {
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: 8px;
    background-color: var(--color-bg-secondary);
    /* This forces the scrollbar context */
    direction: ltr; 
}
#project-iframe {
    width: 100%;
    height: 100%;
    border: none;
    /* This brings it back to RTL for the content */
    direction: rtl; 
}

/* --- 5. Collapsed Sidebar State --- */
body.sidebar-collapsed .sidebar {
    transform: translateX(100%);
}
body.sidebar-collapsed .page-wrapper {
    width: 100%;
    margin-right: 0;
}

/* --- 6. Login Page Styles --- */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}
.login-container {
    background-color: var(--color-bg-secondary);
    padding: 40px;
    border-radius: 8px;
    box-shadow: var(--shadow-light);
    text-align: center;
    width: 90%;
    max-width: 400px;
}
.login-container h2 {
    margin-bottom: 10px;
    color: var(--color-text-primary);
}
.login-container p {
    margin-bottom: 25px;
    color: var(--color-text-secondary);
}
.google-login-btn {
    background-color: #4285F4;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: background-color 0.3s;
    width: 100%;
    font-family: var(--font-main);
}
.google-login-btn:hover { background-color: #357ae8; }
.google-login-btn:disabled {
    background-color: #aaa;
    cursor: not-allowed;
}
.login-error-message {
    color: #dc3545;
    font-size: 0.9rem;
    margin-top: 15px;
    display: none; /* Hidden by default */
}

/* --- 7. Utility Classes (Spinners) --- */
.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-left-color: var(--color-accent-primary);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- 8. Media Queries (Responsiveness) --- */
@media (max-width: 768px) {
    /* Make sidebar overlay on mobile */
    .sidebar {
        transform: translateX(100%);
        box-shadow: -5px 0 15px rgba(0, 0, 0, 0.1);
    }
    .page-wrapper {
        width: 100%;
        margin-right: 0;
    }

    /* When sidebar is open on mobile */
    body.sidebar-open .sidebar {
        transform: translateX(0);
    }
    
    /* Dim the background when sidebar is open */
    body.sidebar-open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.4);
        z-index: 99;
    }

    .main-header { padding: 0 15px; }
    .header-right { gap: 15px; }
    .theme-switcher { display: none; } /* Hide theme switcher on small screens */
    .user-info span { display: none; } /* Hide username, keep photo */
    
    .main-content { padding: 15px; }
    
    .welcome-message h1 { font-size: 1.8rem; }
    .welcome-message p { font-size: 1rem; }
}