<?php
/**
 * Full admin skin + ALFASMART live visitor dashboard.
 *
 * @package ALFASMART
 */

if (! defined('ABSPATH')) {
    exit;
}

/* --------------------------------------------------------------------------
 * Favicon helpers
 * -------------------------------------------------------------------------- */

function alfasmart_admin_favicon_id()
{
    $favicon = null;

    if (function_exists('get_field')) {
        foreach (array('option', 'options', 'option_en', 'options_en', 'option_ar', 'options_ar') as $option_post_id) {
            $favicon = get_field('favicon', $option_post_id);
            if ($favicon) {
                break;
            }
        }
    }

    if (is_array($favicon)) {
        return (int) ($favicon['ID'] ?? $favicon['id'] ?? 0);
    }

    if (is_numeric($favicon)) {
        return (int) $favicon;
    }

    return (int) get_option('site_icon');
}

function alfasmart_is_https_request()
{
    if (is_ssl()) {
        return true;
    }

    if (! empty($_SERVER['HTTPS']) && 'off' !== strtolower((string) $_SERVER['HTTPS'])) {
        return true;
    }

    if (! empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && 'https' === strtolower((string) $_SERVER['HTTP_X_FORWARDED_PROTO'])) {
        return true;
    }

    return 'https' === wp_parse_url(home_url('/'), PHP_URL_SCHEME);
}

function alfasmart_admin_favicon_url($allow_core_fallback = true)
{
    $favicon_id = alfasmart_admin_favicon_id();
    $favicon    = $favicon_id ? wp_get_attachment_image_url($favicon_id, 'full') : '';

    if (! $favicon && function_exists('alfasmart_get_option_image_url')) {
        $favicon = alfasmart_get_option_image_url('favicon');
    }

    if (! $favicon && $allow_core_fallback && function_exists('get_site_icon_url')) {
        $favicon = get_site_icon_url();
    }

    if (! $favicon) {
        return '';
    }

    $favicon = set_url_scheme($favicon, alfasmart_is_https_request() ? 'https' : 'http');

    return add_query_arg('as-favicon', $favicon_id ?: md5($favicon), $favicon);
}

function alfasmart_print_favicon_tags()
{
    $favicon = alfasmart_admin_favicon_url();

    if (! $favicon) {
        return;
    }

    printf('<link rel="icon" href="%s" sizes="32x32">' . "\n", esc_url($favicon));
    printf('<link rel="icon" href="%s" sizes="192x192">' . "\n", esc_url($favicon));
    printf('<link rel="shortcut icon" href="%s">' . "\n", esc_url($favicon));
    printf('<link rel="apple-touch-icon" href="%s">' . "\n", esc_url($favicon));
}

function alfasmart_sync_wp_site_icon()
{
    $favicon_id = alfasmart_admin_favicon_id();

    if ($favicon_id && (int) get_option('site_icon') !== $favicon_id) {
        update_option('site_icon', $favicon_id);
    }
}

add_filter('get_site_icon_url', function ($url, $size, $blog_id) {
    $favicon = alfasmart_admin_favicon_url(false);

    return $favicon ?: $url;
}, 10, 3);

add_filter('site_icon_meta_tags', function ($meta_tags) {
    $favicon = alfasmart_admin_favicon_url(false);

    if (! $favicon) {
        return $meta_tags;
    }

    return array(
        sprintf('<link rel="icon" href="%s" sizes="32x32" />', esc_url($favicon)),
        sprintf('<link rel="icon" href="%s" sizes="192x192" />', esc_url($favicon)),
        sprintf('<link rel="apple-touch-icon" href="%s" />', esc_url($favicon)),
        sprintf('<meta name="msapplication-TileImage" content="%s" />', esc_url($favicon)),
    );
});

add_action('init', 'alfasmart_sync_wp_site_icon', 20);
add_action('admin_init', 'alfasmart_sync_wp_site_icon', 20);
add_action('acf/save_post', 'alfasmart_sync_wp_site_icon', 20);
add_action('wp_head', 'alfasmart_print_favicon_tags', 1);
add_action('admin_head', 'alfasmart_print_favicon_tags', 1);
add_action('admin_head', 'alfasmart_print_favicon_tags', 99);
add_action('login_head', 'alfasmart_print_favicon_tags', 1);
add_action('login_head', 'alfasmart_print_favicon_tags', 99);

/* --------------------------------------------------------------------------
 * Admin brand polish
 * -------------------------------------------------------------------------- */

add_action('admin_head', function () {
    ?>
    <style>
        :root {
            --as-admin-accent: #4862ff;
            --as-admin-accent-dark: #354be2;
            --as-admin-dark: #111522;
        }

        #wpadminbar,
        #adminmenu,
        #adminmenuback,
        #adminmenuwrap {
            background: var(--as-admin-dark);
        }

        #adminmenu .wp-has-current-submenu .wp-submenu,
        #adminmenu .wp-submenu,
        #adminmenu li.current a.menu-top,
        #adminmenu li.wp-has-current-submenu a.wp-has-current-submenu {
            background: #171c2d;
        }

        #adminmenu a:hover,
        #adminmenu li.menu-top:hover,
        #adminmenu li.opensub > a.menu-top,
        .wp-core-ui .button-primary {
            background: var(--as-admin-accent);
            border-color: var(--as-admin-accent);
            color: #fff;
        }

        .wp-core-ui .button-primary:hover,
        .wp-core-ui .button-primary:focus {
            background: var(--as-admin-accent-dark);
            border-color: var(--as-admin-accent-dark);
        }

        .acf-field .acf-label label {
            font-weight: 700;
        }
    </style>
    <?php
});

add_action('admin_bar_menu', function ($wp_admin_bar) {
    $wp_admin_bar->remove_node('wp-logo');

    if (is_admin()) {
        $wp_admin_bar->add_node(array(
            'id'    => 'as-admin-theme-toggle',
            'title' => '<span class="ab-icon dashicons dashicons-lightbulb"></span><span class="ab-label">Mode</span>',
            'href'  => '#as-toggle-admin-theme',
            'meta'  => array(
                'class' => 'as-adminbar-theme-toggle',
                'title' => __('Toggle admin light/dark mode', 'alfasmart'),
            ),
        ));
    }
}, 999);



/* --------------------------------------------------------------------------
 * Full admin theme persistence, no flash, and footer branding
 * -------------------------------------------------------------------------- */

function alfasmart_admin_saved_theme_mode()
{
    $mode = isset($_COOKIE['as_admin_theme']) ? sanitize_key(wp_unslash($_COOKIE['as_admin_theme'])) : '';

    if (! in_array($mode, array('dark', 'light'), true)) {
        $mode = '';
    }

    return $mode;
}

add_filter('admin_body_class', function ($classes) {
    if ('dark' === alfasmart_admin_saved_theme_mode()) {
        $classes .= ' as-admin-skin-dark-page as-admin-dashboard-dark-page';
    }

    return $classes;
});

add_action('admin_head', function () {
    ?>
    <script>
        (function () {
            try {
                var cookieMatch = document.cookie.match(/(?:^|; )as_admin_theme=([^;]+)/);
                var cookieMode = cookieMatch ? decodeURIComponent(cookieMatch[1]) : '';
                var savedMode = cookieMode || window.localStorage.getItem('as-admin-dashboard-theme') || '';

                if (!savedMode && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
                    savedMode = 'dark';
                }

                if (savedMode === 'dark') {
                    document.documentElement.classList.add('as-admin-skin-dark-root');
                    document.documentElement.style.background = '#080d19';
                } else {
                    document.documentElement.classList.remove('as-admin-skin-dark-root');
                    document.documentElement.style.background = '#f3f6fc';
                }
            } catch (e) {}
        })();
    </script>
    <?php
}, 0);

add_filter('admin_footer_text', function () {
    return '<span class="as-admin-footer-brand">Designed &amp; powered by <strong>Love</strong></span>';
}, 999);

add_filter('update_footer', function () {
    return '<span class="as-admin-footer-version">ALFASMART Control Center</span>';
}, 999);

/* --------------------------------------------------------------------------
 * Dashboard traffic analytics
 * -------------------------------------------------------------------------- */

function alfasmart_admin_is_arabic()
{
    if (function_exists('pll_current_language') && 'ar' === pll_current_language('slug')) {
        return true;
    }

    return is_rtl() || 0 === strpos((string) get_locale(), 'ar');
}

function alfasmart_admin_logo_url()
{
    $logo = '';

    if (function_exists('alfasmart_get_option_image_url')) {
        $logo = alfasmart_get_option_image_url('footer_logo', 'logo-footer.webp');

        if (! $logo) {
            $logo = alfasmart_get_option_image_url('site_logo', 'logo.webp');
        }
    }

    if (! $logo && defined('ALFASMART_URI')) {
        $logo = ALFASMART_URI . '/assets/images/logo.webp';
    }

    return $logo;
}

function alfasmart_analytics_option_key()
{
    return 'alfasmart_visit_analytics_v2';
}

function alfasmart_analytics_live_option_key()
{
    return 'alfasmart_live_visitors_v2';
}

function alfasmart_analytics_empty_day()
{
    return array(
        'views'         => 0,
        'unique'        => 0,
        'user_views'    => 0,
        'guest_views'   => 0,
        'mobile_views'  => 0,
        'desktop_views' => 0,
        'hours'         => array_fill(0, 24, 0),
    );
}

function alfasmart_analytics_default_stats()
{
    return array(
        'total_views'      => 0,
        'total_unique'     => 0,
        'total_user_views' => 0,
        'total_guest_views'=> 0,
        'started_at'       => current_time('mysql'),
        'days'             => array(),
    );
}

function alfasmart_analytics_get_stats()
{
    $stats = get_option(alfasmart_analytics_option_key(), array());

    if (! is_array($stats)) {
        $stats = array();
    }

    $stats = wp_parse_args($stats, alfasmart_analytics_default_stats());

    if (! isset($stats['days']) || ! is_array($stats['days'])) {
        $stats['days'] = array();
    }

    return $stats;
}

function alfasmart_analytics_is_bot_request()
{
    $ua = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower((string) wp_unslash($_SERVER['HTTP_USER_AGENT'])) : '';

    if ('' === $ua) {
        return false;
    }

    return (bool) preg_match('/bot|crawl|spider|slurp|bingpreview|facebookexternalhit|whatsapp|telegrambot|preview|monitoring|uptime|semrush|ahrefs|mj12/i', $ua);
}

function alfasmart_analytics_should_skip()
{
    if (wp_doing_ajax() || wp_doing_cron()) {
        return true;
    }

    if (defined('REST_REQUEST') && REST_REQUEST) {
        return true;
    }

    if (alfasmart_analytics_is_bot_request()) {
        return true;
    }

    return false;
}

function alfasmart_analytics_visitor_id()
{
    $cookie_name = 'as_visit_sid';
    $sid         = isset($_COOKIE[$cookie_name]) ? sanitize_text_field(wp_unslash($_COOKIE[$cookie_name])) : '';

    if (! $sid || ! preg_match('/^[a-f0-9]{32}$/', $sid)) {
        $sid = function_exists('wp_generate_uuid4') ? md5(wp_generate_uuid4() . microtime(true)) : md5(uniqid('as', true));

        if (! headers_sent()) {
            $secure = is_ssl();
            $path   = defined('COOKIEPATH') && COOKIEPATH ? COOKIEPATH : '/';
            $domain = defined('COOKIE_DOMAIN') ? COOKIE_DOMAIN : '';

            setcookie($cookie_name, $sid, time() + YEAR_IN_SECONDS, $path, $domain, $secure, true);
            $_COOKIE[$cookie_name] = $sid;
        }
    }

    if (is_user_logged_in()) {
        return 'user_' . get_current_user_id() . '_' . $sid;
    }

    return 'guest_' . $sid;
}

function alfasmart_analytics_current_role_key()
{
    if (is_user_logged_in()) {
        return 'user';
    }

    return 'guest';
}

function alfasmart_analytics_prune_days($days, $limit = 120)
{
    if (! is_array($days) || count($days) <= $limit) {
        return is_array($days) ? $days : array();
    }

    ksort($days);

    return array_slice($days, -1 * absint($limit), null, true);
}

function alfasmart_analytics_track_live_visitor($visitor_id, $role, $context)
{
    $live = get_option(alfasmart_analytics_live_option_key(), array());

    if (! is_array($live)) {
        $live = array();
    }

    $now = time();

    foreach ($live as $key => $visitor) {
        $last = isset($visitor['last']) ? (int) $visitor['last'] : 0;

        if ($last < ($now - 15 * MINUTE_IN_SECONDS)) {
            unset($live[$key]);
        }
    }

    $live[md5($visitor_id)] = array(
        'last'    => $now,
        'role'    => $role,
        'context' => $context,
    );

    if (count($live) > 350) {
        uasort(
            $live,
            function ($a, $b) {
                return ((int) ($b['last'] ?? 0)) <=> ((int) ($a['last'] ?? 0));
            }
        );
        $live = array_slice($live, 0, 350, true);
    }

    update_option(alfasmart_analytics_live_option_key(), $live, false);
}

function alfasmart_analytics_record_visit($context = 'frontend')
{
    if (alfasmart_analytics_should_skip()) {
        return;
    }

    // Track public/front-end traffic only. Admin dashboard opens and admin visits are intentionally excluded.
    if (is_admin() || 'frontend' !== $context) {
        return;
    }

    // Do not count administrators as visitors, even when they open the public website while logged in.
    if (is_user_logged_in() && current_user_can('manage_options')) {
        return;
    }

    $today      = current_time('Y-m-d');
    $hour       = (int) current_time('G');
    $visitor_id = alfasmart_analytics_visitor_id();
    $role       = alfasmart_analytics_current_role_key();
    $stats      = alfasmart_analytics_get_stats();

    if (! isset($stats['days'][$today]) || ! is_array($stats['days'][$today])) {
        $stats['days'][$today] = alfasmart_analytics_empty_day();
    } else {
        $stats['days'][$today] = wp_parse_args($stats['days'][$today], alfasmart_analytics_empty_day());
    }

    $unique_key = 'as_unique_' . md5($visitor_id . '_' . $today);
    $is_unique  = ! get_transient($unique_key);

    $stats['days'][$today]['views']++;
    $stats['days'][$today]['hours'][$hour] = (int) ($stats['days'][$today]['hours'][$hour] ?? 0) + 1;
    $stats['total_views']++;

    if ($is_unique) {
        $stats['days'][$today]['unique']++;
        $stats['total_unique']++;
        set_transient($unique_key, 1, DAY_IN_SECONDS + HOUR_IN_SECONDS);
    }

    if ('user' === $role) {
        $stats['days'][$today]['user_views']++;
        $stats['total_user_views']++;
    } else {
        $stats['days'][$today]['guest_views']++;
        $stats['total_guest_views']++;
    }

    if (wp_is_mobile()) {
        $stats['days'][$today]['mobile_views']++;
    } else {
        $stats['days'][$today]['desktop_views']++;
    }

    alfasmart_analytics_track_live_visitor($visitor_id, $role, 'frontend');

    $stats['days'] = alfasmart_analytics_prune_days($stats['days']);
    update_option(alfasmart_analytics_option_key(), $stats, false);
}

add_action('template_redirect', function () {
    alfasmart_analytics_record_visit('frontend');
}, 1);

function alfasmart_analytics_day_labels($is_ar, $days = 14)
{
    $labels = array();
    $keys   = array();
    $stamp  = current_time('timestamp');

    for ($i = $days - 1; $i >= 0; $i--) {
        $current = strtotime('-' . $i . ' days', $stamp);
        $keys[]  = date('Y-m-d', $current);

        if ($is_ar) {
            $labels[] = date_i18n('j M', $current);
        } else {
            $labels[] = date('M j', $current);
        }
    }

    return array(
        'labels' => $labels,
        'keys'   => $keys,
    );
}

