:root {
    --primary-color: #3f51b5;
    /* Professional Blue-Indigo */
    --primary-hover: #303f9f;
    --bg-color: #f0f2f5;
    --card-bg: #ffffff;
    --text-primary: #333333;
    --text-secondary: #777777;
    --border-color: #e0e0e0;
    --input-bg: #f8f9fa;
    --message-out: #8E24AA;
    /* Nahdi / Purple */
    --message-in: #f0f0f0;
    /* Light Gray for logical contrast */
    --message-text-out: #ffffff;
    --danger: #ff4444;
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --header-height: 65px;
    --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 6px 16px rgba(0, 0, 0, 0.12);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #121212;
        --card-bg: #1e1e1e;
        --text-primary: #f5f5f5;
        --text-secondary: #aaaaaa;
        --border-color: #333333;
        --input-bg: #2c2c2c;
        --message-out: #3f51b5;
        --message-in: #2c2c2c;
        --message-text-out: #ffffff;
        --danger: #cf6679;
        --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.3);
    }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    direction: rtl;
    text-align: right;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    justify-content: center;
}

/* App Frame */
.app-container {
    display: flex;
    width: 100%;
    height: 100%;
    /* Ensure full height */
    background: var(--card-bg);
    overflow: hidden;
    position: relative;
    max-width: 100%;
    /* FULL WIDTH - No more small window */
    box-shadow: none;
    /* No shadow needed for full screen */
}

/* ... existing styles ... */

.logo {
    font-family: 'Grand Hotel', cursive;
    font-size: 56px;
    /* Even bigger */
    font-weight: 400;
    background: linear-gradient(45deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
    -webkit-background-clip: text;
    background-clip: text;
    /* Standard property fix */
    -webkit-text-fill-color: transparent;
    color: transparent;
    /* Fallback */
    margin-bottom: 25px;
    letter-spacing: 1px;
}

.home-layout {
    flex-direction: column;
    /* Fix Home Feed alignment */
}

/* Global Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

main,
.auth-box,
.sidebar,
.chat-window {
    animation: fadeIn 0.4s ease-out;
}

/* Common Header */
.sidebar-header,
.chat-header {
    height: var(--header-height);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 20px;
    background: var(--card-bg);
}

/* --- Social Features (Home/Feed/Profile) --- */

/* Headers */
.main-header,
.profile-header-nav {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 50;
    padding-top: env(safe-area-inset-top);
    /* Notch Support */
    height: calc(var(--header-height) + env(safe-area-inset-top));
}

.profile-header-nav {
    justify-content: space-between;
}

.header-content {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-small {
    font-weight: 800;
    font-size: 20px;
    color: var(--primary-color);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 15px;
}

.avatar-small {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #eee;
    overflow: hidden;
    cursor: pointer;
}

.icon-btn {
    padding: 8px;
    background: transparent;
    border-radius: 50%;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
}

.icon-btn:hover {
    background: var(--bg-color);
}

/* Feed & Search */
.feed-container {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    /* justify-content: center;  <-- Optional: if they want vertical centering, but usually top is better. 
       Let's stick to top but ensure margin auto handles horizontal. */
}

.search-section {
    margin-bottom: 20px;
    position: relative;
}

.search-wrapper {
    position: relative;
}

#home-search-input {
    width: 100%;
    padding: 12px 20px;
    border-radius: 24px;
    background: var(--input-bg);
    border: 1px solid transparent;
    font-size: 15px;
    text-align: right;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.02);
}

#home-search-input:focus {
    border-color: var(--primary-color);
    background: var(--card-bg);
}

.search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    margin-top: 8px;
    z-index: 100;
    max-height: 350px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}

.search-dropdown:not(.hidden) {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.search-result-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.1s;
}

.search-result-item:hover {
    background: var(--bg-color);
}

/* Stats & Quick Actions */
.stats-card {
    background: var(--card-bg);
    border-radius: 18px;
    padding: 15px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    margin-bottom: 25px;
    border: 1px solid var(--border-color);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-value {
    font-weight: 800;
    font-size: 20px;
    color: var(--text-primary);
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.stat-divider {
    width: 1px;
    height: 35px;
    background: var(--border-color);
}

.quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 30px;
}

.action-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 18px;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: transform 0.1s;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
}

.action-card:active {
    transform: scale(0.97);
}

