@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800&display=swap');

:root {
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --primary-dark: #3730a3;
    --accent: #f59e0b;
    --bg-main: #f1f5f9;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --card-bg: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-md: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

body {
    font-family: 'Cairo', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    margin: 0;
    display: flex;
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
}



/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: #cbd5e1;
    padding: 1.25rem 0.75rem;
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease;
}

/* Sidebar backdrop (mobile overlay) */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: all 0.3s ease;
}

.sidebar-backdrop.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.sidebar-header {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 2rem;
    padding: 0 1rem;
    background: linear-gradient(135deg, #818cf8, #c084fc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.6rem 0.875rem;
    color: #94a3b8;
    text-decoration: none;
    border-radius: 0.6rem;
    transition: all 0.2s ease;
    margin-bottom: 0.25rem;
    font-weight: 500;
    font-size: 0.925rem;
}

.nav-link i {
    width: 24px;
    font-size: 1.1rem;
    margin-left: 0.75rem;
    display: flex;
    justify-content: center;
}

.nav-link:hover {
    background-color: var(--sidebar-hover);
    color: #f8fafc;
}

.nav-link.active {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
}

/* Main Content */
.main-content {
    margin-right: 260px;
    /* Match sidebar width */
    flex: 1;
    padding: 2.5rem;
    transition: margin 0.3s ease;
    min-width: 0;
}

/* Mobile Toggle */
.mobile-toggle {
    display: none;
    background: white;
    border: 1px solid var(--border);
    padding: 0.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 1.25rem;
    color: var(--text-main);
}

/* Responsive */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(110%);
        transition: transform 0.3s ease;
    }

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


    .main-content {
        margin-right: 0;
        padding: 1rem;
    }

    .mobile-toggle {
        display: block;
    }

    .header {
        padding: 0.75rem 1rem;
        margin-bottom: 1rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    .stat-card {
        padding: 1.25rem;
    }

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

    /* Stack grid children on tablet/mobile */
    .dashboard-grid {
        grid-template-columns: 1fr !important;
    }

    .show-grid {
        grid-template-columns: 1fr !important;
    }

    /* DataTables mobile fixes */
    .dataTables_wrapper .dataTables_filter input {
        width: 160px;
    }

    .dataTables_wrapper .dataTables_filter input:focus {
        width: 200px;
    }

    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        float: none;
        text-align: right;
    }
}

@media (max-width: 640px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .stat-card {
        padding: 1rem;
    }

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

    .stat-label {
        font-size: 0.8rem;
    }

    .header h1 {
        font-size: 1.1rem;
    }

    .header {
        padding: 0.625rem 0.875rem;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    .user-info span {
        display: none;
    }

    .auth-card {
        padding: 1.5rem;
        max-width: 90%;
    }

    /* DataTables: stack top controls */
    .dataTables_wrapper .dataTables_length {
        margin-bottom: 0.5rem;
    }

    .dataTables_wrapper .dataTables_filter input {
        width: 130px;
    }

    .dataTables_wrapper .dataTables_filter input:focus {
        width: 160px;
    }

    /* Make table horizontally scrollable */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table.dataTable {
        min-width: 500px;
    }

    /* Cards padding */
    .card {
        padding: 1rem;
    }

    /* AI tools form */
    .ai-tools-form>div {
        grid-template-columns: 1fr !important;
    }
}

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

    .main-content {
        padding: 0.75rem;
    }

    .header {
        border-radius: 0.75rem;
    }

    .header h1 {
        font-size: 1rem;
    }

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

    .dataTables_wrapper .dataTables_paginate .paginate_button {
        padding: 0.3rem 0.5rem !important;
        font-size: 0.7rem !important;
    }
}

/* Action Buttons in DataTables */
.action-btn {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
}

.action-btn.view {
    background-color: #eff6ff;
    color: #3b82f6;
}

.action-btn.view:hover {
    background-color: #3b82f6;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.action-btn.edit {
    background-color: #f8fafc;
    color: #64748b;
}

.action-btn.edit:hover {
    background-color: #64748b;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(100, 116, 139, 0.3);
}

.action-btn.delete {
    background-color: #fff1f2;
    color: #ef4444;
}

.action-btn.delete:hover {
    background-color: #ef4444;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
    background: white;
    padding: 1rem 2rem;
    border-radius: 1rem;
    box-shadow: var(--shadow-sm);
}

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

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    color: var(--text-main);
}

.user-avatar {
    width: 40px;
    height: 40px;
    background: var(--primary-light);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 1.25rem;
    box-shadow: var(--shadow);
    padding: 1.5rem;
    border: 1px solid var(--border);
    transition: transform 0.2s ease;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

/* Dashboard two-column grid (charts & tables) */
.dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
}