function alfasmart_analytics_live_counts()
{
    $live = get_option(alfasmart_analytics_live_option_key(), array());

    if (! is_array($live)) {
        $live = array();
    }

    $now    = time();
    $counts = array(
        // Active website visitors within the last 5 minutes.
        'total'        => 0,
        'user'         => 0,
        'guest'        => 0,

        // Direct/live-now website visitors: active within the last 60 seconds.
        'direct_total' => 0,
        'direct_user'  => 0,
        'direct_guest' => 0,
    );

    foreach ($live as $visitor) {
        $last = isset($visitor['last']) ? (int) $visitor['last'] : 0;

        if ($last < ($now - 5 * MINUTE_IN_SECONDS)) {
            continue;
        }

        $role    = isset($visitor['role']) ? (string) $visitor['role'] : 'guest';
        $context = isset($visitor['context']) ? (string) $visitor['context'] : 'frontend';

        if ('frontend' !== $context) {
            continue;
        }

        if (! in_array($role, array('guest', 'user'), true)) {
            $role = 'guest';
        }

        $counts['total']++;
        $counts[$role]++;

        if ($last >= ($now - MINUTE_IN_SECONDS)) {
            $counts['direct_total']++;
            $counts['direct_' . $role]++;
        }
    }

    return $counts;
}

function alfasmart_analytics_percent_change($today, $yesterday)
{
    $today     = (int) $today;
    $yesterday = (int) $yesterday;

    if ($yesterday <= 0 && $today > 0) {
        return 100;
    }

    if ($yesterday <= 0) {
        return 0;
    }

    return (int) round((($today - $yesterday) / $yesterday) * 100);
}

function alfasmart_admin_dashboard_payload()
{
    $is_ar = alfasmart_admin_is_arabic();
    $stats = alfasmart_analytics_get_stats();
    $range = alfasmart_analytics_day_labels($is_ar, 14);
    $today_key     = current_time('Y-m-d');
    $yesterday_key = date('Y-m-d', strtotime('-1 day', current_time('timestamp')));
    $today         = wp_parse_args($stats['days'][$today_key] ?? array(), alfasmart_analytics_empty_day());
    $yesterday     = wp_parse_args($stats['days'][$yesterday_key] ?? array(), alfasmart_analytics_empty_day());
    $live          = alfasmart_analytics_live_counts();

    $visits_series = array();
    $unique_series = array();

    foreach ($range['keys'] as $key) {
        $day = wp_parse_args($stats['days'][$key] ?? array(), alfasmart_analytics_empty_day());
        $visits_series[] = (int) $day['views'];
        $unique_series[] = (int) $day['unique'];
    }

    $hours       = array_values(array_map('intval', $today['hours']));
    $hour_labels = array();

    for ($i = 0; $i < 24; $i++) {
        $hour_labels[] = sprintf('%02d:00', $i);
    }

    $online_total  = max(0, (int) $live['total']);
    $direct_total  = max(0, (int) $live['direct_total']);
    $standby_total = max(0, $online_total - $direct_total);

    return array(
        'locale' => $is_ar ? 'ar' : 'en',
        'rtl'    => $is_ar,
        'colors' => array(
            'primary' => '#4862ff',
            'deep'    => '#3248df',
            'cyan'    => '#23c7ff',
            'gold'    => '#ffb84d',
            'violet'  => '#7c5cff',
            'green'   => '#21c986',
            'dark'    => '#101626',
        ),
        'days' => $range['labels'],
        'hours' => $hour_labels,
        'traffic' => array(
            'series' => array(
                array(
                    'name' => $is_ar ? 'زيارات الموقع' : 'Website visits',
                    'data' => $visits_series,
                ),
                array(
                    'name' => $is_ar ? 'زوار فريدون' : 'Unique visitors',
                    'data' => $unique_series,
                ),
            ),
        ),
        'todayHours' => array(
            'series' => array(
                array(
                    'name' => $is_ar ? 'زيارات اليوم' : 'Today visits',
                    'data' => $hours,
                ),
            ),
        ),
        'visitorSplit' => array(
            'labels' => $is_ar ? array('زوار غير مسجلين', 'أعضاء مسجلين') : array('Guests', 'Logged-in users'),
            'series' => array((int) $today['guest_views'], (int) $today['user_views']),
        ),
        'liveStatus' => array(
            'labels' => $is_ar ? array('زائر مباشر الآن', 'أونلاين آخر 5 دقائق') : array('Direct now', 'Online last 5 min'),
            'series' => array($direct_total, $standby_total),
        ),
        'device' => array(
            'labels' => $is_ar ? array('موبايل', 'ديسكتوب') : array('Mobile', 'Desktop'),
            'series' => array((int) $today['mobile_views'], (int) $today['desktop_views']),
        ),
        'summary' => array(
            'today'             => (int) $today['views'],
            'yesterday'         => (int) $yesterday['views'],
            'todayUnique'       => (int) $today['unique'],
            'liveNow'           => $online_total,
            'liveDirectNow'     => $direct_total,
            'liveDirectGuests'  => (int) $live['direct_guest'],
            'liveDirectUsers'   => (int) $live['direct_user'],
            'guestToday'        => (int) $today['guest_views'],
            'userToday'         => (int) $today['user_views'],
            'totalViews'        => (int) $stats['total_views'],
            'totalUnique'       => (int) $stats['total_unique'],
            'change'            => alfasmart_analytics_percent_change($today['views'], $yesterday['views']),
            'trackingStartedAt' => $stats['started_at'],
        ),
        'text' => array(
            'total'         => $is_ar ? 'الإجمالي' : 'Total',
            'visits'        => $is_ar ? 'زيارة' : 'Visits',
            'empty'         => $is_ar ? 'لا توجد بيانات كافية بعد' : 'Not enough data yet',
            'light'         => $is_ar ? 'لايت' : 'Light',
            'dark'          => $is_ar ? 'دارك' : 'Dark',
            'themeLight'    => $is_ar ? 'تفعيل الوضع الفاتح' : 'Switch to light mode',
            'themeDark'     => $is_ar ? 'تفعيل الوضع الداكن' : 'Switch to dark mode',
            'autoRefresh'   => $is_ar ? 'تحديث تلقائي كل 30 ثانية' : 'Auto refresh every 30 seconds',
            'lastMinute'    => $is_ar ? 'آخر 60 ثانية' : 'Last 60 seconds',
        ),
    );
}

function alfasmart_admin_dashboard_kpis()
{
    $is_ar = alfasmart_admin_is_arabic();
    $payload = alfasmart_admin_dashboard_payload();
    $summary = $payload['summary'];
    $change  = (int) $summary['change'];
    $change_label = ($change > 0 ? '+' : '') . $change . '%';

    return array(
        array(
            'key'   => 'liveDirectNow',
            'value' => $summary['liveDirectNow'],
            'label' => $is_ar ? 'زائر مباشر الآن' : 'Direct visitor now',
            'hint'  => $is_ar ? 'نشط على الموقع خلال آخر 60 ثانية' : 'Active on the website during the last 60 seconds',
            'icon'  => 'dashicons-controls-play',
            'tone'  => 'red',
        ),
        array(
            'key'   => 'today',
            'value' => $summary['today'],
            'label' => $is_ar ? 'زيارات الموقع اليوم' : 'Website visits today',
            'hint'  => $is_ar ? 'مقارنة بأمس: ' . $change_label : 'Vs yesterday: ' . $change_label,
            'icon'  => 'dashicons-visibility',
            'tone'  => 'blue',
        ),
        array(
            'key'   => 'liveNow',
            'value' => $summary['liveNow'],
            'label' => $is_ar ? 'أونلاين آخر 5 دقائق' : 'Online last 5 minutes',
            'hint'  => $is_ar ? 'زوار فعليين على الموقع فقط' : 'Real website visitors only',
            'icon'  => 'dashicons-rss',
            'tone'  => 'cyan',
        ),
        array(
            'key'   => 'todayUnique',
            'value' => $summary['todayUnique'],
            'label' => $is_ar ? 'زوار فريدون اليوم' : 'Unique visitors today',
            'hint'  => $is_ar ? 'كل زائر يتم حسابه مرة يوميًا' : 'Each visitor counted once per day',
            'icon'  => 'dashicons-id',
            'tone'  => 'violet',
        ),
        array(
            'key'   => 'guestToday',
            'value' => $summary['guestToday'],
            'label' => $is_ar ? 'زوار غير مسجلين' : 'Guest visits today',
            'hint'  => $is_ar ? 'زيارات من خارج حسابات ووردبريس' : 'Visits outside WordPress accounts',
            'icon'  => 'dashicons-groups',
            'tone'  => 'gold',
        ),
        array(
            'key'   => 'totalViews',
            'value' => $summary['totalViews'],
            'label' => $is_ar ? 'إجمالي الزيارات' : 'Total tracked visits',
            'hint'  => $is_ar ? 'يبدأ العد من وقت تركيب الملف' : 'Tracking starts after installing this file',
            'icon'  => 'dashicons-chart-area',
            'tone'  => 'blue',
        ),
    );
}

function alfasmart_render_dashboard_widget()
{
    $is_ar   = alfasmart_admin_is_arabic();
    $logo    = alfasmart_admin_logo_url();
    $kpis    = alfasmart_admin_dashboard_kpis();
    $payload = alfasmart_admin_dashboard_payload();
    $summary = $payload['summary'];
    ?>
    <div class="as-admin-dashboard" data-as-admin-dashboard dir="<?php echo esc_attr($is_ar ? 'rtl' : 'ltr'); ?>">
        <div class="as-admin-hero">
            <div class="as-admin-hero-content">
                <?php if ($logo) : ?>
                    <span class="as-admin-logo-wrap">
                        <img src="<?php echo esc_url($logo); ?>" alt="<?php echo esc_attr(get_bloginfo('name')); ?>">
                    </span>
                <?php endif; ?>

                <span class="as-admin-eyebrow">
                    <?php echo esc_html($is_ar ? 'لوحة زوار ALFASMART المباشرة' : 'ALFASMART Live Visitor Center'); ?>
                </span>
                <h2><?php echo esc_html($is_ar ? 'متابعة الزائر المباشر وزيارات الموقع بدون إحصائيات الأدمن' : 'Live visitor and website traffic without admin statistics'); ?></h2>
                <p><?php echo esc_html($is_ar ? 'البيانات هنا للزوار الحقيقيين على الموقع فقط: زائر مباشر الآن، أونلاين آخر 5 دقائق، زيارات اليوم، والزوار الفريدون. تم حذف جزء زيارات الأدمن بالكامل من الواجهة.' : 'This dashboard tracks real website visitors only: direct visitors now, online users in the last 5 minutes, today visits, and unique visitors. Admin visit sections have been removed.'); ?></p>

                <div class="as-admin-mini-strip">
                    <span><?php echo esc_html($is_ar ? 'زائر مباشر' : 'Direct now'); ?> <b data-as-summary-value="liveDirectNow"><?php echo esc_html(number_format_i18n((int) $summary['liveDirectNow'])); ?></b></span>
                    <span><?php echo esc_html($is_ar ? 'زوار فريدون اليوم' : 'Unique today'); ?> <b data-as-summary-value="todayUnique"><?php echo esc_html(number_format_i18n((int) $summary['todayUnique'])); ?></b></span>
                    <span><?php echo esc_html($is_ar ? 'أمس' : 'Yesterday'); ?> <b data-as-summary-value="yesterday"><?php echo esc_html(number_format_i18n((int) $summary['yesterday'])); ?></b></span>
                    <span><?php echo esc_html($is_ar ? 'إجمالي زوار فريدون' : 'Total unique'); ?> <b data-as-summary-value="totalUnique"><?php echo esc_html(number_format_i18n((int) $summary['totalUnique'])); ?></b></span>
                </div>
            </div>

            <div class="as-admin-hero-actions">
                <button type="button" class="as-admin-theme-toggle" data-as-dashboard-theme-toggle aria-label="<?php echo esc_attr($is_ar ? 'تبديل الوضع' : 'Toggle mode'); ?>">
                    <span class="dashicons dashicons-lightbulb"></span>
                    <b data-as-theme-label><?php echo esc_html($is_ar ? 'دارك' : 'Dark'); ?></b>
                </button>
                <a class="as-admin-button" href="<?php echo esc_url(home_url('/')); ?>" target="_blank" rel="noopener">
                    <?php echo esc_html($is_ar ? 'زيارة الموقع' : 'Visit website'); ?>
                    <span class="dashicons dashicons-external"></span>
                </a>
            </div>
        </div>

        <div class="as-admin-kpi-grid">
            <?php foreach ($kpis as $kpi) : ?>
                <article class="as-admin-kpi-card as-tone-<?php echo esc_attr($kpi['tone']); ?>">
                    <span class="as-admin-kpi-icon dashicons <?php echo esc_attr($kpi['icon']); ?>"></span>
                    <strong data-as-kpi-value="<?php echo esc_attr($kpi['key']); ?>"><?php echo esc_html(number_format_i18n((int) $kpi['value'])); ?></strong>
                    <span><?php echo esc_html($kpi['label']); ?></span>
                    <small><?php echo esc_html($kpi['hint']); ?></small>
                </article>
            <?php endforeach; ?>
        </div>

        <div class="as-admin-charts-grid">
            <article class="as-admin-chart-card as-admin-chart-card-wide">
                <div class="as-admin-chart-head">
                    <div>
                        <span><?php echo esc_html($is_ar ? 'آخر 14 يوم' : 'Last 14 days'); ?></span>
                        <h3><?php echo esc_html($is_ar ? 'اتجاه زيارات الموقع والزوار الفريدين' : 'Website visits and unique visitors trend'); ?></h3>
                    </div>
                    <b class="as-admin-live-badge"><?php echo esc_html($is_ar ? 'مباشر' : 'Live'); ?></b>
                </div>
                <div id="as-admin-traffic-chart" class="as-admin-chart" aria-hidden="true"></div>
            </article>

            <article class="as-admin-chart-card">
                <div class="as-admin-chart-head">
                    <div>
                        <span><?php echo esc_html($is_ar ? 'اليوم بالساعة' : 'Today by hour'); ?></span>
                        <h3><?php echo esc_html($is_ar ? 'زيارات الموقع خلال اليوم' : 'Website visits during the day'); ?></h3>
                    </div>
                </div>
                <div id="as-admin-hours-chart" class="as-admin-chart as-admin-chart-compact" aria-hidden="true"></div>
            </article>

            <article class="as-admin-chart-card">
                <div class="as-admin-chart-head">
                    <div>
                        <span><?php echo esc_html($is_ar ? 'نوع الزائر' : 'Visitor type'); ?></span>
                        <h3><?php echo esc_html($is_ar ? 'زوار غير مسجلين مقابل أعضاء' : 'Guests vs logged-in users'); ?></h3>
                    </div>
                </div>
                <div id="as-admin-split-chart" class="as-admin-chart as-admin-chart-donut" aria-hidden="true"></div>
            </article>

            <article class="as-admin-chart-card">
                <div class="as-admin-chart-head">
                    <div>
                        <span><?php echo esc_html($is_ar ? 'الأجهزة' : 'Devices'); ?></span>
                        <h3><?php echo esc_html($is_ar ? 'موبايل مقابل ديسكتوب اليوم' : 'Mobile vs desktop today'); ?></h3>
                    </div>
                </div>
                <div id="as-admin-device-chart" class="as-admin-chart as-admin-chart-donut" aria-hidden="true"></div>
            </article>

            <article class="as-admin-chart-card">
                <div class="as-admin-chart-head">
                    <div>
                        <span><?php echo esc_html($is_ar ? 'مباشر الآن' : 'Live now'); ?></span>
                        <h3><?php echo esc_html($is_ar ? 'زائر مباشر مقابل أونلاين آخر 5 دقائق' : 'Direct visitor vs online last 5 minutes'); ?></h3>
                    </div>
                </div>
                <div id="as-admin-live-status-chart" class="as-admin-chart as-admin-chart-donut" aria-hidden="true"></div>
            </article>
        </div>

        <p class="as-admin-note">
            <?php echo esc_html($is_ar ? 'ملحوظة: الزائر المباشر يعني زائر نشط على الموقع خلال آخر 60 ثانية. يتم استبعاد الأدمن من العد حتى لو فتح الموقع وهو مسجل دخول.' : 'Note: a direct visitor is active on the website within the last 60 seconds. Administrators are excluded from tracking even when viewing the public website while logged in.'); ?>
            <span><?php echo esc_html($is_ar ? 'تحديث تلقائي كل 30 ثانية.' : 'Auto refresh every 30 seconds.'); ?></span>
        </p>
    </div>
    <?php
}

