:root {
    --primary: #6c5ce7;
    --primary-dark: #5849be;
    --secondary: #a29bfe;
    --bg-dark: #1e272e;
    --bg-lighter: #2d3436;
    --text-light: #dfe6e9;
    --text-muted: #b2bec3;
    --danger: #e74c3c;
    --success: #00b894;
    --warning: #fdcb6e;
    --sidebar-width: 260px;
    --header-height: 70px;
}

.hidden {
    display: none !important;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Cairo', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-light);
    direction: rtl;
    overflow-x: hidden;
}

/* Auth Overlay */
.auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
}

.auth-box {
    background: var(--bg-lighter);
    padding: 40px;
    border-radius: 12px;
    width: 400px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.auth-box h2 {
    color: var(--primary);
    margin-bottom: 10px;
}

.auth-box .hint {
    font-size: 0.9em;
    color: var(--text-muted);
    margin-bottom: 20px;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
    text-align: right;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-muted);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #444;
    background: #111;
    color: white;
    font-family: inherit;
    box-sizing: border-box;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    width: 100%;
    transition: 0.3s;
}

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

/* Sidebar */
.sidebar {
    position: fixed;
    right: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-lighter);
    display: flex;
    flex-direction: column;
    border-left: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--primary);
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
    overflow-y: auto;
}

.nav-item {
    width: 100%;
    padding: 15px 20px;
    /* Reduced from 25px to bring closer to right */
    background: none;
    border: none;
    border-right: 4px solid transparent;
    /* Fixes the jumping glitch */
    color: var(--text-muted);
    text-align: right;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 1rem;
    transition: all 0.2s ease;
    /* Smooth transition */
}

.nav-item:hover,
.nav-item.active {
    background: rgba(108, 92, 231, 0.1);
    color: var(--primary);
    border-right: 4px solid var(--primary);
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.nav-item.logout {
    color: var(--danger);
}

.nav-item.logout:hover {
    background: rgba(231, 76, 60, 0.1);
}

/* Main Content */
.main-content {
    margin-right: var(--sidebar-width);
    min-height: 100vh;
}

.top-bar {
    height: var(--header-height);
    background: var(--bg-lighter);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 30px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

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

.user-menu .avatar {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.content-area {
    padding: 30px;
}

/* Sections */
.section {
    display: none;
    animation: fadeIn 0.3s;
}

.section.active {
    display: block;
}

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

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

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--bg-lighter);
    padding: 24px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.stat-card .icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.icon.users {
    background: rgba(52, 152, 219, 0.15);
    color: #3498db;
}

.icon.posts {
    background: rgba(155, 89, 182, 0.15);
    color: #9b59b6;
}

.icon.revenue {
    background: rgba(46, 204, 113, 0.15);
    color: #2ecc71;
}

.icon.reports {
    background: rgba(231, 76, 60, 0.15);
    color: #e74c3c;
}

.stat-card .info h3 {
    margin: 0 0 5px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.stat-card .info p {
    margin: 0;
    font-size: 1.5rem;
    font-weight: bold;
}

/* Tables */
.table-container {
    background: var(--bg-lighter);
    border-radius: 12px;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 15px 20px;
    text-align: right;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.9rem;
}

td {
    color: var(--text-light);
}

.status-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: bold;
}

.status-active {
    background: rgba(46, 204, 113, 0.15);
    color: #2ecc71;
}

.status-banned {
    background: rgba(231, 76, 60, 0.15);
    color: #e74c3c;
}

.status-pending {
    background: rgba(241, 196, 15, 0.15);
    color: #f1c40f;
}

.action-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    margin-left: 10px;
    padding: 5px;
    transition: 0.2s;
}

.action-btn:hover {
    color: var(--text-light);
    transform: scale(1.1);
}

.action-btn.delete:hover {
    color: var(--danger);
}

.action-btn.edit:hover {
    color: var(--primary);
}

/* Cards Grid (Posts) */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.admin-card {
    background: var(--bg-lighter);
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.admin-card img {
    width: 100%;
    height: 200px;
    object-fit: cover;
}

.admin-card .content {
    padding: 15px;
}

.admin-card .meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}

.admin-card-actions {
    padding: 10px 15px;
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    /* Changed from center to allow scrolling from top */
    padding: 20px;
    overflow-y: auto;
    box-sizing: border-box;
}

.modal-content {
    background: var(--bg-lighter);
    padding: 30px;
    border-radius: 12px;
    width: 500px;
    max-width: 100%;
    margin: auto;
    /* Centers it if smaller than viewport, otherwise allows scrolling */
    position: relative;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    animation: slideUp 0.3s;
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.5);
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

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

/* Toolbar */
.toolbar {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    background: var(--bg-lighter);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.toolbar label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    color: var(--text-light);
    font-size: 0.95rem;
    user-select: none;
}

.toolbar input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

#delete-selected-comments {
    margin-right: auto;
    width: auto;
    font-size: 0.9rem;
    padding: 8px 20px;
}

.comment-checkbox {
    accent-color: var(--primary);
}

/* Sidebar Toggle Button (Hidden by default) */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 10px;
    margin-left: 10px;
}

.header-left {
    display: flex;
    align-items: center;
}

/* Responsive Styles */
@media (max-width: 992px) {
    :root {
        --sidebar-width: 0px;
        /* Disable margin on main content */
    }

    .sidebar {
        width: 260px;
        z-index: 10001;
        right: -260px;
        /* Hide off-screen */
        transition: right 0.3s ease;
    }

    .sidebar.show {
        right: 0;
    }

    .main-content {
        margin-right: 0;
    }

    .sidebar-toggle {
        display: block;
    }

    .top-bar {
        padding: 0 15px;
    }

    .top-bar h1 {
        font-size: 1.2rem;
    }

    .user-menu span {
        display: none;
        /* Hide name on mobile */
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 600px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        padding: 15px;
    }

    .stat-card .info p {
        font-size: 1.2rem;
    }

    .content-area {
        padding: 15px;
    }

    .auth-box {
        width: 90%;
        padding: 20px;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar input,
    .toolbar select {
        width: 100%;
    }

    .cards-grid {
        grid-template-columns: 1fr;
    }

    /* تحويل الجداول إلى كروت في الشاشات الصغيرة جداً */
    .table-container {
        border: none;
        background: none;
    }

    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    tr {
        background: var(--bg-lighter);
        margin-bottom: 20px;
        border-radius: 12px;
        padding: 10px;
        border: 1px solid rgba(255, 255, 255, 0.05);
        display: flex;
        flex-direction: column;
    }

    td {
        border: none;
        position: relative;
        padding-right: 45% !important;
        text-align: left !important;
        min-height: 40px;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
        font-size: 0.85rem;
    }

    td:before {
        position: absolute;
        right: 15px;
        width: 40%;
        white-space: nowrap;
        font-weight: bold;
        color: var(--primary);
        content: attr(data-label);
        text-align: right;
    }

    td:last-child {
        border-bottom: none !important;
        justify-content: center;
        padding: 15px 10px !important;
        flex-wrap: wrap;
        gap: 5px;
    }

    td:last-child:before {
        display: none;
    }

    /* تحسين الأزرار في الجوال */
    .action-btn {
        padding: 8px 12px;
        margin: 2px;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 8px;
        font-size: 0.8rem;
        flex: 1;
        min-width: 80px;
        text-align: center;
    }

    .modal-content {
        padding: 20px;
        border-radius: 12px;
        width: 95%;
        margin: 10px auto;
    }
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
}

.sidebar-overlay.show {
    display: block;
}