:root {
    /* --- Light Theme Defaults (Slate & Blue) --- */
    --primary-color: #0f172a;
    /* Slate 900 - Headings/Dark Text */
    --primary-light: #334155;
    /* Slate 700 */
    --accent-color: #2563eb;
    /* Blue 600 - Primary Action */
    --accent-hover: #1d4ed8;
    /* Blue 700 */

    --bg-body: #f1f5f9;
    /* Slate 100 - Main Background */
    --bg-surface: #ffffff;
    /* White - Cards/Sidebar/Header */
    --bg-code: #f8fafc;
    /* Slate 50 - Subtle Backgrounds */

    --text-main: #0f172a;
    /* Slate 900 */
    --text-muted: #64748b;
    /* Slate 500 */
    --text-light: #94a3b8;
    /* Slate 400 */
    --text-inverse: #ffffff;
    /* White text on dark backgrounds */

    --border-color: #e2e8f0;
    /* Slate 200 */

    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    /* Spacing & Layout */
    --sidebar-width: 280px;
    --header-height: 70px;
    --radius: 12px;
    --radius-sm: 8px;

    /* Shadows meant for Light Mode */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    /* Transitions - GLOBAL SMOOTHNESS (The "Emotion") */
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-theme: background-color 0.5s ease, color 0.5s ease, border-color 0.5s ease, box-shadow 0.5s ease;
}

/* --- Dark Theme Overrides (Refined for "Logic" & Contrast) --- */
[data-theme="dark"] {
    --primary-color: #f1f5f9;
    /* Slate 100 - Stronger white for headers */
    --primary-light: #94a3b8;
    /* Slate 400 - Muted text */
    --accent-color: #60a5fa;
    /* Blue 400 - Lighter blue for dark mode visibility */
    --accent-hover: #93c5fd;
    /* Blue 300 */

    --bg-body: #0f172a;
    /* Slate 900 - Deep clean dark */
    --bg-surface: #1e293b;
    /* Slate 800 - Cards */
    --bg-code: #334155;
    /* Slate 700 */

    --text-main: #f8fafc;
    /* Almost white */
    --text-muted: #cbd5e1;
    /* Slate 300 - Readable gray */
    --text-light: #94a3b8;
    /* Slate 400 */
    --text-inverse: #0f172a;
    /* Dark text on light elements */

    --border-color: #334155;
    /* Slate 700 - Distinct borders */

    /* Glows instead of muddy shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5), 0 2px 4px -2px rgb(0 0 0 / 0.5);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.7), 0 4px 6px -4px rgb(0 0 0 / 0.7);
}

/* Apply smooth theme transition to body and major containers */
body,
.sidebar,
.topbar,
.book-card,
.user-profile-card,
.user-profile,
.card-grid,
.btn,
.icon-btn,
input,
select {
    transition: var(--transition-theme);
}

/* --- Toggle Button "Emotion" --- */
.theme-toggle {
    position: relative;
    overflow: hidden;
}

.theme-toggle:active {
    transform: scale(0.9);
}

/* Icon Animation Logic */
@keyframes rotate-in {
    from {
        transform: rotate(-90deg) scale(0.5);
        opacity: 0;
    }

    to {
        transform: rotate(0) scale(1);
        opacity: 1;
    }
}

.spin-anim {
    animation: rotate-in 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}



/* --- Profile Page Styles (Clean & Simple) --- */
.profile-header-card {
    background: var(--bg-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-bottom: 2rem;
    position: relative;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}

/* Horizontal Layout for Large Screens */
@media (min-width: 768px) {
    .profile-header-card.horizontal {
        flex-direction: row;
        align-items: flex-start;
        text-align: right;
        gap: 2rem;
    }

    .profile-header-card.horizontal .profile-avatar-wrapper,
    .profile-header-card.horizontal .profile-avatar-simple {
        margin-bottom: 0;
        flex-shrink: 0;
    }

    .profile-header-card.horizontal .profile-info {
        flex: 1;
        width: 100%;
    }

    .profile-header-card.horizontal .profile-stats {
        justify-content: flex-start;
        border-top: none;
        border-bottom: none;
        padding: 0;
        margin-bottom: 1.5rem;
    }

    .profile-header-card.horizontal .action-grid {
        justify-content: flex-start;
        max-width: none;
    }
}

.profile-avatar-wrapper {
    position: relative;
    width: 120px;
    height: 120px;
    margin-bottom: 1rem;
}

.profile-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid var(--bg-body);
    box-shadow: var(--shadow-md);
    background-color: var(--bg-code);
}

.profile-avatar-simple {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid var(--bg-body);
    box-shadow: var(--shadow-md);
    background-color: var(--bg-code);
    margin-bottom: 1rem;
}

.avatar-upload-btn {
    position: absolute;
    bottom: 0;
    right: 0;
    background: var(--accent-color);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.avatar-upload-btn:hover {
    transform: scale(1.1);
    background: var(--accent-hover);
}

.profile-name {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: var(--primary-color);
}

.profile-role-wrapper {
    margin-bottom: 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
}

.profile-header-card.horizontal .profile-role-wrapper {
    justify-content: flex-start;
}

.profile-role-item {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.profile-bio {
    color: var(--text-main);
    max-width: 600px;
    line-height: 1.6;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.profile-header-card.horizontal .profile-bio {
    max-width: 100%;
}

.profile-stats {
    display: flex;
    gap: 2rem;
    justify-content: center;
    margin-bottom: 1.5rem;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem;
    width: 100%;
}

.stat-item {
    text-align: center;
    min-width: 80px;
}

.stat-value {
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--accent-color);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.action-grid {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
}

/* --- Community/User Grid Styles --- */
.user-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
}

.user-profile-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    transition: var(--transition);
}

.user-profile-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent-color);
}