add_action('wp_dashboard_setup', function () {
    $core_widgets = array(
        'dashboard_activity',
        'dashboard_incoming_links',
        'dashboard_plugins',
        'dashboard_primary',
        'dashboard_quick_press',
        'dashboard_recent_comments',
        'dashboard_recent_drafts',
        'dashboard_right_now',
        'dashboard_secondary',
        'dashboard_site_health',
    );

    foreach ($core_widgets as $widget) {
        remove_meta_box($widget, 'dashboard', 'normal');
        remove_meta_box($widget, 'dashboard', 'side');
    }

    wp_add_dashboard_widget(
        'alfasmart_dashboard_widget',
        __('ALFASMART Dashboard', 'alfasmart'),
        'alfasmart_render_dashboard_widget',
        null,
        null,
        'normal',
        'high'
    );
}, 999);

add_filter('screen_layout_columns', function ($columns) {
    $screen = function_exists('get_current_screen') ? get_current_screen() : null;

    if ($screen && 'dashboard' === $screen->id) {
        $columns['dashboard'] = 1;
    }

    return $columns;
});

add_filter('get_user_option_screen_layout_dashboard', function () {
    return 1;
});

add_action('wp_ajax_alfasmart_admin_dashboard_payload', function () {
    if (! current_user_can('read')) {
        wp_send_json_error(array('message' => 'forbidden'), 403);
    }

    check_ajax_referer('alfasmart_admin_dashboard_payload', 'nonce');

    wp_send_json_success(alfasmart_admin_dashboard_payload());
});

function alfasmart_admin_dashboard_inline_css()
{
    return <<<'CSS'
/* ALFASMART full WordPress admin skin + live visitor dashboard */
:root {
  --as-wp-accent: #4862ff;
  --as-wp-accent-2: #23c7ff;
  --as-wp-accent-dark: #3248df;
  --as-wp-bg: #f3f6fc;
  --as-wp-panel: rgba(255,255,255,0.92);
  --as-wp-panel-solid: #ffffff;
  --as-wp-ink: #101626;
  --as-wp-muted: rgba(16,22,38,.64);
  --as-wp-line: rgba(72,98,255,.14);
  --as-wp-shadow: 0 20px 60px rgba(11,23,57,.10);
  --as-wp-menu: #0d1425;
  --as-wp-menu-2: #151d31;
}

body.wp-admin {
  background:
    radial-gradient(circle at 8% 6%, rgba(72,98,255,.08), transparent 32%),
    radial-gradient(circle at 92% 28%, rgba(35,199,255,.07), transparent 30%),
    var(--as-wp-bg);
  color: var(--as-wp-ink);
  font-family: Inter, Arial, sans-serif;
}

.rtl body.wp-admin,
body.wp-admin.rtl {
  font-family: Cairo, Tahoma, Arial, sans-serif;
}

body.wp-admin.as-admin-skin-dark-page {
  --as-wp-bg: #080d19;
  --as-wp-panel: rgba(17,24,43,.9);
  --as-wp-panel-solid: #11182b;
  --as-wp-ink: #f7f9ff;
  --as-wp-muted: rgba(231,237,255,.68);
  --as-wp-line: rgba(147,166,255,.16);
  --as-wp-shadow: 0 24px 70px rgba(0,0,0,.30);
  --as-wp-menu: #070b16;
  --as-wp-menu-2: #10182b;
  background:
    radial-gradient(circle at 8% 6%, rgba(72,98,255,.22), transparent 34%),
    radial-gradient(circle at 92% 28%, rgba(35,199,255,.12), transparent 30%),
    var(--as-wp-bg);
  color: var(--as-wp-ink);
}

body.wp-admin #wpcontent,
body.wp-admin #wpfooter {
  color: var(--as-wp-ink);
}

body.wp-admin #wpcontent {
  padding-top: 14px;
}

body.wp-admin .wrap h1,
body.wp-admin .wrap h2,
body.wp-admin .wrap h3,
body.wp-admin .form-table th,
body.wp-admin .metabox-holder h2.hndle,
body.wp-admin .postbox .hndle,
body.wp-admin .postbox-header h2,
body.wp-admin .nav-tab,
body.wp-admin .subsubsub a,
body.wp-admin label {
  color: var(--as-wp-ink);
}

body.wp-admin p,
body.wp-admin .description,
body.wp-admin .howto,
body.wp-admin .form-wrap p,
body.wp-admin .tablenav,
body.wp-admin .subsubsub,
body.wp-admin #wpfooter {
  color: var(--as-wp-muted);
}

#wpadminbar,
#adminmenu,
#adminmenuback,
#adminmenuwrap {
  background: var(--as-wp-menu) !important;
}

#wpadminbar {
  box-shadow: 0 14px 36px rgba(3, 7, 18, .18);
}

#wpadminbar .ab-top-menu > li.hover > .ab-item,
#wpadminbar.nojq .quicklinks .ab-top-menu > li > .ab-item:focus,
#wpadminbar:not(.mobile) .ab-top-menu > li:hover > .ab-item,
#wpadminbar:not(.mobile) .ab-top-menu > li > .ab-item:focus,
#wpadminbar .menupop .ab-sub-wrapper {
  background: var(--as-wp-menu-2) !important;
}

#wpadminbar #wp-admin-bar-as-admin-theme-toggle > .ab-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(72, 98, 255, .20);
  color: #fff;
}

#wpadminbar #wp-admin-bar-as-admin-theme-toggle .dashicons {
  width: 16px;
  height: 16px;
  font-size: 16px;
  line-height: 20px;
}

#adminmenu div.wp-menu-image:before,
#adminmenu a,
#adminmenu .wp-submenu a,
#wpadminbar a.ab-item,
#wpadminbar > #wp-toolbar span.ab-label,
#wpadminbar > #wp-toolbar span.noticon {
  color: rgba(255,255,255,.76) !important;
}

#adminmenu li.menu-top:hover,
#adminmenu li.opensub > a.menu-top,
#adminmenu li > a.menu-top:focus,
#adminmenu .wp-has-current-submenu .wp-submenu,
#adminmenu .wp-submenu,
#adminmenu li.current a.menu-top,
#adminmenu li.wp-has-current-submenu a.wp-has-current-submenu {
  background: var(--as-wp-menu-2) !important;
}

#adminmenu li.current a.menu-top,
#adminmenu li.wp-has-current-submenu a.wp-has-current-submenu,
#adminmenu li.menu-top:hover > a,
#adminmenu li.opensub > a.menu-top {
  color: #fff !important;
}

#adminmenu li.current a.menu-top::after,
#adminmenu li.wp-has-current-submenu a.wp-has-current-submenu::after {
  border-right-color: var(--as-wp-bg) !important;
}

#adminmenu li.wp-has-current-submenu a.wp-has-current-submenu,
#adminmenu li.current a.menu-top {
  box-shadow: inset 4px 0 0 var(--as-wp-accent);
}

.rtl #adminmenu li.wp-has-current-submenu a.wp-has-current-submenu,
.rtl #adminmenu li.current a.menu-top {
  box-shadow: inset -4px 0 0 var(--as-wp-accent);
}

body.wp-admin .postbox,
body.wp-admin .stuffbox,
body.wp-admin .welcome-panel,
body.wp-admin .card,
body.wp-admin .health-check-accordion,
body.wp-admin .plugins .active th,
body.wp-admin .plugins .active td,
body.wp-admin table.widefat,
body.wp-admin .wp-list-table,
body.wp-admin .acf-postbox,
body.wp-admin .acf-field,
body.wp-admin .notice,
body.wp-admin div.updated,
body.wp-admin div.error {
  border-color: var(--as-wp-line);
  border-radius: 18px;
  background: var(--as-wp-panel);
  box-shadow: var(--as-wp-shadow);
}

body.wp-admin .postbox-header,
body.wp-admin .handlediv,
body.wp-admin .hndle,
body.wp-admin table.widefat thead th,
body.wp-admin table.widefat tfoot th {
  border-color: var(--as-wp-line) !important;
}

body.wp-admin.as-admin-skin-dark-page input,
body.wp-admin.as-admin-skin-dark-page textarea,
body.wp-admin.as-admin-skin-dark-page select,
body.wp-admin.as-admin-skin-dark-page .select2-container--default .select2-selection--single,
body.wp-admin.as-admin-skin-dark-page .select2-container--default .select2-selection--multiple {
  background: #0d1425 !important;
  border-color: rgba(147,166,255,.20) !important;
  color: #f7f9ff !important;
}

body.wp-admin.as-admin-skin-dark-page table.widefat,
body.wp-admin.as-admin-skin-dark-page table.widefat td,
body.wp-admin.as-admin-skin-dark-page table.widefat th,
body.wp-admin.as-admin-skin-dark-page .postbox-header,
body.wp-admin.as-admin-skin-dark-page .postbox .inside,
body.wp-admin.as-admin-skin-dark-page .misc-pub-section {
  color: var(--as-wp-ink);
  border-color: var(--as-wp-line) !important;
}

body.wp-admin.as-admin-skin-dark-page table.widefat tbody tr:hover {
  background: rgba(72,98,255,.08);
}

.wp-core-ui .button-primary,
.wp-core-ui .button-primary:hover,
.wp-core-ui .button-primary:focus {
  background: linear-gradient(135deg, var(--as-wp-accent), var(--as-wp-accent-dark));
  border-color: var(--as-wp-accent);
  color: #fff;
  border-radius: 999px;
  box-shadow: 0 12px 28px rgba(72,98,255,.24);
}

.wp-core-ui .button,
.wp-core-ui .button-secondary {
  border-radius: 999px;
  border-color: var(--as-wp-line);
}

body.wp-admin .nav-tab-wrapper,
body.wp-admin .wp-filter {
  border-color: var(--as-wp-line);
}

body.wp-admin .nav-tab-active,
body.wp-admin .nav-tab-active:focus,
body.wp-admin .nav-tab-active:hover {
  border-color: var(--as-wp-accent);
  background: rgba(72,98,255,.10);
  color: var(--as-wp-accent);
}

.acf-field .acf-label label {
  font-weight: 800;
}

/* Dashboard layout */
body.index-php #wpbody-content { padding-bottom: 52px; }
body.index-php #dashboard-widgets-wrap,
body.index-php #dashboard-widgets,
body.index-php #dashboard-widgets .postbox-container,
body.index-php #dashboard-widgets #postbox-container-1,
body.index-php #dashboard-widgets #normal-sortables {
  width: 100% !important;
  max-width: none;
}
body.index-php #dashboard-widgets .postbox-container { float: none; }
body.index-php #dashboard-widgets .meta-box-sortables { min-height: 0; }
body.index-php #alfasmart_dashboard_widget { border: 0; background: transparent; box-shadow: none; }
body.index-php #alfasmart_dashboard_widget .postbox-header,
body.index-php #alfasmart_dashboard_widget .handlediv,
body.index-php #alfasmart_dashboard_widget .hndle { display: none; }
body.index-php #alfasmart_dashboard_widget .inside { margin: 0; padding: 0; }

