<?php


if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// Panel version (read from the project root `version` file). Displayed in the
// sidebar footer on every page. Always shown with a leading "v".
$__panelVersionRaw = trim((string)@file_get_contents(__DIR__ . '/../version'));
if ($__panelVersionRaw === '') $__panelVersionRaw = '5.0.0-omni';
$__panelVersion = (stripos($__panelVersionRaw, 'v') === 0) ? $__panelVersionRaw : ('v' . $__panelVersionRaw);

if (isset($_SESSION["user"])) {
    $__can_check = false;
    $__ip_list   = [];
    $__iplogin_unlimited = false;
    if (isset($pdo) && $pdo instanceof PDO) {
        $__can_check   = true;
        $__stmt_ip     = $pdo->query("SELECT iplogin FROM setting LIMIT 1");
        $__raw_iplogin = $__stmt_ip ? (string)$__stmt_ip->fetchColumn() : '';
        if ($__raw_iplogin === '*' || $__raw_iplogin === 'all' || $__raw_iplogin === 'unlimited') {
            $__iplogin_unlimited = true;
        } elseif ($__raw_iplogin !== '' && $__raw_iplogin !== '0') {
            $__decoded = json_decode($__raw_iplogin, true);
            if (is_array($__decoded)) {
                if (in_array('*', $__decoded, true) || in_array('all', $__decoded, true) || in_array('unlimited', $__decoded, true)) {
                    $__iplogin_unlimited = true;
                } else {
                    $__ip_list = $__decoded;
                }
            } elseif (filter_var($__raw_iplogin, FILTER_VALIDATE_IP)) {
                $__ip_list = [$__raw_iplogin];
            }
        }
    }
    if ($__can_check) {
        $__current_ip = $_SERVER['REMOTE_ADDR'] ?? '';
        $__allowed    = $__iplogin_unlimited || (!empty($__ip_list) && in_array($__current_ip, $__ip_list, true));
        if (!$__allowed) {
            session_unset();
            session_destroy();
            header('Location: login.php', true, 302);
            exit;
        }
        unset($__current_ip, $__allowed);
    }
    unset($__can_check, $__ip_list, $__raw_iplogin, $__decoded, $__stmt_ip, $__iplogin_unlimited);
}


if (!function_exists('icon')) {
    $__iconsLib = __DIR__ . '/lib/icons.php';
    if (is_file($__iconsLib) && is_readable($__iconsLib)) {
        @include_once $__iconsLib;
    }
}
if (!function_exists('icon')) {
    function icon(string $name, string $class = 'svg-icon'): string {
        static $paths = [
            'bars'        => '<line x1="4" y1="6"  x2="20" y2="6"/><line x1="4" y1="12" x2="20" y2="12"/><line x1="4" y1="18" x2="20" y2="18"/>',
            'robot'       => '<rect x="3" y="11" width="18" height="10" rx="2" ry="2"/><circle cx="12" cy="5" r="2"/><path d="M12 7v4"/><line x1="8"  y1="16" x2="8.01" y2="16"/><line x1="16" y1="16" x2="16.01" y2="16"/>',
            'chevron-down'=> '<polyline points="6 9 12 15 18 9"/>',
            'moon'        => '<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>',
            'arrow-right-from-bracket' => '<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/>',
            'home'        => '<path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/>',
            'users'       => '<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/>',
            'dollar-sign' => '<line x1="12" y1="1" x2="12" y2="23"/><path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/>',
            'package'     => '<line x1="16.5" y1="9.4" x2="7.5" y2="4.21"/><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><polyline points="3.27 6.96 12 12.01 20.73 6.96"/><line x1="12" y1="22.08" x2="12" y2="12"/>',
            'grid'        => '<rect x="3"  y="3"  width="7" height="7"/><rect x="14" y="3"  width="7" height="7"/><rect x="14" y="14" width="7" height="7"/><rect x="3"  y="14" width="7" height="7"/>',
            'wallet'      => '<rect x="2" y="6" width="20" height="14" rx="2"/><polyline points="22 12 18 12 18 16 22 16"/><path d="M2 10V6a2 2 0 0 1 2-2h14"/>',
            'ban'         => '<circle cx="12" cy="12" r="10"/><line x1="4.93" y1="4.93" x2="19.07" y2="19.07"/>',
            'keyboard'    => '<rect x="2" y="4" width="20" height="16" rx="2" ry="2"/><line x1="6"  y1="8" x2="6.01" y2="8"/><line x1="10" y1="8" x2="10.01" y2="8"/><line x1="14" y1="8" x2="14.01" y2="8"/><line x1="18" y1="8" x2="18.01" y2="8"/><line x1="7"  y1="16" x2="17" y2="16"/>',
        ];
        $p = $paths[$name] ?? '<circle cx="12" cy="12" r="3"/>';
        return '<svg class="' . htmlspecialchars($class, ENT_QUOTES, 'UTF-8') . '" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' . $p . '</svg>';
    }
}