.user-avatar-lg {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin-bottom: 1rem;
    object-fit: cover;
    background: var(--bg-code);
    border: none;
    box-shadow: none;
}

.user-card-content {
    /* No special style needed for simple card */
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.user-card-name {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
}

.user-card-bio {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    height: 2.8em;
    line-height: 1.4;
}

.user-stats-row {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 1rem;
    width: 100%;
    border-top: 1px solid var(--bg-body);
    padding-top: 1rem;
}

.stat-mini {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.stat-mini b {
    display: block;
    font-size: 1rem;
    color: var(--text-main);
    font-weight: 700;
}

/* Edit Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-surface);
    padding: 2rem;
    border-radius: var(--radius);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
}

.close-modal-btn {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s;
}

.close-modal-btn:hover {
    color: var(--danger);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Cairo', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
    overflow-x: hidden;
}

/* --- Layout Shell --- */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    position: fixed;
    height: 100vh;
    height: 100dvh;
    /* For mobile browsers */
    top: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--accent-color);
    font-weight: 800;
    font-size: 1.25rem;
    text-decoration: none;
}

.sidebar-nav {
    flex: 1;
    padding: 1.5rem 1rem;
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.875rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.nav-link:hover {
    background-color: #eff6ff;
    color: var(--accent-color);
}

.nav-link.active {
    background-color: var(--accent-color);
    color: white;
    box-shadow: var(--shadow-md);
}

.nav-link i {
    width: 24px;
    text-align: center;
    font-size: 1.1rem;
}


/* Sidebar User Profile (Pinned to Bottom) */
.user-profile {
    padding: 1.25rem;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
    background-color: var(--bg-surface);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.03);
    /* Subtle lift */
    position: relative;
    z-index: 10;
}

.user-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    border-radius: var(--radius);
    /* More rounded */
    transition: var(--transition);
    border: 1px solid transparent;
    /* Prevent jump on hover */
}

.user-card:hover {
    background-color: var(--bg-code);
    border-color: var(--border-color);
}