.as-admin-dashboard,
.as-admin-dashboard * { box-sizing: border-box; }
.as-admin-dashboard {
  --as-admin-brand: #4862ff;
  --as-admin-brand-dark: #3248df;
  --as-admin-cyan: #23c7ff;
  --as-admin-gold: #ffb84d;
  --as-admin-violet: #7c5cff;
  --as-admin-green: #21c986;
  --as-admin-ink: var(--as-wp-ink);
  --as-admin-muted: var(--as-wp-muted);
  --as-admin-card: var(--as-wp-panel);
  --as-admin-line: var(--as-wp-line);
  --as-admin-shadow: var(--as-wp-shadow);
  max-width: 1480px;
  margin: 16px 20px 0 0;
  color: var(--as-admin-ink);
  font-family: Inter, Arial, sans-serif;
}
.rtl .as-admin-dashboard,
.as-admin-dashboard[dir="rtl"] { margin: 16px 0 0 20px; font-family: Cairo, Tahoma, Arial, sans-serif; }
.as-admin-hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 190px;
  gap: 30px;
  align-items: center;
  min-height: 270px;
  padding: clamp(28px, 4vw, 50px);
  border: 1px solid rgba(255,255,255,.72);
  border-radius: 34px;
  background:
    linear-gradient(135deg, rgba(13,18,34,.96), rgba(16,25,50,.94)),
    radial-gradient(circle at 15% 10%, rgba(72,98,255,.42), transparent 34%);
  box-shadow: 0 34px 110px rgba(7,12,28,.22);
  overflow: hidden;
  isolation: isolate;
}
.as-admin-hero:before,
.as-admin-hero:after { content:""; position:absolute; z-index:-1; border-radius:999px; pointer-events:none; }
.as-admin-hero:before { inset:-160px -120px auto auto; width:440px; aspect-ratio:1; background:radial-gradient(circle, rgba(72,98,255,.54), transparent 66%); }
.as-admin-hero:after { inset:auto auto -190px -100px; width:470px; aspect-ratio:1; background:radial-gradient(circle, rgba(35,199,255,.23), transparent 68%); }
.as-admin-logo-wrap { display:inline-flex; align-items:center; justify-content:center; width:min(246px,70vw); min-height:64px; margin-bottom:20px; padding:12px 16px; border:1px solid rgba(255,255,255,.14); border-radius:21px; background:rgba(255,255,255,.07); backdrop-filter:blur(18px); }
.as-admin-logo-wrap img { display:block; max-width:100%; max-height:54px; object-fit:contain; }
.as-admin-eyebrow { display:inline-flex; align-items:center; gap:9px; margin-bottom:13px; color:#9fb0ff; font-size:12px; font-weight:900; letter-spacing:.12em; text-transform:uppercase; }
.as-admin-dashboard[dir="rtl"] .as-admin-eyebrow { letter-spacing:0; }
.as-admin-eyebrow:before { content:""; display:inline-block; width:9px; height:9px; border-radius:999px; background:var(--as-admin-green); box-shadow:0 0 0 7px rgba(33,201,134,.16); }
.as-admin-hero h2 { max-width:850px; margin:0; color:#fff; font-size:clamp(28px,4vw,50px); line-height:1.12; font-weight:1000; letter-spacing:-.045em; }
.as-admin-dashboard[dir="rtl"] .as-admin-hero h2 { letter-spacing:-.015em; }
.as-admin-hero p { max-width:850px; margin:17px 0 0; color:rgba(245,247,255,.76); font-size:15px; line-height:1.95; }
.as-admin-mini-strip { display:flex; flex-wrap:wrap; gap:10px; margin-top:24px; }
.as-admin-mini-strip span { display:inline-flex; align-items:center; gap:8px; min-height:38px; padding:0 13px; border:1px solid rgba(255,255,255,.12); border-radius:999px; background:rgba(255,255,255,.08); color:rgba(255,255,255,.74); font-size:12px; font-weight:800; backdrop-filter:blur(14px); }
.as-admin-mini-strip b { color:#fff; font-size:14px; }
.as-admin-hero-actions { display:flex; flex-direction:column; gap:12px; align-self:end; min-width:180px; }
.as-admin-button,
.as-admin-theme-toggle { display:inline-flex; align-items:center; justify-content:center; gap:8px; min-height:47px; padding:0 18px; border:0; border-radius:999px; background:linear-gradient(135deg,var(--as-admin-brand),var(--as-admin-brand-dark)); color:#fff !important; text-decoration:none; font-weight:900; box-shadow:0 18px 36px rgba(72,98,255,.34); cursor:pointer; transition:transform .2s ease, box-shadow .2s ease; }
.as-admin-button:hover,
.as-admin-button:focus,
.as-admin-theme-toggle:hover,
.as-admin-theme-toggle:focus { transform:translateY(-2px); box-shadow:0 22px 44px rgba(72,98,255,.42); }
.as-admin-theme-toggle { border:1px solid rgba(255,255,255,.16); background:rgba(255,255,255,.08); box-shadow:none; backdrop-filter:blur(14px); }
.as-admin-kpi-grid { display:grid; grid-template-columns:repeat(6,minmax(0,1fr)); gap:16px; margin:18px 0; }
.as-admin-kpi-card { position:relative; min-height:178px; padding:23px 22px; border:1px solid var(--as-admin-line); border-radius:27px; background:var(--as-admin-card); box-shadow:var(--as-admin-shadow); overflow:hidden; backdrop-filter:blur(18px); }
.as-admin-kpi-card:before { content:""; position:absolute; inset:auto -42px -56px auto; width:138px; aspect-ratio:1; border-radius:999px; background:radial-gradient(circle, rgba(72,98,255,.18), transparent 70%); pointer-events:none; }
.as-tone-green:before { background:radial-gradient(circle, rgba(33,201,134,.18), transparent 70%); }
.as-tone-cyan:before { background:radial-gradient(circle, rgba(35,199,255,.18), transparent 70%); }
.as-tone-gold:before { background:radial-gradient(circle, rgba(255,184,77,.20), transparent 70%); }
.as-tone-violet:before { background:radial-gradient(circle, rgba(124,92,255,.18), transparent 70%); }
.as-admin-kpi-icon { display:inline-flex; align-items:center; justify-content:center; width:43px; height:43px; margin-bottom:15px; border-radius:15px; background:rgba(72,98,255,.11); color:var(--as-admin-brand); }
.as-tone-green .as-admin-kpi-icon { background:rgba(33,201,134,.12); color:var(--as-admin-green); }
.as-tone-cyan .as-admin-kpi-icon { background:rgba(35,199,255,.12); color:var(--as-admin-cyan); }
.as-tone-gold .as-admin-kpi-icon { background:rgba(255,184,77,.14); color:#e29a31; }
.as-tone-violet .as-admin-kpi-icon { background:rgba(124,92,255,.13); color:var(--as-admin-violet); }
.as-admin-kpi-icon.dashicons { font-size:22px; }
.as-admin-kpi-card strong { display:block; margin-bottom:8px; color:var(--as-admin-brand); font-size:clamp(29px,3vw,42px); line-height:.96; font-weight:1000; letter-spacing:-.045em; }
.as-tone-green strong { color:var(--as-admin-green); }
.as-tone-cyan strong { color:var(--as-admin-cyan); }
.as-tone-gold strong { color:#e29a31; }
.as-tone-violet strong { color:var(--as-admin-violet); }
.as-admin-kpi-card span:not(.dashicons) { display:block; margin-bottom:8px; color:var(--as-admin-ink); font-weight:1000; font-size:13px; }
.as-admin-kpi-card small { display:block; color:var(--as-admin-muted); font-size:12px; line-height:1.75; }
.as-admin-charts-grid { display:grid; grid-template-columns:minmax(0,1.28fr) minmax(340px,.72fr); gap:18px; }
.as-admin-chart-card { min-width:0; padding:clamp(19px,2.4vw,27px); border:1px solid var(--as-admin-line); border-radius:29px; background:var(--as-admin-card); box-shadow:var(--as-admin-shadow); overflow:hidden; backdrop-filter:blur(18px); }
.as-admin-chart-card-wide { grid-row:span 2; }
.as-admin-chart-head { display:flex; align-items:flex-start; justify-content:space-between; gap:16px; margin-bottom:20px; }
.as-admin-chart-head span { display:block; margin-bottom:7px; color:var(--as-admin-brand); font-size:12px; font-weight:1000; letter-spacing:.09em; text-transform:uppercase; }
.as-admin-dashboard[dir="rtl"] .as-admin-chart-head span { letter-spacing:0; }
.as-admin-chart-head h3 { margin:0; color:var(--as-admin-ink); font-size:clamp(18px,2vw,24px); line-height:1.28; font-weight:1000; }
.as-admin-chart-head b { display:inline-flex; align-items:center; min-height:34px; padding:0 13px; border-radius:999px; background:rgba(33,201,134,.12); color:var(--as-admin-green); font-weight:1000; }
.as-admin-chart { min-height:310px; }
.as-admin-chart-compact { min-height:275px; }
.as-admin-chart-donut { min-height:300px; }
.as-admin-chart .apexcharts-canvas,
.as-admin-chart .apexcharts-svg { max-width:100%; }
.as-admin-dashboard .apexcharts-menu { border:0 !important; border-radius:14px !important; box-shadow:0 20px 50px rgba(11,23,57,.14) !important; }
.as-admin-note { margin:18px 4px 0; color:var(--as-admin-muted); font-size:12px; line-height:1.75; }
@media (max-width:1380px){ .as-admin-kpi-grid{grid-template-columns:repeat(3,minmax(0,1fr));}.as-admin-charts-grid{grid-template-columns:1fr;}.as-admin-chart-card-wide{grid-row:auto;} }
@media (max-width:960px){ .as-admin-dashboard,.rtl .as-admin-dashboard,.as-admin-dashboard[dir="rtl"]{margin:12px 10px 0 0;}.as-admin-hero{grid-template-columns:1fr;min-height:auto;}.as-admin-hero-actions{align-self:stretch;flex-direction:row;flex-wrap:wrap;}.as-admin-button,.as-admin-theme-toggle{flex:1 1 170px;}.as-admin-kpi-grid{grid-template-columns:repeat(2,minmax(0,1fr));} }
@media (max-width:640px){ body.index-php #wpbody-content .wrap{margin-right:10px;}.as-admin-hero{padding:24px 20px;border-radius:26px;}.as-admin-hero h2{font-size:27px;}.as-admin-mini-strip{gap:8px;}.as-admin-mini-strip span{width:100%;justify-content:space-between;}.as-admin-kpi-grid{grid-template-columns:1fr;gap:12px;}.as-admin-kpi-card{min-height:auto;padding:18px;border-radius:22px;}.as-admin-chart-card{padding:18px 12px 10px;border-radius:22px;}.as-admin-chart-head{padding:0 4px;margin-bottom:14px;}.as-admin-chart{min-height:260px;} }

/* --------------------------------------------------------------------------
   ALFASMART v2: complete wp-admin polish, dark fixes, table readability
   -------------------------------------------------------------------------- */
html.as-admin-skin-dark-root,
html.as-admin-skin-dark-root body,
html.as-admin-skin-dark-root body.wp-admin {
  background: #080d19 !important;
}

body.wp-admin,
body.wp-admin * {
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

body.wp-admin #wpbody-content {
  min-height: calc(100vh - 70px);
}

body.wp-admin #wpcontent {
  background: transparent !important;
}

body.wp-admin a {
  color: #0b71d9;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  transition: color .18s ease, background .18s ease, border-color .18s ease, box-shadow .18s ease, transform .18s ease, opacity .18s ease;
}

body.wp-admin.as-admin-skin-dark-page a,
html.as-admin-skin-dark-root body.wp-admin a {
  color: #68a7ff;
}

body.wp-admin a:hover,
body.wp-admin a:focus {
  color: var(--as-wp-accent);
}

body.wp-admin.as-admin-skin-dark-page a:hover,
html.as-admin-skin-dark-root body.wp-admin a:hover,
body.wp-admin.as-admin-skin-dark-page a:focus,
html.as-admin-skin-dark-root body.wp-admin a:focus {
  color: #9fb8ff;
}

/* Professional sidebar */
#adminmenuback,
#adminmenuwrap {
  box-shadow: 18px 0 50px rgba(4, 8, 20, .22);
}

#adminmenu {
  padding: 10px 8px;
  box-sizing: border-box;
}

#adminmenu li.menu-top {
  margin: 4px 0;
}

#adminmenu li.menu-top > a,
#adminmenu .wp-submenu a {
  border-radius: 13px;
  transition: transform .18s ease, background .18s ease, color .18s ease, box-shadow .18s ease;
}

#adminmenu li.menu-top > a {
  min-height: 36px;
}

#adminmenu li.menu-top:hover > a,
#adminmenu li.opensub > a.menu-top,
#adminmenu li > a.menu-top:focus {
  transform: translateX(3px);
  background: linear-gradient(135deg, rgba(72,98,255,.95), rgba(35,199,255,.70)) !important;
  box-shadow: 0 14px 28px rgba(72,98,255,.24);
}

.rtl #adminmenu li.menu-top:hover > a,
.rtl #adminmenu li.opensub > a.menu-top,
.rtl #adminmenu li > a.menu-top:focus {
  transform: translateX(-3px);
}

#adminmenu li.wp-has-current-submenu > a.wp-has-current-submenu,
#adminmenu li.current > a.menu-top {
  background: linear-gradient(135deg, rgba(72,98,255,.98), rgba(50,72,223,.98)) !important;
  border-radius: 14px;
  box-shadow: 0 18px 42px rgba(72,98,255,.32);
}

#adminmenu .wp-submenu {
  margin: 7px 0 9px !important;
  padding: 8px !important;
  border-radius: 18px;
  background: rgba(12,18,34,.96) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 18px 50px rgba(0,0,0,.24);
}

#adminmenu .wp-submenu a:hover,
#adminmenu .wp-submenu a:focus,
#adminmenu .wp-submenu li.current a {
  color: #fff !important;
  background: rgba(72,98,255,.26) !important;
}

/* Admin bar */
#wpadminbar {
  backdrop-filter: blur(18px);
}

#wpadminbar .ab-item,
#wpadminbar a.ab-item {
  transition: background .18s ease, color .18s ease, transform .18s ease;
}

#wpadminbar .ab-top-menu > li:hover > .ab-item {
  transform: translateY(1px);
}

#wpadminbar .menupop .ab-sub-wrapper {
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 0 0 18px 18px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0,0,0,.28);
}

/* Buttons, filters, page actions */
.wp-core-ui .button,
.wp-core-ui .button-secondary,
.wp-core-ui .page-title-action,
.wp-core-ui .button-primary {
  min-height: 34px;
  border-radius: 999px !important;
  font-weight: 800;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease, border-color .18s ease, color .18s ease;
}

.wp-core-ui .button:hover,
.wp-core-ui .button-secondary:hover,
.wp-core-ui .page-title-action:hover,
.wp-core-ui .button:focus,
.wp-core-ui .button-secondary:focus,
.wp-core-ui .page-title-action:focus {
  transform: translateY(-1px);
  border-color: rgba(72,98,255,.45) !important;
  color: var(--as-wp-accent) !important;
  box-shadow: 0 12px 28px rgba(72,98,255,.14) !important;
}

.wp-core-ui .button-primary:hover,
.wp-core-ui .button-primary:focus {
  transform: translateY(-1px);
  box-shadow: 0 16px 34px rgba(72,98,255,.32) !important;
}

body.wp-admin.as-admin-skin-dark-page .wp-core-ui .button,
body.wp-admin.as-admin-skin-dark-page .wp-core-ui .button-secondary,
body.wp-admin.as-admin-skin-dark-page .wp-core-ui .page-title-action,
html.as-admin-skin-dark-root body.wp-admin .wp-core-ui .button,
html.as-admin-skin-dark-root body.wp-admin .wp-core-ui .button-secondary,
html.as-admin-skin-dark-root body.wp-admin .wp-core-ui .page-title-action {
  background: rgba(17,24,43,.92) !important;
  border-color: rgba(147,166,255,.20) !important;
  color: #eef3ff !important;
}

