<?php
$executive = is_array($executive ?? null) ? $executive : [];
$hospitalName = $hospital['name'] ?? 'New Jeddah';
$isAr = current_lang() === 'ar';

$txt = function (string $en, string $ar = '') use ($isAr): string {
    return $isAr && $ar !== '' ? $ar : $en;
};

$num = function ($value): string {
    return number_format((float)$value, 0);
};

$money = function ($value): string {
    return 'SAR ' . compact_money((float)$value);
};

$get = function (array $arr, string $key) {
    return array_key_exists($key, $arr) ? $arr[$key] : null;
};

$flow = is_array($executive['flow'] ?? null) ? $executive['flow'] : [];
$finance = is_array($executive['finance'] ?? null) ? $executive['finance'] : [];
$capacity = is_array($executive['capacity'] ?? null) ? $executive['capacity'] : [];
$clinical = is_array($executive['clinical'] ?? null) ? $executive['clinical'] : [];
$status = is_array($executive['status'] ?? null)
    ? $executive['status']
    : [
        'status' => 'STABLE',
        'tone' => 'good',
        'text' => 'Operations normal',
    ];
$alerts = is_array($executive['alerts'] ?? null) ? $executive['alerts'] : [];
$actions = is_array($executive['actions'] ?? null) ? $executive['actions'] : [];

$units = is_array($capacity['units'] ?? null)
    ? array_slice($capacity['units'], 0, 3)
    : [];

$topSpecialties = is_array($clinical['top_specialties'] ?? null)
    ? array_slice($clinical['top_specialties'], 0, 3)
    : [];

$topDoctor = is_array($clinical['top_doctor'] ?? null)
    ? $clinical['top_doctor']
    : null;

$lastUpdated = (string)($executive['last_updated'] ?? date('Y-m-d H:i'));
$isFastMode = !empty($executive['is_fast_mode']);
$isSummaryMode = ((string)($executive['mode'] ?? '') === 'summary');

$operational = is_array($executive['operational'] ?? null)
    ? $executive['operational']
    : [];

$operationalDate = (string)(
    $operational['operational_date']
    ?? ($executive['today'] ?? date('Y-m-d'))
);

$operationalWindow = trim(
    (string)($operational['window_start'] ?? '')
    . ' → '
    . (string)($operational['window_end'] ?? ''),
    ' →'
);

$isRollover = !empty($operational['is_rollover']);

$operationalModeText = $isRollover
    ? $txt('Night operational window', 'نافذة التشغيل الليلية')
    : $txt('Current operational day', 'اليوم التشغيلي الحالي');

$smartCount = function (
    $value,
    bool $trusted = true
) use ($isFastMode, $num): string {
    if ($value === null || $value === '') {
        return '—';
    }

    if ($isFastMode && !$trusted && (float)$value == 0.0) {
        return '—';
    }

    return $num($value);
};

$smartMoney = function (
    $value,
    bool $trusted = true
) use ($isFastMode, $money): string {
    if ($value === null || $value === '') {
        return '—';
    }

    if ($isFastMode && !$trusted && (float)$value == 0.0) {
        return '—';
    }

    return $money($value);
};

$smartPct = function (
    $value,
    bool $trusted = true
) use ($isFastMode): string {
    if ($value === null || $value === '') {
        return '—';
    }

    if ($isFastMode && !$trusted && (float)$value == 0.0) {
        return '—';
    }

    return number_format((float)$value, 0) . '%';
};

$occupancyRate = $capacity['occupancy_rate'] ?? null;
$todayRevenue = $get($finance, 'today_total');
$monthRevenue = $get($finance, 'month_total');
$availableBeds = $get($capacity, 'available_beds');
$totalBeds = $get($capacity, 'total_beds');
$er = (int)($get($flow, 'er') ?? 0);

$erPressure = $er >= 50
    ? $txt('HIGH', 'مرتفع')
    : (
        $er > 0
            ? $txt('WATCH', 'متابعة')
            : $txt('LOW', 'منخفض')
    );

$erPressureClass = $er >= 50
    ? 'high'
    : ($er > 0 ? 'watch' : 'low');

$opMix = (float)($clinical['op_mix'] ?? 0);
$ipMix = (float)($clinical['ip_mix'] ?? 0);

