<?php
$huddle = is_array($huddle ?? null) ? $huddle : [];
$isAr = current_lang() === 'ar';
$txt = static function (string $en, string $ar = '') use ($isAr): string {
    return $isAr && $ar !== '' ? $ar : $en;
};
$pick = static function (array $row, string $key, string $fallback = '') use ($isAr): string {
    if ($isAr && trim((string)($row[$key . '_ar'] ?? '')) !== '') { return (string)$row[$key . '_ar']; }
    return (string)($row[$key] ?? $fallback);
};
$format = static function ($value, string $type = 'number'): string {
    if ($value === null || $value === '') { return '—'; }
    $number = (float)$value;
    if ($type === 'money') { return 'SAR ' . compact_money($number); }
    if ($type === 'percent') { return number_format($number, 1) . '%'; }
    return number_format($number, 0);
};
$short = static function (string $value, int $limit = 190): string {
    $value = trim($value);
    if ($value === '') { return ''; }
    if (function_exists('mb_strlen') && mb_strlen($value, 'UTF-8') > $limit) {
        return mb_substr($value, 0, $limit - 1, 'UTF-8') . '…';
    }
    if (strlen($value) > $limit) { return substr($value, 0, $limit - 1) . '…'; }
    return $value;
};
$statusLabel = static function (string $value) use ($txt): string {
    $value = strtolower(trim($value));
    $map = [
        'open' => $txt('Open', 'مفتوح'),
        'reviewed' => $txt('Reviewed', 'تمت المراجعة'),
        'deferred' => $txt('Deferred', 'مؤجل'),
        'unassigned' => $txt('Unassigned', 'غير مسند'),
        'assigned' => $txt('Assigned', 'مسند'),
        'on_track' => $txt('On Track', 'على المسار'),
        'due_soon' => $txt('Due Soon', 'استحقاق قريب'),
        'follow_up_due' => $txt('Follow-up Due', 'متابعة مستحقة'),
        'overdue' => $txt('Overdue', 'متأخر'),
        'escalated' => $txt('Escalated', 'مصعد'),
        'resolved' => $txt('Resolved', 'تم الحل'),
        'critical' => $txt('Critical', 'حرج'),
        'watch' => $txt('Watch', 'متابعة'),
        'routine' => $txt('Routine', 'روتيني'),
        'opportunity' => $txt('Opportunity', 'فرصة'),
    ];
    return $map[$value] ?? ucfirst(str_replace('_', ' ', $value));
};
$decisionTypeLabel = static function (string $value) use ($txt): string {
    $map = [
        'Leadership decision' => $txt('Leadership decision', 'قرار قيادي'),
        'Recovery decision' => $txt('Recovery decision', 'قرار تصحيحي'),
        'Follow-up decision' => $txt('Follow-up decision', 'قرار متابعة'),
        'Commitment confirmation' => $txt('Commitment confirmation', 'تأكيد الالتزام'),
        'Assign owner' => $txt('Assign owner', 'تعيين مسؤول'),
        'Resolve deferral' => $txt('Resolve deferral', 'حسم التأجيل'),
        'Opportunity review' => $txt('Opportunity review', 'مراجعة فرصة'),
    ];
    return $map[$value] ?? $value;
};

$hospitalName = (string)($hospital['name'] ?? strtoupper((string)($hospitalCode ?? 'NJCH')));
$operationalDate = (string)($huddle['operational_date'] ?? date('Y-m-d'));
$lastUpdated = (string)($huddle['last_updated'] ?? '');
$freshness = strtolower((string)($huddle['freshness'] ?? 'unavailable'));
$executiveStatus = is_array($huddle['executive_status'] ?? null) ? $huddle['executive_status'] : [];
$meeting = is_array($huddle['meeting_status'] ?? null) ? $huddle['meeting_status'] : [];
$statusTone = strtolower((string)($meeting['tone'] ?? $executiveStatus['tone'] ?? 'good'));
$changes = is_array($huddle['meaningful_changes'] ?? null) ? $huddle['meaningful_changes'] : [];
$agenda = is_array($huddle['decision_agenda'] ?? null) ? $huddle['decision_agenda'] : [];
$commitmentRoot = is_array($huddle['open_commitments'] ?? null) ? $huddle['open_commitments'] : [];
$commitments = is_array($commitmentRoot['rows'] ?? null) ? $commitmentRoot['rows'] : [];
$ownerRows = is_array($huddle['owner_accountability'] ?? null) ? $huddle['owner_accountability'] : [];
$decisions = is_array($huddle['documented_decisions'] ?? null) ? $huddle['documented_decisions'] : [];
$comparison = is_array($huddle['day_comparison'] ?? null) ? $huddle['day_comparison'] : [];
$op = is_array($huddle['operational'] ?? null) ? $huddle['operational'] : [];
$operationalWindow = trim((string)($op['window_start'] ?? '') . ' → ' . (string)($op['window_end'] ?? ''), " →\t\n\r\0\x0B");
$meetingState = (string)($meeting['state'] ?? 'READY');
$meetingStateDisplay = $isAr ? ([
    'READY' => 'جاهز',
    'FOCUS' => 'تركيز',
    'ACTION REQUIRED' => 'يتطلب إجراء',
][$meetingState] ?? $meetingState) : $meetingState;
$decisionCount = (int)($meeting['decision_count'] ?? count($agenda));
$overdueCount = (int)($meeting['overdue'] ?? 0);
$followUpCount = (int)($meeting['follow_up_due'] ?? 0);
$unassignedCount = (int)($meeting['unassigned'] ?? 0);
$dueTodayCount = (int)($meeting['due_today'] ?? 0);
?>