.user-avatar {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--accent-color), var(--accent-hover));
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.2rem;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.user-info {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.user-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.btn-logout {
    background: white;
    border: 1px solid var(--border-color);
    color: var(--danger);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    /* Circular button */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.btn-logout:hover {
    background-color: #fee2e2;
    border-color: #fecaca;
    transform: rotate(180deg);
    /* Playful interaction */
}

/* Main Content */
.main-content {
    flex: 1;
    margin-right: var(--sidebar-width);
    /* Offset for fixed sidebar */
    width: calc(100% - var(--sidebar-width));
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Top Bar */
.topbar {
    height: var(--header-height);
    background: var(--bg-surface);
    /* Glassmorphism if needed, solid for now */
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 900;
    box-shadow: var(--shadow-sm);
}

.mobile-toggle {
    display: none;
    font-size: 1.5rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-main);
}

.page-title {
    font-size: 1.25rem;
    font-weight: 700;
}

/* Page Body */
.page-container {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* --- Components --- */

/* Cards */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.book-card {
    background: var(--bg-surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 1.0rem;
    position: relative;
}

.book-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent-color);
}

.book-image {
    width: 100%;
    height: 180px;
    object-fit: contain;
    /* Don't crop books */
    background-color: var(--bg-code);
    border-radius: var(--radius-sm);
    mix-blend-mode: multiply;
}

[data-theme="dark"] .book-image {
    mix-blend-mode: normal;
    background-color: rgba(255, 255, 255, 0.05);
}

.book-meta {
    flex: 1;
}

.book-title {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
    color: var(--text-main);
}

.book-author {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.book-tags {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #f1f5f9;
    color: var(--text-muted);
}

.badge-sell {
    background: #dbeafe;
    color: #1e40af;
}

.badge-exchange {
    background: #dcfce7;
    color: #166534;
}


.badge-loan {
    background: #fef9c3;
    color: #854d0e;
}

.notification-badge {
    position: absolute;
    top: -5px;
    right: -8px;
    background-color: var(--danger);
    color: white;
    font-size: 0.6rem;
    padding: 0.1rem 0.3rem;
    border-radius: 99px;
    min-width: 16px;
    text-align: center;
    border: 2px solid var(--bg-surface);
    font-weight: bold;
    line-height: 1;
}

.card-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: auto;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

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

.btn-primary:hover {
    background-color: var(--accent-hover);
}

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

.btn-outline:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
    background-color: #eff6ff;
}

.btn-danger {
    background-color: #fee2e2;
    color: #dc2626;
}

.btn-danger:hover {
    background-color: #fecaca;
}

.btn-full {
    width: 100%;
}


.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: var(--transition);
}

.icon-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
    /* Light mode hover */
    color: var(--accent-color);
}

[data-theme="dark"] .icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    /* Dark mode hover */
    color: var(--accent-color);
}

.theme-toggle {
    margin-left: 0.5rem;
    font-size: 1.2rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-main);
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    transition: var(--transition);
    background-color: var(--bg-surface);
    color: var(--text-main);
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Search Bar (In Topbar or Page) */
.search-container {
    position: relative;
    max-width: 500px;
    width: 100%;
}

.search-input {
    width: 100%;
    padding: 0.65rem 2.5rem 0.65rem 1rem;
    border-radius: 99px;
    border: 1px solid var(--border-color);
    background: var(--bg-code);
    color: var(--text-main);
}

.search-input:focus {
    background: var(--bg-surface);
    border-color: var(--accent-color);
    outline: none;
}