$statusValue = trim((string)($status['status'] ?? 'STABLE'));
if ($statusValue === '') {
    $statusValue = 'STABLE';
}

$statusDetail = trim((string)($status['text'] ?? ''));
if ($statusDetail === '' || $isSummaryMode) {
    $statusDetail = $txt(
        'Current operating position is available for review.',
        'الوضع التشغيلي الحالي متاح للمراجعة.'
    );
}

$operationalCards = [
    [
        'label' => $txt('OPD Visits', 'زيارات العيادات'),
        'value' => $get($flow, 'opd'),
        'icon' => '♧',
        'tone' => 'teal',
        'href' => url_to('visits'),
        'trusted' => !$isFastMode,
    ],
    [
        'label' => $txt('ER Visits', 'زيارات الطوارئ'),
        'value' => $get($flow, 'er'),
        'icon' => '🚑',
        'tone' => 'red',
        'href' => url_to('visits'),
        'trusted' => !$isFastMode,
    ],
    [
        'label' => $txt('Admissions', 'الدخول'),
        'value' => $get($flow, 'admissions'),
        'icon' => '▤',
        'tone' => 'purple',
        'href' => url_to('visits'),
        'trusted' => true,
    ],
    [
        'label' => $txt('Discharges', 'الخروج'),
        'value' => $get($flow, 'discharges'),
        'icon' => '⇥',
        'tone' => 'green',
        'href' => url_to('visits'),
        'trusted' => !$isFastMode,
    ],
    [
        'label' => $txt('Scheduled OR', 'عمليات مجدولة'),
        'value' => $get($flow, 'scheduled_operations'),
        'icon' => '▣',
        'tone' => 'blue',
        'href' => url_to('operations'),
        'trusted' => !$isFastMode,
    ],
    [
        'label' => $txt('Performed OR', 'عمليات منفذة'),
        'value' => $get($flow, 'performed_operations'),
        'icon' => '✎',
        'tone' => 'teal',
        'href' => url_to('operations'),
        'trusted' => !$isFastMode,
    ],
];

if (!$alerts) {
    $alerts = [[
        'severity' => 'good',
        'title' => $txt(
            'No critical issues require executive attention',
            'لا توجد مشكلات حرجة تتطلب تدخل الإدارة'
        ),
        'text' => $txt(
            'Current operational and data-quality checks show no critical issue requiring immediate action.',
            'لا تظهر الفحوصات التشغيلية وجود مشكلة حرجة تتطلب إجراءً فوريًا.'
        ),
    ]];
}

$technicalAlertPatterns = [
    'summary layer',
    'fast executive summary table',
    'schema-aware',
    'scheduled refresh job',
    'refresh executive summary',
    'طبقة الملخص',
    'جدول الملخص التنفيذي',
    'وظيفة التحديث المجدولة',
];

$sanitizeAlert = function (array $alert) use (
    $technicalAlertPatterns,
    $txt
): array {
    $combined = strtolower(
        trim(
            (string)($alert['title'] ?? '')
            . ' '
            . (string)($alert['text'] ?? '')
        )
    );

    foreach ($technicalAlertPatterns as $pattern) {
        if (strpos($combined, strtolower($pattern)) !== false) {
            return [
                'severity' => 'good',
                'title' => $txt(
                    'No critical issues require executive attention',
                    'لا توجد مشكلات حرجة تتطلب تدخل الإدارة'
                ),
                'text' => $txt(
                    'Current indicators show no immediate operational concern requiring executive action.',
                    'لا تظهر المؤشرات الحالية حاجة إلى إجراء تنفيذي فوري.'
                ),
            ];
        }
    }

    return $alert;
};

$alerts = array_map($sanitizeAlert, $alerts);
$alerts = array_slice($alerts, 0, 2);