.action-card.primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(63, 81, 181, 0.25);
}

.action-card.primary .icon-box {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.icon-box {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: var(--input-bg);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

.badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--danger);
    color: white;
    font-size: 11px;
    font-weight: bold;
    padding: 2px 8px;
    border-radius: 10px;
}

/* Suggestions */
.suggestions-section h3 {
    font-size: 17px;
    margin-bottom: 15px;
    color: var(--text-primary);
    font-weight: 700;
}

.suggestions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 15px;
}

@media (max-width: 480px) {
    .suggestions-grid {
        grid-template-columns: 1fr 1fr;
        /* Force 2 columns on mobile */
        gap: 10px;
    }

    .feed-container {
        padding: 15px 15px 80px 15px;
        /* Extra bottom padding for safety */
    }

    .main-header .user-menu {
        gap: 10px;
    }
}

.suggestion-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 18px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
    transition: transform 0.2s;
}

.suggestion-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.s-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #eee;
    overflow: hidden;
    margin-bottom: 5px;
}

.s-name {
    font-weight: 700;
    font-size: 14px;
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

.s-username {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: -5px;
}

.s-btn {
    margin-top: 8px;
    width: 100%;
    padding: 8px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    background: var(--input-bg);
    color: var(--text-primary);
    border: none;
    cursor: pointer;
    transition: background 0.2s;
}

.s-btn.follow {
    background: var(--primary-color);
    color: white;
}

.s-btn.follow:hover {
    background: var(--primary-hover);
}

/* Profile Page */
.profile-layout {
    flex-direction: column;
    max-width: 600px;
    margin: 0 auto;
    background: var(--card-bg);
    height: 100dvh;
}

.profile-content {
    padding: 30px 20px;
    overflow-y: auto;
    text-align: center;
}

.profile-avatar-large {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: #eee;
    margin: 0 auto 15px;
    overflow: hidden;
    border: 4px solid var(--card-bg);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.profile-fullname {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.profile-username {
    color: var(--text-secondary);
    font-size: 15px;
    direction: ltr;
    /* Ensure username LTR @handle */
    font-weight: 500;
}

.profile-bio {
    margin: 20px 0;
    font-size: 15px;
    color: var(--text-primary);
    line-height: 1.6;
    max-width: 80%;
    margin-left: auto;
    margin-right: auto;
}

.profile-stats {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin: 25px 0;
    padding: 20px 0;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.profile-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 10px;
}

.action-btn {
    flex: 1;
    padding: 12px;
    border-radius: 14px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    max-width: 160px;
    font-size: 15px;
    transition: transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.action-btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 10px rgba(63, 81, 181, 0.2);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.loading-screen,
.error-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    height: 100%;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* --- Existing Chat & Sidebar Styles --- */
.sidebar {
    width: 380px;
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    z-index: 10;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 10px 20px 10px;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    margin-bottom: 5px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-item:hover {
    background-color: var(--bg-color);
}

.chat-item.active {
    background-color: rgba(63, 81, 181, 0.08);
}

.avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background-color: #e0e0e0;
    margin-left: 15px;
    flex-shrink: 0;
    overflow: hidden;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-info {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

.chat-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.chat-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.unread-badge {
    background: var(--danger);
    color: white;
    font-size: 11px;
    font-weight: bold;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-color);
    position: relative;
}

#back-btn {
    background: transparent;
    padding: 8px;
    margin-left: 12px;
    border-radius: 50%;
    color: var(--text-primary);
    display: none;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    width: 40px;
    height: 40px;
}

#back-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background-image: radial-gradient(var(--border-color) 1px, transparent 1px);
    background-size: 20px 20px;
}

.message {
    max-width: 75%;
    padding: 10px 18px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.message.sent {
    align-self: flex-end;
    background-color: var(--message-out);
    color: var(--message-text-out);
    border-bottom-left-radius: 4px;
}

.message.received {
    align-self: flex-start;
    background-color: var(--message-in);
    color: var(--text-primary);
    border-bottom-right-radius: 4px;
}

.chat-input-area {
    background: var(--card-bg);
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-top: 1px solid var(--border-color);
}

.chat-input {
    flex: 1;
    border-radius: 24px;
    background: var(--input-bg);
    border: 1px solid transparent;
    padding: 12px 18px;
    color: var(--text-primary);
}

.chat-input:focus {
    background: var(--card-bg);
    border-color: var(--border-color);
    outline: none;
}

#send-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 4px 10px rgba(63, 81, 181, 0.3);
    transition: transform 0.2s;
}

#send-btn:hover {
    transform: scale(1.05);
}

/* Auth Box Styles (Login/Register) */


.logo {
    font-family: 'Grand Hotel', cursive;
    font-size: 48px;
    /* Larger for impact */
    font-weight: 400;
    /* Cursive doesn't need bold usually */
    background: -webkit-linear-gradient(45deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
    /* Instagram Gradient */
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 25px;
    letter-spacing: 1px;
}

.auth-box {
    width: 100%;
    max-width: 400px;
    background: #ffffff;
    /* Clean white like Insta */
    padding: 40px;
    border: none;
    /* Subtle border removed for cleaner look, relying on shadow */
    border-radius: 24px;
    /* Smoother corners */
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    /* Softer, deeper shadow */
    margin: auto;
    /* Ensure it's centered in the flex container */
}

.form-group input {
    width: 100%;
    /* Full width to ensure centering */
    background: #fafafa;
    border: 1px solid #dbdbdb;
    border-radius: 12px;
    /* Smoother inputs */
    padding: 14px;
    font-size: 15px;
    transition: 0.2s;
    box-sizing: border-box;
    /* Ensure padding doesn't affect width */
    text-align: center;
    /* Center the text inside as per user request asking for "boxes in the middle" - satisfying both interpretations */
}

.form-group input:focus {
    border-color: #a8a8a8;
    background: #ffffff;
    box-shadow: none;
    /* Clean focus */
}

#login-btn,
#register-btn {
    width: 100%;
    border-radius: 12px;
    /* Smoother buttons */
    background: linear-gradient(45deg, #405de6, #5851db, #833ab4, #c13584, #e1306c, #fd1d1d);
    font-size: 16px;
    /* Slightly larger text */
    padding: 12px;
    border: none;
    color: white;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
}

.separator {
    margin: 25px 0;
    color: var(--text-secondary);
    font-size: 14px;
    position: relative;
}

.separator::before,
.separator::after {
    content: "";
    position: absolute;
    top: 50%;
    width: 42%;
    height: 1px;
    background: var(--border-color);
}

/* Auth Pages Layout */
.auth-body {
    display: flex;
    justify-content: center;
    align-items: center;
    /* Center Vertically */
    min-height: 100vh;
    background-color: #fafafa;
    /* Insta-like background */
}

.auth-body .container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100vh;
    /* Use full height for easier positioning */
    position: relative;
}

.auth-body main {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    margin-bottom: auto;
    /* Push content to center if using flex column, 
       but wait, we want auth-box in center. 
       Let's use margin: auto for the main block inside container
    */
    margin-top: auto;
}

/* Watermark Positioning */
/* Watermark Positioning */
.watermark {
    position: absolute;
    bottom: 20px;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 13px;
    color: #8e8e8e;
    font-family: 'Segoe UI', sans-serif;
    opacity: 0.7;
}

.separator::after {
    right: 0;
}

.alt-action {
    margin-top: 30px;
    font-size: 15px;
    color: var(--text-secondary);
    text-align: center;
}

.alt-action a {
    color: var(--primary-color);
    font-weight: 700;
    text-decoration: none;
}

/* Responsive */
@media (max-width: 768px) {
    body {
        background-color: var(--card-bg);
    }

    .app-container {
        box-shadow: none;
        height: 100dvh;
    }

    .sidebar {
        width: 100%;
        border: none;
    }

    .auth-box {
        width: 100%;
        box-shadow: none;
        background: transparent;
        padding: 20px;
    }

    .chat-window {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 20;
        visibility: hidden;
        opacity: 0;
        transform: translateX(20px);
        background: var(--bg-color);
        transition: visibility 0s 0.3s, opacity 0.3s ease, transform 0.3s ease;
    }

    body.show-chat .chat-window {
        visibility: visible;
        opacity: 1;
        transform: translateX(0);
        transition: opacity 0.3s ease, transform 0.3s ease;
    }

    body.show-chat .sidebar {
        display: none;
    }

    #back-btn {
        display: flex;
        /* Flex to center icon */
    }
}