$__user    = isset($_SESSION["user"]) ? htmlspecialchars($_SESSION["user"], ENT_QUOTES, 'UTF-8') : 'admin';
$__current = strtolower(basename($_SERVER['SCRIPT_NAME'] ?? 'index.php'));
$__avatar  = function_exists('mb_substr') ? mb_substr($__user, 0, 1, 'UTF-8') : substr($__user, 0, 1);


$__schemaLib = __DIR__ . '/lib/schema.php';
if (is_file($__schemaLib) && is_readable($__schemaLib)) {
    @include_once $__schemaLib;
    if (function_exists('aycore_schema_ready') && isset($pdo) && $pdo instanceof PDO) {
        try { aycore_schema_ready($pdo); } catch (\Throwable $e) { error_log('[header] schema_ready failed: ' . $e->getMessage()); }
    }
}
?>

<link rel="stylesheet" href="css/ay-controls.css">
<link rel="stylesheet" href="css/v5-omni.css?v=<?php echo rawurlencode($__panelVersion); ?>">
<link rel="stylesheet" href="css/v7-architect.css?v=<?php echo rawurlencode($__panelVersion); ?>">
<script>
(function () {
    try {


        var color = localStorage.getItem('itzaydin_v4_color') || localStorage.getItem('aycore_color') || 'blue';
        var html = document.documentElement;
        var s = html.style;
        var PRESET = { red:'#ef4444', blue:'#3b82f6', purple:'#a855f7', yellow:'#facc15', orange:'#f97316', green:'#22c55e' };
        function fg(r,g,b){ function lin(v){ v/=255; return v<=0.03928 ? v/12.92 : Math.pow((v+0.055)/1.055,2.4); } var L=0.2126*lin(r)+0.7152*lin(g)+0.0722*lin(b); return L>0.45?'#14121d':'#ffffff'; }
        var hex;
        if (PRESET[color]) { hex = PRESET[color]; html.setAttribute('data-color', color); }
        else {
            var m=/^#?([0-9a-f]{6})$/i.exec(color);
            if (m) { hex='#'+m[1].toLowerCase(); var n=parseInt(m[1],16),r=(n>>16)&255,g=(n>>8)&255,b=n&255;
                s.setProperty('--accent',hex); s.setProperty('--accent-soft','rgba('+r+','+g+','+b+',0.15)');
                s.setProperty('--accent-mid','rgba('+r+','+g+','+b+',0.35)'); s.setProperty('--accent-glow','rgba('+r+','+g+','+b+',0.5)');
                html.setAttribute('data-color','custom'); }
            else { hex=PRESET.blue; html.setAttribute('data-color','blue'); }
        }
        var pn=parseInt(hex.slice(1),16); s.setProperty('--accent-fg', fg((pn>>16)&255,(pn>>8)&255,pn&255));
        html.setAttribute('data-theme','dark');
    } catch (e) {  }
})();
</script>