if (!$actions) {
    $actions = [
        [
            'tone' => 'teal',
            'title' => $txt(
                'Review today’s priorities',
                'مراجعة أولويات اليوم'
            ),
            'text' => $txt(
                'Confirm items that need executive attention and the next action.',
                'تأكيد البنود التي تحتاج اهتمام الإدارة والإجراء التالي.'
            ),
            'href' => url_to('action-center'),
        ],
        [
            'tone' => 'purple',
            'title' => $txt(
                'Review financial performance',
                'مراجعة الأداء المالي'
            ),
            'text' => $txt(
                'Examine revenue and net position for the current period.',
                'مراجعة الإيرادات وصافي الأداء للفترة الحالية.'
            ),
            'href' => url_to('revenue'),
        ],
        [
            'tone' => 'blue',
            'title' => $txt(
                'Review capacity readiness',
                'مراجعة جاهزية السعة'
            ),
            'text' => $txt(
                'Check bed availability and occupancy across key units.',
                'مراجعة توافر الأسرة والإشغال في الوحدات الرئيسية.'
            ),
            'href' => url_to('beds'),
        ],
    ];
}

$actions = array_slice($actions, 0, 3);

foreach ($actions as $index => $action) {
    $actionTitle = trim((string)($action['title'] ?? ''));

    if (
        strcasecmp($actionTitle, 'Refresh Executive Summary') === 0
        || $actionTitle === 'تحديث الملخص التنفيذي'
    ) {
        $actions[$index]['title'] = $txt(
            'Review today’s priorities',
            'مراجعة أولويات اليوم'
        );
        $actions[$index]['text'] = $txt(
            'Confirm items that need executive attention and the next action.',
            'تأكيد البنود التي تحتاج اهتمام الإدارة والإجراء التالي.'
        );
        $actions[$index]['href'] = url_to('action-center');
    }
}

$unitFallback = [
    ['label' => 'ICU', 'value' => null],
    ['label' => 'Medical', 'value' => null],
    ['label' => 'Surgical', 'value' => null],
];

$unitsToRender = $units ?: $unitFallback;
?>

<section
    class="exec-leadership-dashboard"
    data-exec-leadership-contract="v3"
    data-responsive-contract="desktop:4-3-2;tablet:2-2-1;mobile:1-1-1"
    data-operational-card-count="6"