.search-icon {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

/* Auth Pages (Centered) */
.auth-layout {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #f1f5f9 0%, #cbd5e1 100%);
    padding: 1rem;
}

.auth-card {
    background: white;
    padding: 2.5rem;
    border-radius: 24px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
}

[data-theme="dark"] .auth-layout {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

[data-theme="dark"] .auth-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
}

/* Utilities */
.text-center {
    text-align: center;
}

.mb-1 {
    margin-bottom: 0.25rem;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.hidden {
    display: none !important;
}

/* --- Responsive Design --- */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(100%);
        /* Hide to right */
        right: 0;
        box-shadow: -4px 0 10px rgba(0, 0, 0, 0.1);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .main-content {
        margin-right: 0;
        width: 100%;
    }

    .mobile-toggle {
        display: block;
    }

    .topbar {
        padding: 0 1rem;
    }

    .page-container {
        padding: 1rem;
    }
}

/* --- Utility Classes (Visibility) --- */
.d-none {
    display: none !important;
}

.d-block {
    display: block !important;
}

@media (min-width: 992px) {
    .d-lg-none {
        display: none !important;
    }

    .d-lg-block {
        display: block !important;
    }
}

@media (max-width: 991.98px) {
    .d-lg-none {
        display: block !important;
    }

    .d-lg-block {
        display: none !important;
    }

    .sidebar {
        width: 260px;
        /* Slightly narrower on mobile */
    }
}

/* Better Mobile Grid */
@media (max-width: 576px) {

    .card-grid,
    .user-grid {
        grid-template-columns: 1fr;
        /* Full width cards on very small screens */
        gap: 1rem;
    }

    .profile-header-card {
        padding: 1.5rem;
    }

    .profile-avatar-wrapper {
        width: 100px;
        height: 100px;
    }

    .profile-avatar-simple {
        width: 100px;
        height: 100px;
    }

    .profile-stats {
        gap: 1rem;
        padding: 0.75rem;
    }

    .stat-value {
        font-size: 1.1rem;
    }

    .search-input {
        font-size: 0.9rem;
    }
}

/* Sidebar Backdrop for Mobile */
.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    display: none;
    backdrop-filter: blur(2px);
}

.sidebar-backdrop.active {
    display: block;
}

/* --- Toast Notifications --- */
/* --- Premium Toast Notifications --- */
.toast-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* Start from dead center */
    z-index: 2147483647;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Center items inside */
    gap: 15px;
    pointer-events: none;
    width: 100%;
    max-width: 400px;
    padding: 0 1rem;
}