<header class="app-header">
    <div class="app-header__left">
        <button class="btn-icon" id="sidebar-toggle" aria-label="منو">
            <?php echo icon('bars'); ?>
        </button>
        <a href="index.php" class="app-logo">
            <span class="app-logo__mark"><?php echo icon('robot', 'svg-icon svg-sm'); ?></span>
            <span>iTzAYDiN<span class="ay-logo-thin">/BOT</span></span>
        </a>
        <span class="app-status-pill"><i class="ay-live-dot"></i> iTz Core • آماده مدیریت</span>
        <button type="button" class="ay-command-open" id="ayCommandOpen" aria-label="جستجوی سریع بخش‌های مدیریت">
            <span>⌘</span><b>iTz Finder</b><kbd>Ctrl K</kbd>
        </button>
    </div>

    <div class="profile-wrap">
        <button class="profile-trigger" type="button" aria-label="حساب کاربری">
            
            <span class="profile-avatar itz-brand-avatar" title="iTzAYDiN-BOT" aria-label="iTzAYDiN-BOT">
                iTz
            </span>
            <span class="profile-info">
                <b>iTz Operator</b>
                <small><?php echo $__user; ?></small>
            </span>
            <?php echo icon('chevron-down', 'svg-icon svg-xs'); ?>
        </button>

        <div class="profile-menu">
            <div class="profile-menu__head">
                <b><?php echo $__user; ?></b>
                <small>دسترسی مالک سیستم</small>
            </div>

            <a href="appearance.php" class="menu-item">
                <svg class="svg-icon svg-sm" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 8 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H2a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 3.6 8a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H8a1.65 1.65 0 0 0 1-1.51V2a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V8a1.65 1.65 0 0 0 1.51 1H22a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>
                <span>شخصی‌سازی رابط</span>
            </a>

            <hr>

            <a href="login.php" class="menu-danger">
                <?php echo icon('arrow-right-from-bracket', 'svg-icon svg-sm'); ?>
                <span>پایان نشست مدیریت</span>
            </a>
        </div>
    </div>
</header>

