/* ============ SANAD+ Admin Design System ============ */
:root {
    --primary: #0EA5E9;
    --primary-hover: #0284C7;
    --primary-light: #E0F2FE;
    --secondary: #38BDF8;
    --background: #F0F9FF;
    --surface: #FFFFFF;
    --text: #0F172A;
    --text-secondary: #64748B;
    --muted: #94A3B8;
    --border: #E2E8F0;
    --success: #10B981;
    --success-bg: #D1FAE5;
    --warning: #F59E0B;
    --warning-bg: #FEF3C7;
    --error: #EF4444;
    --error-bg: #FEE2E2;
    --info-bg: #DBEAFE;

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;

    --topbar-h: 60px;
    --sidebar-w: 260px;

    --shadow-sm: 0 1px 3px rgba(15,23,42,0.04);
    --shadow: 0 2px 8px rgba(15,23,42,0.06);
    --shadow-lg: 0 8px 24px rgba(15,23,42,0.10);

    --transition: 200ms ease;
}

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

html, body {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

body {
    font-family: 'Cairo', 'Tajawal', system-ui, sans-serif;
    background: var(--background);
    color: var(--text);
    direction: rtl;
    font-size: 15px;
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
}

/* ============ Header ============ */
.admin-topbar {
    position: fixed;
    top: 0; right: 0; left: 0;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.admin-topbar-right, .admin-topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-text {
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--text);
}

.highlight { color: var(--primary); }

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

.icon-btn:hover { background: var(--primary-light); color: var(--primary); }
.icon-btn .material-icons { font-size: 22px; }

.admin-badge {
    background: var(--primary);
    color: white;
    padding: 4px 12px;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 700;
}

/* ============ Sidebar ============ */
.sidebar {
    position: fixed;
    top: var(--topbar-h);
    right: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    padding: 16px 12px;
    z-index: 95;
    transform: translateX(100%);
    transition: transform 250ms ease;
}

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

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.5);
    opacity: 0;
    pointer-events: none;
    z-index: 90;
    transition: opacity 250ms ease;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--radius);
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    transition: var(--transition);
    text-align: right;
    width: 100%;
}

.sidebar-item:hover { background: var(--primary-light); color: var(--primary); }

.sidebar-item.active {
    background: var(--primary-light);
    color: var(--primary-hover);
}

.sidebar-item .material-icons { font-size: 20px; }

/* ============ Content ============ */
.admin-content {
    margin-top: var(--topbar-h);
    padding: 16px;
    min-height: calc(100vh - var(--topbar-h));
    max-width: 100vw;
}