/* Inputs and select2 */
body.wp-admin input[type="text"],
body.wp-admin input[type="search"],
body.wp-admin input[type="email"],
body.wp-admin input[type="url"],
body.wp-admin input[type="password"],
body.wp-admin input[type="number"],
body.wp-admin input[type="date"],
body.wp-admin input[type="datetime-local"],
body.wp-admin textarea,
body.wp-admin select,
body.wp-admin .select2-container--default .select2-selection--single,
body.wp-admin .select2-container--default .select2-selection--multiple {
  border-radius: 11px !important;
  border-color: var(--as-wp-line) !important;
  box-shadow: none !important;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

body.wp-admin input:focus,
body.wp-admin textarea:focus,
body.wp-admin select:focus {
  border-color: rgba(72,98,255,.62) !important;
  box-shadow: 0 0 0 4px rgba(72,98,255,.14) !important;
  outline: 0 !important;
}

/* Dark mode: cover all WordPress table/list alternating rows */
body.wp-admin.as-admin-skin-dark-page .widefat,
body.wp-admin.as-admin-skin-dark-page .wp-list-table,
body.wp-admin.as-admin-skin-dark-page .fixed,
body.wp-admin.as-admin-skin-dark-page .striped,
html.as-admin-skin-dark-root body.wp-admin .widefat,
html.as-admin-skin-dark-root body.wp-admin .wp-list-table,
html.as-admin-skin-dark-root body.wp-admin .fixed,
html.as-admin-skin-dark-root body.wp-admin .striped {
  background: rgba(17,24,43,.92) !important;
  color: #f4f7ff !important;
  border-color: rgba(147,166,255,.16) !important;
}

body.wp-admin.as-admin-skin-dark-page .widefat thead tr,
body.wp-admin.as-admin-skin-dark-page .widefat tfoot tr,
html.as-admin-skin-dark-root body.wp-admin .widefat thead tr,
html.as-admin-skin-dark-root body.wp-admin .widefat tfoot tr {
  background: rgba(10,15,30,.98) !important;
}

body.wp-admin.as-admin-skin-dark-page .widefat tbody tr,
body.wp-admin.as-admin-skin-dark-page .widefat tbody tr.alternate,
body.wp-admin.as-admin-skin-dark-page .widefat tbody tr:nth-child(odd),
body.wp-admin.as-admin-skin-dark-page .striped > tbody > :nth-child(odd),
body.wp-admin.as-admin-skin-dark-page .striped > tbody > :nth-child(even),
body.wp-admin.as-admin-skin-dark-page .wp-list-table tbody tr,
body.wp-admin.as-admin-skin-dark-page .wp-list-table tbody tr.alternate,
html.as-admin-skin-dark-root body.wp-admin .widefat tbody tr,
html.as-admin-skin-dark-root body.wp-admin .widefat tbody tr.alternate,
html.as-admin-skin-dark-root body.wp-admin .widefat tbody tr:nth-child(odd),
html.as-admin-skin-dark-root body.wp-admin .striped > tbody > :nth-child(odd),
html.as-admin-skin-dark-root body.wp-admin .striped > tbody > :nth-child(even),
html.as-admin-skin-dark-root body.wp-admin .wp-list-table tbody tr,
html.as-admin-skin-dark-root body.wp-admin .wp-list-table tbody tr.alternate {
  background: rgba(17,24,43,.92) !important;
  color: #f4f7ff !important;
}

body.wp-admin.as-admin-skin-dark-page .widefat tbody tr:nth-child(even),
body.wp-admin.as-admin-skin-dark-page .wp-list-table tbody tr:nth-child(even),
html.as-admin-skin-dark-root body.wp-admin .widefat tbody tr:nth-child(even),
html.as-admin-skin-dark-root body.wp-admin .wp-list-table tbody tr:nth-child(even) {
  background: rgba(13,20,37,.96) !important;
}

body.wp-admin.as-admin-skin-dark-page .widefat tbody tr:hover,
body.wp-admin.as-admin-skin-dark-page .wp-list-table tbody tr:hover,
html.as-admin-skin-dark-root body.wp-admin .widefat tbody tr:hover,
html.as-admin-skin-dark-root body.wp-admin .wp-list-table tbody tr:hover {
  background: rgba(72,98,255,.14) !important;
  box-shadow: inset 4px 0 0 rgba(72,98,255,.75);
}

.rtl body.wp-admin.as-admin-skin-dark-page .widefat tbody tr:hover,
.rtl body.wp-admin.as-admin-skin-dark-page .wp-list-table tbody tr:hover,
.rtl html.as-admin-skin-dark-root body.wp-admin .widefat tbody tr:hover,
.rtl html.as-admin-skin-dark-root body.wp-admin .wp-list-table tbody tr:hover {
  box-shadow: inset -4px 0 0 rgba(72,98,255,.75);
}

body.wp-admin.as-admin-skin-dark-page .widefat td,
body.wp-admin.as-admin-skin-dark-page .widefat th,
body.wp-admin.as-admin-skin-dark-page .wp-list-table td,
body.wp-admin.as-admin-skin-dark-page .wp-list-table th,
body.wp-admin.as-admin-skin-dark-page .column-title strong,
body.wp-admin.as-admin-skin-dark-page .row-title,
body.wp-admin.as-admin-skin-dark-page .post-state,
body.wp-admin.as-admin-skin-dark-page .row-actions,
body.wp-admin.as-admin-skin-dark-page .row-actions span,
body.wp-admin.as-admin-skin-dark-page .sorting-indicators .sorting-indicator,
html.as-admin-skin-dark-root body.wp-admin .widefat td,
html.as-admin-skin-dark-root body.wp-admin .widefat th,
html.as-admin-skin-dark-root body.wp-admin .wp-list-table td,
html.as-admin-skin-dark-root body.wp-admin .wp-list-table th,
html.as-admin-skin-dark-root body.wp-admin .column-title strong,
html.as-admin-skin-dark-root body.wp-admin .row-title,
html.as-admin-skin-dark-root body.wp-admin .post-state,
html.as-admin-skin-dark-root body.wp-admin .row-actions,
html.as-admin-skin-dark-root body.wp-admin .row-actions span,
html.as-admin-skin-dark-root body.wp-admin .sorting-indicators .sorting-indicator {
  color: #f4f7ff !important;
  border-color: rgba(147,166,255,.14) !important;
}

body.wp-admin.as-admin-skin-dark-page .widefat th a,
body.wp-admin.as-admin-skin-dark-page .widefat td a,
body.wp-admin.as-admin-skin-dark-page .wp-list-table th a,
body.wp-admin.as-admin-skin-dark-page .wp-list-table td a,
html.as-admin-skin-dark-root body.wp-admin .widefat th a,
html.as-admin-skin-dark-root body.wp-admin .widefat td a,
html.as-admin-skin-dark-root body.wp-admin .wp-list-table th a,
html.as-admin-skin-dark-root body.wp-admin .wp-list-table td a {
  color: #6dabff !important;
}

body.wp-admin.as-admin-skin-dark-page .row-actions .trash a,
html.as-admin-skin-dark-root body.wp-admin .row-actions .trash a {
  color: #ff7d8b !important;
}

/* Dark mode: metaboxes, forms, taxonomy boxes, editor panels */
body.wp-admin.as-admin-skin-dark-page .postbox,
body.wp-admin.as-admin-skin-dark-page .stuffbox,
body.wp-admin.as-admin-skin-dark-page .welcome-panel,
body.wp-admin.as-admin-skin-dark-page .card,
body.wp-admin.as-admin-skin-dark-page .notice,
body.wp-admin.as-admin-skin-dark-page div.updated,
body.wp-admin.as-admin-skin-dark-page div.error,
body.wp-admin.as-admin-skin-dark-page .menu-edit,
body.wp-admin.as-admin-skin-dark-page .menu-settings,
body.wp-admin.as-admin-skin-dark-page .accordion-section-content,
body.wp-admin.as-admin-skin-dark-page .wp-filter,
body.wp-admin.as-admin-skin-dark-page .plugins .active th,
body.wp-admin.as-admin-skin-dark-page .plugins .active td,
body.wp-admin.as-admin-skin-dark-page .plugin-card,
body.wp-admin.as-admin-skin-dark-page .theme,
body.wp-admin.as-admin-skin-dark-page .theme-browser .theme,
body.wp-admin.as-admin-skin-dark-page .acf-postbox,
body.wp-admin.as-admin-skin-dark-page .acf-field,
body.wp-admin.as-admin-skin-dark-page .acf-fields,
html.as-admin-skin-dark-root body.wp-admin .postbox,
html.as-admin-skin-dark-root body.wp-admin .stuffbox,
html.as-admin-skin-dark-root body.wp-admin .welcome-panel,
html.as-admin-skin-dark-root body.wp-admin .card,
html.as-admin-skin-dark-root body.wp-admin .notice,
html.as-admin-skin-dark-root body.wp-admin div.updated,
html.as-admin-skin-dark-root body.wp-admin div.error,
html.as-admin-skin-dark-root body.wp-admin .menu-edit,
html.as-admin-skin-dark-root body.wp-admin .menu-settings,
html.as-admin-skin-dark-root body.wp-admin .accordion-section-content,
html.as-admin-skin-dark-root body.wp-admin .wp-filter,
html.as-admin-skin-dark-root body.wp-admin .plugins .active th,
html.as-admin-skin-dark-root body.wp-admin .plugins .active td,
html.as-admin-skin-dark-root body.wp-admin .plugin-card,
html.as-admin-skin-dark-root body.wp-admin .theme,
html.as-admin-skin-dark-root body.wp-admin .theme-browser .theme,
html.as-admin-skin-dark-root body.wp-admin .acf-postbox,
html.as-admin-skin-dark-root body.wp-admin .acf-field,
html.as-admin-skin-dark-root body.wp-admin .acf-fields {
  background: rgba(17,24,43,.92) !important;
  color: #f4f7ff !important;
  border-color: rgba(147,166,255,.16) !important;
}

body.wp-admin.as-admin-skin-dark-page .postbox-header,
body.wp-admin.as-admin-skin-dark-page .hndle,
body.wp-admin.as-admin-skin-dark-page .inside,
body.wp-admin.as-admin-skin-dark-page .submitbox,
body.wp-admin.as-admin-skin-dark-page #minor-publishing,
body.wp-admin.as-admin-skin-dark-page #major-publishing-actions,
body.wp-admin.as-admin-skin-dark-page .categorydiv div.tabs-panel,
body.wp-admin.as-admin-skin-dark-page .customlinkdiv div.tabs-panel,
body.wp-admin.as-admin-skin-dark-page .posttypediv div.tabs-panel,
body.wp-admin.as-admin-skin-dark-page .taxonomydiv div.tabs-panel,
body.wp-admin.as-admin-skin-dark-page .tabs-panel,
html.as-admin-skin-dark-root body.wp-admin .postbox-header,
html.as-admin-skin-dark-root body.wp-admin .hndle,
html.as-admin-skin-dark-root body.wp-admin .inside,
html.as-admin-skin-dark-root body.wp-admin .submitbox,
html.as-admin-skin-dark-root body.wp-admin #minor-publishing,
html.as-admin-skin-dark-root body.wp-admin #major-publishing-actions,
html.as-admin-skin-dark-root body.wp-admin .categorydiv div.tabs-panel,
html.as-admin-skin-dark-root body.wp-admin .customlinkdiv div.tabs-panel,
html.as-admin-skin-dark-root body.wp-admin .posttypediv div.tabs-panel,
html.as-admin-skin-dark-root body.wp-admin .taxonomydiv div.tabs-panel,
html.as-admin-skin-dark-root body.wp-admin .tabs-panel {
  background: rgba(13,20,37,.94) !important;
  color: #f4f7ff !important;
  border-color: rgba(147,166,255,.14) !important;
}

body.wp-admin.as-admin-skin-dark-page .wrap h1,
body.wp-admin.as-admin-skin-dark-page .wrap h2,
body.wp-admin.as-admin-skin-dark-page .wrap h3,
body.wp-admin.as-admin-skin-dark-page .form-table th,
body.wp-admin.as-admin-skin-dark-page label,
body.wp-admin.as-admin-skin-dark-page .postbox .hndle,
body.wp-admin.as-admin-skin-dark-page .postbox-header h2,
body.wp-admin.as-admin-skin-dark-page .nav-tab,
body.wp-admin.as-admin-skin-dark-page .subsubsub a,
html.as-admin-skin-dark-root body.wp-admin .wrap h1,
html.as-admin-skin-dark-root body.wp-admin .wrap h2,
html.as-admin-skin-dark-root body.wp-admin .wrap h3,
html.as-admin-skin-dark-root body.wp-admin .form-table th,
html.as-admin-skin-dark-root body.wp-admin label,
html.as-admin-skin-dark-root body.wp-admin .postbox .hndle,
html.as-admin-skin-dark-root body.wp-admin .postbox-header h2,
html.as-admin-skin-dark-root body.wp-admin .nav-tab,
html.as-admin-skin-dark-root body.wp-admin .subsubsub a {
  color: #f6f8ff !important;
}

body.wp-admin.as-admin-skin-dark-page p,
body.wp-admin.as-admin-skin-dark-page .description,
body.wp-admin.as-admin-skin-dark-page .howto,
body.wp-admin.as-admin-skin-dark-page .form-wrap p,
body.wp-admin.as-admin-skin-dark-page .tablenav,
body.wp-admin.as-admin-skin-dark-page .subsubsub,
html.as-admin-skin-dark-root body.wp-admin p,
html.as-admin-skin-dark-root body.wp-admin .description,
html.as-admin-skin-dark-root body.wp-admin .howto,
html.as-admin-skin-dark-root body.wp-admin .form-wrap p,
html.as-admin-skin-dark-root body.wp-admin .tablenav,
html.as-admin-skin-dark-root body.wp-admin .subsubsub {
  color: rgba(231,237,255,.72) !important;
}

/* Dark mode: chart text and dashboard card typography */
body.wp-admin.as-admin-skin-dark-page .as-admin-chart-head h3,
html.as-admin-skin-dark-root body.wp-admin .as-admin-chart-head h3,
body.wp-admin.as-admin-skin-dark-page .as-admin-kpi-card span:not(.dashicons),
html.as-admin-skin-dark-root body.wp-admin .as-admin-kpi-card span:not(.dashicons) {
  color: #f7f9ff !important;
}

body.wp-admin.as-admin-skin-dark-page .as-admin-chart-head span,
html.as-admin-skin-dark-root body.wp-admin .as-admin-chart-head span {
  color: #8fa4ff !important;
}

body.wp-admin.as-admin-skin-dark-page .apexcharts-text,
body.wp-admin.as-admin-skin-dark-page .apexcharts-title-text,
body.wp-admin.as-admin-skin-dark-page .apexcharts-legend-text,
body.wp-admin.as-admin-skin-dark-page .apexcharts-datalabel-label,
body.wp-admin.as-admin-skin-dark-page .apexcharts-datalabel-value,
html.as-admin-skin-dark-root body.wp-admin .apexcharts-text,
html.as-admin-skin-dark-root body.wp-admin .apexcharts-title-text,
html.as-admin-skin-dark-root body.wp-admin .apexcharts-legend-text,
html.as-admin-skin-dark-root body.wp-admin .apexcharts-datalabel-label,
html.as-admin-skin-dark-root body.wp-admin .apexcharts-datalabel-value {
  fill: #f7f9ff !important;
  color: #f7f9ff !important;
}

body.wp-admin.as-admin-skin-dark-page .apexcharts-yaxis-label,
body.wp-admin.as-admin-skin-dark-page .apexcharts-xaxis-label,
html.as-admin-skin-dark-root body.wp-admin .apexcharts-yaxis-label,
html.as-admin-skin-dark-root body.wp-admin .apexcharts-xaxis-label {
  fill: rgba(231,237,255,.68) !important;
}

/* Cards and internal page hover polish */
body.wp-admin .postbox,
body.wp-admin .card,
body.wp-admin .plugin-card,
body.wp-admin .theme-browser .theme,
body.wp-admin .as-admin-kpi-card,
body.wp-admin .as-admin-chart-card {
  transition: transform .22s ease, box-shadow .22s ease, border-color .22s ease, background .22s ease;
}

body.wp-admin .postbox:hover,
body.wp-admin .card:hover,
body.wp-admin .plugin-card:hover,
body.wp-admin .theme-browser .theme:hover,
body.wp-admin .as-admin-kpi-card:hover,
body.wp-admin .as-admin-chart-card:hover {
  transform: translateY(-3px);
  border-color: rgba(72,98,255,.28) !important;
  box-shadow: 0 28px 80px rgba(11,23,57,.15);
}

body.wp-admin.as-admin-skin-dark-page .postbox:hover,
body.wp-admin.as-admin-skin-dark-page .card:hover,
body.wp-admin.as-admin-skin-dark-page .plugin-card:hover,
body.wp-admin.as-admin-skin-dark-page .theme-browser .theme:hover,
body.wp-admin.as-admin-skin-dark-page .as-admin-kpi-card:hover,
body.wp-admin.as-admin-skin-dark-page .as-admin-chart-card:hover,
html.as-admin-skin-dark-root body.wp-admin .postbox:hover,
html.as-admin-skin-dark-root body.wp-admin .card:hover,
html.as-admin-skin-dark-root body.wp-admin .plugin-card:hover,
html.as-admin-skin-dark-root body.wp-admin .theme-browser .theme:hover,
html.as-admin-skin-dark-root body.wp-admin .as-admin-kpi-card:hover,
html.as-admin-skin-dark-root body.wp-admin .as-admin-chart-card:hover {
  border-color: rgba(143,164,255,.24) !important;
  box-shadow: 0 30px 90px rgba(0,0,0,.36);
}

/* Footer branding */
#wpfooter {
  padding: 18px 24px !important;
  border-top: 1px solid var(--as-wp-line);
  background: rgba(255,255,255,.32);
  backdrop-filter: blur(14px);
}

body.wp-admin.as-admin-skin-dark-page #wpfooter,
html.as-admin-skin-dark-root body.wp-admin #wpfooter {
  background: rgba(8,13,25,.54) !important;
  color: rgba(231,237,255,.72) !important;
}

.as-admin-footer-brand strong,
.as-admin-footer-version {
  color: var(--as-wp-accent);
  font-weight: 1000;
}

/* Dashboard widget title spacing */
body.index-php .wrap > h1 {
  margin-bottom: 18px;
}


/* --------------------------------------------------------------------------
   ALFASMART v3: premium light mode, red live pulse, and stronger full-admin skin
   -------------------------------------------------------------------------- */
:root {
  --as-live-red: #ff314f;
  --as-live-red-2: #ff6a7d;
  --as-live-red-soft: rgba(255, 49, 79, .12);
  --as-admin-radius-xl: 30px;
  --as-admin-radius-lg: 22px;
  --as-admin-radius-md: 14px;
}

/* Global wp-admin canvas */
body.wp-admin:not(.as-admin-skin-dark-page),
html:not(.as-admin-skin-dark-root) body.wp-admin {
  --as-wp-bg: #eef4ff;
  --as-wp-panel: rgba(255,255,255,.86);
  --as-wp-panel-solid: #ffffff;
  --as-wp-ink: #07111f;
  --as-wp-muted: #60708a;
  --as-wp-line: rgba(72,98,255,.16);
  --as-wp-shadow: 0 24px 70px rgba(22,34,76,.12);
  background:
    radial-gradient(circle at 3% 0%, rgba(72,98,255,.16), transparent 30%),
    radial-gradient(circle at 100% 8%, rgba(35,199,255,.14), transparent 34%),
    linear-gradient(135deg, #f8fbff 0%, #eef4ff 48%, #e8f7ff 100%) !important;
}

body.wp-admin.as-admin-skin-dark-page,
html.as-admin-skin-dark-root body.wp-admin {
  background:
    radial-gradient(circle at 2% 2%, rgba(72,98,255,.22), transparent 32%),
    radial-gradient(circle at 100% 14%, rgba(35,199,255,.10), transparent 34%),
    linear-gradient(135deg, #070b16 0%, #0b1020 50%, #070b16 100%) !important;
}

body.wp-admin #wpcontent {
  padding-left: 24px;
  padding-right: 24px;
}

.rtl body.wp-admin #wpcontent {
  padding-left: 24px;
  padding-right: 24px;
}