<aside class="app-sidebar ay-v5-sidebar">
    <div class="ay-side-brand">
        <div class="ay-side-brand__mark">iTz</div>
        <div><strong>iTzAYDiN-BOT</strong><small>Independent Control Suite</small></div>
    </div>

    <div class="sidebar-section-label">فرماندهی</div>
    <ul class="sidebar-menu">
        <li><a href="index.php"><span class="menu-symbol"><?php echo icon('home', 'svg-icon svg-sm'); ?></span><span>نمای کلی سیستم</span></a></li>
        <li><a href="control.php"><span class="menu-symbol"><?php echo icon('sliders', 'svg-icon svg-sm'); ?></span><span>iTz Command Center</span></a></li>
        <li><a href="architecture.php"><span class="menu-symbol">🧬</span><span>V7 Architecture OS</span></a></li>
        <li><a href="automations.php"><span class="menu-symbol">⚡</span><span>Automation Studio</span></a></li>
        <li><a href="observability.php"><span class="menu-symbol">📡</span><span>Observability</span></a></li>
        <li><a href="customer360.php"><span class="menu-symbol">🧠</span><span>Customer 360</span></a></li>
        <li><a href="tasks.php"><span class="menu-symbol">✅</span><span>Task Center</span></a></li>
        <li><a href="ops.php"><span class="menu-symbol"><?php echo icon('shield', 'svg-icon svg-sm'); ?></span><span>سلامت و عملیات</span></a></li>
        <li><a href="system.php"><span class="menu-symbol"><?php echo icon('gear', 'svg-icon svg-sm'); ?></span><span>تنظیمات هسته</span></a></li>
    </ul>

    <div class="sidebar-section-label">فروش و مشتری</div>
    <ul class="sidebar-menu">
        <li><a href="commerce.php"><span class="menu-symbol">🛒</span><span>iTz Commerce Hub</span></a></li>
        <li><a href="users.php"><span class="menu-symbol"><?php echo icon('users', 'svg-icon svg-sm'); ?></span><span>مرکز مرکز کاربران</span></a></li>
        <li><a href="invoice.php"><span class="menu-symbol"><?php echo icon('dollar-sign', 'svg-icon svg-sm'); ?></span><span>سفارش‌ها و فاکتورها</span></a></li>
        <li><a href="service.php"><span class="menu-symbol"><?php echo icon('package', 'svg-icon svg-sm'); ?></span><span>اشتراک‌های فعال</span></a></li>
        <li><a href="product.php"><span class="menu-symbol"><?php echo icon('grid', 'svg-icon svg-sm'); ?></span><span>پلن‌ها و پلن‌ها</span></a></li>
        <li><a href="discounts.php"><span class="menu-symbol"><?php echo icon('ticket', 'svg-icon svg-sm'); ?></span><span>کمپین و تخفیف</span></a></li>
        <li><a href="cancelService.php"><span class="menu-symbol"><?php echo icon('list', 'svg-icon svg-sm'); ?></span><span>صف درخواست‌ها</span></a></li>
    </ul>

    <div class="sidebar-section-label">زیرساخت سرویس</div>
    <ul class="sidebar-menu">
        <li><a href="xui.php"><span class="menu-symbol"><?php echo icon('server', 'svg-icon svg-sm'); ?></span><span>3x-ui Modern Hub</span></a></li>
        <li><a href="pasarguard.php"><span class="menu-symbol">🛡</span><span>PasarGuard Hub</span></a></li>
        <li><a href="rebecca.php"><span class="menu-symbol">🧬</span><span>Rebecca Hub</span></a></li>
        <li><a href="backend-hub.php"><span class="menu-symbol">🧩</span><span>Backend Capability Hub</span></a></li>
        <li><a href="panels.php"><span class="menu-symbol"><?php echo icon('server', 'svg-icon svg-sm'); ?></span><span>Backend Registry</span></a></li>
        <li><a href="inbound.php"><span class="menu-symbol"><?php echo icon('sliders', 'svg-icon svg-sm'); ?></span><span>Inbound Studio</span></a></li>
        <li><a href="stock.php"><span class="menu-symbol"><?php echo icon('package', 'svg-icon svg-sm'); ?></span><span>خزانه کانفیگ</span></a></li>
        <li><a href="applinks.php"><span class="menu-symbol"><?php echo icon('grid', 'svg-icon svg-sm'); ?></span><span>کلاینت‌ها و لینک دانلود</span></a></li>
    </ul>

    <div class="sidebar-section-label">مالی</div>
    <ul class="sidebar-menu">
        <li><a href="finance.php"><span class="menu-symbol"><?php echo icon('wallet', 'svg-icon svg-sm'); ?></span><span>Payment Lab</span></a></li>
        <li><a href="payment.php"><span class="menu-symbol"><?php echo icon('dollar-sign', 'svg-icon svg-sm'); ?></span><span>دفتر دفتر تراکنش‌ها</span></a></li>
        <li><a href="shopsettings.php"><span class="menu-symbol"><?php echo icon('grid', 'svg-icon svg-sm'); ?></span><span>سیاست فروشگاه</span></a></li>
    </ul>

    <div class="sidebar-section-label">تجربه ربات</div>
    <ul class="sidebar-menu">
        <li><a href="textbot.php"><span class="menu-symbol"><?php echo icon('text', 'svg-icon svg-sm'); ?></span><span>iTz Text Studio</span></a></li>
        <li><a href="keyboard.php"><span class="menu-symbol"><?php echo icon('keyboard', 'svg-icon svg-sm'); ?></span><span>Menu Composer</span></a></li>
        <li><a href="service_keyboard.php"><span class="menu-symbol"><?php echo icon('palette', 'svg-icon svg-sm'); ?></span><span>Button Style Lab</span></a></li>
        <li><a href="broadcast.php"><span class="menu-symbol"><?php echo icon('users', 'svg-icon svg-sm'); ?></span><span>مرکز اعلان و ارسال</span></a></li>
        <li><a href="settings.php"><span class="menu-symbol"><?php echo icon('gear', 'svg-icon svg-sm'); ?></span><span>رفتار ربات و امنیت</span></a></li>
        <li><a href="appearance.php"><span class="menu-symbol"><?php echo icon('palette', 'svg-icon svg-sm'); ?></span><span>هویت بصری</span></a></li>
    </ul>

    <div class="sidebar-version ay-side-version">
        <span class="ay-version-dot"></span>
        <div><small>iTz Independent</small><b><?php echo htmlspecialchars($__panelVersion, ENT_QUOTES, 'UTF-8'); ?></b></div>
    </div>