.section-title {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 16px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.section-header .section-title { margin-bottom: 0; }

.admin-section { display: none; }
.admin-section.active { display: block; animation: fadeIn 250ms ease; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============ Dashboard Stats ============ */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

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

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}

.stat-icon .material-icons { font-size: 22px; }

.stat-icon-primary { background: var(--primary-light); color: var(--primary); }
.stat-icon-info { background: var(--info-bg); color: #2563EB; }
.stat-icon-success { background: var(--success-bg); color: var(--success); }
.stat-icon-warning { background: var(--warning-bg); color: var(--warning); }

.stat-number {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 2px;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ============ Card ============ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-header h3 {
    font-size: 1.05rem;
    font-weight: 700;
}

/* ============ Buttons ============ */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 10px 18px;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary .material-icons { font-size: 18px; }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 9px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    font-family: inherit;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-outline .material-icons { font-size: 16px; }

.btn-danger {
    background: var(--error);
    color: white;
    border: none;
    padding: 9px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    font-family: inherit;
    transition: var(--transition);
}

.btn-danger:hover { background: #DC2626; }

.btn-success {
    background: var(--success);
    color: white;
    border: none;
    padding: 9px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    font-family: inherit;
}

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ============ Search Box ============ */
.search-box {
    display: flex;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 14px;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.search-box .material-icons {
    color: var(--muted);
    font-size: 20px;
}

.search-box input {
    border: none;
    outline: none;
    background: none;
    font-family: inherit;
    font-size: 0.9rem;
    flex: 1;
    min-width: 0;
    color: var(--text);
}

.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.toolbar .search-box { min-width: 200px; }

/* ============ Filters ============ */
.advanced-filters {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 16px;
    background: var(--surface);
    padding: 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-group label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
}

.filter-group input,
.filter-group select {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
    width: 100%;
}

.filter-group input:focus,
.filter-group select:focus { border-color: var(--primary); }

/* ============ Table ============ */
.table-container {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow-x: auto;
    box-shadow: var(--shadow-sm);
}

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

th, td {
    padding: 12px 14px;
    text-align: right;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

th {
    background: var(--background);
    font-weight: 700;
    color: var(--text-secondary);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--primary-light); }

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

.category-card, .payment-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.category-card:hover, .payment-card:hover {
    box-shadow: var(--shadow);
    border-color: var(--primary);
}

.card-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius);
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 10px;
    overflow: hidden;
    font-size: 1.5rem;
}

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

.card-title {
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 4px;
    word-break: break-word;
}

.card-actions {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-top: 10px;
    flex-wrap: wrap;
}

.card-actions .btn-danger,
.card-actions .btn-outline {
    padding: 6px 10px;
    font-size: 0.78rem;
}

/* ============ Status Badges ============ */
.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 50px;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
}

.status-badge.completed, .status-badge.approved, .status-badge.verified {
    background: var(--success-bg);
    color: #047857;
}

.status-badge.failed, .status-badge.rejected {
    background: var(--error-bg);
    color: #B91C1C;
}

.status-badge.pending, .status-badge.review {
    background: var(--warning-bg);
    color: #B45309;
}

.status-badge.processing, .status-badge.cancelled {
    background: var(--info-bg);
    color: #1D4ED8;
}

.vip-badge {
    background: linear-gradient(135deg, #FCD34D, #F59E0B);
    color: #78350F;
    font-weight: 800;
    padding: 3px 10px;
    border-radius: 50px;
    font-size: 0.72rem;
    display: inline-block;
}

/* ============ Modal ============ */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.5);
    z-index: 200;
    overflow-y: auto;
    padding: 16px;
}

.modal.active { display: flex; align-items: center; justify-content: center; }

.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 100%;
    max-width: 520px;
    position: relative;
    animation: modalIn 250ms ease;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
}

@keyframes modalIn {
    from { transform: translateY(16px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 8px;
}

.close-modal {
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary);
    background: none;
    border: none;
    padding: 4px;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-modal:hover { background: var(--background); color: var(--text); }

/* ============ Confirm Modal ============ */
.confirm-content {
    text-align: center;
    max-width: 400px;
}

.confirm-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--warning-bg);
    color: var(--warning);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.confirm-icon.danger { background: var(--error-bg); color: var(--error); }
.confirm-icon .material-icons { font-size: 32px; }

.confirm-content h3 {
    font-size: 1.15rem;
    font-weight: 800;
    margin-bottom: 8px;
}

.confirm-content p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 20px;
    line-height: 1.6;
}

.confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.confirm-actions button {
    min-width: 100px;
    justify-content: center;
}

/* ============ Form ============ */
.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 6px;
    color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--primary); }

.form-group textarea { resize: vertical; min-height: 80px; }

.image-preview {
    width: 100%;
    height: 100px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 8px;
    overflow: hidden;
}

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

/* ============ Empty State ============ */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.empty-state .material-icons {
    font-size: 40px;
    display: block;
    margin-bottom: 10px;
    color: var(--muted);
}

/* ============ Toast ============ */
.toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: calc(100% - 32px);
    max-width: 400px;
    pointer-events: none;
}

.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    animation: toastIn 250ms ease;
    pointer-events: auto;
    border-right: 4px solid var(--primary);
}

.toast.success { border-right-color: var(--success); }
.toast.error { border-right-color: var(--error); }
.toast.warning { border-right-color: var(--warning); }

.toast .material-icons { font-size: 20px; }
.toast.success .material-icons { color: var(--success); }
.toast.error .material-icons { color: var(--error); }
.toast.warning .material-icons { color: var(--warning); }
.toast.info .material-icons { color: var(--primary); }