body.wp-admin #wpbody-content > .wrap {
  margin-top: 22px;
}

body.wp-admin .wrap > h1,
body.wp-admin .wrap h1.wp-heading-inline {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin: 0 10px 18px 0;
  color: var(--as-wp-ink) !important;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: -.035em;
}

.rtl body.wp-admin .wrap > h1,
.rtl body.wp-admin .wrap h1.wp-heading-inline {
  margin: 0 0 18px 10px;
  letter-spacing: 0;
}

/* Top admin bar and screen buttons */
#wpadminbar {
  height: 34px;
  background: rgba(9,14,28,.96) !important;
  border-bottom: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 16px 44px rgba(5,10,24,.18) !important;
}

#wpadminbar .quicklinks .ab-empty-item,
#wpadminbar .quicklinks a,
#wpadminbar .shortlink-input {
  height: 34px !important;
  line-height: 34px !important;
}

#wpadminbar .ab-icon,
#wpadminbar .ab-item:before,
#wpadminbar>#wp-toolbar>#wp-admin-bar-root-default .ab-icon {
  top: 2px;
}

#screen-meta-links {
  margin: 4px 0 18px;
}

#screen-meta-links .show-settings {
  min-height: 36px;
  padding: 0 18px !important;
  border: 1px solid rgba(72,98,255,.18) !important;
  border-radius: 999px !important;
  background: rgba(255,255,255,.86) !important;
  color: #1b2740 !important;
  font-weight: 800;
  box-shadow: 0 12px 30px rgba(18,32,68,.08);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

#screen-meta-links .show-settings:hover,
#screen-meta-links .show-settings:focus {
  transform: translateY(-1px);
  border-color: rgba(72,98,255,.34) !important;
  box-shadow: 0 16px 36px rgba(72,98,255,.14);
}

body.wp-admin.as-admin-skin-dark-page #screen-meta-links .show-settings,
html.as-admin-skin-dark-root body.wp-admin #screen-meta-links .show-settings {
  background: rgba(14,21,39,.92) !important;
  color: #f7f9ff !important;
  border-color: rgba(147,166,255,.18) !important;
}

/* Sidebar: stronger branded application shell */
#adminmenuback,
#adminmenuwrap {
  width: 172px;
  background:
    radial-gradient(circle at 18% 8%, rgba(72,98,255,.24), transparent 34%),
    linear-gradient(180deg, #0c1324 0%, #080d19 100%) !important;
  border-right: 1px solid rgba(255,255,255,.08);
}

.rtl #adminmenuback,
.rtl #adminmenuwrap {
  border-right: 0;
  border-left: 1px solid rgba(255,255,255,.08);
}

#adminmenu {
  width: 172px;
  padding: 14px 10px 18px !important;
}

#adminmenu .wp-menu-name {
  padding: 8px 8px 8px 36px;
  font-weight: 750;
}

.rtl #adminmenu .wp-menu-name {
  padding: 8px 36px 8px 8px;
}

#adminmenu div.wp-menu-image {
  width: 36px;
}

#adminmenu li.menu-top > a {
  position: relative;
  min-height: 42px;
  border-radius: 16px !important;
  overflow: hidden;
}

#adminmenu li.menu-top > a:before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
  background: linear-gradient(135deg, rgba(72,98,255,.22), rgba(35,199,255,.12));
  transition: opacity .18s ease;
}

#adminmenu li.menu-top:hover > a:before,
#adminmenu li.opensub > a.menu-top:before,
#adminmenu li.wp-has-current-submenu > a.wp-has-current-submenu:before,
#adminmenu li.current > a.menu-top:before {
  opacity: 1;
}

#adminmenu li.menu-top:hover > a,
#adminmenu li.opensub > a.menu-top,
#adminmenu li > a.menu-top:focus {
  transform: translateX(5px) scale(1.015);
}

.rtl #adminmenu li.menu-top:hover > a,
.rtl #adminmenu li.opensub > a.menu-top,
.rtl #adminmenu li > a.menu-top:focus {
  transform: translateX(-5px) scale(1.015);
}

#adminmenu .wp-submenu {
  left: 172px;
  border: 1px solid rgba(255,255,255,.08) !important;
}

.rtl #adminmenu .wp-submenu {
  right: 172px;
  left: auto;
}

#wpcontent,
#wpfooter {
  margin-left: 172px;
}

.rtl #wpcontent,
.rtl #wpfooter {
  margin-left: 0;
  margin-right: 172px;
}

/* Dashboard hero light readability fix */
body.wp-admin .as-admin-dashboard .as-admin-hero {
  border: 1px solid rgba(255,255,255,.46);
  background:
    radial-gradient(circle at 82% 0%, rgba(72,98,255,.76), transparent 42%),
    radial-gradient(circle at 4% 100%, rgba(35,199,255,.24), transparent 36%),
    linear-gradient(135deg, #0b1224 0%, #151d34 52%, #3347a9 100%) !important;
  box-shadow: 0 34px 110px rgba(32, 48, 106, .22);
}

body.wp-admin .as-admin-dashboard .as-admin-hero h2,
body.wp-admin .as-admin-dashboard .as-admin-hero p,
body.wp-admin .as-admin-dashboard .as-admin-hero .as-admin-eyebrow,
body.wp-admin .as-admin-dashboard .as-admin-hero .as-admin-mini-strip span,
body.wp-admin .as-admin-dashboard .as-admin-hero .as-admin-mini-strip b {
  text-shadow: 0 12px 28px rgba(0,0,0,.22);
}

body.wp-admin .as-admin-dashboard .as-admin-hero h2 {
  color: #ffffff !important;
}

body.wp-admin .as-admin-dashboard .as-admin-hero p {
  color: rgba(245,247,255,.78) !important;
}

body.wp-admin .as-admin-dashboard .as-admin-eyebrow {
  color: #b9c6ff !important;
}

body.wp-admin .as-admin-dashboard .as-admin-mini-strip span {
  border-color: rgba(255,255,255,.18) !important;
  background: rgba(255,255,255,.10) !important;
  color: rgba(255,255,255,.82) !important;
}

body.wp-admin .as-admin-dashboard .as-admin-mini-strip b {
  color: #fff !important;
}

body.wp-admin .as-admin-dashboard .as-admin-mini-strip span:first-child {
  background: rgba(255,49,79,.16) !important;
  border-color: rgba(255,49,79,.42) !important;
  color: #ffdce2 !important;
  box-shadow: 0 0 0 1px rgba(255,49,79,.10), 0 14px 34px rgba(255,49,79,.13);
}

body.wp-admin .as-admin-dashboard .as-admin-mini-strip span:first-child:before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--as-live-red);
  box-shadow: 0 0 0 0 rgba(255,49,79,.75);
  animation: asLivePulse 1.45s ease-out infinite;
}

/* KPI cards light/dark refinement */
body.wp-admin .as-admin-kpi-grid {
  gap: 18px;
}

body.wp-admin .as-admin-kpi-card {
  border: 1px solid rgba(72,98,255,.13);
  background:
    linear-gradient(180deg, rgba(255,255,255,.96), rgba(255,255,255,.84)),
    radial-gradient(circle at 100% 100%, rgba(72,98,255,.10), transparent 42%) !important;
  box-shadow: 0 22px 60px rgba(20,34,78,.10);
}

body.wp-admin .as-admin-kpi-card:hover {
  transform: translateY(-6px) scale(1.012);
  box-shadow: 0 34px 84px rgba(20,34,78,.16) !important;
}

body.wp-admin.as-admin-skin-dark-page .as-admin-kpi-card,
html.as-admin-skin-dark-root body.wp-admin .as-admin-kpi-card {
  background:
    linear-gradient(180deg, rgba(17,24,43,.96), rgba(13,20,37,.91)),
    radial-gradient(circle at 100% 100%, rgba(72,98,255,.18), transparent 42%) !important;
  border-color: rgba(147,166,255,.16) !important;
}

.as-tone-red {
  border-color: rgba(255,49,79,.28) !important;
}

.as-tone-red:before {
  background: radial-gradient(circle, rgba(255,49,79,.22), transparent 70%) !important;
}

.as-tone-red:after {
  content: "";
  position: absolute;
  top: 24px;
  right: 24px;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--as-live-red);
  box-shadow: 0 0 0 0 rgba(255,49,79,.78);
  animation: asLivePulse 1.4s ease-out infinite;
}

.rtl .as-tone-red:after,
.as-admin-dashboard[dir="rtl"] .as-tone-red:after {
  right: auto;
  left: 24px;
}

.as-tone-red .as-admin-kpi-icon {
  background: rgba(255,49,79,.13) !important;
  color: var(--as-live-red) !important;
}

.as-tone-red strong {
  color: var(--as-live-red) !important;
}

.as-tone-red small {
  color: rgba(255,49,79,.82) !important;
}

body.wp-admin.as-admin-skin-dark-page .as-tone-red small,
html.as-admin-skin-dark-root body.wp-admin .as-tone-red small {
  color: #ff9aaa !important;
}

@keyframes asLivePulse {
  0% { box-shadow: 0 0 0 0 rgba(255,49,79,.72); transform: scale(1); }
  70% { box-shadow: 0 0 0 13px rgba(255,49,79,0); transform: scale(1.08); }
  100% { box-shadow: 0 0 0 0 rgba(255,49,79,0); transform: scale(1); }
}

/* Chart cards: cleaner light separation */
body.wp-admin .as-admin-chart-card {
  background:
    linear-gradient(180deg, rgba(255,255,255,.96), rgba(255,255,255,.88)) !important;
  border-color: rgba(72,98,255,.13) !important;
  box-shadow: 0 22px 64px rgba(20,34,78,.10);
}

body.wp-admin .as-admin-chart-card:hover {
  transform: translateY(-5px);
}

body.wp-admin.as-admin-skin-dark-page .as-admin-chart-card,
html.as-admin-skin-dark-root body.wp-admin .as-admin-chart-card {
  background: linear-gradient(180deg, rgba(17,24,43,.96), rgba(13,20,37,.92)) !important;
}

body.wp-admin .as-admin-chart-head h3,
body.wp-admin .as-admin-kpi-card span:not(.dashicons) {
  color: #07111f !important;
}

body.wp-admin .as-admin-chart-head span {
  color: var(--as-wp-accent) !important;
}

body.wp-admin .as-admin-note {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  padding: 14px 18px;
  border: 1px solid rgba(72,98,255,.12);
  border-radius: 18px;
  background: rgba(255,255,255,.68);
  color: #66728a !important;
}

body.wp-admin.as-admin-skin-dark-page .as-admin-note,
html.as-admin-skin-dark-root body.wp-admin .as-admin-note {
  background: rgba(13,20,37,.68) !important;
  color: rgba(231,237,255,.74) !important;
  border-color: rgba(147,166,255,.14) !important;
}

/* WordPress internal pages: table and content system */
body.wp-admin:not(.as-admin-skin-dark-page) .widefat,
body.wp-admin:not(.as-admin-skin-dark-page) .wp-list-table,
body.wp-admin:not(.as-admin-skin-dark-page) .postbox,
body.wp-admin:not(.as-admin-skin-dark-page) .card,
body.wp-admin:not(.as-admin-skin-dark-page) .stuffbox,
body.wp-admin:not(.as-admin-skin-dark-page) .plugin-card,
body.wp-admin:not(.as-admin-skin-dark-page) .theme-browser .theme,
body.wp-admin:not(.as-admin-skin-dark-page) .wp-filter,
body.wp-admin:not(.as-admin-skin-dark-page) .acf-postbox,
body.wp-admin:not(.as-admin-skin-dark-page) .acf-field,
body.wp-admin:not(.as-admin-skin-dark-page) .acf-fields,
body.wp-admin:not(.as-admin-skin-dark-page) .notice {
  background: rgba(255,255,255,.86) !important;
  border-color: rgba(72,98,255,.13) !important;
  box-shadow: 0 18px 54px rgba(20,34,78,.09) !important;
}

body.wp-admin:not(.as-admin-skin-dark-page) .widefat thead tr,
body.wp-admin:not(.as-admin-skin-dark-page) .widefat tfoot tr {
  background: linear-gradient(180deg, #f7faff, #eef4ff) !important;
}

body.wp-admin:not(.as-admin-skin-dark-page) .widefat tbody tr,
body.wp-admin:not(.as-admin-skin-dark-page) .wp-list-table tbody tr {
  background: rgba(255,255,255,.86) !important;
  transition: background .18s ease, box-shadow .18s ease, transform .18s ease;
}

body.wp-admin:not(.as-admin-skin-dark-page) .widefat tbody tr:nth-child(even),
body.wp-admin:not(.as-admin-skin-dark-page) .wp-list-table tbody tr:nth-child(even) {
  background: rgba(246,249,255,.88) !important;
}

body.wp-admin:not(.as-admin-skin-dark-page) .widefat tbody tr:hover,
body.wp-admin:not(.as-admin-skin-dark-page) .wp-list-table tbody tr:hover {
  background: rgba(72,98,255,.07) !important;
  box-shadow: inset 4px 0 0 rgba(72,98,255,.70);
}

.rtl body.wp-admin:not(.as-admin-skin-dark-page) .widefat tbody tr:hover,
.rtl body.wp-admin:not(.as-admin-skin-dark-page) .wp-list-table tbody tr:hover {
  box-shadow: inset -4px 0 0 rgba(72,98,255,.70);
}

body.wp-admin:not(.as-admin-skin-dark-page) .widefat th,
body.wp-admin:not(.as-admin-skin-dark-page) .widefat td,
body.wp-admin:not(.as-admin-skin-dark-page) .wp-list-table th,
body.wp-admin:not(.as-admin-skin-dark-page) .wp-list-table td,
body.wp-admin:not(.as-admin-skin-dark-page) .row-title,
body.wp-admin:not(.as-admin-skin-dark-page) .column-title strong {
  color: #101626 !important;
  border-color: rgba(72,98,255,.10) !important;
}

body.wp-admin:not(.as-admin-skin-dark-page) .post-state,
body.wp-admin:not(.as-admin-skin-dark-page) .row-actions,
body.wp-admin:not(.as-admin-skin-dark-page) .row-actions span {
  color: #6b758a !important;
}

body.wp-admin .subsubsub {
  margin: 2px 0 18px;
}

body.wp-admin .subsubsub a {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  text-decoration: none;
}

body.wp-admin .subsubsub a.current {
  background: rgba(72,98,255,.12);
  color: var(--as-wp-accent) !important;
  font-weight: 900;
}

body.wp-admin.as-admin-skin-dark-page .subsubsub a.current,
html.as-admin-skin-dark-root body.wp-admin .subsubsub a.current {
  background: rgba(72,98,255,.22) !important;
}

/* Forms and filters */
body.wp-admin input[type="text"],
body.wp-admin input[type="search"],
body.wp-admin input[type="email"],
body.wp-admin input[type="url"],
body.wp-admin input[type="password"],
body.wp-admin input[type="number"],
body.wp-admin input[type="date"],
body.wp-admin input[type="datetime-local"],
body.wp-admin textarea,
body.wp-admin select {
  min-height: 36px;
  background: rgba(255,255,255,.92) !important;
  color: #101626 !important;
}

body.wp-admin.as-admin-skin-dark-page input[type="text"],
body.wp-admin.as-admin-skin-dark-page input[type="search"],
body.wp-admin.as-admin-skin-dark-page input[type="email"],
body.wp-admin.as-admin-skin-dark-page input[type="url"],
body.wp-admin.as-admin-skin-dark-page input[type="password"],
body.wp-admin.as-admin-skin-dark-page input[type="number"],
body.wp-admin.as-admin-skin-dark-page input[type="date"],
body.wp-admin.as-admin-skin-dark-page input[type="datetime-local"],
body.wp-admin.as-admin-skin-dark-page textarea,
body.wp-admin.as-admin-skin-dark-page select,
html.as-admin-skin-dark-root body.wp-admin input[type="text"],
html.as-admin-skin-dark-root body.wp-admin input[type="search"],
html.as-admin-skin-dark-root body.wp-admin input[type="email"],
html.as-admin-skin-dark-root body.wp-admin input[type="url"],
html.as-admin-skin-dark-root body.wp-admin input[type="password"],
html.as-admin-skin-dark-root body.wp-admin input[type="number"],
html.as-admin-skin-dark-root body.wp-admin input[type="date"],
html.as-admin-skin-dark-root body.wp-admin input[type="datetime-local"],
html.as-admin-skin-dark-root body.wp-admin textarea,
html.as-admin-skin-dark-root body.wp-admin select {
  background: rgba(9,15,30,.96) !important;
  color: #f7f9ff !important;
}

body.wp-admin .tablenav .actions select,
body.wp-admin .tablenav .actions input,
body.wp-admin .tablenav .actions .button {
  margin-right: 6px;
}

.rtl body.wp-admin .tablenav .actions select,
.rtl body.wp-admin .tablenav .actions input,
.rtl body.wp-admin .tablenav .actions .button {
  margin-right: 0;
  margin-left: 6px;
}

/* Footer replacement polish */
#wpfooter {
  border-top: 1px solid rgba(72,98,255,.12) !important;
  background: rgba(255,255,255,.52) !important;
  box-shadow: 0 -18px 60px rgba(20,34,78,.06);
}

body.wp-admin.as-admin-skin-dark-page #wpfooter,
html.as-admin-skin-dark-root body.wp-admin #wpfooter {
  border-top-color: rgba(147,166,255,.12) !important;
  background: rgba(7,11,22,.70) !important;
}

/* Responsive admin shell */
@media (max-width: 960px) {
  body.wp-admin #wpcontent { padding-left: 14px; padding-right: 14px; }
  .auto-fold #adminmenuback,
  .auto-fold #adminmenuwrap,
  .auto-fold #adminmenu { width: 36px; }
  .auto-fold #wpcontent,
  .auto-fold #wpfooter { margin-left: 36px; }
  .rtl.auto-fold #wpcontent,
  .rtl.auto-fold #wpfooter { margin-right: 36px; margin-left: 0; }
}

@media (max-width: 782px) {
  #wpcontent,
  .rtl #wpcontent { margin-left: 0; margin-right: 0; padding-left: 12px; padding-right: 12px; }
  #wpfooter,
  .rtl #wpfooter { margin-left: 0; margin-right: 0; }
  body.wp-admin #wpbody-content > .wrap { margin-top: 14px; }
  body.wp-admin .wrap > h1,
  body.wp-admin .wrap h1.wp-heading-inline { font-size: 22px; }
}

/* Better responsive spacing inside tables */
@media (max-width: 782px) {
  body.wp-admin #wpcontent { padding-left: 14px; padding-right: 14px; }
  #adminmenu { padding: 0; }
  body.wp-admin .wrap { margin-left: 0; margin-right: 0; }
}

/* --------------------------------------------------------------------------
   ALFASMART v3: dark mode patch for Screen Options, Help, ACF tabs, panels
   -------------------------------------------------------------------------- */
body.wp-admin.as-admin-skin-dark-page #screen-meta,
body.wp-admin.as-admin-skin-dark-page #screen-options-wrap,
body.wp-admin.as-admin-skin-dark-page #contextual-help-wrap,
body.wp-admin.as-admin-skin-dark-page #contextual-help-back,
body.wp-admin.as-admin-skin-dark-page .contextual-help-sidebar,
body.wp-admin.as-admin-skin-dark-page .contextual-help-tabs,
body.wp-admin.as-admin-skin-dark-page .help-tab-content,
html.as-admin-skin-dark-root body.wp-admin #screen-meta,
html.as-admin-skin-dark-root body.wp-admin #screen-options-wrap,
html.as-admin-skin-dark-root body.wp-admin #contextual-help-wrap,
html.as-admin-skin-dark-root body.wp-admin #contextual-help-back,
html.as-admin-skin-dark-root body.wp-admin .contextual-help-sidebar,
html.as-admin-skin-dark-root body.wp-admin .contextual-help-tabs,
html.as-admin-skin-dark-root body.wp-admin .help-tab-content {
  background: #0d1425 !important;
  color: #f7f9ff !important;
  border-color: rgba(147,166,255,.16) !important;
  box-shadow: 0 24px 70px rgba(0,0,0,.24) !important;
}

body.wp-admin.as-admin-skin-dark-page #screen-meta *,
body.wp-admin.as-admin-skin-dark-page #contextual-help-wrap *,
html.as-admin-skin-dark-root body.wp-admin #screen-meta *,
html.as-admin-skin-dark-root body.wp-admin #contextual-help-wrap * {
  color: #f7f9ff !important;
}

body.wp-admin.as-admin-skin-dark-page #screen-meta a,
body.wp-admin.as-admin-skin-dark-page #contextual-help-wrap a,
html.as-admin-skin-dark-root body.wp-admin #screen-meta a,
html.as-admin-skin-dark-root body.wp-admin #contextual-help-wrap a {
  color: #8fb2ff !important;
}

body.wp-admin.as-admin-skin-dark-page #screen-meta a:hover,
body.wp-admin.as-admin-skin-dark-page #contextual-help-wrap a:hover,
html.as-admin-skin-dark-root body.wp-admin #screen-meta a:hover,
html.as-admin-skin-dark-root body.wp-admin #contextual-help-wrap a:hover {
  color: #ffffff !important;
}

body.wp-admin.as-admin-skin-dark-page .contextual-help-tabs .active,
body.wp-admin.as-admin-skin-dark-page .contextual-help-tabs .active a,
body.wp-admin.as-admin-skin-dark-page .contextual-help-tabs a:hover,
html.as-admin-skin-dark-root body.wp-admin .contextual-help-tabs .active,
html.as-admin-skin-dark-root body.wp-admin .contextual-help-tabs .active a,
html.as-admin-skin-dark-root body.wp-admin .contextual-help-tabs a:hover {
  background: rgba(72,98,255,.18) !important;
  color: #ffffff !important;
  border-color: rgba(147,166,255,.18) !important;
}

body.wp-admin.as-admin-skin-dark-page #contextual-help-columns,
body.wp-admin.as-admin-skin-dark-page .contextual-help-tabs-wrap,
html.as-admin-skin-dark-root body.wp-admin #contextual-help-columns,
html.as-admin-skin-dark-root body.wp-admin .contextual-help-tabs-wrap {
  background: transparent !important;
}

body.wp-admin.as-admin-skin-dark-page #screen-options-wrap input,
body.wp-admin.as-admin-skin-dark-page #screen-options-wrap select,
body.wp-admin.as-admin-skin-dark-page #screen-options-wrap label,
html.as-admin-skin-dark-root body.wp-admin #screen-options-wrap input,
html.as-admin-skin-dark-root body.wp-admin #screen-options-wrap select,
html.as-admin-skin-dark-root body.wp-admin #screen-options-wrap label {
  color: #f7f9ff !important;
}

body.wp-admin.as-admin-skin-dark-page .acf-tab-wrap,
body.wp-admin.as-admin-skin-dark-page .acf-tab-group,
body.wp-admin.as-admin-skin-dark-page .acf-fields > .acf-tab-wrap,
body.wp-admin.as-admin-skin-dark-page .acf-field-tab,
html.as-admin-skin-dark-root body.wp-admin .acf-tab-wrap,
html.as-admin-skin-dark-root body.wp-admin .acf-tab-group,
html.as-admin-skin-dark-root body.wp-admin .acf-fields > .acf-tab-wrap,
html.as-admin-skin-dark-root body.wp-admin .acf-field-tab {
  background: #0b1020 !important;
  border-color: rgba(147,166,255,.16) !important;
}

body.wp-admin.as-admin-skin-dark-page .acf-tab-group li a,
html.as-admin-skin-dark-root body.wp-admin .acf-tab-group li a {
  background: rgba(17,24,43,.92) !important;
  color: #8fb2ff !important;
  border-color: rgba(147,166,255,.16) !important;
}

body.wp-admin.as-admin-skin-dark-page .acf-tab-group li.active a,
body.wp-admin.as-admin-skin-dark-page .acf-tab-group li a:hover,
html.as-admin-skin-dark-root body.wp-admin .acf-tab-group li.active a,
html.as-admin-skin-dark-root body.wp-admin .acf-tab-group li a:hover {
  background: rgba(72,98,255,.18) !important;
  color: #ffffff !important;
  border-color: rgba(143,164,255,.35) !important;
}

body.wp-admin.as-admin-skin-dark-page .acf-field,
body.wp-admin.as-admin-skin-dark-page .acf-fields,
body.wp-admin.as-admin-skin-dark-page .acf-input,
body.wp-admin.as-admin-skin-dark-page .acf-label,
html.as-admin-skin-dark-root body.wp-admin .acf-field,
html.as-admin-skin-dark-root body.wp-admin .acf-fields,
html.as-admin-skin-dark-root body.wp-admin .acf-input,
html.as-admin-skin-dark-root body.wp-admin .acf-label {
  background: rgba(13,20,37,.94) !important;
  color: #f7f9ff !important;
  border-color: rgba(147,166,255,.14) !important;
}

body.wp-admin.as-admin-skin-dark-page .acf-label label,
body.wp-admin.as-admin-skin-dark-page .acf-label p,
body.wp-admin.as-admin-skin-dark-page .acf-field .description,
html.as-admin-skin-dark-root body.wp-admin .acf-label label,
html.as-admin-skin-dark-root body.wp-admin .acf-label p,
html.as-admin-skin-dark-root body.wp-admin .acf-field .description {
  color: rgba(231,237,255,.82) !important;
}

body.wp-admin.as-admin-skin-dark-page .form-table,
body.wp-admin.as-admin-skin-dark-page .form-table td,
body.wp-admin.as-admin-skin-dark-page .form-table th,
body.wp-admin.as-admin-skin-dark-page .inside,
body.wp-admin.as-admin-skin-dark-page .misc-pub-section,
body.wp-admin.as-admin-skin-dark-page .major-publishing-actions,
body.wp-admin.as-admin-skin-dark-page #major-publishing-actions,
body.wp-admin.as-admin-skin-dark-page #minor-publishing,
html.as-admin-skin-dark-root body.wp-admin .form-table,
html.as-admin-skin-dark-root body.wp-admin .form-table td,
html.as-admin-skin-dark-root body.wp-admin .form-table th,
html.as-admin-skin-dark-root body.wp-admin .inside,
html.as-admin-skin-dark-root body.wp-admin .misc-pub-section,
html.as-admin-skin-dark-root body.wp-admin .major-publishing-actions,
html.as-admin-skin-dark-root body.wp-admin #major-publishing-actions,
html.as-admin-skin-dark-root body.wp-admin #minor-publishing {
  background: rgba(13,20,37,.94) !important;
  color: #f7f9ff !important;
  border-color: rgba(147,166,255,.14) !important;
}

body.wp-admin.as-admin-skin-dark-page .nav-tab-wrapper,
body.wp-admin.as-admin-skin-dark-page .nav-tab,
html.as-admin-skin-dark-root body.wp-admin .nav-tab-wrapper,
html.as-admin-skin-dark-root body.wp-admin .nav-tab {
  background: #0d1425 !important;
  border-color: rgba(147,166,255,.16) !important;
  color: #8fb2ff !important;
}

body.wp-admin.as-admin-skin-dark-page .nav-tab-active,
body.wp-admin.as-admin-skin-dark-page .nav-tab-active:hover,
body.wp-admin.as-admin-skin-dark-page .nav-tab:hover,
html.as-admin-skin-dark-root body.wp-admin .nav-tab-active,
html.as-admin-skin-dark-root body.wp-admin .nav-tab-active:hover,
html.as-admin-skin-dark-root body.wp-admin .nav-tab:hover {
  background: rgba(72,98,255,.20) !important;
  color: #ffffff !important;
  border-color: rgba(143,164,255,.35) !important;
}

body.wp-admin.as-admin-skin-dark-page input[type="checkbox"],
body.wp-admin.as-admin-skin-dark-page input[type="radio"],
html.as-admin-skin-dark-root body.wp-admin input[type="checkbox"],
html.as-admin-skin-dark-root body.wp-admin input[type="radio"] {
  background-color: #0b1020 !important;
  border-color: rgba(147,166,255,.35) !important;
}

body.wp-admin.as-admin-skin-dark-page input[type="checkbox"]:checked::before,
html.as-admin-skin-dark-root body.wp-admin input[type="checkbox"]:checked::before {
  filter: brightness(1.8);
}

body.wp-admin.as-admin-skin-dark-page .notice,
body.wp-admin.as-admin-skin-dark-page div.updated,
body.wp-admin.as-admin-skin-dark-page div.error,
html.as-admin-skin-dark-root body.wp-admin .notice,
html.as-admin-skin-dark-root body.wp-admin div.updated,
html.as-admin-skin-dark-root body.wp-admin div.error {
  background: rgba(13,20,37,.96) !important;
  color: #f7f9ff !important;
  border-color: rgba(147,166,255,.16) !important;
}

CSS;
}

function alfasmart_admin_dashboard_inline_js()
{
    return <<<'JS'
(function ($) {
  "use strict";

  var charts = [];
  var data = window.alfasmartAdminDashboard || {};
  var config = window.alfasmartAdminDashboardConfig || {};
  var refreshTimer = null;

  function dashboard() { return document.querySelector("[data-as-admin-dashboard]"); }
  function isRtl() { return !!data.rtl || data.locale === "ar" || document.documentElement.dir === "rtl"; }
  function isDarkMode() { return document.body.classList.contains("as-admin-skin-dark-page"); }
  function colors() { return $.extend({ primary:"#4862ff", deep:"#3248df", cyan:"#23c7ff", gold:"#ffb84d", violet:"#7c5cff", green:"#21c986", red:"#ff314f", dark:"#101626" }, data.colors || {}); }
  function chartTextColor() { return isDarkMode() ? "#f7f9ff" : "#101626"; }
  function chartMutedColor() { return isDarkMode() ? "rgba(231,237,255,.68)" : "rgba(16,22,38,.58)"; }
  function chartGridColor() { return isDarkMode() ? "rgba(231,237,255,.12)" : "rgba(16,22,38,.10)"; }
  function hasValues(values) { return Array.isArray(values) && values.some(function (value) { return Number(value) > 0; }); }
  function safeSeries(values) { return hasValues(values) ? values.map(Number) : [1]; }
  function safeLabels(values, labels) { return hasValues(values) ? labels : [(data.text && data.text.empty) || "No data yet"]; }
  function numberLocale() { return data.locale === "ar" ? "ar-EG" : "en-US"; }
  function formatNumber(value) { try { return Number(value || 0).toLocaleString(numberLocale()); } catch (e) { return String(Math.round(Number(value || 0))); } }

  function applyTheme(mode) {
    var dark = mode === "dark";
    document.documentElement.classList.toggle("as-admin-skin-dark-root", dark);
    document.body.classList.toggle("as-admin-skin-dark-page", dark);
    document.body.classList.toggle("as-admin-dashboard-dark-page", dark);

    var el = dashboard();
    if (el) { el.classList.toggle("as-dashboard-dark", dark); }

    var labelText = dark ? ((data.text && data.text.light) || "Light") : ((data.text && data.text.dark) || "Dark");
    $(["[data-as-theme-label]", "#wp-admin-bar-as-admin-theme-toggle .ab-label"].join(",")).text(labelText);

    try { window.localStorage.setItem("as-admin-dashboard-theme", dark ? "dark" : "light"); } catch (e) {}
    try { document.cookie = "as_admin_theme=" + encodeURIComponent(dark ? "dark" : "light") + "; path=/; max-age=31536000; samesite=lax"; } catch (e) {}
    renderDashboard();
  }

  function initThemeToggle() {
    var saved = "";
    try {
      var cookieMatch = document.cookie.match(/(?:^|; )as_admin_theme=([^;]+)/);
      saved = cookieMatch ? decodeURIComponent(cookieMatch[1]) : "";
    } catch (e) {}
    if (!saved) { try { saved = window.localStorage.getItem("as-admin-dashboard-theme") || ""; } catch (e) {} }
    if (!saved) { saved = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; }
    applyTheme(saved);

    $(document).on("click", "[data-as-dashboard-theme-toggle], #wp-admin-bar-as-admin-theme-toggle > a", function (event) {
      event.preventDefault();
      applyTheme(isDarkMode() ? "light" : "dark");
    });
  }

  function updateLiveNumbers() {
    var summary = data.summary || {};
    $("[data-as-kpi-value]").each(function () {
      var key = this.getAttribute("data-as-kpi-value");
      if (key && Object.prototype.hasOwnProperty.call(summary, key)) { this.textContent = formatNumber(summary[key]); }
    });
    $("[data-as-summary-value]").each(function () {
      var key = this.getAttribute("data-as-summary-value");
      if (key && Object.prototype.hasOwnProperty.call(summary, key)) { this.textContent = formatNumber(summary[key]); }
    });
  }

  function baseOptions() {
    var rtl = isRtl();
    var palette = colors();
    return {
      chart: {
        fontFamily: rtl ? "Cairo, Tahoma, Arial, sans-serif" : "Inter, Arial, sans-serif",
        toolbar: { show: true, tools: { download:false, selection:false, zoom:false, zoomin:false, zoomout:false, pan:false, reset:false } },
        animations: { enabled:true, easing:"easeinout", speed:760, animateGradually:{ enabled:true, delay:80 }, dynamicAnimation:{ enabled:true, speed:360 } },
        foreColor: chartTextColor()
      },
      colors: [palette.primary, palette.cyan, palette.violet, palette.gold, palette.green],
      dataLabels: { enabled:false },
      stroke: { curve:"smooth", width:3, lineCap:"round" },
      grid: { borderColor: chartGridColor(), strokeDashArray:5, xaxis:{ lines:{ show:false } }, yaxis:{ lines:{ show:true } }, padding:{ left: rtl ? 8 : 4, right: rtl ? 4 : 8 } },
      legend: { position:"top", horizontalAlign: rtl ? "right" : "left", fontSize:"13px", labels:{ colors: chartMutedColor() }, markers:{ radius:12 } },
      tooltip: { theme: isDarkMode() ? "dark" : "light" }
    };
  }

  function mergeOptions(base, extra) { return $.extend(true, {}, base, extra); }
  function destroyCharts() { charts.forEach(function (chart) { if (chart && typeof chart.destroy === "function") { chart.destroy(); } }); charts = []; }
  function renderChart(selector, options) { var element = document.querySelector(selector); if (!element || typeof ApexCharts === "undefined") { return; } var chart = new ApexCharts(element, options); charts.push(chart); chart.render(); }

  function renderDashboard() {
    var el = dashboard();
    if (!el || typeof ApexCharts === "undefined") { return; }
    destroyCharts();

    var rtl = isRtl();
    var palette = colors();
    var base = baseOptions();
    var days = data.days || [];
    var hours = data.hours || [];
    var traffic = data.traffic || {};
    var todayHours = data.todayHours || {};
    var visitorSplit = data.visitorSplit || {};
    var device = data.device || {};
    var liveStatus = data.liveStatus || {};

    renderChart("#as-admin-traffic-chart", mergeOptions(base, {
      series: traffic.series || [],
      chart: { type:"area", height:390, parentHeightOffset:0 },
      fill: { type:"gradient", gradient:{ shadeIntensity:.5, opacityFrom:isDarkMode() ? .42 : .34, opacityTo:.035, stops:[0,85,100] } },
      xaxis: { categories:days, labels:{ rotate:0, style:{ colors:chartMutedColor(), fontSize:"12px" } }, axisBorder:{ show:false }, axisTicks:{ show:false } },
      yaxis: { opposite:rtl, forceNiceScale:true, min:0, labels:{ formatter:function(v){ return Math.round(v); }, style:{ colors:chartMutedColor(), fontSize:"12px" } } },
      responsive:[{ breakpoint:782, options:{ chart:{ height:315 }, legend:{ position:"bottom", horizontalAlign:"center" }, stroke:{ width:2.5 }, xaxis:{ labels:{ hideOverlappingLabels:true, trim:true } } } }, { breakpoint:480, options:{ chart:{ height:270 }, grid:{ padding:{ left:0, right:0 } }, xaxis:{ labels:{ show:false } }, yaxis:{ labels:{ show:false } } } }]
    }));

    renderChart("#as-admin-hours-chart", mergeOptions(base, {
      series: todayHours.series || [],
      chart: { type:"bar", height:285, parentHeightOffset:0 },
      plotOptions: { bar:{ borderRadius:7, columnWidth:"52%" } },
      stroke: { width:2, curve:"smooth" },
      xaxis: { categories:hours, tickAmount:6, labels:{ rotate:0, style:{ colors:chartMutedColor(), fontSize:"11px" } }, axisBorder:{ show:false }, axisTicks:{ show:false } },
      yaxis: { opposite:rtl, min:0, forceNiceScale:true, labels:{ formatter:function(v){ return Math.round(v); }, style:{ colors:chartMutedColor(), fontSize:"12px" } } },
      responsive:[{ breakpoint:480, options:{ chart:{ height:250 }, legend:{ position:"bottom", horizontalAlign:"center" }, xaxis:{ labels:{ show:false } }, yaxis:{ labels:{ show:false } } } }]
    }));

    renderChart("#as-admin-split-chart", mergeOptions(base, {
      series: safeSeries(visitorSplit.series || []),
      labels: safeLabels(visitorSplit.series || [], visitorSplit.labels || []),
      chart: { type:"donut", height:305, parentHeightOffset:0 },
      colors: hasValues(visitorSplit.series || []) ? [palette.cyan, palette.gold] : [isDarkMode() ? "rgba(255,255,255,.12)" : "rgba(72,98,255,.18)"],
      stroke: { width:0 },
      plotOptions: { pie:{ donut:{ size:"70%", labels:{ show:true, name:{ color:chartMutedColor() }, value:{ color:chartTextColor(), fontSize:"23px", fontWeight:900, formatter:function(v){ return Math.round(v); } }, total:{ show:true, label:(data.text && data.text.total) || "Total", color:chartMutedColor(), formatter:function(w){ var total=(w.globals.seriesTotals||[]).reduce(function(s,c){ return s+c; },0); return hasValues(visitorSplit.series || []) ? total : "0"; } } } } } },
      legend: { position:"bottom", horizontalAlign:"center" }
    }));

    renderChart("#as-admin-device-chart", mergeOptions(base, {
      series: safeSeries(device.series || []),
      labels: safeLabels(device.series || [], device.labels || []),
      chart: { type:"donut", height:305, parentHeightOffset:0 },
      colors: hasValues(device.series || []) ? [palette.green, palette.primary] : [isDarkMode() ? "rgba(255,255,255,.12)" : "rgba(72,98,255,.18)"],
      stroke: { width:0 },
      plotOptions: { pie:{ donut:{ size:"68%", labels:{ show:true, name:{ color:chartMutedColor() }, value:{ color:chartTextColor(), fontSize:"23px", fontWeight:900, formatter:function(v){ return Math.round(v); } }, total:{ show:true, label:(data.text && data.text.total) || "Total", color:chartMutedColor(), formatter:function(w){ var total=(w.globals.seriesTotals||[]).reduce(function(s,c){ return s+c; },0); return hasValues(device.series || []) ? total : "0"; } } } } } },
      legend: { position:"bottom", horizontalAlign:"center" }
    }));

    renderChart("#as-admin-live-status-chart", mergeOptions(base, {
      series: safeSeries(liveStatus.series || []),
      labels: safeLabels(liveStatus.series || [], liveStatus.labels || []),
      chart: { type:"donut", height:305, parentHeightOffset:0 },
      colors: hasValues(liveStatus.series || []) ? [palette.red || "#ff314f", palette.cyan] : [isDarkMode() ? "rgba(255,255,255,.12)" : "rgba(72,98,255,.18)"],
      stroke: { width:0 },
      plotOptions: { pie:{ donut:{ size:"70%", labels:{ show:true, name:{ color:chartMutedColor() }, value:{ color:chartTextColor(), fontSize:"23px", fontWeight:900, formatter:function(v){ return Math.round(v); } }, total:{ show:true, label:(data.text && data.text.lastMinute) || "Last 60 seconds", color:chartMutedColor(), formatter:function(){ return (data.summary && typeof data.summary.liveDirectNow !== "undefined") ? formatNumber(data.summary.liveDirectNow) : "0"; } } } } } },
      legend: { position:"bottom", horizontalAlign:"center" }
    }));
  }

  function refreshPayload() {
    if (!config.ajaxUrl || !config.nonce || !dashboard()) { return; }
    $.ajax({ url:config.ajaxUrl, method:"POST", dataType:"json", data:{ action:"alfasmart_admin_dashboard_payload", nonce:config.nonce } }).done(function (response) {
      if (!response || !response.success || !response.data) { return; }
      data = response.data;
      updateLiveNumbers();
      renderDashboard();
    });
  }

  function initAutoRefresh() {
    if (!dashboard()) { return; }
    if (refreshTimer) { window.clearInterval(refreshTimer); }
    refreshTimer = window.setInterval(refreshPayload, 30000);
  }

  $(function () {
    initThemeToggle();
    updateLiveNumbers();
    renderDashboard();
    initAutoRefresh();
    $(window).on("resize", function () { window.clearTimeout(window.alfasmartAdminDashboardResizeTimer); window.alfasmartAdminDashboardResizeTimer = window.setTimeout(renderDashboard, 220); });
  });
})(jQuery);
JS;
}

add_action('admin_enqueue_scripts', function ($hook) {
    wp_enqueue_style(
        'alfasmart-admin-fonts',
        'https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700;800;900;1000&family=Inter:wght@400;500;600;700;800;900&display=swap',
        array(),
        null
    );

    wp_enqueue_style('dashicons');

    wp_register_style('alfasmart-admin-dashboard-inline', false, array('alfasmart-admin-fonts', 'dashicons'), null);
    wp_enqueue_style('alfasmart-admin-dashboard-inline');
    wp_add_inline_style('alfasmart-admin-dashboard-inline', alfasmart_admin_dashboard_inline_css());

    wp_register_script('alfasmart-admin-dashboard-inline', false, array('jquery'), null, true);
    wp_enqueue_script('alfasmart-admin-dashboard-inline');

    $inline_before = 'window.alfasmartAdminDashboardConfig = ' . wp_json_encode(array(
        'ajaxUrl' => admin_url('admin-ajax.php'),
        'nonce'   => wp_create_nonce('alfasmart_admin_dashboard_payload'),
    )) . ';' . "\n";

    if ('index.php' === $hook) {
        wp_enqueue_script(
            'apexcharts',
            'https://cdn.jsdelivr.net/npm/apexcharts',
            array(),
            null,
            true
        );

        wp_add_inline_script(
            'apexcharts',
            $inline_before . 'window.alfasmartAdminDashboard = ' . wp_json_encode(alfasmart_admin_dashboard_payload()) . ';' . "\n" . alfasmart_admin_dashboard_inline_js(),
            'after'
        );
    } else {
        wp_add_inline_script(
            'alfasmart-admin-dashboard-inline',
            $inline_before . 'window.alfasmartAdminDashboard = window.alfasmartAdminDashboard || {};' . "\n" . alfasmart_admin_dashboard_inline_js(),
            'after'
        );
    }
});

/* --------------------------------------------------------------------------
 * Login page polish
 * -------------------------------------------------------------------------- */

add_filter('login_headerurl', function () {
    return home_url('/');
});

add_filter('login_headertext', function () {
    return get_bloginfo('name');
});

add_action('login_head', function () {
    $logo = function_exists('alfasmart_get_option_image_url') ? alfasmart_get_option_image_url('footer_logo', 'logo-footer.webp') : '';
    ?>
    <style>
        body.login {
            min-height: 100vh;
            background:
                linear-gradient(145deg, rgba(5, 8, 17, 0.82), rgba(11, 18, 34, 0.94)),
                radial-gradient(circle at 18% 14%, rgba(72, 98, 255, 0.28), transparent 32%),
                radial-gradient(circle at 84% 86%, rgba(35, 199, 255, 0.16), transparent 34%),
                #070b15;
            font-family: "Cairo", "Inter", Arial, sans-serif;
        }

        body.login #login {
            width: min(430px, calc(100% - 32px));
            padding: 7vh 0 0;
        }

        body.login h1 a {
            width: 260px;
            height: 76px;
            margin: 0 auto 28px;
            background-image: url("<?php echo esc_url($logo); ?>");
            background-size: contain;
            background-position: center;
            background-repeat: no-repeat;
        }

        body.login form {
            padding: 34px 34px 30px;
            border: 1px solid rgba(255, 255, 255, 0.14);
            border-radius: 22px;
            background: rgba(255, 255, 255, 0.92);
            box-shadow: 0 34px 90px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.72);
            backdrop-filter: blur(18px);
        }

        body.login label {
            color: #121827;
            font-weight: 700;
        }

        body.login form .input,
        body.login input[type="text"] {
            min-height: 48px;
            border: 1px solid #d8dce6;
            border-radius: 12px;
            background: #fff;
            box-shadow: none;
            color: #121827;
            font-size: 16px;
        }

        body.login form .input:focus,
        body.login input[type="text"]:focus {
            border-color: #4862ff;
            box-shadow: 0 0 0 3px rgba(72, 98, 255, 0.14);
        }

        body.login .button.wp-hide-pw {
            color: #4862ff;
        }

        body.login .button-primary {
            min-height: 44px;
            padding: 0 22px;
            border: 0;
            border-radius: 999px;
            background: linear-gradient(135deg, #4862ff 0%, #3248df 100%);
            box-shadow: 0 14px 32px rgba(72, 98, 255, 0.28);
            font-weight: 700;
        }

        body.login .button-primary:hover,
        body.login .button-primary:focus {
            background: linear-gradient(135deg, #6075ff 0%, #3248df 100%);
            box-shadow: 0 18px 40px rgba(72, 98, 255, 0.34);
        }

        body.login #nav,
        body.login #backtoblog,
        body.login .privacy-policy-page-link,
        body.login .language-switcher {
            text-align: center;
        }

        body.login #nav a,
        body.login #backtoblog a,
        body.login .privacy-policy-page-link a {
            color: rgba(255, 255, 255, 0.82);
            font-weight: 600;
        }

        body.login #nav a:hover,
        body.login #backtoblog a:hover,
        body.login .privacy-policy-page-link a:hover {
            color: #23c7ff;
        }

        body.login .language-switcher {
            margin-top: 22px;
        }

        body.login .language-switcher select,
        body.login .language-switcher .button {
            min-height: 42px;
            border-radius: 10px;
        }

        body.login .message,
        body.login .notice,
        body.login #login_error {
            border-radius: 14px;
            border-left-color: #4862ff;
            box-shadow: 0 18px 44px rgba(0, 0, 0, 0.18);
        }
    </style>
    <?php
});