<section class="huddle2-page huddle2-tone-<?= e($statusTone) ?>">
    <?php if (!empty($huddleError)): ?>
        <div class="huddle2-error">
            <strong><?= e($txt('The leadership brief could not fully load.', 'تعذر تحميل ملخص اجتماع القيادة بالكامل.')) ?></strong>
            <span><?= e($txt('Refresh the page or contact the dashboard administrator if the issue continues.', 'حدّث الصفحة أو تواصل مع مسؤول النظام إذا استمرت المشكلة.')) ?></span>
        </div>
    <?php endif; ?>

    <header class="huddle2-hero">
        <div class="huddle2-hero-copy">
            <span class="huddle2-phase">Phase 10.7.2</span>
            <small><?= e($txt('DAILY LEADERSHIP HUDDLE', 'اجتماع القيادة اليومي')) ?></small>
            <h2><?= e($txt("Today's leadership focus", 'محور اجتماع القيادة اليوم')) ?></h2>
            <p><?= e($txt(
                'A decision agenda built around change, commitments, ownership and next steps — not a repeat of the main dashboard.',
                'أجندة قرارات مبنية على التغيرات والالتزامات والمسؤولية والخطوات التالية — وليست تكرارًا للوحة الرئيسية.'
            )) ?></p>
            <div class="huddle2-meta">
                <span><b><?= e($txt('Branch', 'الفرع')) ?></b><?= e($hospitalName) ?></span>
                <span><b><?= e($txt('Operational Day', 'اليوم التشغيلي')) ?></b><?= e($operationalDate) ?></span>
                <?php if ($operationalWindow !== ''): ?><span><b><?= e($txt('Window', 'الفترة')) ?></b><?= e($operationalWindow) ?></span><?php endif; ?>
                <span class="freshness-<?= e($freshness) ?>"><b><?= e($txt('Data', 'البيانات')) ?></b><?= e($freshness === 'fresh' ? $txt('Fresh', 'محدثة') : ($freshness === 'stale' ? $txt('Needs refresh', 'تحتاج تحديثًا') : $txt('Unavailable', 'غير متاحة'))) ?></span>
            </div>
        </div>

        <aside class="huddle2-hero-pulse">
            <div class="huddle2-pulse-head">
                <span><?= e($txt('MEETING STATUS', 'حالة الاجتماع')) ?></span>
                <b><?= e($meetingStateDisplay) ?></b>
            </div>
            <div class="huddle2-decision-number">
                <strong><?= e((string)$decisionCount) ?></strong>
                <span><?= e($txt('decisions need leadership attention', 'قرارات تحتاج انتباه القيادة')) ?></span>
            </div>
            <div class="huddle2-hero-actions no-print">
                <button type="button" onclick="window.print()">⎙ <?= e($txt('Print Brief', 'طباعة الملخص')) ?></button>
                <a href="<?= e(url_to('action-center')) ?>"><?= e($txt('Action Center', 'مركز الإجراءات')) ?> →</a>
            </div>
        </aside>
    </header>

    <section class="huddle2-focus-strip" aria-label="Meeting-specific executive focus">
        <article class="focus-decisions">
            <span>◆</span>
            <div><small><?= e($txt('Decisions needed', 'قرارات مطلوبة')) ?></small><strong><?= e((string)$decisionCount) ?></strong></div>
        </article>
        <article class="focus-overdue">
            <span>!</span>
            <div><small><?= e($txt('Overdue commitments', 'التزامات متأخرة')) ?></small><strong><?= e((string)$overdueCount) ?></strong></div>
        </article>
        <article class="focus-followup">
            <span>↻</span>
            <div><small><?= e($txt('Follow-up due', 'متابعة مستحقة')) ?></small><strong><?= e((string)$followUpCount) ?></strong></div>
        </article>
        <article class="focus-owner">
            <span>◎</span>
            <div><small><?= e($txt('Ownership gaps', 'فجوات المسؤولية')) ?></small><strong><?= e((string)$unassignedCount) ?></strong></div>
        </article>
    </section>

    <section class="huddle2-primary-grid">
        <article class="huddle2-panel huddle2-change-panel">
            <header class="huddle2-panel-head">
                <div>
                    <small><?= e($txt('QUESTION 1', 'السؤال 1')) ?></small>
                    <h3><?= e($txt('What changed since yesterday?', 'ما الذي تغيّر منذ الأمس؟')) ?></h3>
                    <p><?= e($txt('Only material movements are shown; routine KPI values stay on the main dashboard.', 'نعرض فقط التغيرات المهمة؛ أما القيم الروتينية فتبقى في اللوحة الرئيسية.')) ?></p>
                </div>
                <?php if (!empty($comparison['available'])): ?><span><?= e((string)($comparison['previous_operational_date'] ?? '')) ?></span><?php endif; ?>
            </header>

            <?php if (empty($comparison['available'])): ?>
                <div class="huddle2-empty huddle2-empty-soft">
                    <strong><?= e($txt('Previous-day comparison is not available yet.', 'مقارنة اليوم السابق غير متاحة حتى الآن.')) ?></strong>
                    <p><?= e($txt('The comparison will appear automatically when a prior operational-day summary is available.', 'ستظهر المقارنة تلقائيًا عند توفر ملخص ليوم تشغيلي سابق.')) ?></p>
                </div>
            <?php elseif (!$changes): ?>
                <div class="huddle2-calm-state">
                    <span>✓</span>
                    <div>
                        <strong><?= e($txt('No material daily movement requires leadership discussion.', 'لا يوجد تغير يومي جوهري يحتاج مناقشة القيادة.')) ?></strong>
                        <p><?= e($txt('The detailed KPI values remain available on the Executive Command Center.', 'تظل تفاصيل المؤشرات متاحة في مركز القيادة التنفيذي.')) ?></p>
                    </div>
                </div>
            <?php else: ?>
                <div class="huddle2-change-grid">
                    <?php foreach ($changes as $change): ?>
                        <?php if (!is_array($change)) { continue; }
                        $direction = (string)($change['direction'] ?? 'flat');
                        $tone = (string)($change['tone'] ?? 'info');
                        $delta = $change['delta'] ?? null;
                        ?>
                        <article class="huddle2-change-card change-<?= e($tone) ?> direction-<?= e($direction) ?>">
                            <div class="huddle2-change-icon"><?= $direction === 'up' ? '↑' : ($direction === 'down' ? '↓' : '→') ?></div>
                            <div class="huddle2-change-main">
                                <small><?= e($pick($change, 'label', 'Metric')) ?></small>
                                <strong><?= e($format($change['current'] ?? null, (string)($change['format'] ?? 'number'))) ?></strong>
                            </div>
                            <div class="huddle2-change-delta">
                                <span><?= e($txt('vs previous day', 'مقارنة باليوم السابق')) ?></span>
                                <b><?= $delta === null ? '—' : e(($direction === 'up' ? '+' : ($direction === 'down' ? '−' : '')) . $format(abs((float)$delta), (string)($change['format'] ?? 'number'))) ?></b>
                            </div>
                        </article>
                    <?php endforeach; ?>
                </div>
            <?php endif; ?>
        </article>

        <aside class="huddle2-panel huddle2-readiness-panel">
            <header class="huddle2-panel-head compact">
                <div>
                    <small><?= e($txt('MEETING READINESS', 'جاهزية الاجتماع')) ?></small>
                    <h3><?= e($txt('What must be settled today?', 'ما الذي يجب حسمه اليوم؟')) ?></h3>
                </div>
            </header>
            <div class="huddle2-readiness-status readiness-<?= e($statusTone) ?>">
                <small><?= e($txt('Leadership focus', 'تركيز القيادة')) ?></small>
                <strong><?= e($meetingStateDisplay) ?></strong>
                <p><?= e($decisionCount > 0
                    ? $txt($decisionCount . ' decision items are ready for discussion.', $decisionCount . ' بنود قرار جاهزة للمناقشة.')
                    : $txt('No unresolved decision item is currently blocking the huddle.', 'لا توجد بنود قرار غير محسومة تعيق الاجتماع حاليًا.')) ?></p>
            </div>
            <div class="huddle2-readiness-list">
                <div><span><?= e($txt('Due today', 'مستحق اليوم')) ?></span><b><?= e((string)$dueTodayCount) ?></b></div>
                <div><span><?= e($txt('Overdue', 'متأخر')) ?></span><b><?= e((string)$overdueCount) ?></b></div>
                <div><span><?= e($txt('Follow-up due', 'متابعة مستحقة')) ?></span><b><?= e((string)$followUpCount) ?></b></div>
                <div><span><?= e($txt('Without owner', 'بدون مسؤول')) ?></span><b><?= e((string)$unassignedCount) ?></b></div>
            </div>
            <div class="huddle2-sequence">
                <small><?= e($txt('HUDDLE SEQUENCE', 'تسلسل الاجتماع')) ?></small>
                <ol>
                    <li><b>1</b><span><?= e($txt('Review material changes', 'مراجعة التغيرات المهمة')) ?></span></li>
                    <li><b>2</b><span><?= e($txt('Take decisions', 'اتخاذ القرارات')) ?></span></li>
                    <li><b>3</b><span><?= e($txt('Confirm owners and due dates', 'تأكيد المسؤولين ومواعيد الاستحقاق')) ?></span></li>
                </ol>
            </div>
        </aside>
    </section>

    <section class="huddle2-panel huddle2-agenda-panel">
        <header class="huddle2-panel-head huddle2-agenda-head">
            <div>
                <small><?= e($txt('QUESTION 2', 'السؤال 2')) ?></small>
                <h3><?= e($txt("Today's decision agenda", 'أجندة قرارات اليوم')) ?></h3>
                <p><?= e($txt('Only items that need a leadership choice, ownership commitment or deferral resolution are shown.', 'نعرض فقط البنود التي تحتاج قرارًا قياديًا أو التزام مسؤولية أو حسم تأجيل.')) ?></p>
            </div>
            <div class="huddle2-agenda-count"><strong><?= e((string)$decisionCount) ?></strong><span><?= e($txt('decision items', 'بنود قرار')) ?></span></div>
        </header>

        <?php if (!$agenda): ?>
            <div class="huddle2-empty huddle2-empty-success">
                <strong><?= e($txt('No decision item currently requires leadership action.', 'لا يوجد بند قرار يحتاج تدخل القيادة حاليًا.')) ?></strong>
                <p><?= e($txt('Continue monitoring the Executive Command Center for operational changes.', 'استمر في متابعة مركز القيادة التنفيذي للتغيرات التشغيلية.')) ?></p>
            </div>
        <?php else: ?>
            <div class="huddle2-agenda-list">
                <?php foreach ($agenda as $index => $item): ?>
                    <?php if (!is_array($item)) { continue; }
                    $severity = strtolower((string)($item['severity'] ?? 'routine'));
                    $accountability = strtolower((string)($item['accountability_status'] ?? 'unassigned'));
                    ?>
                    <article class="huddle2-agenda-item agenda-<?= e($severity) ?>">
                        <div class="huddle2-agenda-rank"><span><?= e((string)($index + 1)) ?></span></div>
                        <div class="huddle2-agenda-body">
                            <div class="huddle2-agenda-title-row">
                                <div>
                                    <div class="huddle2-tags">
                                        <span class="tag-severity"><?= e($statusLabel($severity)) ?></span>
                                        <span class="tag-accountability state-<?= e($accountability) ?>"><?= e($statusLabel($accountability)) ?></span>
                                        <span class="tag-decision"><?= e($decisionTypeLabel((string)($item['decision_type'] ?? 'Leadership decision'))) ?></span>
                                    </div>
                                    <h4><?= e($pick($item, 'title', 'Action')) ?></h4>
                                </div>
                                <a class="no-print" href="index.php?page=action-review&action=<?= rawurlencode((string)($item['action_key'] ?? '')) ?>&lang=<?= e(current_lang()) ?>"><?= e($txt('Open decision', 'فتح القرار')) ?> →</a>
                            </div>
                            <div class="huddle2-decision-grid">
                                <div>
                                    <small><?= e($txt('WHY NOW', 'لماذا الآن')) ?></small>
                                    <p><?= e($short($pick($item, 'why', ''), 210)) ?></p>
                                </div>
                                <div>
                                    <small><?= e($txt('DECISION REQUIRED', 'القرار المطلوب')) ?></small>
                                    <p><?= e($short($pick($item, 'decision_required', ''), 220)) ?></p>
                                </div>
                            </div>
                            <div class="huddle2-agenda-footer">
                                <span><b><?= e($txt('Owner', 'المسؤول')) ?></b><?= e((string)($item['owner_name'] ?? '') ?: $txt('Not assigned', 'غير مسند')) ?></span>
                                <span><b><?= e($txt('Due', 'الاستحقاق')) ?></b><?= e((string)($item['due_date'] ?? '') ?: '—') ?></span>
                                <?php if ((string)($item['follow_up_date'] ?? '') !== ''): ?><span><b><?= e($txt('Follow-up', 'المتابعة')) ?></b><?= e((string)$item['follow_up_date']) ?></span><?php endif; ?>
                            </div>
                        </div>
                    </article>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
    </section>

    <section class="huddle2-secondary-grid">
        <article class="huddle2-panel huddle2-commitments-panel">
            <header class="huddle2-panel-head">
                <div>
                    <small><?= e($txt('QUESTIONS 3 & 6', 'السؤالان 3 و6')) ?></small>
                    <h3><?= e($txt('What is overdue?', 'ما المتأخر؟')) ?></h3>
                    <p><?= e($txt('What happens next? Open commitments are sorted by accountability risk.', 'ما الخطوة التالية؟ يتم ترتيب الالتزامات المفتوحة حسب مخاطر المساءلة.')) ?></p>
                </div>
                <span><?= e((string)($commitmentRoot['total'] ?? count($commitments))) ?></span>
            </header>
            <?php if (!$commitments): ?>
                <div class="huddle2-empty huddle2-empty-success"><strong><?= e($txt('No open commitment requires follow-up.', 'لا توجد التزامات مفتوحة تحتاج متابعة.')) ?></strong></div>
            <?php else: ?>
                <div class="huddle2-commitment-list">
                    <?php foreach ($commitments as $row): ?>
                        <?php if (!is_array($row)) { continue; }
                        $state = strtolower((string)($row['accountability_status'] ?? 'unassigned'));
                        ?>
                        <a href="index.php?page=action-review&action=<?= rawurlencode((string)($row['action_key'] ?? '')) ?>&lang=<?= e(current_lang()) ?>" class="huddle2-commitment-row">
                            <span class="commitment-state state-<?= e($state) ?>"><?= e($statusLabel($state)) ?></span>
                            <div class="commitment-title"><strong><?= e($pick($row, 'title', 'Action')) ?></strong><small><?= e($statusLabel((string)($row['severity'] ?? 'routine'))) ?></small></div>
                            <div class="commitment-owner"><small><?= e($txt('Owner', 'المسؤول')) ?></small><b><?= e((string)($row['owner_name'] ?? '') ?: $txt('Not assigned', 'غير مسند')) ?></b></div>
                            <div class="commitment-due"><small><?= e($txt('Due', 'الاستحقاق')) ?></small><b><?= e((string)($row['due_date'] ?? '') ?: '—') ?></b></div>
                        </a>
                    <?php endforeach; ?>
                    <?php if ((int)($commitmentRoot['remaining'] ?? 0) > 0): ?>
                        <a class="huddle2-more-link no-print" href="<?= e(url_to('action-governance-dashboard')) ?>">+<?= e((string)$commitmentRoot['remaining']) ?> <?= e($txt('more commitments', 'التزامات أخرى')) ?> →</a>
                    <?php endif; ?>
                </div>
            <?php endif; ?>
        </article>

        <aside class="huddle2-panel huddle2-owners-panel">
            <header class="huddle2-panel-head">
                <div>
                    <small><?= e($txt('QUESTION 4', 'السؤال 4')) ?></small>
                    <h3><?= e($txt('Who owns what?', 'من المسؤول عن ماذا؟')) ?></h3>
                    <p><?= e($txt('Accountability workload, not activity volume.', 'عبء المساءلة، وليس مجرد حجم النشاط.')) ?></p>
                </div>
                <a class="no-print" href="<?= e(url_to('action-governance-dashboard')) ?>"><?= e($txt('Governance', 'الحوكمة')) ?> →</a>
            </header>
            <?php if (!$ownerRows): ?>
                <div class="huddle2-empty"><strong><?= e($txt('No accountability workload is available.', 'لا توجد بيانات عبء مساءلة متاحة.')) ?></strong></div>
            <?php else: ?>
                <div class="huddle2-owner-list">
                    <?php foreach ($ownerRows as $index => $owner): ?>
                        <?php if (!is_array($owner)) { continue; }
                        $ownerName = (string)($owner['owner'] ?? 'Unassigned');
                        $isUnassigned = strtolower($ownerName) === 'unassigned';
                        ?>
                        <article class="huddle2-owner-row <?= $isUnassigned ? 'owner-gap' : '' ?>">
                            <div class="huddle2-owner-avatar"><?= e($isUnassigned ? '!' : strtoupper(substr($ownerName, 0, 1))) ?></div>
                            <div class="huddle2-owner-name">
                                <strong><?= e($isUnassigned ? $txt('Ownership gap', 'فجوة مسؤولية') : $ownerName) ?></strong>
                                <span><?= e((string)($owner['active'] ?? 0)) ?> <?= e($txt('active commitments', 'التزامات نشطة')) ?></span>
                            </div>
                            <div class="huddle2-owner-metrics">
                                <span><b><?= e((string)($owner['overdue'] ?? 0)) ?></b><?= e($txt('overdue', 'متأخر')) ?></span>
                                <span><b><?= e((string)($owner['escalated'] ?? 0)) ?></b><?= e($txt('escalated', 'مصعد')) ?></span>
                            </div>
                        </article>
                    <?php endforeach; ?>
                </div>
            <?php endif; ?>
        </aside>
    </section>

    <section class="huddle2-panel huddle2-decisions-panel">
        <header class="huddle2-panel-head">
            <div>
                <small><?= e($txt('QUESTION 5', 'السؤال 5')) ?></small>
                <h3><?= e($txt('What was decided today?', 'ما الذي تم تقريره اليوم؟')) ?></h3>
                <p><?= e($txt('Only documented human decisions and resolutions are shown. QA activity and placeholder notes are excluded.', 'نعرض فقط القرارات والحلول البشرية الموثقة. يتم استبعاد نشاط الاختبار والملاحظات المؤقتة.')) ?></p>
            </div>
            <span><?= e((string)count($decisions)) ?></span>
        </header>
        <?php if (!$decisions): ?>
            <div class="huddle2-decision-empty">
                <div>✎</div>
                <section>
                    <strong><?= e($txt('No documented leadership decision has been recorded for this operational day yet.', 'لم يتم توثيق قرار قيادي لهذا اليوم التشغيلي حتى الآن.')) ?></strong>
                    <p><?= e($txt('Record the decision, owner and follow-up in Action Review so the next huddle starts with accountable commitments.', 'سجّل القرار والمسؤول والمتابعة في صفحة مراجعة الإجراء حتى يبدأ الاجتماع التالي بالتزامات واضحة.')) ?></p>
                </section>
                <a class="no-print" href="<?= e(url_to('action-center')) ?>"><?= e($txt('Open actions', 'فتح الإجراءات')) ?> →</a>
            </div>
        <?php else: ?>
            <div class="huddle2-decision-timeline">
                <?php foreach ($decisions as $decision): ?>
                    <?php if (!is_array($decision)) { continue; } ?>
                    <article>
                        <div class="decision-dot"></div>
                        <div>
                            <span><?= e((string)($decision['type'] ?? '') === 'resolution' ? $txt('RESOLUTION', 'حل') : (((string)($decision['type'] ?? '') === 'deferred_decision') ? $txt('DEFERRED DECISION', 'قرار تأجيل') : $txt('DECISION', 'قرار'))) ?></span>
                            <h4><?= e($pick($decision, 'title', 'Action')) ?></h4>
                            <p><?= e($short((string)($decision['decision'] ?? ''), 300)) ?></p>
                            <small><?= e((string)($decision['by'] ?? '') ?: '—') ?> · <?= e((string)($decision['at'] ?? '') ?: '—') ?></small>
                        </div>
                    </article>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
    </section>

    <footer class="huddle2-footer">
        <div>
            <strong><?= e($txt('Purpose of this page', 'هدف هذه الصفحة')) ?></strong>
            <span><?= e($txt('Decision agenda + commitments + accountability. Detailed KPI monitoring remains in the Executive Command Center.', 'أجندة قرارات + التزامات + مساءلة. تبقى المراقبة التفصيلية للمؤشرات في مركز القيادة التنفيذي.')) ?></span>
        </div>
        <div>
            <span><b><?= e($txt('Operational Day', 'اليوم التشغيلي')) ?></b><?= e($operationalDate) ?></span>
            <span><b><?= e($txt('Last Updated', 'آخر تحديث')) ?></b><?= e($lastUpdated !== '' ? $lastUpdated : '—') ?></span>
            <span><b><?= e($txt('Report', 'التقرير')) ?></b>Phase 10.7.2</span>
        </div>
    </footer>
</section>
