.elementor-283 .elementor-element.elementor-element-348dd7f{--display:flex;--flex-direction:column;--container-widget-width:100%;--container-widget-height:initial;--container-widget-flex-grow:0;--container-widget-align-self:initial;--flex-wrap-mobile:wrap;--justify-content:space-between;}.elementor-283 .elementor-element.elementor-element-9552cf8{width:100%;max-width:100%;}.elementor-283 .elementor-element.elementor-element-179c7d3{--display:flex;}.elementor-283 .elementor-element.elementor-element-2aa3200{width:100%;max-width:100%;}.elementor-283 .elementor-element.elementor-element-2aa3200 > .elementor-widget-container{margin:0px 0px 0px 0px;}.elementor-283 .elementor-element.elementor-element-2aa3200.elementor-element{--align-self:center;}.elementor-283 .elementor-element.elementor-element-43aad34{--display:flex;}@media(min-width:768px){.elementor-283 .elementor-element.elementor-element-348dd7f{--content-width:1424px;}.elementor-283 .elementor-element.elementor-element-179c7d3{--content-width:1595px;}.elementor-283 .elementor-element.elementor-element-43aad34{--content-width:1600px;}}/* Start custom CSS for shortcode, class: .elementor-element-9552cf8 *//* ═══════════════════════════════════════════════════════
   4. קבלת הליד — שמירה + מייל
   ═══════════════════════════════════════════════════════ */
add_action( 'wp_ajax_gali_lead',        'gali_handle_lead' );
add_action( 'wp_ajax_nopriv_gali_lead', 'gali_handle_lead' );

function gali_handle_lead() {

    if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'gali_lead_nonce' ) ) {
        wp_send_json_error( 'פג תוקף הטופס. רעננו את הדף ונסו שוב.' );
    }

    // מלכודת ספאם — שדה מוסתר שרק בוטים ממלאים
    if ( ! empty( $_POST['gm_website'] ) ) {
        wp_send_json_success( 'ok' );
    }

    $name  = sanitize_text_field( wp_unslash( $_POST['gm_name']  ?? '' ) );
    $phone = sanitize_text_field( wp_unslash( $_POST['gm_phone'] ?? '' ) );
    $date  = sanitize_text_field( wp_unslash( $_POST['gm_date']  ?? '' ) );
    $type  = sanitize_text_field( wp_unslash( $_POST['gm_type']  ?? '' ) );
    $note  = sanitize_textarea_field( wp_unslash( $_POST['gm_note'] ?? '' ) );
    $src   = sanitize_text_field( wp_unslash( $_POST['gm_source'] ?? '' ) );
    $page  = esc_url_raw( wp_unslash( $_POST['page'] ?? '' ) );

    if ( '' === $name || '' === $phone ) {
        wp_send_json_error( 'נא למלא שם ומספר טלפון.' );
    }

    $digits = preg_replace( '/\D/', '', $phone );
    if ( strlen( $digits ) < 9 ) {
        wp_send_json_error( 'מספר הטלפון לא נראה תקין.' );
    }

    /* ── שמירה בוורדפרס ─────────────────────────────── */
    $body  = "טלפון: {$phone}\n";
    $body .= $date ? "תאריך האירוע: {$date}\n" : '';
    $body .= $type ? "סוג האירוע: {$type}\n"   : '';
    $body .= $note ? "הערות: {$note}\n"        : '';
    $body .= "מקור בדף: " . ( $src ?: '—' ) . "\n";
    $body .= "עמוד: {$page}\n";
    $body .= "נשלח: " . current_time( 'd/m/Y H:i' );

    $post_id = wp_insert_post( array(
        'post_type'    => 'gali_lead',
        'post_status'  => 'publish',
        'post_title'   => $name,
        'post_content' => $body,
    ) );

    if ( $post_id && ! is_wp_error( $post_id ) ) {
        update_post_meta( $post_id, '_gali_phone', $phone );
        update_post_meta( $post_id, '_gali_date',  $date );
        update_post_meta( $post_id, '_gali_type',  $type );
        update_post_meta( $post_id, '_gali_src',   $src );
    }

    /* ── מייל התראה ─────────────────────────────────── */
    $wa = 'https://wa.me/972' . ltrim( $digits, '0' );

    $subject = 'ליד חדש מהאתר — ' . $name . ( $type ? ' · ' . $type : '' );

    $html  = '<div style="font-family:Arial,sans-serif;direction:rtl;text-align:right;max-width:560px">';
    $html .= '<h2 style="color:#E93B42;margin:0 0 14px">ליד חדש מהאתר 🎧</h2>';
    $html .= '<table cellpadding="8" style="border-collapse:collapse;width:100%;font-size:15px">';
    $html .= '<tr style="background:#FDECEC"><td><b>שם</b></td><td>' . esc_html( $name ) . '</td></tr>';
    $html .= '<tr><td><b>טלפון</b></td><td><a href="tel:' . esc_attr( $phone ) . '">' . esc_html( $phone ) . '</a></td></tr>';
    if ( $date ) $html .= '<tr style="background:#FDECEC"><td><b>תאריך האירוע</b></td><td>' . esc_html( $date ) . '</td></tr>';
    if ( $type ) $html .= '<tr><td><b>סוג האירוע</b></td><td>' . esc_html( $type ) . '</td></tr>';
    if ( $note ) $html .= '<tr style="background:#FDECEC"><td><b>הערות</b></td><td>' . nl2br( esc_html( $note ) ) . '</td></tr>';
    $html .= '<tr><td><b>מקור בדף</b></td><td>' . esc_html( $src ?: '—' ) . '</td></tr>';
    $html .= '<tr style="background:#FDECEC"><td><b>נשלח</b></td><td>' . current_time( 'd/m/Y H:i' ) . '</td></tr>';
    $html .= '</table>';
    $html .= '<p style="margin:20px 0"><a href="' . esc_url( $wa ) . '" '
           . 'style="background:#25D366;color:#06301A;padding:12px 26px;border-radius:99px;'
           . 'text-decoration:none;font-weight:bold;display:inline-block">פתח וואטסאפ עם הליד</a></p>';
    $html .= '<p style="font-size:12px;color:#888">נשלח אוטומטית מ-djgali.co.il</p>';
    $html .= '</div>';

    $host = wp_parse_url( home_url(), PHP_URL_HOST );
    $host = preg_replace( '/^www\./', '', $host );

    $headers = array(
        'Content-Type: text/html; charset=UTF-8',
        'From: אתר גלי מרגלית <noreply@' . $host . '>',
    );

    $sent = wp_mail( gali_lead_recipients(), $subject, $html, $headers );

    // המייל נכשל אך הליד נשמר — לא מכשילים את הגולש
    if ( ! $sent && $post_id ) {
        update_post_meta( $post_id, '_gali_mail_failed', '1' );
        error_log( 'GALI LEAD: saved #' . $post_id . ' but wp_mail failed.' );
    }

    wp_send_json_success( 'ok' );
}