</aside>

<div class="sidebar-overlay"></div>

<div class="ay-command" id="ayCommand" aria-hidden="true">
    <div class="ay-command__backdrop" data-ay-command-close></div>
    <div class="ay-command__panel" role="dialog" aria-modal="true" aria-label="iTz Finder">
        <div class="ay-command__head"><span class="ay-command__mark">iTz</span><div><b>iTz Finder</b><small>اسم قابلیت را بنویس؛ مستقیم برو همان بخش</small></div><button type="button" class="btn-icon" data-ay-command-close aria-label="بستن">×</button></div>
        <input id="ayCommandSearch" class="ay-command__search" type="search" placeholder="مثلاً: تتراپی، Inbound، کاربر، متن، بکاپ…" autocomplete="off">
        <div class="ay-command__results" id="ayCommandResults">
            <?php
            $__ayCommands = [
                ['control.php','iTz Command Center','کنترل مرکزی قابلیت‌های ربات'],
                ['architecture.php','V7 Architecture OS','module feature flag rollout kill switch'],
                ['automations.php','Automation Studio','event condition action rule tag task'],
                ['observability.php','Observability','event metric audit telemetry timeline'],
                ['customer360.php','Customer 360','crm tag score task user history'],
                ['tasks.php','Task Center','automation tasks follow up admin queue'],
                ['xui.php','3x-ui Modern Hub','ثنایی جدید token inbound auto sync legacy'],
                ['pasarguard.php','iTz PasarGuard Hub','pasarguard api reseller role admin traffic'],
                ['rebecca.php','iTz Rebecca Hub','rebecca service node user openapi host inbound'],
                ['backend-hub.php','Backend Capability Hub','تمام پنل‌ها lifecycle feature matrix health'],
                ['panels.php','Backend Registry','marzban pasarguard hiddify x-ui backend'],
                ['system.php','Core Settings','setting rollback تنظیمات هسته'],
                ['textbot.php','iTz Text Studio','متن جستجو premium emoji'],
                ['ops.php','Operations & Health','سلامت webhook backup cache امنیت diagnostics'],
                ['keyboard.php','Menu Composer','دکمه چیدمان منوی ربات'],
                ['commerce.php','iTz Commerce Hub','سایت فروشگاه سفارش محصول پارامتر webhook api payment bridge'],
                ['users.php','مرکز کاربران','حساب موجودی دسترسی'],
                ['invoice.php','سفارش‌ها','فاکتور خرید سفارش'],
                ['service.php','اشتراک‌ها','اشتراک کانفیگ فعال'],
                ['product.php','پلن‌ها','پلن حجم زمان قیمت'],
                ['payment.php','دفتر دفتر تراکنش‌ها','درگاه تراکنش مالی رسید'],
                ['finance.php','Payment Lab','درگاه تتراپی api key مالی'],
                ['discounts.php','Campaign Studio','کد کمپین فروش'],
                ['stock.php','خزانه کانفیگ','ظرفیت شبکه داخلی stock'],
                ['broadcast.php','مرکز اعلان','پیام اعلان broadcast'],
                ['shopsettings.php','سیاست فروشگاه','خرید برند فروش'],
                ['settings.php','رفتار ربات','امنیت رفتار سرویس'],
                ['appearance.php','هویت بصری','تم رنگ برند رابط'],
                ['service_keyboard.php','Button Style Lab','رنگ سرویس keyboard'],
                ['applinks.php','Client Links','دانلود کلاینت'],
                ['cancelService.php','Service Queue','لغو صف رسیدگی'],
                ['inbound.php','Inbound Studio','اینباند اتصال'],
            ];
            foreach ($__ayCommands as $__cmd):
                $__hayRaw = implode(' ', $__cmd);
                $__hay = function_exists('mb_strtolower') ? mb_strtolower($__hayRaw, 'UTF-8') : strtolower($__hayRaw);
            ?>
            <a class="ay-command__item" href="<?php echo htmlspecialchars($__cmd[0],ENT_QUOTES); ?>" data-ay-search="<?php echo htmlspecialchars($__hay,ENT_QUOTES,'UTF-8'); ?>"><span><?php echo htmlspecialchars($__cmd[1],ENT_QUOTES,'UTF-8'); ?></span><small><?php echo htmlspecialchars($__cmd[2],ENT_QUOTES,'UTF-8'); ?></small><b>↵</b></a>
            <?php endforeach; unset($__ayCommands,$__cmd,$__hay,$__hayRaw); ?>
        </div>
        <div class="ay-command__foot"><span><kbd>↑</kbd><kbd>↓</kbd> انتخاب</span><span><kbd>Enter</kbd> بازکردن</span><span><kbd>Esc</kbd> بستن</span></div>
    </div>