>
    <?php if (!empty($executiveError)): ?>
        <div class="exec-leadership-warning" role="status">
            <span>!</span>
            <div>
                <strong>
                    <?= e($txt(
                        'Some information is temporarily unavailable.',
                        'بعض المعلومات غير متاحة مؤقتًا.'
                    )) ?>
                </strong>
                <p>
                    <?= e($txt(
                        'Available verified information is still shown below.',
                        'يتم عرض المعلومات المتاحة والموثقة أدناه.'
                    )) ?>
                </p>
            </div>
        </div>
    <?php endif; ?>

    <section
        class="exec-leadership-section exec-leadership-section--priority"
        aria-label="<?= e($txt('Executive summary', 'الملخص التنفيذي')) ?>"
    >
        <div class="exec-leadership-section-head">
            <div>
                <span class="exec-leadership-overline">
                    <?= e($txt('Executive Summary', 'الملخص التنفيذي')) ?>
                </span>
                <h2>
                    <?= e($txt(
                        'Current hospital position at a glance',
                        'الوضع الحالي للمستشفى بنظرة واحدة'
                    )) ?>
                </h2>
                <p>
                    <?= e($txt(
                        'Leadership view of the hospital’s current operating position.',
                        'عرض تنفيذي للوضع التشغيلي الحالي للمستشفى.'
                    )) ?>
                </p>
            </div>

            <div class="exec-leadership-context">
                <div>
                    <small><?= e($txt('Operational day', 'اليوم التشغيلي')) ?></small>
                    <strong><?= e($operationalDate) ?></strong>
                </div>
                <div>
                    <small><?= e($txt('Last updated', 'آخر تحديث')) ?></small>
                    <strong><?= e($lastUpdated) ?></strong>
                </div>
            </div>
        </div>

        <div
            class="exec-leadership-situation"
            data-grid-role="situation"
        >
            <article class="exec-leadership-kpi exec-tone-status">
                <span class="exec-leadership-kpi__icon">◇</span>
                <div class="exec-leadership-kpi__copy">
                    <small><?= e($txt('Hospital Status', 'حالة المستشفى')) ?></small>
                    <strong><?= e($statusValue) ?></strong>
                    <p><?= e($statusDetail) ?></p>
                </div>
            </article>

            <article class="exec-leadership-kpi exec-tone-revenue">
                <span class="exec-leadership-kpi__icon">◈</span>
                <div class="exec-leadership-kpi__copy">
                    <small><?= e($txt('Today Revenue', 'إيراد اليوم')) ?></small>
                    <strong><?= e($smartMoney($todayRevenue, true)) ?></strong>
                    <p><?= e($operationalModeText) ?></p>
                </div>
            </article>

            <article class="exec-leadership-kpi exec-tone-capacity">
                <span class="exec-leadership-kpi__icon">▱</span>
                <div class="exec-leadership-kpi__copy">
                    <small><?= e($txt('Occupancy', 'الإشغال')) ?></small>
                    <strong><?= e($smartPct($occupancyRate, !$isFastMode)) ?></strong>
                    <p>
                        <?= e($txt('Beds available', 'الأسرة المتاحة')) ?>:
                        <b><?= e($smartCount($availableBeds, !$isFastMode)) ?></b>
                    </p>
                </div>
            </article>

            <article class="exec-leadership-kpi exec-tone-pressure">
                <span class="exec-leadership-kpi__icon">⚠</span>
                <div class="exec-leadership-kpi__copy">
                    <small><?= e($txt('ER Pressure', 'ضغط الطوارئ')) ?></small>
                    <strong class="is-<?= e($erPressureClass) ?>">
                        <?= e($erPressure) ?>
                    </strong>
                    <p>
                        <?= e($txt('ER visits today', 'زيارات الطوارئ اليوم')) ?>:
                        <b><?= e($smartCount($get($flow, 'er'), !$isFastMode)) ?></b>
                    </p>
                </div>
            </article>
        </div>
    </section>

    <section
        class="exec-leadership-section"
        aria-label="<?= e($txt('Hospital pulse', 'مؤشرات اليوم')) ?>"
    >
        <div class="exec-leadership-section-head exec-leadership-section-head--compact">
            <div>
                <span class="exec-leadership-overline">
                    <?= e($txt('Today at a Glance', 'نظرة اليوم')) ?>
                </span>
                <h2><?= e($txt('Hospital Pulse', 'مؤشرات اليوم')) ?></h2>
                <p>
                    <?= e($txt(
                        'Current-day activity across core hospital services.',
                        'نشاط اليوم الحالي عبر الخدمات الأساسية بالمستشفى.'
                    )) ?>
                </p>
            </div>
        </div>

        <div
            class="exec-leadership-pulse-grid"
            data-grid-role="pulse"
        >
            <?php foreach ($operationalCards as $card): ?>
                <a
                    class="exec-leadership-pulse-card tone-<?= e($card['tone']) ?>"
                    href="<?= e($card['href']) ?>"
                >
                    <span class="exec-leadership-pulse-card__icon">
                        <?= e($card['icon']) ?>
                    </span>
                    <div>
                        <small><?= e($card['label']) ?></small>
                        <strong>
                            <?= e($smartCount(
                                $card['value'],
                                (bool)($card['trusted'] ?? true)
                            )) ?>
                        </strong>
                    </div>
                    <em>→</em>
                </a>
            <?php endforeach; ?>
        </div>
    </section>

    <section
        class="exec-leadership-section"
        aria-label="<?= e($txt('Decision support', 'دعم القرار')) ?>"
    >
        <div class="exec-leadership-section-head exec-leadership-section-head--compact">
            <div>
                <span class="exec-leadership-overline">
                    <?= e($txt('Decision Support', 'دعم القرار')) ?>
                </span>
                <h2>
                    <?= e($txt(
                        'What matters for the next decision',
                        'ما يهم للقرار التالي'
                    )) ?>
                </h2>
                <p>
                    <?= e($txt(
                        'Priority information supporting the next executive decision.',
                        'معلومات ذات أولوية تدعم القرار التنفيذي التالي.'
                    )) ?>
                </p>
            </div>
        </div>

        <div
            class="exec-leadership-main-grid"
            data-grid-role="main"
        >
            <article class="exec-leadership-panel">
                <header class="exec-leadership-panel__head">
                    <span>♧</span>
                    <div>
                        <small><?= e($txt('Performance Overview', 'نظرة عامة على الأداء')) ?></small>
                        <h3><?= e($txt('Patient Flow', 'تدفق المرضى')) ?></h3>
                    </div>
                </header>

                <div class="exec-leadership-flow-grid">
                    <div>
                        <small><?= e($txt('OPD Visits', 'زيارات العيادات')) ?></small>
                        <strong><?= e($smartCount($get($flow, 'opd'), !$isFastMode)) ?></strong>
                    </div>
                    <div>
                        <small><?= e($txt('ER Visits', 'زيارات الطوارئ')) ?></small>
                        <strong><?= e($smartCount($get($flow, 'er'), !$isFastMode)) ?></strong>
                    </div>
                    <div>
                        <small><?= e($txt('Admissions', 'الدخول')) ?></small>
                        <strong><?= e($smartCount($get($flow, 'admissions'), true)) ?></strong>
                    </div>
                    <div>
                        <small><?= e($txt('Discharges', 'الخروج')) ?></small>
                        <strong><?= e($smartCount($get($flow, 'discharges'), !$isFastMode)) ?></strong>
                    </div>
                </div>

                <footer class="exec-leadership-panel__footer">
                    <span>
                        <?= e($txt(
                            'Expected discharges in operational day',
                            'الخروج المتوقع في اليوم التشغيلي'
                        )) ?>
                    </span>
                    <strong>
                        <?= e($smartCount($get($capacity, 'expected_discharges'), true)) ?>
                    </strong>
                    <?php if ($operationalWindow !== ''): ?>
                        <em><?= e($operationalWindow) ?></em>
                    <?php endif; ?>
                </footer>
            </article>

            <article class="exec-leadership-panel">
                <header class="exec-leadership-panel__head">
                    <span>▱</span>
                    <div>
                        <small><?= e($txt('Capacity Overview', 'نظرة عامة على السعة')) ?></small>
                        <h3><?= e($txt('Capacity & Occupancy', 'السعة والإشغال')) ?></h3>
                    </div>
                </header>

                <div
                    class="exec-leadership-capacity"
                    data-capacity-visual-contract="v2"
                    data-capacity-ring-purpose="occupancy-rate"
                    data-capacity-unit-bars="high-contrast-track-fill"
                >
                    <div class="exec-leadership-capacity-overview">
                        <div
                            class="exec-leadership-donut"
                            style="--p:<?= e((string)max(
                                0,
                                min(100, (float)($occupancyRate ?? 0))
                            )) ?>"
                        >
                            <strong><?= e($smartPct($occupancyRate, !$isFastMode)) ?></strong>
                            <small><?= e($txt('Occupancy', 'الإشغال')) ?></small>
                        </div>

                        <div class="exec-leadership-capacity-meta">
                            <div>
                                <small><?= e($txt('Total Beds', 'إجمالي الأسرة')) ?></small>
                                <strong><?= e($smartCount($totalBeds, !$isFastMode)) ?></strong>
                            </div>
                            <div>
                                <small><?= e($txt('Available', 'المتاح')) ?></small>
                                <strong><?= e($smartCount($availableBeds, !$isFastMode)) ?></strong>
                            </div>
                        </div>
                    </div>

                    <div class="exec-leadership-units">
                        <?php foreach ($unitsToRender as $unit): ?>
                            <?php
                            $label = (string)(
                                $unit['unit_label']
                                ?? $unit['label']
                                ?? 'Unit'
                            );
                            $raw = $unit['occupancy_pct'] ?? $unit['value'] ?? null;
                            $hasValue = !($raw === null || $raw === '');
                            $unitValue = $hasValue ? (float)$raw : 0;
                            $unitWidth = max(
                                0,
                                min(100, $unitValue)
                            );
                            ?>
                            <div class="exec-leadership-unit-row">
                                <span><?= e($label) ?></span>
                                <b class="exec-leadership-unit-track">
                                    <i style="--w:<?= e((string)$unitWidth) ?>%"></i>
                                </b>
                                <em>
                                    <?= e(
                                        $hasValue
                                            ? number_format($unitValue, 0) . '%'
                                            : '—'
                                    ) ?>
                                </em>
                            </div>
                        <?php endforeach; ?>
                    </div>
                </div>

                <a class="exec-leadership-link" href="<?= e(url_to('beds')) ?>">
                    <?= e($txt('Open Beds Dashboard', 'فتح لوحة الأسرة')) ?> →
                </a>
            </article>

            <article class="exec-leadership-panel">
                <header class="exec-leadership-panel__head">
                    <span>◈</span>
                    <div>
                        <small><?= e($txt('Financial Position', 'الوضع المالي')) ?></small>
                        <h3><?= e($txt('Finance Snapshot', 'لمحة مالية')) ?></h3>
                    </div>
                    <a href="<?= e(url_to('revenue')) ?>">
                        <?= e($txt('Revenue', 'الإيرادات')) ?>
                    </a>
                </header>

                <div class="exec-leadership-finance-grid">
                    <div>
                        <small><?= e($txt('Today Revenue', 'إيراد اليوم')) ?></small>
                        <strong><?= e($smartMoney($todayRevenue, true)) ?></strong>
                    </div>
                    <div>
                        <small><?= e($txt('Month Revenue', 'إيراد الشهر')) ?></small>
                        <strong><?= e($smartMoney($monthRevenue, true)) ?></strong>
                    </div>
                    <div>
                        <small><?= e($txt('Cash', 'نقدي')) ?></small>
                        <strong><?= e($smartMoney($get($finance, 'cash'), true)) ?></strong>
                    </div>
                    <div>
                        <small><?= e($txt('Insurance', 'تأمين')) ?></small>
                        <strong><?= e($smartMoney($get($finance, 'insurance'), true)) ?></strong>
                    </div>
                    <div>
                        <small><?= e($txt('MOH', 'وزارة الصحة')) ?></small>
                        <strong><?= e($smartMoney($get($finance, 'moh'), true)) ?></strong>
                    </div>
                    <div class="is-net">
                        <small><?= e($txt('Net', 'الصافي')) ?></small>
                        <strong><?= e($smartMoney($get($finance, 'net'), true)) ?></strong>
                    </div>
                </div>
            </article>

            <article
                class="exec-leadership-panel exec-leadership-panel--clinical-compact"
                data-top-specialty-limit="3"
            >
                <header class="exec-leadership-panel__head">
                    <span>♙</span>
                    <div>
                        <small><?= e($txt('Clinical Overview', 'النظرة السريرية')) ?></small>
                        <h3><?= e($txt('Clinical Activity', 'النشاط السريري')) ?></h3>
                    </div>
                </header>

                <div class="exec-leadership-clinical-summary">
                    <div>
                        <small><?= e($txt('Active Doctors', 'الأطباء النشطون')) ?></small>
                        <strong><?= e($smartCount(
                            $get($clinical, 'active_doctors'),
                            !$isFastMode
                        )) ?></strong>
                    </div>

                    <div>
                        <small><?= e($txt('OP / IP Mix', 'مزيج العيادات / التنويم')) ?></small>
                        <strong>
                            <?= e(
                                ($opMix == 0.0 && $ipMix == 0.0 && $isSummaryMode)
                                    ? '— / —'
                                    : (
                                        number_format($opMix, 0)
                                        . '% / '
                                        . number_format($ipMix, 0)
                                        . '%'
                                    )
                            ) ?>
                        </strong>
                    </div>

                    <div class="is-wide">
                        <small><?= e($txt(
                            'Top Doctor by Net Revenue',
                            'أعلى طبيب بالصافي'
                        )) ?></small>
                        <strong><?= e((string)($topDoctor['label'] ?? '—')) ?></strong>
                        <em>
                            <?= e(
                                isset($topDoctor['value'])
                                    ? $money($topDoctor['value'])
                                    : '—'
                            ) ?>
                        </em>
                    </div>
                </div>

                <ol class="exec-leadership-ranking">
                    <?php if ($topSpecialties): ?>
                        <?php foreach ($topSpecialties as $index => $specialty): ?>
                            <?php
                            $specialtyValue = (float)($specialty['value'] ?? 0);
                            $maxSpecialty = max(
                                1,
                                (float)($topSpecialties[0]['value'] ?? 1)
                            );
                            ?>
                            <li>
                                <span><?= e((string)($index + 1)) ?></span>
                                <b><?= e((string)(
                                    $specialty['label']
                                    ?? $txt('Specialty', 'التخصص')
                                )) ?></b>
                                <i style="--w:<?= e((string)max(
                                    8,
                                    min(100, ($specialtyValue / $maxSpecialty) * 100)
                                )) ?>%"></i>
                                <em><?= e($money($specialtyValue)) ?></em>
                            </li>
                        <?php endforeach; ?>
                    <?php else: ?>
                        <li class="is-empty">
                            <span>—</span>
                            <b><?= e($txt(
                                'No specialty data available',
                                'لا تتوفر بيانات التخصصات'
                            )) ?></b>
                            <em>—</em>
                        </li>
                    <?php endif; ?>
                </ol>
            </article>

            <aside
                class="exec-leadership-panel exec-leadership-panel--content-fit exec-leadership-panel--attention-wide"
                data-critical-alerts-layout="natural-height"
                data-attention-layout="full-width-compact"
            >
                <header class="exec-leadership-panel__head">
                    <span>⚠</span>
                    <div>
                        <small><?= e($txt('Attention Required', 'ما يحتاج الانتباه')) ?></small>
                        <h3><?= e($txt('Critical Alerts', 'التنبيهات الحرجة')) ?></h3>
                    </div>
                    <a href="<?= e(url_to('action-center', ['section' => 'alerts'])) ?>">
                        <?= e($txt('View all', 'عرض الكل')) ?>
                    </a>
                </header>

                <div class="exec-leadership-alert-list">
                    <?php foreach ($alerts as $alert): ?>
                        <div class="exec-leadership-alert severity-<?= e((string)(
                            $alert['severity']
                            ?? 'low'
                        )) ?>">
                            <span>◇</span>
                            <div>
                                <strong><?= e((string)($alert['title'] ?? $txt(
                                    'Alert',
                                    'تنبيه'
                                ))) ?></strong>
                                <p><?= e((string)($alert['text'] ?? '')) ?></p>
                            </div>
                        </div>
                    <?php endforeach; ?>
                </div>
            </aside>

            <aside
                class="exec-leadership-panel exec-leadership-panel--actions-wide"
                data-actions-layout="full-width-three-up"
            >
                <header class="exec-leadership-panel__head">
                    <span>▸</span>
                    <div>
                        <small><?= e($txt('Next Action', 'الإجراء التالي')) ?></small>
                        <h3><?= e($txt('Recommended Actions', 'الإجراءات المقترحة')) ?></h3>
                    </div>
                </header>

                <div class="exec-leadership-actions">
                    <?php foreach ($actions as $action): ?>
                        <div class="exec-leadership-action tone-<?= e((string)(
                            $action['tone']
                            ?? 'teal'
                        )) ?>">
                            <div>
                                <strong><?= e((string)(
                                    $action['title']
                                    ?? $txt('Action', 'إجراء')
                                )) ?></strong>
                                <p><?= e((string)($action['text'] ?? '')) ?></p>
                            </div>

                            <a href="<?= e((string)(
                                $action['href']
                                ?? url_to('action-center')
                            )) ?>">
                                <?= e($txt('Review', 'مراجعة')) ?>
                            </a>
                        </div>
                    <?php endforeach; ?>
                </div>

                <a
                    class="exec-leadership-action-center"
                    href="<?= e(url_to('action-center')) ?>"
                >
                    <?= e($txt('Open Action Center', 'فتح مركز الإجراءات')) ?> →
                </a>
            </aside>
        </div>
    </section>

    <nav
        class="exec-leadership-quick"
        aria-label="<?= e($txt('Quick access', 'وصول سريع')) ?>"
    >
        <a href="<?= e(url_to('revenue')) ?>">◈ <?= e($txt('Revenue', 'الإيرادات')) ?></a>
        <a href="<?= e(url_to('visits')) ?>">♧ <?= e($txt('Visits', 'الزيارات')) ?></a>
        <a href="<?= e(url_to('doctors')) ?>">♙ <?= e($txt('Doctors', 'الأطباء')) ?></a>
        <a href="<?= e(url_to('beds')) ?>">▱ <?= e($txt('Beds & Capacity', 'الأسرة والسعة')) ?></a>
        <a href="<?= e(url_to('action-center')) ?>">⚠ <?= e($txt('Action Center', 'مركز الإجراءات')) ?></a>
    </nav>
</section>