/* ════════════════

/* ═══════════════════════════════════════════════
   1. ביטול השוליים של אלמנטור בכל הדף
   ⚠ שייך לדף הזה בלבד — אל תעביר ל-CSS גלובלי
   ═══════════════════════════════════════════════ */
.elementor-section,
.e-con{
  width:100%!important;
  max-width:100%!important;
  padding-inline:0!important;
  margin-inline:0!important;
  --content-width:100%!important;
  --padding-inline-start:0px!important;
  --padding-inline-end:0px!important;
}
.elementor-section > .elementor-container,
.e-con > .e-con-inner{
  width:100%!important;
  max-width:100%!important;
  padding-inline:0!important;
  margin-inline:0!important;
}
.elementor-widget-html > .elementor-widget-container{
  padding:0!important;
  margin:0!important;
}
html,body{overflow-x:hidden}

/* ═══════════════════════════════════════════════
   2. תפריט עליון — גדול וממורכז
   ═══════════════════════════════════════════════ */
.gm .gm-nav__inner{min-height:96px;gap:24px}
.gm .gm-nav__logo img{height:76px}
.gm .gm-nav__list{
  flex:1;
  justify-content:center;
  gap:6px;
}
.gm .gm-nav__link{
  font-size:1.12rem;
  font-weight:600;
  padding:12px 22px;
}
@media(max-width:1140px){
  .gm .gm-nav__list{justify-content:flex-start}
}
@media(max-width:860px){
  .gm .gm-nav__inner{min-height:64px;gap:10px}
  .gm .gm-nav__logo img{height:46px}
  .gm .gm-nav__link{font-size:1rem;padding:9px 15px}
}/* End custom CSS */