</div>
<script>
(function(){
    var box=document.getElementById('ayCommand'), openBtn=document.getElementById('ayCommandOpen'), input=document.getElementById('ayCommandSearch');
    if(!box||!input) return;
    var items=[].slice.call(box.querySelectorAll('.ay-command__item')), visible=[], idx=0;
    function render(){ var q=(input.value||'').trim().toLocaleLowerCase('fa'); visible=[]; items.forEach(function(a){ var ok=!q||(a.getAttribute('data-ay-search')||'').toLocaleLowerCase('fa').indexOf(q)!==-1; a.hidden=!ok; a.classList.remove('is-active'); if(ok) visible.push(a); }); idx=0; if(visible[0]) visible[0].classList.add('is-active'); }
    function show(){box.classList.add('is-open');box.setAttribute('aria-hidden','false');document.body.classList.add('ay-command-lock');input.value='';render();setTimeout(function(){input.focus();},30);}
    function hide(){box.classList.remove('is-open');box.setAttribute('aria-hidden','true');document.body.classList.remove('ay-command-lock');}
    function move(delta){if(!visible.length)return;visible[idx]&&visible[idx].classList.remove('is-active');idx=(idx+delta+visible.length)%visible.length;visible[idx].classList.add('is-active');visible[idx].scrollIntoView({block:'nearest'});}
    openBtn&&openBtn.addEventListener('click',show); box.querySelectorAll('[data-ay-command-close]').forEach(function(x){x.addEventListener('click',hide);}); input.addEventListener('input',render);
    document.addEventListener('keydown',function(e){ if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==='k'){e.preventDefault();box.classList.contains('is-open')?hide():show();return;} if(!box.classList.contains('is-open'))return; if(e.key==='Escape'){hide();} else if(e.key==='ArrowDown'){e.preventDefault();move(1);} else if(e.key==='ArrowUp'){e.preventDefault();move(-1);} else if(e.key==='Enter'&&visible[idx]){e.preventDefault();location.href=visible[idx].href;} });
})();
</script>