@keyframes toastIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.toast.hiding { animation: toastOut 200ms ease forwards; }

@keyframes toastOut {
    to { transform: translateY(20px); opacity: 0; }
}

/* ============ Loading Skeleton ============ */
.skeleton {
    background: linear-gradient(90deg, #F1F5F9 25%, #E2E8F0 50%, #F1F5F9 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 6px;
    height: 16px;
    display: inline-block;
    width: 100%;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============ Login Screen ============ */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--background);
    padding: 20px;
}

.login-box {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

.login-box h2 {
    text-align: center;
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 24px;
}

/* ============ Tablet ≥ 640px ============ */
@media (min-width: 640px) {
    .admin-content { padding: 20px 24px; }
    .stats-cards { grid-template-columns: repeat(4, 1fr); gap: 14px; }
    .advanced-filters { grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto; }
    .section-title { font-size: 1.5rem; }
}

/* ============ Desktop ≥ 1024px ============ */
@media (min-width: 1024px) {
    .sidebar {
        transform: translateX(0);
        z-index: 90;
    }
    .sidebar-overlay { display: none !important; }
    .menu-btn { display: none; }
    .admin-content {
        margin-right: var(--sidebar-w);
        padding: 24px 32px;
        max-width: calc(100vw - var(--sidebar-w));
    }
    .stat-card { padding: 20px; }
    .stat-number { font-size: 1.6rem; }
}

/* ============ Mobile < 640px — Tables as Cards ============ */
@media (max-width: 639px) {
    /* Table to card transformation */
    .table-container {
        background: transparent;
        border: none;
        box-shadow: none;
        overflow: visible;
    }

    .table-container table,
    .table-container thead,
    .table-container tbody,
    .table-container th,
    .table-container td,
    .table-container tr {
        display: block;
        width: 100%;
    }

    .table-container thead { display: none; }

    .table-container tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 14px;
        margin-bottom: 10px;
        box-shadow: var(--shadow-sm);
    }

    .table-container tr:hover td { background: transparent; }

    .table-container td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 10px;
        padding: 8px 0;
        border-bottom: 1px solid var(--background);
        font-size: 0.85rem;
        text-align: left;
    }

    .table-container td:last-child { border-bottom: none; padding-bottom: 0; }
    .table-container td:first-child { padding-top: 0; }

    .table-container td::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--text-secondary);
        font-size: 0.75rem;
        flex-shrink: 0;
        min-width: 80px;
    }

    .table-container td > * {
        text-align: left;
    }

    .table-container td[data-label="إجراءات"],
    .table-container td[data-label="الصورة"] {
        flex-direction: column;
        align-items: stretch;
    }

    .table-container td[data-label="إجراءات"]::before,
    .table-container td[data-label="الصورة"]::before {
        margin-bottom: 6px;
    }

    .table-container img {
        max-width: 60px;
        max-height: 60px;
        border-radius: 8px;
        object-fit: cover;
    }

    /* Cards grid smaller */
    .cards-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }

    /* Buttons block on mobile in toolbar */
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar .search-box,
    .toolbar .btn-outline { width: 100%; justify-content: center; }

    /* Section header stack */
    .section-header {
        flex-direction: column;
        align-items: stretch;
    }

    .section-header .btn-primary,
    .section-header .btn-outline {
        width: 100%;
        justify-content: center;
    }

    /* Modal full width */
    .modal-content {
        padding: 20px 16px;
        border-radius: var(--radius);
    }

    /* Stat cards compact */
    .stat-card { padding: 14px; }
    .stat-number { font-size: 1.25rem; }
    .stat-icon { width: 36px; height: 36px; }
    .stat-icon .material-icons { font-size: 20px; }
}

/* ============ Small mobile < 360px ============ */
@media (max-width: 359px) {
    .stats-cards { grid-template-columns: 1fr; }
    .cards-grid { grid-template-columns: 1fr; }
    .admin-content { padding: 12px; }
}

/* ============ LTR for technical values ============ */
.ltr { direction: ltr; unicode-bidi: embed; display: inline-block; }

/* ============ Scrollbar ============ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }