        <?php if ($current_tab === 'address'): ?>
            <!-- Address & Contacts Tab -->
            <div class="fs-tab-pane">
                <div class="fs-client-info-section">
                    <h3><?php esc_html_e('Client information', 'freelance-studio'); ?></h3>
                    
                    <div class="fs-info-grid">
                        <div class="fs-info-row">
                            <div class="fs-info-field">
                                <label><?php esc_html_e('Company name', 'freelance-studio'); ?></label>
                                <div class="fs-info-value"><?php echo esc_html($display_name); ?></div>
                            </div>
                        </div>
                        
                        <div class="fs-info-row two-col">
                            <div class="fs-info-field">
                                <label><?php esc_html_e('Street address', 'freelance-studio'); ?></label>
                                <div class="fs-info-value"><?php echo esc_html($client->address ?: '-'); ?></div>
                            </div>
                            <div class="fs-info-field">
                                <label><?php esc_html_e('Apt/Unit', 'freelance-studio'); ?></label>
                                <div class="fs-info-value"><?php echo isset($client->address_2) && $client->address_2 ? esc_html($client->address_2) : '-'; ?></div>
                            </div>
                        </div>
                        
                        <div class="fs-info-row two-col">
                            <div class="fs-info-field">
                                <label><?php esc_html_e('City', 'freelance-studio'); ?></label>
                                <div class="fs-info-value"><?php echo esc_html($client->city ?: '-'); ?></div>
                            </div>
                            <div class="fs-info-field">
                                <label><?php esc_html_e('Zip code', 'freelance-studio'); ?></label>
                                <div class="fs-info-value"><?php echo esc_html($client->zip ?: '-'); ?></div>
                            </div>
                        </div>
                        
                        <div class="fs-info-row two-col">
                            <div class="fs-info-field">
                                <label><?php esc_html_e('Country', 'freelance-studio'); ?></label>
                                <div class="fs-info-value"><?php echo esc_html($client->country ?: 'United States'); ?></div>
                            </div>
                            <div class="fs-info-field">
                                <label><?php esc_html_e('State', 'freelance-studio'); ?></label>
                                <div class="fs-info-value"><?php echo esc_html($client->state ?: '-'); ?></div>
                            </div>
                        </div>
                    </div>
                    
                    <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-clients&action=edit&id=' . $client->id) ); ?>" class="button button-primary">
                        <?php esc_html_e('Save changes', 'freelance-studio'); ?>
                    </a>
                </div>
                
                <!-- Client Portal Section -->
                <?php 
                $portal_url = FS_Client::get_portal_url($client->id);
                ?>
                <div class="fs-portal-link-section">
                    <div class="fs-section-header">
                        <h3><?php esc_html_e('Client Portal', 'freelance-studio'); ?></h3>
                    </div>
                    
                    <?php if ($client->portal_enabled && $portal_url): ?>
                    <p class="description"><?php esc_html_e('Share this link with your client to give them access to their portal where they can view projects, invoices, and proposals.', 'freelance-studio'); ?></p>
                    <div class="fs-link-copy-group">
                        <input type="text" readonly class="fs-copy-link" value="<?php echo esc_url($portal_url); ?>" id="fs-portal-link">
                        <button type="button" class="button" onclick="navigator.clipboard.writeText(document.getElementById('fs-portal-link').value); this.textContent='<?php esc_html_e('Copied!', 'freelance-studio'); ?>';">
                            <?php esc_html_e('Copy Link', 'freelance-studio'); ?>
                        </button>
                        <a href="<?php echo esc_url($portal_url); ?>" class="button" target="_blank">
                            <?php esc_html_e('Preview', 'freelance-studio'); ?>
                        </a>
                    </div>
                    <?php else: ?>
                    <p class="description"><?php esc_html_e('Portal access is disabled for this client.', 'freelance-studio'); ?></p>
                    <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-clients&action=edit&id=' . $client->id) ); ?>" class="button">
                        <?php esc_html_e('Enable Portal Access', 'freelance-studio'); ?>
                    </a>
                    <?php endif; ?>
                </div>
                
                <!-- Contacts Section -->
                <div class="fs-contacts-section">
                    <div class="fs-section-header">
                        <h3><?php esc_html_e('Contacts', 'freelance-studio'); ?></h3>
                        <button type="button" class="fs-btn fs-btn-secondary fs-btn-small fs-add-contact-btn" data-client-id="<?php echo  intval( $client->id ); ?>">
                            <?php esc_html_e('+ Add contact', 'freelance-studio'); ?>
                        </button>
                    </div>
                    
                    <table class="fs-table fs-contacts-table widefat">
                        <thead>
                            <tr>
                                <th><?php esc_html_e('Contact name', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Role', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Email', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Phone', 'freelance-studio'); ?></th>
                                <th class="column-actions"></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if (!empty($contacts)): ?>
                                <?php foreach ($contacts as $contact): ?>
                                    <tr data-contact-id="<?php echo  intval( $contact->id ); ?>">
                                        <td>
                                            <strong><?php echo esc_html($contact->name); ?></strong>
                                            <?php if (!empty($contact->is_primary)): ?>
                                                <span class="fs-badge primary"><?php esc_html_e('Primary', 'freelance-studio'); ?></span>
                                            <?php endif; ?>
                                            <?php if (!empty($contact->is_billing_contact)): ?>
                                                <span class="fs-badge billing"><?php esc_html_e('Billing', 'freelance-studio'); ?></span>
                                            <?php endif; ?>
                                            <?php if (!empty($contact->is_project_contact)): ?>
                                                <span class="fs-badge project"><?php esc_html_e('Project', 'freelance-studio'); ?></span>
                                            <?php endif; ?>
                                        </td>
                                        <td><?php echo !empty($contact->role) ? esc_html($contact->role) : '<span class="text-muted">-</span>'; ?></td>
                                        <td>
                                            <?php if (!empty($contact->email)): ?>
                                                <a href="mailto:<?php echo esc_attr($contact->email); ?>"><?php echo esc_html($contact->email); ?></a>
                                            <?php else: ?>
                                                -
                                            <?php endif; ?>
                                        </td>
                                        <td><?php echo !empty($contact->phone) ? esc_html($contact->phone) : '-'; ?></td>
                                        <td class="column-actions">
                                            <button type="button" class="fs-icon-btn fs-edit-contact" data-contact-id="<?php echo  intval( $contact->id ); ?>" title="<?php esc_attr_e('Edit', 'freelance-studio'); ?>"><span class="dashicons dashicons-edit"></span></button>
                                            <button type="button" class="fs-icon-btn fs-delete-contact" data-contact-id="<?php echo  intval( $contact->id ); ?>" title="<?php esc_attr_e('Delete', 'freelance-studio'); ?>"><span class="dashicons dashicons-trash"></span></button>
                                        </td>
                                    </tr>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <tr>
                                    <td colspan="5" class="text-muted text-center">
                                        <?php esc_html_e('No contacts added yet. Add contacts via the Edit Client page.', 'freelance-studio'); ?>
                                    </td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            
        <?php elseif ($current_tab === 'projects'): ?>
            <!-- Projects Tab -->
            <div class="fs-tab-pane">
                <div class="fs-tab-header">
                    <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-projects&action=add&client_id=' . $client->id) ); ?>" class="fs-btn fs-btn-primary">
                        <?php esc_html_e('New Project', 'freelance-studio'); ?>
                    </a>
                </div>
                
                <?php if (empty($projects)): ?>
                    <div class="fs-empty-state small">
                        <p><?php esc_html_e('No projects yet.', 'freelance-studio'); ?></p>
                    </div>
                <?php else: ?>
                    <!-- Mobile Project Cards -->
                    <div class="fs-invoice-mobile-list fs-mobile-only">
                        <?php foreach ($projects as $project): 
                            $project_value = '';
                            if ($project->billing_type === 'fixed') {
                                $project_value = FS_View_Context::format_currency($project->fixed_price);
                            } elseif ($project->billing_type === 'retainer') {
                                $project_value = FS_View_Context::format_currency($project->retainer_amount) . '/mo';
                            } else {
                                $p_rate = get_option('fs_default_hourly_rate', 75);
                                $p_svcs = $project->services;
                                if (is_string($p_svcs)) $p_svcs = json_decode($p_svcs, true);
                                if (!empty($p_svcs) && is_array($p_svcs)) {
                                    foreach ($p_svcs as $svc) {
                                        if (isset($svc['pricing_type']) && $svc['pricing_type'] === 'hourly' && !empty($svc['rate'])) {
                                            $p_rate = floatval($svc['rate']);
                                            break;
                                        }
                                    }
                                }
                                $project_value = FS_View_Context::format_currency($p_rate) . '/hr';
                            }
                        ?>
                        <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-projects&action=view&id=' . $project->id) ); ?>" class="fs-invoice-mobile-row">
                            <div class="fs-invoice-mobile-left">
                                <span class="fs-invoice-mobile-client"><?php echo esc_html($project->name); ?></span>
                                <span class="fs-invoice-mobile-number"><?php echo  esc_html( ucfirst($project->billing_type) ); ?><?php if ($project->start_date): ?> · <?php echo  esc_html( FS_View_Context::format_date($project->start_date) ); ?><?php endif; ?></span>
                                <?php echo  wp_kses_post( FS_View_Context::status_badge($project->status) ); ?>
                            </div>
                            <div class="fs-invoice-mobile-right">
                                <span class="fs-invoice-mobile-amount"><?php echo  esc_html( $project_value ); ?></span>
                            </div>
                        </a>
                        <?php endforeach; ?>
                    </div>

                    <!-- Desktop Table -->
                    <table class="fs-table widefat fs-desktop-only">
                        <thead>
                            <tr>
                                <th><?php esc_html_e('Project', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Status', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Type', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Value', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Start Date', 'freelance-studio'); ?></th>
                                <th class="column-actions"></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($projects as $project): ?>
                                <tr>
                                    <td>
                                        <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-projects&action=view&id=' . $project->id) ); ?>">
                                            <strong><?php echo esc_html($project->name); ?></strong>
                                        </a>
                                    </td>
                                    <td><?php echo  wp_kses_post( FS_View_Context::status_badge($project->status) ); ?></td>
                                    <td><?php echo  esc_html( ucfirst($project->billing_type) ); ?></td>
                                    <td>
                                        <?php 
                                        if ($project->billing_type === 'fixed') {
                                            echo  esc_html( FS_View_Context::format_currency($project->fixed_price) );                                        } elseif ($project->billing_type === 'retainer') {
                                            echo  esc_html( FS_View_Context::format_currency($project->retainer_amount) . '/mo' );                                        } else {
                                            // Get hourly rate from services
                                            $hourly_rate = get_option('fs_default_hourly_rate', 75);
                                            $proj_services = $project->services;
                                            if (is_string($proj_services)) {
                                                $proj_services = json_decode($proj_services, true);
                                            }
                                            if (!empty($proj_services) && is_array($proj_services)) {
                                                foreach ($proj_services as $svc) {
                                                    if (isset($svc['pricing_type']) && $svc['pricing_type'] === 'hourly' && !empty($svc['rate'])) {
                                                        $hourly_rate = floatval($svc['rate']);
                                                        break;
                                                    }
                                                }
                                            }
                                            echo  esc_html( FS_View_Context::format_currency($hourly_rate) . '/hr' );                                        }
                                        ?>
                                    </td>
                                    <td><?php echo  esc_html( $project->start_date ? FS_View_Context::format_date($project->start_date) : '-' ); ?></td>
                                    <td class="column-actions">
                                        <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-projects&action=edit&id=' . $project->id) ); ?>"><?php esc_html_e('Edit', 'freelance-studio'); ?></a>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                <?php endif; ?>
            </div>
            
        <?php elseif ($current_tab === 'tasks'): ?>
            <!-- Tasks Tab -->
            <div class="fs-tab-pane">
                <div class="fs-tab-header">
                    <div class="fs-tab-header-left">
                        <span class="fs-task-count-badge">
                            <?php echo sprintf( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                                /* translators: 1. count/number */
                                _n('%d open task', '%d open tasks', count($client_tasks), 'freelance-studio'), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                                count($client_tasks)
                            ); ?>
                        </span>
                    </div>
                    <button type="button" class="fs-btn fs-btn-primary" id="add-client-task-btn" data-client-id="<?php echo  intval( $client->id ); ?>">
                        <?php esc_html_e('New Task', 'freelance-studio'); ?>
                    </button>
                </div>
                
                <?php if (empty($client_tasks)): ?>
                    <div class="fs-empty-state small">
                        <p><?php esc_html_e('No tasks yet for this client.', 'freelance-studio'); ?></p>
                        <p class="fs-empty-hint"><?php esc_html_e('Create tasks here for client-related work that isn\'t tied to a specific project.', 'freelance-studio'); ?></p>
                    </div>
                <?php else: ?>
                    <?php
                    $priorities = FS_Task::get_priorities();
                    $priority_colors = array(
                        'low' => '#6b7280',
                        'medium' => '#f59e0b',
                        'high' => '#f97316',
                        'urgent' => '#ef4444',
                    );
                    $kanban_status_labels = FS_View_Context::get_task_status_labels();
                    $kanban_status_colors = FS_View_Context::get_task_status_colors();
                    $sort_base = admin_url('admin.php?page=fs-clients&action=view&id=' . $client->id . '&tab=tasks');
                    ?>
                    <table class="wp-list-table widefat fixed striped fs-table" style="table-layout: auto;">
                        <thead>
                            <tr>
                                <th style="width: 40px;"></th>
                                <th>
                                    <a href="<?php echo esc_url(add_query_arg(array('task_sort' => 'title', 'task_order' => ($task_sort === 'title' && $task_order === 'ASC') ? 'DESC' : 'ASC'), $sort_base)); ?>" class="fs-sortable-header <?php echo $task_sort === 'title' ? 'active' : ''; ?>">
                                        <?php esc_html_e('Task', 'freelance-studio'); ?>
                                        <span class="fs-sort-indicator"><?php echo $task_sort === 'title' ? ($task_order === 'DESC' ? '↓' : '↑') : '↕'; ?></span>
                                    </a>
                                </th>
                                <th style="width: 22%;"><?php esc_html_e('Project', 'freelance-studio'); ?></th>
                                <th style="width: 90px;"><?php esc_html_e('Assigned To', 'freelance-studio'); ?></th>
                                <th style="width: 80px;">
                                    <a href="<?php echo esc_url(add_query_arg(array('task_sort' => 'priority', 'task_order' => ($task_sort === 'priority' && $task_order === 'DESC') ? 'ASC' : 'DESC'), $sort_base)); ?>" class="fs-sortable-header <?php echo $task_sort === 'priority' ? 'active' : ''; ?>">
                                        <?php esc_html_e('Priority', 'freelance-studio'); ?>
                                        <span class="fs-sort-indicator"><?php echo $task_sort === 'priority' ? ($task_order === 'DESC' ? '↓' : '↑') : '↕'; ?></span>
                                    </a>
                                </th>
                                <th style="width: 130px;">
                                    <a href="<?php echo esc_url(add_query_arg(array('task_sort' => 'status', 'task_order' => ($task_sort === 'status' && $task_order === 'ASC') ? 'DESC' : 'ASC'), $sort_base)); ?>" class="fs-sortable-header <?php echo $task_sort === 'status' ? 'active' : ''; ?>">
                                        <?php esc_html_e('Status', 'freelance-studio'); ?>
                                        <span class="fs-sort-indicator"><?php echo $task_sort === 'status' ? ($task_order === 'DESC' ? '↓' : '↑') : '↕'; ?></span>
                                    </a>
                                </th>
                                <th style="width: 110px;">
                                    <a href="<?php echo esc_url(add_query_arg(array('task_sort' => 'due_date', 'task_order' => ($task_sort === 'due_date' && $task_order === 'ASC') ? 'DESC' : 'ASC'), $sort_base)); ?>" class="fs-sortable-header <?php echo $task_sort === 'due_date' ? 'active' : ''; ?>">
                                        <?php esc_html_e('Due Date', 'freelance-studio'); ?>
                                        <span class="fs-sort-indicator"><?php echo $task_sort === 'due_date' ? ($task_order === 'DESC' ? '↓' : '↑') : '↕'; ?></span>
                                    </a>
                                </th>
                                <th style="width: 50px;"></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($client_tasks as $task): 
                                $is_completed = $task->status === 'completed';
                                $is_overdue = $task->due_date && strtotime($task->due_date) < time() && !$is_completed;
                                $is_client_task = ($task->assigned_to ?? 'freelancer') === 'client';
                                $priority_color = $priority_colors[$task->priority] ?? '#6b7280';
                            ?>
                            <tr class="<?php echo $is_completed ? 'task-completed' : ''; ?> <?php echo $is_overdue ? 'task-overdue' : ''; ?>">
                                <td class="column-status">
                                    <label class="fs-task-checkbox-wrapper">
                                        <input type="checkbox" class="fs-task-toggle" data-id="<?php echo esc_attr($task->id); ?>" <?php checked($is_completed); ?>>
                                        <span class="fs-task-checkbox-custom"></span>
                                    </label>
                                </td>
                                <td class="column-title">
                                    <div class="fs-task-title-cell">
                                        <a href="#" class="fs-task-title-link <?php echo  esc_attr( $is_completed ? 'completed' : '' ); ?>" data-id="<?php echo  intval( $task->id ); ?>">
                                            <?php echo esc_html($task->title); ?>
                                        </a>
                                        <?php if ($task->description): ?>
                                            <span class="fs-task-description"><?php echo esc_html(wp_trim_words($task->description, 10)); ?></span>
                                        <?php endif; ?>
                                    </div>
                                </td>
                                <td class="column-context">
                                    <?php if (!empty($task->project_id) && !empty($task->project_name)): ?>
                                        <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-projects&action=view&id=' . $task->project_id . '&tab=tasks') ); ?>">
                                            <?php echo esc_html($task->project_name); ?>
                                        </a>
                                    <?php else: ?>
                                        <span class="fs-task-client-subtext"><?php esc_html_e('Client Task', 'freelance-studio'); ?></span>
                                    <?php endif; ?>
                                </td>
                                <td class="column-assignee">
                                    <span class="fs-assignee-badge <?php echo $is_client_task ? 'client' : 'designer'; ?>">
                                        <span class="dashicons <?php echo $is_client_task ? 'dashicons-businessperson' : 'dashicons-admin-users'; ?>"></span>
                                        <?php echo  esc_html( $is_client_task ? __('Client', 'freelance-studio') : __('Me', 'freelance-studio') ); ?>
                                    </span>
                                </td>
                                <td class="column-priority">
                                    <span class="fs-priority-badge" style="background-color: <?php echo  esc_attr( $priority_color ); ?>15; color: <?php echo  esc_attr( $priority_color ); ?>;">
                                        <?php echo esc_html($priorities[$task->priority] ?? $task->priority); ?>
                                    </span>
                                </td>
                                <td class="column-kanban-status">
                                    <select class="fs-inline-status-select fs-task-status-select fs-dashboard-task-status task-status-<?php echo esc_attr($task->status); ?>" 
                                            data-task-id="<?php echo esc_attr($task->id); ?>" 
                                            data-original="<?php echo esc_attr($task->status); ?>">
                                        <?php 
                                        $inline_statuses = array_diff_key($kanban_status_labels, array('archived' => 1, 'cancelled' => 1));
                                        foreach ($inline_statuses as $skey => $slabel): ?>
                                            <option value="<?php echo esc_attr($skey); ?>" <?php selected($task->status, $skey); ?>>
                                                <?php echo esc_html($slabel); ?>
                                            </option>
                                        <?php endforeach; ?>
                                    </select>
                                </td>
                                <td class="column-due">
                                    <?php if ($task->due_date): ?>
                                        <span class="fs-due-date <?php echo $is_overdue ? 'overdue' : ''; ?>">
                                            <?php if ($is_overdue): ?>
                                                <span class="dashicons dashicons-warning"></span>
                                            <?php endif; ?>
                                            <?php echo esc_html(gmdate('M j, Y', strtotime($task->due_date))); ?>
                                        </span>
                                    <?php else: ?>
                                        <span class="fs-no-date">—</span>
                                    <?php endif; ?>
                                </td>
                                <td class="column-actions">
                                    <?php if ($task->status === 'requested'): ?>
                                        <button type="button" class="fs-btn fs-btn-primary fs-btn-small accept-task-request"
                                                data-id="<?php echo esc_attr($task->id); ?>"
                                                title="<?php esc_attr_e('Accept Request', 'freelance-studio'); ?>">
                                            <?php esc_html_e('Accept', 'freelance-studio'); ?>
                                        </button>
                                    <?php elseif (!$is_completed): ?>
                                        <?php if ( ! function_exists( 'fs_studio_is_free_plan' ) || ! fs_studio_is_free_plan() ): ?>
                                        <button type="button" class="fs-task-start-timer"
                                                data-task-id="<?php echo esc_attr($task->id); ?>"
                                                data-project-id="<?php echo esc_attr($task->project_id); ?>"
                                                data-task-name="<?php echo esc_attr($task->title); ?>"
                                                title="<?php esc_attr_e('Start Timer', 'freelance-studio'); ?>">
                                            <span class="dashicons dashicons-clock"></span>
                                        </button>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                    <div class="fs-row-menu">
                                        <button type="button" class="fs-row-menu-trigger">⋯</button>
                                        <div class="fs-row-menu-dropdown">
                                            <a href="#" class="fs-task-title-link" data-id="<?php echo esc_attr($task->id); ?>"><?php esc_html_e('Edit', 'freelance-studio'); ?></a>
                                            <?php if (!empty($task->project_id)): ?>
                                                <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-projects&action=view&id=' . $task->project_id . '&tab=tasks') ); ?>"><?php esc_html_e('View in Project', 'freelance-studio'); ?></a>
                                            <?php endif; ?>
                                            <a href="#" class="archive-task-btn" data-id="<?php echo esc_attr($task->id); ?>"><?php esc_html_e('Archive', 'freelance-studio'); ?></a>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                <?php endif; ?>
            </div>
            
        <?php elseif ($current_tab === 'time'): ?>
            <!-- Time Entries Tab -->
            <?php FS_View_Context::render_custom_activity_css(); ?>
            <div class="fs-tab-pane">
                <div class="fs-tab-header">
                    <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-time-tracking&action=add&client_id=' . $client->id) ); ?>" class="fs-btn fs-btn-primary">
                        <?php esc_html_e('New Time Entry', 'freelance-studio'); ?>
                    </a>
                </div>
                
                <?php 
                $client_time_entries = FS_Time_Entry::get_all(array('client_id' => $client->id, 'running' => false));
                $client_activity_types = FS_Time_Entry::get_activity_types();
                ?>
                
                <?php if (empty($client_time_entries)): ?>
                    <div class="fs-empty-state small">
                        <p><?php esc_html_e('No time tracked for this client yet.', 'freelance-studio'); ?></p>
                    </div>
                <?php else: ?>
                    <table class="fs-table widefat">
                        <thead>
                            <tr>
                                <th style="width: 90px;"><?php esc_html_e('Duration', 'freelance-studio'); ?></th>
                                <th style="width: 120px;"><?php esc_html_e('Time', 'freelance-studio'); ?></th>
                                <th style="width: 100px;"><?php esc_html_e('Activity', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Project', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Task', 'freelance-studio'); ?></th>
                                <th style="width: 110px;"><?php esc_html_e('Status', 'freelance-studio'); ?></th>
                                <th style="width: 60px;" class="column-actions"></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($client_time_entries as $entry): ?>
                                <tr data-entry-id="<?php echo  intval( $entry->id ); ?>">
                                    <td>
                                        <strong><?php echo esc_html(FS_Time_Entry::format_duration($entry->duration)); ?></strong>
                                    </td>
                                    <td>
                                        <?php 
                                        $local_time = FS_Time_Entry::utc_to_local($entry->start_time, 'g:ia');
                                        $local_date = FS_Time_Entry::utc_to_local($entry->start_time, 'n/j');
                                        echo esc_html($local_time);
                                        echo ' <span class="fs-date">' . esc_html($local_date) . '</span>';
                                        ?>
                                    </td>
                                    <td>
                                        <span class="fs-activity-badge fs-activity-<?php echo esc_attr($entry->activity); ?>">
                                            <?php echo esc_html($client_activity_types[$entry->activity] ?? $entry->activity); ?>
                                        </span>
                                    </td>
                                    <td>
                                        <?php if ($entry->project_name): ?>
                                            <span class="dashicons dashicons-portfolio"></span>
                                            <?php echo esc_html($entry->project_name); ?>
                                        <?php else: ?>
                                            <span class="fs-no-project"><?php esc_html_e('No project', 'freelance-studio'); ?></span>
                                        <?php endif; ?>
                                        <?php if ($entry->description): ?>
                                            <br><small class="fs-entry-description"><?php echo esc_html($entry->description); ?></small>
                                        <?php endif; ?>
                                    </td>
                                    <td>
                                        <?php if (!empty($entry->task_name)): ?>
                                            <span class="dashicons dashicons-yes-alt" style="color: var(--fs-primary);"></span>
                                            <?php echo esc_html($entry->task_name); ?>
                                        <?php else: ?>
                                            <span class="fs-no-task">—</span>
                                        <?php endif; ?>
                                    </td>
                                    <td>
                                        <?php if ($entry->invoiced): ?>
                                            <span class="fs-status-badge fs-status-invoiced" title="<?php esc_attr_e('Invoiced', 'freelance-studio'); ?>">
                                                <span class="fs-status-dot"></span>
                                                <span class="fs-status-text"><?php esc_html_e('Invoiced', 'freelance-studio'); ?></span>
                                            </span>
                                        <?php elseif ($entry->billable): ?>
                                            <span class="fs-status-badge fs-status-billable" title="<?php esc_attr_e('Billable', 'freelance-studio'); ?>">
                                                <span class="fs-status-dot"></span>
                                                <span class="fs-status-text"><?php esc_html_e('Billable', 'freelance-studio'); ?></span>
                                            </span>
                                        <?php else: ?>
                                            <span class="fs-status-badge fs-status-non-billable" title="<?php esc_attr_e('Non-billable', 'freelance-studio'); ?>">
                                                <span class="fs-status-dot"></span>
                                                <span class="fs-status-text"><?php esc_html_e('Non-billable', 'freelance-studio'); ?></span>
                                            </span>
                                        <?php endif; ?>
                                    </td>
                                    <td class="column-actions">
                                        <div class="fs-row-menu">
                                            <button type="button" class="fs-row-menu-trigger">⋯</button>
                                            <div class="fs-row-menu-dropdown">
                                                <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-time-tracking&action=edit&id=' . $entry->id) ); ?>"><?php esc_html_e('Edit', 'freelance-studio'); ?></a>
                                                <?php if ($entry->billable && !$entry->invoiced): ?>
                                                    <a href="#" class="fs-toggle-billable" data-id="<?php echo esc_attr($entry->id); ?>" data-billable="0"><?php esc_html_e('Mark Non-billable', 'freelance-studio'); ?></a>
                                                <?php elseif (!$entry->billable): ?>
                                                    <a href="#" class="fs-toggle-billable" data-id="<?php echo esc_attr($entry->id); ?>" data-billable="1"><?php esc_html_e('Mark Billable', 'freelance-studio'); ?></a>
                                                <?php endif; ?>
                                                <hr>
                                                <a href="#" class="fs-delete-entry text-danger" data-id="<?php echo esc_attr($entry->id); ?>"><?php esc_html_e('Delete', 'freelance-studio'); ?></a>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                <?php endif; ?>
            </div>
            
        <?php elseif ($current_tab === 'proposals'): ?>
            <!-- Proposals Tab -->
            <div class="fs-tab-pane">
                <div class="fs-tab-header">
                    <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-proposals&action=add&client_id=' . $client->id) ); ?>" class="fs-btn fs-btn-primary">
                        <?php esc_html_e('New Proposal', 'freelance-studio'); ?>
                    </a>
                </div>
                
                <?php if (empty($client_proposals)): ?>
                    <div class="fs-empty-state small">
                        <p><?php esc_html_e('No proposals yet.', 'freelance-studio'); ?></p>
                    </div>
                <?php else: ?>
                    <table class="fs-table widefat">
                        <thead>
                            <tr>
                                <th><?php esc_html_e('Proposal', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Date', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Valid Until', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Amount', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Status', 'freelance-studio'); ?></th>
                                <th class="column-actions"></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($client_proposals as $proposal): ?>
                                <tr>
                                    <td>
                                        <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-proposals&action=view&id=' . $proposal->id) ); ?>">
                                            <strong><?php echo esc_html($proposal->title); ?></strong>
                                        </a>
                                        <br><span style="color: #666; font-size: 12px;"><?php echo esc_html($proposal->proposal_number); ?></span>
                                    </td>
                                    <td><?php echo  esc_html( FS_View_Context::format_date($proposal->created_at) ); ?></td>
                                    <td>
                                        <?php if ($proposal->valid_until): ?>
                                            <?php echo  esc_html( FS_View_Context::format_date($proposal->valid_until) ); ?>
                                            <?php if (FS_Proposal::is_expired($proposal)): ?>
                                                <br><span style="color: #dc3545; font-size: 12px;"><?php esc_html_e('Expired', 'freelance-studio'); ?></span>
                                            <?php endif; ?>
                                        <?php else: ?>
                                            -
                                        <?php endif; ?>
                                    </td>
                                    <td><?php echo  esc_html( FS_View_Context::format_currency($proposal->total_amount) ); ?></td>
                                    <td><?php echo  wp_kses_post( FS_View_Context::status_badge($proposal->status) ); ?></td>
                                    <td class="column-actions">
                                        <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-proposals&action=edit&id=' . $proposal->id) ); ?>"><?php esc_html_e('Edit', 'freelance-studio'); ?></a>
                                        <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-proposals&action=pdf&id=' . $proposal->id) ); ?>" target="_blank"><?php esc_html_e('PDF', 'freelance-studio'); ?></a>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                <?php endif; ?>
            </div>
            
        <?php elseif ($current_tab === 'invoices'): ?>
            <!-- Invoices Tab -->
            <div class="fs-tab-pane">
                <div class="fs-tab-header">
                    <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-finances&tab=invoices&action=add&client_id=' . $client->id) ); ?>" class="fs-btn fs-btn-primary">
                        <?php esc_html_e('New Invoice', 'freelance-studio'); ?>
                    </a>
                </div>
                
                <!-- Invoice Stats -->
                <div class="fs-invoice-stats">
                    <div class="fs-stat-item">
                        <span class="fs-stat-label"><?php esc_html_e('Total Invoiced', 'freelance-studio'); ?></span>
                        <span class="fs-stat-value"><?php echo  esc_html( FS_View_Context::format_currency($stats['total_invoiced']) ); ?></span>
                    </div>
                    <div class="fs-stat-item">
                        <span class="fs-stat-label"><?php esc_html_e('Total Paid', 'freelance-studio'); ?></span>
                        <span class="fs-stat-value success"><?php echo  esc_html( FS_View_Context::format_currency($stats['total_paid']) ); ?></span>
                    </div>
                    <div class="fs-stat-item">
                        <span class="fs-stat-label"><?php esc_html_e('Outstanding', 'freelance-studio'); ?></span>
                        <span class="fs-stat-value <?php echo  esc_attr( $stats['outstanding'] > 0 ? 'warning' : '' ); ?>"><?php echo  esc_html( FS_View_Context::format_currency($stats['outstanding']) ); ?></span>
                    </div>
                </div>
                
                <?php if (empty($invoices)): ?>
                    <div class="fs-empty-state small">
                        <p><?php esc_html_e('No invoices yet.', 'freelance-studio'); ?></p>
                    </div>
                <?php else: ?>
                    <table class="fs-table widefat">
                        <thead>
                            <tr>
                                <th><?php esc_html_e('Invoice #', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Project', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Due Date', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Amount', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Status', 'freelance-studio'); ?></th>
                                <th class="column-actions"></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($invoices as $invoice): ?>
                                <tr>
                                    <td>
                                        <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-finances&tab=invoices&action=view&id=' . $invoice->id) ); ?>">
                                            <strong><?php echo esc_html($invoice->invoice_number); ?></strong>
                                        </a>
                                    </td>
                                    <td>
                                        <?php if (!empty($invoice->project_id) && !empty($invoice->project_name)): ?>
                                            <a href="<?php echo esc_url( admin_url('admin.php?page=fs-projects&action=view&id=' . $invoice->project_id) ); ?>">
                                                <?php echo esc_html($invoice->project_name); ?>
                                            </a>
                                        <?php else: ?>
                                            <span class="fs-text-muted">&mdash;</span>
                                        <?php endif; ?>
                                    </td>
                                    <td><?php echo  esc_html( FS_View_Context::format_date($invoice->due_date) ); ?></td>
                                    <td><?php echo  esc_html( FS_View_Context::format_currency($invoice->total) ); ?></td>
                                    <td><?php echo  wp_kses_post( FS_View_Context::status_badge($invoice->status) ); ?></td>
                                    <td class="column-actions">
                                        <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-finances&tab=invoices&action=edit&id=' . $invoice->id) ); ?>"><?php esc_html_e('Edit', 'freelance-studio'); ?></a>
                                        <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-finances&tab=invoices&action=pdf&id=' . $invoice->id) ); ?>"><?php esc_html_e('PDF', 'freelance-studio'); ?></a>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                <?php endif; ?>
            </div>
            
        <?php elseif ($current_tab === 'expenses'): ?>
            <!-- Expenses Tab -->
            <div class="fs-tab-pane">
                <?php if (empty($client_expenses)): ?>
                    <div class="fs-empty-state small">
                        <p><?php esc_html_e('No expenses recorded for this client\'s projects.', 'freelance-studio'); ?></p>
                    </div>
                <?php else: ?>
                    <table class="fs-table widefat">
                        <thead>
                            <tr>
                                <th><?php esc_html_e('Date', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Description', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Category', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Project', 'freelance-studio'); ?></th>
                                <th><?php esc_html_e('Amount', 'freelance-studio'); ?></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($client_expenses as $expense): ?>
                                <tr>
                                    <td><?php echo  esc_html( FS_View_Context::format_date($expense->expense_date) ); ?></td>
                                    <td><?php echo esc_html($expense->expense_name); ?></td>
                                    <td><?php echo esc_html($expense->category); ?></td>
                                    <td><?php echo esc_html($expense->project_name ?? '-'); ?></td>
                                    <td><?php echo  esc_html( FS_View_Context::format_currency($expense->amount) ); ?></td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                <?php endif; ?>
            </div>
            
        <?php elseif ($current_tab === 'notes'): ?>
            <!-- Notes Tab -->
            <div class="fs-tab-pane">
                <div class="fs-notes-section">
                    <?php if (!empty($client->notes)): ?>
                        <div class="fs-notes-content">
                            <?php echo nl2br(esc_html($client->notes)); ?>
                        </div>
                    <?php else: ?>
                        <div class="fs-empty-state small">
                            <p><?php esc_html_e('No notes for this client.', 'freelance-studio'); ?></p>
                        </div>
                    <?php endif; ?>
                    <p class="fs-notes-actions">
                        <a href="<?php echo  esc_url( admin_url('admin.php?page=fs-clients&action=edit&id=' . $client->id) ); ?>" class="button">
                            <?php esc_html_e('Edit Notes', 'freelance-studio'); ?>
                        </a>
                    </p>
                </div>
            </div>
            
        <?php endif; ?>
        



<!-- Add Contact Modal -->
<div id="fs-contact-modal" class="fs-modal">
    <div class="fs-modal-content">
        <div class="fs-modal-header">
            <h3><?php esc_html_e('Add Contact', 'freelance-studio'); ?></h3>
            <button type="button" class="fs-modal-close">&times;</button>
        </div>
        <form id="fs-contact-form" method="post">
            <?php wp_nonce_field('fs_save_contact', 'fs_contact_nonce'); ?>
            <input type="hidden" name="action" value="fs_save_contact">
            <input type="hidden" name="client_id" value="<?php echo  intval( $client->id ); ?>">
            <input type="hidden" name="contact_id" value="">
            
            <div class="fs-modal-body">
                <div class="fs-form-group">
                    <label for="contact_name"><?php esc_html_e('Name', 'freelance-studio'); ?> *</label>
                    <input type="text" name="contact_name" id="contact_name" required>
                </div>
                
                <div class="fs-form-group">
                    <label for="contact_role"><?php esc_html_e('Role/Position', 'freelance-studio'); ?></label>
                    <input type="text" name="contact_role" id="contact_role" placeholder="<?php esc_attr_e('e.g., Project Manager, CEO', 'freelance-studio'); ?>">
                </div>
                
                <div class="fs-form-row">
                    <div class="fs-form-group">
                        <label for="contact_email"><?php esc_html_e('Email', 'freelance-studio'); ?></label>
                        <input type="email" name="contact_email" id="contact_email">
                    </div>
                    
                    <div class="fs-form-group">
                        <label for="contact_phone"><?php esc_html_e('Phone', 'freelance-studio'); ?></label>
                        <input type="tel" name="contact_phone" id="contact_phone">
                    </div>
                </div>
                
                <div class="fs-contact-badges">
                    <label>
                        <input type="checkbox" name="contact_is_primary" value="1">
                        <?php esc_html_e('Primary Contact', 'freelance-studio'); ?>
                    </label>
                    <label>
                        <input type="checkbox" name="contact_is_billing" value="1">
                        <?php esc_html_e('Billing Contact', 'freelance-studio'); ?>
                    </label>
                    <label>
                        <input type="checkbox" name="contact_is_project" value="1">
                        <?php esc_html_e('Project Contact', 'freelance-studio'); ?>
                    </label>
                </div>
            </div>
            
            <div class="fs-modal-footer">
                <button type="button" class="fs-btn fs-btn-secondary fs-modal-cancel"><?php esc_html_e('Cancel', 'freelance-studio'); ?></button>
                <button type="submit" class="fs-btn fs-btn-primary"><?php esc_html_e('Save Contact', 'freelance-studio'); ?></button>
            </div>
        </form>



<!-- Client Task Modal -->
<!-- Task Modal (shared partial) -->
<?php
$task_modal_context = 'client';
$task_modal_projects = $projects;
$task_modal_client_id = $client->id;
include JEEB_FS_PLUGIN_DIR . 'includes/views/partials/task-modal.php';
?>

<script>
window.fsTaskModal = {
    nonce: '<?php echo esc_attr( wp_create_nonce("fs_ajax_nonce") ); ?>',
    context: 'client',
    strings: {
        addTask: '<?php echo esc_js(__("Add Task", "freelance-studio")); ?>',
        editTask: '<?php echo esc_js(__("Edit Task", "freelance-studio")); ?>',
        createTask: '<?php echo esc_js(__("Add Task", "freelance-studio")); ?>',
        updateTask: '<?php echo esc_js(__("Update Task", "freelance-studio")); ?>',
        errorLoading: '<?php echo esc_js(__("Error loading task", "freelance-studio")); ?>',
        errorSaving: '<?php echo esc_js(__("Error saving task", "freelance-studio")); ?>',
        saving: '<?php echo esc_js(__("Saving...", "freelance-studio")); ?>'
    }
};
</script>

<script>
jQuery(document).ready(function($) {
    // Wire add task button to shared modal
    $('#add-client-task-btn').on('click', function() {
        openTaskModal();
    });
    
    // Inline task status change (matches main task list behavior)
    var ajaxNonce = '<?php echo esc_attr( wp_create_nonce("fs_ajax_nonce") ); ?>';
    
    // Archive task
    $(document).on('click', '.archive-task-btn', function(e) {
        e.preventDefault();
        var taskId = $(this).data('id');
        var $row = $(this).closest('tr');
        
        $.ajax({
            url: ajaxurl,
            type: 'POST',
            data: { action: 'fs_archive_task', nonce: ajaxNonce, id: taskId },
            success: function(response) {
                if (response.success) {
                    $row.fadeOut(200, function() { location.reload(); });
                } else {
                    alert(response.data || 'Error archiving task');
                }
            }
        });
    });
    
    $(document).on('change', '.fs-task-status-select', function() {
        var $select = $(this);
        var taskId = $select.data('task-id');
        var newStatus = $select.val();
        var originalStatus = $select.data('original');
        
        $select.prop('disabled', true);
        
        $.ajax({
            url: ajaxurl,
            type: 'POST',
            data: {
                action: 'fs_update_task_status',
                task_id: taskId,
                status: newStatus,
                nonce: ajaxNonce
            },
            success: function(response) {
                if (response.success) {
                    $select.data('original', newStatus);
                    $select.removeClass('task-status-' + originalStatus).addClass('task-status-' + newStatus);
                    
                    var $row = $select.closest('tr');
                    if (newStatus === 'completed') {
                        $row.addClass('task-completed');
                        $row.find('.fs-task-checkbox-wrapper input').prop('checked', true);
                        $row.find('.fs-task-title-link').addClass('completed');
                    } else {
                        $row.removeClass('task-completed');
                        $row.find('.fs-task-checkbox-wrapper input').prop('checked', false);
                        $row.find('.fs-task-title-link').removeClass('completed');
                    }
                } else {
                    alert(response.data || 'Error updating task status');
                    $select.val(originalStatus);
                }
                $select.prop('disabled', false);
            },
            error: function() {
                alert('Error updating task status');
                $select.val(originalStatus);
                $select.prop('disabled', false);
            }
        });
    });
});
</script>