.stat-card {
    position: relative;
    overflow: hidden;
    padding: 1.75rem;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background-color: var(--primary);
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-main);
    margin-top: 0.5rem;
}

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

/* Tables */
.table-container {
    overflow-x: auto;
    background: white;
    border-radius: 0.75rem;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

th {
    background-color: #f8fafc;
    text-align: right;
    padding: 1.25rem 1rem;
    color: var(--text-muted);
    font-weight: 700;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tr:hover td {
    background-color: #f8fafc;
}

/* Auth Pages */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 100vh;
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    padding: 2.5rem;
    border-radius: 1.5rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #475569;
}

input,
select,
textarea {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    font-size: 0.95rem;
    box-sizing: border-box;
    font-family: 'Cairo', sans-serif;
    transition: all 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}

.btn {
    padding: 0.875rem 1.5rem;
    border-radius: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-decoration: none;
    font-size: 0.95rem;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2);
}

.btn-primary:hover {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 10px 15px -3px rgba(79, 70, 229, 0.3);
}

.btn-secondary {
    background-color: #e2e8f0;
    color: #475569;
}

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

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

.alert {
    padding: 1.25rem;
    border-radius: 0.75rem;
    margin-bottom: 1.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.alert-error {
    background-color: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-success {
    background-color: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

/* Pagination */
.pagination {
    display: flex;
    gap: 0.5rem;
    margin-top: 2rem;
    justify-content: center;
}

.page-item {
    list-style: none;
}

.page-link {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text-main);
    text-decoration: none;
    background: white;
}

.active .page-link {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Global DataTables Styling */
.dataTables_wrapper {
    padding: 0;
}

.dataTables_wrapper .dataTables_length label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #64748b;
    font-size: 0.85rem;
    font-weight: 600;
}

.dataTables_wrapper .dataTables_length select {
    padding: 0.4rem 2rem 0.4rem 0.75rem !important;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    font-weight: 700;
    color: #1e293b;
    cursor: pointer;
    background-color: #f8fafc;
}

.dataTables_wrapper .dataTables_filter label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #64748b;
    font-weight: 600;
    font-size: 0.85rem;
}

.dataTables_wrapper .dataTables_filter input {
    width: 250px;
    padding: 0.6rem 1rem !important;
    border-radius: 12px;
    border: 1.5px solid #e2e8f0;
    background: #f8fafc;
    transition: all 0.3s ease;
}

.dataTables_wrapper .dataTables_filter input:focus {
    width: 300px;
    background: white;
    border-color: #4f46e5;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
    outline: none;
}

/* Table Design */
table.dataTable {
    border: none !important;
    border-spacing: 0 !important;
    margin: 1.5rem 0 !important;
}

table.dataTable thead th {
    padding: 1rem !important;
    background: #f8fafc !important;
    color: #475569 !important;
    font-size: 0.75rem !important;
    font-weight: 800 !important;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid #e2e8f0 !important;
}

table.dataTable tbody tr td {
    padding: 1.25rem 1rem !important;
    border-bottom: 1px solid #f1f5f9 !important;
    vertical-align: middle;
}

table.dataTable tbody tr:hover {
    background-color: #f1f5f9 !important;
}

/* Pagination */
.dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 0.4rem 0.9rem !important;
    margin: 0 0.15rem !important;
    border-radius: 10px !important;
    border: 1px solid #e2e8f0 !important;
    background: white !important;
    color: #475569 !important;
    font-weight: 700 !important;
    font-size: 0.8rem !important;
    transition: all 0.2s;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: #f1f5f9 !important;
    border-color: #cbd5e1 !important;
    color: #4f46e5 !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: #4f46e5 !important;
    border-color: #4f46e5 !important;
    color: white !important;
}

/* Helpers */
.d-flex {
    display: flex !important;
}

.justify-content-between {
    justify-content: space-between !important;
}

.align-items-center {
    align-items: center !important;
}

.mb-4 {
    margin-bottom: 1.5rem !important;
}

.mt-4 {
    margin-top: 1.5rem !important;
}

/* RTL Fixes */
[dir="rtl"] .dataTables_wrapper .dataTables_filter {
    text-align: left;
}

[dir="rtl"] .dataTables_wrapper .dataTables_length {
    text-align: right;
}

[dir="rtl"] .dataTables_wrapper .dataTables_paginate {
    text-align: left;
}

[dir="rtl"] .dataTables_wrapper .dataTables_info {
    text-align: right;
}