.toast {
    background: white;
    padding: 0;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: stretch;
    min-height: 64px;
    overflow: hidden;
    position: relative;
    pointer-events: auto;
    animation: toastSlideIn 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

/* Icon Box */
.toast-icon-box {
    width: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: white;
    flex-shrink: 0;
}

.toast.success .toast-icon-box {
    background: linear-gradient(135deg, #10b981, #059669);
}

.toast.error .toast-icon-box {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

.toast.info .toast-icon-box {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.toast.warning .toast-icon-box {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

/* Content */
.toast-content {
    flex: 1;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
}

.toast-message {
    color: var(--text-main);
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.4;
}

/* Progress Bar */
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    width: 100%;
    background: rgba(0, 0, 0, 0.1);
}

.toast-progress::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    animation: progress 4s linear forwards;
    transform-origin: left;
}

/* Flip progress for RTL */
html[dir="rtl"] .toast-progress::after {
    transform-origin: right;
    right: 0;
    left: auto;
}


@keyframes toastSlideIn {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    80% {
        transform: scale(1.05);
        opacity: 1;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: scale(0.9);
    }
}

@keyframes progress {
    from {
        transform: scaleX(1);
    }

    to {
        transform: scaleX(0);
    }
}

/* --- Custom Modal System --- */
.custom-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 2147483647;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    animation: fadeIn 0.3s forwards;
}

.custom-modal {
    background: var(--bg-surface);
    width: 90%;
    max-width: 400px;
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    transform: scale(0.9);
    opacity: 0;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    text-align: center;
    position: relative;
    margin: auto;
}

.custom-modal-icon {
    width: 64px;
    height: 64px;
    background: var(--bg-code);
    color: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    margin: 0 auto 1.5rem;
}

.custom-modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: var(--text-main);
}

.custom-modal-message {
    color: var(--text-muted);
    margin-bottom: 2rem;
    line-height: 1.6;
    font-size: 1rem;
}

.custom-modal-input {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    margin-bottom: 1.5rem;
    font-size: 1rem;
    outline: none;
    transition: all 0.2s;
    text-align: center;
    background: var(--bg-surface);
    color: var(--text-main);
}

.custom-modal-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.custom-modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.btn-modal {
    padding: 0.875rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    flex: 1;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    font-size: 1rem;
}

.btn-modal-cancel {
    background: var(--bg-code);
    color: var(--text-muted);
}

.btn-modal-cancel:hover {
    background: var(--border-color);
    color: var(--text-main);
}

.btn-modal-confirm {
    background: var(--primary-color);
    color: white;
}

[data-theme="dark"] .btn-modal-confirm {
    background: var(--accent-color);
    color: white;
}

.btn-modal-confirm:hover {
    background: var(--primary-light);
    transform: translateY(-1px);
}

[data-theme="dark"] .btn-modal-confirm:hover {
    background: var(--accent-hover);
}

.btn-modal-danger {
    background: #ef4444;
    color: white;
}

.btn-modal-danger:hover {
    background: #dc2626;
    transform: translateY(-1px);
}

/* --- Dark Mode Badge Overrides --- */
[data-theme="dark"] .badge {
    background: var(--bg-code);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .badge-sell {
    background: rgba(37, 99, 235, 0.2);
    color: #93c5fd;
    border-color: #1e40af;
}

[data-theme="dark"] .badge-exchange {
    background: rgba(22, 163, 74, 0.2);
    color: #86efac;
    border-color: #166534;
}

[data-theme="dark"] .badge-loan {
    background: rgba(202, 138, 4, 0.2);
    color: #fde047;
    border-color: #854d0e;
}



@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

@keyframes popIn {
    0% {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }

    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* --- Listing Details Page Redesign --- */
.details-container {
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.details-breadcrumb {
    margin-bottom: 2rem;
    color: var(--text-muted);
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.details-breadcrumb a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.details-breadcrumb a:hover {
    text-decoration: underline;
}

.details-card {
    background: var(--bg-surface);
    border-radius: 24px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: grid;
    grid-template-columns: 450px 1fr;
    /* Image | Content */
    gap: 0;
}

.details-image-section {
    background: var(--bg-code);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    border-left: 1px solid var(--border-color);
    /* RTL specific */
}

.details-hero-image {
    width: 100%;
    max-width: 400px;
    border-radius: 16px;
    box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.15);
    transition: transform 0.3s ease;
}

.details-hero-image:hover {
    transform: scale(1.02);
}

.details-content-section {
    padding: 3rem;
    display: flex;
    flex-direction: column;
}

.details-header {
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1.5rem;
}

.details-title {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-main);
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.details-badges {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.details-price {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--primary-color);
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.details-price small {
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: normal;
}

.details-meta-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.details-meta-item {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.meta-icon {
    width: 40px;
    height: 40px;
    background: var(--bg-code);
    color: var(--primary-color);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.meta-content h4 {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.meta-content p {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
}

.seller-mini-card {
    background: var(--bg-code);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.25rem;
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.seller-avatar {
    width: 50px;
    height: 50px;
    background: var(--gradient);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.25rem;
}

.action-buttons-area {
    margin-top: auto;
}

.btn-xl {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

@media (max-width: 992px) {
    .details-card {
        grid-template-columns: 1fr;
    }

    .details-image-section {
        border-left: none;
        border-bottom: 1px solid var(--border-color);
        padding: 1.5rem;
    }

    .details-content-section {
        padding: 1.5rem;
    }
}

/* --- Profile Header Card (Missing Styles) --- */
.profile-header-card {
    background: var(--bg-surface);
    border-radius: 20px;
    padding: 2rem;
    display: flex;
    align-items: center;
    gap: 2rem;
    box-shadow: var(--shadow-lg);
    margin-bottom: 2rem;
    border: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.profile-avatar-simple {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid var(--bg-body);
    box-shadow: var(--shadow-md);
    background: var(--bg-code);
}

.profile-info {
    flex: 1;
}

/* --- Chat / Messaging System --- */

.chat-layout {
    display: flex;
    height: calc(100vh - var(--header-height));
    background: var(--bg-surface);
    overflow: hidden;
}

/* Chat Sidebar */
.chat-sidebar {
    width: 350px;
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
}

.chat-sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.chat-sidebar-header h3 {
    margin-bottom: 1rem;
    font-size: 1.25rem;
    color: var(--text-main);
}

.chat-tabs {
    display: flex;
    gap: 0.5rem;
}

.chat-tab {
    flex: 1;
    padding: 0.5rem;
    border: none;
    background: none;
    color: var(--text-muted);
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: var(--transition);
}

.chat-tab.active {
    color: var(--text-main);
    border-color: var(--text-main);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.chat-item:hover,
.chat-item.active {
    background: var(--bg-code);
}

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-info {
    flex: 1;
    overflow: hidden;
}

.chat-name {
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.25rem;
}

.chat-preview {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent-color);
}

/* Chat Window */
.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-body);
    position: relative;
}

.chat-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

.chat-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--text-main);
    width: 80px;
    height: 80px;
    border: 2px solid var(--text-main);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Active Chat */
.active-chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    padding: 1rem 2rem;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-avatar-sm {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-user-details h4 {
    margin: 0;
    color: var(--text-main);
    font-size: 1rem;
}

.chat-user-details span {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.messages-area {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message-row {
    display: flex;
    flex-direction: column;
    max-width: 60%;
}

.message-row.me {
    align-self: flex-end;
    align-items: flex-end;
}

.message-row.them {
    align-self: flex-start;
    align-items: flex-start;
}

.message-bubble {
    padding: 0.75rem 1rem;
    border-radius: 20px;
    font-size: 0.95rem;
    line-height: 1.4;
    word-wrap: break-word;
}

.message-row.me .message-bubble {
    background: var(--accent-color);
    color: white;
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 4px;
}

.message-row.them .message-bubble {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 20px;
}

.message-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    margin-right: 0.5rem;
}

.chat-input-area {
    padding: 1.5rem;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 1rem;
}

.chat-input-area input {
    flex: 1;
    padding: 0.75rem 1rem;
    border-radius: 24px;
    border: 1px solid var(--border-color);
    background: var(--bg-body);
    font-family: inherit;
    color: var(--text-main);
    outline: none;
}

.chat-input-area input:focus {
    border-color: var(--accent-color);
}

.btn-send {
    background: none;
    border: none;
    color: var(--accent-color);
    font-size: 1.25rem;
    cursor: pointer;
    transition: transform 0.2s;
}

.btn-send:hover {
    transform: scale(1.1);
}

/* Mobile Responsive Chat */
@media (max-width: 768px) {
    .chat-sidebar {
        width: 100%;
    }

    .chat-window {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    [dir="rtl"] .chat-window {
        transform: translateX(100%);
    }

    .chat-window.open {
        transform: translateX(0);
    }

    .back-to-list {
        background: none;
        border: none;
        font-size: 1.2rem;
        color: var(--text-main);
        cursor: pointer;
        margin-left: 0.5rem;
    }
}



.profile-name {
    margin: 0 0 0.5rem 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

.profile-role-wrapper {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.profile-role-item {
    font-size: 0.9rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.profile-bio {
    color: var(--text-main);
    margin-bottom: 1.5rem;
    line-height: 1.6;
    max-width: 600px;
}

.profile-stats {
    display: flex;
    gap: 2rem;
    margin-bottom: 1.5rem;
    background: var(--bg-code);
    padding: 1rem;
    border-radius: 12px;
    display: inline-flex;
}

.stat-item {
    text-align: center;
    min-width: 80px;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.action-grid {
    display: flex;
    gap: 1rem;
}

@media (max-width: 768px) {
    .profile-header-card {
        flex-direction: column;
        text-align: center;
        padding: 1.5rem;
    }

    .profile-role-wrapper {
        justify-content: center;
    }

    .action-grid {
        justify-content: center;
        width: 100%;
    }

    .profile-stats {
        width: 100%;
        justify-content: space-around;
    }

    .profile-avatar-simple {
        width: 100px;
        height: 100px;
    }
}

/* --- Site Footer (Light Theme) --- */
.site-footer {
    background: var(--bg-surface);
    color: var(--text-muted);
    padding: 3rem 0 1.5rem;
    margin-top: auto;
    border-top: 1px solid var(--border-color);
    font-family: 'Cairo', sans-serif;
    width: 100%;
    margin-right: 0;
    /* Align with flow */
}

/* Ensure footer respects sidebar if inside main-content */
.main-content .site-footer {
    width: 100%;
}

.footer-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 2rem;
    direction: rtl;
}

.footer-column h3 {
    color: var(--text-main);
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1.25rem;
    position: relative;
    padding-bottom: 0.5rem;
}

.footer-column h3::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 40px;
    height: 3px;
    background: var(--primary-color);
    border-radius: 2px;
}

.footer-links {
    list-style: none;
    padding: 0;
    margin: 0;
}

.footer-links li {
    margin-bottom: 0.75rem;
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
}

.footer-links a:hover {
    color: var(--primary-color);
    transform: translateX(-3px);
}

.social-links {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

.social-btn {
    width: 36px;
    height: 36px;
    background: var(--bg-surface);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-color);
    text-decoration: none;
    transition: all 0.2s ease;
    border: 1px solid var(--border-color);
}

.social-btn:hover {
    background: var(--primary-color);
    color: #fff;
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(var(--primary-rgb), 0.1);
}

.contact-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.contact-item i {
    color: var(--primary-color);
    width: 20px;
    text-align: center;
}

.copyright {
    text-align: center;
    padding-top: 2rem;
    margin-top: 2rem;
    border-top: 1px solid #e2e8f0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .site-footer {
        padding-bottom: 5rem;
    }
}

/* --- Global Animations & Motion --- */

/* Keyframes */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

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

@keyframes pulse-subtle {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.02);
    }

    100% {
        transform: scale(1);
    }
}

/* Apply Animations */
.page-container {
    animation: fadeInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.auth-card {
    animation: fadeInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Staggered Grid Items */
.card-grid .book-card,
.user-grid .user-profile-card,
.stats-grid .stat-card {
    opacity: 0;
    /* Hidden initially */
    animation: fadeInUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Stagger delays for first 10 items to avoid lag on huge lists */
.card-grid .book-card:nth-child(1),
.user-grid .user-profile-card:nth-child(1) {
    animation-delay: 0.05s;
}

.card-grid .book-card:nth-child(2),
.user-grid .user-profile-card:nth-child(2) {
    animation-delay: 0.1s;
}

.card-grid .book-card:nth-child(3),
.user-grid .user-profile-card:nth-child(3) {
    animation-delay: 0.15s;
}

.card-grid .book-card:nth-child(4),
.user-grid .user-profile-card:nth-child(4) {
    animation-delay: 0.2s;
}

.card-grid .book-card:nth-child(5),
.user-grid .user-profile-card:nth-child(5) {
    animation-delay: 0.25s;
}

.card-grid .book-card:nth-child(6),
.user-grid .user-profile-card:nth-child(6) {
    animation-delay: 0.3s;
}

/* Interactive Elements */
.btn:active,
.book-card:active,
.nav-link:active {
    transform: scale(0.96) !important;
    /* Click press effect */
}

/* Sidebar Motion */
.sidebar .nav-link {
    transition: all 0.2s ease;
}

.sidebar .nav-link:hover {
    transform: translateX(-5px);
    /* Slide slightly left on hover (RTL) */
}

/* Enhanced Focus States */
input:focus,
select:focus,
textarea:focus {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
    border-color: var(--accent-color);
}

/* --- View Transition API (Theme Toggle "Beam" Effect) --- */
::view-transition-old(root),
::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
}

/* Ensure the new view is on top during transition */
::view-transition-new(root) {
    z-index: 10000;
}